Re: Trouble reading unformatted f77 (unix) integers? [message #4155] |
Wed, 10 May 1995 00:00 |
thompson
Messages: 584 Registered: August 1991
|
Senior Member |
|
|
Brett Hennig <bretth@lovelace.maths.monash.edu.au> writes:
> Here's the problem:
> The F77 code:
> open(unit=51,name='test1.dat',status='unknown',form='unforma tted')
> write(51)1,2,3
> close(51)
> end
> The idl code(that doesn't work):
> openr,n,'test1.dat',/get_lun,/f77_unformatted
> x=0 & y=0 & z=0
> readu,n,x,y,z
> print,x,y,z -----> 1 0 2
> free_lun,n
> end
> Code that does:
> openr,n,'test1.dat',/get_lun,/f77_unformatted
> x=0 & y=0 & z=0 & dum1=0 & dum2=0
> readu,n,x,dum1,y,dum2,z
> print,x,dum1,y,dum2,z -----> 1 0 2 0 3
> free_lun,n
> end
> is idl not interpreting the input correctly? or.. ? ?
Your problem is very simple. The default integer data type in FORTRAN takes up
four bytes (INTEGER*4). In IDL parlance, this is known as a long integer. The
default IDL integer type is a short integer which only takes up two bytes.
The following code should work correctly.
openr,n,'test1.dat',/get_lun,/f77_unformatted
x=0L & y=0L & z=0L
readu,n,x,y,z
print,x,y,z
free_lun,n
end
As should this.
openr,n,'test1.dat',/get_lun,/f77_unformatted
xyz=lonarr(3)
readu,n,xyz
print,xyz
free_lun,n
end
Bill Thompson
|
|
|
Re: Trouble reading unformatted f77 (unix) integers? [message #4156 is a reply to message #4155] |
Wed, 10 May 1995 00:00  |
evans
Messages: 1 Registered: May 1995
|
Junior Member |
|
|
In article <3oqb90$l2l@harbinger.cc.monash.edu.au>, Brett Hennig
<bretth@lovelace.maths.monash.edu.au> writes:
> Here's the problem:
> The F77 code:
>
> open(unit=51,name='test1.dat',status='unknown',form='unforma tted')
> write(51)1,2,3
> close(51)
> end
>
> The idl code(that doesn't work):
>
> openr,n,'test1.dat',/get_lun,/f77_unformatted
> x=0 & y=0 & z=0
> readu,n,x,y,z
> print,x,y,z -----> 1 0 2
> free_lun,n
> end
The problem is that x, y, z are being initialized as integers
(2 bytes) rather than longs (4 bytes), while the fortran program
is writing out 4-byte integers.
Replacing the line
x=0 & y=0 & z=0
with
x=0L & y=0L & z=0L
will make the idl code work correctly.
Cheers!
Ian
------------------------------------------------------------ -----------
Ian Evans phone: +1-(410)-338-4756
FOS Scientist fax: +1-(410)-338-4767
Space Telescope Science Institute internet: evans@fos.stsci.edu
3700 San Martin Drive NSI/DECnet: stfosc::evans
Baltimore, MD 21218
U.S.A.
Disclaimer: The statements made herein reflect solely the opinions of
the author, and should in no way be construed as being representative
of the views of the Space Telescope Science Institute, the Association
of Universities for Research in Astronomy, or the National Aeronautics
and Space Administration.
------------------------------------------------------------ -----------
|
|
|
Re: Trouble reading unformatted f77 (unix) integers? [message #4157 is a reply to message #4155] |
Wed, 10 May 1995 00:00  |
mallozzi
Messages: 60 Registered: August 1994
|
Member |
|
|
> The F77 code:
> open(unit=51,name='test1.dat',status='unknown',form='unforma tted')
> write(51)1,2,3
> close(51)
> end
IDL's integers are 2 bytes long. I think when you write out the fortran
integers as above, it takes them to be INTEGER*4. i.e. 4 bytes. The byte
sizes MUST match when you write/read like this. Try defining the variables
you are going to read in IDL as LONGs, which are 4 byte integers.
|
|
|