Subject: Re: Help Number Format

From: [email-masked] (Jason Mathews)
Date: 12 May 1995 13:29:24 GMT

In article <[email-masked]>,
Brian Gough <[email-masked]> wrote:
>In article <[email-masked]> [email-masked] (Stephen C. Steel) writes:
>
>   If you try to read data file written by non-Intel machines you may have
>   more problems as some store the bytes in a multibyte value in the
>   opposite order (eg. the Motorola processors used in Macintoshes and
>   many Unix workstations).
>
>I wish this were the only problem! I have been searching for a nice
>unix utility for converting between different numeric formats (ieee &
>non-ieee) as well as different endianness, but I haven't found
>one. Does anyone know if such a thing exists?
>
>It would be a useful thing to have, especially if all the problems of
>dealing with the more arcane formats could be solved once and for all.
>
>It would be nice not to have to write more bit-twiddling code every
>time we get a dataset in an obscure binary format.
>--
>Brian Gough
>
>Theoretical Physics, Fermilab,
>PO Box 500, Batavia IL-60510.
>tel: +1 708 840-3666 (fax 5435)
>[email-masked]                          

The NSSDC CDF scientific data format package does all the conversion
internally between the supported platforms (Mac, PC, flavors of UNIX,
VMS, OpenVMS, ...), which converts between the different machine
architectures (big-endian vs. little-endian, IEEE vs. non-IEEE).
All of the conversion routines are written in C and part of the
library source code available via anonymous ftp at ncgl.gsfc.nasa.gov
in /pub/cdf/dist/cdf25/.

For example the routine FP34toFP2single will convert Floating-point/34
to floating-point/2, single-precision (i.e., VAX floating point to
equivalent SGI format). These routines are located in the distribution
package as cdf25-dist/src/lib/cdfed.c.

The following table defines the four types of Floating-point encodings:

   1..........Sun, SGi, IBM-RS, HP, NeXT, Macintosh
   2..........DECstation, IBM-PC, DEC Alpha (OSF/1)
   3..........VAX, DEC Alpha (OpenVMS - D_FLOAT)
   4..........DEC Alpha (OpenVMS - G_FLOAT)

Each of the four classes is labeled in the source as FP1, FP2, FP3, and FP4.
Therefore, a conversion from types 3&4 to 2 would be defined as the routine
FP34toFP2 and the reverse.

A description of floating-point numbers from the CDF User's Guide is below:

"Single-Precision Floating-Point Data Types.

The single-precision floating-point encodings on the supported computers are
either IEEE 754 floating-point or Digital's F_FLOAT floating-point. There are
also two different byte orderings for the computers that use IEEE 754 (big-
endian and little-endian). 

Double-Precision Floating-Point Data Types.

The double-precision floating-point encodings on the supported computers are
either IEEE 754 floating-point, Digital's D_FLOAT floating-point, or Digital's
G_FLOAT floating-point. There are also two different byte orderings for the
computers that use IEEE 754 (big-endian and little-endian)."

The CDF User's Guide is available from anonymous ftp as a well as a hypertext
version via the CDF Home page URL: http://nssdc.gsfc.nasa.gov/cdf/cdf_home.html

Jason Mathews

-- 
------------------------------------------------------------------------------
Jason Mathews, Code 633.2	|National Space Science Data Center
NASA/Goddard Space Flight Center|email: [email-masked]
Greenbelt, MD 20771-0001  USA	|http://coney.gsfc.nasa.gov/Mathews/jason.html
--------------------------------+
-- 
------------------------------------------------------------------------------
Jason Mathews, Code 633.2	|National Space Science Data Center
NASA/Goddard Space Flight Center|email: [email-masked]
Greenbelt, MD 20771-0001  USA	|http://coney.gsfc.nasa.gov/Mathews/jason.html