UNAVCO IDV: Making NetCDF 3D Grids for the IDV UNAVCO IDV: Making NetCDF 3D Grids for the IDV (was The GIAG Format ASCII format)

The IDV uses NetCDF format (binary) files for gridded data. There are many ways to make NetCDF files. Read about NetCDF for the GEON IDV and read Using the NetCDF Data Format for 2D and 3D grids, and Seismic Tomography.

This web page was about making netCDF files by means of an intermediate ASCII format, called GIAG. Now this page describes making netCDF files in a more direct way which is faster, easier, and far less error-prone.

You will need the program ncgen to make netCDF files from ".cdl" files. See Unidata NetCDF.

This example is to make 3D grid files of M latitudes and N longitudes, at D depths. The latitude-longitude grid is the same for all depth levels.

Nested grids of differing resolutions do not work. Grids of irregular latitude-longitude values do not work. There may be ways to make NetCDF files for such grids.

This demo .cdl file is like what you want to make. Use that file as an example.

First create a new file, with a name ending in extension .cdl, beginning with a header section something like this:

netcdf Demo_NetCDF_CDL_file {
//  You can add comments like this.
The name "Demo_NetCDF_CDL_file" can be most anything.

You can add a comment; this may be useful in case you have more than one data set.

dimensions:
        lon = 99 ;
        lat = 99 ;
        depth = 10 ;
variables:
   float lat(lat) ;
       lat:long_name = "latitude" ;
       lat:units = "degrees_north" ;
   float lon(lon) ;
       lon:long_name = "longitude" ;
       lon:units = "degrees_east" ;
   float depth(depth) ;
       depth:units = "kilometer" ;
       depth:positive = "down" ;
   float Pv(depth, lon, lat) ;
        Pv:long_name = "P wave velocity" ;
        Pv:missing_value = "-99.0" ;
        Pv:units = " km s-1" ;

Give the count of longitudes and latitudes in each grid, and how many depth values, as shown in

   lon = 99 ;
   lat = 99 ;
   depth = 10 ;

The 'variables" section can remain as shown in the demo file. You can change: the units of depth, to meters for example; the name of the dependent variable, Pv in the demo; and the units of the dependent variable.

Next in the .cdl file is the data section, with coordinate values:

data:

 lat = 42.0, 42.051000, 42.10099, 42.152000, 42.20199, 42.253, 42.30299, 42.35399, 42.404000, 42.45499, 42.505000, 42.55599, 42.606000, 42.65699, 42.707000, 42.758000, 42.  808, 42.859000,
... ;

 lon = -111.0, -110.929, -110.8589, -110.788, -110.717, -110.646, -110.5759, -110.505, -110.434, -110.364, -110.2930, -110.2219, -110.152, -110.081, -110.0100, -109.9389, - 109.869, -109.798,
... ;

 depth = 0.0, 10.0, 15.0, 20.0, 25.0, 30.0, 35.0, 40.0, 45.0, 50.0 ;

Do not omit the

data: 

Each line of values must end with ";".

Each line has a 1D array of coordinate values. (some values are omitted above). In this case there must be 99 values in both the lat = and lon = rows, and 10 values in the depth = row.

Increasing values may not be necessary, but are typical and will work. Do otherwise if you want to experiment.

Finally comes the values of the dependent variable:

 Pv = ..., 6.4649999, 6.4569999, 6.45600004, 6.46300001, 6.476, 6.4889999, 6.49500001, 6.49399, 6.49099997, 6.48599, 6.  47900001, 6.468, 6.452, 6.43299, 6.41099996, 6.3879999, 6.367, 6.35200003, 6.34900002, 6.3639999, 6.39799997, 6.43499996, 6.45399997, 6.44500003, 6.40800004, 6.37800001, 6. 38499, 6.41000001, 6.42699996, 6.44200002, 6.46, 6.47799, 6.49099997, 6.49800002, -99.0, -99.0, -99.0, -99.0, -99.0, -99.0,
...;

There must be exactly 99 * 99 * 10 values in this line in this case, and accordingly in your case.

The order of values in the line are by fastest changing coordinate, in this case, in the order (depth, lon, lat).

The order of the independent variables (depth, lon, lat), must be correct in the 'float Pv' line at top. It specifies the order of changing values in the 1D array for Pv. If the order is wrong the data may display in the IDV but in the wrong location or wrong depth; some very weird results may occur.

The .cld file ends with this line:

}

Convert the .cdl file 'my_cdl_file.cdl' to NetCDF using ncgen with the command

ncgen -o my_netcdf_file.nc my_cdl_file.cdl


The UNAVCO web page NetCDF Data Format has a list of "Variable names for the IDV" that the IDV recognizes for special plots, such as focal mechanisms. These variable names, such as ve and eps2, should be used in the ASCII files as the "short name" where appropriate.