Go to the previous, next section.
We will use a small netCDF example to illustrate the concepts of netCDF dimensions, variables, and attributes. The notation used to describe this simple netCDF object is called CDL (network Common Data form Language). It provides an easily comprehended text version of the structure and contents of a binary netCDF file:
netcdf example_1 { // example of CDL notation for a netCDF file
dimensions: // dimension names and sizes are declared first
lat = 5, lon = 10, level = 4, time = unlimited;
variables: // variable types, names, shapes, attributes
float temp(time,level,lat,lon);
temp:long_name = "temperature";
temp:units = "celsius";
float rh(time,lat,lon);
rh:long_name = "relative humidity";
rh:valid_range = 0.0, 1.0; // min and max
int lat(lat), lon(lon), level(level);
lat:units = "degrees_north";
lon:units = "degrees_east";
level:units = "millibars";
short time(time);
time:units = "hours since 1990-11-25 12:00 UTC";
// global attributes
:source = "National Weather Service";
data: // optional data assignments
level = 1000, 850, 700, 500;
lat = 20, 30, 40, 50, 60;
lon = -160,-140,-118,-96,-84,-52,-45,-35,-25,-15;
time = 12;
rh =.5,.2,.4,.2,.3,.2,.4,.5,.6,.7,
.1,.3,.1,.1,.1,.1,.5,.7,.8,.8,
.1,.2,.2,.2,.2,.5,.7,.8,.9,.9,
.1,.2,.3,.3,.3,.3,.7,.8,.9,.9,
0,.1,.2,.4,.4,.4,.4,.7,.9,.9;
}
The CDL notation for a netCDF file can be generated automatically by
using ncdump, a utility program described later (see section ncdump).
Another netCDF utility, ncgen, generates a netCDF file (or
optionally C or FORTRAN source code containing calls needed to produce a
netCDF file) from CDL input (see section ncgen). It is not necessary to
learn much about CDL notation to use the netCDF library; we use it in
this document as a concise way of presenting netCDF examples.
The CDL notation will be explained more fully as we describe the components of a netCDF file. For now, note that CDL statements are terminated by a semicolon. Spaces, tabs, and newlines can be used freely for readability. Comments in CDL follow the characters `//' on any line. A CDL description of a netCDF file takes the form
netCDF name {
dimensions: ...
variables: ...
data: ...
}
where the name is used only as a default in constructing the name
of the file generated by the ncgen utility. The CDL description
consists of three optional parts, introduced by the keywords
dimensions, variables, and data. NetCDF dimension
declarations appear after the dimensions keyword, netCDF
variables and attributes are defined after the variables keyword,
and variable data assignments appear after the data keyword.
Go to the previous, next section.