Again, fwrite problem

Charles Seman Charles.Seman at NOAA.GOV
Thu Mar 31 18:04:49 EST 2005


Dear Mark,

Have you tried an unformatted read, like this:

open(21,file='grads.fwrite',status='old',form='unformatted',recl=41*32)
do t=1,tt
do k=1,L
  inum=k+(t-1)*L
  read(21,rec=inum) data2d
  do j=1,32
  do i=1,41
    data(i,j,k) = data2d(i,j)
  enddo
  enddo
enddo
enddo

with a defined 2D array "data2d(41,32)"?

Also, you may want to try specifying the RECL in bytes... see, for example:
http://docs.sun.com/source/819-0491/2_io.html
(the above web site was found using Google with search words: Fortran +
read + recl)

I hope this helps,
Chuck


Mark Wang wrote:

>Hi all
>I am trying to deal with the MM5v3 output data through GrADSv1.8SL11.
>The MM5v3 programs are on Linux, and GrADS and Fortran77 are on DEC.
>First, I can correctly use fwrite to convert MM5v3 data to GrADS output.
>(Compare with MM5toGrADS and self-writing GrADS ctl files.)
>But when I try to write a Fortran77 program to read the GrADS output,
>I met a problem.
>
>The xdef of self-writing ctl is:
>xdef  41 linear 121.989  0.2027
>ydef  32 linear  24.9028 0.2027
>
>After execute GrADS, and open that ctl file.
>The result of q dims is:
>X is varying   Lon = 121.989 to 130.097   X = 1.00003 to 41.0001
>Y is varying   Lat = 24.9028 to 31.1865   Y = 1.00001 to 32
>
>Then I write a gs file,to fwrite variables without set any x or y dimension.
>'open model_all.ctl'
>'set fwrite model_all.bin'
>tt=1
>while(tt<=25)
> 'set gxout fwrite';'set t 'tt
> level=1
> while(level<=20)
>  'd h(z='level')'
> level=level+1
> endwhile
>tt=tt+1
>endwhile
>'disable fwrite'
>
>The message of fwrite is:
>Wrote 1312 elements to grads.fwrite as Stream Little_Endian
>
>The Fortran77 program is:
>open(21,file='grads.fwrite',status='old',form='unformatted',recl=41*32)
>do t=1,tt
> do k=1,L
>  inum=k+(t-1)*L
>  read(21,rec=inum) ((data(i,j,k),i=1,41),j=1,32)
> enddo
>enddo
>
>The program of Fortran77 is correct.
>But when I execute the program, some kinds of errors happen:
>forrtl: Not a typewriter
>forrtl: severe(39): error during read, unit 21, file grads.fwrite
>
>If the variables, times of fwrite data increase, the error become:
>forrtl: Bad file number
>forrtl: severe(39): error during read, unit 21, file grads.fwrite
>
>All of these errors happen at the end of grads.fwrite file.
>Could anyone help me solving this problem?
>Thank you very much!
>
>Mark
>
>

--

********************************************************************
 Charles Seman                                Charles.Seman at noaa.gov
 U.S. Department of Commerce / NOAA / OAR
 Geophysical Fluid Dynamics Laboratory         voice: (609) 452-6547
 201 Forrestal Road                              fax: (609) 987-5063
 Princeton, NJ  08542                 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."



More information about the gradsusr mailing list