Go to the previous, next section.

Parts of a NetCDF File

A netCDF data set is stored as a single file comprising three parts:

All the data are represented in XDR form to make them machine-independent.

The descriptive header at the beginning of the netCDF file is an XDR encoding of a high-level data structure that represents information about the dimensions, variables, and attributes in the file. The variable descriptions in this header contain offsets to the beginning of each variable's data or the relative offset of a variable within a record. The descriptions also contain the dimension size and information needed to determine how to map multidimensional indices for each variable to the appropriate offsets.

This header has no usable extra space; it is only as large as it needs to be for the dimensions, variables, and attributes in each netCDF file. This has the advantage that netCDF files are compact, requiring very little overhead to store the ancillary data that makes the files self-describing. A potential disadvantage of this organization is that any operation on a netCDF file that requires expanding the header, for example adding a set of new dimensions and new variables to an existing netCDF file, will be as expensive as copying the file. This expense is incurred when ncendef() is called, after a call to ncredef(). If you create all necessary dimensions, variables, and attributes before writing variable data, and avoid later additions and renamings of netCDF components that require more space in the header part of the file, you avoid the cost associated with expanding the header.

The fixed-size data part that follows the header contains all the variable data for variables that do not employ the unlimited (record) dimension. The data for each variable is stored contiguously in this part of the file. If there is no unlimited dimension, this is the last part of the netCDF file.

The record-data part that follows the fixed-size data consists of a variable number of records, each of which contains data for all the record variables. The record data for each variable is stored contiguously in each record.

The order in which the data in the fixed-size data part and in each record appears is the same as the order in which the variables were defined, in increasing numerical order by netCDF variable ID. This knowledge can sometimes be used to enhance data access performance, since the best data access is currently achieved by reading or writing the data in sequential order.

Go to the previous, next section.