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

Home » Public Forums » archive » Saving structure variables
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: Saving structure variables [message #16212 is a reply to message #16133] Tue, 06 July 1999 00:00 Go to previous messageGo to previous message
Liam Gumley is currently offline  Liam Gumley
Messages: 473
Registered: November 1994
Senior Member
Bernard Puc wrote:
> Ah, but unfortunately, the files were stored as unformatted binary.
> I need to find a way of reading them on a Linux platform. This is
> part of moving an archive of data one time to a new platform. I
> guess I'll have to read in the structures, resave as IDL save files,
> and transfer to the new platform.

Bernard,

I went back and read your original message again, and I think I
understand your problem a little better. I assume the data was saved to
disk on the SGI something like this:

record = {name:'Test', value:indgen(10)}
data = replicate(record, 100)
openw, 1, 'test.dat'
writeu, 1, data
close, 1

Then to read the data in Linux, the code should look like this:

record = {name:' ', value:intarr(10)}
data = replicate(record, 100)
openr, 1, 'test.dat'
readu, 1, data
close, 1
data = swap_endian(data)

Note that only the data values are stored in the file on disk; the
structure tag names are set by the IDL statements in the read procedure
which define the structure.

I notice that you use the word 'archive' in your second post. In my
experience, data archives tend to live longer than we expect, so I
recommend putting at least a little effort into making sure the archived
data can be read on both little-endian and big-endian platforms.

For example, if you stay with the method shown above, you could make the
reader more intelligent, so that it queries the *data* itself to see
whether the byte order needs to be swapped (this assumes that your data
format stays constant). You can pick a couple of items from each record
whose values you expect to be in a certain range, e.g.

HOUR must be in the range 0 to 24,
DATE must be in the range 19950101 to 20101231,

then your reader would work like this:

(1) Define the record structure
(2) Read the first record from the data file
(3) If HOUR and DATE are within limits, turn swap flag OFF and goto step
(7)
(4) If HOUR and DATE are out of limits, use SWAP_ENDIAN on the entire
record
(5) If HOUR and DATE are within limits, turn swap flag ON and goto step
(7)
(6) The file is not in the expected format, so stop with an error
message
(7) Read the rest of the data file, using SWAP_ENDIAN is swap flag is on

This will give you a reader that handles byte-swapping transparently on
SGI or Linux.

Note that the IDL SAVE format could potentially change at some point in
a future version of IDL. If I really wanted a safe *archive* format, I
would not use SAVE. Rather, I would use a binary format as described
above, or a portable self describing format like netCDF.

Cheers,
Liam.

--
Liam E. Gumley
Space Science and Engineering Center, UW-Madison
http://cimss.ssec.wisc.edu/~gumley
[Message index]
 
Read Message
Read Message
Read Message
Previous Topic: GET_DRAW_VIEW question
Next Topic: Finding map SCALE given latitude.

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

Current Time: Tue Dec 02 12:36:38 PST 2025

Total time taken to generate the page: 0.88459 seconds