5.4 Learn About an User Defined Type: nc_inq_user_type
Given an ncid and a typeid, get the information about a user defined
type. This function will work on any user defined type, whether
compound, opaque, enumeration, or variable length array.
Usage
nc_inq_user_type(int ncid, nc_type xtype, char *name, size_t *sizep,
nc_type *base_nc_typep, size_t *nfieldsp, int *classp);
ncid- The ncid for the group containing the user defined type.
xtype- The typeid for this type, as returned by nc_def_compound,
nc_def_opaque, nc_def_enum, nc_def_vlen, or nc_inq_var.
name- If non-NULL, the name of the user defined type will be copied here. It
will be NC_MAX_NAME bytes or less.
sizep- If non-NULL, the size of the user defined type will be copied here.
base_nc_typep- If non-NULL, the base typeid will be copied here for vlen and enum
types.
nfieldsp- If non-NULL, the number of fields will be copied here for enum and
compound types.
classp- Return the class of the user defined type, NC_VLEN, NC_OPAQUE,
NC_ENUM, or NC_COMPOUND.
Errors
NC_NOERR- No error.
NC_EBADTYPEID- Bad typeid.
NC_EBADFIELDID- Bad fieldid.
NC_EHDFERR- An error was reported by the HDF5 layer.
Example
/* Create a file. */
if (nc_create(FILE_NAME, NC_NETCDF4, &ncid)) ERR;
/* Create an enum type. */
if (nc_def_enum(ncid, NC_INT, TYPE_NAME, &typeid)) ERR;
for (i = 0; i < NUM_MEMBERS; i++)
if (nc_insert_enum(ncid, typeid, member_name[i],
&member_value[i])) ERR;
/* Check it out. */
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, TYPE_NAME) || base_size_in != sizeof(int) ||
base_nc_type_in != NC_INT || nfields_in != NUM_MEMBERS || class_in != NC_ENUM) ERR;