writing binary data to disk with pgf90

I’m trying to dump some real*4 binary arrays to disk and I
get garbage results, even though doing an ascii dump of a portion
of the array shows the data values themselves to be ok.

If I’m dumping an array (real4) of NSMP samples to disk, what
should I set the record length to be? I’m currently setting the
record length to NSMP
4, but this produces garbage.

Thanks for any help,

Catherine

Here’s a code sample:

PROGRAM READ_QSCAT

IMPLICIT NONE

INTEGER, PARAMETER :: NLAT = 180
INTEGER, PARAMETER :: NLONG = 360
INTEGER, PARAMETER :: NPIX = 4

CHARACTER(LEN=120) :: FILENAME
REAL4, DIMENSION(NLONGNPIX,NLATNPIX) :: WINDSPD, WINDDIR, RADRAIN
INTEGER
4, DIMENSION(NLONGNPIX,NLATNPIX) :: SCATFLAG

INTEGER :: ILINE,ISMP

INTEGER :: IERR

filename = ‘/data/L2TC/cmm/tasc/200001’

call get_scat_averaged_v03(filename, windspd, winddir, scatflag, radrain, ierr)

open(10,file=‘windspeed.bin’,form=‘unformatted’,access=‘direct’, &
recl=nlongnpix4,action=‘write’,status=‘replace’)
open(11,file=‘windangle.bin’,form=‘unformatted’,access=‘direct’, &
recl=nlongnpix4,action=‘write’,status=‘replace’)

do iline = 1,nlatnpix
write(10,rec=iline) (windspd(ismp,iline),ismp=1,nlong
npix)
write(11,rec=iline) (winddir(ismp,iline),ismp=1,nlong*npix)
end do

close(10)
close(11)

END PROGRAM READ_QSCAT

Hi Catherine,

We looked over the code you posted and see nothing wrong with it so are wondering how you are reading in the data to determine that it’s garbage? Is it being read by a separate application that was compiled with byteswaping? Does the read use ‘sequential’ instead of ‘direct’ access?

  • Mat

It was my mistake. I was dumping the data out on a little-endian
machine and displaying it on a big-endian one. Once I byte-swapped,
I got back the values that I wanted.

I remember some Fortran compilers had slightly different rules
for calculating the record-length in a binary file so I was under the
(wrong) impression that I had hit that problem.

Catherine