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.
Hi Mike, > In the netCDF docs, I see the following: > > 2.1.1 Naming Conventions > > The names of dimensions, variables and attributes consist of arbitrary > sequences of alphanumeric characters (as well as underscore '_' and > hyphen '-'), beginning with a letter or underscore. (However names > commencing with underscore are reserved for system use.) Case is > significant in netCDF names. > > Could you please expand on what you mean by 'However names commencing > with underscore are reserved for system use'? If I name a variable > starting with underscore, will it work as normal? We reserved names beginning with an underscore for system use, because we needed a namespace that wouldn't clash with user names. Up until now, we have only used this namespace for special attributes, including "_FillValue", "_Unsigned", and the special virtual attributes supported by ncdump and ncgen4 for netCDF-4 variable characteristics, such as "_Fletcher32", "_ChunkSizes", "_Endianness", "_DeflateLevel", "_Shuffle", "_Storage", and "_NoFill", and the global attribute "_Format". In the future we have plans for other special attributes, including "_Scale" and "_Offset". We have so far not used any reserved names for variables, but may want to do so in the future, and might at some point enforce the restriction by not permitting new names beginning with "_" in order to prevent future clashes. However that would only be for creating new names. The netCDF library has always allowed reading names containing arbitrary characters, so if such files were created in the past, they will always be readable. Another consideration is whether you want your files to comply with the CF Conventions. The current version 1.4 of CF requires: Variable, dimension and attribute names should begin with a letter and be composed of letters, digits, and underscores. Note that this is in conformance with the COARDS conventions, but is more restrictive than the netCDF interface which allows use of the hyphen character. The netCDF interface also allows leading underscores in names, but the NUG states that this is reserved for system use. so strictly speaking, a file containing a variable beginning with an underscore that does not have special meaning in the library is not CF-compliant. If you want to transform names from one namespace to names that are guaranteed not to clash with names in another namespace, one way to do it is to just prefix the names with the namespace followed by underscore, i.e. "varname" gets mapped to "NCAR_varname", for example, to use an NCAR namespace. If you don't care about CF compliance, you could use the ":" character instead, so "varname" would map to "NCAR:varname", which would display in the CDL produced by ncdump and parsed by ncgen as "NCAR\:varname". I hope this helps to clarify why we reserve leading "_" in names ... --Russ Russ Rew UCAR Unidata Program address@hidden http://www.unidata.ucar.edu Ticket Details =================== Ticket ID: YZQ-382018 Department: Support netCDF Priority: Normal Status: Closed