Usenet comp.unix.osf.osf1 (1992-2004)
 help / color / mirror / Atom feed
From: mats@royac1.astro.su.se (mats)
Subject: Re: Reading / Converting IEEE floating point data
Date: 17 Aug 1994 14:13:25 GMT	[thread overview]
Message-ID: <MATS.94Aug17161325@royac1.astro.su.se> (raw)
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 <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);
}


      reply	other threads:[~1994-08-17 14:13 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1994-08-17 12:23 Reading / Converting IEEE floating point data mats
1994-08-17 14:13 ` mats [this message]
read-only archive

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox