From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII X-Google-Thread: fee84,a6ccf70f515c5eed X-Google-Attributes: gidfee84,public X-Google-ArrivalTime: 1994-08-17 07:29:05 PST Path: bga.com!news.sprintlink.net!hookup!swrinde!howland.reston.ans.net!EU.net!sunic!news.kth.se!news.kth.se!mats From: mats@royac1.astro.su.se (mats) Newsgroups: comp.unix.osf.osf1 Subject: Re: Reading / Converting IEEE floating point data Date: 17 Aug 1994 14:13:25 GMT Organization: Stockholm Observatory, Stockholm, Sweden Distribution: world Message-ID: References: Reply-To: Mats L�fdahl NNTP-Posting-Host: royac1.astro.su.se Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit In-reply-to: mats@royac1.astro.su.se's message of 17 Aug 1994 12:23:37 GMT 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 #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); }