Next: , Previous: nc_def_enum, Up: User Defined Data Types


5.31 Inserting a Field into a Enum Type: nc_insert_enum

Insert a named member into a enum type.

Usage

     int nc_insert_enum(int ncid, nc_type xtype, const char *identifier,
                        const void *value);
ncid
The ncid of the group which contains the type.
typeid
The typeid for this enum type, as returned by nc_def_enum, or nc_inq_var.
identifier
The identifier of the new member.
value
The value that is to be associated with this member.

Errors

NC_NOERR
No error.
NC_EBADID
Bad group id.
NC_ENAMEINUSE
That name is in use. Field names must be unique within a enum type.
NC_EMAXNAME
Name exceed max length NC_MAX_NAME.
NC_EBADNAME
Name contains illegal characters.
NC_ENOTNC4
Attempting a netCDF-4 operation on a netCDF-3 file. NetCDF-4 operations can only be performed on files defined with a create mode which includes flag NC_NETCDF4. (see nc_open).
NC_ESTRICTNC3
This file was created with the strict netcdf-3 flag, therefore netcdf-4 operations are not allowed. (see nc_open).
NC_EHDFERR
An error was reported by the HDF5 layer.
NC_ENOTINDEFINE
Not in define mode.

Example

This example is from libsrc4/tst_enums.c; also see the example in See nc_def_enum.

           char brady_name[NUM_BRADYS][NC_MAX_NAME + 1] = {"Mike", "Carol", "Greg", "Marsha",
                                                            "Peter", "Jan", "Bobby", "Whats-her-face",
                                                            "Alice"};
           unsigned char brady_value[NUM_BRADYS] = {0, 1,2,3,4,5,6,7,8};
           unsigned char data[BRADY_DIM_LEN] = {0, 4, 8};
           unsigned char value_in;
     
           /* Create a file. */
           if (nc_create(FILE_NAME, NC_NETCDF4, &ncid)) ERR;
     
           /* Create an enum type based on unsigned bytes. */
           if (nc_def_enum(ncid, NC_UBYTE, BRADYS, &typeid)) ERR;
           for (i = 0; i < NUM_BRADYS; i++)
              if (nc_insert_enum(ncid, typeid, brady_name[i],
                                 &brady_value[i])) ERR;