Use this function to define a variable length array type.
nc_def_vlen(int ncid, char *name, nc_type base_typeid, nc_type *xtypep);
ncidnamebase_typeidxtypepNC_NOERRNC_EMAXNAMENC_ENAMEINUSENC_EBADNAMENC_EBADIDNC_EBADGRPIDNC_EINVALNC_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;