| Re: f77 unformatted file reading error [message #41596] |
Fri, 12 November 2004 14:10  |
Mark Hadfield
Messages: 783 Registered: May 1995
|
Senior Member |
|
|
Jaehyung Yu wrote:
> I have downloaded one file named "bal_flux.bas_smooth35", and tried to read
> the file as following;
>
> IDL> file = 'bal_flux.bas_smooth35'
> IDL> openr, lun, file, /f77_unformatted, /get_lun
> IDL> nx = 0L & ny = 0L
> IDL> readu, lun, nx, ny
> %READU: Corrupted f77 unformatted file detected. Unit: 100,
> File:>>E:\LAMBERT_DB\MASS_BALANCE\bal_flux.bas_smooth35
> % Execution halted at: $MAIN$
>
> I am using PC version 6.0.1, and set the "working directory" in "start up"
> tap in preference menu to the directory that the data are
> located.
>
> The other guy used the same file to extract the same way. And she was
> successful. The only difference between hers and mine is that hers is unix
> version and mine is PC version.
I don't think /F77_UNFORMATTED works on the PC.
It is possible files in "Fortran unformatted" format in IDL on Windows.
The problem is that each record in the file is typically preceded and
followed by a 32-bit integer (maybe 64-bit on some platforms) specifying
the record length. So you have to read that too.
Here's an example from some code to read NCEP CMB OI SST data (don't
worry if acronyms make no sense to you). The files contain data with
little-endian byte order, so the OPEN statement swaps the byte order for
the PC. The first record in the file is a header with eight long-integer
values. Here I read them into an array called "info"
openr, lun, infile, /GET_LUN, /SWAP_IF_LITTLE_ENDIAN
n0 = 0L
n1 = 0L
info = lonarr(8)
readu, lun, n0, info, n1
if n0 ne 4*n_elements(info) then $
message, 'Wrong byte count in header:'+string(n0)
if n1 ne n0 then $
message, 'Wrong byte count in header:'+string(n1)
free_lun, lun
--
Mark Hadfield "Ka puwaha te tai nei, Hoea tatou"
m.hadfield@niwa.co.nz
National Institute for Water and Atmospheric Research (NIWA)
|
|
|
|