Create a compound type. Provide an ncid, a name, and a total size (in bytes) of one element of the completed compound type.
After calling this function, fill out the type with repeated calls to nc_insert_compound (see nc_insert_compound). Call nc_insert_compound once for each field you wish to insert into the compound type.
Note that there does not seem to be a way to read such types into structures in Fortran 90 (and there are no structures in Fortran 77).
int nc_def_compound(int ncid, size_t size, char *name, nc_type *typeidp);
ncidsizenametypeidpNC_NOERRNC_EBADIDNC_ENAMEINUSENC_EMAXNAMENC_EBADNAMENC_ENOTNC4NC_ESTRICTNC3NC_EHDFERRNC_EPERMNC_ENOTINDEFINE struct s1
{
int i1;
int i2;
};
struct s1 data[DIM_LEN], data_in[DIM_LEN];
/* Create a file with a compound type. Write a little data. */
if (nc_create(FILE_NAME, NC_NETCDF4, &ncid)) ERR;
if (nc_def_compound(ncid, sizeof(struct s1), SVC_REC, &typeid)) 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;
if (nc_def_dim(ncid, STARDATE, DIM_LEN, &dimid)) ERR;
if (nc_def_var(ncid, SERVICE_RECORD, typeid, 1, dimids, &varid)) ERR;
if (nc_put_var(ncid, varid, data)) ERR;
if (nc_close(ncid)) ERR;