NetCDF  4.3.2
 All Data Structures Files Functions Variables Typedefs Macros Modules Pages
Attributes

Attributes hold metadata about data and files. 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...
 
int nc_get_att_string (int ncid, int varid, const char *name, char **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

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:

1 #include <netcdf.h>
2  ...
3 int status;
4 int ncid;
5 int rh_id;
6  ...
7 status = nc_open("foo.nc", NC_WRITE, &ncid);
8 if (status != NC_NOERR) handle_error(status);
9  ...
10 status = nc_inq_varid (ncid, "rh", &rh_id);
11 if (status != NC_NOERR) handle_error(status);
12  ...
13 status = nc_redef(ncid);
14 if (status != NC_NOERR) handle_error(status);
15 status = nc_del_att(ncid, rh_id, "Units");
16 if (status != NC_NOERR) handle_error(status);
17 status = nc_enddef(ncid);
18 if (status != NC_NOERR) handle_error(status);

Definition at line 157 of file datt.c.

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 where 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 attribute's variable, or NC_GLOBAL for a global attribute.
nameAttribute object_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.

Definition at line 41 of file dattget.c.

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 incure 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 object_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.

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.

1 #include <netcdf.h>
2  ...
3 int status;
4 int ncid;
5 int rh_id;
6 int vr_len, t_len;
7 double *vr_val;
8 char *title;
9 extern char *malloc()
10 
11  ...
12 status = nc_open("foo.nc", NC_NOWRITE, &ncid);
13 if (status != NC_NOERR) handle_error(status);
14  ...
15 status = nc_inq_varid (ncid, "rh", &rh_id);
16 if (status != NC_NOERR) handle_error(status);
17  ...
18 status = nc_inq_attlen (ncid, rh_id, "valid_range", &vr_len);
19 if (status != NC_NOERR) handle_error(status);
20 status = nc_inq_attlen (ncid, NC_GLOBAL, "title", &t_len);
21 if (status != NC_NOERR) handle_error(status);
22 
23 vr_val = (double *) malloc(vr_len * sizeof(double));
24 title = (char *) malloc(t_len + 1);
25 
26 status = nc_get_att_double(ncid, rh_id, "valid_range", vr_val);
27 if (status != NC_NOERR) handle_error(status);
28 status = nc_get_att_text(ncid, NC_GLOBAL, "title", title);
29 if (status != NC_NOERR) handle_error(status);
30 title[t_len] = '\0';
31  ...

Definition at line 195 of file dattget.c.

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 incure 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 object_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.

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.

1 #include <netcdf.h>
2  ...
3 int status;
4 int ncid;
5 int rh_id;
6 int vr_len, t_len;
7 double *vr_val;
8 char *title;
9 extern char *malloc()
10 
11  ...
12 status = nc_open("foo.nc", NC_NOWRITE, &ncid);
13 if (status != NC_NOERR) handle_error(status);
14  ...
15 status = nc_inq_varid (ncid, "rh", &rh_id);
16 if (status != NC_NOERR) handle_error(status);
17  ...
18 status = nc_inq_attlen (ncid, rh_id, "valid_range", &vr_len);
19 if (status != NC_NOERR) handle_error(status);
20 status = nc_inq_attlen (ncid, NC_GLOBAL, "title", &t_len);
21 if (status != NC_NOERR) handle_error(status);
22 
23 vr_val = (double *) malloc(vr_len * sizeof(double));
24 title = (char *) malloc(t_len + 1);
25 
26 status = nc_get_att_double(ncid, rh_id, "valid_range", vr_val);
27 if (status != NC_NOERR) handle_error(status);
28 status = nc_get_att_text(ncid, NC_GLOBAL, "title", title);
29 if (status != NC_NOERR) handle_error(status);
30 title[t_len] = '\0';
31  ...

Definition at line 186 of file dattget.c.

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 incure 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 object_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.

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.

1 #include <netcdf.h>
2  ...
3 int status;
4 int ncid;
5 int rh_id;
6 int vr_len, t_len;
7 double *vr_val;
8 char *title;
9 extern char *malloc()
10 
11  ...
12 status = nc_open("foo.nc", NC_NOWRITE, &ncid);
13 if (status != NC_NOERR) handle_error(status);
14  ...
15 status = nc_inq_varid (ncid, "rh", &rh_id);
16 if (status != NC_NOERR) handle_error(status);
17  ...
18 status = nc_inq_attlen (ncid, rh_id, "valid_range", &vr_len);
19 if (status != NC_NOERR) handle_error(status);
20 status = nc_inq_attlen (ncid, NC_GLOBAL, "title", &t_len);
21 if (status != NC_NOERR) handle_error(status);
22 
23 vr_val = (double *) malloc(vr_len * sizeof(double));
24 title = (char *) malloc(t_len + 1);
25 
26 status = nc_get_att_double(ncid, rh_id, "valid_range", vr_val);
27 if (status != NC_NOERR) handle_error(status);
28 status = nc_get_att_text(ncid, NC_GLOBAL, "title", title);
29 if (status != NC_NOERR) handle_error(status);
30 title[t_len] = '\0';
31  ...

Definition at line 168 of file dattget.c.

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 incure 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 object_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.

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.

1 #include <netcdf.h>
2  ...
3 int status;
4 int ncid;
5 int rh_id;
6 int vr_len, t_len;
7 double *vr_val;
8 char *title;
9 extern char *malloc()
10 
11  ...
12 status = nc_open("foo.nc", NC_NOWRITE, &ncid);
13 if (status != NC_NOERR) handle_error(status);
14  ...
15 status = nc_inq_varid (ncid, "rh", &rh_id);
16 if (status != NC_NOERR) handle_error(status);
17  ...
18 status = nc_inq_attlen (ncid, rh_id, "valid_range", &vr_len);
19 if (status != NC_NOERR) handle_error(status);
20 status = nc_inq_attlen (ncid, NC_GLOBAL, "title", &t_len);
21 if (status != NC_NOERR) handle_error(status);
22 
23 vr_val = (double *) malloc(vr_len * sizeof(double));
24 title = (char *) malloc(t_len + 1);
25 
26 status = nc_get_att_double(ncid, rh_id, "valid_range", vr_val);
27 if (status != NC_NOERR) handle_error(status);
28 status = nc_get_att_text(ncid, NC_GLOBAL, "title", title);
29 if (status != NC_NOERR) handle_error(status);
30 title[t_len] = '\0';
31  ...

Definition at line 177 of file dattget.c.

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 incure 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 object_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.

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.

1 #include <netcdf.h>
2  ...
3 int status;
4 int ncid;
5 int rh_id;
6 int vr_len, t_len;
7 double *vr_val;
8 char *title;
9 extern char *malloc()
10 
11  ...
12 status = nc_open("foo.nc", NC_NOWRITE, &ncid);
13 if (status != NC_NOERR) handle_error(status);
14  ...
15 status = nc_inq_varid (ncid, "rh", &rh_id);
16 if (status != NC_NOERR) handle_error(status);
17  ...
18 status = nc_inq_attlen (ncid, rh_id, "valid_range", &vr_len);
19 if (status != NC_NOERR) handle_error(status);
20 status = nc_inq_attlen (ncid, NC_GLOBAL, "title", &t_len);
21 if (status != NC_NOERR) handle_error(status);
22 
23 vr_val = (double *) malloc(vr_len * sizeof(double));
24 title = (char *) malloc(t_len + 1);
25 
26 status = nc_get_att_double(ncid, rh_id, "valid_range", vr_val);
27 if (status != NC_NOERR) handle_error(status);
28 status = nc_get_att_text(ncid, NC_GLOBAL, "title", title);
29 if (status != NC_NOERR) handle_error(status);
30 title[t_len] = '\0';
31  ...

Definition at line 231 of file dattget.c.

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 incure 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 object_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.

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.

1 #include <netcdf.h>
2  ...
3 int status;
4 int ncid;
5 int rh_id;
6 int vr_len, t_len;
7 double *vr_val;
8 char *title;
9 extern char *malloc()
10 
11  ...
12 status = nc_open("foo.nc", NC_NOWRITE, &ncid);
13 if (status != NC_NOERR) handle_error(status);
14  ...
15 status = nc_inq_varid (ncid, "rh", &rh_id);
16 if (status != NC_NOERR) handle_error(status);
17  ...
18 status = nc_inq_attlen (ncid, rh_id, "valid_range", &vr_len);
19 if (status != NC_NOERR) handle_error(status);
20 status = nc_inq_attlen (ncid, NC_GLOBAL, "title", &t_len);
21 if (status != NC_NOERR) handle_error(status);
22 
23 vr_val = (double *) malloc(vr_len * sizeof(double));
24 title = (char *) malloc(t_len + 1);
25 
26 status = nc_get_att_double(ncid, rh_id, "valid_range", vr_val);
27 if (status != NC_NOERR) handle_error(status);
28 status = nc_get_att_text(ncid, NC_GLOBAL, "title", title);
29 if (status != NC_NOERR) handle_error(status);
30 title[t_len] = '\0';
31  ...

Definition at line 141 of file dattget.c.

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 incure 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 object_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.

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.

1 #include <netcdf.h>
2  ...
3 int status;
4 int ncid;
5 int rh_id;
6 int vr_len, t_len;
7 double *vr_val;
8 char *title;
9 extern char *malloc()
10 
11  ...
12 status = nc_open("foo.nc", NC_NOWRITE, &ncid);
13 if (status != NC_NOERR) handle_error(status);
14  ...
15 status = nc_inq_varid (ncid, "rh", &rh_id);
16 if (status != NC_NOERR) handle_error(status);
17  ...
18 status = nc_inq_attlen (ncid, rh_id, "valid_range", &vr_len);
19 if (status != NC_NOERR) handle_error(status);
20 status = nc_inq_attlen (ncid, NC_GLOBAL, "title", &t_len);
21 if (status != NC_NOERR) handle_error(status);
22 
23 vr_val = (double *) malloc(vr_len * sizeof(double));
24 title = (char *) malloc(t_len + 1);
25 
26 status = nc_get_att_double(ncid, rh_id, "valid_range", vr_val);
27 if (status != NC_NOERR) handle_error(status);
28 status = nc_get_att_text(ncid, NC_GLOBAL, "title", title);
29 if (status != NC_NOERR) handle_error(status);
30 title[t_len] = '\0';
31  ...

Definition at line 159 of file dattget.c.

int nc_get_att_string ( 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 incure 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 object_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.

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.

1 #include <netcdf.h>
2  ...
3 int status;
4 int ncid;
5 int rh_id;
6 int vr_len, t_len;
7 double *vr_val;
8 char *title;
9 extern char *malloc()
10 
11  ...
12 status = nc_open("foo.nc", NC_NOWRITE, &ncid);
13 if (status != NC_NOERR) handle_error(status);
14  ...
15 status = nc_inq_varid (ncid, "rh", &rh_id);
16 if (status != NC_NOERR) handle_error(status);
17  ...
18 status = nc_inq_attlen (ncid, rh_id, "valid_range", &vr_len);
19 if (status != NC_NOERR) handle_error(status);
20 status = nc_inq_attlen (ncid, NC_GLOBAL, "title", &t_len);
21 if (status != NC_NOERR) handle_error(status);
22 
23 vr_val = (double *) malloc(vr_len * sizeof(double));
24 title = (char *) malloc(t_len + 1);
25 
26 status = nc_get_att_double(ncid, rh_id, "valid_range", vr_val);
27 if (status != NC_NOERR) handle_error(status);
28 status = nc_get_att_text(ncid, NC_GLOBAL, "title", title);
29 if (status != NC_NOERR) handle_error(status);
30 title[t_len] = '\0';
31  ...

Definition at line 249 of file dattget.c.

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 incure 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 object_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.

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.

1 #include <netcdf.h>
2  ...
3 int status;
4 int ncid;
5 int rh_id;
6 int vr_len, t_len;
7 double *vr_val;
8 char *title;
9 extern char *malloc()
10 
11  ...
12 status = nc_open("foo.nc", NC_NOWRITE, &ncid);
13 if (status != NC_NOERR) handle_error(status);
14  ...
15 status = nc_inq_varid (ncid, "rh", &rh_id);
16 if (status != NC_NOERR) handle_error(status);
17  ...
18 status = nc_inq_attlen (ncid, rh_id, "valid_range", &vr_len);
19 if (status != NC_NOERR) handle_error(status);
20 status = nc_inq_attlen (ncid, NC_GLOBAL, "title", &t_len);
21 if (status != NC_NOERR) handle_error(status);
22 
23 vr_val = (double *) malloc(vr_len * sizeof(double));
24 title = (char *) malloc(t_len + 1);
25 
26 status = nc_get_att_double(ncid, rh_id, "valid_range", vr_val);
27 if (status != NC_NOERR) handle_error(status);
28 status = nc_get_att_text(ncid, NC_GLOBAL, "title", title);
29 if (status != NC_NOERR) handle_error(status);
30 title[t_len] = '\0';
31  ...

Definition at line 132 of file dattget.c.

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 incure 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 object_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.

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.

1 #include <netcdf.h>
2  ...
3 int status;
4 int ncid;
5 int rh_id;
6 int vr_len, t_len;
7 double *vr_val;
8 char *title;
9 extern char *malloc()
10 
11  ...
12 status = nc_open("foo.nc", NC_NOWRITE, &ncid);
13 if (status != NC_NOERR) handle_error(status);
14  ...
15 status = nc_inq_varid (ncid, "rh", &rh_id);
16 if (status != NC_NOERR) handle_error(status);
17  ...
18 status = nc_inq_attlen (ncid, rh_id, "valid_range", &vr_len);
19 if (status != NC_NOERR) handle_error(status);
20 status = nc_inq_attlen (ncid, NC_GLOBAL, "title", &t_len);
21 if (status != NC_NOERR) handle_error(status);
22 
23 vr_val = (double *) malloc(vr_len * sizeof(double));
24 title = (char *) malloc(t_len + 1);
25 
26 status = nc_get_att_double(ncid, rh_id, "valid_range", vr_val);
27 if (status != NC_NOERR) handle_error(status);
28 status = nc_get_att_text(ncid, NC_GLOBAL, "title", title);
29 if (status != NC_NOERR) handle_error(status);
30 title[t_len] = '\0';
31  ...

Definition at line 204 of file dattget.c.

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 incure 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 object_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.

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.

1 #include <netcdf.h>
2  ...
3 int status;
4 int ncid;
5 int rh_id;
6 int vr_len, t_len;
7 double *vr_val;
8 char *title;
9 extern char *malloc()
10 
11  ...
12 status = nc_open("foo.nc", NC_NOWRITE, &ncid);
13 if (status != NC_NOERR) handle_error(status);
14  ...
15 status = nc_inq_varid (ncid, "rh", &rh_id);
16 if (status != NC_NOERR) handle_error(status);
17  ...
18 status = nc_inq_attlen (ncid, rh_id, "valid_range", &vr_len);
19 if (status != NC_NOERR) handle_error(status);
20 status = nc_inq_attlen (ncid, NC_GLOBAL, "title", &t_len);
21 if (status != NC_NOERR) handle_error(status);
22 
23 vr_val = (double *) malloc(vr_len * sizeof(double));
24 title = (char *) malloc(t_len + 1);
25 
26 status = nc_get_att_double(ncid, rh_id, "valid_range", vr_val);
27 if (status != NC_NOERR) handle_error(status);
28 status = nc_get_att_text(ncid, NC_GLOBAL, "title", title);
29 if (status != NC_NOERR) handle_error(status);
30 title[t_len] = '\0';
31  ...

Definition at line 150 of file dattget.c.

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 incure 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 object_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.

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.

1 #include <netcdf.h>
2  ...
3 int status;
4 int ncid;
5 int rh_id;
6 int vr_len, t_len;
7 double *vr_val;
8 char *title;
9 extern char *malloc()
10 
11  ...
12 status = nc_open("foo.nc", NC_NOWRITE, &ncid);
13 if (status != NC_NOERR) handle_error(status);
14  ...
15 status = nc_inq_varid (ncid, "rh", &rh_id);
16 if (status != NC_NOERR) handle_error(status);
17  ...
18 status = nc_inq_attlen (ncid, rh_id, "valid_range", &vr_len);
19 if (status != NC_NOERR) handle_error(status);
20 status = nc_inq_attlen (ncid, NC_GLOBAL, "title", &t_len);
21 if (status != NC_NOERR) handle_error(status);
22 
23 vr_val = (double *) malloc(vr_len * sizeof(double));
24 title = (char *) malloc(t_len + 1);
25 
26 status = nc_get_att_double(ncid, rh_id, "valid_range", vr_val);
27 if (status != NC_NOERR) handle_error(status);
28 status = nc_get_att_text(ncid, NC_GLOBAL, "title", title);
29 if (status != NC_NOERR) handle_error(status);
30 title[t_len] = '\0';
31  ...

Definition at line 222 of file dattget.c.

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 incure 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 object_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.

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.

1 #include <netcdf.h>
2  ...
3 int status;
4 int ncid;
5 int rh_id;
6 int vr_len, t_len;
7 double *vr_val;
8 char *title;
9 extern char *malloc()
10 
11  ...
12 status = nc_open("foo.nc", NC_NOWRITE, &ncid);
13 if (status != NC_NOERR) handle_error(status);
14  ...
15 status = nc_inq_varid (ncid, "rh", &rh_id);
16 if (status != NC_NOERR) handle_error(status);
17  ...
18 status = nc_inq_attlen (ncid, rh_id, "valid_range", &vr_len);
19 if (status != NC_NOERR) handle_error(status);
20 status = nc_inq_attlen (ncid, NC_GLOBAL, "title", &t_len);
21 if (status != NC_NOERR) handle_error(status);
22 
23 vr_val = (double *) malloc(vr_len * sizeof(double));
24 title = (char *) malloc(t_len + 1);
25 
26 status = nc_get_att_double(ncid, rh_id, "valid_range", vr_val);
27 if (status != NC_NOERR) handle_error(status);
28 status = nc_get_att_text(ncid, NC_GLOBAL, "title", title);
29 if (status != NC_NOERR) handle_error(status);
30 title[t_len] = '\0';
31  ...

Definition at line 240 of file dattget.c.

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 incure 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 object_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.

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.

1 #include <netcdf.h>
2  ...
3 int status;
4 int ncid;
5 int rh_id;
6 int vr_len, t_len;
7 double *vr_val;
8 char *title;
9 extern char *malloc()
10 
11  ...
12 status = nc_open("foo.nc", NC_NOWRITE, &ncid);
13 if (status != NC_NOERR) handle_error(status);
14  ...
15 status = nc_inq_varid (ncid, "rh", &rh_id);
16 if (status != NC_NOERR) handle_error(status);
17  ...
18 status = nc_inq_attlen (ncid, rh_id, "valid_range", &vr_len);
19 if (status != NC_NOERR) handle_error(status);
20 status = nc_inq_attlen (ncid, NC_GLOBAL, "title", &t_len);
21 if (status != NC_NOERR) handle_error(status);
22 
23 vr_val = (double *) malloc(vr_len * sizeof(double));
24 title = (char *) malloc(t_len + 1);
25 
26 status = nc_get_att_double(ncid, rh_id, "valid_range", vr_val);
27 if (status != NC_NOERR) handle_error(status);
28 status = nc_get_att_text(ncid, NC_GLOBAL, "title", title);
29 if (status != NC_NOERR) handle_error(status);
30 title[t_len] = '\0';
31  ...

Definition at line 213 of file dattget.c.

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 object_name. 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:

1 #include <netcdf.h>
2  ...
3 int status;
4 int ncid;
5 int rh_id;
6 nc_type vr_type, t_type;
7 size_t vr_len, t_len;
8 
9  ...
10 status = nc_open("foo.nc", NC_NOWRITE, &ncid);
11 if (status != NC_NOERR) handle_error(status);
12  ...
13 status = nc_inq_varid (ncid, "rh", &rh_id);
14 if (status != NC_NOERR) handle_error(status);
15  ...
16 status = nc_inq_att (ncid, rh_id, "valid_range", &vr_type, &vr_len);
17 if (status != NC_NOERR) handle_error(status);
18 status = nc_inq_att (ncid, NC_GLOBAL, "title", &t_type, &t_len);
19 if (status != NC_NOERR) handle_error(status);

Definition at line 72 of file dattinq.c.

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 object_name.
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.

Definition at line 101 of file dattinq.c.

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 object_name.
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.

Definition at line 200 of file dattinq.c.

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 object_name.

Definition at line 129 of file dattinq.c.

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 object_name.
xtypepPointer to location for returned attribute Data Types.

Definition at line 174 of file dattinq.c.

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.

Definition at line 149 of file dattinq.c.

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.

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 object_name. 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:

1 #include <netcdf.h>
2  ...
3 int status;
4 int ncid;
5 int rh_id;
6 static double rh_range[] = {0.0, 100.0};
7 static char title[] = "example netCDF dataset";
8  ...
9 status = nc_open("foo.nc", NC_WRITE, &ncid);
10 if (status != NC_NOERR) handle_error(status);
11  ...
12 status = nc_redef(ncid);
13 if (status != NC_NOERR) handle_error(status);
14 status = nc_inq_varid (ncid, "rh", &rh_id);
15 if (status != NC_NOERR) handle_error(status);
16  ...
17 status = nc_put_att_double (ncid, rh_id, "valid_range",
18  NC_DOUBLE, 2, rh_range);
19 if (status != NC_NOERR) handle_error(status);
20 status = nc_put_att_text (ncid, NC_GLOBAL, "title",
21  strlen(title), title)
22 if (status != NC_NOERR) handle_error(status);
23  ...
24 status = nc_enddef(ncid);
25 if (status != NC_NOERR) handle_error(status);

Definition at line 226 of file dattput.c.

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.

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 object_name. 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:

1 #include <netcdf.h>
2  ...
3 int status;
4 int ncid;
5 int rh_id;
6 static double rh_range[] = {0.0, 100.0};
7 static char title[] = "example netCDF dataset";
8  ...
9 status = nc_open("foo.nc", NC_WRITE, &ncid);
10 if (status != NC_NOERR) handle_error(status);
11  ...
12 status = nc_redef(ncid);
13 if (status != NC_NOERR) handle_error(status);
14 status = nc_inq_varid (ncid, "rh", &rh_id);
15 if (status != NC_NOERR) handle_error(status);
16  ...
17 status = nc_put_att_double (ncid, rh_id, "valid_range",
18  NC_DOUBLE, 2, rh_range);
19 if (status != NC_NOERR) handle_error(status);
20 status = nc_put_att_text (ncid, NC_GLOBAL, "title",
21  strlen(title), title)
22 if (status != NC_NOERR) handle_error(status);
23  ...
24 status = nc_enddef(ncid);
25 if (status != NC_NOERR) handle_error(status);

Definition at line 303 of file dattput.c.

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.

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 object_name. 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:

1 #include <netcdf.h>
2  ...
3 int status;
4 int ncid;
5 int rh_id;
6 static double rh_range[] = {0.0, 100.0};
7 static char title[] = "example netCDF dataset";
8  ...
9 status = nc_open("foo.nc", NC_WRITE, &ncid);
10 if (status != NC_NOERR) handle_error(status);
11  ...
12 status = nc_redef(ncid);
13 if (status != NC_NOERR) handle_error(status);
14 status = nc_inq_varid (ncid, "rh", &rh_id);
15 if (status != NC_NOERR) handle_error(status);
16  ...
17 status = nc_put_att_double (ncid, rh_id, "valid_range",
18  NC_DOUBLE, 2, rh_range);
19 if (status != NC_NOERR) handle_error(status);
20 status = nc_put_att_text (ncid, NC_GLOBAL, "title",
21  strlen(title), title)
22 if (status != NC_NOERR) handle_error(status);
23  ...
24 status = nc_enddef(ncid);
25 if (status != NC_NOERR) handle_error(status);

Definition at line 292 of file dattput.c.

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.

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 object_name. 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:

1 #include <netcdf.h>
2  ...
3 int status;
4 int ncid;
5 int rh_id;
6 static double rh_range[] = {0.0, 100.0};
7 static char title[] = "example netCDF dataset";
8  ...
9 status = nc_open("foo.nc", NC_WRITE, &ncid);
10 if (status != NC_NOERR) handle_error(status);
11  ...
12 status = nc_redef(ncid);
13 if (status != NC_NOERR) handle_error(status);
14 status = nc_inq_varid (ncid, "rh", &rh_id);
15 if (status != NC_NOERR) handle_error(status);
16  ...
17 status = nc_put_att_double (ncid, rh_id, "valid_range",
18  NC_DOUBLE, 2, rh_range);
19 if (status != NC_NOERR) handle_error(status);
20 status = nc_put_att_text (ncid, NC_GLOBAL, "title",
21  strlen(title), title)
22 if (status != NC_NOERR) handle_error(status);
23  ...
24 status = nc_enddef(ncid);
25 if (status != NC_NOERR) handle_error(status);

Definition at line 270 of file dattput.c.

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.

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 object_name. 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:

1 #include <netcdf.h>
2  ...
3 int status;
4 int ncid;
5 int rh_id;
6 static double rh_range[] = {0.0, 100.0};
7 static char title[] = "example netCDF dataset";
8  ...
9 status = nc_open("foo.nc", NC_WRITE, &ncid);
10 if (status != NC_NOERR) handle_error(status);
11  ...
12 status = nc_redef(ncid);
13 if (status != NC_NOERR) handle_error(status);
14 status = nc_inq_varid (ncid, "rh", &rh_id);
15 if (status != NC_NOERR) handle_error(status);
16  ...
17 status = nc_put_att_double (ncid, rh_id, "valid_range",
18  NC_DOUBLE, 2, rh_range);
19 if (status != NC_NOERR) handle_error(status);
20 status = nc_put_att_text (ncid, NC_GLOBAL, "title",
21  strlen(title), title)
22 if (status != NC_NOERR) handle_error(status);
23  ...
24 status = nc_enddef(ncid);
25 if (status != NC_NOERR) handle_error(status);

Definition at line 281 of file dattput.c.

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.

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 object_name. 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:

1 #include <netcdf.h>
2  ...
3 int status;
4 int ncid;
5 int rh_id;
6 static double rh_range[] = {0.0, 100.0};
7 static char title[] = "example netCDF dataset";
8  ...
9 status = nc_open("foo.nc", NC_WRITE, &ncid);
10 if (status != NC_NOERR) handle_error(status);
11  ...
12 status = nc_redef(ncid);
13 if (status != NC_NOERR) handle_error(status);
14 status = nc_inq_varid (ncid, "rh", &rh_id);
15 if (status != NC_NOERR) handle_error(status);
16  ...
17 status = nc_put_att_double (ncid, rh_id, "valid_range",
18  NC_DOUBLE, 2, rh_range);
19 if (status != NC_NOERR) handle_error(status);
20 status = nc_put_att_text (ncid, NC_GLOBAL, "title",
21  strlen(title), title)
22 if (status != NC_NOERR) handle_error(status);
23  ...
24 status = nc_enddef(ncid);
25 if (status != NC_NOERR) handle_error(status);

Definition at line 347 of file dattput.c.

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.

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 object_name. 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:

1 #include <netcdf.h>
2  ...
3 int status;
4 int ncid;
5 int rh_id;
6 static double rh_range[] = {0.0, 100.0};
7 static char title[] = "example netCDF dataset";
8  ...
9 status = nc_open("foo.nc", NC_WRITE, &ncid);
10 if (status != NC_NOERR) handle_error(status);
11  ...
12 status = nc_redef(ncid);
13 if (status != NC_NOERR) handle_error(status);
14 status = nc_inq_varid (ncid, "rh", &rh_id);
15 if (status != NC_NOERR) handle_error(status);
16  ...
17 status = nc_put_att_double (ncid, rh_id, "valid_range",
18  NC_DOUBLE, 2, rh_range);
19 if (status != NC_NOERR) handle_error(status);
20 status = nc_put_att_text (ncid, NC_GLOBAL, "title",
21  strlen(title), title)
22 if (status != NC_NOERR) handle_error(status);
23  ...
24 status = nc_enddef(ncid);
25 if (status != NC_NOERR) handle_error(status);

Definition at line 237 of file dattput.c.

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.

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 object_name. 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:

1 #include <netcdf.h>
2  ...
3 int status;
4 int ncid;
5 int rh_id;
6 static double rh_range[] = {0.0, 100.0};
7 static char title[] = "example netCDF dataset";
8  ...
9 status = nc_open("foo.nc", NC_WRITE, &ncid);
10 if (status != NC_NOERR) handle_error(status);
11  ...
12 status = nc_redef(ncid);
13 if (status != NC_NOERR) handle_error(status);
14 status = nc_inq_varid (ncid, "rh", &rh_id);
15 if (status != NC_NOERR) handle_error(status);
16  ...
17 status = nc_put_att_double (ncid, rh_id, "valid_range",
18  NC_DOUBLE, 2, rh_range);
19 if (status != NC_NOERR) handle_error(status);
20 status = nc_put_att_text (ncid, NC_GLOBAL, "title",
21  strlen(title), title)
22 if (status != NC_NOERR) handle_error(status);
23  ...
24 status = nc_enddef(ncid);
25 if (status != NC_NOERR) handle_error(status);

Definition at line 259 of file dattput.c.

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 object_name. 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 48 of file dattput.c.

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.

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 object_name. 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:

1 #include <netcdf.h>
2  ...
3 int status;
4 int ncid;
5 int rh_id;
6 static double rh_range[] = {0.0, 100.0};
7 static char title[] = "example netCDF dataset";
8  ...
9 status = nc_open("foo.nc", NC_WRITE, &ncid);
10 if (status != NC_NOERR) handle_error(status);
11  ...
12 status = nc_redef(ncid);
13 if (status != NC_NOERR) handle_error(status);
14 status = nc_inq_varid (ncid, "rh", &rh_id);
15 if (status != NC_NOERR) handle_error(status);
16  ...
17 status = nc_put_att_double (ncid, rh_id, "valid_range",
18  NC_DOUBLE, 2, rh_range);
19 if (status != NC_NOERR) handle_error(status);
20 status = nc_put_att_text (ncid, NC_GLOBAL, "title",
21  strlen(title), title)
22 if (status != NC_NOERR) handle_error(status);
23  ...
24 status = nc_enddef(ncid);
25 if (status != NC_NOERR) handle_error(status);

Definition at line 135 of file dattput.c.

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.

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 object_name. 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:

1 #include <netcdf.h>
2  ...
3 int status;
4 int ncid;
5 int rh_id;
6 static double rh_range[] = {0.0, 100.0};
7 static char title[] = "example netCDF dataset";
8  ...
9 status = nc_open("foo.nc", NC_WRITE, &ncid);
10 if (status != NC_NOERR) handle_error(status);
11  ...
12 status = nc_redef(ncid);
13 if (status != NC_NOERR) handle_error(status);
14 status = nc_inq_varid (ncid, "rh", &rh_id);
15 if (status != NC_NOERR) handle_error(status);
16  ...
17 status = nc_put_att_double (ncid, rh_id, "valid_range",
18  NC_DOUBLE, 2, rh_range);
19 if (status != NC_NOERR) handle_error(status);
20 status = nc_put_att_text (ncid, NC_GLOBAL, "title",
21  strlen(title), title)
22 if (status != NC_NOERR) handle_error(status);
23  ...
24 status = nc_enddef(ncid);
25 if (status != NC_NOERR) handle_error(status);

Definition at line 314 of file dattput.c.

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.

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 object_name. 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:

1 #include <netcdf.h>
2  ...
3 int status;
4 int ncid;
5 int rh_id;
6 static double rh_range[] = {0.0, 100.0};
7 static char title[] = "example netCDF dataset";
8  ...
9 status = nc_open("foo.nc", NC_WRITE, &ncid);
10 if (status != NC_NOERR) handle_error(status);
11  ...
12 status = nc_redef(ncid);
13 if (status != NC_NOERR) handle_error(status);
14 status = nc_inq_varid (ncid, "rh", &rh_id);
15 if (status != NC_NOERR) handle_error(status);
16  ...
17 status = nc_put_att_double (ncid, rh_id, "valid_range",
18  NC_DOUBLE, 2, rh_range);
19 if (status != NC_NOERR) handle_error(status);
20 status = nc_put_att_text (ncid, NC_GLOBAL, "title",
21  strlen(title), title)
22 if (status != NC_NOERR) handle_error(status);
23  ...
24 status = nc_enddef(ncid);
25 if (status != NC_NOERR) handle_error(status);

Definition at line 248 of file dattput.c.

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.

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 object_name. 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:

1 #include <netcdf.h>
2  ...
3 int status;
4 int ncid;
5 int rh_id;
6 static double rh_range[] = {0.0, 100.0};
7 static char title[] = "example netCDF dataset";
8  ...
9 status = nc_open("foo.nc", NC_WRITE, &ncid);
10 if (status != NC_NOERR) handle_error(status);
11  ...
12 status = nc_redef(ncid);
13 if (status != NC_NOERR) handle_error(status);
14 status = nc_inq_varid (ncid, "rh", &rh_id);
15 if (status != NC_NOERR) handle_error(status);
16  ...
17 status = nc_put_att_double (ncid, rh_id, "valid_range",
18  NC_DOUBLE, 2, rh_range);
19 if (status != NC_NOERR) handle_error(status);
20 status = nc_put_att_text (ncid, NC_GLOBAL, "title",
21  strlen(title), title)
22 if (status != NC_NOERR) handle_error(status);
23  ...
24 status = nc_enddef(ncid);
25 if (status != NC_NOERR) handle_error(status);

Definition at line 336 of file dattput.c.

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.

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 object_name. 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:

1 #include <netcdf.h>
2  ...
3 int status;
4 int ncid;
5 int rh_id;
6 static double rh_range[] = {0.0, 100.0};
7 static char title[] = "example netCDF dataset";
8  ...
9 status = nc_open("foo.nc", NC_WRITE, &ncid);
10 if (status != NC_NOERR) handle_error(status);
11  ...
12 status = nc_redef(ncid);
13 if (status != NC_NOERR) handle_error(status);
14 status = nc_inq_varid (ncid, "rh", &rh_id);
15 if (status != NC_NOERR) handle_error(status);
16  ...
17 status = nc_put_att_double (ncid, rh_id, "valid_range",
18  NC_DOUBLE, 2, rh_range);
19 if (status != NC_NOERR) handle_error(status);
20 status = nc_put_att_text (ncid, NC_GLOBAL, "title",
21  strlen(title), title)
22 if (status != NC_NOERR) handle_error(status);
23  ...
24 status = nc_enddef(ncid);
25 if (status != NC_NOERR) handle_error(status);

Definition at line 359 of file dattput.c.

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.

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 object_name. 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:

1 #include <netcdf.h>
2  ...
3 int status;
4 int ncid;
5 int rh_id;
6 static double rh_range[] = {0.0, 100.0};
7 static char title[] = "example netCDF dataset";
8  ...
9 status = nc_open("foo.nc", NC_WRITE, &ncid);
10 if (status != NC_NOERR) handle_error(status);
11  ...
12 status = nc_redef(ncid);
13 if (status != NC_NOERR) handle_error(status);
14 status = nc_inq_varid (ncid, "rh", &rh_id);
15 if (status != NC_NOERR) handle_error(status);
16  ...
17 status = nc_put_att_double (ncid, rh_id, "valid_range",
18  NC_DOUBLE, 2, rh_range);
19 if (status != NC_NOERR) handle_error(status);
20 status = nc_put_att_text (ncid, NC_GLOBAL, "title",
21  strlen(title), title)
22 if (status != NC_NOERR) handle_error(status);
23  ...
24 status = nc_enddef(ncid);
25 if (status != NC_NOERR) handle_error(status);

Definition at line 325 of file dattput.c.

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 object_name.
newnameThe new attribute object_name.

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:

1 #include <netcdf.h>
2  ...
3 int status;
4 int ncid;
5 int rh_id;
6  ...
7 status = nc_open("foo.nc", NC_NOWRITE, &ncid);
8 if (status != NC_NOERR) handle_error(status);
9  ...
10 status = nc_inq_varid (ncid, "rh", &rh_id);
11 if (status != NC_NOERR) handle_error(status);
12  ...
13 status = nc_rename_att(ncid, rh_id, "units", "Units");
14 if (status != NC_NOERR) handle_error(status);

Definition at line 107 of file datt.c.


Return to the Main Unidata NetCDF page.
Generated on Sun Nov 23 2014 16:17:49 for NetCDF. NetCDF is a Unidata library.