|
30 | 30 | * allocate enough space to hold them. If you don't know how much |
31 | 31 | * space to reserve, call nc_inq_attlen() first to find out the length |
32 | 32 | * of the attribute. |
| 33 | + * |
| 34 | + * <h1>Example</h1> |
| 35 | + * |
| 36 | + * Here is an example using nc_get_att_double() to determine the |
| 37 | + * values of a variable attribute named valid_range for a netCDF |
| 38 | + * variable named rh from a netCDF dataset named foo.nc. |
| 39 | + * |
| 40 | + * In this example, it is assumed that we don't know how many values |
| 41 | + * will be returned, but that we do know the types of the |
| 42 | + * attributes. Hence, to allocate enough space to store them, we must |
| 43 | + * first inquire about the length of the attributes. |
| 44 | +
|
| 45 | +@code |
| 46 | + #include <netcdf.h> |
| 47 | + ... |
| 48 | + int status; |
| 49 | + int ncid; |
| 50 | + int rh_id; |
| 51 | + int vr_len; |
| 52 | + double *vr_val; |
| 53 | +
|
| 54 | + ... |
| 55 | + status = nc_open("foo.nc", NC_NOWRITE, &ncid); |
| 56 | + if (status != NC_NOERR) handle_error(status); |
| 57 | + ... |
| 58 | + status = nc_inq_varid (ncid, "rh", &rh_id); |
| 59 | + if (status != NC_NOERR) handle_error(status); |
| 60 | + ... |
| 61 | + status = nc_inq_attlen (ncid, rh_id, "valid_range", &vr_len); |
| 62 | + if (status != NC_NOERR) handle_error(status); |
| 63 | +
|
| 64 | + vr_val = (double *) malloc(vr_len * sizeof(double)); |
| 65 | +
|
| 66 | + status = nc_get_att_double(ncid, rh_id, "valid_range", vr_val); |
| 67 | + if (status != NC_NOERR) handle_error(status); |
| 68 | + ... |
| 69 | +@endcode |
33 | 70 | */ |
34 | 71 | /**@{*/ /* Start doxygen member group. */ |
35 | 72 |
|
@@ -224,73 +261,6 @@ nc_get_att_schar(int ncid, int varid, const char *name, signed char *value) |
224 | 261 | return ncp->dispatch->get_att(ncid, varid, name, (void *)value, NC_BYTE); |
225 | 262 | } |
226 | 263 |
|
227 | | -/** |
228 | | - * @ingroup attributes |
229 | | - * Get an attribute of an atomic type. |
230 | | - * |
231 | | - * Also see @ref getting_attributes "Getting Attributes" |
232 | | - * |
233 | | - * This function gets an attribute of an atomic type from the netCDF |
234 | | - * file. |
235 | | - * |
236 | | - * @param ncid NetCDF or group ID, from a previous call to nc_open(), |
237 | | - * nc_create(), nc_def_grp(), or associated inquiry functions such as |
238 | | - * nc_inq_ncid(). |
239 | | - * @param varid Variable ID of the attribute's variable, or |
240 | | - * ::NC_GLOBAL for a global attribute. |
241 | | - * @param name Attribute name. |
242 | | - * @param value Pointer that will get array of attribute value(s). Use |
243 | | - * nc_inq_attlen() to learn length. |
244 | | - * |
245 | | - * <h1>Example</h1> |
246 | | - * |
247 | | - * Here is an example using nc_get_att_double() to determine the |
248 | | - * values of a variable attribute named valid_range for a netCDF |
249 | | - * variable named rh from a netCDF dataset named foo.nc. |
250 | | - * |
251 | | - * In this example, it is assumed that we don't know how many values |
252 | | - * will be returned, but that we do know the types of the |
253 | | - * attributes. Hence, to allocate enough space to store them, we must |
254 | | - * first inquire about the length of the attributes. |
255 | | -
|
256 | | -@code |
257 | | - #include <netcdf.h> |
258 | | - ... |
259 | | - int status; |
260 | | - int ncid; |
261 | | - int rh_id; |
262 | | - int vr_len; |
263 | | - double *vr_val; |
264 | | -
|
265 | | - ... |
266 | | - status = nc_open("foo.nc", NC_NOWRITE, &ncid); |
267 | | - if (status != NC_NOERR) handle_error(status); |
268 | | - ... |
269 | | - status = nc_inq_varid (ncid, "rh", &rh_id); |
270 | | - if (status != NC_NOERR) handle_error(status); |
271 | | - ... |
272 | | - status = nc_inq_attlen (ncid, rh_id, "valid_range", &vr_len); |
273 | | - if (status != NC_NOERR) handle_error(status); |
274 | | -
|
275 | | - vr_val = (double *) malloc(vr_len * sizeof(double)); |
276 | | -
|
277 | | - status = nc_get_att_double(ncid, rh_id, "valid_range", vr_val); |
278 | | - if (status != NC_NOERR) handle_error(status); |
279 | | - ... |
280 | | -@endcode |
281 | | -
|
282 | | - * @return ::NC_NOERR for success. |
283 | | - * @return ::NC_EBADID Bad ncid. |
284 | | - * @return ::NC_ENOTVAR Bad varid. |
285 | | - * @return ::NC_EBADNAME Bad name. See \ref object_name. |
286 | | - * @return ::NC_EINVAL Invalid parameters. |
287 | | - * @return ::NC_ENOTATT Can't find attribute. |
288 | | - * @return ::NC_ECHAR Can't convert to or from NC_CHAR. |
289 | | - * @return ::NC_ENOMEM Out of memory. |
290 | | - * @return ::NC_ERANGE Data conversion went out of range. |
291 | | - * @author Glenn Davis, Ed Hartnett, Dennis Heimbigner |
292 | | -*/ |
293 | | - |
294 | 264 | /** |
295 | 265 | * @ingroup attributes |
296 | 266 | * Get an attribute of an signed char type. |
|
0 commit comments