[Thread Prev][Thread Next][Index]

Re: [ferret_users] CRU ascii file to netcdf



Hi Peter,
During many years of converting ASCII files of gridded data to netCDF, where the ASCII files were not written with Ferret in mind, I have come to the conclusion that the simplest solution (though usually not the most elegant) is best. Ferret likes ASCII data to come in records each of which has the same number of values so I would kick the original file into one or more temporary files each of which is "Ferret friendly". The style of your data makes the creation of the temporary file easy since the data records are already of equal length and since there is no useful info in the 1st, 12th, 25th records other than to indicate the x-y ordering they can be discarded.

Step 1: Make the temporary file
   awk '{if(NR%11 != 1) print $0}' your.file > your_new.file

This excludes all the "lon,lat" header records. In less favorable circumstances I'd write a more complex script or a crude Fortran program to achieve the same purpose and, if the data rows were not of equal length (say the last year had only 8 months) might write only one value per record in the temporary file.

Step 2: Convert the temporary file to netCDF in a Ferret session (noting order of data is t-varying fastest, then y, then x)
   def axis/x=4:258:1 xax ; def axis/y=1:228:1 yax ; def axis/t=1:120:1 tax
   def grid/x=xax/y=yax/t=tax grd
   file/form=free/col=12/g=grd/var=v/ord=tyx your_new.file
   save/file=your_data.nc v

Hope this helps and do check for typos if you use it as I only did a quick check of concept. Perhaps someone else will provide an "elegant" solution.
Mick
--------------

Peter Szabo wrote:
Dear Ferret Users,

Its me, again...
I have data set of CRU 10" in ASCII format like this:
   4   1
 -999 -999 -999 -999 -999 -999 -999 -999 -999 -999 -999 -999
 -999 -999 -999 -999 -999 -999 -999 -999 -999 -999 -999 -999
 -999 -999 -999 -999 -999 -999 -999 -999 -999 -999 -999 -999
 -999 -999 -999 -999 -999 -999 -999 -999 -999 -999 -999 -999
 -999 -999 -999 -999 -999 -999 -999 -999 -999 -999 -999 -999
 -999 -999 -999 -999 -999 -999 -999 -999 -999 -999 -999 -999
 -999 -999 -999 -999 -999 -999 -999 -999 -999 -999 -999 -999
 -999 -999 -999 -999 -999 -999 -999 -999 -999 -999 -999 -999
 -999 -999 -999 -999 -999 -999 -999 -999 -999 -999 -999 -999
 -999 -999 -999 -999 -999 -999 -999 -999 -999 -999 -999 -999
   4   2
 -999 -999 -999 -999 -999 -999 -999 -999 -999 -999 -999 -999
 -999 -999 -999 -999 -999 -999 -999 -999 -999 -999 -999 -999
 -999 -999 -999 -999 -999 -999 -999 -999 -999 -999 -999 -999
 -999 -999 -999 -999 -999 -999 -999 -999 -999 -999 -999 -999
 -999 -999 -999 -999 -999 -999 -999 -999 -999 -999 -999 -999
 -999 -999 -999 -999 -999 -999 -999 -999 -999 -999 -999 -999
 -999 -999 -999 -999 -999 -999 -999 -999 -999 -999 -999 -999
 -999 -999 -999 -999 -999 -999 -999 -999 -999 -999 -999 -999
 -999 -999 -999 -999 -999 -999 -999 -999 -999 -999 -999 -999
 -999 -999 -999 -999 -999 -999 -999 -999 -999 -999 -999 -999
The 1st, 12th, 23th... lines are the coordinate numbers of the data (the longitude goes from 4:258, the latitude goes from 1:228) The "real" first row means a year 1961... The last one 1970. The columns mean months of the year. So 10*12 matrix i have after the grid defining numbers. I would like to make a netcdf of it. Here is how i was trying to solve this problem.

--------------------------
define axis/t=1:120:1/np=120 time
define grid/t=time grid
repeat/range=1:58140:1/name=m (file/ez/var="lon,lat"/skip=`2+11*(m-1)`:`11+11*(m-1)` "myfile" ;\
file/var=pre/skip=`1+11*(m-1)`/columns=12/grid=grid "myfile" ;\
save/file="oåutput.nc <http://output.nc>"/append/clobber/ilimits=1:258/jlimits=1:228/i=`lon`/j=`lat` pre)
----------------------------

Has anyone faced this problem?
Thank You,
Peter Szabo, HMS



[Thread Prev][Thread Next][Index]

Contact Us
Dept of Commerce / NOAA / OAR / PMEL / TMAP

Privacy Policy | Disclaimer | Accessibility Statement