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


5.3 Find a Typeid from Group and Name: nc_inq_typeid

Given a group ID and a type name, find the ID of the type. If the type is not found in the group, then the parents are searched. If still not found, the entire file is searched.

Usage

     int nc_inq_typeid(int ncid, const char *name, nc_type *typeidp);
ncid
The group id.
name
The name of a type.
typeidp
A pointer to an int which will get the typeid.

Errors

NC_NOERR
No error.
NC_EBADID
Bad ncid.
NC_EBADTYPE
Can't find type.

Example

The following example is from the test program libsrc4/tst_vars.c. It tests that the correct names are given for atomic types.

     	 /* Check inquire of atomic types */
     	 if (nc_inq_type(ncid, NC_BYTE, name_in, &size_in)) ERR;
     	 if (strcmp(name_in, "byte") || size_in != sizeof(char)) ERR;
     	 if (nc_inq_type(ncid, NC_CHAR, name_in, &size_in)) ERR;
     	 if (strcmp(name_in, "char") || size_in != sizeof(char)) ERR;
     	 if (nc_inq_type(ncid, NC_SHORT, name_in, &size_in)) ERR;
     	 if (strcmp(name_in, "short") || size_in != sizeof(short)) ERR;
     	 if (nc_inq_type(ncid, NC_INT, name_in, &size_in)) ERR;
     	 if (strcmp(name_in, "int") || size_in != sizeof(int)) ERR;
     	 if (nc_inq_type(ncid, NC_FLOAT, name_in, &size_in)) ERR;
     	 if (strcmp(name_in, "float") || size_in != sizeof(float)) ERR;
     	 if (nc_inq_type(ncid, NC_DOUBLE, name_in, &size_in)) ERR;
     	 if (strcmp(name_in, "double") || size_in != sizeof(double)) ERR;
     	 if (nc_inq_type(ncid, NC_UBYTE, name_in, &size_in)) ERR;
     	 if (strcmp(name_in, "ubyte") || size_in != sizeof(unsigned char)) ERR;
     	 if (nc_inq_type(ncid, NC_USHORT, name_in, &size_in)) ERR;
     	 if (strcmp(name_in, "ushort") || size_in != sizeof(unsigned short)) ERR;
     	 if (nc_inq_type(ncid, NC_UINT, name_in, &size_in)) ERR;
     	 if (strcmp(name_in, "uint") || size_in != sizeof(unsigned int)) ERR;
     	 if (nc_inq_type(ncid, NC_INT64, name_in, &size_in)) ERR;
     	 if (strcmp(name_in, "int64") || size_in != sizeof(long long)) ERR;
     	 if (nc_inq_type(ncid, NC_UINT64, name_in, &size_in)) ERR;
     	 if (strcmp(name_in, "uint64") || size_in != sizeof(unsigned long long)) ERR;
     	 if (nc_inq_type(ncid, NC_STRING, name_in, &size_in)) ERR;
     	 if (strcmp(name_in, "string") || size_in != 0) ERR;
     	 if (xtype_in != NC_SHORT) ERR;