
If you use fwrite, the data set created is already in GrADS format,
and no conversion program is needed.  Lets say you wanted to write
out 12 times into an output file:

    set x 1 144
    set y 1 73
    set lev 500
    set t 1 12
    set gxout fwrite
    set fwrite z500.dat
    d z

Since three dimensions are varying, GrADS will 'loop' through time
by default.  Each display will output a single grid that is 144 by 73
(2.5x2.5 degrees lat-lon).  After this, either quit out of GrADs, or
issue the command"

    disable fwrite

to close the output file.  YOu will then need a GrADS descriptor file
for the data set:

    dset z500.dat
    title ....
    undef ....
    xdef 144 linear 0 2.5
    ydef 144 linear -90 2.5
    zdef 1 linear 500 1
    tdef 12 linear ....
    vars 1
    z500  0 99 500mb Heights
    endvars

If you have the descriptor file already created, you can create the
data set from a script, close the fwrite data set, and open the
descriptor file without ever leaving GrADS.

When using fwrite, it is VERY important to remember the data written
is the *RESULT* of whatever expression is entered, and is the size
that is a result of the current dimension environment.  So if you want
to be absolutely sure of what data you are getting, always specify the
dimension environment using 'set x' and 'set y
rather than 'set lon' or 'set lat' -- since these can result in
rouding outwards during the data access, and the result can be more
data points than expected.... Brian

Dear Lin,

>
> And I tried to save these output by "set gxout fwrite" for further
> processing.  I thought the output should be a 41*51 array of data
> type REAL.  However, it was not recognized.
>
>
> Does anybody know how I can access the output by oacres ...?
>


        As I understand it, when you "fwrite" a GrADS display grads
writes the output just as it reads it from a GrADs data file (in binary,
unformatted, etc...).  That way, you can then just write a descriptor
file to read the "grads.fwrite" file created by the fwrite display...

        So, to then READ the data from the "grads.fwrite" file in say
FORTRAN code (I'm assuming you're using some sort of code to rewrite
the GrADS output to IDL format) - you must use the same open statement
that you would use to write GrADS data (for FORTRAN, you need access='direct'
form='unformatted', recl=[your record length] in your open statement)

        and then to read the data from the fwrite file you use:

read (file_unit#,rec=recordnumber) variable

        where,
                file_unit# = the unit # specified in open statement
                recordnumber = integer specifying record number in fwrite file
                                (say if you output a time series)
                variable = dimensioned variable according to grid dimensions
                           of oacres output (and yes, here it could be a
                           variable of type REAL).


        Well, hope this helps...

        Cheers,
        Adam


Hello GrADS Users:

I thought it might be useful to point out a couple of things to be
careful of when using fwrite...

1.  Beware of wrapping longitudes:
When you open a global data file, GrADS will try to wrap the longitudes
if it can.  That is, if your data has 144 longitudes varying from
0 to 357.5, GrADS will set the longitude dimension to be varying from
0 to 360.0 (or X varying from 1 145).  This works great if you are
plotting contours, but can lead to confusion if you are writing out the
data with fwrite.  If you write out the data using fwrite under the
above circumstances, you will get 145 longitudes--when you may expect
only 144.  This will cause problems if you try to read in the data in
specifying only 144 longitudes.  You need to 'set x 1 144' before
writing out the data with fwrite in order to get the data in the same
format as the original file you opened.

2.  Set your dimensions with x,y,z,t:
When writing binary data from GrADS, it is best to set your dimensions
with the x,y,z,and t indices instead of lon,lat,lev,and time.  Also, as
Mike F. has pointed out, use 'q dims' to double check your current
dimension environment before writing your data to disk.
--

> Hi,
>
> I have a little problem with global assimilation data files. I only need the
> data between -50 < longitude < 50 and -35 < latitude < 35. Because I am not
> very familiar with FORTRAN my question is whether there is a possibility in
> GrADS to reduce a global data file by selecting the right data (right
> latitude and longitude area) and throwing the rest away.
>
> It would give me lots of more free disk space.
>
> Thanks,
>
> Gerald
> Wageningen Agricultural University
> The Netherlands
>
With "set gxout fwrite" you can write the data in the current 4-dimensions
to a file instead of displaying the data.  Then you write a new control
file with the correct dimension of the written data and you are set.

An example:
Say your data file contain just 1 variable "u" on 5 levels at 3 time steps on
a 2x3 deg grid starting at greenwich and -90.
Then do the following:

ga-> set lon -50 50
ga-> set lat -35 35
ga-> set z 1 5
ga-> set t 1 3
ga-> set gxout fwrite
ga-> set fwrite newdatafile.gad
ga-> q dim
ga-> d u
ga-> disable fwrite
ga-> set gxout contour

In the new control-file you update:

dset ^newdatafile.gad
xdef 51 linear -50 2
ydef 21 linear -30 3

N.B.:
1)If you have more that 1 variable in the data-file you may have to write
  a script and loop through levels and time.
2) It may be better to specify lon and lat in grid dimension than as lon and
 lat.
  this way it's easier to control the location of the output grid.
  The above "q dim" shows the exact grid location of the written data.

I hope this helps.

Matt


