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


5.4 Learn About a User Defined Type: nc_inq_type

Given an ncid and a typeid, get the information about a type. This function will work on any type, including atomic and any user defined type, whether compound, opaque, enumeration, or variable length array.

For even more information about a user defined type nc_inq_user_type.

Usage

     nc_inq_type(int ncid, nc_type xtype, char *name, size_t *sizep);
ncid
The ncid for the group containing the type (ignored for atomic types).
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, or as found in netcdf.h in the list of atomic types (NC_CHAR, NC_INT, etc.).
name
If non-NULL, the name of the user defined type will be copied here. It will be NC_MAX_NAME bytes or less. For atomic types, the type name from CDL will be given.
sizep
If non-NULL, the (in-memory) size of the type in bytes will be copied here. VLEN type size is the size of nc_vlen_t. String size is returned as the size of a character pointer. The size may be used to malloc space for the data, no matter what the type.

Return Codes

NC_NOERR
No error.
NC_EBADTYPEID
Bad typeid.
NC_ENOTNC4
Seeking a user-defined type in a netCDF-3 file.
NC_ESTRICTNC3
Seeking a user-defined type in a netCDF-4 file for which classic model has been turned on.
NC_EBADGRPID
Bad group ID in ncid.
NC_EBADID
Type ID not found.
NC_EHDFERR
An error was reported by the HDF5 layer.

Example

This example is from the test program tst_enums.c, and it uses all the possible inquiry functions on an enum type.

           /* Check it out. */
           if (nc_inq_user_type(ncid, typeids[0], 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;
           if (nc_inq_type(ncid, typeids[0], name_in, &base_size_in)) ERR;
           if (strcmp(name_in, TYPE_NAME) || base_size_in != sizeof(int)) ERR;
           if (nc_inq_enum(ncid, typeids[0], name_in, &base_nc_type, &base_size_in, &num_members)) ERR;
           if (strcmp(name_in, TYPE_NAME) || base_nc_type != NC_INT || num_members != 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, member_name[i]) || value_in != member_value[i]) ERR;
              if (nc_inq_enum_ident(ncid, typeid, member_value[i], name_in)) ERR;
              if (strcmp(name_in, member_name[i])) ERR;
           }
     
           if (nc_close(ncid)) ERR;