[gradsusr] Fortran to Read in GrADS Binary File

Lydia Rill lydia.d.rill at gmail.com
Tue Jul 5 09:57:01 EDT 2016


Hi all,

I am a new grads user and I have never worked with binary files before. I
have a large binary file I created in grads (code shown below). I want to
split up the binary file by latitude and longitude degree into smaller
binary files. While this is possible in GrADS, it is too slow for my needs,
so I am trying to do it in Fortran 90.

However, I am having problems reading the GrADS binary file in Fortran. It
gives me the missing value for each of my variables at every time step and
every location.

The binary file contains NLDAS 2 forcing data, with 464 x steps, 224 y
steps, and 13688 daily time steps for 4 variables (only 1 Z level). It is a
large file at 22GB, and I can successfully display the variables in GrADS
from this binary file. This binary file was created from data in Grib files.

I have tried many various ways of reading in the binary data, using x and y
loops, or time loops, or looping through the 4 variables, but nothing has
been successful.

I am working on a Mac (El Capitan).

Here is the GrADS script I used to create the binary file:

function main(args)

counthr=subwrd(args,1)

'reinit'

'open /Volumes/WebData/NLDAS2/ProcessingFiles/24hours.ctl'

'set undef 9.999e20'

'set gxout fwrite'

'set fwrite -ap /Volumes/WebData/NLDAS2/DailyNLDAS/daily.bin'


'set t 1'

t1=1+4

t1p=1+5

while(t1<=counthr+5-23)

t2=t1+23

t2p=t1p+23

'd (max(TMP2m,t='t1',t='t2')-273.15)'

'd (min(TMP2m,t='t1',t='t2')-273.15)'

'd sum(APCPsfc,t='t1p',t='t2p')'

'd (ave(DSWRFsfc,t='t1',t='t2')*24*3600/1000000)'

t1=t1+24

t1p=t1p+24

endwhile

'quit'

Here is the Fortran script to read the binary file

Program Readbin

implicit none

integer irec,i,j,t,days

real tmin(464,224),tmax(464,224),prcp(464,224),srad(464,224)

OPEN(17,file='/Volumes/WebData/NLDAS2/DailyNLDAS/daily.bin',&

&STATUS='Old',FORM='UNFORMATTED',ACCESS='DIRECT',RECL=464*224*4)


OPEN(18,file='/Volumes/WebData/NLDAS2/DailyNLDAS/testdaily.bin',&

&STATUS='UNKNOWN',FORM='UNFORMATTED',ACCESS='DIRECT',RECL=464*224*4)

days=10

irec=1

do t=1,days

     read(17,REC=irec) ((tmax(i,j),i=1,8),j=1,8)

     read(17,REC=irec+1) ((tmin(i,j),i=1,8),j=1,8)

     read(17,REC=irec+2) ((prcp(i,j),i=1,8),j=1,8)

     read(17,REC=irec+3) ((srad(i,j),i=1,8),j=1,8)

     write(18,REC=irec) ((tmin(i,j),i=1,8),j=1,8)

     write(18,REC=irec+1) ((tmin(i,j),i=1,8),j=1,8)

     write(18,REC=irec+2) ((prcp(i,j),i=1,8),j=1,8)

     write(18,REC=irec+3) ((srad(i,j),i=1,8),j=1,8)

     irec=irec+4

enddo

end program

The corresponding control file is:

set ^testdaily.bin

undef 9.999E+20

title Daily NLDAS2 Data for 00Z through 23Z

xdef 8 linear -124.9375 0.125

ydef 8 linear 25.0625 0.125

tdef 10 linear 00Z02Jan1979 1dy

zdef 1 linear 1 1

vars 4

TMAX 0 12,105,2 ** maximum temperature at 2m above surface [C]

TMIN 0 11,105,2 ** minimum temperature at 2m above surface [C]

PRCP 0 61,1,0 ** total precipitation backward accumulated [kg/m^2 or mm]

SRAD 0 204,1,0 ** total surface downward shortwave radiation flux [mJ/m^2]

ENDVARS


Thanks,

Lydia

-- 
Lydia D. Rill
M.S., Michigan State University 2016
B.S., Valparaiso University 2014
(224) 406-5130
Lydia.D.Rill at gmail.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://gradsusr.org/pipermail/gradsusr/attachments/20160705/9f8bada6/attachment-0001.html 


More information about the gradsusr mailing list