creating a txt file using grads

JEFFREY S GALL jsg229 at PSU.EDU
Mon Jan 14 17:15:05 EST 2008


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


-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://gradsusr.org/pipermail/gradsusr/attachments/20080114/e02ac32a/attachment.html 


More information about the gradsusr mailing list