Go to the previous, next section.

Delete an Attribute

The function ncattdel (or NCADEL for FORTRAN) deletes a netCDF attribute from an open netCDF file. The netCDF file must be in define mode.

In case of an error, ncattdel returns -1; NCADEL returns a nonzero value in rcode. Possible causes of errors include:

ncattdel: C Interface

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

ncid
NetCDF ID, returned from a previous call to ncopen or nccreate.

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

name
The name of the attribute to be deleted.

Here is an example using ncattdel to delete the variable attribute Units for a variable rh in an existing netCDF file named `foo.nc':

#include "netcdf.h"
   ...
int  ncid;        /* netCDF ID */
int  rh_id;       /* variable ID */
   ...
ncid = ncopen("foo.nc", NC_WRITE);
   ...
rh_id = ncvarid (ncid, "rh");
   ...
/* delete attribute */
ncredef(ncid);                  /* enter define mode */
ncattdel(ncid, rh_id, "Units");
ncendef(ncid);                  /* leave define mode */

NCADEL: FORTRAN Interface

      SUBROUTINE NCADEL (INTEGER NCID, INTEGER VARID,
     +                   CHARACTER*(*) ATTNAM, INTEGER RCODE)

NCID
NetCDF ID, returned from a previous call to NCOPN or NCCRE.

VARID
ID of the attribute's variable, or NCGLOBAL for a global attribute.

ATTNAM
The original attribute name.

RCODE
Returned error code. If no errors occurred, 0 is returned.

Here is an example using NCADEL to delete the variable attribute Units for a variable rh in an existing netCDF file named `foo.nc':

      INCLUDE 'netcdf.inc'
         ...
      INTEGER  NCID     ! netCDF ID
      INTEGER  RHID      ! variable ID
         ...
      NCID = NCOPN ('foo.nc', NCWRITE, RCODE)
         ...
      RHID = NCVID (NCID, 'rh', RCODE)
         ...
* delete attribute
      CALL NCREDF (NCID, RCODE)  ! enter define mode
      CALL NCADEL (NCID, RHID, 'Units', RCODE)
      CALL NCENDF (NCID, RCODE)  ! leave define mode

Go to the previous, next section.