2012 Unidata NetCDF Workshop > The NetCDF Classic Data Model
5.11 Variables Versus Attributes
When should you use variables or attributes?
Both netCDF variables and attributes are named, typed containers for
values. When should you use a
netCDF attribute instead of a netCDF variable to hold a value?
Characteristics of variables:
- intended for data
- can hold arrays too large for memory
- may be multidimensional
- support partial access (only a subset of values)
- values may be changed, more data may be appended
- may have attached attributes, e.g for units
- have shape specified with netCDF dimensions
- read from file when user asks for data
Characteristics of attributes:
- intended for metadata, information about entire variable or dataset
- used for small units of information that fit in memory
- for single values, strings, or small 1-D arrays
- atomic access, must be written or read all at once
- values typically don't change after creation
- an attribute may not have attributes
- length specified when created
- read when file is opened
2012 Unidata NetCDF Workshop > The NetCDF Classic Data Model