Unidata - To provide the data services, tools, and cyberinfrastructure leadership that advance Earth system science, enhance educational opportunities, and broaden participation. Unidata
         
  advanced  
 

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



5.3 Learn About an 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 size of the type (in bytes) will be copied here. VLEN type size is the size of one element of the VLEN. String size is returned as zero, since it varies from string to string.

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;
 
 
  Contact Us     Site Map     Search     Terms and Conditions     Privacy Policy     Participation Policy
 
National Science Foundation (NSF) UCAR Office of Programs University Corporation for Atmospheric Research (UCAR)   Unidata is a member of the UCAR Office of Programs, is managed by the University Corporation for Atmospheric Research, and is sponsored by the National Science Foundation.
P.O. Box 3000     Boulder, CO 80307-3000 USA     Tel: 303-497-8643     Fax: 303-497-8690