Re: Fortran unformatted data: Big or little endian [message #34956 is a reply to message #34955] |
Wed, 30 April 2003 06:30   |
Michael Schroeter
Messages: 5 Registered: January 2002
|
Junior Member |
|
|
David Fanning wrote:
> Michael Schroeter (schroeter@muk.uni-hannover.de) writes:
>
>
>> I have a problem reading Fortran unformatted data in IDL. I have a file
>> containing data of well known size (e.g., an array of 100 x 100 single
>> precision floating point values). Unfortunately, I don't know something
>> about the machine (big or little endian machine) on which the file has
>> been produced. Is there a way to get this information on the fly by IDL
>> in order to open the file automatically in the correctly (using the
>> /SWAP_ENDIAN option or not). The way I used so far was trial and error.
>> But since I have many of those files I'm searching for a solution
>> without recompiling my source code.
>>
>> Do you have any ideas?
>
>
> Here is an article with some ideas:
>
> http://www.dfanning.com/tips/endian_machines.html
>
> Cheers,
>
> David
>
Hi David,
the problem is that I don't know the "endian nature" of the machine that
created the data.
In the meanwhile I tried using error catching, like shown in this
code-snippet:
array = FLTARR(100,100)
OPENR, lun, data_file, /F77_UNFORMATTED, /GET_LUN
CATCH, error_status
IF error_status NE 0 THEN BEGIN
PRINT, 'Error index: ', error_status
PRINT, 'Error message: ', !ERROR_STATE.MSG
FREE_LUN, lun
OPENR, lun, data_file, /SWAP_ENDIAN, /F77_UNFORMATTED, /GET_LUN
READU, lun, array
CATCH, /CANCEL
ENDIF ELSE BEIN
READU, array
ENDELSE
and it works (up to now ;-)).
Anyway, thanks and best regards
Michael
|
|
|