How can I use fortran to read a Grads binary data file
Ming Yang
myang at EMAIL.UNC.EDU
Thu Sep 15 10:37:08 EDT 2005
Hi,
Thank you for your help. I still cannot figure out how to read it. Here
is the descriptor file
DSET ^topo-ice5g.t21.bin
UNDEF -9.99e+33
options byteswapped
XDEF 64 LINEAR 0 5.6250
YDEF 32 LEVELS
-85.761 -80.269 -74.745 -69.213
-63.679 -58.143 -52.607 -47.070
-41.532 -35.995 -30.458 -24.920
-19.382 -13.844 -8.307 -2.769
2.769 8.307 13.844 19.382
24.920 30.458 35.995 41.532
47.070 52.607 58.143 63.679
69.213 74.745 80.269 85.761
ZDEF 1 LINEAR 1 1
TDEF 1 LINEAR JAN1960 1MO
VARS 1
TOPO 1 99 Ice
ENDVARS
And here is my fortran program
program readbin
integer nlat,nlon,irec
parameter (nlon=64, nlat=32)
real*4 berg(nlat,nlon)
OPEN(17,file='topo-ice5g.t21.bin',
&STATUS='UNKNOWN',
&FORM='UNFORMATTED',ACCESS='DIRECT', RECL=64*32)
irec=1
do i=1,nlat
do j=1,nlon
read(17,REC=irec) berg(i,j)
irec=irec+1
write(*,*) berg(i,j)
enddo
enddo
end
Here is what I got after run this fortran program
-2.8802414E-11
3.4926203E-10
3.3586933E-22
-1.3897608E-11
****** FORTRAN RUN-TIME SYSTEM ******
Error 1066: record not in file
Location: the READ statement at line 15 of "readbin.f"
Unit: 17
File: topo-ice5g.t21.bin
Abort
The print out number is definetely wrong according the display of the
data in Grads. But I don't know how to fix it.
Best,
Ming
On Thu, 15 Sep 2005, [ISO-8859-1] Heiner Körnich wrote:
> Hi Ming,
>
> GrADS is using standard binary data. Depending on your option in .ctl,
> you read it with direct access for no option and sequential acces for
> "sequential" option. do you mean sequential with stream?
> Details to fortran are here:
> http://www.geocities.com/Athens/Olympus/5564/prof77.htm
>
> Cheers,
> Heiner
>
> Ming Yang wrote:
>
> > Hi, guys
> > I have a Grads binary file and I want to use a fortran program to
> > read it
> > and write to an ASCII file. Do you know how can I do that. I know the
> > binary
> > file is a "stream" file and I am supposed to use direct access to read
> > it,
> > right? Thank you for your attention.
> >
> > Best,
> > Ming
> >
> > Ming Yang
> > Department of Geological Sciences
> > University of North Carolina at Chapel Hill
> > myang at email.unc.edu
> > 919-843-5846
> >
> >
>
> --
> Heiner Körnich
> Dept. of Meteorology Tel: +46 8 164333
> Stockholms University
> S-106 91 Stockholm, Sweden Email: heiner at misu.su.se
>
More information about the gradsusr
mailing list