comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: Fortran and byte swapping
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: Fortran and byte swapping [message #7676 is a reply to message #7673] Fri, 13 December 1996 00:00 Go to previous message
Liam Gumley is currently offline  Liam Gumley
Messages: 473
Registered: November 1994
Senior Member
Simon Williams wrote:
> I have a large dataset which is in Unformatted variable-length
> records written in FORTRAN on a SUN (big endian). I want to
> read it on a DEC alpha running OSF (little endian) using IDL.
> It is not really practical to convert the whole dataset.
>
> 1. I Can't use "openr, ..... ,/f77_unformatted" because the
> record length information stored in the file is byte-swapped
> so it falls over on the first read.
>
> 2. I could drop the /f77_unformatted keyword and handle the
> record structure myself, but even then I can't see a simple
> way of doing it - I would need an IDL function which behaves
> like readu, so that I can pass an arbitrary number of arguments
> to it or I will have to clog up my routine with a load of
> calls to byteorder for each parameter I read.
>
> Any ideas? The nicest solution would be a "byteswap keyword" to
> the open routines - like the one provided by dec fortran, but I
> guess that's a bit much to ask!

If you don't want to convert the datafile, then:

First, open the file without the /F77_UNFORMATTED keyword.

Create a record length index array by reading (READU) the first length
word, swapping it using SWAP_ENDIAN, store it in the array, skip to the
next length word (POINT_LUN), swap it, etc. to the end of the file.

You now have a record length index array that you can use to read the
file. Point back to the beginning of the file, and skip the length
word, read the number of data words indicated in the length array, and
then swap the data array using SWAP_ENDIAN.

Seems simple enough. I'd write some code for you but I haven't had my
coffee yet.

Cheers,
Liam.
[Message index]
 
Read Message
Read Message
Read Message
Previous Topic: Your GOD Loves You - YES YOU!
Next Topic: NT and Unix systime precision

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Sat Oct 11 15:57:36 PDT 2025

Total time taken to generate the page: 0.64109 seconds