2011 Unidata NetCDF Workshop > The Two NetCDF Data Models
4.13 Variables Versus Attributes
When should you use variables or attributes?
Both netCDF variables and attributes are named, typed containers for
values. This leads to the question, when is it appropriate to 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 attributes
- shape specified with netCDF dimensions
- variables are read 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
- attributes are read when file is opened
2011 Unidata NetCDF Workshop > The Two NetCDF Data Models