Re: Q: IDL and endianness issues [message #19686] |
Thu, 13 April 2000 00:00 |
Nando Iavarone
Messages: 48 Registered: December 1998
|
Member |
|
|
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
Ossi Vaananen wrote:
<blockquote TYPE=CITE>Hi!
<p>Let's say I have a binary file with known structure, and
<br>the file is written on a little-endian machine. Then I want
<br>to read it again on a big-endian machine. How do I do it?
<p>If endianness was no problem, I could do this simply by
<br>creating a structure with contents that match the alignment
<br>of the different data types in the binary file, and then
<br>read data to it from the file with READU.
<p>In Matlab, files can be opened with the endianness of the
<br>file explicitly given as an argument to fopen. In IDL manuals
<br>I saw no reference to such a feature in IDL.
<p>The question is, does there exist a built-in feature in IDL
<br>that somehow allows endianness-specified file I/O?
<p>All the best,
<p>Ossi Vaananen
<br>Espoo, Finland</blockquote>
see 'BYTEORDER' procedure and the 'SWAP_ENDIAN' function.
<br>bye.
<br>
<pre>--
Nando Iavarone
Advanced Computer System - SPACE DIVISION
via Lazzaro Belli, 23
00040 Frascati - RM
Tel: +39-6-944091 (switchboard)
9440968 (direct)
E-mail:
f.iavarone@acsys.it
FrdndVrn@altavista.net</pre>
</html>
|
|
|
Re: Q: IDL and endianness issues [message #19720 is a reply to message #19686] |
Tue, 11 April 2000 00:00  |
Liam E. Gumley
Messages: 378 Registered: January 2000
|
Senior Member |
|
|
> Ossi Vaananen wrote:
>> Hi!
>>
>> Let's say I have a binary file with known structure, and
>> the file is written on a little-endian machine. Then I want
>> to read it again on a big-endian machine. How do I do it?
>>
>> If endianness was no problem, I could do this simply by
>> creating a structure with contents that match the alignment
>> of the different data types in the binary file, and then
>> read data to it from the file with READU.
>>
>> In Matlab, files can be opened with the endianness of the
>> file explicitly given as an argument to fopen. In IDL manuals
>> I saw no reference to such a feature in IDL.
>>
>> The question is, does there exist a built-in feature in IDL
>> that somehow allows endianness-specified file I/O?
You might want to check out the following:
http://cimss.ssec.wisc.edu/~gumley/binarytools.html
Cheers,
Liam.
|
|
|
Re: Q: IDL and endianness issues [message #19721 is a reply to message #19720] |
Tue, 11 April 2000 00:00  |
Paul van Delst
Messages: 364 Registered: March 1997
|
Senior Member |
|
|
Ossi Vaananen wrote:
>
> Hi!
>
> Let's say I have a binary file with known structure, and
> the file is written on a little-endian machine. Then I want
> to read it again on a big-endian machine. How do I do it?
>
> If endianness was no problem, I could do this simply by
> creating a structure with contents that match the alignment
> of the different data types in the binary file, and then
> read data to it from the file with READU.
>
> In Matlab, files can be opened with the endianness of the
> file explicitly given as an argument to fopen. In IDL manuals
> I saw no reference to such a feature in IDL.
>
> The question is, does there exist a built-in feature in IDL
> that somehow allows endianness-specified file I/O?
yes. You can use the swap_endian function or the swap_endian keyword to
the open command.
--
Paul van Delst Ph: (301) 763-8000 x7274
CIMSS @ NOAA/NCEP Fax: (301) 763-8545
Rm.202, 5200 Auth Rd. Email: pvandelst@ncep.noaa.gov
Camp Springs MD 20746
|
|
|
Re: Q: IDL and endianness issues [message #19722 is a reply to message #19720] |
Tue, 11 April 2000 00:00  |
Ed Santiago
Messages: 8 Registered: January 2000
|
Junior Member |
|
|
Use the SWAP_IF_ options to OpenR:
OpenR, lun, fname, /Get_Lun, /Swap_If_Big_Endian
foo = ULonArr(1024) ; or a struct, or floats, or whatever
ReadU, lun, foo
Have fun,
^E
--
Eduardo Santiago Software Type esm@nospam.lanl.gov RKBA!
|
|
|
Re: Q: IDL and endianness issues [message #19723 is a reply to message #19720] |
Tue, 11 April 2000 00:00  |
John-David T. Smith
Messages: 384 Registered: January 2000
|
Senior Member |
|
|
Ossi Vaananen wrote:
>
> Hi!
>
> Let's say I have a binary file with known structure, and
> the file is written on a little-endian machine. Then I want
> to read it again on a big-endian machine. How do I do it?
>
> If endianness was no problem, I could do this simply by
> creating a structure with contents that match the alignment
> of the different data types in the binary file, and then
> read data to it from the file with READU.
>
> In Matlab, files can be opened with the endianness of the
> file explicitly given as an argument to fopen. In IDL manuals
> I saw no reference to such a feature in IDL.
>
> The question is, does there exist a built-in feature in IDL
> that somehow allows endianness-specified file I/O?
>
Take a look at byteorder() or swap_endian(). For best results, use the nasa
routines ieee_to_host and host_to_ieee.
Good luck,
JD
--
J.D. Smith |*| WORK: (607) 255-5842
Cornell University Dept. of Astronomy |*| (607) 255-6263
304 Space Sciences Bldg. |*| FAX: (607) 255-5875
Ithaca, NY 14853 |*|
|
|
|