Re: Grads

From: Adam Phillips <asphilli_at_nyahnyahspammersnyahnyah>
Date: Fri Mar 05 2010 - 16:08:19 MST

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
>

_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Fri Mar 5 16:08:24 2010

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