* Reading / Converting IEEE floating point data
@ 1994-08-17 12:23 mats
1994-08-17 14:13 ` mats
0 siblings, 1 reply; 2+ messages in thread
From: mats @ 1994-08-17 12:23 UTC (permalink / raw)
Question:
Is there a filter that reads IEEE floating point data files and
outputs in a format suited for use on a DEC Alpha OSF1? There are no
headers in the files, just the numerical data.
Background:
I'm trying to read some image data into my image processing software
on a DEC Alpha OSF1.
For testing purposes, I have three files with the same image in
unsigned-byte format, signed-word format and 4-byte IEEE float. The
data files are generated by some of my colleagues with what I am told is
"Sun numerical representation conventions".
I can read all the files. The byte data looks like expected. If I swap
the bytes in the signed-word data, these look fine, too. I don't know
what to do with the floating point data, though.
I would really appreciate it if anyone could solve this problem for
me.
/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
--------------------------------------------------------------------------
^ permalink raw reply [flat|nested] 2+ messages in thread
* 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
end of thread, other threads:[~1994-08-17 14:13 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
1994-08-17 12:23 Reading / Converting IEEE floating point data mats
1994-08-17 14:13 ` mats
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox