Go to the previous, next section.
A variable represents a multidimensional array of values of the same type. A variable has a name, a data type, and a shape described by its list of dimensions, all of which are specified when the variable is created. Each variable may also have data values and associated attributes, which may be added or changed after the variable is created. Variables are used to store the bulk of the data in a netCDF file, and are the primary component used by utilities to identify sub-parts of a netCDF file.
Like a dimension name, a variable name is an arbitrary sequence of alphanumeric characters (also including `_' and `-') beginning with a letter. Case is distinguished in variable names. Long names help to make a netCDF file self-documenting, but ancillary information about a variable is better stored in variable attributes (discussed below) than encoded as part of the name.
A variable data type is one of a small set of netCDF types that
have the names NC_BYTE
, NC_CHAR
, NC_SHORT
,
NC_LONG
, NC_FLOAT
, and NC_DOUBLE
in the C interface
and the corresponding names NCBYTE
, NCCHAR
, NCSHORT
,
NCLONG
, NCFLOAT
, and NCDOUBLE
in the
FORTRAN interface. In the CDL notation, these types are given the
simpler names byte
, char
, short
, long
,
float
, and double
. int
may be used as a synonym
for long
and real
may be used as a synonym for
float
in the CDL notation. We will postpone a discussion of the
exact meaning of each of the types until the discussion of data,
below. For now, it suffices to know that the choice of the type used to
represent variable data depends on the range of values it can have, the
precision to which values are known, and the number of bits required to
represent the variable in a netCDF file on disk.
The shape of a variable is specified by its list of dimensions. If a variable has an unlimited dimension, that dimension must appear first in the list of dimensions in CDL. It is possible to define variables with no dimensions, also called scalar variables. There are no scalar variables in the example netCDF file.
CDL variable declarations appear after the variables
keyword in
a CDL unit. They have the form
type variable_name ( dim_name_1, dim_name_2, ... ) ;for variables with dimensions, or
type variable_name ;for scalar variables.
In the CDL example there are six variables. As discussed above, four of
these are coordinate variables for dimensions. The remaining variables,
temp
and rh
, contain what is usually thought of as the
data. Each of these variables has the unlimited dimension time
as its first dimension, so they are called record variables. A
variable that is not a record variable has a fixed size (number of data
values) given by the product of its dimensions. A record variable has a
current size, given by the product of the maximum record written so far
and the other dimensions of the variable. Only record variables may
grow after they are defined.
Go to the previous, next section.