Hi Jeff:<br><br>Thank you very much for your quick reply:<br><br>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 .
<br><br>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).
<br><br>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.
<br><br>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.
<br><br>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".
<br><br>I would be very interested to know if there would a quick and elegant way as easy as this (a loop made for binaries):<br><br>sdfopen <a href="http://data.nc">data.nc</a>'<br>'set gxout fwrite'<br>'set fwrite -le
test.bin'<br>ii=0<br>while(ii<=10000)<br>ii=ii+1<br>say ' 'ii<br>'set t 'ii<br>'set lat a'<br>'set lon a'<br>'d v'<br>endwhile<br>'disable fwrite'<br>'close 1'
<br><br>I wish one could just replace the *.bin by *.txt and change a flag in the fwrite command line. Does such command exist ?<br><br>Cheers and thank you very much again for your detailed explanation,<br><br>Alex-<br><br>
<br><br><br><div class="gmail_quote">On Jan 14, 2008 3:15 PM, JEFFREY S GALL <<a href="mailto:jsg229@psu.edu">jsg229@psu.edu</a>> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Alex,<br>
<br>
Its a little confusing, but here is how I do it at least using the following
steps (Im <br>
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. <br><br>STEPS:<br>
<br>
1. define the box of data you would like to output to a text file.
For example, suppose you <br>
want to print out the values of 850 mb zonal wind at each grid point between a
lat-lon <br>
box bounded by 0-10 deg N and 130-150 deg lon.<br>
<br>
2. open your filename:<br>
<br>
'open example.ctl'<br>
<br>
3. Do: 'set lev 850'<br>
'set t 1'<br>
<br>
Now only the x and y dimensions should be varying<br>
<br>4. get the lower gridpoint values:<br>
<br>
'q w2gr 130 0' where 0 is min lat and 130 is min lon<br>
rec = sublin(result,1)<br>
x1 = subwrd(rec,3)<br>
y1 = subwrd(rec,6)<br>
<br>
Here, x1 and y1 are your lower bounds.<br>
<br>5. Now, get the upper bounds:<br>
'q w2gr 150 10'<br>
rec = sublin(result,1)<br>
x2 = subwrd(rec,3)<br>
y2 = subwrd(rec,6)<br>
<br>6. modify x1 x2 y1 y2 such that they are integers within your
box:<br>x1=(math_int(x1))+1<br>y1=(math_int(y1))+1<br>x2=math_int(x2)<br>y2=math_int(y2)<br><br><br>7. Now loop from x1 to x2 and y1 to y2<br>
<br>
i=x1<br>
j=y1<br>
while(i<=x2)<br>
while(j<=y2)<br>
<br>
'set x 'i<br>
'set y 'j<br>
'd u'<br>
rec = sublin(result,1)<br>
val=subwrd(rec,5)<br>
<br>
say "val is: "i" "j" "val<br>
filename=test.txt<br>
<br>8. the write command writest to a txt file<br><br>write(filename,i" "j" "val)<br>
<br>
'c'<br>
j=j+1<br>
endwhile<br>
j=y1<br>
i=i+1<br>
endwhile<br>
<br>
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.<br><br>Jeff<br>
</blockquote></div><br><br clear="all"><br>-- <br>-------------------------------------------------------------<br>Alexandre Fierro<br>PhD<br>School of Meteorology University of Oklahoma / <br>National Severe Storms Laboratory (NOAA)
<br><br>"When a man sits with a pretty girl for an hour, it seems like a minute.<br> But let him sit on a hot stove for a minute, and its longer than any hour. <br>That's relativity."
<br> -Albert Einstein-