Re: VMS vs UNIX, unformatted binary files [message #3609 is a reply to message #3594] |
Thu, 16 February 1995 06:52   |
ryba
Messages: 33 Registered: October 1992
|
Member |
|
|
In article <CHASE.95Feb15180954@retro.jhuapl.edu>, chase@retro.jhuapl.edu (Chris Chase S1A) writes:
|> >>>>> "Lars" == Lars Soeraas <lars@rapid.fi.uib.no> writes:
|> Lars> We are trying to read unformatted binary files in IDL on a
|> Lars> UNIX system (HP 9000, series 700). The files to be read have been
|> Lars> generated by IDL on a VAX VMS. The problem is that the bytes are
|> Lars> swapped and the files contain a mixture of lonint, int, floats
|> Lars> and character strings. We have an idl program to read the files
|> Lars> which works well on a VAX but returns garbage on the UNIX system.
|> Lars> Is there a simple way of avoiding this problem?
|>
|> Use XDR format. This format is portable among versions of IDL running
|> on different machines. This is a special portable binary format that can be
|> read by other programs (e.g., C and PASCAL) on machines that have the
|> XDR library. See Chapter 17 of the IDL User Guide.
|>
|> To use the XDR format, just add the /XDR keyword to your open
|> statements in IDL. It is that easy.
|>
|> If you want to create XDR files with other programs for IDL to read,
|> there is an example in the User Guide. It is C program that creates
|> an XDR data file which is then easily read into IDL.
A probably simpler way to use XDR format if you have any intention
of reading these files outside of IDL is to use netCDF. The ncdf_*
calls in IDL are very easy to use, and the C and FORTRAN API's for
netCDF are essentially identical to the IDL one. I had a problem with
some F77 unformatted files on a VAX, with some VAX FORTRAN routines
for reading them. I wrote a read/process program in FORTRAN that runs
on the VAX and writes its output as a netCDF file, then FTP the file
over, and use IDL (and other C programs) to read them on the Sun. Of
further benefit is the fact that netCDF is a standard self-documenting file
format, which beats custom file formats. Hell, even NCSA Mosaic can parse
a netCDF file, and Collage and Slicer can plot their contents.
--
Dr. Marty Ryba | Generation X:
MIT Lincoln Laboratory | Too young to be cynical,
ryba@ll.mit.edu | too old to be optimistic.
Of course nothing I say here is official policy, and Laboratory affiliation is
for identification purposes only, blah, blah, blah....
|
|
|