NOAA Logo National Centers for Environmental Information

NOAA Satellite and Information Service

NCEI is transitioning to a new website and paths to data resources will be changing. Please contact NCEI.Info@noaa.gov with any questions of issues. See the new website at www.ncei.noaa.gov.

You are here:Home > GTSPP

NetCDF Components

A netCDF file contains three basic components:

  1. variables,
  2. dimensions, and
  3. attributes.

The variables store the actual data, the dimensions give the relevant dimension information for the variables, and the attributes provide auxiliary information about the variables or the dataset itself.

All components have both a name and an ID number by which they are identified. These components can be used together to capture the meaning of data and relations among data fields in an array-oriented dataset.

Variables
A variable is a multidimensional object that has, among other characteristics, a shape, which is defined by the number, order, and sizes of its dimensions. When a netCDF variable is defined, the number and order of the dimensions that define its shape are specified. Hence you must first create the necessary dimensions before creating a netCDF variable that uses them.
Dimensions
A netCDF dimension has both a name and a size. A dimension is an arbitrary sequence of alphanumeric characters (as well as the underscore character, `_', and the hyphen character, `-') beginning with a letter. Case is distinguished in netCDF names. A dimension size is an arbitrary positive integer, except that one dimension in a netCDF file can have the size UNLIMITED. Such a dimension is called the unlimited dimension or the record dimension. If a variable has an unlimited dimension, that dimension must be the most significant (slowest changing) one. Thus any unlimited dimension must be the first dimension in a CDL shape (and first in C declarations, but last in FORTRAN). The number of dimensions is called the rank (a.k.a. dimensionality).

Uses for netCDF dimensions:

  • Specifying the shapes and sizes of variables

    The basic unit of named data in a netCDF file is a variable. In general, a variable is a multidimensional object that has, among other characteristics, a shape, which is defined by the number, order, and sizes of its dimensions. When a netCDF variable is defined, the number and order of the dimensions that define its shape are specified. Hence you must first create the necessary dimensions before creating a netCDF variable that uses them.

  • Using Dimensions to Relate Variables

    Variables are related by the dimensions they share. For example, if two variables are defined with the same dimensions, they might represent observations or model output for the same set of points. In the example netCDF file, variables temp and rh share the time, lat, and lon dimensions.

  • Providing a Way to Define Coordinate Systems

    create avariable with the same name as a dimension and specify coordinate values for that variable. A variable should only be given the same name as a dimension in a netCDF file when it is to be used as a coordinate variable. Such variables are indexed by the dimension for which they provide coordinate values, for example, latitude(latitude).

Attributes
A netCDF attribute is meant to contain information about a netCDF variable or about an entire netCDF file. This information is ancillary data, or data about data, analogous to the information stored in data dictionaries and schema in conventional database systems An attribute has an associated variable, a name, a data type, a length, and a value. Individual attributes are identified by specifying a variable and an attribute name. Each attribute is associated with a single variable when it is created. A global attribute is one that applies to the whole netCDF rather than any particular variable. Global attributes are defined and accessed similarly to variable attributes. Attribute names follow the same rules as dimension and variable names. Providing meaningful names for attributes is important, but using agreed on conventional names is also required if generic applications and utility programs will be used on a netCDF file. For example, every variable for which units make sense should have a units attribute defined, so the units can be printed in labels. Furthermore, if the netCDF file is ever to be used as input to generic units-aware software, the values of the units attributes should be expressed in a conventional form (see Attribute Conventions) as a character string that can be interpreted by that software.