Previous: , Up: Attributes   [Index]


5.7 Delete an Attribute: ncmpi_del_att

The function ncmpi_del_att deletes a netCDF attribute from an opened netCDF file.

Note that once an attribute is deleted, the attribute IDs of other attributes obtained prior to the deletion may no longer be valid. Users should call ncmpi_inq_attid() to obtain the up-to-date attribute IDs.

Operational Mode

This API is a collective subroutine.

These APIs must be called while the file is in define mode.

Usage

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

NetCDF ID, from a previous call to ncmpi_open or ncmpi_create.

varid

ID of the attribute’s variable, or NC_GLOBAL for a global attribute.

name

The name of the attribute to be deleted.

Return Error Codes

ncmpi_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 ncmpi_del_att to delete the variable attribute Units for a variable rh in an existing netCDF file named foo.nc:

#include <pnetcdf.h>
   ... 
int  status;      /* error status */
int  ncid;        /* netCDF ID */
int  rh_id;       /* variable ID */
   ... 
status = ncmpi_open(MPI_COMM_WORLD, "foo.nc", NC_WRITE, MPI_INFO_NULL, &ncid);
if (status != NC_NOERR) handle_error(status);
   ... 
status = ncmpi_inq_varid(ncid, "rh", &rh_id);
if (status != NC_NOERR) handle_error(status);
   ... 
/* delete attribute */
status = ncmpi_redef(ncid);        /* enter define mode */
if (status != NC_NOERR) handle_error(status);
status = ncmpi_del_att(ncid, rh_id, "Units");
if (status != NC_NOERR) handle_error(status);
status = ncmpi_enddef(ncid);       /* leave define mode */
if (status != NC_NOERR) handle_error(status);

Previous: , Up: Attributes   [Index]