This archive contains answers to questions sent to Unidata support through mid-2025. Note that the archive is no longer being updated. We provide the archive for reference; many of the answers presented here remain technically correct, even if somewhat outdated. For the most up-to-date information on the use of NSF Unidata software and data services, please consult the Software Documentation first.
> Organization: University of Alaska > Keywords: 199408060038.AA13541 netCDF char variables Hi, > I have several variable length character strings to be stored in > non-record variables of a netcdf file. I have seen the syntax for > storing character arrays in record variables but am having difficulty > applying it to variables without dimension dependence. Also, how should > these non record strings be declared in the .cdl file? Sorry to take so long to reply; I was on vacation. There is a section entitled ``Reading and Writing Character String Values'' in the NetCDF User's Guide in the chapter on Variables that provides an explanation and examples of writing character string values in non-record variables. This section also explains why character strings must be modeled as character arrays in netCDF, with the character-position dimension explicit. In particular, this means that character-string valued variables must be of fixed length, and if you don't want to waste space by padding their values, you must use a separate dimension for each character variable. If you can store character values in netCDF attributes instead of netCDF variables, the CDL syntax is much simpler and you don't need to worry about providing explicit lengths or maximum lengths for character strings. Conventionally, character-position dimensions have names that have a ``_len'' of ``Len'' suffix, although this convention is not followed in the examples in the NetCDF User's Guide. There are some examples of netCDF files that use string variables in the pub/netcdf/cdl/ directory on ftp.unidata.ucar.edu, available via anonymous FTP. For example, the `staName' variable in `upperAir.cdl', and the `origin', `model', and `navname' variables in `maps_hybrid_b.cdl' are non-record variables that have character string values. There are many other examples in the same directory. -- Russ Rew UCAR Unidata Program address@hidden P.O. Box 3000 http://www.unidata.ucar.edu/ Boulder, CO 80307-3000