VAPoR
3.0.0
|
Defines API for reading a collection of data. More...
#include <DC.h>
Classes | |
class | Attribute |
Variable or global metadata. More... | |
class | BaseVar |
Base class for storing variable metadata. More... | |
class | CoordVar |
Coordinate variable metadata. More... | |
class | DataVar |
Data variable metadata. More... | |
class | Dimension |
Metadata describing a coordinate dimension. More... | |
Public Types | |
enum | XType { INVALID = -1, FLOAT, DOUBLE, INT32, INT64, TEXT } |
External storage types for primitive data. More... | |
Public Types inherited from VetsUtil::MyBase | |
typedef void(* | ErrMsgCB_T) (const char *msg, int err_code) |
typedef void(* | DiagMsgCB_T) (const char *msg) |
Public Member Functions | |
DC () | |
virtual | ~DC () |
virtual int | Initialize (const vector< string > &paths)=0 |
virtual bool | GetDimension (string dimname, DC::Dimension &dimension) const =0 |
virtual std::vector< string > | GetDimensionNames () const =0 |
virtual bool | GetCoordVarInfo (string varname, DC::CoordVar &cvar) const =0 |
virtual bool | GetDataVarInfo (string varname, DC::DataVar &datavar) const =0 |
virtual bool | GetBaseVarInfo (string varname, DC::BaseVar &var) const =0 |
virtual std::vector< string > | GetDataVarNames () const =0 |
virtual std::vector< string > | GetCoordVarNames () const =0 |
virtual int | GetNumRefLevels (string varname) const =0 |
virtual int | GetAtt (string varname, string attname, vector< double > &values) const =0 |
virtual int | GetAtt (string varname, string attname, vector< long > &values) const =0 |
virtual int | GetAtt (string varname, string attname, string &values) const =0 |
virtual std::vector< string > | GetAttNames (string varname) const =0 |
virtual XType | GetAttType (string varname, string attname) const =0 |
virtual int | GetDimLensAtLevel (string varname, int level, std::vector< size_t > &dims_at_level, std::vector< size_t > &bs_at_level) const =0 |
virtual int | GetMapProjection (string lonname, string latname, string &projstring) const =0 |
virtual int | OpenVariableRead (size_t ts, string varname, int level=0, int lod=0)=0 |
virtual int | CloseVariable ()=0 |
virtual int | Read (float *data)=0 |
virtual int | ReadSlice (float *slice)=0 |
virtual int | ReadRegion (const vector< size_t > &min, const vector< size_t > &max, float *region)=0 |
virtual int | ReadRegionBlock (const vector< size_t > &min, const vector< size_t > &max, float *region)=0 |
virtual int | GetVar (string varname, int level, int lod, float *data)=0 |
virtual int | GetVar (size_t ts, string varname, int level, int lod, float *data)=0 |
virtual bool | VariableExists (size_t ts, string varname, int reflevel=0, int lod=0) const =0 |
virtual bool | GetDimension (string dimname, size_t &length, int &axis) const |
virtual std::vector< string > | GetDataVarNames (int ndim, bool spatial) const |
virtual std::vector< string > | GetCoordVarNames (int ndim, bool spatial) const |
virtual bool | IsTimeVarying (string varname) const |
virtual bool | IsCompressed (string varname) const |
virtual int | GetNumTimeSteps (string varname) const |
virtual int | GetCRatios (string varname, vector< size_t > &cratios) const |
virtual bool | IsDataVar (string varname) const |
virtual bool | IsCoordVar (string varname) const |
virtual int | GetMapProjection (string varname, string &projstring) const |
Public Member Functions inherited from VetsUtil::MyBase | |
MyBase () | |
const string & | getClassName () const |
Static Public Member Functions | |
static bool | ParseDimensions (const vector< DC::Dimension > &dimensions, vector< size_t > &sdims, size_t &numts) |
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) |
Additional Inherited Members | |
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 |
Protected Member Functions inherited from VetsUtil::MyBase | |
void | SetClassName (const string &name) |
Defines API for reading a collection of data.
The abstract Data Collection (DC) class defines an API for reading metadata and sampled data from a data collection. A data collection is a set of related data, most typically the discrete outputs from a single numerical simulation. The DC class is an abstract virtual class, providing a public API, but performing no actual storage operations. Derived implementations of the DC base class are required to support the API.
Variables in a DC may have 1, 2, or 3 spatial dimensions, and 0 or 1 temporal dimensions.
The DC is structured in the spirit of the "NetCDF Climate and Forecast (CF) Metadata Conventions", version 1.6, 5, December 2011. It supports only a subset of the CF functionality (e.g. there is no support for "Discrete Sampling Geometries"). Moreover, it is more restrictive than the CF in a number of areas. Particular items of note include:
This class inherits from VetsUtil::MyBase. Unless otherwise documented any method that returns an integer value is returning status. A negative value indicates failure. Error messages are logged via VetsUtil::MyBase::SetErrMsg(). Methods that return a boolean do not, unless otherwise documented, log an error message upon failure (return of false).
level | Grid refinement level for multiresolution variables. Compressed variables in the DC, if they exist, have a multi-resolution representation: the sampling grid for multi-resolution variables is hierarchical, and the dimension lengths of adjacent levels in the hierarchy differ by a factor of two. The To provide maximum flexibility as well as compatibility with previous versions of the DC the interpretation of For positive values of For negative values of |
lod | The level-of-detail parameter, lod , selects the approximation level for a compressed variable. The lod parameter is similar to the level parameter in that it provides control over accuracy of a compressed variable. However, instead of selecting the grid resolution the lod parameter controls the compression factor by indexing into the cratios vector (see below). As with the level parameter, both positive and negative values may be used to index into cratios and different interpretations. |
For positive values of lod
, a value of 0 indicates the the first element of cratios
, a value of 1 indicates the second element, and so on up to the size of the cratios
vector (See DC::GetCRatios()).
For negative values of lod
a value of -1 indexes the last element of cratios
, a value of -2 indexes the second to last element, and so on. Using negative values the first element of cratios
- the greatest compression rate - is indexed by negating the size of the cratios
vector.
cratios | A monotonically decreasing vector of compression ratios. Compressed variables in the DC are stored with a fixed, finite number of compression factors. The cratios vector is used to specify the available compression factors (ratios). A compression factor of 1 indicates no compression (1:1). A value of 2 indciates two to one compression (2:1), and so on. The minimum valid value of cratios is 1. The maximum value is determined by a number of factors and can be obtained using the CompressionInfo() method. |
bs | An ordered list of block dimensions that specifies the block decomposition of the variable. The rank of bs may be less than that of a variable's array dimensions, in which case only the n fastest varying variable dimensions will be blocked, where n is the rank of bs . The ordering of the dimensions in bs is from fastest to slowest. A block is the basic unit of compression in the DC: variables are decomposed into blocks, and individual blocks are compressed independently. |
wname | Name of wavelet used for transforming compressed variables between wavelet and physical space. Valid values are "bior1.1", "bior1.3", "bior1.5", "bior2.2", "bior2.4", "bior2.6", "bior2.8", "bior3.1", "bior3.3", "bior3.5", "bior3.7", "bior3.9", "bior4.4" |
enum VAPoR::DC::XType |
|
pure virtual |
Close the currently opened variable
Close the handle for variable opened with OpenVariableRead()
Implemented in VAPoR::VDC, VAPoR::VDCNetCDF, and VAPoR::DCWRF.
|
pure virtual |
Read an attribute
This method reads an attribute from the DC. The attribute can either be "global", if varname
is the empty string, or bound to a variable if varname
indentifies a variable in the DC.
[in] | varname | The name of the variable the attribute is bound to, or the empty string if the attribute is global |
[in] | attname | The attributes name |
[out] | type | The primitive data type storage format. This is the type that will be used to store the attribute on disk |
[out] | values | A vector to contain the returned floating point attribute values |
status | A negative int is returned on failure |
Implemented in VAPoR::VDC, and VAPoR::DCWRF.
|
pure virtual |
Implemented in VAPoR::VDC, and VAPoR::DCWRF.
|
pure virtual |
Implemented in VAPoR::VDC, and VAPoR::DCWRF.
|
pure virtual |
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 |
Implemented in VAPoR::VDC, and VAPoR::DCWRF.
|
pure virtual |
Return the external data type for an attribute
Returns the external storage 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. |
Implemented in VAPoR::VDC, and VAPoR::DCWRF.
|
pure virtual |
Return metadata about a data or coordinate variable
If the variable varname
is defined as either a data or coordinate variable its metadata will be returned in var
.
bool | If the named variable cannot be found false is returned and the values of var are undefined. |
Implemented in VAPoR::VDC, and VAPoR::DCWRF.
|
pure virtual |
Return a coordinate variable's definition
Return a reference to a DC::CoordVar object describing the coordinate variable named by varname
[in] | varname | A string specifying the name of the coordinate variable. |
[out] | coordvar | A CoordVar object containing the definition of the named variable. |
bool | False is returned if the named coordinate variable does not exist, and the contents of cvar will be undefined. |
Implemented in VAPoR::VDC, and VAPoR::DCWRF.
|
pure virtual |
Return a list of names for all of the defined coordinate variables.
Returns a list of names for all coordinate variables defined
Implemented in VAPoR::VDC, and VAPoR::DCWRF.
|
virtual |
Return a list of coordinate variables with a given dimension rank
Returns a list of all coordinate variables defined having a dimension rank of ndim
. If spatial
is true, only the spatial dimension rank of the variable is compared against ndim
[in] | ndim | Rank of dimensions for comparision |
[in] | spatial | Only compare spatial dimensions against ndim |
|
virtual |
Return the compression ratio vector for the indicated variable
Return the compression ratio vector for the indicated variable. The vector returned contains an ordered list of available compression ratios for the variable named by variable
. If the variable is not compressed, the cratios
parameter will contain a single element, one.
[in] | varname | Data or coordinate variable name. |
[out] | cratios | Ordered vector of compression ratios |
status | A negative int is returned on failure |
|
pure virtual |
Return a data variable's definition
Return a reference to a DC::DataVar object describing the data variable named by varname
[in] | varname | A string specifying the name of the variable. |
[out] | datavar | A DataVar object containing the definition of the named Data variable. |
bool | If the named data variable cannot be found false is returned and the values of datavar are undefined. |
Implemented in VAPoR::VDC, and VAPoR::DCWRF.
|
pure virtual |
Return a list of names for all of the defined data variables.
Returns a list of names for all data variables defined
Implemented in VAPoR::VDC, and VAPoR::DCWRF.
|
virtual |
Return a list of data variables with a given dimension rank
Returns a list of all data variables defined having a dimension rank of ndim
. If spatial
is true, only the spatial dimension rank of the variable is compared against ndim
[in] | ndim | Rank of dimensions for comparision |
[in] | spatial | Only compare spatial dimensions against ndim |
|
pure virtual |
Return a dimensions's definition
This method returns the definition of the dimension named by dimname
as a reference to a DC::Dimension object. If dimname
is not defined as a dimension then the name of dimension
will be the empty string()
[in] | dimname | A string specifying the name of the dimension. |
[out] | dimension | The returned Dimension object reference |
bool | If the named dimension can not be found false is returned. |
Implemented in VAPoR::VDC, and VAPoR::DCWRF.
|
virtual |
Return a dimensions's definition
This method returns the length and axis for the dimension named by dimname
. If dimname
is not defined as a dimension length
and axis
will both be set to zero, and false returned.
[in] | dimname | A string specifying the name of the dimension. |
[out] | length | The dimension length, which must be greater than zero. |
[out] | axis | The axis associated with the dimension. |
bool | If the named dimension can not be found false is returned. |
|
pure virtual |
Return names of all defined dimensions
This method returns the list of names of all of the dimensions defined in the DC.
Implemented in VAPoR::VDC, and VAPoR::DCWRF.
|
pure virtual |
Return a variable's dimension lengths at a specified refinement level
Compressed variables have a multi-resolution grid representation. This method returns the variable's ordered spatial and temporal dimension lengths, and block dimensions at the multiresolution refinement level specified by level
.
If the variable named by varname
is not compressed the variable's native dimensions are returned.
[in] | varname | Data or coordinate variable name. |
[in] | level | Specifies a member of a multi-resolution variable's grid hierarchy as described above. |
[out] | dims_at_level | An ordered vector containing the variable's dimensions at the specified refinement level |
[out] | bs_at_level | An ordered vector containing the variable's block dimensions at the specified refinement level |
status | Zero is returned upon success, otherwise -1. |
Implemented in VAPoR::VDC, and VAPoR::DCWRF.
|
pure virtual |
Return a Proj4 map projection string.
For georeference data sets that have map projections this method returns a properly formatted Proj4 projection string for mapping from geographic to cartographic coordinates. If no such projection exists an empty string is returned.
[in] | lonname | Name of longitude coordinate variable |
[in] | latname | Name of latitude coordinate variable |
[out] | projstring | An empty string if a Proj4 map projection is not available for the named coordinate pair, otherwise a properly formatted Proj4 projection string is returned. |
Implemented in VAPoR::VDC, and VAPoR::DCWRF.
|
virtual |
Return a Proj4 map projection string for the named variable.
For georeference data sets that have map projections this method returns a properly formatted Proj4 projection string for mapping from geographic to cartographic coordinates. If no such projection exists for the named data variable an empty string is returned.
[in] | varname | Name of a data variable |
[out] | projstring | An empty string if a Proj4 map projection is not available for the named coordinate pair, otherwise a properly formatted Proj4 projection string is returned. |
|
pure virtual |
Return the number of refinement levels for the indicated variable
Compressed variables have a multi-resolution grid representation. This method returns the number of levels in the hiearchy. A value of one indicates that only the native resolution is available. A value of two indicates that two levels, the native plus the next coarsest are available, and so on.
[in] | varname | Data or coordinate variable name. |
num | If varname is unknown zero is returned. if varname is not compressed (has no multi-resolution representation) one is returned. Otherwise the total number of levels in the multi-resolution hierarchy are returned. |
Implemented in VAPoR::VDC, and VAPoR::DCWRF.
|
virtual |
Return the time dimension length for a variable
Returns the number of time steps (length of the time dimension) for which a variable is defined. If varname
does not have a time coordinate 1 is returned. If varname
is not defined as a variable a negative int is returned.
[in] | varname | A string specifying the name of the variable. |
count | The length of the time dimension, or a negative int if varname is undefined. |
|
pure virtual |
Read an entire variable in one call
This method reads and entire variable (all time steps, all grid points) from a DC. This is the simplest interface for reading data from a DC. If the variable is split across multiple files GetVar() ensures that the data are correctly gathered and assembled into memory Any variables currently opened with OpenVariableRead() are first closed. Thus variables need not be opened with OpenVariableRead() prior to calling GetVar();
It is an error to call this method in define mode
[in] | varname | Name of the variable to write |
[in] | level | Refinement level of the variable. Ignored if the variable is not compressed. |
[in] | lod | Approximation level of the variable. A value of -1 indicates the maximum approximation level defined for the DC. Ignored if the variable is not compressed. |
[out] | data | Pointer to where data will be copied. It is the caller's responsbility to ensure data points to sufficient memory. |
status | A negative int is returned on failure |
Implemented in VAPoR::VDC, VAPoR::VDCNetCDF, and VAPoR::DCWRF.
|
pure virtual |
Read an entire variable at a given time step in one call
This method reads and entire variable (all grid points) at time step ts
from a DC. This is the simplest interface for reading data from a DC. Any variables currently opened with OpenVariableRead() are first closed. Thus variables need not be opened with OpenVariableRead() prior to calling GetVar();
It is an error to call this method in define mode
[in] | ts | Time step of the variable to write. This is the integer offset into the variable's temporal dimension. If the variable does not have a temporal dimension ts is ignored. |
[in] | varname | Name of the variable to write |
[in] | level | Refinement level of the variable. Ignored if the variable is not compressed. |
[in] | lod | Approximation level of the variable. A value of -1 indicates the maximum approximation level defined for the DC. Ignored if the variable is not compressed. |
[out] | data | Pointer to where data will be copied. It is the caller's responsbility to ensure data points to sufficient memory. |
status | A negative int is returned on failure |
Implemented in VAPoR::VDC, VAPoR::VDCNetCDF, and VAPoR::DCWRF.
|
pure virtual |
Initialize the DC class
Prepare a DC for reading. This method prepares the master DC file indicated by path
for reading. The method should be called immediately after the constructor, before any other class methods. This method exists only because C++ constructors can not return error codes.
[in] | path | Path name of file that contains, or will contain, the DC master file for this data collection |
status | A negative int is returned on failure |
Implemented in VAPoR::DCWRF.
|
virtual |
Return a boolean indicating whether a variable is compressed
This method returns true if the variable named by varname
is defined and it has a compressed representation. If either of these conditions is not true the method returns false.
[in] | varname | A string specifying the name of the variable. |
bool | Returns true if variable varname exists and is compressed |
|
inlinevirtual |
Return a boolean indicating whether a variable is a coordinate variable
This method returns true if a coordinate variable is defined with the name varname
. Otherwise the method returns false.
bool | Returns true if varname names a defined coordinate variable |
|
inlinevirtual |
|
virtual |
Return a boolean indicating whether a variable is time varying
This method returns true if the variable named by varname
is defined and it has a time axis dimension. If either of these conditions is not true the method returns false.
[in] | varname | A string specifying the name of the variable. |
bool | Returns true if variable varname exists and is time varying. |
|
pure virtual |
Open the named variable for reading
This method prepares a data or coordinate variable, indicated by a variable name and time step pair, for subsequent read operations by methods of this class. The value of the refinement levels parameter, level
, indicates the resolution of the volume in the multiresolution hierarchy as described by GetDimLensAtLevel().
The level-of-detail parameter, lod
, selects the approximation level. Valid values for lod
are integers in the range 0..n-1, where n is returned by DC::BaseVar::GetCRatios().size(), or the value -1 may be used to select the best approximation available.
An error occurs, indicated by a negative return value, if the volume identified by the {varname, timestep, level, lod} tupple is not available. Note the availability of a volume can be tested with the VariableExists() method.
[in] | ts | Time step of the variable to read. This is the integer offset into the variable's temporal dimension. If the variable does not have a temporal dimension ts is ignored. |
[in] | varname | Name of the variable to read |
[in] | level | Refinement level of the variable. Ignored if the variable is not compressed. |
[in] | lod | Approximation level of the variable. A value of -1 indicates the maximum approximation level defined for the DC. Ignored if the variable is not compressed. |
status | Returns a non-negative value on success |
Implemented in VAPoR::VDC, VAPoR::VDCNetCDF, and VAPoR::DCWRF.
|
static |
Parse a vector of DC::Dimensions into space and time dimensions
This is a convenience utility that parses an ordered vector of Dimensions into a vector of spatial lengths, and the number of time steps (if time varying). The dimension vector axis must be ordered: X, Y, Z, T
[in] | dimensions | An ordered vector of dimensions |
[out] | sdims | Ordered vector of dimension lengths extracted from dimensions |
[out] | numts | The number of time steps if dimensions contains a time dimension, otherwise numts will be one |
status | A value of true is returned if the dimensions contains a correctly sized and ordered vector of dimensions |
|
pure virtual |
Read all spatial values of the currently opened variable
This method reads, and decompresses as necessary, the contents of the currently opened variable into the array data
. The number of values read into data
is given by the product of the spatial dimensions of the open variable at the refinement level specified.
It is the caller's responsibility to ensure data
points to adequate space.
[out] | data | An array of data to be written |
status | Returns a non-negative value on success |
Implemented in VAPoR::VDC, VAPoR::VDCNetCDF, and VAPoR::DCWRF.
|
pure virtual |
Read in and return a subregion from the currently opened variable
This method reads and returns a subset of variable data. The min
and max
vectors, whose dimensions must match the spatial rank of the currently opened variable, identify the minimum and maximum extents, in grid coordinates, of the subregion of interest. The minimum and maximum valid values of an element of min or max are 0 and n-1, respectively, where n is the length of the associated dimension at the opened refinement level.
The region returned is stored in the memory region pointed to by region
. It is the caller's responsbility to ensure adequate space is available.
[in] | min | Minimum region extents in grid coordinates |
[in] | max | Maximum region extents in grid coordinates |
[out] | region | The requested volume subregion |
status | Returns a non-negative value on success |
Implemented in VAPoR::VDC, and VAPoR::DCWRF.
|
pure virtual |
Read in and return a blocked subregion from the currently opened variable.
This method is identical to ReadRegion() with the exceptions that for compressed variables:
start
and count
must be aligned with the underlying storage block of the variable. See DC::SetCompressionBlock()region
will preserve its underlying storage blocking (the data will not be contiguous) Implemented in VAPoR::VDC, VAPoR::VDCNetCDF, and VAPoR::DCWRF.
|
pure virtual |
Read a single slice of data from the currently opened variable
Decompress, as necessary, and read a single slice (2D array) of data from the variable indicated by the most recent call to OpenVariableRead(). The dimensions of a slices are NX by NY, where NX is the dimension of the array along the fastest varying spatial dimension, specified in grid points, and NY is the length of the second fastest varying dimension at the currently opened grid refinement level. See OpenVariableRead().
This method should be called exactly NZ times for each opened variable, where NZ is the dimension of third, and slowest varying dimension. In the case of a 2D variable, NZ is 1.
It is the caller's responsibility to ensure slice
points to adequate space.
[out] | slice | A 2D slice of data |
status | Returns a non-negative value on success |
Implemented in VAPoR::VDC, VAPoR::VDCNetCDF, and VAPoR::DCWRF.
|
pure virtual |
Returns true if indicated data volume is available
Returns true if the variable identified by the timestep, variable name, refinement level, and level-of-detail is present in the data set. Returns false if the variable is not available.
[in] | ts | A valid time step between 0 and GetNumTimesteps()-1 |
[in] | varname | A valid variable name |
[in] | reflevel | Refinement level requested. |
[in] | lod | Compression level of detail requested. refinement level contained in the DC. |
Implemented in VAPoR::VDC, VAPoR::VDCNetCDF, and VAPoR::DCWRF.