Personal tools
You are here: Home Documentation Users Guide 10. Converting to NetCDF 10.2 SIMPLE CONVERSIONS USING FERRET
Document Actions

10.2 SIMPLE CONVERSIONS USING FERRET

In straightforward conversion operations where ASCII or unformatted binary data files are already readable by Ferret, the conversion to direct access, self-describing netCDF formatted data can be accomplished by Ferret itself. The following set of examples illustrates these procedures:

Example 1

Consider an ASCII file uv.data, with two variables, u and v, defined on a grid 360 by 180. The following set of commands will properly read in u and v and convert them to a netCDF formatted data set:

yes? DEFINE AXIS/x=1:360:1/units=degrees xaxis
yes? DEFINE AXIS/y=1:180:1/units=degrees yaxis
yes? DEFINE GRID/x=xaxis/y=yaxis uv_grid
yes? FILE/GRID=uv_grid/BAD=-999/VAR="u,v" uv.data
yes? SET VARIABLE/TITLE="zonal velocity" u
yes? SAVE/FILE=uv.cdf u,v

See command DEFINE AXIS in the Commands Reference. See the chapter "Grids and Regions" for setting up formatted latitude, longitude and time axes.

Example 2

Consider now two separate ASCII files, u.data and v.data, defined on a grid 360 by 180. The following set of commands will properly read in u and v and convert them to a single netCDF formatted data set:

yes? DEF AXIS/x=1:360:1/units=degrees xaxis
yes? DEF AXIS/y=1:180:1/units=degrees yaxis
yes? DEF GRID/x=xaxis/y=yaxis uv_grid
yes? FILE/GRID=uv_grid/BAD=-999/VAR=u u.data
yes? FILE/GRID=uv_grid/BAD=-999/VAR=v v.data
yes? SAVE/FILE=uv2.cdf u[D=1]
yes? SAVE/APPEND/FILE=uv2.cdf v[D=2]

Example 3—multiple time steps

Consider 12 ASCII files, uv.data1 to uv.data12, each defined on the same grid as above but each representing a successive time step. The following set of commands illustrates how to save these data into a single netCDF data set (time series):

yes? DEF AXIS/x=1:360:1 xaxis
yes? DEF AXIS/y=1:180:1 yaxis
yes? DEF AXIS/t=1:1:1 taxis1
yes? DEF GRID/x=xaxis/y=yaxis/t=taxis1 uv_grid1
yes? FILE/GRID=uv_grid1/BAD=-999/VAR="u,v" uv.data1
yes? SAVE/FILE=uv1_12t.cdf u,v
yes? CANCEL DATA uv.data1
yes? DEF AXIS/t=2:2:1 taxis1
yes? FILE/GRID=uv_grid1/BAD=-999/VAR="u,v" uv.data2
yes? SAVE/APPEND/FILE=uv1_12t.cdf u,v
. . .

and so on, redefining the time axis to be 3:3:1, 4:4:1, ... each time a new file is set.

When the input data is in netCDF files, please see the following FAQ on using data from a set of input files. Note particularly the example showing how to add time information to the variable when the grid of the input data has no time axis.

FAQ: How can I use data as a time series when it exists in multiple files?

Example 4—multiple slabs

The procedure used in example 3, above, is possible because netCDF files can be extended along the time axis. In order to append multiple levels (Z axis), the netCDF file must first be created including all of its vertical levels (the levels initially are filled with a missing data flag).

Consider 5 ASCII files, uv.data1 to uv.data5, each defined on the same grid as above but each representing a successive vertical level. Note that the output grid has an axis containing all the Z levels that the file will contain (and that the other Z axes, zaxis1, zaxis2, ... are defined only for the purpose of reading the data in). The following set of commands illustrates how to save these data into a single netCDF data set:

yes? DEF AXIS/x=1:360:1 xaxis
yes? DEF AXIS/y=1:180:1 yaxis
yes? DEF AXIS/Z=0:100:25/DEPTH zaxis
yes? DEF GRID/X=xaxis/Y=yaxis/Z=zaxis uv_grid
yes? DEF AXIS/Z=0:0:1 zaxis1
yes? DEF GRID/LIKE=uv_grid/Z=zaxis1 uv_grid1

yes? FILE/GRID=uv_grid1/BAD=-999/VAR="u,v" uv.data1
yes? LET/TITLE="My U data" u1 = u[G=uv_grid]
yes? LET/TITLE="My V data" v1 = v[G=uv_grid]
yes? SAVE/FILE=uv1_5z.cdf/KLIMITS=1:5/K=1 u1, v1

yes? CANCEL DATA uv.data1
yes? DEF AXIS/Z=25:25:1 zaxis1
yes? FILE/GRID=uv_grid1/BAD=-999/VAR="u,v" uv.data2
yes? SAVE/FILE=uv1_5z.cdf/K=2/APPEND u1,v1
. . .
yes? CANCEL DATA/ALL ! Cancel definitions before using new file
yes? CANCEL VAR/ALL
yes? USE uv1_5z.cdf

The netCDF utilities "ncdump" and "ncgen" can also be combined with a text editor to make final refinements to the netCDF files created by SAVE. (These utilities can be obtained from http://www.unidata.ucar.edu/ . See  http://www.unidata.ucar.edu/downloads/netcdf ). Here is a simple example that removes all "history" attributes from a netCDF file using pipes and the Unix "grep" utility:

% ncdump old_file.cdf | grep -v history | ncgen -o new_file.cdf

In addition, the toolset "NetCDF Operator", or NCO, contains a number of operators for manipulating netCDF files. This software can be found at http://nco.sourceforge.net/



Powered by Plone CMS, the Open Source Content Management System

This site conforms to the following standards: