Problem with self-made binary files

Charles Seman Charles.Seman at NOAA.GOV
Mon Jan 24 17:15:28 EST 2005


Dear Andrea,

Could you try:

      WRITE (7,REC=1) U
      WRITE (7,REC=2) V

for unformatted output (number of elements are specified in your "open"
statement)?  This works for our codes... If you had an NDZ, then put the
write statements in a vertical loop, and assign data to 2D "U" and "V"
for each level (or modify the RECL and array dimensions).

I hope this helps,
Chuck

Andrea Storto wrote:

> Hi everybody,
> I'm trying to create binary files for GrADS with Fortran:
>
> ...
>       PARAMETER (NDY=16,NDX=116)
> ...
>       REAL U(NDY,NDX)
>       REAL V(NDY,NDX)
> ...
> C  Reading from files:
>
>       do 2 i=1,NDY
>           read(3,*) (U(i,k),k=1,NDX)
>           read(4,*) (V(i,k),k=1,NDX)
> 2     continue
> ...
> C  Writing on standard output to test:
>
>       WRITE (*,*) 'U variables:'
>       WRITE (*,*) ((U(K,L),L=1,NDX),K=1,NDY)
>       WRITE (*,*) '   '
>       WRITE (*,*) 'V variables:'
>       WRITE (*,*) ((V(K,L),L=1,NDX),K=1,NDY)
>
> C  Writing binary files:
>
>       OPEN (7,FILE='uv_uhiX1.dat' ,FORM='UNFORMATTED',
>      &ACCESS='DIRECT',RECL=NDY*NDX)
> C For Linux pgf77 just change the last row in:
> C   &ACCESS='DIRECT',RECL=NDY*NDX*4)
>
>       WRITE (7,REC=1) ((U(K,L),L=1,NDX),K=1,NDY)
>       WRITE (7,REC=2) ((V(K,L),L=1,NDX),K=1,NDY)
>       CLOSE(7)
> ...
>
> and ctl file songs like:
>
>  dset   ^uv_uhiX1.dat
>  title   Prova
>  undef    1e+20
>  xdef          16 linear   1.206897       2.413793
>  ydef         116 linear   1.031250       2.062500
>  zdef      1 levels 0
>  tdef      1 linear 0Z2jan1987 1dy
>  vars      2
>     u 1 33,100 Eastward wind [m/s]
>     v 1 34,100 Northward wind [m/s]
>  endvars
>
> I compiled with Visual Fortran: OK
> Built .exe: OK
> Verified Standard output and file existence: OK
> Tested the same command :
>        OPEN (7,FILE='uv_uhiX1.dat' ,FORM='UNFORMATTED',
>      &ACCESS='DIRECT',RECL=NDY*NDX)
>        WRITE (7,REC=1) ((U(K,L),L=1,NDX),K=1,NDY)
>        WRITE (7,REC=2) ((V(K,L),L=1,NDX),K=1,NDY)
>        CLOSE(7)
> : OK for smaller matrices and manual initialization
> for U and V(!!!)
> Tested ctl structure: OK
> But when I type "open uv_uhiX1.ctl" I get:
>
> Scanning description file:    uv_uhiX1.ctl
> Open Error: Unexpected EOF reading variables
> Was expecting 2 records. Found 0.
>   The data file was not opened.
>
> I don't know why I get this messsage, since I used the same
> fortran code (but initializing variables not from file but in Fortran
> itself!!!).
> Moreover, I can see in standard output correct values for my variables
> (even if some of them have exponential notation, others fixed notation)
> Have you ever had my problem?
> Thank you in advance
>
> Andrea Storto
>


--

********************************************************************
 Charles Seman                                Charles.Seman at noaa.gov
 Geophysical Fluid Dynamics Laboratory / NOAA
 Princeton University                          voice: (609) 452-6547
 P.O. Box 308                                    fax: (609) 987-5063
 Princeton, NJ  08542-0308            http://www.gfdl.noaa.gov/~cjs/
********************************************************************

"The contents of this message are mine personally and do not reflect
any position of the Government or NOAA."

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://gradsusr.org/pipermail/gradsusr/attachments/20050124/11eaeb40/attachment.html 


More information about the gradsusr mailing list