1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208
|
/** \file
Attribute inquiry functions
These functions find out about attributes.
Copyright 2011 University Corporation for Atmospheric
Research/Unidata. See \ref copyright file for more info. */
#include "ncdispatch.h"
/** \name Learning about Attributes
Functions to learn about the attributes in a file. */
/*! \{ */ /* All these functions are part of this named group... */
/**
\ingroup attributes
Return information about a netCDF attribute.
The function nc_inq_att returns the attribute's type and length.
\param 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().
\param varid Variable ID of the attribute's variable, or ::NC_GLOBAL
for a global attribute.
\param name Pointer to the location for the returned attribute \ref
object_name. \ref ignored_if_null.
\param xtypep Pointer to location for returned attribute \ref
data_type. \ref ignored_if_null.
\param 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. \ref ignored_if_null.
\section nc_inq_att_example 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:
\code
#include <netcdf.h>
...
int status;
int ncid;
int rh_id;
nc_type vr_type, t_type;
size_t vr_len, t_len;
...
status = nc_open("foo.nc", NC_NOWRITE, &ncid);
if (status != NC_NOERR) handle_error(status);
...
status = nc_inq_varid (ncid, "rh", &rh_id);
if (status != NC_NOERR) handle_error(status);
...
status = nc_inq_att (ncid, rh_id, "valid_range", &vr_type, &vr_len);
if (status != NC_NOERR) handle_error(status);
status = nc_inq_att (ncid, NC_GLOBAL, "title", &t_type, &t_len);
if (status != NC_NOERR) handle_error(status);
\endcode
*/
int
nc_inq_att(int ncid, int varid, const char *name, nc_type *xtypep,
size_t *lenp)
{
NC* ncp;
int stat = NC_check_id(ncid, &ncp);
if(stat != NC_NOERR) return stat;
return ncp->dispatch->inq_att(ncid, varid, name, xtypep, lenp);
}
/**
\ingroup attributes
Find an attribute ID.
\param 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().
\param varid Variable ID of the attribute's variable, or ::NC_GLOBAL for
a global attribute.
\param name Attribute \ref object_name.
\param 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.
*/
int
nc_inq_attid(int ncid, int varid, const char *name, int *idp)
{
NC* ncp;
int stat = NC_check_id(ncid, &ncp);
if(stat != NC_NOERR) return stat;
return ncp->dispatch->inq_attid(ncid, varid, name, idp);
}
/**
\ingroup attributes
Find the name of an attribute.
\param 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().
\param varid Variable ID of the attribute's variable, or ::NC_GLOBAL
for a global attribute.
\param 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().
\param name Pointer to the location for the returned attribute \ref
object_name.
*/
int
nc_inq_attname(int ncid, int varid, int attnum, char *name)
{
NC* ncp;
int stat = NC_check_id(ncid, &ncp);
if(stat != NC_NOERR) return stat;
return ncp->dispatch->inq_attname(ncid, varid, attnum, name);
}
/**
\ingroup attributes
Find number of global or group attributes.
\param 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().
\param nattsp Pointer where number of global or group attributes will be
written. \ref ignored_if_null.
*/
int
nc_inq_natts(int ncid, int *nattsp)
{
NC* ncp;
int stat = NC_check_id(ncid, &ncp);
if(stat != NC_NOERR) return stat;
if(nattsp == NULL) return NC_NOERR;
return ncp->dispatch->inq(ncid, NULL, NULL, nattsp, NULL);
}
/**
\ingroup attributes
Find the type of an attribute.
\param 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().
\param varid Variable ID of the attribute's variable, or ::NC_GLOBAL
for a global or group attribute.
\param name Attribute \ref object_name.
\param xtypep Pointer to location for returned attribute \ref data_type.
*/
int
nc_inq_atttype(int ncid, int varid, const char *name, nc_type *xtypep)
{
NC* ncp;
int stat = NC_check_id(ncid, &ncp);
if(stat != NC_NOERR) return stat;
return ncp->dispatch->inq_att(ncid, varid, name, xtypep, NULL);
}
/**
\ingroup attributes
Find the length of an attribute.
\param 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().
\param varid Variable ID of the attribute's variable, or ::NC_GLOBAL
for a global or group attribute.
\param name Attribute \ref object_name.
\param 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. \ref ignored_if_null.
*/
int
nc_inq_attlen(int ncid, int varid, const char *name, size_t *lenp)
{
NC* ncp;
int stat = NC_check_id(ncid, &ncp);
if(stat != NC_NOERR) return stat;
return ncp->dispatch->inq_att(ncid, varid, name, NULL, lenp);
}
/*! \} */ /* End of named group ...*/
|