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>