Use this function to define a variable length array type.
nc_def_vlen(int ncid, const char *name, nc_type base_typeid, nc_type *xtypep);
ncid
name
base_typeid
xtypep
NC_NOERR
NC_EMAXNAME
NC_ENAMEINUSE
NC_EBADNAME
NC_EBADID
NC_EBADGRPID
NC_EINVAL
NC_ENOMEM
#define DIM_LEN 3 #define ATT_NAME "att_name" nc_vlen_t data[DIM_LEN]; int *phony; /* Create phony data. */ for (i=0; i<DIM_LEN; i++) { if (!(phony = malloc(sizeof(int) * i+1))) return NC_ENOMEM; for (j=0; j<i+1; j++) phony[j] = -99; data[i].p = phony; data[i].len = i+1; } /* Define a VLEN of NC_INT, and write an attribute of that type. */ if (nc_def_vlen(ncid, "name1", NC_INT, &typeid)) ERR; if (nc_put_att(ncid, NC_GLOBAL, ATT_NAME, typeid, DIM_LEN, data)) ERR;