Next: , Previous: nc_insert_enum, Up: User Defined Data Types


5.32 Learn About a Enum Type: nc_inq_enum

Get information about a user-define enumeration type.

Usage

     nc_inq_enum(int ncid, nc_type xtype, char *name, nc_type *base_nc_typep,
                 size_t *base_sizep, size_t *num_membersp);
ncid
The group ID of the group which holds the enum type.
xtype
The typeid for this enum type, as returned by nc_def_enum, or nc_inq_var.
name
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.
base_nc_typep
If non-NULL, a pointer to a nc_type, which will get the base integer type of this enum.
base_sizep
If non-NULL, a size_t pointer, which will get the size (in bytes) of the base integer type of this enum.
num_membersp
If non-NULL, a size_t pointer which will get the number of members defined for this enumeration type.

Errors

NC_NOERR
No error.
NC_EBADTYPEID
Bad type id.
NC_EHDFERR
An error was reported by the HDF5 layer.

Example

This example is from libsrc4/tst_enums.c, and is a continuation of the example above for nc_insert_enum. First an enum type is created, with one element for each of the nine members of the Brady family on a popular American television show which occupies far too much memory space in my brain!

In the example, the enum type is created, then checked using the nc_inq_enum and nc_inq_enum_member functions. See nc_inq_enum_member.

           char brady_name[NUM_BRADYS][NC_MAX_NAME + 1] = {"Mike", "Carol", "Greg", "Marsha",
                                                            "Peter", "Jan", "Bobby", "Whats-her-face",
                                                            "Alice"};
           unsigned char brady_value[NUM_BRADYS] = {0, 1,2,3,4,5,6,7,8};
           unsigned char data[BRADY_DIM_LEN] = {0, 4, 8};
           unsigned char value_in;
     
           /* Create a file. */
           if (nc_create(FILE_NAME, NC_NETCDF4, &ncid)) ERR;
     
           /* Create an enum type based on unsigned bytes. */
           if (nc_def_enum(ncid, NC_UBYTE, BRADYS, &typeid)) ERR;
           for (i = 0; i < NUM_BRADYS; i++)
              if (nc_insert_enum(ncid, typeid, brady_name[i],
                                 &brady_value[i])) ERR;
     
           /* Check it out. */
           if (nc_inq_enum(ncid, typeid, name_in, &base_nc_type, &base_size_in, &num_members)) ERR;
           if (strcmp(name_in, BRADYS) || base_nc_type != NC_UBYTE || base_size_in != 1 ||
               num_members != NUM_BRADYS) ERR;
           for (i = 0; i < NUM_BRADYS; i++)
           {
              if (nc_inq_enum_member(ncid, typeid, i, name_in, &value_in)) ERR;
              if (strcmp(name_in, brady_name[i]) || value_in != brady_value[i]) ERR;
              if (nc_inq_enum_ident(ncid, typeid, brady_value[i], name_in)) ERR;
              if (strcmp(name_in, brady_name[i])) ERR;
           }