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

Home » Public Forums » archive » Re: f77 unformatted file reading error
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Re: f77 unformatted file reading error [message #41596] Fri, 12 November 2004 14:10
Mark Hadfield is currently offline  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)
Re: f77 unformatted file reading error [message #41661 is a reply to message #41596] Thu, 11 November 2004 00:45 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Jaehyung Yu writes:

> I am totally new to IDL, but have to use this program to extract binary
> data.
>
> Need your help.
>
> 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.

I think it is likely this is just a byte ordering problem.
Try setting the SWAP_IF_LITTLE_ENDIAN keyword on your
OPENR statement and see if that works better.

Cheers,

David
--
David W. Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http:/www.dfanning.com/
Phone: 970-221-0438, IDL Book Orders: 1-888-461-0155
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: meshes and some irritations
Next Topic: Re: Link to a variable page into an ION code

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

Current Time: Wed Oct 08 19:37:14 PDT 2025

Total time taken to generate the page: 0.00710 seconds