NetCDF
4.9.2
|
Attribute functions. More...
#include "ncdispatch.h"
Go to the source code of this file.
Functions | |
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_double (int ncid, int varid, const char *name, double *value) |
Get an attribute array of type double. 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_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_longlong (int ncid, int varid, const char *name, long long *value) |
Get an attribute array of type long long. 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_short (int ncid, int varid, const char *name, short *value) |
Get an attribute array of type short. More... | |
int | nc_get_att_string (int ncid, int varid, const char *name, char **value) |
Get an attribute array of type string. More... | |
int | nc_get_att_text (int ncid, int varid, const char *name, char *value) |
Get a text attribute. 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_uchar (int ncid, int varid, const char *name, unsigned char *value) |
Get an attribute of an signed char type. 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_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_ushort (int ncid, int varid, const char *name, unsigned short *value) |
Get an attribute array of type unsigned short. More... | |