Previous: nc_rename_att, Up: Attributes


5.7 Delete an Attribute: nc_del_att

The function nc_del_att deletes a netCDF attribute from an open netCDF dataset. The netCDF dataset must be in define mode.

Usage

int nc_del_att (int ncid, int varid, const char* name);

ncid
NetCDF ID, from a previous call to nc_open or nc_create.
varid
ID of the attribute's variable, or NC_GLOBAL for a global attribute.
name
The name of the attribute to be deleted.

Errors

nc_del_att returns the value NC_NOERR if no errors occurred. Otherwise, the returned status indicates an error. Possible causes of errors include:

Example

Here is an example using nc_del_att to delete the variable attribute Units for a variable rh in an existing netCDF dataset named foo.nc:

     #include <netcdf.h>
        ...
     int  status;      /* error status */
     int  ncid;        /* netCDF ID */
     int  rh_id;       /* variable ID */
        ...
     status = nc_open("foo.nc", NC_WRITE, &ncid);
     if (status != NC_NOERR) handle_error(status);
        ...
     status = nc_inq_varid (ncid, "rh", &rh_id);
     if (status != NC_NOERR) handle_error(status);
        ...
     /* delete attribute */
     status = nc_redef(ncid);        /* enter define mode */
     if (status != NC_NOERR) handle_error(status);
     status = nc_del_att(ncid, rh_id, "Units");
     if (status != NC_NOERR) handle_error(status);
     status = nc_enddef(ncid);       /* leave define mode */
     if (status != NC_NOERR) handle_error(status);