* Re: Reading / Converting IEEE floating point data
1994-08-17 12:23 Reading / Converting IEEE floating point data mats
@ 1994-08-17 14:13 ` mats
0 siblings, 0 replies; 2+ messages in thread
From: mats @ 1994-08-17 14:13 UTC (permalink / raw)
I wrote:
Mats> Is there a filter that reads IEEE floating point data files
Mats> and outputs in a format suited for use on a DEC Alpha OSF1?
Mats> There are no headers in the files, just the numerical data.
My problem was solved by Eric Frey. His response to my question is
appended after my .sig below.
/Mats
--------------------------------------------------------------------------
Mats L�fdahl Internet: Mats@Astro.su.se
Stockholm Observatory MLofdahl@Solar.Stanford.edu
S-133 36 Saltsj�baden Voice: +46 - 8 16 44 75
Sweden Fax: +46 - 8 717 47 19
--------------------------------------------------------------------------
The Alpha uses IEEE floating point, but a different byte order than Sun.
Attached is a stupid program that I have written to do the swapping. Note
that you can use it for going back to a Sun too.
Eric Frey
/* swapbytes
Descrpiton: this is a simple program for swapping the order of bytes in a
binary 2 byte integer files. this is useful, for example, when transferring
clinicallly acquired image data files from a VAX to a SUN or STELLAR.
Usage: swapbytes infile outfile
Revision history:
written 10/25/89 eric frey
*/
#include <stdio.h>
#define SWAP(a,b,t) t = a; a = b; b = t
main(argc,argv)
int argc;
char **argv;
{
int count=0;
FILE *fpin, *fpout;
char errbuf[256];
char buf[4];/* buffers whose bytes are to be swapped*/
char tmp;
if (argc != 3){
fprintf(stderr,"usage: swapbytes infile outfile\n");
exit(1);
}
if ((fpin = fopen(*++argv,"r")) == NULL){
sprintf(errbuf, "can't open %s for input", *argv);
perror(errbuf);
exit(1);
}
if ((fpout = fopen(*++argv,"w")) == NULL){
sprintf(errbuf, "can't open %s for output", *argv);
perror(errbuf);
}
while(fread(buf,4,1,fpin) == 1){
count++;
SWAP(buf[0], buf[3], tmp);
SWAP(buf[1], buf[2], tmp);
if (fwrite(buf,4,1,fpout) != 1){
perror("error writing output file");
exit(1);
}
}
fprintf(stderr,"swapped %d 4 byte integers\n",count);
return(0);
}
^ permalink raw reply [flat|nested] 2+ messages in thread