2008 Unidata NetCDF Workshop for Developers and Data Providers > Best Practices
8.4 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.
Recommendations
- Do not use char type for 8-bit numeric data, use byte type
instead.
- Use an attribute in preference to a variable to store a single
string.
- 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
in netCDF-3:
- Fortran: pad with blanks and never terminate with
a zero byte.
- C: pad with zeros and always terminate with a zero
byte.
- To accommodate these variable-length string conventions when reading,
trim zeros and blanks from the end of the char array and
if in C, add a zero byte terminator if needed.
- A common error in using the netCDF-3 C API is assuming char attribute
values are null-terminated.
2008 Unidata NetCDF Workshop for Developers and Data Providers > Best Practices