5.21 Define a Variable Length Array (VLEN): nc_def_vlen
Use this function to define a variable length array type.
Usage
nc_def_vlen(int ncid, char *name, nc_type base_typeid, nc_type *xtypep);
ncid- The ncid of the file to create the VLEN type in.
name- A name for the VLEN type.
base_typeid- The typeid of the base type of the VLEN. For example, for a VLEN of
shorts, the base type is NC_SHORT. This can be a user defined type.
xtypep- A pointer to an nc_type variable. The typeid of the new VLEN type will
be set here.
Errors
NC_NOERR- No error.
NC_EMAXNAME- NC_MAX_NAME exceeded.
NC_ENAMEINUSE- Name is already in use.
NC_EBADNAME- Attribute or variable name contains illegal characters.
NC_EBADID- ncid invalid.
NC_EBADGRPID- Group ID part of ncid was invalid.
NC_EINVAL- Size is invalid.
NC_ENOMEM- Out of memory.
Example
#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;