Re: Fortran unformatted data: Big or little endian [message #34951 is a reply to message #34948] |
Wed, 30 April 2003 08:05   |
thompson
Messages: 584 Registered: August 1991
|
Senior Member |
|
|
David Fanning <david@dfanning.com> writes:
> Michael Schroeter (schroeter@muk.uni-hannover.de) writes:
>> and it works (up to now ;-)).
> I suspect it works *most* of the time. I don't see anything
> in there to *cause* the error. :-)
> You can certainly read data any way you like. It's not
> until you try to make *sense* of the data that you are
> likely to run into trouble. In your case, you might try
> reading a known data value from the file. It that value
> is total nonsense (your were expecting 45 and you get
> -20435), then you could "throw" an error, rewind the file,
> and read the data again with the SWAP_ENDIAN keyword set.
My experience has been that if one reads in floating point data with the wrong
byte-order, not only is the result garbage, but that one ends up with some
extremely large numbers, both positive and negative. For example, I reversed
the byte-order of an ordinary array, and ended up with an array with values of
2.70437e+38 and -1.90746e+38. One can use this to augment the procedure you
already have, by checking for values beyond a (generously defined) reasonable
range. In a sense, this is the same idea as David's, extended to where you may
not know what the exact value is that you expect, but you can recognize a
ridiculous value when you see one.
Cheers,
Bill Thompson
|
|
|