fwrite (Resolved - Read for details)

Mark Sponsler msponsler at COMCAST.NET
Mon Oct 17 19:11:47 EDT 2005


Thanks again for all your help.  I made an intersting yet simple discovery along the way to solving this problem...

** Variables written out using fwrite MUST be read back into Grads in the exact same order. **

For example:

set fwrite grads.fwrite
set gxout fwrite
d var1
d var2
disable fwrite

The ctl file to read the data back into grads must list the variables in the exact same order they are written out (e.g.):
.....
vars 2
var1  0 107,1,1  ** var1 [deg]
var2  0 100,1,1  ** var2 [m]
ENDVARS

If the order ir reversed (i.e var2, var1)  you'll be reading degrees for meters or visa versa.

Thanks again,
Mark

-------------- Original message --------------

> The "options yrev" should not be used. Even though your original file has x
> and y reversed, fwrite writes the data from grads arrays so everything is in
> the order grads expects. I don't think that would give you the results you
> report, though. The grid should just be skewed around since you are reading
> rows and columns in the wrong order. The little endian may be a problem.
> If you are writing and reading the files on the same machine, you don't need
> to specify the endian type. Again, fwrite uses the expected format for the
> machine you are on. Since you only have two variables with one time and
> level, there isn't much more that could be wrong.
>
> > -----Original Message-----
> > From: Mark Sponsler [mailto:msponsler at COMCAST.NET]
> > Sent: Monday, October 17, 2005 2:42 PM
> > To: GRADSUSR at LIST.CINECA.IT
> > Subject: fwrite (again)
> >
> >
> > Sorry to be so bothersome but I have another simple question
> > that I could
> > not answer after reviewing the documentation.
> >
> > When using the fwrite defaults, it streams the data to a
> > binary file for
> > eventualy re-ingestion into GRADS. Is some level of fortran
> > manipulation
> > of the fwrite output required before it can be re-read by Grads?
> >
> > I ask because I was able to manually generate a control file
> > and get Grads
> > to read the file producing some results, but the data is way off
> > (Significant Wave Heights are all too high and and Direction
> > is set to 180
> > degrees for all grib points).
> >
> > Here's my modified control file:
> >
> > dset grads.fwrite
> > undef 9.999E+20
> > options little_endian
> > options yrev
> > ydef 157 linear -78.000000 1
> > xdef 288 linear 0.000000 1.250000
> > tdef 1 linear 18Z12nov2004 03hr
> > zdef 1 linear 1 1
> > vars 2
> > DIRPWsfc 0 107,1,1 ** surface Primary wave direction [deg]
> > HTSGWsfc 0 100,1,1 ** surface Sig height of wind waves and swell [m]
> > ENDVARS
> >
> > Here's the control file for original dataset that fwrite used as it's
> > source:
> >
> > dset nww3.all.grb
> > index nww3.all.grb.idx
> > undef 9.999E+20
> > title nww3.all.grb
> > * produced by grib2ctl v0.9.12.5p33e
> > dtype grib 233
> > options yrev
> > ydef 157 linear -78.000000 1
> > xdef 288 linear 0.000000 1.250000
> > tdef 61 linear 18Z12nov2004 03hr
> > zdef 1 linear 1 1
> > vars 11
> > DIRPWsfc 0 107,1,1 ** surface Primary wave direction [deg]
> > DIRSWsfc 0 109,1,1 ** surface Secondary wave direction [deg]
> > HTSGWsfc 0 100,1,1 ** surface Sig height of wind waves and swell [m]
> > PERPWsfc 0 108,1,1 ** surface Primary wave mean period [s]
> > PERSWsfc 0 110,1,1 ** surface Secondary wave mean period [s]
> > UGRDsfc 0 33,1,1 ** surface u wind [m/s]
> > VGRDsfc 0 34,1,1 ** surface v wind [m/s]
> > WDIRsfc 0 31,1,1 ** surface Wind direction [deg]
> > WINDsfc 0 32,1,1 ** surface Wind speed [m/s]
> > WVDIRsfc 0 101,1,1 ** surface Direction of wind waves [deg]
> > WVPERsfc 0 103,1,1 ** surface Mean period of wind waves [s]
> > ENDVARS
> >
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://gradsusr.org/pipermail/gradsusr/attachments/20051017/1da733e8/attachment.html 


More information about the gradsusr mailing list