NetCDF  4.7.0
Attributes

Attributes hold metadata about data and files. More...

Functions

int nc_get_att_string (int ncid, int varid, const char *name, char **value)
 Get a variable-length string attribute. More...
 

Deleting and Renaming Attributes

Functions to delete or rename an attribute.

int nc_rename_att (int ncid, int varid, const char *name, const char *newname)
 Rename an attribute. More...
 
int nc_del_att (int ncid, int varid, const char *name)
 Delete an attribute. More...
 

Getting Attributes

Functions to get the values of attributes.

int nc_get_att (int ncid, int varid, const char *name, void *value)
 Get an attribute of any type. More...
 
int nc_get_att_text (int ncid, int varid, const char *name, char *value)
 Get an attribute. More...
 
int nc_get_att_schar (int ncid, int varid, const char *name, signed char *value)
 Get an attribute. More...
 
int nc_get_att_uchar (int ncid, int varid, const char *name, unsigned char *value)
 Get an attribute. More...
 
int nc_get_att_short (int ncid, int varid, const char *name, short *value)
 Get an attribute. More...
 
int nc_get_att_int (int ncid, int varid, const char *name, int *value)
 Get an attribute. More...
 
int nc_get_att_long (int ncid, int varid, const char *name, long *value)
 Get an attribute. More...
 
int nc_get_att_float (int ncid, int varid, const char *name, float *value)
 Get an attribute. More...
 
int nc_get_att_double (int ncid, int varid, const char *name, double *value)
 Get an attribute. More...
 
int nc_get_att_ubyte (int ncid, int varid, const char *name, unsigned char *value)
 Get an attribute. More...
 
int nc_get_att_ushort (int ncid, int varid, const char *name, unsigned short *value)
 Get an attribute. More...
 
int nc_get_att_uint (int ncid, int varid, const char *name, unsigned int *value)
 Get an attribute. More...
 
int nc_get_att_longlong (int ncid, int varid, const char *name, long long *value)
 Get an attribute. More...
 
int nc_get_att_ulonglong (int ncid, int varid, const char *name, unsigned long long *value)
 Get an attribute. More...
 

Learning about Attributes

Functions to learn about the attributes in a file.

int nc_inq_att (int ncid, int varid, const char *name, nc_type *xtypep, size_t *lenp)
 Return information about a netCDF attribute. More...
 
int nc_inq_attid (int ncid, int varid, const char *name, int *idp)
 Find an attribute ID. More...
 
int nc_inq_attname (int ncid, int varid, int attnum, char *name)
 Find the name of an attribute. More...
 
int nc_inq_natts (int ncid, int *nattsp)
 Find number of global or group attributes. More...
 
int nc_inq_atttype (int ncid, int varid, const char *name, nc_type *xtypep)
 Find the type of an attribute. More...
 
int nc_inq_attlen (int ncid, int varid, const char *name, size_t *lenp)
 Find the length of an attribute. More...
 

Writing Attributes

Functions to write attributes.

int nc_put_att_string (int ncid, int varid, const char *name, size_t len, const char **value)
 Write a string attribute. More...
 
int nc_put_att_text (int ncid, int varid, const char *name, size_t len, const char *value)
 Write a text attribute. More...
 
int nc_put_att (int ncid, int varid, const char *name, nc_type xtype, size_t len, const void *value)
 Write an attribute. More...
 
int nc_put_att_schar (int ncid, int varid, const char *name, nc_type xtype, size_t len, const signed char *value)
 Write an attribute. More...
 
int nc_put_att_uchar (int ncid, int varid, const char *name, nc_type xtype, size_t len, const unsigned char *value)
 Write an attribute. More...
 
int nc_put_att_short (int ncid, int varid, const char *name, nc_type xtype, size_t len, const short *value)
 Write an attribute. More...
 
int nc_put_att_int (int ncid, int varid, const char *name, nc_type xtype, size_t len, const int *value)
 Write an attribute. More...
 
int nc_put_att_long (int ncid, int varid, const char *name, nc_type xtype, size_t len, const long *value)
 Write an attribute. More...
 
int nc_put_att_float (int ncid, int varid, const char *name, nc_type xtype, size_t len, const float *value)
 Write an attribute. More...
 
int nc_put_att_double (int ncid, int varid, const char *name, nc_type xtype, size_t len, const double *value)
 Write an attribute. More...
 
int nc_put_att_ubyte (int ncid, int varid, const char *name, nc_type xtype, size_t len, const unsigned char *value)
 Write an attribute. More...
 
int nc_put_att_ushort (int ncid, int varid, const char *name, nc_type xtype, size_t len, const unsigned short *value)
 Write an attribute. More...
 
int nc_put_att_uint (int ncid, int varid, const char *name, nc_type xtype, size_t len, const unsigned int *value)
 Write an attribute. More...
 
int nc_put_att_longlong (int ncid, int varid, const char *name, nc_type xtype, size_t len, const long long *value)
 Write an attribute. More...
 
int nc_put_att_ulonglong (int ncid, int varid, const char *name, nc_type xtype, size_t len, const unsigned long long *value)
 Write an attribute. More...
 

Detailed Description

Attributes hold metadata about data and files.

ncatts.png
Attributes store metadata.

Attributes may be associated with a netCDF variable to specify such properties as units, special values, maximum and minimum valid values, scaling factors, and offsets.

Attributes for a netCDF dataset are defined when the dataset is first created, while the netCDF dataset is in define mode. Additional attributes may be added later by reentering define mode.

A netCDF attribute has a netCDF variable to which it is assigned, a name, a type, a length, and a sequence of one or more values.

An attribute is designated by its variable ID and name. When an attribute name is not known, it may be designated by its variable ID and number in order to determine its name, using the function nc_inq_attname().

The attributes associated with a variable are typically defined immediately after the variable is created, while still in define mode. The data type, length, and value of an attribute may be changed even when in data mode, as long as the changed attribute requires no more space than the attribute as originally defined.

It is also possible to have attributes that are not associated with any variable. These are called global attributes and are identified by using NC_GLOBAL as a variable pseudo-ID. Global attributes are usually related to the netCDF dataset as a whole and may be used for purposes such as providing a title or processing history for a netCDF dataset.

Operations supported on attributes are:

Function Documentation

◆ nc_del_att()

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

Delete an attribute.

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

Parameters
ncidNetCDF or group ID, from a previous call to nc_open(), nc_create(), nc_def_grp(), or associated inquiry functions such as nc_inq_ncid().
varidVariable ID of the attribute's variable, or NC_GLOBAL for a global attribute.
nameAttribute name.

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;
int ncid;
int rh_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);
...
status = nc_redef(ncid);
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);
if (status != NC_NOERR) handle_error(status);
Returns
NC_NOERR No error.
NC_EBADID Bad ncid.
NC_ENOTVAR Bad varid.
NC_EBADNAME Bad name.
NC_EINVAL Name not provided.
NC_EPERM File was opened read only.
NC_ENOTINDEFINE File is not in define mode.
NC_ENOTATT Attribute not found.
NC_EATTMETA Failure at HDF5 layer.
Author
Glenn Davis, Ed Hartnett, Dennis Heimbigner

Definition at line 183 of file datt.c.

◆ nc_get_att()

int nc_get_att ( int  ncid,
int  varid,
const char *  name,
void *  value 
)

Get an attribute of any type.

The nc_get_att() functions works for any type of attribute, and must be used to get attributes of user-defined type. We recommend that they type safe versions of this function be used for atomic data types.

Parameters
ncidNetCDF or group ID, from a previous call to nc_open(), nc_create(), nc_def_grp(), or associated inquiry functions such as nc_inq_ncid().
varidVariable ID of the attribute's variable, or NC_GLOBAL for a global attribute.
nameAttribute name.
valuePointer to location for returned attribute value(s). All elements of the vector of attribute values are returned, so you must allocate enough space to hold them. Before using the value as a C string, make sure it is null-terminated. Call nc_inq_attlen() first to find out the length of the attribute.
Note
See documentation for nc_get_att_string() regarding a special case where memory must be explicitly released.
Returns
NC_NOERR for success.
NC_EBADID Bad ncid.
NC_ENOTVAR Bad varid.
NC_EBADNAME Bad name. See NetCDF Names.
NC_EINVAL Invalid parameters.
NC_ENOTATT Can't find attribute.
NC_ECHAR Can't convert to or from NC_CHAR.
NC_ENOMEM Out of memory.
NC_ERANGE Data conversion went out of range.

Example

Here is an example using nc_get_att() from nc_test4/tst_vl.c creates a VLEN attribute, then uses nc_get_att() to read it.

#define FILE_NAME "tst_vl.nc"
#define VLEN_NAME "vlen_name"
#define ATT_NAME "att_name"
int ncid, typeid;
nc_vlen_t data[DIM_LEN], data_in[DIM_LEN];
...
if (nc_create(FILE_NAME, NC_NETCDF4, &ncid)) ERR;
if (nc_def_vlen(ncid, VLEN_NAME, NC_INT, &typeid)) ERR;
...
if (nc_put_att(ncid, NC_GLOBAL, ATT_NAME, typeid, DIM_LEN, data)) ERR;
if (nc_close(ncid)) ERR;
...
if (nc_open(FILE_NAME, NC_NOWRITE, &ncid)) ERR;
if (nc_get_att(ncid, NC_GLOBAL, ATT_NAME, data_in)) ERR;
...
if (nc_close(ncid)) ERR;
Author
Glenn Davis, Ed Hartnett, Dennis Heimbigner

Definition at line 83 of file dattget.c.

◆ nc_get_att_double()

int nc_get_att_double ( int  ncid,
int  varid,
const char *  name,
double *  value 
)

Get an attribute.

This function gets an attribute from the netCDF file. The nc_get_att() function works with any type of data, including user defined types.

Note
The netCDF library reads all attributes into memory when the file is opened with nc_open(). Getting an attribute copies the value from the in-memory store, and does not incur any file I/O penalties.
Parameters
ncidNetCDF or group ID, from a previous call to nc_open(), nc_create(), nc_def_grp(), or associated inquiry functions such as nc_inq_ncid().
varidVariable ID of the attribute's variable, or NC_GLOBAL for a global attribute.
nameAttribute name.
valuePointer to location for returned attribute value(s). All elements of the vector of attribute values are returned, so you must allocate enough space to hold them. If you don't know how much space to reserve, call nc_inq_attlen() first to find out the length of the attribute.
Returns
NC_NOERR for success.
NC_EBADID Bad ncid.
NC_ENOTVAR Bad varid.
NC_EBADNAME Bad name. See NetCDF Names.
NC_EINVAL Invalid parameters.
NC_ENOTATT Can't find attribute.
NC_ECHAR Can't convert to or from NC_CHAR.
NC_ENOMEM Out of memory.
NC_ERANGE Data conversion went out of range.

Example

Here is an example using nc_get_att_double() to determine the values of a variable attribute named valid_range for a netCDF variable named rh and using nc_get_att_text() to read a global attribute named title in an existing netCDF dataset named foo.nc.

In this example, it is assumed that we don't know how many values will be returned, but that we do know the types of the attributes. Hence, to allocate enough space to store them, we must first inquire about the length of the attributes.

#include <netcdf.h>
...
int status;
int ncid;
int rh_id;
int vr_len, t_len;
double *vr_val;
char *title;
extern char *malloc()
...
status = nc_open("foo.nc", NC_NOWRITE, &ncid);
if (status != NC_NOERR) handle_error(status);
...
status = nc_inq_varid (ncid, "rh", &rh_id);
if (status != NC_NOERR) handle_error(status);
...
status = nc_inq_attlen (ncid, rh_id, "valid_range", &vr_len);
if (status != NC_NOERR) handle_error(status);
status = nc_inq_attlen (ncid, NC_GLOBAL, "title", &t_len);
if (status != NC_NOERR) handle_error(status);
vr_val = (double *) malloc(vr_len * sizeof(double));
title = (char *) malloc(t_len + 1);
status = nc_get_att_double(ncid, rh_id, "valid_range", vr_val);
if (status != NC_NOERR) handle_error(status);
status = nc_get_att_text(ncid, NC_GLOBAL, "title", title);
if (status != NC_NOERR) handle_error(status);
title[t_len] = '\0';
...
Author
Glenn Davis, Ed Hartnett, Dennis Heimbigner

Definition at line 257 of file dattget.c.

◆ nc_get_att_float()

int nc_get_att_float ( int  ncid,
int  varid,
const char *  name,
float *  value 
)

Get an attribute.

This function gets an attribute from the netCDF file. The nc_get_att() function works with any type of data, including user defined types.

Note
The netCDF library reads all attributes into memory when the file is opened with nc_open(). Getting an attribute copies the value from the in-memory store, and does not incur any file I/O penalties.
Parameters
ncidNetCDF or group ID, from a previous call to nc_open(), nc_create(), nc_def_grp(), or associated inquiry functions such as nc_inq_ncid().
varidVariable ID of the attribute's variable, or NC_GLOBAL for a global attribute.
nameAttribute name.
valuePointer to location for returned attribute value(s). All elements of the vector of attribute values are returned, so you must allocate enough space to hold them. If you don't know how much space to reserve, call nc_inq_attlen() first to find out the length of the attribute.
Returns
NC_NOERR for success.
NC_EBADID Bad ncid.
NC_ENOTVAR Bad varid.
NC_EBADNAME Bad name. See NetCDF Names.
NC_EINVAL Invalid parameters.
NC_ENOTATT Can't find attribute.
NC_ECHAR Can't convert to or from NC_CHAR.
NC_ENOMEM Out of memory.
NC_ERANGE Data conversion went out of range.

Example

Here is an example using nc_get_att_double() to determine the values of a variable attribute named valid_range for a netCDF variable named rh and using nc_get_att_text() to read a global attribute named title in an existing netCDF dataset named foo.nc.

In this example, it is assumed that we don't know how many values will be returned, but that we do know the types of the attributes. Hence, to allocate enough space to store them, we must first inquire about the length of the attributes.

#include <netcdf.h>
...
int status;
int ncid;
int rh_id;
int vr_len, t_len;
double *vr_val;
char *title;
extern char *malloc()
...
status = nc_open("foo.nc", NC_NOWRITE, &ncid);
if (status != NC_NOERR) handle_error(status);
...
status = nc_inq_varid (ncid, "rh", &rh_id);
if (status != NC_NOERR) handle_error(status);
...
status = nc_inq_attlen (ncid, rh_id, "valid_range", &vr_len);
if (status != NC_NOERR) handle_error(status);
status = nc_inq_attlen (ncid, NC_GLOBAL, "title", &t_len);
if (status != NC_NOERR) handle_error(status);
vr_val = (double *) malloc(vr_len * sizeof(double));
title = (char *) malloc(t_len + 1);
status = nc_get_att_double(ncid, rh_id, "valid_range", vr_val);
if (status != NC_NOERR) handle_error(status);
status = nc_get_att_text(ncid, NC_GLOBAL, "title", title);
if (status != NC_NOERR) handle_error(status);
title[t_len] = '\0';
...
Author
Glenn Davis, Ed Hartnett, Dennis Heimbigner

Definition at line 247 of file dattget.c.

◆ nc_get_att_int()

int nc_get_att_int ( int  ncid,
int  varid,
const char *  name,
int *  value 
)

Get an attribute.

This function gets an attribute from the netCDF file. The nc_get_att() function works with any type of data, including user defined types.

Note
The netCDF library reads all attributes into memory when the file is opened with nc_open(). Getting an attribute copies the value from the in-memory store, and does not incur any file I/O penalties.
Parameters
ncidNetCDF or group ID, from a previous call to nc_open(), nc_create(), nc_def_grp(), or associated inquiry functions such as nc_inq_ncid().
varidVariable ID of the attribute's variable, or NC_GLOBAL for a global attribute.
nameAttribute name.
valuePointer to location for returned attribute value(s). All elements of the vector of attribute values are returned, so you must allocate enough space to hold them. If you don't know how much space to reserve, call nc_inq_attlen() first to find out the length of the attribute.
Returns
NC_NOERR for success.
NC_EBADID Bad ncid.
NC_ENOTVAR Bad varid.
NC_EBADNAME Bad name. See NetCDF Names.
NC_EINVAL Invalid parameters.
NC_ENOTATT Can't find attribute.
NC_ECHAR Can't convert to or from NC_CHAR.
NC_ENOMEM Out of memory.
NC_ERANGE Data conversion went out of range.

Example

Here is an example using nc_get_att_double() to determine the values of a variable attribute named valid_range for a netCDF variable named rh and using nc_get_att_text() to read a global attribute named title in an existing netCDF dataset named foo.nc.

In this example, it is assumed that we don't know how many values will be returned, but that we do know the types of the attributes. Hence, to allocate enough space to store them, we must first inquire about the length of the attributes.

#include <netcdf.h>
...
int status;
int ncid;
int rh_id;
int vr_len, t_len;
double *vr_val;
char *title;
extern char *malloc()
...
status = nc_open("foo.nc", NC_NOWRITE, &ncid);
if (status != NC_NOERR) handle_error(status);
...
status = nc_inq_varid (ncid, "rh", &rh_id);
if (status != NC_NOERR) handle_error(status);
...
status = nc_inq_attlen (ncid, rh_id, "valid_range", &vr_len);
if (status != NC_NOERR) handle_error(status);
status = nc_inq_attlen (ncid, NC_GLOBAL, "title", &t_len);
if (status != NC_NOERR) handle_error(status);
vr_val = (double *) malloc(vr_len * sizeof(double));
title = (char *) malloc(t_len + 1);
status = nc_get_att_double(ncid, rh_id, "valid_range", vr_val);
if (status != NC_NOERR) handle_error(status);
status = nc_get_att_text(ncid, NC_GLOBAL, "title", title);
if (status != NC_NOERR) handle_error(status);
title[t_len] = '\0';
...
Author
Glenn Davis, Ed Hartnett, Dennis Heimbigner

Definition at line 227 of file dattget.c.

◆ nc_get_att_long()

int nc_get_att_long ( int  ncid,
int  varid,
const char *  name,
long *  value 
)

Get an attribute.

This function gets an attribute from the netCDF file. The nc_get_att() function works with any type of data, including user defined types.

Note
The netCDF library reads all attributes into memory when the file is opened with nc_open(). Getting an attribute copies the value from the in-memory store, and does not incur any file I/O penalties.
Parameters
ncidNetCDF or group ID, from a previous call to nc_open(), nc_create(), nc_def_grp(), or associated inquiry functions such as nc_inq_ncid().
varidVariable ID of the attribute's variable, or NC_GLOBAL for a global attribute.
nameAttribute name.
valuePointer to location for returned attribute value(s). All elements of the vector of attribute values are returned, so you must allocate enough space to hold them. If you don't know how much space to reserve, call nc_inq_attlen() first to find out the length of the attribute.
Returns
NC_NOERR for success.
NC_EBADID Bad ncid.
NC_ENOTVAR Bad varid.
NC_EBADNAME Bad name. See NetCDF Names.
NC_EINVAL Invalid parameters.
NC_ENOTATT Can't find attribute.
NC_ECHAR Can't convert to or from NC_CHAR.
NC_ENOMEM Out of memory.
NC_ERANGE Data conversion went out of range.

Example

Here is an example using nc_get_att_double() to determine the values of a variable attribute named valid_range for a netCDF variable named rh and using nc_get_att_text() to read a global attribute named title in an existing netCDF dataset named foo.nc.

In this example, it is assumed that we don't know how many values will be returned, but that we do know the types of the attributes. Hence, to allocate enough space to store them, we must first inquire about the length of the attributes.

#include <netcdf.h>
...
int status;
int ncid;
int rh_id;
int vr_len, t_len;
double *vr_val;
char *title;
extern char *malloc()
...
status = nc_open("foo.nc", NC_NOWRITE, &ncid);
if (status != NC_NOERR) handle_error(status);
...
status = nc_inq_varid (ncid, "rh", &rh_id);
if (status != NC_NOERR) handle_error(status);
...
status = nc_inq_attlen (ncid, rh_id, "valid_range", &vr_len);
if (status != NC_NOERR) handle_error(status);
status = nc_inq_attlen (ncid, NC_GLOBAL, "title", &t_len);
if (status != NC_NOERR) handle_error(status);
vr_val = (double *) malloc(vr_len * sizeof(double));
title = (char *) malloc(t_len + 1);
status = nc_get_att_double(ncid, rh_id, "valid_range", vr_val);
if (status != NC_NOERR) handle_error(status);
status = nc_get_att_text(ncid, NC_GLOBAL, "title", title);
if (status != NC_NOERR) handle_error(status);
title[t_len] = '\0';
...
Author
Glenn Davis, Ed Hartnett, Dennis Heimbigner

Definition at line 237 of file dattget.c.

◆ nc_get_att_longlong()

int nc_get_att_longlong ( int  ncid,
int  varid,
const char *  name,
long long *  value 
)

Get an attribute.

This function gets an attribute from the netCDF file. The nc_get_att() function works with any type of data, including user defined types.

Note
The netCDF library reads all attributes into memory when the file is opened with nc_open(). Getting an attribute copies the value from the in-memory store, and does not incur any file I/O penalties.
Parameters
ncidNetCDF or group ID, from a previous call to nc_open(), nc_create(), nc_def_grp(), or associated inquiry functions such as nc_inq_ncid().
varidVariable ID of the attribute's variable, or NC_GLOBAL for a global attribute.
nameAttribute name.
valuePointer to location for returned attribute value(s). All elements of the vector of attribute values are returned, so you must allocate enough space to hold them. If you don't know how much space to reserve, call nc_inq_attlen() first to find out the length of the attribute.
Returns
NC_NOERR for success.
NC_EBADID Bad ncid.
NC_ENOTVAR Bad varid.
NC_EBADNAME Bad name. See NetCDF Names.
NC_EINVAL Invalid parameters.
NC_ENOTATT Can't find attribute.
NC_ECHAR Can't convert to or from NC_CHAR.
NC_ENOMEM Out of memory.
NC_ERANGE Data conversion went out of range.

Example

Here is an example using nc_get_att_double() to determine the values of a variable attribute named valid_range for a netCDF variable named rh and using nc_get_att_text() to read a global attribute named title in an existing netCDF dataset named foo.nc.

In this example, it is assumed that we don't know how many values will be returned, but that we do know the types of the attributes. Hence, to allocate enough space to store them, we must first inquire about the length of the attributes.

#include <netcdf.h>
...
int status;
int ncid;
int rh_id;
int vr_len, t_len;
double *vr_val;
char *title;
extern char *malloc()
...
status = nc_open("foo.nc", NC_NOWRITE, &ncid);
if (status != NC_NOERR) handle_error(status);
...
status = nc_inq_varid (ncid, "rh", &rh_id);
if (status != NC_NOERR) handle_error(status);
...
status = nc_inq_attlen (ncid, rh_id, "valid_range", &vr_len);
if (status != NC_NOERR) handle_error(status);
status = nc_inq_attlen (ncid, NC_GLOBAL, "title", &t_len);
if (status != NC_NOERR) handle_error(status);
vr_val = (double *) malloc(vr_len * sizeof(double));
title = (char *) malloc(t_len + 1);
status = nc_get_att_double(ncid, rh_id, "valid_range", vr_val);
if (status != NC_NOERR) handle_error(status);
status = nc_get_att_text(ncid, NC_GLOBAL, "title", title);
if (status != NC_NOERR) handle_error(status);
title[t_len] = '\0';
...
Author
Glenn Davis, Ed Hartnett, Dennis Heimbigner

Definition at line 297 of file dattget.c.

◆ nc_get_att_schar()

int nc_get_att_schar ( int  ncid,
int  varid,
const char *  name,
signed char *  value 
)

Get an attribute.

This function gets an attribute from the netCDF file. The nc_get_att() function works with any type of data, including user defined types.

Note
The netCDF library reads all attributes into memory when the file is opened with nc_open(). Getting an attribute copies the value from the in-memory store, and does not incur any file I/O penalties.
Parameters
ncidNetCDF or group ID, from a previous call to nc_open(), nc_create(), nc_def_grp(), or associated inquiry functions such as nc_inq_ncid().
varidVariable ID of the attribute's variable, or NC_GLOBAL for a global attribute.
nameAttribute name.
valuePointer to location for returned attribute value(s). All elements of the vector of attribute values are returned, so you must allocate enough space to hold them. If you don't know how much space to reserve, call nc_inq_attlen() first to find out the length of the attribute.
Returns
NC_NOERR for success.
NC_EBADID Bad ncid.
NC_ENOTVAR Bad varid.
NC_EBADNAME Bad name. See NetCDF Names.
NC_EINVAL Invalid parameters.
NC_ENOTATT Can't find attribute.
NC_ECHAR Can't convert to or from NC_CHAR.
NC_ENOMEM Out of memory.
NC_ERANGE Data conversion went out of range.

Example

Here is an example using nc_get_att_double() to determine the values of a variable attribute named valid_range for a netCDF variable named rh and using nc_get_att_text() to read a global attribute named title in an existing netCDF dataset named foo.nc.

In this example, it is assumed that we don't know how many values will be returned, but that we do know the types of the attributes. Hence, to allocate enough space to store them, we must first inquire about the length of the attributes.

#include <netcdf.h>
...
int status;
int ncid;
int rh_id;
int vr_len, t_len;
double *vr_val;
char *title;
extern char *malloc()
...
status = nc_open("foo.nc", NC_NOWRITE, &ncid);
if (status != NC_NOERR) handle_error(status);
...
status = nc_inq_varid (ncid, "rh", &rh_id);
if (status != NC_NOERR) handle_error(status);
...
status = nc_inq_attlen (ncid, rh_id, "valid_range", &vr_len);
if (status != NC_NOERR) handle_error(status);
status = nc_inq_attlen (ncid, NC_GLOBAL, "title", &t_len);
if (status != NC_NOERR) handle_error(status);
vr_val = (double *) malloc(vr_len * sizeof(double));
title = (char *) malloc(t_len + 1);
status = nc_get_att_double(ncid, rh_id, "valid_range", vr_val);
if (status != NC_NOERR) handle_error(status);
status = nc_get_att_text(ncid, NC_GLOBAL, "title", title);
if (status != NC_NOERR) handle_error(status);
title[t_len] = '\0';
...
Author
Glenn Davis, Ed Hartnett, Dennis Heimbigner

Definition at line 197 of file dattget.c.

◆ nc_get_att_short()

int nc_get_att_short ( int  ncid,
int  varid,
const char *  name,
short *  value 
)

Get an attribute.

This function gets an attribute from the netCDF file. The nc_get_att() function works with any type of data, including user defined types.

Note
The netCDF library reads all attributes into memory when the file is opened with nc_open(). Getting an attribute copies the value from the in-memory store, and does not incur any file I/O penalties.
Parameters
ncidNetCDF or group ID, from a previous call to nc_open(), nc_create(), nc_def_grp(), or associated inquiry functions such as nc_inq_ncid().
varidVariable ID of the attribute's variable, or NC_GLOBAL for a global attribute.
nameAttribute name.
valuePointer to location for returned attribute value(s). All elements of the vector of attribute values are returned, so you must allocate enough space to hold them. If you don't know how much space to reserve, call nc_inq_attlen() first to find out the length of the attribute.
Returns
NC_NOERR for success.
NC_EBADID Bad ncid.
NC_ENOTVAR Bad varid.
NC_EBADNAME Bad name. See NetCDF Names.
NC_EINVAL Invalid parameters.
NC_ENOTATT Can't find attribute.
NC_ECHAR Can't convert to or from NC_CHAR.
NC_ENOMEM Out of memory.
NC_ERANGE Data conversion went out of range.

Example

Here is an example using nc_get_att_double() to determine the values of a variable attribute named valid_range for a netCDF variable named rh and using nc_get_att_text() to read a global attribute named title in an existing netCDF dataset named foo.nc.

In this example, it is assumed that we don't know how many values will be returned, but that we do know the types of the attributes. Hence, to allocate enough space to store them, we must first inquire about the length of the attributes.

#include <netcdf.h>
...
int status;
int ncid;
int rh_id;
int vr_len, t_len;
double *vr_val;
char *title;
extern char *malloc()
...
status = nc_open("foo.nc", NC_NOWRITE, &ncid);
if (status != NC_NOERR) handle_error(status);
...
status = nc_inq_varid (ncid, "rh", &rh_id);
if (status != NC_NOERR) handle_error(status);
...
status = nc_inq_attlen (ncid, rh_id, "valid_range", &vr_len);
if (status != NC_NOERR) handle_error(status);
status = nc_inq_attlen (ncid, NC_GLOBAL, "title", &t_len);
if (status != NC_NOERR) handle_error(status);
vr_val = (double *) malloc(vr_len * sizeof(double));
title = (char *) malloc(t_len + 1);
status = nc_get_att_double(ncid, rh_id, "valid_range", vr_val);
if (status != NC_NOERR) handle_error(status);
status = nc_get_att_text(ncid, NC_GLOBAL, "title", title);
if (status != NC_NOERR) handle_error(status);
title[t_len] = '\0';
...
Author
Glenn Davis, Ed Hartnett, Dennis Heimbigner

Definition at line 217 of file dattget.c.

◆ nc_get_att_string()

int nc_get_att_string ( int  ncid,
int  varid,
const char *  name,
char **  value 
)

Get a variable-length string attribute.

This function gets an attribute from netCDF file. The nc_get_att() function works with any type of data including user defined types, but this function will retrieve attributes which are of type variable-length string.

Note
Note that unlike most other nc_get_att functions, nc_get_att_string() allocates a chunk of memory which is returned to the calling function. This chunk of memory must be specifically deallocated with nc_free_string() to avoid any memory leaks. Also note that you must still preallocate the memory needed for the array of pointers passed to nc_get_att_string().
Parameters
ncidNetCDF or group ID, from a previous call to nc_open(), nc_create(), nc_def_grp(), or associated inquiry functions such as nc_inq_ncid().
varidVariable ID of the attribute's variable, or NC_GLOBAL for a global attribute.
nameAttribute name.
valuePointer to location for returned attribute value(s). All elements of the vector of attribute values are returned, so you must allocate enough space to hold them. If you don't know how much space to reserve, call nc_inq_attlen() first to find out the length of the attribute.
Returns
NC_NOERR for success.
NC_EBADID Bad ncid.
NC_ENOTVAR Bad varid.
NC_EBADNAME Bad name. See NetCDF Names.
NC_EINVAL Invalid parameters.
NC_ENOTATT Can't find attribute.
NC_ECHAR Can't convert to or from NC_CHAR.
NC_ENOMEM Out of memory.
NC_ERANGE Data conversion went out of range.

Example

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <netcdf.h>
void check(int stat) {
if (stat != NC_NOERR) {
printf("NetCDF error: %s\n", nc_strerror(stat));
exit(1);
}
}
int main(int argc, char ** argv) {
int stat = 0;
int ncid = 0;
stat = nc_open("test.nc", NC_NOWRITE, &ncid); check(stat);
int varid = 0;
stat = nc_inq_varid(ncid, "variable", &varid); check(stat);
size_t attlen = 0;
stat = nc_inq_attlen(ncid, varid, "attribute", &attlen); check(stat);
char **string_attr = (char**)malloc(attlen * sizeof(char*));
memset(string_attr, 0, attlen * sizeof(char*));
stat = nc_get_att_string(ncid, varid, "attribute", string_attr); check(stat);
for (size_t k = 0; k < attlen; ++k) {
printf("variable:attribute[%d] = %s\n", k, string_attr[k]);
}
stat = nc_free_string(attlen, string_attr); check(stat);
free(string_attr);
stat = nc_close(ncid); check(stat);
return 0;
}
Author
Glenn Davis, Ed Hartnett, Dennis Heimbigner

Definition at line 408 of file dattget.c.

◆ nc_get_att_text()

int nc_get_att_text ( int  ncid,
int  varid,
const char *  name,
char *  value 
)

Get an attribute.

This function gets an attribute from the netCDF file. The nc_get_att() function works with any type of data, including user defined types.

Note
The netCDF library reads all attributes into memory when the file is opened with nc_open(). Getting an attribute copies the value from the in-memory store, and does not incur any file I/O penalties.
Parameters
ncidNetCDF or group ID, from a previous call to nc_open(), nc_create(), nc_def_grp(), or associated inquiry functions such as nc_inq_ncid().
varidVariable ID of the attribute's variable, or NC_GLOBAL for a global attribute.
nameAttribute name.
valuePointer to location for returned attribute value(s). All elements of the vector of attribute values are returned, so you must allocate enough space to hold them. If you don't know how much space to reserve, call nc_inq_attlen() first to find out the length of the attribute.
Returns
NC_NOERR for success.
NC_EBADID Bad ncid.
NC_ENOTVAR Bad varid.
NC_EBADNAME Bad name. See NetCDF Names.
NC_EINVAL Invalid parameters.
NC_ENOTATT Can't find attribute.
NC_ECHAR Can't convert to or from NC_CHAR.
NC_ENOMEM Out of memory.
NC_ERANGE Data conversion went out of range.

Example

Here is an example using nc_get_att_double() to determine the values of a variable attribute named valid_range for a netCDF variable named rh and using nc_get_att_text() to read a global attribute named title in an existing netCDF dataset named foo.nc.

In this example, it is assumed that we don't know how many values will be returned, but that we do know the types of the attributes. Hence, to allocate enough space to store them, we must first inquire about the length of the attributes.

#include <netcdf.h>
...
int status;
int ncid;
int rh_id;
int vr_len, t_len;
double *vr_val;
char *title;
extern char *malloc()
...
status = nc_open("foo.nc", NC_NOWRITE, &ncid);
if (status != NC_NOERR) handle_error(status);
...
status = nc_inq_varid (ncid, "rh", &rh_id);
if (status != NC_NOERR) handle_error(status);
...
status = nc_inq_attlen (ncid, rh_id, "valid_range", &vr_len);
if (status != NC_NOERR) handle_error(status);
status = nc_inq_attlen (ncid, NC_GLOBAL, "title", &t_len);
if (status != NC_NOERR) handle_error(status);
vr_val = (double *) malloc(vr_len * sizeof(double));
title = (char *) malloc(t_len + 1);
status = nc_get_att_double(ncid, rh_id, "valid_range", vr_val);
if (status != NC_NOERR) handle_error(status);
status = nc_get_att_text(ncid, NC_GLOBAL, "title", title);
if (status != NC_NOERR) handle_error(status);
title[t_len] = '\0';
...
Author
Glenn Davis, Ed Hartnett, Dennis Heimbigner

Definition at line 187 of file dattget.c.

◆ nc_get_att_ubyte()

int nc_get_att_ubyte ( int  ncid,
int  varid,
const char *  name,
unsigned char *  value 
)

Get an attribute.

This function gets an attribute from the netCDF file. The nc_get_att() function works with any type of data, including user defined types.

Note
The netCDF library reads all attributes into memory when the file is opened with nc_open(). Getting an attribute copies the value from the in-memory store, and does not incur any file I/O penalties.
Parameters
ncidNetCDF or group ID, from a previous call to nc_open(), nc_create(), nc_def_grp(), or associated inquiry functions such as nc_inq_ncid().
varidVariable ID of the attribute's variable, or NC_GLOBAL for a global attribute.
nameAttribute name.
valuePointer to location for returned attribute value(s). All elements of the vector of attribute values are returned, so you must allocate enough space to hold them. If you don't know how much space to reserve, call nc_inq_attlen() first to find out the length of the attribute.
Returns
NC_NOERR for success.
NC_EBADID Bad ncid.
NC_ENOTVAR Bad varid.
NC_EBADNAME Bad name. See NetCDF Names.
NC_EINVAL Invalid parameters.
NC_ENOTATT Can't find attribute.
NC_ECHAR Can't convert to or from NC_CHAR.
NC_ENOMEM Out of memory.
NC_ERANGE Data conversion went out of range.

Example

Here is an example using nc_get_att_double() to determine the values of a variable attribute named valid_range for a netCDF variable named rh and using nc_get_att_text() to read a global attribute named title in an existing netCDF dataset named foo.nc.

In this example, it is assumed that we don't know how many values will be returned, but that we do know the types of the attributes. Hence, to allocate enough space to store them, we must first inquire about the length of the attributes.

#include <netcdf.h>
...
int status;
int ncid;
int rh_id;
int vr_len, t_len;
double *vr_val;
char *title;
extern char *malloc()
...
status = nc_open("foo.nc", NC_NOWRITE, &ncid);
if (status != NC_NOERR) handle_error(status);
...
status = nc_inq_varid (ncid, "rh", &rh_id);
if (status != NC_NOERR) handle_error(status);
...
status = nc_inq_attlen (ncid, rh_id, "valid_range", &vr_len);
if (status != NC_NOERR) handle_error(status);
status = nc_inq_attlen (ncid, NC_GLOBAL, "title", &t_len);
if (status != NC_NOERR) handle_error(status);
vr_val = (double *) malloc(vr_len * sizeof(double));
title = (char *) malloc(t_len + 1);
status = nc_get_att_double(ncid, rh_id, "valid_range", vr_val);
if (status != NC_NOERR) handle_error(status);
status = nc_get_att_text(ncid, NC_GLOBAL, "title", title);
if (status != NC_NOERR) handle_error(status);
title[t_len] = '\0';
...
Author
Glenn Davis, Ed Hartnett, Dennis Heimbigner

Definition at line 267 of file dattget.c.

◆ nc_get_att_uchar()

int nc_get_att_uchar ( int  ncid,
int  varid,
const char *  name,
unsigned char *  value 
)

Get an attribute.

This function gets an attribute from the netCDF file. The nc_get_att() function works with any type of data, including user defined types.

Note
The netCDF library reads all attributes into memory when the file is opened with nc_open(). Getting an attribute copies the value from the in-memory store, and does not incur any file I/O penalties.
Parameters
ncidNetCDF or group ID, from a previous call to nc_open(), nc_create(), nc_def_grp(), or associated inquiry functions such as nc_inq_ncid().
varidVariable ID of the attribute's variable, or NC_GLOBAL for a global attribute.
nameAttribute name.
valuePointer to location for returned attribute value(s). All elements of the vector of attribute values are returned, so you must allocate enough space to hold them. If you don't know how much space to reserve, call nc_inq_attlen() first to find out the length of the attribute.
Returns
NC_NOERR for success.
NC_EBADID Bad ncid.
NC_ENOTVAR Bad varid.
NC_EBADNAME Bad name. See NetCDF Names.
NC_EINVAL Invalid parameters.
NC_ENOTATT Can't find attribute.
NC_ECHAR Can't convert to or from NC_CHAR.
NC_ENOMEM Out of memory.
NC_ERANGE Data conversion went out of range.

Example

Here is an example using nc_get_att_double() to determine the values of a variable attribute named valid_range for a netCDF variable named rh and using nc_get_att_text() to read a global attribute named title in an existing netCDF dataset named foo.nc.

In this example, it is assumed that we don't know how many values will be returned, but that we do know the types of the attributes. Hence, to allocate enough space to store them, we must first inquire about the length of the attributes.

#include <netcdf.h>
...
int status;
int ncid;
int rh_id;
int vr_len, t_len;
double *vr_val;
char *title;
extern char *malloc()
...
status = nc_open("foo.nc", NC_NOWRITE, &ncid);
if (status != NC_NOERR) handle_error(status);
...
status = nc_inq_varid (ncid, "rh", &rh_id);
if (status != NC_NOERR) handle_error(status);
...
status = nc_inq_attlen (ncid, rh_id, "valid_range", &vr_len);
if (status != NC_NOERR) handle_error(status);
status = nc_inq_attlen (ncid, NC_GLOBAL, "title", &t_len);
if (status != NC_NOERR) handle_error(status);
vr_val = (double *) malloc(vr_len * sizeof(double));
title = (char *) malloc(t_len + 1);
status = nc_get_att_double(ncid, rh_id, "valid_range", vr_val);
if (status != NC_NOERR) handle_error(status);
status = nc_get_att_text(ncid, NC_GLOBAL, "title", title);
if (status != NC_NOERR) handle_error(status);
title[t_len] = '\0';
...
Author
Glenn Davis, Ed Hartnett, Dennis Heimbigner

Definition at line 207 of file dattget.c.

◆ nc_get_att_uint()

int nc_get_att_uint ( int  ncid,
int  varid,
const char *  name,
unsigned int *  value 
)

Get an attribute.

This function gets an attribute from the netCDF file. The nc_get_att() function works with any type of data, including user defined types.

Note
The netCDF library reads all attributes into memory when the file is opened with nc_open(). Getting an attribute copies the value from the in-memory store, and does not incur any file I/O penalties.
Parameters
ncidNetCDF or group ID, from a previous call to nc_open(), nc_create(), nc_def_grp(), or associated inquiry functions such as nc_inq_ncid().
varidVariable ID of the attribute's variable, or NC_GLOBAL for a global attribute.
nameAttribute name.
valuePointer to location for returned attribute value(s). All elements of the vector of attribute values are returned, so you must allocate enough space to hold them. If you don't know how much space to reserve, call nc_inq_attlen() first to find out the length of the attribute.
Returns
NC_NOERR for success.
NC_EBADID Bad ncid.
NC_ENOTVAR Bad varid.
NC_EBADNAME Bad name. See NetCDF Names.
NC_EINVAL Invalid parameters.
NC_ENOTATT Can't find attribute.
NC_ECHAR Can't convert to or from NC_CHAR.
NC_ENOMEM Out of memory.
NC_ERANGE Data conversion went out of range.

Example

Here is an example using nc_get_att_double() to determine the values of a variable attribute named valid_range for a netCDF variable named rh and using nc_get_att_text() to read a global attribute named title in an existing netCDF dataset named foo.nc.

In this example, it is assumed that we don't know how many values will be returned, but that we do know the types of the attributes. Hence, to allocate enough space to store them, we must first inquire about the length of the attributes.

#include <netcdf.h>
...
int status;
int ncid;
int rh_id;
int vr_len, t_len;
double *vr_val;
char *title;
extern char *malloc()
...
status = nc_open("foo.nc", NC_NOWRITE, &ncid);
if (status != NC_NOERR) handle_error(status);
...
status = nc_inq_varid (ncid, "rh", &rh_id);
if (status != NC_NOERR) handle_error(status);
...
status = nc_inq_attlen (ncid, rh_id, "valid_range", &vr_len);
if (status != NC_NOERR) handle_error(status);
status = nc_inq_attlen (ncid, NC_GLOBAL, "title", &t_len);
if (status != NC_NOERR) handle_error(status);
vr_val = (double *) malloc(vr_len * sizeof(double));
title = (char *) malloc(t_len + 1);
status = nc_get_att_double(ncid, rh_id, "valid_range", vr_val);
if (status != NC_NOERR) handle_error(status);
status = nc_get_att_text(ncid, NC_GLOBAL, "title", title);
if (status != NC_NOERR) handle_error(status);
title[t_len] = '\0';
...
Author
Glenn Davis, Ed Hartnett, Dennis Heimbigner

Definition at line 287 of file dattget.c.

◆ nc_get_att_ulonglong()

int nc_get_att_ulonglong ( int  ncid,
int  varid,
const char *  name,
unsigned long long *  value 
)

Get an attribute.

This function gets an attribute from the netCDF file. The nc_get_att() function works with any type of data, including user defined types.

Note
The netCDF library reads all attributes into memory when the file is opened with nc_open(). Getting an attribute copies the value from the in-memory store, and does not incur any file I/O penalties.
Parameters
ncidNetCDF or group ID, from a previous call to nc_open(), nc_create(), nc_def_grp(), or associated inquiry functions such as nc_inq_ncid().
varidVariable ID of the attribute's variable, or NC_GLOBAL for a global attribute.
nameAttribute name.
valuePointer to location for returned attribute value(s). All elements of the vector of attribute values are returned, so you must allocate enough space to hold them. If you don't know how much space to reserve, call nc_inq_attlen() first to find out the length of the attribute.
Returns
NC_NOERR for success.
NC_EBADID Bad ncid.
NC_ENOTVAR Bad varid.
NC_EBADNAME Bad name. See NetCDF Names.
NC_EINVAL Invalid parameters.
NC_ENOTATT Can't find attribute.
NC_ECHAR Can't convert to or from NC_CHAR.
NC_ENOMEM Out of memory.
NC_ERANGE Data conversion went out of range.

Example

Here is an example using nc_get_att_double() to determine the values of a variable attribute named valid_range for a netCDF variable named rh and using nc_get_att_text() to read a global attribute named title in an existing netCDF dataset named foo.nc.

In this example, it is assumed that we don't know how many values will be returned, but that we do know the types of the attributes. Hence, to allocate enough space to store them, we must first inquire about the length of the attributes.

#include <netcdf.h>
...
int status;
int ncid;
int rh_id;
int vr_len, t_len;
double *vr_val;
char *title;
extern char *malloc()
...
status = nc_open("foo.nc", NC_NOWRITE, &ncid);
if (status != NC_NOERR) handle_error(status);
...
status = nc_inq_varid (ncid, "rh", &rh_id);
if (status != NC_NOERR) handle_error(status);
...
status = nc_inq_attlen (ncid, rh_id, "valid_range", &vr_len);
if (status != NC_NOERR) handle_error(status);
status = nc_inq_attlen (ncid, NC_GLOBAL, "title", &t_len);
if (status != NC_NOERR) handle_error(status);
vr_val = (double *) malloc(vr_len * sizeof(double));
title = (char *) malloc(t_len + 1);
status = nc_get_att_double(ncid, rh_id, "valid_range", vr_val);
if (status != NC_NOERR) handle_error(status);
status = nc_get_att_text(ncid, NC_GLOBAL, "title", title);
if (status != NC_NOERR) handle_error(status);
title[t_len] = '\0';
...
Author
Glenn Davis, Ed Hartnett, Dennis Heimbigner

Definition at line 307 of file dattget.c.

◆ nc_get_att_ushort()

int nc_get_att_ushort ( int  ncid,
int  varid,
const char *  name,
unsigned short *  value 
)

Get an attribute.

This function gets an attribute from the netCDF file. The nc_get_att() function works with any type of data, including user defined types.

Note
The netCDF library reads all attributes into memory when the file is opened with nc_open(). Getting an attribute copies the value from the in-memory store, and does not incur any file I/O penalties.
Parameters
ncidNetCDF or group ID, from a previous call to nc_open(), nc_create(), nc_def_grp(), or associated inquiry functions such as nc_inq_ncid().
varidVariable ID of the attribute's variable, or NC_GLOBAL for a global attribute.
nameAttribute name.
valuePointer to location for returned attribute value(s). All elements of the vector of attribute values are returned, so you must allocate enough space to hold them. If you don't know how much space to reserve, call nc_inq_attlen() first to find out the length of the attribute.
Returns
NC_NOERR for success.
NC_EBADID Bad ncid.
NC_ENOTVAR Bad varid.
NC_EBADNAME Bad name. See NetCDF Names.
NC_EINVAL Invalid parameters.
NC_ENOTATT Can't find attribute.
NC_ECHAR Can't convert to or from NC_CHAR.
NC_ENOMEM Out of memory.
NC_ERANGE Data conversion went out of range.

Example

Here is an example using nc_get_att_double() to determine the values of a variable attribute named valid_range for a netCDF variable named rh and using nc_get_att_text() to read a global attribute named title in an existing netCDF dataset named foo.nc.

In this example, it is assumed that we don't know how many values will be returned, but that we do know the types of the attributes. Hence, to allocate enough space to store them, we must first inquire about the length of the attributes.

#include <netcdf.h>
...
int status;
int ncid;
int rh_id;
int vr_len, t_len;
double *vr_val;
char *title;
extern char *malloc()
...
status = nc_open("foo.nc", NC_NOWRITE, &ncid);
if (status != NC_NOERR) handle_error(status);
...
status = nc_inq_varid (ncid, "rh", &rh_id);
if (status != NC_NOERR) handle_error(status);
...
status = nc_inq_attlen (ncid, rh_id, "valid_range", &vr_len);
if (status != NC_NOERR) handle_error(status);
status = nc_inq_attlen (ncid, NC_GLOBAL, "title", &t_len);
if (status != NC_NOERR) handle_error(status);
vr_val = (double *) malloc(vr_len * sizeof(double));
title = (char *) malloc(t_len + 1);
status = nc_get_att_double(ncid, rh_id, "valid_range", vr_val);
if (status != NC_NOERR) handle_error(status);
status = nc_get_att_text(ncid, NC_GLOBAL, "title", title);
if (status != NC_NOERR) handle_error(status);
title[t_len] = '\0';
...
Author
Glenn Davis, Ed Hartnett, Dennis Heimbigner

Definition at line 277 of file dattget.c.

◆ nc_inq_att()

int nc_inq_att ( int  ncid,
int  varid,
const char *  name,
nc_type xtypep,
size_t *  lenp 
)

Return information about a netCDF attribute.

The function nc_inq_att returns the attribute's type and length.

Parameters
ncidNetCDF or group ID, from a previous call to nc_open(), nc_create(), nc_def_grp(), or associated inquiry functions such as nc_inq_ncid().
varidVariable ID of the attribute's variable, or NC_GLOBAL for a global attribute.
namePointer to the location for the returned attribute NetCDF Names. Ignored if NULL.
xtypepPointer to location for returned attribute Data Types. Ignored if NULL.
lenpPointer to location for returned number of values currently stored in the attribute. For attributes of type NC_CHAR, you should not assume that this includes a trailing zero byte; it doesn't if the attribute was stored without a trailing zero byte, for example from a FORTRAN program. Before using the value as a C string, make sure it is null-terminated. Ignored if NULL.

Example

Here is an example using nc_inq_att() to find out the type and length of a variable attribute named valid_range for a netCDF variable named rh and a global attribute named title in an existing netCDF dataset named foo.nc:

#include <netcdf.h>
...
int status;
int ncid;
int rh_id;
nc_type vr_type, t_type;
size_t vr_len, t_len;
...
status = nc_open("foo.nc", NC_NOWRITE, &ncid);
if (status != NC_NOERR) handle_error(status);
...
status = nc_inq_varid (ncid, "rh", &rh_id);
if (status != NC_NOERR) handle_error(status);
...
status = nc_inq_att (ncid, rh_id, "valid_range", &vr_type, &vr_len);
if (status != NC_NOERR) handle_error(status);
status = nc_inq_att (ncid, NC_GLOBAL, "title", &t_type, &t_len);
if (status != NC_NOERR) handle_error(status);
Returns
NC_NOERR no error.
NC_EBADID bad ncid.
NC_ENOTVAR bad varid.
NC_EBADGRPID bad group ID.
NC_EBADNAME bad name.
NC_ENOTATT attribute not found.
NC_ECHAR illegal conversion to or from NC_CHAR.
NC_ENOMEM out of memory.
NC_ERANGE range error when converting data.
Author
Glenn Davis, Ed Hartnett, Dennis Heimbigner

Definition at line 83 of file dattinq.c.

◆ nc_inq_attid()

int nc_inq_attid ( int  ncid,
int  varid,
const char *  name,
int *  idp 
)

Find an attribute ID.

Parameters
ncidNetCDF or group ID, from a previous call to nc_open(), nc_create(), nc_def_grp(), or associated inquiry functions such as nc_inq_ncid().
varidVariable ID of the attribute's variable, or NC_GLOBAL for a global attribute.
nameAttribute NetCDF Names.
idpPointer to location for returned attribute number that specifies which attribute this is for this variable (or which global attribute). If you already know the attribute name, knowing its number is not very useful, because accessing information about an attribute requires its name.

Example

Here is an example using nc_inq_attid() from nc_test4/tst_vars2.c. In this example three attributes are created in a file. Then it is re-opened, and their IDs are checked. They will be 0, 1, and 2, in the order that the attributes were written to the file.

#include <netcdf.h>
...
printf("**** testing fill value with three other attributes...");
{
#define NUM_LEADERS 3
char leader[NUM_LEADERS][NC_MAX_NAME + 1] = {"hair_length_of_strategoi",
"hair_length_of_Miltiades",
"hair_length_of_Darius_I"};
short hair_length[NUM_LEADERS] = {3, 11, 4};
short short_in;
int a;
if (nc_create(FILE_NAME, cmode, &ncid)) ERR;
if (nc_def_dim(ncid, DIM1_NAME, DIM1_LEN, &dimids[0])) ERR;
if (nc_def_var(ncid, VAR_NAME, NC_BYTE, NUM_DIMS, dimids, &varid)) ERR;
for (a = 0; a < NUM_LEADERS; a++)
if (nc_put_att_short(ncid, varid, leader[a], NC_SHORT, 1, &hair_length[a])) ERR;
if (nc_put_att_schar(ncid, varid, _FillValue, NC_BYTE, 1, &fill_value)) ERR;
if (nc_close(ncid)) ERR;
if (nc_open(FILE_NAME, NC_NOWRITE, &ncid)) ERR;
for (a = 0; a < NUM_LEADERS; a++)
{
...
if (nc_inq_attid(ncid, 0, leader[a], &attnum_in)) ERR;
if (attnum_in != a) ERR;
}
if (nc_close(ncid)) ERR;
Returns
NC_NOERR no error.
NC_EBADID bad ncid.
NC_ENOTVAR bad varid.
NC_EBADGRPID bad group ID.
NC_EBADNAME bad name.
NC_ENOTATT attribute not found.
NC_ENOMEM out of memory.
Author
Glenn Davis, Ed Hartnett, Dennis Heimbigner

Definition at line 161 of file dattinq.c.

◆ nc_inq_attlen()

int nc_inq_attlen ( int  ncid,
int  varid,
const char *  name,
size_t *  lenp 
)

Find the length of an attribute.

Parameters
ncidNetCDF or group ID, from a previous call to nc_open(), nc_create(), nc_def_grp(), or associated inquiry functions such as nc_inq_ncid().
varidVariable ID of the attribute's variable, or NC_GLOBAL for a global or group attribute.
nameAttribute NetCDF Names.
lenpPointer to location for returned number of values currently stored in the attribute. Before using the value as a C string, make sure it is null-terminated. Ignored if NULL.

Example

Here is an example from nc_test4/tst_h_scalar.c which checks the attributes of an already-open netCDF file. In this code, the length of two attributes are checked, and found to be 1.

#include <netcdf.h>
...
int
check_attrs(int ncid, int obj)
{
int attid;
int natts = 0;
size_t len;
nc_type type;
char *vlstr;
char fixstr[10];
int x;
...
if (nc_inq_attlen(ncid, obj, VSTR_ATT1_NAME, &len)) ERR_GOTO;
if (len != 1) ERR_GOTO;
...
if (nc_inq_attlen(ncid, obj, VSTR_ATT2_NAME, &len)) ERR_GOTO;
if (len != 1) ERR_GOTO;
Returns
NC_NOERR no error.
NC_EBADID bad ncid.
NC_ENOTVAR bad varid.
NC_EBADGRPID bad group ID.
NC_EBADNAME bad name.
NC_ENOTATT attribute not found.
NC_ECHAR illegal conversion to or from NC_CHAR.
NC_ENOMEM out of memory.
NC_ERANGE range error when converting data.
Author
Glenn Davis, Ed Hartnett, Dennis Heimbigner

Definition at line 425 of file dattinq.c.

◆ nc_inq_attname()

int nc_inq_attname ( int  ncid,
int  varid,
int  attnum,
char *  name 
)

Find the name of an attribute.

Parameters
ncidNetCDF or group ID, from a previous call to nc_open(), nc_create(), nc_def_grp(), or associated inquiry functions such as nc_inq_ncid().
varidVariable ID of the attribute's variable, or NC_GLOBAL for a global attribute.
attnumAttribute number. The attributes for each variable are numbered from 0 (the first attribute) to natts-1, where natts is the number of attributes for the variable, as returned from a call to nc_inq_varnatts().
namePointer to the location for the returned attribute NetCDF Names.

Example

Here is an example from nc_test4/tst_atts3.c a variable of every type is added to a file, with names from the 'names' array. Then the file is re-opened, and the names of the attributes are checked in a for loop.

#include <netcdf.h>
...
#define NUM_ATTS 8
#define ATT_MAX_NAME 25
int
tst_att_ordering(int cmode)
{
int ncid;
char name[NUM_ATTS][ATT_MAX_NAME + 1] = {"Gc", "Gb", "Gs", "Gi", "Gf",
"Gd", "Gatt-name-dashes", "Gatt.name.dots"};
int len[NUM_ATTS] = {0, 2, 3, 3, 3, 3, 1, 1};
signed char b[2] = {-128, 127};
short s[3] = {-32768, 0, 32767};
int i[3] = {42, 0, -42};
float f[3] = {42.0, -42.0, 42.0};
double d[3] = {420.0, -420.0, 420.0};
int att_name_dashes = -1, att_name_dots = -2;
char name_in[NC_MAX_NAME];
int j;
if (nc_create(FILE_NAME, cmode, &ncid)) ERR;
...
if (nc_put_att_text(ncid, NC_GLOBAL, name[0], len[0], NULL)) ERR;
if (nc_put_att_schar(ncid, NC_GLOBAL, name[1], NC_BYTE, len[1], b)) ERR;
if (nc_put_att_short(ncid, NC_GLOBAL, name[2], NC_SHORT, len[2], s)) ERR;
if (nc_put_att_int(ncid, NC_GLOBAL, name[3], NC_INT, len[3], i)) ERR;
if (nc_put_att_float(ncid, NC_GLOBAL, name[4], NC_FLOAT, len[4], f)) ERR;
if (nc_put_att_double(ncid, NC_GLOBAL, name[5], NC_DOUBLE, len[5], d)) ERR;
if (nc_put_att_int(ncid, NC_GLOBAL, name[6], NC_INT, len[6], &att_name_dashes)) ERR;
if (nc_put_att_int(ncid, NC_GLOBAL, name[7], NC_INT, len[7], &att_name_dots)) ERR;
if (nc_close(ncid)) ERR;
...
if (nc_open(FILE_NAME, 0, &ncid)) ERR;
for (j = 0; j < NUM_ATTS; j++)
{
if (nc_inq_attname(ncid, NC_GLOBAL, j, name_in)) ERR;
if (strcmp(name_in, name[j])) ERR;
}
if (nc_close(ncid)) ERR;
Returns
NC_NOERR no error.
NC_EBADID bad ncid.
NC_ENOTVAR bad varid.
NC_EBADGRPID bad group ID.
NC_EBADNAME bad name.
NC_ENOTATT attribute not found.
NC_ECHAR illegal conversion to or from NC_CHAR.
NC_ENOMEM out of memory.
NC_ERANGE range error when converting data.
Author
Glenn Davis, Ed Hartnett, Dennis Heimbigner

Definition at line 253 of file dattinq.c.

◆ nc_inq_atttype()

int nc_inq_atttype ( int  ncid,
int  varid,
const char *  name,
nc_type xtypep 
)

Find the type of an attribute.

Parameters
ncidNetCDF or group ID, from a previous call to nc_open(), nc_create(), nc_def_grp(), or associated inquiry functions such as nc_inq_ncid().
varidVariable ID of the attribute's variable, or NC_GLOBAL for a global or group attribute.
nameAttribute NetCDF Names.
xtypepPointer to location for returned attribute Data Types.

Example

Here is an example from nc_test4/tst_h_refs.c. In this example, a file with an integer attribute is open. It's type is confirmed to be NC_INT.

#include <netcdf.h>
...
printf("*** Checking accessing file through netCDF-4 API...");
{
int ncid, varid, attid;
nc_type type;
if (nc_open(FILE_NAME, NC_NOWRITE, &ncid)) ERR;
...
if (nc_inq_atttype(ncid, NC_GLOBAL, INT_ATT_NAME, &type)) ERR;
if (type != NC_INT) ERR;
Returns
NC_NOERR no error.
NC_EBADID bad ncid.
NC_ENOTVAR bad varid.
NC_EBADGRPID bad group ID.
NC_EBADNAME bad name.
NC_ENOTATT attribute not found.
NC_ECHAR illegal conversion to or from NC_CHAR.
NC_ENOMEM out of memory.
NC_ERANGE range error when converting data.
Author
Glenn Davis, Ed Hartnett, Dennis Heimbigner

Definition at line 358 of file dattinq.c.

◆ nc_inq_natts()

int nc_inq_natts ( int  ncid,
int *  nattsp 
)

Find number of global or group attributes.

Parameters
ncidNetCDF or group ID, from a previous call to nc_open(), nc_create(), nc_def_grp(), or associated inquiry functions such as nc_inq_ncid().
nattspPointer where number of global or group attributes will be written. Ignored if NULL.

Example

Here is an example from

#include <netcdf.h>
...
int
check_4D_example(char *file_name, int expected_format)
{
int ncid;
int format, ndims_in, nvars_in, natts_in;
...
if (nc_open(file_name, 0, &ncid)) ERR;
...
if (nc_inq_natts(ncid, &natts_in)) ERR;
if (natts_in != 0) ERR;
Returns
NC_NOERR no error.
NC_EBADID bad ncid.
NC_EBADGRPID bad group ID.
Author
Glenn Davis, Ed Hartnett, Dennis Heimbigner

Definition at line 300 of file dattinq.c.

◆ nc_put_att()

int nc_put_att ( int  ncid,
int  varid,
const char *  name,
nc_type  xtype,
size_t  len,
const void *  value 
)

Write an attribute.

The function nc_put_att_ type adds or changes a variable attribute or global attribute of an open netCDF dataset. If this attribute is new, or if the space required to store the attribute is greater than before, the netCDF dataset must be in define mode for classic formats (or netCDF-4/HDF5 with NC_CLASSIC_MODEL).

With netCDF-4 files, nc_put_att will notice if you are writing a _FillValue attribute, and will tell the HDF5 layer to use the specified fill value for that variable. With either classic or netCDF-4 files, a _FillValue attribute will be checked for validity, to make sure it has only one value and that its type matches the type of the associated variable.

Although it's possible to create attributes of all types, text and double attributes are adequate for most purposes.

Parameters
ncidNetCDF or group ID, from a previous call to nc_open(), nc_create(), nc_def_grp(), or associated inquiry functions such as nc_inq_ncid().
varidVariable ID of the variable to which the attribute will be assigned or NC_GLOBAL for a global or group attribute.
nameAttribute NetCDF Names. Appendix A: Attribute Conventions may apply.
xtypeData Types of the attribute.
lenNumber of values provided for the attribute.
valuePointer to one or more values.
Returns
NC_NOERR No error.
NC_EINVAL More than one value for _FillValue or trying to set global _FillValue.
NC_ENOTVAR Couldn't find varid.
NC_EBADTYPE Fill value and var must be same type.
NC_ENOMEM Out of memory
NC_ELATEFILL Fill values must be written while the file is still in initial define mode.

Example

Here is an example using nc_put_att_double() to add a variable attribute named valid_range for a netCDF variable named rh and nc_put_att_text() to add a global attribute named title to an existing netCDF dataset named foo.nc:

#include <netcdf.h>
...
int status;
int ncid;
int rh_id;
static double rh_range[] = {0.0, 100.0};
static char title[] = "example netCDF dataset";
...
status = nc_open("foo.nc", NC_WRITE, &ncid);
if (status != NC_NOERR) handle_error(status);
...
status = nc_redef(ncid);
if (status != NC_NOERR) handle_error(status);
status = nc_inq_varid (ncid, "rh", &rh_id);
if (status != NC_NOERR) handle_error(status);
...
status = nc_put_att_double (ncid, rh_id, "valid_range",
NC_DOUBLE, 2, rh_range);
if (status != NC_NOERR) handle_error(status);
status = nc_put_att_text (ncid, NC_GLOBAL, "title",
strlen(title), title)
if (status != NC_NOERR) handle_error(status);
...
status = nc_enddef(ncid);
if (status != NC_NOERR) handle_error(status);

Definition at line 231 of file dattput.c.

◆ nc_put_att_double()

int nc_put_att_double ( int  ncid,
int  varid,
const char *  name,
nc_type  xtype,
size_t  len,
const double *  value 
)

Write an attribute.

The function nc_put_att_ type adds or changes a variable attribute or global attribute of an open netCDF dataset. If this attribute is new, or if the space required to store the attribute is greater than before, the netCDF dataset must be in define mode for classic formats (or netCDF-4/HDF5 with NC_CLASSIC_MODEL).

With netCDF-4 files, nc_put_att will notice if you are writing a _FillValue attribute, and will tell the HDF5 layer to use the specified fill value for that variable. With either classic or netCDF-4 files, a _FillValue attribute will be checked for validity, to make sure it has only one value and that its type matches the type of the associated variable.

Although it's possible to create attributes of all types, text and double attributes are adequate for most purposes.

Parameters
ncidNetCDF or group ID, from a previous call to nc_open(), nc_create(), nc_def_grp(), or associated inquiry functions such as nc_inq_ncid().
varidVariable ID of the variable to which the attribute will be assigned or NC_GLOBAL for a global or group attribute.
nameAttribute NetCDF Names. Appendix A: Attribute Conventions may apply.
xtypeData Types of the attribute.
lenNumber of values provided for the attribute.
valuePointer to one or more values.
Returns
NC_NOERR No error.
NC_EINVAL More than one value for _FillValue or trying to set global _FillValue.
NC_ENOTVAR Couldn't find varid.
NC_EBADTYPE Fill value and var must be same type.
NC_ENOMEM Out of memory
NC_ELATEFILL Fill values must be written while the file is still in initial define mode.

Example

Here is an example using nc_put_att_double() to add a variable attribute named valid_range for a netCDF variable named rh and nc_put_att_text() to add a global attribute named title to an existing netCDF dataset named foo.nc:

#include <netcdf.h>
...
int status;
int ncid;
int rh_id;
static double rh_range[] = {0.0, 100.0};
static char title[] = "example netCDF dataset";
...
status = nc_open("foo.nc", NC_WRITE, &ncid);
if (status != NC_NOERR) handle_error(status);
...
status = nc_redef(ncid);
if (status != NC_NOERR) handle_error(status);
status = nc_inq_varid (ncid, "rh", &rh_id);
if (status != NC_NOERR) handle_error(status);
...
status = nc_put_att_double (ncid, rh_id, "valid_range",
NC_DOUBLE, 2, rh_range);
if (status != NC_NOERR) handle_error(status);
status = nc_put_att_text (ncid, NC_GLOBAL, "title",
strlen(title), title)
if (status != NC_NOERR) handle_error(status);
...
status = nc_enddef(ncid);
if (status != NC_NOERR) handle_error(status);

Definition at line 308 of file dattput.c.

◆ nc_put_att_float()

int nc_put_att_float ( int  ncid,
int  varid,
const char *  name,
nc_type  xtype,
size_t  len,
const float *  value 
)

Write an attribute.

The function nc_put_att_ type adds or changes a variable attribute or global attribute of an open netCDF dataset. If this attribute is new, or if the space required to store the attribute is greater than before, the netCDF dataset must be in define mode for classic formats (or netCDF-4/HDF5 with NC_CLASSIC_MODEL).

With netCDF-4 files, nc_put_att will notice if you are writing a _FillValue attribute, and will tell the HDF5 layer to use the specified fill value for that variable. With either classic or netCDF-4 files, a _FillValue attribute will be checked for validity, to make sure it has only one value and that its type matches the type of the associated variable.

Although it's possible to create attributes of all types, text and double attributes are adequate for most purposes.

Parameters
ncidNetCDF or group ID, from a previous call to nc_open(), nc_create(), nc_def_grp(), or associated inquiry functions such as nc_inq_ncid().
varidVariable ID of the variable to which the attribute will be assigned or NC_GLOBAL for a global or group attribute.
nameAttribute NetCDF Names. Appendix A: Attribute Conventions may apply.
xtypeData Types of the attribute.
lenNumber of values provided for the attribute.
valuePointer to one or more values.
Returns
NC_NOERR No error.
NC_EINVAL More than one value for _FillValue or trying to set global _FillValue.
NC_ENOTVAR Couldn't find varid.
NC_EBADTYPE Fill value and var must be same type.
NC_ENOMEM Out of memory
NC_ELATEFILL Fill values must be written while the file is still in initial define mode.

Example

Here is an example using nc_put_att_double() to add a variable attribute named valid_range for a netCDF variable named rh and nc_put_att_text() to add a global attribute named title to an existing netCDF dataset named foo.nc:

#include <netcdf.h>
...
int status;
int ncid;
int rh_id;
static double rh_range[] = {0.0, 100.0};
static char title[] = "example netCDF dataset";
...
status = nc_open("foo.nc", NC_WRITE, &ncid);
if (status != NC_NOERR) handle_error(status);
...
status = nc_redef(ncid);
if (status != NC_NOERR) handle_error(status);
status = nc_inq_varid (ncid, "rh", &rh_id);
if (status != NC_NOERR) handle_error(status);
...
status = nc_put_att_double (ncid, rh_id, "valid_range",
NC_DOUBLE, 2, rh_range);
if (status != NC_NOERR) handle_error(status);
status = nc_put_att_text (ncid, NC_GLOBAL, "title",
strlen(title), title)
if (status != NC_NOERR) handle_error(status);
...
status = nc_enddef(ncid);
if (status != NC_NOERR) handle_error(status);

Definition at line 297 of file dattput.c.

◆ nc_put_att_int()

int nc_put_att_int ( int  ncid,
int  varid,
const char *  name,
nc_type  xtype,
size_t  len,
const int *  value 
)

Write an attribute.

The function nc_put_att_ type adds or changes a variable attribute or global attribute of an open netCDF dataset. If this attribute is new, or if the space required to store the attribute is greater than before, the netCDF dataset must be in define mode for classic formats (or netCDF-4/HDF5 with NC_CLASSIC_MODEL).

With netCDF-4 files, nc_put_att will notice if you are writing a _FillValue attribute, and will tell the HDF5 layer to use the specified fill value for that variable. With either classic or netCDF-4 files, a _FillValue attribute will be checked for validity, to make sure it has only one value and that its type matches the type of the associated variable.

Although it's possible to create attributes of all types, text and double attributes are adequate for most purposes.

Parameters
ncidNetCDF or group ID, from a previous call to nc_open(), nc_create(), nc_def_grp(), or associated inquiry functions such as nc_inq_ncid().
varidVariable ID of the variable to which the attribute will be assigned or NC_GLOBAL for a global or group attribute.
nameAttribute NetCDF Names. Appendix A: Attribute Conventions may apply.
xtypeData Types of the attribute.
lenNumber of values provided for the attribute.
valuePointer to one or more values.
Returns
NC_NOERR No error.
NC_EINVAL More than one value for _FillValue or trying to set global _FillValue.
NC_ENOTVAR Couldn't find varid.
NC_EBADTYPE Fill value and var must be same type.
NC_ENOMEM Out of memory
NC_ELATEFILL Fill values must be written while the file is still in initial define mode.

Example

Here is an example using nc_put_att_double() to add a variable attribute named valid_range for a netCDF variable named rh and nc_put_att_text() to add a global attribute named title to an existing netCDF dataset named foo.nc:

#include <netcdf.h>
...
int status;
int ncid;
int rh_id;
static double rh_range[] = {0.0, 100.0};
static char title[] = "example netCDF dataset";
...
status = nc_open("foo.nc", NC_WRITE, &ncid);
if (status != NC_NOERR) handle_error(status);
...
status = nc_redef(ncid);
if (status != NC_NOERR) handle_error(status);
status = nc_inq_varid (ncid, "rh", &rh_id);
if (status != NC_NOERR) handle_error(status);
...
status = nc_put_att_double (ncid, rh_id, "valid_range",
NC_DOUBLE, 2, rh_range);
if (status != NC_NOERR) handle_error(status);
status = nc_put_att_text (ncid, NC_GLOBAL, "title",
strlen(title), title)
if (status != NC_NOERR) handle_error(status);
...
status = nc_enddef(ncid);
if (status != NC_NOERR) handle_error(status);

Definition at line 275 of file dattput.c.

◆ nc_put_att_long()

int nc_put_att_long ( int  ncid,
int  varid,
const char *  name,
nc_type  xtype,
size_t  len,
const long *  value 
)

Write an attribute.

The function nc_put_att_ type adds or changes a variable attribute or global attribute of an open netCDF dataset. If this attribute is new, or if the space required to store the attribute is greater than before, the netCDF dataset must be in define mode for classic formats (or netCDF-4/HDF5 with NC_CLASSIC_MODEL).

With netCDF-4 files, nc_put_att will notice if you are writing a _FillValue attribute, and will tell the HDF5 layer to use the specified fill value for that variable. With either classic or netCDF-4 files, a _FillValue attribute will be checked for validity, to make sure it has only one value and that its type matches the type of the associated variable.

Although it's possible to create attributes of all types, text and double attributes are adequate for most purposes.

Parameters
ncidNetCDF or group ID, from a previous call to nc_open(), nc_create(), nc_def_grp(), or associated inquiry functions such as nc_inq_ncid().
varidVariable ID of the variable to which the attribute will be assigned or NC_GLOBAL for a global or group attribute.
nameAttribute NetCDF Names. Appendix A: Attribute Conventions may apply.
xtypeData Types of the attribute.
lenNumber of values provided for the attribute.
valuePointer to one or more values.
Returns
NC_NOERR No error.
NC_EINVAL More than one value for _FillValue or trying to set global _FillValue.
NC_ENOTVAR Couldn't find varid.
NC_EBADTYPE Fill value and var must be same type.
NC_ENOMEM Out of memory
NC_ELATEFILL Fill values must be written while the file is still in initial define mode.

Example

Here is an example using nc_put_att_double() to add a variable attribute named valid_range for a netCDF variable named rh and nc_put_att_text() to add a global attribute named title to an existing netCDF dataset named foo.nc:

#include <netcdf.h>
...
int status;
int ncid;
int rh_id;
static double rh_range[] = {0.0, 100.0};
static char title[] = "example netCDF dataset";
...
status = nc_open("foo.nc", NC_WRITE, &ncid);
if (status != NC_NOERR) handle_error(status);
...
status = nc_redef(ncid);
if (status != NC_NOERR) handle_error(status);
status = nc_inq_varid (ncid, "rh", &rh_id);
if (status != NC_NOERR) handle_error(status);
...
status = nc_put_att_double (ncid, rh_id, "valid_range",
NC_DOUBLE, 2, rh_range);
if (status != NC_NOERR) handle_error(status);
status = nc_put_att_text (ncid, NC_GLOBAL, "title",
strlen(title), title)
if (status != NC_NOERR) handle_error(status);
...
status = nc_enddef(ncid);
if (status != NC_NOERR) handle_error(status);

Definition at line 286 of file dattput.c.

◆ nc_put_att_longlong()

int nc_put_att_longlong ( int  ncid,
int  varid,
const char *  name,
nc_type  xtype,
size_t  len,
const long long *  value 
)

Write an attribute.

The function nc_put_att_ type adds or changes a variable attribute or global attribute of an open netCDF dataset. If this attribute is new, or if the space required to store the attribute is greater than before, the netCDF dataset must be in define mode for classic formats (or netCDF-4/HDF5 with NC_CLASSIC_MODEL).

With netCDF-4 files, nc_put_att will notice if you are writing a _FillValue attribute, and will tell the HDF5 layer to use the specified fill value for that variable. With either classic or netCDF-4 files, a _FillValue attribute will be checked for validity, to make sure it has only one value and that its type matches the type of the associated variable.

Although it's possible to create attributes of all types, text and double attributes are adequate for most purposes.

Parameters
ncidNetCDF or group ID, from a previous call to nc_open(), nc_create(), nc_def_grp(), or associated inquiry functions such as nc_inq_ncid().
varidVariable ID of the variable to which the attribute will be assigned or NC_GLOBAL for a global or group attribute.
nameAttribute NetCDF Names. Appendix A: Attribute Conventions may apply.
xtypeData Types of the attribute.
lenNumber of values provided for the attribute.
valuePointer to one or more values.
Returns
NC_NOERR No error.
NC_EINVAL More than one value for _FillValue or trying to set global _FillValue.
NC_ENOTVAR Couldn't find varid.
NC_EBADTYPE Fill value and var must be same type.
NC_ENOMEM Out of memory
NC_ELATEFILL Fill values must be written while the file is still in initial define mode.

Example

Here is an example using nc_put_att_double() to add a variable attribute named valid_range for a netCDF variable named rh and nc_put_att_text() to add a global attribute named title to an existing netCDF dataset named foo.nc:

#include <netcdf.h>
...
int status;
int ncid;
int rh_id;
static double rh_range[] = {0.0, 100.0};
static char title[] = "example netCDF dataset";
...
status = nc_open("foo.nc", NC_WRITE, &ncid);
if (status != NC_NOERR) handle_error(status);
...
status = nc_redef(ncid);
if (status != NC_NOERR) handle_error(status);
status = nc_inq_varid (ncid, "rh", &rh_id);
if (status != NC_NOERR) handle_error(status);
...
status = nc_put_att_double (ncid, rh_id, "valid_range",
NC_DOUBLE, 2, rh_range);
if (status != NC_NOERR) handle_error(status);
status = nc_put_att_text (ncid, NC_GLOBAL, "title",
strlen(title), title)
if (status != NC_NOERR) handle_error(status);
...
status = nc_enddef(ncid);
if (status != NC_NOERR) handle_error(status);

Definition at line 352 of file dattput.c.

◆ nc_put_att_schar()

int nc_put_att_schar ( int  ncid,
int  varid,
const char *  name,
nc_type  xtype,
size_t  len,
const signed char *  value 
)

Write an attribute.

The function nc_put_att_ type adds or changes a variable attribute or global attribute of an open netCDF dataset. If this attribute is new, or if the space required to store the attribute is greater than before, the netCDF dataset must be in define mode for classic formats (or netCDF-4/HDF5 with NC_CLASSIC_MODEL).

With netCDF-4 files, nc_put_att will notice if you are writing a _FillValue attribute, and will tell the HDF5 layer to use the specified fill value for that variable. With either classic or netCDF-4 files, a _FillValue attribute will be checked for validity, to make sure it has only one value and that its type matches the type of the associated variable.

Although it's possible to create attributes of all types, text and double attributes are adequate for most purposes.

Parameters
ncidNetCDF or group ID, from a previous call to nc_open(), nc_create(), nc_def_grp(), or associated inquiry functions such as nc_inq_ncid().
varidVariable ID of the variable to which the attribute will be assigned or NC_GLOBAL for a global or group attribute.
nameAttribute NetCDF Names. Appendix A: Attribute Conventions may apply.
xtypeData Types of the attribute.
lenNumber of values provided for the attribute.
valuePointer to one or more values.
Returns
NC_NOERR No error.
NC_EINVAL More than one value for _FillValue or trying to set global _FillValue.
NC_ENOTVAR Couldn't find varid.
NC_EBADTYPE Fill value and var must be same type.
NC_ENOMEM Out of memory
NC_ELATEFILL Fill values must be written while the file is still in initial define mode.

Example

Here is an example using nc_put_att_double() to add a variable attribute named valid_range for a netCDF variable named rh and nc_put_att_text() to add a global attribute named title to an existing netCDF dataset named foo.nc:

#include <netcdf.h>
...
int status;
int ncid;
int rh_id;
static double rh_range[] = {0.0, 100.0};
static char title[] = "example netCDF dataset";
...
status = nc_open("foo.nc", NC_WRITE, &ncid);
if (status != NC_NOERR) handle_error(status);
...
status = nc_redef(ncid);
if (status != NC_NOERR) handle_error(status);
status = nc_inq_varid (ncid, "rh", &rh_id);
if (status != NC_NOERR) handle_error(status);
...
status = nc_put_att_double (ncid, rh_id, "valid_range",
NC_DOUBLE, 2, rh_range);
if (status != NC_NOERR) handle_error(status);
status = nc_put_att_text (ncid, NC_GLOBAL, "title",
strlen(title), title)
if (status != NC_NOERR) handle_error(status);
...
status = nc_enddef(ncid);
if (status != NC_NOERR) handle_error(status);

Definition at line 242 of file dattput.c.

◆ nc_put_att_short()

int nc_put_att_short ( int  ncid,
int  varid,
const char *  name,
nc_type  xtype,
size_t  len,
const short *  value 
)

Write an attribute.

The function nc_put_att_ type adds or changes a variable attribute or global attribute of an open netCDF dataset. If this attribute is new, or if the space required to store the attribute is greater than before, the netCDF dataset must be in define mode for classic formats (or netCDF-4/HDF5 with NC_CLASSIC_MODEL).

With netCDF-4 files, nc_put_att will notice if you are writing a _FillValue attribute, and will tell the HDF5 layer to use the specified fill value for that variable. With either classic or netCDF-4 files, a _FillValue attribute will be checked for validity, to make sure it has only one value and that its type matches the type of the associated variable.

Although it's possible to create attributes of all types, text and double attributes are adequate for most purposes.

Parameters
ncidNetCDF or group ID, from a previous call to nc_open(), nc_create(), nc_def_grp(), or associated inquiry functions such as nc_inq_ncid().
varidVariable ID of the variable to which the attribute will be assigned or NC_GLOBAL for a global or group attribute.
nameAttribute NetCDF Names. Appendix A: Attribute Conventions may apply.
xtypeData Types of the attribute.
lenNumber of values provided for the attribute.
valuePointer to one or more values.
Returns
NC_NOERR No error.
NC_EINVAL More than one value for _FillValue or trying to set global _FillValue.
NC_ENOTVAR Couldn't find varid.
NC_EBADTYPE Fill value and var must be same type.
NC_ENOMEM Out of memory
NC_ELATEFILL Fill values must be written while the file is still in initial define mode.

Example

Here is an example using nc_put_att_double() to add a variable attribute named valid_range for a netCDF variable named rh and nc_put_att_text() to add a global attribute named title to an existing netCDF dataset named foo.nc:

#include <netcdf.h>
...
int status;
int ncid;
int rh_id;
static double rh_range[] = {0.0, 100.0};
static char title[] = "example netCDF dataset";
...
status = nc_open("foo.nc", NC_WRITE, &ncid);
if (status != NC_NOERR) handle_error(status);
...
status = nc_redef(ncid);
if (status != NC_NOERR) handle_error(status);
status = nc_inq_varid (ncid, "rh", &rh_id);
if (status != NC_NOERR) handle_error(status);
...
status = nc_put_att_double (ncid, rh_id, "valid_range",
NC_DOUBLE, 2, rh_range);
if (status != NC_NOERR) handle_error(status);
status = nc_put_att_text (ncid, NC_GLOBAL, "title",
strlen(title), title)
if (status != NC_NOERR) handle_error(status);
...
status = nc_enddef(ncid);
if (status != NC_NOERR) handle_error(status);

Definition at line 264 of file dattput.c.

◆ nc_put_att_string()

int nc_put_att_string ( int  ncid,
int  varid,
const char *  name,
size_t  len,
const char **  value 
)

Write a string attribute.

The function nc_put_att_string adds or changes a variable attribute or global attribute of an open netCDF dataset. The string type is only available in netCDF-4/HDF5 files, when NC_CLASSIC_MODEL has not been used in nc_create().

Parameters
ncidNetCDF or group ID, from a previous call to nc_open(), nc_create(), nc_def_grp(), or associated inquiry functions such as nc_inq_ncid().
varidVariable ID of the variable to which the attribute will be assigned or NC_GLOBAL for a global or group attribute.
nameAttribute NetCDF Names. Appendix A: Attribute Conventions may apply.
lenNumber of values provided for the attribute.
valuePointer to one or more values.
Returns
NC_NOERR No error.
NC_EINVAL More than one value for _FillValue or trying to set global _FillValue.
NC_ENOTVAR Couldn't find varid.
NC_EBADTYPE Fill value and var must be same type.
NC_ENOMEM Out of memory
NC_ELATEFILL Fill values must be written while the file is still in initial define mode.

Definition at line 50 of file dattput.c.

◆ nc_put_att_text()

int nc_put_att_text ( int  ncid,
int  varid,
const char *  name,
size_t  len,
const char *  value 
)

Write a text attribute.

Add or change a text attribute. If this attribute is new, or if the space required to store the attribute is greater than before, the netCDF dataset must be in define mode for classic formats (or netCDF-4/HDF5 with NC_CLASSIC_MODEL).

Although it's possible to create attributes of all types, text and double attributes are adequate for most purposes.

Use the nc_put_att function to create attributes of any type, including user-defined types. We recommend using the type safe versions of this function whenever possible.

Parameters
ncidNetCDF or group ID, from a previous call to nc_open(), nc_create(), nc_def_grp(), or associated inquiry functions such as nc_inq_ncid().
varidVariable ID of the variable to which the attribute will be assigned or NC_GLOBAL for a global attribute.
nameAttribute NetCDF Names. Appendix A: Attribute Conventions may apply.
lenNumber of values provided for the attribute.
valuePointer to one or more values.
Returns
NC_NOERR No error.
NC_EINVAL More than one value for _FillValue or trying to set global _FillValue.
NC_ENOTVAR Couldn't find varid.
NC_EBADTYPE Fill value and var must be same type.
NC_ENOMEM Out of memory
NC_ELATEFILL Fill values must be written while the file is still in initial define mode.
Note
With netCDF-4 files, nc_put_att will notice if you are writing a Fill_Value attribute, and will tell the HDF5 layer to use the specified fill value for that variable.

Example

Here is an example using nc_put_att_double() to add a variable attribute named valid_range for a netCDF variable named rh and nc_put_att_text() to add a global attribute named title to an existing netCDF dataset named foo.nc:

#include <netcdf.h>
...
int status;
int ncid;
int rh_id;
static double rh_range[] = {0.0, 100.0};
static char title[] = "example netCDF dataset";
...
status = nc_open("foo.nc", NC_WRITE, &ncid);
if (status != NC_NOERR) handle_error(status);
...
status = nc_redef(ncid);
if (status != NC_NOERR) handle_error(status);
status = nc_inq_varid (ncid, "rh", &rh_id);
if (status != NC_NOERR) handle_error(status);
...
status = nc_put_att_double (ncid, rh_id, "valid_range",
NC_DOUBLE, 2, rh_range);
if (status != NC_NOERR) handle_error(status);
status = nc_put_att_text (ncid, NC_GLOBAL, "title",
strlen(title), title)
if (status != NC_NOERR) handle_error(status);
...
status = nc_enddef(ncid);
if (status != NC_NOERR) handle_error(status);

Definition at line 139 of file dattput.c.

◆ nc_put_att_ubyte()

int nc_put_att_ubyte ( int  ncid,
int  varid,
const char *  name,
nc_type  xtype,
size_t  len,
const unsigned char *  value 
)

Write an attribute.

The function nc_put_att_ type adds or changes a variable attribute or global attribute of an open netCDF dataset. If this attribute is new, or if the space required to store the attribute is greater than before, the netCDF dataset must be in define mode for classic formats (or netCDF-4/HDF5 with NC_CLASSIC_MODEL).

With netCDF-4 files, nc_put_att will notice if you are writing a _FillValue attribute, and will tell the HDF5 layer to use the specified fill value for that variable. With either classic or netCDF-4 files, a _FillValue attribute will be checked for validity, to make sure it has only one value and that its type matches the type of the associated variable.

Although it's possible to create attributes of all types, text and double attributes are adequate for most purposes.

Parameters
ncidNetCDF or group ID, from a previous call to nc_open(), nc_create(), nc_def_grp(), or associated inquiry functions such as nc_inq_ncid().
varidVariable ID of the variable to which the attribute will be assigned or NC_GLOBAL for a global or group attribute.
nameAttribute NetCDF Names. Appendix A: Attribute Conventions may apply.
xtypeData Types of the attribute.
lenNumber of values provided for the attribute.
valuePointer to one or more values.
Returns
NC_NOERR No error.
NC_EINVAL More than one value for _FillValue or trying to set global _FillValue.
NC_ENOTVAR Couldn't find varid.
NC_EBADTYPE Fill value and var must be same type.
NC_ENOMEM Out of memory
NC_ELATEFILL Fill values must be written while the file is still in initial define mode.

Example

Here is an example using nc_put_att_double() to add a variable attribute named valid_range for a netCDF variable named rh and nc_put_att_text() to add a global attribute named title to an existing netCDF dataset named foo.nc:

#include <netcdf.h>
...
int status;
int ncid;
int rh_id;
static double rh_range[] = {0.0, 100.0};
static char title[] = "example netCDF dataset";
...
status = nc_open("foo.nc", NC_WRITE, &ncid);
if (status != NC_NOERR) handle_error(status);
...
status = nc_redef(ncid);
if (status != NC_NOERR) handle_error(status);
status = nc_inq_varid (ncid, "rh", &rh_id);
if (status != NC_NOERR) handle_error(status);
...
status = nc_put_att_double (ncid, rh_id, "valid_range",
NC_DOUBLE, 2, rh_range);
if (status != NC_NOERR) handle_error(status);
status = nc_put_att_text (ncid, NC_GLOBAL, "title",
strlen(title), title)
if (status != NC_NOERR) handle_error(status);
...
status = nc_enddef(ncid);
if (status != NC_NOERR) handle_error(status);

Definition at line 319 of file dattput.c.

◆ nc_put_att_uchar()

int nc_put_att_uchar ( int  ncid,
int  varid,
const char *  name,
nc_type  xtype,
size_t  len,
const unsigned char *  value 
)

Write an attribute.

The function nc_put_att_ type adds or changes a variable attribute or global attribute of an open netCDF dataset. If this attribute is new, or if the space required to store the attribute is greater than before, the netCDF dataset must be in define mode for classic formats (or netCDF-4/HDF5 with NC_CLASSIC_MODEL).

With netCDF-4 files, nc_put_att will notice if you are writing a _FillValue attribute, and will tell the HDF5 layer to use the specified fill value for that variable. With either classic or netCDF-4 files, a _FillValue attribute will be checked for validity, to make sure it has only one value and that its type matches the type of the associated variable.

Although it's possible to create attributes of all types, text and double attributes are adequate for most purposes.

Parameters
ncidNetCDF or group ID, from a previous call to nc_open(), nc_create(), nc_def_grp(), or associated inquiry functions such as nc_inq_ncid().
varidVariable ID of the variable to which the attribute will be assigned or NC_GLOBAL for a global or group attribute.
nameAttribute NetCDF Names. Appendix A: Attribute Conventions may apply.
xtypeData Types of the attribute.
lenNumber of values provided for the attribute.
valuePointer to one or more values.
Returns
NC_NOERR No error.
NC_EINVAL More than one value for _FillValue or trying to set global _FillValue.
NC_ENOTVAR Couldn't find varid.
NC_EBADTYPE Fill value and var must be same type.
NC_ENOMEM Out of memory
NC_ELATEFILL Fill values must be written while the file is still in initial define mode.

Example

Here is an example using nc_put_att_double() to add a variable attribute named valid_range for a netCDF variable named rh and nc_put_att_text() to add a global attribute named title to an existing netCDF dataset named foo.nc:

#include <netcdf.h>
...
int status;
int ncid;
int rh_id;
static double rh_range[] = {0.0, 100.0};
static char title[] = "example netCDF dataset";
...
status = nc_open("foo.nc", NC_WRITE, &ncid);
if (status != NC_NOERR) handle_error(status);
...
status = nc_redef(ncid);
if (status != NC_NOERR) handle_error(status);
status = nc_inq_varid (ncid, "rh", &rh_id);
if (status != NC_NOERR) handle_error(status);
...
status = nc_put_att_double (ncid, rh_id, "valid_range",
NC_DOUBLE, 2, rh_range);
if (status != NC_NOERR) handle_error(status);
status = nc_put_att_text (ncid, NC_GLOBAL, "title",
strlen(title), title)
if (status != NC_NOERR) handle_error(status);
...
status = nc_enddef(ncid);
if (status != NC_NOERR) handle_error(status);

Definition at line 253 of file dattput.c.

◆ nc_put_att_uint()

int nc_put_att_uint ( int  ncid,
int  varid,
const char *  name,
nc_type  xtype,
size_t  len,
const unsigned int *  value 
)

Write an attribute.

The function nc_put_att_ type adds or changes a variable attribute or global attribute of an open netCDF dataset. If this attribute is new, or if the space required to store the attribute is greater than before, the netCDF dataset must be in define mode for classic formats (or netCDF-4/HDF5 with NC_CLASSIC_MODEL).

With netCDF-4 files, nc_put_att will notice if you are writing a _FillValue attribute, and will tell the HDF5 layer to use the specified fill value for that variable. With either classic or netCDF-4 files, a _FillValue attribute will be checked for validity, to make sure it has only one value and that its type matches the type of the associated variable.

Although it's possible to create attributes of all types, text and double attributes are adequate for most purposes.

Parameters
ncidNetCDF or group ID, from a previous call to nc_open(), nc_create(), nc_def_grp(), or associated inquiry functions such as nc_inq_ncid().
varidVariable ID of the variable to which the attribute will be assigned or NC_GLOBAL for a global or group attribute.
nameAttribute NetCDF Names. Appendix A: Attribute Conventions may apply.
xtypeData Types of the attribute.
lenNumber of values provided for the attribute.
valuePointer to one or more values.
Returns
NC_NOERR No error.
NC_EINVAL More than one value for _FillValue or trying to set global _FillValue.
NC_ENOTVAR Couldn't find varid.
NC_EBADTYPE Fill value and var must be same type.
NC_ENOMEM Out of memory
NC_ELATEFILL Fill values must be written while the file is still in initial define mode.

Example

Here is an example using nc_put_att_double() to add a variable attribute named valid_range for a netCDF variable named rh and nc_put_att_text() to add a global attribute named title to an existing netCDF dataset named foo.nc:

#include <netcdf.h>
...
int status;
int ncid;
int rh_id;
static double rh_range[] = {0.0, 100.0};
static char title[] = "example netCDF dataset";
...
status = nc_open("foo.nc", NC_WRITE, &ncid);
if (status != NC_NOERR) handle_error(status);
...
status = nc_redef(ncid);
if (status != NC_NOERR) handle_error(status);
status = nc_inq_varid (ncid, "rh", &rh_id);
if (status != NC_NOERR) handle_error(status);
...
status = nc_put_att_double (ncid, rh_id, "valid_range",
NC_DOUBLE, 2, rh_range);
if (status != NC_NOERR) handle_error(status);
status = nc_put_att_text (ncid, NC_GLOBAL, "title",
strlen(title), title)
if (status != NC_NOERR) handle_error(status);
...
status = nc_enddef(ncid);
if (status != NC_NOERR) handle_error(status);

Definition at line 341 of file dattput.c.

◆ nc_put_att_ulonglong()

int nc_put_att_ulonglong ( int  ncid,
int  varid,
const char *  name,
nc_type  xtype,
size_t  len,
const unsigned long long *  value 
)

Write an attribute.

The function nc_put_att_ type adds or changes a variable attribute or global attribute of an open netCDF dataset. If this attribute is new, or if the space required to store the attribute is greater than before, the netCDF dataset must be in define mode for classic formats (or netCDF-4/HDF5 with NC_CLASSIC_MODEL).

With netCDF-4 files, nc_put_att will notice if you are writing a _FillValue attribute, and will tell the HDF5 layer to use the specified fill value for that variable. With either classic or netCDF-4 files, a _FillValue attribute will be checked for validity, to make sure it has only one value and that its type matches the type of the associated variable.

Although it's possible to create attributes of all types, text and double attributes are adequate for most purposes.

Parameters
ncidNetCDF or group ID, from a previous call to nc_open(), nc_create(), nc_def_grp(), or associated inquiry functions such as nc_inq_ncid().
varidVariable ID of the variable to which the attribute will be assigned or NC_GLOBAL for a global or group attribute.
nameAttribute NetCDF Names. Appendix A: Attribute Conventions may apply.
xtypeData Types of the attribute.
lenNumber of values provided for the attribute.
valuePointer to one or more values.
Returns
NC_NOERR No error.
NC_EINVAL More than one value for _FillValue or trying to set global _FillValue.
NC_ENOTVAR Couldn't find varid.
NC_EBADTYPE Fill value and var must be same type.
NC_ENOMEM Out of memory
NC_ELATEFILL Fill values must be written while the file is still in initial define mode.

Example

Here is an example using nc_put_att_double() to add a variable attribute named valid_range for a netCDF variable named rh and nc_put_att_text() to add a global attribute named title to an existing netCDF dataset named foo.nc:

#include <netcdf.h>
...
int status;
int ncid;
int rh_id;
static double rh_range[] = {0.0, 100.0};
static char title[] = "example netCDF dataset";
...
status = nc_open("foo.nc", NC_WRITE, &ncid);
if (status != NC_NOERR) handle_error(status);
...
status = nc_redef(ncid);
if (status != NC_NOERR) handle_error(status);
status = nc_inq_varid (ncid, "rh", &rh_id);
if (status != NC_NOERR) handle_error(status);
...
status = nc_put_att_double (ncid, rh_id, "valid_range",
NC_DOUBLE, 2, rh_range);
if (status != NC_NOERR) handle_error(status);
status = nc_put_att_text (ncid, NC_GLOBAL, "title",
strlen(title), title)
if (status != NC_NOERR) handle_error(status);
...
status = nc_enddef(ncid);
if (status != NC_NOERR) handle_error(status);

Definition at line 364 of file dattput.c.

◆ nc_put_att_ushort()

int nc_put_att_ushort ( int  ncid,
int  varid,
const char *  name,
nc_type  xtype,
size_t  len,
const unsigned short *  value 
)

Write an attribute.

The function nc_put_att_ type adds or changes a variable attribute or global attribute of an open netCDF dataset. If this attribute is new, or if the space required to store the attribute is greater than before, the netCDF dataset must be in define mode for classic formats (or netCDF-4/HDF5 with NC_CLASSIC_MODEL).

With netCDF-4 files, nc_put_att will notice if you are writing a _FillValue attribute, and will tell the HDF5 layer to use the specified fill value for that variable. With either classic or netCDF-4 files, a _FillValue attribute will be checked for validity, to make sure it has only one value and that its type matches the type of the associated variable.

Although it's possible to create attributes of all types, text and double attributes are adequate for most purposes.

Parameters
ncidNetCDF or group ID, from a previous call to nc_open(), nc_create(), nc_def_grp(), or associated inquiry functions such as nc_inq_ncid().
varidVariable ID of the variable to which the attribute will be assigned or NC_GLOBAL for a global or group attribute.
nameAttribute NetCDF Names. Appendix A: Attribute Conventions may apply.
xtypeData Types of the attribute.
lenNumber of values provided for the attribute.
valuePointer to one or more values.
Returns
NC_NOERR No error.
NC_EINVAL More than one value for _FillValue or trying to set global _FillValue.
NC_ENOTVAR Couldn't find varid.
NC_EBADTYPE Fill value and var must be same type.
NC_ENOMEM Out of memory
NC_ELATEFILL Fill values must be written while the file is still in initial define mode.

Example

Here is an example using nc_put_att_double() to add a variable attribute named valid_range for a netCDF variable named rh and nc_put_att_text() to add a global attribute named title to an existing netCDF dataset named foo.nc:

#include <netcdf.h>
...
int status;
int ncid;
int rh_id;
static double rh_range[] = {0.0, 100.0};
static char title[] = "example netCDF dataset";
...
status = nc_open("foo.nc", NC_WRITE, &ncid);
if (status != NC_NOERR) handle_error(status);
...
status = nc_redef(ncid);
if (status != NC_NOERR) handle_error(status);
status = nc_inq_varid (ncid, "rh", &rh_id);
if (status != NC_NOERR) handle_error(status);
...
status = nc_put_att_double (ncid, rh_id, "valid_range",
NC_DOUBLE, 2, rh_range);
if (status != NC_NOERR) handle_error(status);
status = nc_put_att_text (ncid, NC_GLOBAL, "title",
strlen(title), title)
if (status != NC_NOERR) handle_error(status);
...
status = nc_enddef(ncid);
if (status != NC_NOERR) handle_error(status);

Definition at line 330 of file dattput.c.

◆ nc_rename_att()

int nc_rename_att ( int  ncid,
int  varid,
const char *  name,
const char *  newname 
)

Rename an attribute.

The function nc_rename_att() changes the name of an attribute. If the new name is longer than the original name, the netCDF dataset must be in define mode. You cannot rename an attribute to have the same name as another attribute of the same variable.

Parameters
ncidNetCDF or group ID, from a previous call to nc_open(), nc_create(), nc_def_grp(), or associated inquiry functions such as nc_inq_ncid().
varidVariable ID of the attribute's variable, or NC_GLOBAL for a global attribute.
nameAttribute NetCDF Names.
newnameThe new attribute NetCDF Names.

Example

Here is an example using nc_rename_att() to rename the variable attribute units to Units for a variable rh in an existing netCDF dataset named foo.nc:

#include <netcdf.h>
...
int status;
int ncid;
int rh_id;
...
status = nc_open("foo.nc", NC_NOWRITE, &ncid);
if (status != NC_NOERR) handle_error(status);
...
status = nc_inq_varid (ncid, "rh", &rh_id);
if (status != NC_NOERR) handle_error(status);
...
status = nc_rename_att(ncid, rh_id, "units", "Units");
if (status != NC_NOERR) handle_error(status);
Returns
NC_NOERR No error.
NC_EBADID Bad ncid.
NC_ENOTVAR Bad varid.
NC_EBADNAME Bad name.
NC_EMAXNAME New name too long.
NC_EINVAL Name or new name not provided.
NC_ENAMEINUSE Name already in use.
NC_EPERM File was opened read only.
NC_ENOTINDEFINE File is not in define mode.
NC_ENOTATT Attribute not found.
NC_EHDFERR Failure at HDF5 layer.
NC_ENOMEM Out of memory.
Author
Glenn Davis, Ed Hartnett, Dennis Heimbigner

Definition at line 121 of file datt.c.


Return to the Main Unidata NetCDF page.
Generated on Mon Apr 29 2019 11:00:00 for NetCDF. NetCDF is a Unidata library.