Introduction
NetCDF-4 is the version of NetCDF, from Unidata, that stores its data in an HDF5 file. It arrived with NetCDF 4.0 and brings HDF5’s features to NetCDF: compressed and chunked variables, groups inside groups, user-defined and string types, and more than one unlimited dimension.
Because it is HDF5 underneath, HDF5 tools can open a NetCDF-4 file too, though they show its internal conventions rather than the NetCDF view. A restricted form, the NetCDF-4 classic model, uses the HDF5 file but only the features of the classic format, so programs written for the classic format can still read it. See all the NetCDF variations.
Structure
The file is an ordinary HDF5 file and starts with the HDF5 signature
89 48 44 46 0D 0A 1A 0A. NetCDF groups are HDF5 groups and NetCDF
variables are HDF5 datasets, with their attributes stored as HDF5 attributes.
Dimensions are stored as HDF5 dimension scales, attached to the datasets that use them.
Recent versions of the library record the NetCDF and HDF5 versions that wrote the file in
a hidden attribute, _NCProperties, on the root group.
Telling .NC files apart
Read the first four bytes. The HDF5 signature 89 48 44 46 means this
format. CDF followed by 01, 02 or 05
means a classic NetCDF file.
Not described
The reference follows the NetCDF-4 part of Unidata's file format specification.
Known, not yet covered
- Reference: NCZarr's Zarr version 3 support (an appendix that the NCZarr page read for this reference does not contain) and the Blosc2 and other registered filters beyond those named on the mapping page, which now covers the Zstandard, Blosc, bzip2 and quantisation attributes and NCZarr.
- Viewer: the viewer reads a NetCDF-4 file through the HDF5 viewer and presents it as NetCDF: the
groups, the dimensions (HDF5 dimension scales, with
_Netcdf4Dimid, the marker name of a dimension that has no coordinate variable, and the unlimited ones), the variables with their NetCDF type (the HDF5 datatype mapping of the format description), their dimensions (DIMENSION_LIST, checked againstREFERENCE_LISTand the lengths of the scales), phony dimensions for a dataset with no scales,_nc4_non_coord_, the attributes the NetCDF API shows and the ones it hides (_NCPropertiesread as the two library versions,_nc3_strictas the classic model with its rules checked), and the user-defined types. The HDF5 tree and tables stay beneath, and the Values table is the HDF5 one for the chosen variable. - Viewer: the chunks of variables stored with filters are not decoded when the file is opened. A chunk is decoded when the values of its variable are read; a filter error or a wrong Fletcher-32 checksum found then joins the Problems list, marked as found when that variable was opened, and the Overview’s counts do not change.
- Viewer: not done for a NetCDF-4 variable: a plot, the CF conventions (fill values and
valid_range,scale_factorandadd_offset, dates, flags, cell methods, climatology and grid mappings, which the classic viewer reads), and values shown as NetCDF types (they are HDF5 values, so a vlen or a compound shows as HDF5 text). The format description’s requirement that every group and dataset set link and attribute creation order is not checked, the HDF5 features it says NetCDF-4 does not use (non-hierarchical groups, multiple links to an object, stored property lists, the date/time type, attributes on user-defined types) are not all flagged, and the_Netcdf4Coordinateslist of a multi-dimensional coordinate variable is checked against the dimension IDs but not used for plotting. The namephony_dim_Nis the viewer’s label: the format description gives no name for a phony dimension. Without_Netcdf4Dimidthe dimension IDs follow the order in which the file lists the scales, which is the viewer’s reading, not stated in the description.
Variants
- NetCDF classic – the original layout: a CDF header of dimensions and variables, then the arrays
- NetCDF-4 – NetCDF data stored in an HDF5 file, with compression, chunks and groups
Links
Software
- Panoply – NASA’s free viewer that plots gridded data on maps (Windows, macOS, Linux)
- NetCDF utilities – Unidata’s
ncdump,ncgenandnccopycommand-line tools - HDFView – The HDF Group’s browser, which shows the HDF5 structure underneath (Windows, macOS, Linux)
Developers
Reference
- NetCDF file format specifications – Unidata’s specification, including how NetCDF-4 uses HDF5