[Thread Prev][Thread Next][Index]

Re: how to create netcdf from ascii files



Hi Enils,
	To let Ferret do it for you you should
1) define your grid x,y,x,t
2) read in the ascii data making sure that the order is correct
3) use ferret's list/file=... command to write the data to netcdf

1) Define your grid
I'll assume the data is at the surface z=0, was collected on 1-jan-2003
and has 1 degree spacing in latitude and longitude. Ferret's normal order
is longitude increasing from west to east and longitude from south to
north so the data in your file does not need to be reversed.

def axis/x=80w:72w:1/units=longitude xax
def axis/y=36n:40n:1/units=latitude yax
def axis/z=0:0:1/units=meters zax
def axis/t="1-jan-2003:00:00":"1-jan-2003:00:00":1/units=days tax
def grid/x=xax/y=yax/z=zax/t=tax grd

The z and t axes are optional for this dataset it would appear but it
does not hurt to add them if appropriate to document the file. But if
you really don't want them you would use
def grid/x=xax/y=yax grd

2) Read in the data from file data.ascii . I'll assume that the data
order is Longitude varying fastest, then Latitude with NO HEADER RECORDS
and with free formatted data with one record for each grid point
	temp, salinity, dop, doc, ph, turbidity, chlorophyll
Another assumption is that data records for the ENTIRE GRID are present.
If there were missing points in the grid (for example points over land)
there would need to be "missing value" records in the appropriate
places in the data file.  Suppose there were and you had used 999.9 as
the missing value code for all locations. Then read in the data using

file/form=free/var=temp,sal,dop,doc,ph,turb,chl/g=grd/ord=xyzt data.ascii
set var/title="Temperature"/bad=999.9 temp
set var/title="Salinity"/bad=999.9 sal
...
set var/title="Chlorophyll"/bad=999.9 chl

Notice that "short names" have been assigned to all variables.  These
are the ones that you would use to access the data if you were to reread
the netCDF file we will create back into ferret.  The "long names"
supplied in the title="..." are the names you would like to appear along
the axis in graphics.  Also note the "/g=grd" option.  This and the
"/order=..." are key to reading in the data in the correct order into
the grid that was defined in step 2. (If the data file were arranged with
latitude varying fastest you would use /ord=yx...)

3) save the data in the netcdf file data.nc as follows

save/file=data.nc temp,sal,dop,doc,ph,turb,chl

Hope this helps,
Good luck,
Mick
PS I just tested the above commands on part of your data example. All
went well but one thing to point out is that the netCDF file stored
the longitudes in the east-longitude convention.
 XAX = 280, 281, 282 ;




[Thread Prev][Thread Next][Index]

Dept of Commerce / NOAA / OAR / PMEL / TMAP

Contact Us | Privacy Policy | Disclaimer | Accessibility Statement