Morwenna Grifiths wrote:
> I'm having difficulty reading unformatted fortran in IDL. I think I am
> doing just what the manual tells me to, but I assume I'm not! Here's a
> sample program.
>
> The fortran code to write the unformatted data:
> program write_out
> integer bb
> real aa
>
> write(6,*) 'in write_out now'
> open(unit=15,file='t1',form='unformatted',status='unknown')
> bb = 23
> write(15) bb
> close(unit=15)
>
> open(unit=16,file='t2',form='unformatted',status='unknown')
> aa=47.0
> write(16) aa
>
> close(unit=16)
>
> stop
> end
>
> The IDL code that doesn't work:
> a=1 & b=1 & c=1 & d=1 & e=1 & f=1 & aa=1.0
>
> openr,1,'t1',/f77_unformatted
> readu,1,a
> close,1
> print,'should be',a ; gives an answer of 0
>
> openr,1,'t1',f77_unformatted
> readu,1,a,b,c,d,e,f
> print,'but it is: ',a,b,c,d,e,f ; gives answers of 0 4 0 23 0 4, so the
> 4th number is correct
> close,1
>
> openr,2,'t2',f77_unformatted
> readu,2,aa
> print,'real number ',aa ; gives an answer of 5.60519e-45, no idea why!
>
> close,/all
>
> So it seems that IDL is reading some extra characters before and after
> the integer, and I have no idea what's happening with the real data.
>
> I'm running both the fortran and IDL on the same machine (a silicon
> graphics).
I compiled and ran your program on my SGI (Origin2000, Irix 6.5) using
% f77 write_out.f
% a.out
The following IDL commands read the file just fine:
openr, 1, 't1', /f77_unformatted
bb = 0L
readu, 1, bb
print, bb
close, 1
openr, 1, 't2', /f77_unformatted
aa = 0.0
readu, 1, aa
print, aa
close, 1
Note that
(1) /f77_unformatted is a keyword (not an argument), hence the leading
slash,
(2) bb is defined as a long integer (0L),
(3) aa is defined as a 32 bit float (0.0).
Cheers,
Liam.
--
Liam E. Gumley
Space Science and Engineering Center, UW-Madison
http://cimss.ssec.wisc.edu/~gumley
|