VAPoR
0.1
|
Wrapper for a collection of netCDF files. More...
#include <NetCDFCollection.h>
Classes | |
class | DerivedVar |
class | TimeVaryingVar |
Public Member Functions | |
NetCDFCollection () | |
virtual | ~NetCDFCollection () |
virtual int | Initialize (const std::vector< string > &files, const std::vector< string > &time_dimnames, const std::vector< string > &time_coordvar) |
virtual bool | VariableExists (string varname) const |
virtual bool | VariableExists (size_t ts, string varname) const |
virtual bool | IsDerivedVar (string varname) const |
virtual bool | IsStaggeredVar (string varname) const |
virtual bool | IsStaggeredDim (string dimname) const |
virtual std::vector< string > | GetVariableNames (int ndim, bool spatial) const |
virtual std::vector< size_t > | GetSpatialDims (string varname) const |
virtual std::vector< string > | GetSpatialDimNames (string varname) const |
virtual size_t | GetTimeDim (string varname) const |
virtual string | GetTimeDimName (string varname) const |
virtual std::vector< size_t > | GetDims (string varname) const |
virtual std::vector< string > | GetDimNames (string varname) const |
virtual bool | IsTimeVarying (string varname) const |
int | GetXType (string varname) const |
std::vector< string > | GetAttNames (string varname) const |
int | GetAttType (string varname, string attname) const |
void | GetAtt (string varname, string attname, std::vector< double > &values) const |
void | GetAtt (string varname, string attname, std::vector< long > &values) const |
void | GetAtt (string varname, string attname, string &values) const |
virtual std::vector< string > | GetDimNames () const |
virtual std::vector< size_t > | GetDims () const |
virtual size_t | GetNumTimeSteps () const |
virtual size_t | GetNumTimeSteps (string varname) const |
virtual int | GetTime (size_t ts, double &time) const |
virtual int | GetTimes (string varname, std::vector< double > ×) const |
virtual std::vector< double > | GetTimes () const |
virtual int | GetFile (size_t ts, string varname, string &file, size_t &local_ts) const |
virtual int | GetVariableInfo (string varname, NetCDFSimple::Variable &varinfo) const |
virtual bool | GetMissingValue (string varname, double &mv) const |
virtual int | OpenRead (size_t ts, string varname) |
virtual int | Read (size_t start[], size_t count[], float *data, int fd=0) |
virtual int | Read (size_t start[], size_t count[], int *data, int fd=0) |
virtual int | Read (std::vector< size_t > start, std::vector< size_t > count, float *data, int fd=0) |
virtual int | Read (std::vector< size_t > start, std::vector< size_t > count, int *data, int fd=0) |
virtual int | Read (float *data, int fd=0) |
virtual int | Read (char *data, int fd=0) |
virtual int | ReadNative (size_t start[], size_t count[], float *data, int fd=0) |
virtual int | ReadNative (size_t start[], size_t count[], int *data, int fd=0) |
virtual int | ReadNative (size_t start[], size_t count[], char *data, int fd=0) |
virtual int | ReadNative (float *data, int fd=0) |
virtual int | ReadNative (int *data, int fd=0) |
virtual int | ReadSlice (float *data, int fd=0) |
virtual int | ReadSliceNative (float *data, int fd=0) |
virtual int | SeekSlice (int offset, int whence, int fd=0) |
virtual int | Close (int fd=0) |
virtual void | SetStaggeredDims (const std::vector< string > dimnames) |
virtual void | SetMissingValueAttName (string attname) |
virtual std::vector< string > | GetFailedVars () const |
void | InstallDerivedVar (string varname, DerivedVar *derivedVar) |
void | RemoveDerivedVar (string varname) |
Public Member Functions inherited from VetsUtil::MyBase | |
MyBase () | |
const string & | getClassName () const |
Protected Member Functions | |
bool | _GetVariableInfo (string varname, NetCDFSimple::Variable &variable) const |
Protected Member Functions inherited from VetsUtil::MyBase | |
void | SetClassName (const string &name) |
Friends | |
std::ostream & | operator<< (std::ostream &o, const NetCDFCollection &ncdfc) |
Additional Inherited Members | |
Public Types inherited from VetsUtil::MyBase | |
typedef void(* | ErrMsgCB_T) (const char *msg, int err_code) |
typedef void(* | DiagMsgCB_T) (const char *msg) |
Static Public Member Functions inherited from VetsUtil::MyBase | |
static void | SetErrMsg (const char *format,...) |
Record a formatted error message. More... | |
static void | SetErrMsg (int errcode, const char *format,...) |
Record a formatted error message and an error code. More... | |
static const char * | GetErrMsg () |
static void | SetErrCode (int err_code) |
Record an error code. More... | |
static int | GetErrCode () |
Retrieve the current error code. More... | |
static void | SetErrMsgCB (ErrMsgCB_T cb) |
static ErrMsgCB_T | GetErrMsgCB () |
static void | SetErrMsgFilePtr (FILE *fp) |
static const FILE * | SetErrMsgFilePtr () |
static void | SetDiagMsg (const char *format,...) |
Record a formatted diagnostic message. More... | |
static const char * | GetDiagMsg () |
static void | SetDiagMsgCB (DiagMsgCB_T cb) |
static DiagMsgCB_T | GetDiagMsgCB () |
static void | SetDiagMsgFilePtr (FILE *fp) |
static bool | EnableErrMsg (bool enable) |
Static Public Attributes inherited from VetsUtil::MyBase | |
static char * | ErrMsg |
static int | ErrCode |
static int | ErrMsgSize |
static FILE * | ErrMsgFilePtr |
static ErrMsgCB_T | ErrMsgCB |
static char * | DiagMsg |
static int | DiagMsgSize |
static FILE * | DiagMsgFilePtr |
static DiagMsgCB_T | DiagMsgCB |
static bool | Enabled |
Wrapper for a collection of netCDF files.
This class treats a collection of netCDF files as a single, time-varying data set, providing a unified interface for accessing named 0D, 1D, 2D, and 3D spatial variables at a specified timestep, independent of which netCDF file contains the data.
The netCDF variables may be "explicitly" time-varying: the slowest varying dimension may correspond to time, while the remaining dimensions correspond to space. Or the variables may be implicitly time-varying, possessing no explicit time dimension, in which case the time index of a variable is determined by file ordering. For example, if the variable "v" is found in the files "a.nc" and "b.nc" and nowhere else, and "a.nc" preceeds "b.nc" in the list of files provided to the class constructor, then a.nc is assumed to contain "v" at time step 0, and "b.nc" contains "v" at time step 1.
The class understands the Arakawa C-Grid ("staggered" variables), and can interpolate them onto a common (unstaggered) grid.
Several file organizations are supported and discussed below. To ease discussion we introduce the terminology:
define TD : Time Dimension
define TCV : Time Coordinate Variable
define TVV : an explicitly Time Varying Variable (it has a time dimension)
define ITVV : an Implicit Time Varying Variable (has no time dimension, but has multiple occurences => order determines time)
define CV: Constant Variable (has no TD, occurs only once). CV variables are define for all time steps
Four file organizations are supported as described below:
case 1: No TD specified (therefore no TCV):
case 2: TD specified, but no TCV:
case 3a: TD & TCV specified, TCV appears in only file:
case 3b: TD & TCV specified, TCV appears in every file with TVV:
Definition at line 96 of file NetCDFCollection.h.
VAPoR::NetCDFCollection::NetCDFCollection | ( | ) |
|
virtual |
|
protected |
|
virtual |
Close the currently opened variable
[in] | fd | A currently opened file descriptor returned by OpenRead(). |
void VAPoR::NetCDFCollection::GetAtt | ( | string | varname, |
string | attname, | ||
std::vector< double > & | values | ||
) | const |
Return attribute values for attribute of type float
Return the values of the named attribute converted to type float.
[in] | attname | Name of the attribute |
[out] | values | A vector of attribute values |
void VAPoR::NetCDFCollection::GetAtt | ( | string | varname, |
string | attname, | ||
std::vector< long > & | values | ||
) | const |
void VAPoR::NetCDFCollection::GetAtt | ( | string | varname, |
string | attname, | ||
string & | values | ||
) | const |
std::vector<string> VAPoR::NetCDFCollection::GetAttNames | ( | string | varname | ) | const |
Return a list of available attribute's names
Returns a vector of all attribute names for the variable, varname
. If varname
is the empty string the names of all of the global attributes are returned. If varname
is not defined an empty vector is returned.
[in] | varname | The name of the variable to query, or the empty string if the names of global attributes are desired. |
attnames | A vector of returned attribute names |
int VAPoR::NetCDFCollection::GetAttType | ( | string | varname, |
string | attname | ||
) | const |
Return the netCDF external data type for an attribute
Returns the nc_type of the named variable attribute.
[in] | varname | The name of the variable to query, or the empty string if the names of global attributes are desired. |
[in] | name | Name of the attribute. |
If | an attribute named by name does not exist, a negative value is returned. |
|
virtual |
Return a variable's temporal and spatial dimension names
Returns the ordered list of temporal and spatial dimension names of the named variable.
[in] | varname | Name of variable |
dimnames | An ordered vector containing the variable's temporal and spatial dimension names. If varname is not defined an empty list is returned. |
|
inlinevirtual |
Return the names of all the dimensions.
Returns a list of all dimension names defined by all netCDF files in the entire collection. The ordering of the returned list coresponds to the ordering of the list of dimenension lengths returned by GetDims(). I.e. the length of the dimension with name GetDimNames()[i] is GetDims[i].
dimnames | A vector containing all dimension names. |
Definition at line 394 of file NetCDFCollection.h.
|
virtual |
Return a variable's temporal and spatial dimensions
Returns the ordered list of temporal and spatial dimensions of the named variable.
[in] | varname | Name of variable |
dims | An ordered vector containing the variables temporal and spatial dimensions. If varname is not defined a zero length vector is returned |
|
inlinevirtual |
Return the lengths of all the dimensions.
Returns a list of all dimension lengths defined by all netCDF files in the entire collection. The ordering of the returned list coresponds to the ordering of the list of dimenension names returned by GetDimNames(). I.e. the length of the dimension with name GetDimNames()[i] is GetDims[i].
dimlens | A vector containing all dimension lengths. |
Definition at line 409 of file NetCDFCollection.h.
|
inlinevirtual |
Return a list of variables that are not available for access
This method returns a list of variables that were detected in the collection of netCDF files but are not accessible from the NetCDFCollection class.
Definition at line 714 of file NetCDFCollection.h.
|
virtual |
Return the path to the netCDF file containing a variable
This method returns the path to the netCDF file containing the variable varname
, at the time step ts
.
[in] | ts | time step of variable |
[in] | varname | Name of variable |
[out] | file | The netCDF file path |
[out] | local_ts | local time index of variable within file |
retval | A negative int is returned on failure. |
|
virtual |
Return the missing value, if any, for a variable
This method returns the value of the missing data value marker, if defined, for the variable named by varname
.
[in] | varname | The variable name |
[out] | mv | The missing value for the variabled name by varname |
bool | The boolean true is returned if a missing value is defined. If no missing variable is defined the return value is false and the value of mv is not defined. |
Reimplemented in VAPoR::NetCDFCFCollection.
|
inlinevirtual |
Return the number of time steps in the data collection all variables
Return the number of time steps present. The number of time steps returned is the number of unique times present, and
[in] | varname | Name of variable |
value | The number of time steps |
Definition at line 424 of file NetCDFCollection.h.
|
inlinevirtual |
Return the number of time available for the named variable
Return the number of time steps present for the variable named by varname
.
[in] | varname | Name of variable |
value | The number of time steps. If varname is either not defined, or is defined but not time varying, 0 is returned. |
Definition at line 439 of file NetCDFCollection.h.
References GetTimeDim().
|
virtual |
Return a variable's spatial dimension names
Returns the ordered list of spatial dimension names of the named variable.
[in] | varname | Name of variable |
dimnames | An ordered vector containing the variable's spatial dimension names. If varname is not defined an empty list is returned. |
|
virtual |
Return a variable's spatial dimensions
Returns the ordered list of spatial dimensions of the named variable.
[in] | varname | Name of variable |
dims | An ordered vector containing the variables spatial dimensions. If varname is not defined a zero length vector is returned |
|
virtual |
Return the user time associated with a time step
This method returns the time, in user-defined coordinates, associated with the time step, ts
. If no time coordinate variable was specified the user time is equivalent to the time step, ts
.
[in] | ts | A valid data set time step in the range from zero to GetNumTimeSteps() - 1. |
[out] | time | The user time |
retval | A negative int is returned on failure. |
|
virtual |
Return a variable's time dimension
Returns time dimension of the named variable.
[in] | varname | Name of variable |
dim | Number of time steps (time dimension) If varname is invalid or varname is not time varying 0 is returned. |
Referenced by GetNumTimeSteps().
|
virtual |
Return a variable's time dimension name
Returns the time dimension name of the named variable.
[in] | varname | Name of variable |
name | A string containing the variable's time dimension name. If varname is invalid or varname is not time varying the empty string is returned. |
|
virtual |
Return all the user times associated with a variable
This method returns the times, in user-defined coordinates, associated with the the variable, varname
.
[in] | varname | Name of variable |
|
inlinevirtual |
Return all the user times for this collection
This method returns the times, in user-defined coordinates, for this data collection.
retval | times A vector of user times. |
Definition at line 485 of file NetCDFCollection.h.
|
virtual |
Return the NetCDFSimple::Variable for the named variable
This method copies the contents of the NetCDFSimple::Variable class for the named variable into varinfo
[in] | varname | Name of variable |
retval | A negative int is returned on failure. |
|
virtual |
Return a list of variables with a given rank
Returns a list of variables having a dimension rank of ndim
. If spatial
is true only the variable's spatial dimension rank is examined. Thus if spatial
is true, and the named variable is explicitly time varying, the time-varying dimension is not counted. For example, if a variable named 'v' is defined with 4 dimensions in the netCDF file, and the slowest varying dimension name matches a named dimension specified in Initialize() by time_dimnames
, then the variable 'v' would be returned by a query with ndim==3 and spatial==true.
[in] | ndim | Rank of dimensions |
[in] | spatial | Only compare spatial dimensions against ndim |
int VAPoR::NetCDFCollection::GetXType | ( | string | varname | ) | const |
Return the netCDF external data type a variable
Returns the nc_type of the named variable
[in] | varname | The name of the variable to query. |
If | a variable named by name does not exist, a negative value is returned. |
|
virtual |
Initialze a new collection
Variables contained in the netCDF files may be explicitly time-varying (i.e. have a time dimension defined), or their time step may be determined implicitly by which file they are contained in.
The time ordering of time-varying variables is determined by:
files
in which the variable occurs[in] | files | A list of file containing time-varying 1D, 2D, and 3D variables. In the absense of an explicit time dimension, or time coordinate variable, the ordering of the files determines the the time steps of the variables contained therein. |
[in] | time_dimnames | A list of netCDF time dimensions. A variable whose slowest varying dimension name matches a name in time_dimnames is an explict time-varying variable with a time dimension. |
[in] | time_coordvar | The name of a coordinate variable containing time data. If a 1D variable with a name given by time_coordvar exists, this variable will be used to determine the time associated with each time step of a variable. |
|
inline |
Definition at line 795 of file NetCDFCollection.h.
|
inlinevirtual |
Returns true if the named variable is a derived variable.
This method returns true if the variable named by varname
is derived from other variables in the data collection.
[in] | varname | A variable name |
bool | Returns true if varname is a derived variable. |
Definition at line 184 of file NetCDFCollection.h.
|
virtual |
Returns true if the specified dimension is staggered
If the dimension named by dimname
is a staggered dimension, true is returned
[in] | dimname | Name of dimension |
|
virtual |
Returns true if the specified variable has any staggered dimensions
If the variabled named by varname
has any staggered dimensions, true is returned
[in] | varname | Name of variable |
boolean | indicating where variable varname has any staggered dimensions. |
|
virtual |
Return true if variable is time varying
Returns true if the variable named by varname
has a time varying coordinate
[in] | varname | Name of variable |
|
virtual |
Open the named variable for reading
This method prepares a netCDF variable, indicated by a variable name and time step pair, for subsequent read operations by methods of this class. A small, non-negative integer for use in subsequent read operations is returned. The file descriptor returned by a successful call will be the lowest-numbered file descriptor not currently open for the process, starting with zero.
[in] | ts | Time step of the variable to read |
[in] | varname | Name of the variable to read |
status | Returns a non-negative file descriptor on success |
Reimplemented in VAPoR::NetCDFCFCollection.
|
virtual |
Read data from the currently opened variable on an unstaggered grid
Read the hyperslice defined by start
and count
from the currently opened variable into the buffer pointed to by data
.
This method is identical in functionality to the netCDF function, nc_get_var_float, with the following two exceptions:
start
and count
) should be specified in the non-staggered coordinates.start
and count
. I.e. if the variable contains n dimensions in the netCDF file, only the n-1 fastest-varying (spatial) dimensions should be specified.[in] | start | Start vector with one element for each dimension |
[in] | count | Count vector with one element for each dimension |
[in] | fd | A currently opened file descriptor returned by OpenRead(). |
retval | A negative int is returned on failure. |
|
virtual |
|
virtual |
|
virtual |
|
virtual |
|
virtual |
|
virtual |
Read data from the currently opened variable on the native grid
This method is identical to the Read() method except that staggered variables are not interpolated to the non-staggered grid. Hence, start
and count
should be specified in staggered coordinates if the variable is staggered, and non-staggerd coordinates if the variable is not staggered.
[in] | start | Start vector with one element for each dimension |
[in] | count | Count vector with one element for each dimension |
[in] | fd | A currently opened file descriptor returned by OpenRead(). |
retval | A negative int is returned on failure. |
|
virtual |
|
virtual |
|
virtual |
|
virtual |
|
virtual |
Read a 2D slice from a 2D or 3D variable
The method will read 2D slices from a 2D or 3D variable until all slices have been processed. If the variable is staggered the slices will be interpolated onto the non-staggered grid for the currently opened variable. For 3D data each call to ReadSlice() will return a subsequent slice until all slices have been processed. The total number of slices is the value of the slowest varying dimension.
[in] | fd | A currently opened file descriptor returned by OpenRead(). |
[out] | data | The possibly resampled 2D data slice. It is the caller's responsibility to ensure that data points to sufficient space. |
status | Returns 1 if successful, 0 if there are no more slices to read, and a negative integer on error. |
|
virtual |
Read a 2D slice from a 2D or 3D variable on the native grid
This method is identical to ReadSlice() with the exception that if the currently opened variable is staggered, the variable will not be resampled to a non-staggered grid.
[in] | fd | A currently opened file descriptor returned by OpenRead(). |
[out] | data | The possibly resampled 2D data slice. It is the caller's responsibility to ensure that data points to sufficient space. |
status | Returns 1 if successful, 0 if there are no more slices to read, and a negative integer on error. |
|
inline |
Definition at line 799 of file NetCDFCollection.h.
|
virtual |
Set the variable slice position indicator
This method changes the position of the slice indicator for an open variable. Subsequent reads with ReadSlice() or ReadSliceNative() will position the slice offset based on offset
. If whence
is 0 then offset
is added to the first variable slice. If whence
is one then offset
is added to the current slice position. If whence
is 2 then offset
is added to the last slice. If the resulting slice position, after adding offset
, lies outside of the variable the offset will be mapped to the closest valid value (i.e. the first or last slice).
[in] | offset | integer slice offset |
[in] | whence | one of 0, 1, 2 |
[in] | fd | A currently opened file descriptor returned by OpenRead(). |
A | negative int is returned if fd is not valid (an open file descriptor) or if whence is not one of 0, 1, or 2. |
|
inlinevirtual |
Identify missing value variable attribute name
This method informs the class instance of the name of a netCDF variable attribute, if one exists, that contains the missing value for the variable. During interpolation of staggered variables the missing value is needed for correct processing
attname | Name of netCDF variable attribute specifying the missing value |
Definition at line 704 of file NetCDFCollection.h.
|
inlinevirtual |
Identify staggered dimensions
This method informs the class instance of any staggered dimensions. Class methods that read variable data will use the staggered dimension list to identify staggered variables and may interpolate the data to a non staggered grid
dimnames | A list of staggered netCDF dimension names |
Definition at line 690 of file NetCDFCollection.h.
|
virtual |
Return a boolean indicating whether a variable exists in the data collection.
This method returns true if the variable named by varname
is contained in the data collection. The variable may be present inside of a netCDF file, or may be a variable derived the the NetCDFCFCollection class. In the latter case all native variables used to construct varname
must also be present.
[in] | varname | A netCDF variable name |
bool | Returns true if varname is contained any one of the netCDF files used to instantiate the class, or if varname is a derived variable. |
|
virtual |
Return a boolean indicating whether a variable is defined for a particular time step.
This method returns true if the variable named by varname
is contained in the data collection and defined for time step ts
. The variable may be present inside of a netCDF file, or may be a variable derived the the NetCDFCFCollection class. In the latter case all native variables used to construct varname
must also be present.
[in] | ts | A valid data set time step in the range from zero to GetNumTimeSteps() - 1. |
[in] | varname | A netCDF variable name |
bool | Returns true if varname is contained any one of the netCDF files used to instantiate the class, or if varname is a derived variable. |
|
friend |