ERF
Energy Research and Forecasting: An Atmospheric Modeling Code
ncutils::NCVar Struct Reference

Representation of a NetCDF variable. More...

#include <ERF_NCInterface.H>

Collaboration diagram for ncutils::NCVar:

Public Member Functions

std::string name () const
 Name of this variable. More...
 
int ndim () const
 Number of array dimensions for this variable. More...
 
std::vector< size_t > shape () const
 Shape of the array (size in each array dimension) More...
 
void put (const double *) const
 Write out the entire variable. More...
 
void put (const float *) const
 
void put (const int *) const
 
void put (const double *, const std::vector< size_t > &, const std::vector< size_t > &) const
 Write out a slice of data. More...
 
void put (const double *, const std::vector< size_t > &, const std::vector< size_t > &, const std::vector< ptrdiff_t > &) const
 
void put (const float *, const std::vector< size_t > &, const std::vector< size_t > &) const
 Write out a slice of data. More...
 
void put (const float *, const std::vector< size_t > &, const std::vector< size_t > &, const std::vector< ptrdiff_t > &) const
 
void put (const int *, const std::vector< size_t > &, const std::vector< size_t > &) const
 
void put (const int *, const std::vector< size_t > &, const std::vector< size_t > &, const std::vector< ptrdiff_t > &) const
 
void put (const char **, const std::vector< size_t > &, const std::vector< size_t > &) const
 
void put (const char **dptr, const std::vector< size_t > &start, const std::vector< size_t > &count, const std::vector< ptrdiff_t > &stride) const
 
void get (double *) const
 Read the entire variable from file. More...
 
void get (float *) const
 
void get (int *) const
 
void get (double *, const std::vector< size_t > &, const std::vector< size_t > &) const
 Read a chunk of data from the file. More...
 
void get (double *, const std::vector< size_t > &, const std::vector< size_t > &, const std::vector< ptrdiff_t > &) const
 Read a chunk of data with strides. More...
 
void get (float *, const std::vector< size_t > &, const std::vector< size_t > &) const
 Read a chunk of data from the file. More...
 
void get (float *, const std::vector< size_t > &, const std::vector< size_t > &, const std::vector< ptrdiff_t > &) const
 Read a chunk of data with strides. More...
 
void get (int *, const std::vector< size_t > &, const std::vector< size_t > &) const
 
void get (int *, const std::vector< size_t > &, const std::vector< size_t > &, const std::vector< ptrdiff_t > &) const
 
void get (char *, const std::vector< size_t > &, const std::vector< size_t > &) const
 Read a chunk of data from the file. More...
 
void get (char *, const std::vector< size_t > &, const std::vector< size_t > &, const std::vector< ptrdiff_t > &) const
 Read a chunk of data with strides. More...
 
bool has_attr (const std::string &name) const
 
void put_attr (const std::string &name, const std::string &value) const
 
void put_attr (const std::string &name, const std::vector< double > &value) const
 
void put_attr (const std::string &name, const std::vector< float > &value) const
 
void put_attr (const std::string &name, const std::vector< int > &value) const
 
std::string get_attr (const std::string &name) const
 
void get_attr (const std::string &name, std::vector< double > &value) const
 
void get_attr (const std::string &name, std::vector< float > &value) const
 
void get_attr (const std::string &name, std::vector< int > &value) const
 
void par_access (int cmode) const
 

Public Attributes

const int ncid
 File/Group identifier. More...
 
const int varid
 Variable ID used with NetCDF API. More...
 

Detailed Description

Representation of a NetCDF variable.

Member Function Documentation

◆ get() [1/11]

void ncutils::NCVar::get ( char *  dptr,
const std::vector< size_t > &  start,
const std::vector< size_t > &  count 
) const

Read a chunk of data from the file.

356 {
357  check_nc_error(
358  nc_get_vara_text(ncid, varid, start.data(), count.data(), dptr));
359 }
const int ncid
File/Group identifier.
Definition: ERF_NCInterface.H:55
const int varid
Variable ID used with NetCDF API.
Definition: ERF_NCInterface.H:58

◆ get() [2/11]

void ncutils::NCVar::get ( char *  dptr,
const std::vector< size_t > &  start,
const std::vector< size_t > &  count,
const std::vector< ptrdiff_t > &  stride 
) const

Read a chunk of data with strides.

365 {
366  check_nc_error(nc_get_vars_text(
367  ncid, varid, start.data(), count.data(), stride.data(), dptr));
368 }

◆ get() [3/11]

void ncutils::NCVar::get ( double *  ptr) const

Read the entire variable from file.

Error-checking wrapper for NetCDF function nc_get_var_double

Parameters
ptrPointer to the data location we use to get
248 {
249  check_nc_error(nc_get_var_double(ncid, varid, ptr));
250 }

◆ get() [4/11]

void ncutils::NCVar::get ( double *  dptr,
const std::vector< size_t > &  start,
const std::vector< size_t > &  count 
) const

Read a chunk of data from the file.

Error-checking wrapper for NetCDF function nc_get_vara_double

Parameters
dptrPointer to the data location for get
startStarting indices
countCount sizes
282 {
283  check_nc_error(
284  nc_get_vara_double(ncid, varid, start.data(), count.data(), dptr));
285 }

◆ get() [5/11]

void ncutils::NCVar::get ( double *  dptr,
const std::vector< size_t > &  start,
const std::vector< size_t > &  count,
const std::vector< ptrdiff_t > &  stride 
) const

Read a chunk of data with strides.

Error-checking wrapper for NetCDF function nc_get_vars_double

Parameters
dptrPointer to the data location for get
startStarting indices
countCount sizes
strideStride length for the data
299 {
300  check_nc_error(nc_get_vars_double(
301  ncid, varid, start.data(), count.data(), stride.data(), dptr));
302 }

◆ get() [6/11]

void ncutils::NCVar::get ( float *  ptr) const

Error-checking wrapper for NetCDF function nc_get_var_float

Parameters
ptrPointer to the data location we use to get
258 {
259  check_nc_error(nc_get_var_float(ncid, varid, ptr));
260 }

◆ get() [7/11]

void ncutils::NCVar::get ( float *  dptr,
const std::vector< size_t > &  start,
const std::vector< size_t > &  count 
) const

Read a chunk of data from the file.

Error-checking wrapper for NetCDF function nc_get_vara_float

Parameters
dptrPointer to the data location for get
startStarting indices
countCount sizes
314 {
315  check_nc_error(
316  nc_get_vara_float(ncid, varid, start.data(), count.data(), dptr));
317 }

◆ get() [8/11]

void ncutils::NCVar::get ( float *  dptr,
const std::vector< size_t > &  start,
const std::vector< size_t > &  count,
const std::vector< ptrdiff_t > &  stride 
) const

Read a chunk of data with strides.

Error-checking wrapper for NetCDF function nc_get_vars_float

Parameters
dptrPointer to the data location for get
startStarting indices
countCount sizes
strideStride length for the data
331 {
332  check_nc_error(nc_get_vars_float(
333  ncid, varid, start.data(), count.data(), stride.data(), dptr));
334 }

◆ get() [9/11]

void ncutils::NCVar::get ( int *  ptr) const

Error-checking wrapper for NetCDF function nc_get_var_int

Parameters
ptrPointer to the data location we use to get
268 {
269  check_nc_error(nc_get_var_int(ncid, varid, ptr));
270 }

◆ get() [10/11]

void ncutils::NCVar::get ( int *  dptr,
const std::vector< size_t > &  start,
const std::vector< size_t > &  count 
) const
339 {
340  check_nc_error(
341  nc_get_vara_int(ncid, varid, start.data(), count.data(), dptr));
342 }

◆ get() [11/11]

void ncutils::NCVar::get ( int *  dptr,
const std::vector< size_t > &  start,
const std::vector< size_t > &  count,
const std::vector< ptrdiff_t > &  stride 
) const
348 {
349  check_nc_error(nc_get_vars_int(
350  ncid, varid, start.data(), count.data(), stride.data(), dptr));
351 }

◆ get_attr() [1/4]

std::string ncutils::NCVar::get_attr ( const std::string &  name) const
403 {
404  size_t lenp;
405  std::vector<char> aval;
406  check_nc_error(nc_inq_attlen(ncid, varid, name.data(), &lenp));
407  aval.resize(lenp);
408  check_nc_error(nc_get_att_text(ncid, varid, name.data(), aval.data()));
409  return std::string{aval.begin(), aval.end()};
410 }
std::string name() const
Name of this variable.
Definition: ERF_NCInterface.cpp:50
Here is the call graph for this function:

◆ get_attr() [2/4]

void ncutils::NCVar::get_attr ( const std::string &  name,
std::vector< double > &  value 
) const
413 {
414  size_t lenp;
415  check_nc_error(nc_inq_attlen(ncid, varid, name.data(), &lenp));
416  values.resize(lenp);
417  check_nc_error(nc_get_att_double(ncid, varid, name.data(), values.data()));
418 }
Here is the call graph for this function:

◆ get_attr() [3/4]

void ncutils::NCVar::get_attr ( const std::string &  name,
std::vector< float > &  value 
) const
421 {
422  size_t lenp;
423  check_nc_error(nc_inq_attlen(ncid, varid, name.data(), &lenp));
424  values.resize(lenp);
425  check_nc_error(nc_get_att_float(ncid, varid, name.data(), values.data()));
426 }
Here is the call graph for this function:

◆ get_attr() [4/4]

void ncutils::NCVar::get_attr ( const std::string &  name,
std::vector< int > &  value 
) const
429 {
430  size_t lenp;
431  check_nc_error(nc_inq_attlen(ncid, varid, name.data(), &lenp));
432  values.resize(lenp);
433  check_nc_error(nc_get_att_int(ncid, varid, name.data(), values.data()));
434 }
Here is the call graph for this function:

◆ has_attr()

bool ncutils::NCVar::has_attr ( const std::string &  name) const
371 {
372  int ierr;
373  size_t lenp;
374  ierr = nc_inq_att(ncid, varid, name.data(), nullptr, &lenp);
375  return (ierr == NC_NOERR);
376 }
Here is the call graph for this function:

◆ name()

std::string ncutils::NCVar::name ( ) const

Name of this variable.

Error-checking wrapper for NetCDF function nc_inq_varname

51 {
52  check_nc_error(nc_inq_varname(ncid, varid, recname));
53  return std::string(recname);
54 }

Referenced by get_attr(), has_attr(), and put_attr().

Here is the caller graph for this function:

◆ ndim()

int ncutils::NCVar::ndim ( ) const

Number of array dimensions for this variable.

Error-checking wrapper for NetCDF function nc_inq_varndims

60 {
61  int ndims;
62  check_nc_error(nc_inq_varndims(ncid, varid, &ndims));
63  return ndims;
64 }

Referenced by shape().

Here is the caller graph for this function:

◆ par_access()

void ncutils::NCVar::par_access ( int  cmode) const
438 {
439  check_nc_error(nc_var_par_access(ncid, varid, cmode));
440 }

◆ put() [1/11]

void ncutils::NCVar::put ( const char **  dptr,
const std::vector< size_t > &  start,
const std::vector< size_t > &  count 
) const

Error-checking wrapper for NetCDF function nc_put_vara_string

Parameters
dptrPointer to the data to put
startStarting indices
countCount sizes
220 {
221  check_nc_error(
222  nc_put_vara_string(ncid, varid, start.data(), count.data(), dptr));
223 }

◆ put() [2/11]

void ncutils::NCVar::put ( const char **  dptr,
const std::vector< size_t > &  start,
const std::vector< size_t > &  count,
const std::vector< ptrdiff_t > &  stride 
) const

Error-checking wrapper for NetCDF function nc_put_vars_string

Parameters
dptrPointer to the data to put
startStarting indices
countCount sizes
strideStride length for the data
237 {
238  check_nc_error(nc_put_vars_string(
239  ncid, varid, start.data(), count.data(), stride.data(), dptr));
240 }

◆ put() [3/11]

void ncutils::NCVar::put ( const double *  ptr) const

Write out the entire variable.

Error-checking wrapper for NetCDF function nc_put_var_double

Parameters
ptrPointer to the data to put
90 {
91  check_nc_error(nc_put_var_double(ncid, varid, ptr));
92 }

◆ put() [4/11]

void ncutils::NCVar::put ( const double *  dptr,
const std::vector< size_t > &  start,
const std::vector< size_t > &  count 
) const

Write out a slice of data.

Error-checking wrapper for NetCDF function nc_put_vara_double

Parameters
dptrPointer to the data to put
startStarting indices
countCount sizes
124 {
125  check_nc_error(
126  nc_put_vara_double(ncid, varid, start.data(), count.data(), dptr));
127 }

◆ put() [5/11]

void ncutils::NCVar::put ( const double *  dptr,
const std::vector< size_t > &  start,
const std::vector< size_t > &  count,
const std::vector< ptrdiff_t > &  stride 
) const

Write out a slice of data with with strides (see hyperslab definition in NetCDF)

Error-checking wrapper for NetCDF function nc_put_vars_double

Parameters
dptrPointer to the data to put
startStarting indices
countCount sizes
strideStride length for the data
141 {
142  check_nc_error(nc_put_vars_double(
143  ncid, varid, start.data(), count.data(), stride.data(), dptr));
144 }

◆ put() [6/11]

void ncutils::NCVar::put ( const float *  ptr) const

Error-checking wrapper for NetCDF function nc_put_var_float

Parameters
ptrPointer to the data to put
100 {
101  check_nc_error(nc_put_var_float(ncid, varid, ptr));
102 }

◆ put() [7/11]

void ncutils::NCVar::put ( const float *  dptr,
const std::vector< size_t > &  start,
const std::vector< size_t > &  count 
) const

Write out a slice of data.

Error-checking wrapper for NetCDF function nc_put_vara_float

Parameters
dptrPointer to the data to put
startStarting indices
countCount sizes
156 {
157  check_nc_error(
158  nc_put_vara_float(ncid, varid, start.data(), count.data(), dptr));
159 }

◆ put() [8/11]

void ncutils::NCVar::put ( const float *  dptr,
const std::vector< size_t > &  start,
const std::vector< size_t > &  count,
const std::vector< ptrdiff_t > &  stride 
) const

Write out a slice of data with with strides (see hyperslab definition in NetCDF)

Error-checking wrapper for NetCDF function nc_put_vars_float

Parameters
dptrPointer to the data to put
startStarting indices
countCount sizes
strideStride length for the data
173 {
174  check_nc_error(nc_put_vars_float(
175  ncid, varid, start.data(), count.data(), stride.data(), dptr));
176 }

◆ put() [9/11]

void ncutils::NCVar::put ( const int *  ptr) const

Error-checking wrapper for NetCDF function nc_put_var_int

Parameters
ptrPointer to the data to put
110 {
111  check_nc_error(nc_put_var_int(ncid, varid, ptr));
112 }

◆ put() [10/11]

void ncutils::NCVar::put ( const int *  dptr,
const std::vector< size_t > &  start,
const std::vector< size_t > &  count 
) const

Error-checking wrapper for NetCDF function nc_put_vara_int

Parameters
dptrPointer to the data to put
startStarting indices
countCount sizes
188 {
189  check_nc_error(
190  nc_put_vara_int(ncid, varid, start.data(), count.data(), dptr));
191 }

◆ put() [11/11]

void ncutils::NCVar::put ( const int *  dptr,
const std::vector< size_t > &  start,
const std::vector< size_t > &  count,
const std::vector< ptrdiff_t > &  stride 
) const

Error-checking wrapper for NetCDF function nc_put_vars_int

Parameters
dptrPointer to the data to put
startStarting indices
countCount sizes
strideStride length for the data
205 {
206  check_nc_error(nc_put_vars_int(
207  ncid, varid, start.data(), count.data(), stride.data(), dptr));
208 }

◆ put_attr() [1/4]

void ncutils::NCVar::put_attr ( const std::string &  name,
const std::string &  value 
) const
379 {
380  check_nc_error(
381  nc_put_att_text(ncid, varid, name.data(), value.size(), value.data()));
382 }
Here is the call graph for this function:

◆ put_attr() [2/4]

void ncutils::NCVar::put_attr ( const std::string &  name,
const std::vector< double > &  value 
) const
385 {
386  check_nc_error(nc_put_att_double(
387  ncid, varid, name.data(), NC_DOUBLE, value.size(), value.data()));
388 }
Here is the call graph for this function:

◆ put_attr() [3/4]

void ncutils::NCVar::put_attr ( const std::string &  name,
const std::vector< float > &  value 
) const
391 {
392  check_nc_error(nc_put_att_float(
393  ncid, varid, name.data(), NC_FLOAT, value.size(), value.data()));
394 }
Here is the call graph for this function:

◆ put_attr() [4/4]

void ncutils::NCVar::put_attr ( const std::string &  name,
const std::vector< int > &  value 
) const
397 {
398  check_nc_error(nc_put_att_int(
399  ncid, varid, name.data(), NC_INT, value.size(), value.data()));
400 }
Here is the call graph for this function:

◆ shape()

std::vector< size_t > ncutils::NCVar::shape ( ) const

Shape of the array (size in each array dimension)

Error-checking function to get the length of each dimension from a NetCDF identity

70 {
71  int ndims = ndim();
72  std::vector<int> dimids(ndims);
73  std::vector<size_t> vshape(ndims);
74 
75  for (int i = 0; i < ndims; ++i)
76  check_nc_error(nc_inq_vardimid(ncid, varid, dimids.data()));
77 
78  for (int i = 0; i < ndims; ++i)
79  check_nc_error(nc_inq_dimlen(ncid, dimids[i], &vshape[i]));
80 
81  return vshape;
82 }
int ndim() const
Number of array dimensions for this variable.
Definition: ERF_NCInterface.cpp:59
Here is the call graph for this function:

Member Data Documentation

◆ ncid

const int ncutils::NCVar::ncid

File/Group identifier.

Referenced by get(), get_attr(), has_attr(), name(), ndim(), par_access(), put(), put_attr(), and shape().

◆ varid

const int ncutils::NCVar::varid

Variable ID used with NetCDF API.

Referenced by get(), get_attr(), has_attr(), name(), ndim(), par_access(), put(), put_attr(), and shape().


The documentation for this struct was generated from the following files: