creating a txt file using grads

Alex Fierro iwonagain at GMAIL.COM
Mon Jan 14 18:03:43 EST 2008


Hi Jeff:

Thank you very much for your quick reply:

I actually had to write a VI (shell) script AND a FORTRAN program to be able
to output the data from 100's GRADS binaries in one large ascii (text) file
.

What I have are massive NETCDF files which contain time series of zonal
(meridional wind in another *.nc file) winds at a resolution of 1.5 deg for
the whole globe. I was asked to extract this data for a given time period
from a smaller box (lets say a grid covering the entire Pacific).

I wrote a GRADS script which output binaries having time series of the zonal
wind at each lat lon (at 1.5 resolution) point within that box (needless to
say there are 100's of these files). I use FORTRAN to later read in each of
these files in sequence and output the data in a huge ascii file in column
format.

For smaller grids, however, I was curious to know if using the command
"fwrite" in a script, there would be an easy way (e.g., a special flag) to
get that time series from the NETCDF file in txt instead of binary.

The method you showed is more complicate that I thought and makes use of
commands like subwrd or subline or 'q w2gr 130 0' that I am not familiar
with. I remember using subwrd once to extract some values and realized it
was quite a "pain".

I would be very interested to know if there would a quick and elegant way as
easy as this (a loop made for binaries):

sdfopen data.nc'
'set gxout fwrite'
'set fwrite -le test.bin'
ii=0
while(ii<=10000)
ii=ii+1
say ' 'ii
'set t 'ii
'set lat a'
'set lon a'
'd v'
endwhile
'disable fwrite'
'close 1'

I wish one could just replace the *.bin by *.txt and change a flag in the
fwrite command line. Does such command exist ?

Cheers and thank you very much again for your detailed explanation,

Alex-




On Jan 14, 2008 3:15 PM, JEFFREY S GALL <jsg229 at psu.edu> wrote:

> Alex,
>
> Its a little confusing, but here is how I do it at least using the
> following steps  (Im
> creating this on the fly as I go, so if there are problems let me know).
> If anyone has a more efficient way of writing text files in grads, could
> they please pass it on because it would be very useful for me as well.
>
> STEPS:
>
> 1.  define the box of data you would like to output to a text file.  For
> example, suppose you
> want to print out the values of 850 mb zonal wind at each grid point
> between a lat-lon
> box bounded by 0-10 deg N and 130-150 deg lon.
>
> 2.  open your filename:
>
> 'open example.ctl'
>
> 3.  Do:  'set lev 850'
>               'set t 1'
>
> Now only the x and y dimensions should be varying
>
> 4.  get the lower gridpoint values:
>
> 'q w2gr 130 0'  where 0 is min lat and 130 is min lon
> rec = sublin(result,1)
>   x1 = subwrd(rec,3)
>   y1 = subwrd(rec,6)
>
> Here, x1 and y1 are your lower bounds.
>
> 5.  Now, get the upper bounds:
> 'q w2gr 150 10'
> rec = sublin(result,1)
>   x2 = subwrd(rec,3)
>   y2 = subwrd(rec,6)
>
> 6.  modify x1 x2 y1 y2 such that they are integers within your box:
> x1=(math_int(x1))+1
> y1=(math_int(y1))+1
> x2=math_int(x2)
> y2=math_int(y2)
>
>
> 7.  Now loop from x1 to x2 and y1 to y2
>
> i=x1
> j=y1
> while(i<=x2)
> while(j<=y2)
>
> 'set x 'i
> 'set y 'j
> 'd u'
> rec = sublin(result,1)
> val=subwrd(rec,5)
>
> say "val is:    "i"   "j"    "val
> filename=test.txt
>
> 8.  the write command writest to a txt file
>
> write(filename,i"    "j"     "val)
>
> 'c'
> j=j+1
> endwhile
> j=y1
> i=i+1
> endwhile
>
> That should be it.  The output will write to a file called test.txt.  This
> is the general way I do it at least.  If you have anymore questions let me
> know.
>
> Jeff
>



--
-------------------------------------------------------------
Alexandre Fierro
PhD
School of Meteorology University of Oklahoma /
National Severe Storms Laboratory (NOAA)

"When a man sits with a pretty girl for an hour, it seems like a minute.
But let him sit on a hot stove for a minute, and its longer than any hour.
That's relativity."
                              -Albert Einstein-
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://gradsusr.org/pipermail/gradsusr/attachments/20080114/6997cf9b/attachment.html 


More information about the gradsusr mailing list