NetCDF
4.9.2
|
Attributes hold metadata about data and files. More...
Learning about Attributes | |
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... | |
Getting Attributes | |
Functions to get the values of attributes. For classic format files, the netCDF library reads all attributes into memory when the file is opened with nc_open(). For netCDF-4/HDF5 files, since version 4.7.2, attributes are not read on file open. Instead, when the first read of a variable attribute is done, all attributes for that variable are read. Subsequent access to other attributes of that variable will not incur a disk read. Similarly, when the first NC_GLOBAL attribute is read in a group, all NC_GLOBAL attributes for that group will be read.
ExampleHere 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 from a 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;
double *vr_val;
...
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);
vr_val = (double *) malloc(vr_len * sizeof(double));
status = nc_get_att_double(ncid, rh_id, "valid_range", vr_val);
if (status != NC_NOERR) handle_error(status);
...
EXTERNL int nc_get_att_double(int ncid, int varid, const char *name, double *ip) Get an attribute array of type double. Definition: dattget.c:453 EXTERNL int nc_inq_attlen(int ncid, int varid, const char *name, size_t *lenp) Find the length of an attribute. Definition: dattinq.c:424 EXTERNL int nc_open(const char *path, int mode, int *ncidp) Open an existing netCDF file. Definition: dfile.c:666 EXTERNL int nc_inq_varid(int ncid, const char *name, int *varidp) Find the ID of a variable, from the name. Definition: dvarinq.c:60 Main header file for the C API. | |
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 a text attribute. More... | |
int | nc_get_att_schar (int ncid, int varid, const char *name, signed char *value) |
Get an attribute of an signed char type. More... | |
int | nc_get_att_uchar (int ncid, int varid, const char *name, unsigned char *value) |
Get an attribute of an signed char type. More... | |
int | nc_get_att_short (int ncid, int varid, const char *name, short *value) |
Get an attribute array of type short. More... | |
int | nc_get_att_int (int ncid, int varid, const char *name, int *value) |
Get an attribute array of type int. More... | |
int | nc_get_att_long (int ncid, int varid, const char *name, long *value) |
Get an attribute array of type long. More... | |
int | nc_get_att_float (int ncid, int varid, const char *name, float *value) |
Get an attribute array of type float. More... | |
int | nc_get_att_double (int ncid, int varid, const char *name, double *value) |
Get an attribute array of type double. More... | |
int | nc_get_att_ubyte (int ncid, int varid, const char *name, unsigned char *value) |
Get an attribute array of type unsigned char. More... | |
int | nc_get_att_ushort (int ncid, int varid, const char *name, unsigned short *value) |
Get an attribute array of type unsigned short. More... | |
int | nc_get_att_uint (int ncid, int varid, const char *name, unsigned int *value) |
Get an attribute array of type unsigned int. More... | |
int | nc_get_att_longlong (int ncid, int varid, const char *name, long long *value) |
Get an attribute array of type long long. More... | |
int | nc_get_att_ulonglong (int ncid, int varid, const char *name, unsigned long long *value) |
Get an attribute array of type unsigned long long. More... | |
int | nc_get_att_string (int ncid, int varid, const char *name, char **value) |
Get an attribute array of type string. More... | |
Writing Attributes | |
Functions to write attributes. For netCDF classic formats, attributes 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. For netCDF-4/HDF5 netCDF files, attributes may be defined at any time. In classic format files, 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. In netCDF-4/HDF5 files, attribute name, length, and value may be changed at any time. Attribute data conversion automatically takes place when the type of the data does not match the xtype argument. All attribute data values are converted to xtype before being written to the file. If writing a new attribute, 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).
| |
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 of any type. 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 of type signed char. 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 of type unsigned char. 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 of type short. 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 of type int. 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 of type long. 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 of type float. 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 of type double. 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 of type unsigned char. 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 of type unsigned short. 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 of type unsigned int. 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 of type long long. 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 of type unsigned long long. More... | |
Deleting and Renaming Attributes | |
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... | |
Attributes hold metadata about data and files.
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.
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 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. In netCDF-4/HDF5 files, global attributes are associated with a hierarchical group.
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().
Operations supported on attributes are:
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. For classic netCDF formats, the dataset must be in define mode to delete an attribute. In netCDF-4/HDF5 files, attributes may be deleted at any time.
ncid | NetCDF or group ID, from a previous call to nc_open(), nc_create(), nc_def_grp(), or associated inquiry functions such as nc_inq_ncid(). |
varid | Variable ID of the attribute's variable, or NC_GLOBAL for a global attribute. |
name | Attribute name. |
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:
int nc_get_att | ( | int | ncid, |
int | varid, | ||
const char * | name, | ||
void * | value | ||
) |
Get an attribute of any type.
The nc_get_att() function works for any type of attribute, and must be used to get attributes of user-defined type. We recommend that the type safe versions of this function be used for atomic data types.
Also see Getting Attributes
ncid | NetCDF file or group ID. |
varid | Variable ID, or NC_GLOBAL for a global attribute. |
name | Attribute name. |
value | Pointer that will get array of attribute value(s). Use nc_inq_attlen() to learn length. |
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.
int nc_get_att_double | ( | int | ncid, |
int | varid, | ||
const char * | name, | ||
double * | value | ||
) |
Get an attribute array of type double.
Also see Getting Attributes
ncid | NetCDF file or group ID. |
varid | Variable ID, or NC_GLOBAL for a global attribute. |
name | Attribute name. |
value | Pointer that will get array of attribute value(s). Use nc_inq_attlen() to learn length. |
int nc_get_att_float | ( | int | ncid, |
int | varid, | ||
const char * | name, | ||
float * | value | ||
) |
Get an attribute array of type float.
Also see Getting Attributes
ncid | NetCDF file or group ID. |
varid | Variable ID, or NC_GLOBAL for a global attribute. |
name | Attribute name. |
value | Pointer that will get array of attribute value(s). Use nc_inq_attlen() to learn length. |
int nc_get_att_int | ( | int | ncid, |
int | varid, | ||
const char * | name, | ||
int * | value | ||
) |
Get an attribute array of type int.
Also see Getting Attributes
ncid | NetCDF file or group ID. |
varid | Variable ID, or NC_GLOBAL for a global attribute. |
name | Attribute name. |
value | Pointer that will get array of attribute value(s). Use nc_inq_attlen() to learn length. |
int nc_get_att_long | ( | int | ncid, |
int | varid, | ||
const char * | name, | ||
long * | value | ||
) |
Get an attribute array of type long.
Also see Getting Attributes
ncid | NetCDF file or group ID. |
varid | Variable ID, or NC_GLOBAL for a global attribute. |
name | Attribute name. |
value | Pointer that will get array of attribute value(s). Use nc_inq_attlen() to learn length. |
int nc_get_att_longlong | ( | int | ncid, |
int | varid, | ||
const char * | name, | ||
long long * | value | ||
) |
Get an attribute array of type long long.
Also see Getting Attributes
ncid | NetCDF file or group ID. |
varid | Variable ID, or NC_GLOBAL for a global attribute. |
name | Attribute name. |
value | Pointer that will get array of attribute value(s). Use nc_inq_attlen() to learn length. |
int nc_get_att_schar | ( | int | ncid, |
int | varid, | ||
const char * | name, | ||
signed char * | value | ||
) |
Get an attribute of an signed char type.
Also see Getting Attributes
ncid | NetCDF file or group ID. |
varid | Variable ID, or NC_GLOBAL for a global attribute. |
name | Attribute name. |
value | Pointer that will get array of attribute value(s). Use nc_inq_attlen() to learn length. |
int nc_get_att_short | ( | int | ncid, |
int | varid, | ||
const char * | name, | ||
short * | value | ||
) |
Get an attribute array of type short.
Also see Getting Attributes
ncid | NetCDF file or group ID. |
varid | Variable ID, or NC_GLOBAL for a global attribute. |
name | Attribute name. |
value | Pointer that will get array of attribute value(s). Use nc_inq_attlen() to learn length. |
int nc_get_att_string | ( | int | ncid, |
int | varid, | ||
const char * | name, | ||
char ** | value | ||
) |
Get an attribute array of type string.
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.
Also see Getting Attributes
ncid | NetCDF file or group ID. |
varid | Variable ID, or NC_GLOBAL for a global attribute. |
name | Attribute name. |
value | Pointer that will get array of attribute value(s). Use nc_inq_attlen() to learn length. |
int nc_get_att_text | ( | int | ncid, |
int | varid, | ||
const char * | name, | ||
char * | value | ||
) |
Get a text attribute.
This function gets a text attribute from the netCDF file. Type conversions are not permitted.
Also see Getting Attributes
ncid | NetCDF file or group ID. |
varid | Variable ID, or NC_GLOBAL for a global attribute. |
name | Attribute name. |
value | Pointer that will get array of attribute value(s). Use nc_inq_attlen() to learn length. |
Here is an example using nc_get_att_text() to read a global attribute named title in an existing netCDF dataset named foo.nc.
In this example we learn the length of the attribute, so that an array may be allocated, adding 1 in case a NULL terminator is needed. We then take the precaution of setting the last element of the array to 0, to NULL terminate the string. If a NULL terminator was written with this attribute, strlen(title) will show the correct length (the number of chars before the first NULL terminator).
int nc_get_att_ubyte | ( | int | ncid, |
int | varid, | ||
const char * | name, | ||
unsigned char * | value | ||
) |
Get an attribute array of type unsigned char.
Also see Getting Attributes
ncid | NetCDF file or group ID. |
varid | Variable ID, or NC_GLOBAL for a global attribute. |
name | Attribute name. |
value | Pointer that will get array of attribute value(s). Use nc_inq_attlen() to learn length. |
int nc_get_att_uchar | ( | int | ncid, |
int | varid, | ||
const char * | name, | ||
unsigned char * | value | ||
) |
Get an attribute of an signed char type.
Also see Getting Attributes
ncid | NetCDF file or group ID. |
varid | Variable ID, or NC_GLOBAL for a global attribute. |
name | Attribute name. |
value | Pointer that will get array of attribute value(s). Use nc_inq_attlen() to learn length. |
int nc_get_att_uint | ( | int | ncid, |
int | varid, | ||
const char * | name, | ||
unsigned int * | value | ||
) |
Get an attribute array of type unsigned int.
Also see Getting Attributes
ncid | NetCDF file or group ID. |
varid | Variable ID, or NC_GLOBAL for a global attribute. |
name | Attribute name. |
value | Pointer that will get array of attribute value(s). Use nc_inq_attlen() to learn length. |
int nc_get_att_ulonglong | ( | int | ncid, |
int | varid, | ||
const char * | name, | ||
unsigned long long * | value | ||
) |
Get an attribute array of type unsigned long long.
Also see Getting Attributes
ncid | NetCDF file or group ID. |
varid | Variable ID, or NC_GLOBAL for a global attribute. |
name | Attribute name. |
value | Pointer that will get array of attribute value(s). Use nc_inq_attlen() to learn length. |
int nc_get_att_ushort | ( | int | ncid, |
int | varid, | ||
const char * | name, | ||
unsigned short * | value | ||
) |
Get an attribute array of type unsigned short.
Also see Getting Attributes
ncid | NetCDF file or group ID. |
varid | Variable ID, or NC_GLOBAL for a global attribute. |
name | Attribute name. |
value | Pointer that will get array of attribute value(s). Use nc_inq_attlen() to learn length. |
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.
ncid | NetCDF or group ID, from a previous call to nc_open(), nc_create(), nc_def_grp(), or associated inquiry functions such as nc_inq_ncid(). |
varid | Variable ID of the attribute's variable, or NC_GLOBAL for a global attribute. |
name | Pointer to the location for the returned attribute NetCDF Names. Ignored if NULL. |
xtypep | Pointer to location for returned attribute data type. Ignored if NULL. |
lenp | Pointer 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. |
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:
int nc_inq_attid | ( | int | ncid, |
int | varid, | ||
const char * | name, | ||
int * | idp | ||
) |
Find an attribute ID.
ncid | NetCDF or group ID, from a previous call to nc_open(), nc_create(), nc_def_grp(), or associated inquiry functions such as nc_inq_ncid(). |
varid | Variable ID of the attribute's variable, or NC_GLOBAL for a global attribute. |
name | Attribute NetCDF Names. |
idp | Pointer 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. |
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.
int nc_inq_attlen | ( | int | ncid, |
int | varid, | ||
const char * | name, | ||
size_t * | lenp | ||
) |
Find the length of an attribute.
ncid | NetCDF or group ID, from a previous call to nc_open(), nc_create(), nc_def_grp(), or associated inquiry functions such as nc_inq_ncid(). |
varid | Variable ID of the attribute's variable, or NC_GLOBAL for a global or group attribute. |
name | Attribute NetCDF Names. |
lenp | Pointer 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. |
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.
int nc_inq_attname | ( | int | ncid, |
int | varid, | ||
int | attnum, | ||
char * | name | ||
) |
Find the name of an attribute.
ncid | NetCDF or group ID, from a previous call to nc_open(), nc_create(), nc_def_grp(), or associated inquiry functions such as nc_inq_ncid(). |
varid | Variable ID of the attribute's variable, or NC_GLOBAL for a global attribute. |
attnum | Attribute 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(). |
name | Pointer to the location for the returned attribute NetCDF Names. |
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.
int nc_inq_atttype | ( | int | ncid, |
int | varid, | ||
const char * | name, | ||
nc_type * | xtypep | ||
) |
Find the type of an attribute.
ncid | NetCDF or group ID, from a previous call to nc_open(), nc_create(), nc_def_grp(), or associated inquiry functions such as nc_inq_ncid(). |
varid | Variable ID of the attribute's variable, or NC_GLOBAL for a global or group attribute. |
name | Attribute NetCDF Names. |
xtypep | Pointer to location for returned attribute data type. |
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.
int nc_inq_natts | ( | int | ncid, |
int * | nattsp | ||
) |
Find number of global or group attributes.
ncid | NetCDF or group ID, from a previous call to nc_open(), nc_create(), nc_def_grp(), or associated inquiry functions such as nc_inq_ncid(). |
nattsp | Pointer where number of global or group attributes will be written. Ignored if NULL. |
Here is an example from nc_test4/tst_vars.c:
int nc_put_att | ( | int | ncid, |
int | varid, | ||
const char * | name, | ||
nc_type | xtype, | ||
size_t | len, | ||
const void * | value | ||
) |
Write an attribute of any type.
Also see Writing Attributes
ncid | NetCDF file or group ID. |
varid | Variable ID, or NC_GLOBAL for a global attribute. |
name | Attribute NetCDF Names. |
xtype | The type of attribute to write. Data will be converted to this type. |
len | Number of values provided for the attribute. |
value | Pointer to one or more values. |
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:
int nc_put_att_double | ( | int | ncid, |
int | varid, | ||
const char * | name, | ||
nc_type | xtype, | ||
size_t | len, | ||
const double * | value | ||
) |
Write an attribute of type double.
Also see Writing Attributes
ncid | NetCDF file or group ID. |
varid | Variable ID, or NC_GLOBAL for a global attribute. |
name | Attribute NetCDF Names. |
xtype | The type of attribute to write. Data will be converted to this type. |
len | Number of values provided for the attribute. |
value | Pointer to one or more values. |
int nc_put_att_float | ( | int | ncid, |
int | varid, | ||
const char * | name, | ||
nc_type | xtype, | ||
size_t | len, | ||
const float * | value | ||
) |
Write an attribute of type float.
Also see Writing Attributes
ncid | NetCDF file or group ID. |
varid | Variable ID, or NC_GLOBAL for a global attribute. |
name | Attribute NetCDF Names. |
xtype | The type of attribute to write. Data will be converted to this type. |
len | Number of values provided for the attribute. |
value | Pointer to one or more values. |
int nc_put_att_int | ( | int | ncid, |
int | varid, | ||
const char * | name, | ||
nc_type | xtype, | ||
size_t | len, | ||
const int * | value | ||
) |
Write an attribute of type int.
Also see Writing Attributes
ncid | NetCDF file or group ID. |
varid | Variable ID, or NC_GLOBAL for a global attribute. |
name | Attribute NetCDF Names. |
xtype | The type of attribute to write. Data will be converted to this type. |
len | Number of values provided for the attribute. |
value | Pointer to one or more values. |
int nc_put_att_long | ( | int | ncid, |
int | varid, | ||
const char * | name, | ||
nc_type | xtype, | ||
size_t | len, | ||
const long * | value | ||
) |
Write an attribute of type long.
Also see Writing Attributes
ncid | NetCDF file or group ID. |
varid | Variable ID, or NC_GLOBAL for a global attribute. |
name | Attribute NetCDF Names. |
xtype | The type of attribute to write. Data will be converted to this type. |
len | Number of values provided for the attribute. |
value | Pointer to one or more values. |
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 of type long long.
Also see Writing Attributes
ncid | NetCDF file or group ID. |
varid | Variable ID, or NC_GLOBAL for a global attribute. |
name | Attribute NetCDF Names. |
xtype | The type of attribute to write. Data will be converted to this type. |
len | Number of values provided for the attribute. |
value | Pointer to one or more values. |
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 of type signed char.
Also see Writing Attributes
ncid | NetCDF file or group ID. |
varid | Variable ID, or NC_GLOBAL for a global attribute. |
name | Attribute NetCDF Names. |
xtype | The type of attribute to write. Data will be converted to this type. |
len | Number of values provided for the attribute. |
value | Pointer to one or more values. |
int nc_put_att_short | ( | int | ncid, |
int | varid, | ||
const char * | name, | ||
nc_type | xtype, | ||
size_t | len, | ||
const short * | value | ||
) |
Write an attribute of type short.
Also see Writing Attributes
ncid | NetCDF file or group ID. |
varid | Variable ID, or NC_GLOBAL for a global attribute. |
name | Attribute NetCDF Names. |
xtype | The type of attribute to write. Data will be converted to this type. |
len | Number of values provided for the attribute. |
value | Pointer to one or more values. |
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().
Also see Writing Attributes
ncid | NetCDF file or group ID. |
varid | Variable ID, or NC_GLOBAL for a global attribute. |
name | Attribute NetCDF Names. |
len | Number of values provided for the attribute. |
value | Pointer to one or more values. |
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).
Type conversion is not available with text attributes.
Also see Writing Attributes
ncid | NetCDF file or group ID. |
varid | Variable ID, or NC_GLOBAL for a global attribute. |
name | Attribute NetCDF Names. |
len | The length of the text array. |
value | Pointer to the start of the character array. |
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:
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 of type unsigned char.
Also see Writing Attributes
ncid | NetCDF file or group ID. |
varid | Variable ID, or NC_GLOBAL for a global attribute. |
name | Attribute NetCDF Names. |
xtype | The type of attribute to write. Data will be converted to this type. |
len | Number of values provided for the attribute. |
value | Pointer to one or more values. |
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 of type unsigned char.
Also see Writing Attributes
ncid | NetCDF file or group ID. |
varid | Variable ID, or NC_GLOBAL for a global attribute. |
name | Attribute NetCDF Names. |
xtype | The type of attribute to write. Data will be converted to this type. |
len | Number of values provided for the attribute. |
value | Pointer to one or more values. |
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 of type unsigned int.
Also see Writing Attributes
ncid | NetCDF file or group ID. |
varid | Variable ID, or NC_GLOBAL for a global attribute. |
name | Attribute NetCDF Names. |
xtype | The type of attribute to write. Data will be converted to this type. |
len | Number of values provided for the attribute. |
value | Pointer to one or more values. |
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 of type unsigned long long.
Also see Writing Attributes
ncid | NetCDF file or group ID. |
varid | Variable ID, or NC_GLOBAL for a global attribute. |
name | Attribute NetCDF Names. |
xtype | The type of attribute to write. Data will be converted to this type. |
len | Number of values provided for the attribute. |
value | Pointer to one or more values. |
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 of type unsigned short.
Also see Writing Attributes
ncid | NetCDF file or group ID. |
varid | Variable ID, or NC_GLOBAL for a global attribute. |
name | Attribute NetCDF Names. |
xtype | The type of attribute to write. Data will be converted to this type. |
len | Number of values provided for the attribute. |
value | Pointer to one or more values. |
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. In classic formats, if the new name is longer than the original name, the netCDF dataset must be in define mode. In netCDF-4/HDF5 files, attributes may be renamed at any time. You cannot rename an attribute to have the same name as another attribute of the same variable.
ncid | NetCDF or group ID, from a previous call to nc_open(), nc_create(), nc_def_grp(), or associated inquiry functions such as nc_inq_ncid(). |
varid | Variable ID of the attribute's variable, or NC_GLOBAL for a global attribute. |
name | Attribute NetCDF Names. |
newname | The new attribute NetCDF Names. |
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: