How can I use fortran to read a Grads binary data file

Eric DeWeaver deweaver at AOS.WISC.EDU
Thu Sep 15 12:01:24 EDT 2005


Hi Ming,

Have you tried reading in the array using a single
read statement instead of a loop?  I think the read
statement should be just

      read(17,rec=irec)berg

Also, I'm not sure about RECL=64*32.  Some compilers
want RECL to be the number of reals, but I think there
are also compilers that want RECL to be the number of
bytes.  In that case, you would use

     RECL=64*32*4

There's also the endian issue.  Some compilers have a
way to handle that, but I don't think there's any
specific standard.

Good luck,

Eric

On Thu, 15 Sep 2005, Ming Yang wrote:

>     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