problems read binary grads file with a fortran file

Eric Altshuler ela at COLA.IGES.ORG
Thu Jul 31 15:21:56 EDT 2008

Hi Isilda,

The problem may be that your fortran program opens unit 11 for sequential access but grads writes the fwrite file as flat binary (no control words) which would have to be read in the fortran program by direct access. Opening unit 11 for direct access is one way to solve the problem, but it is easier to tell grads to write the fwrite file sequentially by adding the -sq flag to 'set fwrite':

'set fwrite -sq -le mocambique.gra'

Also, you have specified the dimensions of the array 'a' as (42,42). Be sure that the X-Y dimensions in the grads dimension environment are also (42,42) when the fwrite file is written. It's not possible to tell from your 'set lon' and 'set lat' commands how many grid points are in the lat-lon region you have specified.

Best regards,

Eric L. Altshuler
Assistant Research Scientist
Center for Ocean-Land-Atmosphere Studies
4041 Powder Mill Road, Suite 302
Calverton, MD 20705-3106

E-mail: ela at
Phone: (301) 902-1257
Fax: (301) 595-9793

----- Original Message -----
From: "Isilda da Cunha Menezes" <isilda at UEVORA.PT>
Sent: Thursday, July 31, 2008 6:27:14 AM GMT -05:00 US/Canada Eastern
Subject: problems read binary grads file with a fortran file

I have a problem when I try to read with a fortran program  the binary
data generated by the grads that extracts with the fwrite.

I extracts the data as follows:

'open prec-temp-mocamb_g3.ctl'
'set gxout fwrite'
'set fwrite -le mocambique.gra'
'set lon -8.967 -7.077'
'set lat 36.999 38.511'

'set t 't
'set z 1'

'd (totpcp-totpcp(t-1))+(acccon-acccon(t-1))'

'set z 1'

'd tempc'

* Fim do loop no tempo

*'disable fwrite'

And I read the data created in a fortran program as follows:

      program ler

      real a(42,42),x(42,42,2,24,31)
      integer var,dia,hora,lat,long,soma,j,id,imi,imf,hour


      do hour=1,744
      do var=1,2
      read(11) ((a(long,lat),long=1,42),lat=1,42)
      write(*,*)'estou aqui'

But get an error of core dump. I tried reading the matrix of different
ways, but always get the same error. This file .gra is read  directly with
a fortran program or will have to use another method? If not needed,
someone could indicate me where I have the error?

Best regards,

More information about the gradsusr mailing list