Please, I would like to confirm that the behavior that I observe is intended and not a bug.
I am interested in how enumerations are managed when they are defined in a ncML and afterwards a netCDF file is created from there.
Shortly:
When I define an enumeration, using enhance="all", an associated variable becomes a string (not an enumeration anymore), and I can write any value into it, not only those values defined in the enumeration. Is this intended or a bug?
This behavior looks different than the netCDF-C library approach. The netCDF-C library always manages the integer value and giving the responsibility of doing the conversion to strings to the user/programmer. From the netCDF-C documentation:
Enums are based on any integer types.
The underlying integer type is what is stored in the file.
When using ConvertEnums enhance mode, Variables of type enum are promoted to String types and data is automatically converted using the EnumTypedef objectss, which are maps of the stored integer values to String values.
Ok, I understand, but I was expecting that albeit the variable becomes a netCDF string, the set of values for the variable would be limited to the enumeration mapping. And this is not the case. Let me give an example:
Note that ssd is a variable of string data type. Ok, as described in the tutorial.
But I am surprised when now I could populate the ssd variable with any data. For example, using Python I could write "wrong" in the variable (!), although that is not one of the allowed values in the enumeration (500m, 1km, 2km).
Please, I would like to confirm that the behavior that I observe is intended and not a bug.
I am interested in how enumerations are managed when they are defined in a ncML and afterwards a netCDF file is created from there.
Shortly:
When I define an enumeration, using
enhance="all"
, an associated variable becomes astring
(not anenumeration
anymore), and I can write any value into it, not only those values defined in the enumeration. Is this intended or a bug?This behavior looks different than the netCDF-C library approach. The netCDF-C library always manages the integer value and giving the responsibility of doing the conversion to strings to the user/programmer. From the netCDF-C documentation:
Long explanation:
Following the NetcdfDataset Tutorial (enhance):
Ok, I understand, but I was expecting that albeit the variable becomes a netCDF string, the set of values for the variable would be limited to the enumeration mapping. And this is not the case. Let me give an example:
I created the following ncML:
Note that I use the
enhance="all"
ncML attribute, and thatssd
is a variable of thessd_type
enumeration data type.I create a netCDF file using the netCDF-Java library (note: a preview of v5):
java -Xmx1g -classpath netcdfAll-5.0.0-20180211.132322-244.jar ucar.nc2.write.Nccopy --input test.ncml --output test.nc --format netcdf4
The output netCDF file that I get is this (using
ncdump
):Note that
ssd
is a variable ofstring
data type. Ok, as described in the tutorial.But I am surprised when now I could populate the
ssd
variable with any data. For example, using Python I could write "wrong" in the variable (!), although that is not one of the allowed values in the enumeration (500m, 1km, 2km).And now the output from
ncdump
is:An enumerated variable becomes a string and therefore it accepts any value. Please, is this the intended behavior or a bug?