Get the number of fields, len, and name of a compound type.
int nc_inq_compound(int ncid, nc_type xtype, char *name, size_t *sizep, size_t *nfieldsp);
ncid
xtype
name
sizep
nfieldsp
NC_NOERR
NC_EBADID
NC_ENOTNC4
NC_ESTRICTNC3
NC_EBADTYPE
NC_EBADTYPEID
NC_EHDFERR
The following example is from the test program libsrc4/tst_compounds.c. See also the example for See nc_insert_array_compound.
#define BATTLES_WITH_KLINGONS "Number_of_Battles_with_Klingons" #define DATES_WITH_ALIENS "Dates_with_Alien_Hotties" struct s1 { int i1; int i2; }; /* Create a file with a compound type. */ if (nc_create(FILE_NAME, NC_NETCDF4, &ncid)) ERR; if (nc_def_compound(ncid, sizeof(struct s1), SVC_REC, &typeid)) ERR; if (nc_inq_compound(ncid, typeid, name, &size, &nfields)) ERR; if (nfields) ERR; if (nc_insert_compound(ncid, typeid, BATTLES_WITH_KLINGONS, HOFFSET(struct s1, i1), NC_INT)) ERR; if (nc_insert_compound(ncid, typeid, DATES_WITH_ALIENS, HOFFSET(struct s1, i2), NC_INT)) ERR; /* Check the compound type. */ if (nc_inq_compound(ncid, xtype, name, &size, &nfields)) ERR; if (nfields != 2 || size != 8 || strcmp(name, SVC_REC)) ERR; if (nc_inq_compound_name(ncid, xtype, name)) ERR; if (strcmp(name, SVC_REC)) ERR; if (nc_inq_compound_size(ncid, xtype, &size)) ERR; if (size != 8) ERR; if (nc_inq_compound_nfields(ncid, xtype, &nfields)) ERR; if (nfields != 2) ERR; if (nc_inq_compound_field(ncid, xtype, 0, name, &offset, &field_xtype, &field_ndims, field_sizes)) ERR; if (strcmp(name, BATTLES_WITH_KLINGONS) || offset != 0 || (field_xtype != NC_INT || field_ndims != 0)) ERR; if (nc_inq_compound_field(ncid, xtype, 1, name, &offset, &field_xtype, &field_ndims, field_sizes)) ERR; if (strcmp(name, DATES_WITH_ALIENS) || offset != 4 || field_xtype != NC_INT) ERR; if (nc_inq_compound_fieldname(ncid, xtype, 1, name)) ERR; if (strcmp(name, DATES_WITH_ALIENS)) ERR; if (nc_inq_compound_fieldindex(ncid, xtype, BATTLES_WITH_KLINGONS, &fieldid)) ERR; if (fieldid != 0) ERR; if (nc_inq_compound_fieldoffset(ncid, xtype, 1, &offset)) ERR; if (offset != 4) ERR; if (nc_inq_compound_fieldtype(ncid, xtype, 1, &field_xtype)) ERR; if (field_xtype != NC_INT) ERR;