Output txt specific format

Arlindo da Silva dasilva at ALUM.MIT.EDU
Thu Feb 14 14:04:35 EST 2008


Ranyere,

  As an alternative, here is how you would do his using PyGrADS:

---------------------------------------------------------------------------------------------------
import grads
ga = grads.GaNum(Bin='gradsnc',Echo=False,Window=False)  # start grads
fh = ga.open("../data/model.nc")              # open file
ts = ga.exp('ts')                             # export a variable to python
print "   Lon     Lat      Ts"
print "-------- -------- --------"
for j in range(fh.ny):
    for i in range(fh.nx):
        print "%8.3f %8.3f %8.2f"%(ts.grid.lon[i],ts.grid.lat[j],ts[j,i])
----------------------------------------------------------------------------------------------------------
which produces:

  Lon     Lat      Ts
-------- -------- --------
   0.000  -90.000   258.49
   5.000  -90.000   258.49
  10.000  -90.000   258.49
  15.000  -90.000   258.49
  20.000  -90.000   258.49
  25.000  -90.000   258.49
  ...
 230.000  -18.000   300.49
 235.000  -18.000   299.99
 240.000  -18.000   299.49
 245.000  -18.000   298.99
...

An equivalent script using the Perl interface would be very similar, since
the methods open() and exp() are also available there.

   Arlindo

--
Arlindo da Silva
dasilva at alum.mit.edu
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://gradsusr.org/pipermail/gradsusr/attachments/20080214/9d7c93f8/attachment.html 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: print_ascii.py
Type: application/octet-stream
Size: 557 bytes
Desc: not available
Url : http://gradsusr.org/pipermail/gradsusr/attachments/20080214/9d7c93f8/attachment.obj 


More information about the gradsusr mailing list