[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[netCDF #IHH-601955]: [netcdfgroup] Allowed characters in variable names?
- Subject: [netCDF #IHH-601955]: [netcdfgroup] Allowed characters in variable names?
- Date: Fri, 13 Aug 2010 13:58:50 -0600
Hi Heiko,
> I'm converting some grib data to netcdf. For variable names, I use the
> shortNames defined in my grib-reader (grib_api), which in some cases
> start with numeric characters, e.g. '2t' or '10u'.
>
> This works well with 3.6.2, but when run on another machine (ubuntu
> lucid, netcdf 3.6.3?), I get an error:
>
> NetCDF: Name contains illegal characters
>
>
> I've seen that some of the variable-name code has been changed in 3.6.3
> for UTF-8:
> http://www.unidata.ucar.edu/software/netcdf/docs/faq.html#fv22 but I
> haven't found out if the first character of a variable must be
> alphabetic (except in a very old user-guide at
> http://www.strw.leidenuniv.nl/~sfinx/netcdf9.html)
The first name of a variable need not be alphabetic, as documented here in
the file format description
http://www.unidata.ucar.edu/netcdf/docs/netcdf.html#File-Format
where it says
Note on names: Earlier versions of the netCDF C-library reference
implementation enforced a more restricted set of characters in
creating new names, but permitted reading names containing arbitrary
bytes. This specification extends the permitted characters in names
to include multi-byte UTF-8 encoded Unicode and additional printing
characters from the US-ASCII alphabet. The first character of a name
must be alphanumeric, a multi-byte UTF-8 character, or '_' (reserved
for special names with meaning to implementations, such as the
“_FillValue” attribute). Subsequent characters may also include
printing special characters, except for '/' which is not allowed in
names. Names that have trailing space characters are also not
permitted.
There is a documentation bug in an earlier section of the same Users Guide,
where it says the first character had to be alphabetic rather than
alphanumeric, but I've just fixed that in the snapshot distribution.
> Are names like '2t' forbidden in netcdf, or is this a bug in 3.6.3, or
> is this a bug in my program, which just propagates to the netcdf error
> message?
A name like '2t' is OK for netCDF (though disallowed by some
conventions, such as the CF conventions). This was a bug in 3.6.3 and
4.0, but fixed in release 4.0.1 and all subsequent releases, including
the current 4.1.1 (note you can get just the netCDF-3 libraris by
specifying the configure option --disable-netcdf-4).
However, there was also a bug in your program, at least with standard
C-89 compilers, where you declared
int dimids[NDIMS]
when NDIMS was defined to be 0, which my compiler objected to:
test$ cc -g -o heiko -I/opt/include heiko.c `nc-config --libs`
"heiko.c", line 25: zero or negative subscript
cc: acomp failed for heiko.c
When I just deleted the unused dimids array and used NULL for the
corresponding argument in the nc_def_var calls, it compiled OK:
if ((retval = nc_def_var(ncid, PRES_NAME, NC_FLOAT, NDIMS,
NULL, &pres_varid)))
ERR(retval);
fprintf(stderr, "success\n");
fprintf(stderr, "try defining 2t ...");
if ((retval = nc_def_var(ncid, TEMP_NAME, NC_FLOAT, NDIMS,
NULL, &temp_varid)))
and also ran OK with the 4.0.1, 4.1.1, and subsequent snapshot libraries:
test$ ./heiko
try defining pressure ...success
try defining 2t ...success
*** SUCCESS writing example file!
--Russ
Russ Rew UCAR Unidata Program
address@hidden http://www.unidata.ucar.edu
Ticket Details
===================
Ticket ID: IHH-601955
Department: Support netCDF
Priority: Normal
Status: Closed