Re: Associated reads on Unix/f77 binaries [message #5606 is a reply to message #5603] |
Mon, 22 January 1996 00:00   |
nhbkmich
Messages: 8 Registered: January 1996
|
Junior Member |
|
|
Bryan A. Franz (franz@bikini.gsfc.nasa.gov) wrote:
: Has anybody managed to do associated reads on files generated by f77 under
: Unix ?
: I have RTFM, which states that you can't do associated reads on files
: generated from FORTRAN 77 under Unix. Apparently, f77 sticks a longword
: containing the number of bytes before and after each logical record. IDL's
: readu accounts for the extra bytes, but assoc does not. It seems to me that I
: should still be able to do the associated reads, if I just added a dummy
: longword on either side of my datastructure, but it does not seem to work.
There are two kinds of unformatted files in Fortran: access='sequential' and
access='direct'. The latter one is equivalent to IDL's associated IO, all
records must have the same size and are reached by index. Under UNIX these files
don't contain recordlength information and reading them using ASSOC works fine.
Files written by Fortran with access='sequential' (the default!) may contain
records of different sizes, thus reading by ASSOC might fail.
But the follwing example for reading a sequentially written file with records
of equal sizes works (at least on HP-UX):
Fortran writing square numbers of 1 to 10 into 'unfo.dat':
program unfo
implicit none
integer i
open(1, file='unfo.dat', form='unformatted', access='sequential')
do i=1,10
write(1) i**2
end do
close(1)
end
IDL reading 'unfo.dat' by ASSOC:
pro unfo
openr,unit,'unfo.dat',/get_lun
buf={dummy1:0L, value:0L, dummy2:0L}
unf=assoc(unit,buf)
for i=0,9 do begin
buf=unf(i)
print,buf.value
endfor
free_lun,unit
end
|
|
|