Re: Grads

From: Dave Allured <dave.allured_at_nyahnyahspammersnyahnyah>
Date: Fri Mar 05 2010 - 17:28:34 MST

Make this easier and more robust by copying the original coordinate
variables, rather than listing them out. One of the new 5.1.1
string functions helps. This assumes that the coordinates are
available to the NCL program. For example:

   lat_strings = sprintf (" %.12g", array&lat)
   ny = dimsizes (lat_strings)
   ctltext(4) = "YDEF " + ny + " LEVELS" + str_concat(lat_strings)

The leading space in the sprintf format spec is important. The 12
is the number of significant digits to keep. I do not know whether
Grads requires short lines. If so, there are simple array methods
to get multiple lines. HTH.

--Dave

Adam Phillips wrote:
> Hi Dave,
> I have had to do this kind of thing in the past.. It's easy enough to
> write out the binary file:
> fbindirwrite("test.bin",array)
>
> The fun part comes in writing the ctl file. To do this, I set up a string
> array, and started filling it in using ctl syntax:
> fbindirwrite(fname+".bin",arr)
> ctltext = new(20,string)
> ctltext(0) = "DSET ^"+fname+".bin"
> ctltext(1) = "TITLE Converted from "+fname+".nc"
> ctltext(2) = "UNDEF 1e20"
> ctltext(3) = "XDEF 1 LINEAR 0.0 1.0"
> ctltext(4) = "YDEF 64 LEVELS -87.8638 -85.09653 -82.31291 -79.5256
> -76.7369 -73.94752"
> ctltext(5) = " -71.15775 -68.36776 -65.57761 -62.78735 -59.99702
> -57.20663"
> ctltext(6) = " -54.4162 -51.62573 -48.83524 -46.04473 -43.2542 -40.46365"
>
> (snip)
>
> ctltext(14) = "ZDEF 21 LEVELS 0 5000 10000 15000 20000 25000 30000
> 35000 40000 45000"
> ctltext(15) = " 50000 55000 60000 65000 70000 75000 80000 85000 90000
> 95000 100000"
> ctltext(16) = "TDEF "+nyr+" LINEAR jan1950 1yr"
> ctltext(17) = "VARS 1"
> ctltext(18) = "streamfun 21 99 streamfunction"
> ctltext(19) = "ENDVARS"
> asciiwrite(fname+".ctl",ctltext)
>
> Make sure you test out your new binary/ctl files in GrADS to make sure
> that you everything is as it should be...
>
> Finally, beware of any endian issues with binary file creation/usage.. If
> your model runs on the same machine that the binary file is created on, no
> problem. But if you want to write the binary file on a little endian
> machine (say, a linux box) and your model resides on an IBM supercomputer
> (big-endian), you will have to use NCL's endian switching capabilities.
> They can be found here:
> http://www.ncl.ucar.edu/Applications/r-binary.shtml
>
> Good luck,
> Adam
>
>> Hello everyone. I have a strange request.
>>
>> I am using a model that accepts grads .grd and control (.ctl) files as
>> inputs. Does anyone have a suggestion how I might use NCL to write my SST
>> anomalies to .grd/.ctl files?
>>
>> Thank you very much.
>>
>> Dave Small
>>
>> --
>> David Small
>> Graduate Research Assistant
>> Department of Atmospheric and Oceanic Sciences
>> McGill University
>> Montreal, Quebec, Canada
_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Fri Mar 5 17:28:44 2010

This archive was generated by hypermail 2.1.8 : Mon Mar 08 2010 - 12:07:42 MST