5.31 Learn the Name of a Enum Type: nc_inq_enum_member
Get information about a member of an enum type.
Usage
int nc_inq_enum_member(int ncid, nc_type xtype, int idx, char *name,
void *value);
ncid- The groupid where this enum type exists.
xtype- The typeid for this enum type.
idx- The zero-based index number for the member of interest.
name- If non-NULL, a pointer to an already allocated char array which will
get the name, as a null terminated string. It will have a maximum
length of NC_MAX_NAME+1.
value- If non-NULL, a pointer to storage of the correct integer type
(i.e. the base type of this enum type). It will get the value
associated with this member.
Errors
NC_NOERR- No error.
NC_EBADTYPEID- Bad type id.
NC_EHDFERR- An error was reported by the HDF5 layer.
Example
This is the continuation of the example in nc_def_enum. The file
is reopened and the cloud enum type is examined.
/* Reopen the file. */
if (nc_open(FILE_NAME, NC_NOWRITE, &ncid)) ERR;
if (nc_inq_user_type(ncid, typeid, name_in, &base_size_in, &base_nc_type_in,
&nfields_in, &class_in)) ERR;
if (strcmp(name_in, TYPE2_NAME) ||
base_size_in != sizeof(unsigned char) ||
base_nc_type_in != NC_UBYTE ||
nfields_in != num_members ||
class_in != NC_ENUM) ERR;
if (nc_inq_enum(ncid, typeid, name_in,
&base_nc_type_in, &base_size_in, &num_members_in)) ERR;
if (strcmp(name_in, TYPE2_NAME) ||
base_nc_type_in != NC_UBYTE ||
num_members_in != num_members) ERR;
for (i = 0; i < num_members; i++)
{
if (nc_inq_enum_member(ncid, typeid, i, name_in, &value_in)) ERR;
if (strcmp(name_in, cloud_types[i].name) ||
value_in != cloud_types[i].value) ERR;
if (nc_inq_enum_ident(ncid, typeid, cloud_types[i].value,
name_in)) ERR;
if (strcmp(name_in, cloud_types[i].name)) ERR;
}
if (nc_inq_varid(ncid, VAR2_NAME, &varid)) ERR;
if (nc_get_att(ncid, varid, ATT2_NAME, &value_in)) ERR;
if (value_in != MISSING) ERR;
if(nc_get_var(ncid, varid, cloud_data_in)) ERR;
for (i = 0; i < DIM2_LEN; i++) {
if (cloud_data_in[i] != cloud_data[i]) ERR;
}
if (nc_close(ncid)) ERR;