7.6 Strings and Character Variables
Use character data properly for representing text strings.
The classic data model does not have a primitive string
type with variable-length strings, only arrays of type char.
- Do not use char type for 8-bit numeric data, use byte type
- Use an attribute in preference to a variable to store a single
- Use a multidimensional char array for arrays of strings.
In netCDF-3, all of these strings must be the same length.
- Various conventions are used for writing variable length string data
- Fortran: pad with blanks and never terminate with
a zero byte.
- C: pad with zeros and always terminate with a zero
- To accommodate these variable-length string conventions when reading,
trim zeros and blanks from the end of the char array and
if C, add a zero byte terminator when reading character attribute value.
- A common error in using the netCDF-3 C API is assuming char attribute
values are null-terminated in the netCDF file.