writing binary data with fbinrecwrite

From: mark collier <Mark.Collier_at_nyahnyahspammersnyahnyah>
Date: Wed Oct 19 2011 - 21:39:25 MDT

Hi, because of extremely useful scripting languages like NCL my
fortran is very rusty. I'm trying to write out some data in a local
file format, using write_cif.ncl (below). However, when I try to read
it in, using read_cif.f (below), the header string is garbled,
everything else (integer,float) is OK. I've tried writing out the data
as type character, although I got the right file size, the header is
still not readable. Any help appreciated. Regards, Mark.

cat write_cif.ncl

begin

ofil="test.cif"

system("rm test.cif")

lats=ispan(-90,90,30)*1.0
lons=ispan(0,360,60)*1.0

nlat=dimsizes(lats)
nlon=dimsizes(lons)
nlatlon=nlat*nlon

data=new((/nlat,nlon/),float)

do j=1,nlat
do i=1,nlon
data(i-1,j-1)=j*nlon+i
end do
end do

header
=
"01234567890123456789012345678901234567890123456789012345678901234567890123456789
"

print("Number of lats/lons: "+nlat+","+nlon)
print("header: "+header)

fbinrecwrite(ofil,-1,nlat)
fbinrecwrite(ofil,-1,lats)
fbinrecwrite(ofil,-1,nlon)
fbinrecwrite(ofil,-1,lons)
fbinrecwrite(ofil,-1,header)
fbinrecwrite(ofil,-1,data)

end

cat read_cif.f
        program test
c character*80 header
        character header
        integer nlat,nlon
        real lats(7)
        real lons(7)
        real data(7,7)

        open(1,file="test.cif",form="unformatted",access="sequential",
      c status="old")

        read(1)nlat
        read(1)(lats(j),j=1,nlat)
        read(1)nlon
        read(1)(lons(i),i=1,nlon)
        read(1)header
        read(1)((data(i,j),i=1,nlon),j=1,nlat)

        print*,nlat
        print*,lats
        print*,nlon
        print*,lons
        print*,header
        print*,((data(i,j),i=1,nlon),j=1,nlat)

        end

_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Wed Oct 19 21:39:33 2011

This archive was generated by hypermail 2.1.8 : Mon Oct 24 2011 - 09:29:35 MDT