idl writeu and fortran... [message #35730] |
Thu, 10 July 2003 22:34  |
j oishi
Messages: 2 Registered: July 2003
|
Junior Member |
|
|
hi,
i know i'm stepping into murky waters here, but i have a question about
using idl to write unformatted binary files for fortran. when i write a
single record, ie
openw,unit,'blah.dat',/f77_unformatted,/get_lun
d=fltarr(10)
writeu,unit,d
free_lun(unit)
and then read it in in f77, everything is fine. when i try to add multiple
records to the same file, everything goes to hell:
openw,unit,'blah2.dat',/f77_unformatted,/get_lun
d=fltarr(10)
e=fltarr(10,10)
writeu,unit,d
writeu,unit,e
free_lun(unit)
now, in this second example, i can read the first record out of blah2.dat,
but trying to get e (the second record) out, causes the following error:
data [14:14]$ ./readbin
start: end of file
apparent state: unit 12 named aa0000.D
lately reading sequential unformatted external IO
Abort trap
i've tried this using two versions of idl on two different architectures,
compilers, etc. (reading and writing, that is...not trying to cross
platform with binary files)
can anyone provide insight?
thanks,
j oishi
|
|
|
Re: idl writeu and fortran... [message #35816 is a reply to message #35730] |
Mon, 14 July 2003 06:46  |
Paul Van Delst[1]
Messages: 1157 Registered: April 2002
|
Senior Member |
|
|
j oishi wrote:
>
>> you've opened the file, and c) how you actually read the data. I use Fortran/IDL to
>> write/read unformatted sequential and direct access files every day... all the time... no
>> problems. Across many different unix platforms using different Fortran compilers too.
> for example, the fortran code looks like:
>
> real d(10),e(10,10)
>
> open(12,file='blah.dat',form='unformatted')
>
> read(12) d
> read(12) e
>
> [stuff]
>
> stop
> end
Hmm. That should work just fine. My newsreader has lost your original message so I can't
double check, but if, in IDL, you write a single precision real array of size 10 and then
one of size [10,10] into a file opened using /f77_unformatted, it should work just fine.
Long shot #1:
Are you reading and writing on the same machine? If you're shifting the files from a PC to
some sort of unix workstation (or vice versa), the different byte-sex may be the cause of
the problem since the record length indicator at the beginning of each record will be some
ridiculously large value.
Long shot #2
What Fortran compiler are you using? It may be you are using a compiler that defaults to
record lengths measured in units of words (4 bytes) rather than bytes, e.g. like on an
SGI. So the first record read is expected to be 160 bytes instead of 40 bytes. The next
record length will be whatever the data value in "e" is at byte position 168 in the file
which, being a real value converted to an integer, is likely to be a Bad Number.
paulv
--
Paul van Delst
CIMSS @ NOAA/NCEP/EMC
Ph: (301)763-8000 x7748
Fax:(301)763-8545
|
|
|