MI - Fimex
Public Types | Public Member Functions | Static Public Member Functions | List of all members
MetNoFimex::CDM Class Reference

Data structure of the Common Data Model. More...

#include <fimex/CDM.h>

Public Types

typedef std::vector< CDMAttributeAttrVec
 
typedef std::map< std::string, AttrVecStrAttrVecMap
 
typedef std::vector< CDMDimensionDimVec
 
typedef std::vector< CDMVariableVarVec
 

Public Member Functions

 CDM ()
 
 CDM (const CDM &rhs)
 
virtual ~CDM ()
 
CDMoperator= (const CDM &rhs)
 
void addVariable (const CDMVariable &var) throw (CDMException)
 add variable to cdm More...
 
CDMVariablegetVariable (const std::string &varName) throw (CDMException)
 get a reference of a variable More...
 
const CDMVariablegetVariable (const std::string &varName) const throw (CDMException)
 get a reference of a variable More...
 
bool hasVariable (const std::string &varName) const
 test if variable exists More...
 
std::vector< std::stringfindVariables (const std::string &attrName, const std::string &attrValueRegExp) const
 search for variable with certain attribute-value More...
 
std::vector< std::stringfindVariables (const std::map< std::string, std::string > &findAttributes, const std::vector< std::string > &findDimensions) const
 search for variable with attribute-values and dimensions More...
 
bool renameVariable (const std::string &oldName, const std::string &newName)
 rename a variable More...
 
bool checkVariableAttribute (const std::string &varName, const std::string &attribute, const boost::regex &attrValue) const
 
void removeVariable (const std::string &variableName)
 remove a variable and corresponding attributes More...
 
void addDimension (const CDMDimension &dim) throw (CDMException)
 add a dimension to cdm More...
 
bool hasDimension (const std::string &dimName) const
 
CDMDimensiongetDimension (const std::string &dimName) throw (CDMException)
 get a reference to a dimension More...
 
const CDMDimensiongetDimension (const std::string &dimName) const throw (CDMException)
 
bool testDimensionInUse (const std::string &name) const
 test if a dimension is actively in use More...
 
bool renameDimension (const std::string &oldName, const std::string &newName) throw (CDMException)
 rename a dimension More...
 
bool removeDimension (const std::string &name) throw (CDMException)
 remove a dimension More...
 
const CDMDimensiongetUnlimitedDim () const
 retrieve the unlimited dimension More...
 
bool hasUnlimitedDim (const CDMVariable &var) const
 test if a variable contains the unlimited dim More...
 
void addAttribute (const std::string &varName, const CDMAttribute &attr) throw (CDMException)
 
void addOrReplaceAttribute (const std::string &varName, const CDMAttribute &attr) throw (CDMException)
 
void removeAttribute (const std::string &varName, const std::string &attrName)
 
void toXMLStream (std::ostream &os) const
 print a xml representation to the stream More...
 
const DimVecgetDimensions () const
 get the dimension More...
 
const VarVecgetVariables () const
 get the variables More...
 
const StrAttrVecMapgetAttributes () const
 get the attributes More...
 
std::vector< CDMAttributegetAttributes (const std::string &varName) const
 get the attributes of an variable More...
 
CDMAttributegetAttribute (const std::string &varName, const std::string &attrName) throw (CDMException)
 get an attribute More...
 
const CDMAttributegetAttribute (const std::string &varName, const std::string &attrName) const throw (CDMException)
 get a const. attribute More...
 
bool getAttribute (const std::string &varName, const std::string &attrName, CDMAttribute &retAttribute) const
 get an attribute without throwing an error More...
 
double getFillValue (const std::string &varName) const
 
double getValidMin (const std::string &varName) const
 
double getValidMax (const std::string &varName) const
 
double getAddOffset (const std::string &varName) const
 
double getScaleFactor (const std::string &varName) const
 
std::string getUnits (const std::string &varName) const
 
void generateProjectionCoordinates (boost::shared_ptr< const Projection > projection, const std::string &xDim, const std::string &yDim, const std::string &lonDim, const std::string &latDim)
 generate the projection coordinates (usually named "lat lon") More...
 
 MIFI_DEPRECATED (bool getProjectionAndAxesUnits(std::string &projectionName, std::string &xAxis, std::string &yAxis, std::string &xAxisUnits, std::string &yAxisUnits) const throw(CDMException))
 generate the projection coordinates (usually named "lat lon") More...
 
 MIFI_DEPRECATED (AttrVec getProjection(std::string varName) const)
 get the projection attributes (as of CF-1.0) of a variable More...
 
boost::shared_ptr< const ProjectiongetProjectionOf (std::string varName) const
 get the projection of a variable More...
 
std::string getHorizontalXAxis (std::string varName) const
 get the x-(lon) axis of the variable More...
 
std::string getHorizontalYAxis (std::string varName) const
 get the y-(lat) axis of the variable More...
 
bool getLatitudeLongitude (std::string varName, std::string &latitude, std::string &longitude) const
 detect the latitude and longitude coordinates of the variable More...
 
std::string getTimeAxis (std::string varName) const
 get the time axis of the variable More...
 
std::string getVerticalAxis (std::string varName) const
 get the vertical axis of the variable More...
 

Static Public Member Functions

static const std::stringglobalAttributeNS ()
 the namespace for global attributes More...
 

Detailed Description

Data structure of the Common Data Model.

This class implements the data-structure of the Common Data Model version 1 http://www.unidata.ucar.edu/software/netcdf-java/CDM.html

Examples:
coordinateSystem.cpp, and parallelRead.cpp.

Member Typedef Documentation

Constructor & Destructor Documentation

MetNoFimex::CDM::CDM ( )
MetNoFimex::CDM::CDM ( const CDM rhs)
virtual MetNoFimex::CDM::~CDM ( )
virtual

Member Function Documentation

void MetNoFimex::CDM::addAttribute ( const std::string varName,
const CDMAttribute attr 
)
throw (CDMException
)

add an attribute to cdm

Parameters
varNamename of the variablt the attribute belongs to
attrthe CDMAttribute
Exceptions
CDMExceptionif varName doesn't exist, or attr.getName() already exists
void MetNoFimex::CDM::addDimension ( const CDMDimension dim)
throw (CDMException
)

add a dimension to cdm

Parameters
dimthe dimension
Exceptions
CDMExceptionif dim-name already exists
void MetNoFimex::CDM::addOrReplaceAttribute ( const std::string varName,
const CDMAttribute attr 
)
throw (CDMException
)

add or replace an attribute of the cdm

Parameters
varNamename of variable the attribute belongs to
attrthe CDMAttribute
Exceptions
CDMExceptionif vaName doesn't exist
void MetNoFimex::CDM::addVariable ( const CDMVariable var)
throw (CDMException
)

add variable to cdm

Parameters
varthe variable to add
Exceptions
CDMExceptionif var.varName() already exists
bool MetNoFimex::CDM::checkVariableAttribute ( const std::string varName,
const std::string attribute,
const boost::regex &  attrValue 
) const

check if a variable contains a attributes with a matching string-value

Parameters
varNamevariable
attributethe attribute name
attrValuethe regexp the string-value of the attribute will match against
std::vector<std::string> MetNoFimex::CDM::findVariables ( const std::string attrName,
const std::string attrValueRegExp 
) const

search for variable with certain attribute-value

Parameters
attrNamename of the attribute
attrValueRegExpregular expression the 'string'-value needs to match
Returns
variable names of the variable with attributes matching
std::vector<std::string> MetNoFimex::CDM::findVariables ( const std::map< std::string, std::string > &  findAttributes,
const std::vector< std::string > &  findDimensions 
) const

search for variable with attribute-values and dimensions

And AND search for attributes and dimensions.

Parameters
findAttributesmap with (attribute => string-value regExp) pairs
findDimensionsvector with dimensions contained in variable
Returns
variable names of the variable with attributes matching the request and containing all dimensions
void MetNoFimex::CDM::generateProjectionCoordinates ( boost::shared_ptr< const Projection projection,
const std::string xDim,
const std::string yDim,
const std::string lonDim,
const std::string latDim 
)

generate the projection coordinates (usually named "lat lon")

Parameters
projectionthe projection information
xDimthe x dimension (the corresponding variable needs to contain data and units)
yDimthe y dimension (the corresponding variable needs to contain data and units)
lonDimname of the longitude variable
latDimname of the latitude variable
Exceptions
CDMExceptionif any information is missing

Referenced by globalAttributeNS().

double MetNoFimex::CDM::getAddOffset ( const std::string varName) const

find add_offset value for a variable

Parameters
varName
Returns
double value of "add_offset" attribute, or 0 if there is no such attribute

Referenced by globalAttributeNS().

CDMAttribute& MetNoFimex::CDM::getAttribute ( const std::string varName,
const std::string attrName 
)
throw (CDMException
)

get an attribute

Parameters
varNamename of variable
attrNamename of attribute
Exceptions
CDMExceptionif varName attrName combination doesn't exists

Referenced by globalAttributeNS().

const CDMAttribute& MetNoFimex::CDM::getAttribute ( const std::string varName,
const std::string attrName 
) const
throw (CDMException
)

get a const. attribute

Parameters
varNamename of variable
attrNamename of attribute
Exceptions
CDMExceptionif varName attrName combination doesn't exists
bool MetNoFimex::CDM::getAttribute ( const std::string varName,
const std::string attrName,
CDMAttribute retAttribute 
) const

get an attribute without throwing an error

This method will search for an attribute in the cdm. It will return true on success and return the attribute.

Parameters
varNamename of variable
attrNamename of attribute
retAttributereturns the attribute if found
Returns
true when attribute has been found and set
const StrAttrVecMap& MetNoFimex::CDM::getAttributes ( ) const

get the attributes

Returns
map of type <variableName <attributeName, attribute>>

Referenced by globalAttributeNS().

std::vector<CDMAttribute> MetNoFimex::CDM::getAttributes ( const std::string varName) const

get the attributes of an variable

Parameters
varNamename of variable
CDMDimension& MetNoFimex::CDM::getDimension ( const std::string dimName)
throw (CDMException
)

get a reference to a dimension

Parameters
dimNamename of the dimension
Exceptions
CDMExceptionif dimension doesn't exist
const CDMDimension& MetNoFimex::CDM::getDimension ( const std::string dimName) const
throw (CDMException
)
const DimVec& MetNoFimex::CDM::getDimensions ( ) const

get the dimension

Referenced by globalAttributeNS().

double MetNoFimex::CDM::getFillValue ( const std::string varName) const

get the fill value of an variable (_FillValue attribute)

Returns
value of _FillValue attribute, or the default fill value of variables datatype (MIFI_FILL_XXXX)

Referenced by globalAttributeNS().

std::string MetNoFimex::CDM::getHorizontalXAxis ( std::string  varName) const

get the x-(lon) axis of the variable

This is the same as using the CoordinateSystem::getGeoXAxis().

Parameters
varNamename of variable
Returns
name of x-axis dimension (or "" if not defined)
Warning
not thread-safe, though read-only, it might change the internal state of the CDM due to caching

Referenced by globalAttributeNS().

std::string MetNoFimex::CDM::getHorizontalYAxis ( std::string  varName) const

get the y-(lat) axis of the variable

This is the same as using the CoordinateSystem::getGeoYAxis().

Parameters
varNamename of variable
Returns
name of y-axis dimension (or "" if not defined)
Warning
not thread-safe, though read-only, it might change the internal state of the CDM due to caching

Referenced by globalAttributeNS().

bool MetNoFimex::CDM::getLatitudeLongitude ( std::string  varName,
std::string latitude,
std::string longitude 
) const

detect the latitude and longitude coordinates of the variable

This is the same as using the CoordinateSystem::findAxisOfType() with CoordinateAxis::Lon and CoordinateAxis::Lat.

Parameters
varNamename of variable
latitudereturn value of the latitude
longitudereturn value of the longitude
Returns
true if latitude and longitude have been found
Warning
not thread-safe, though read-only, it might change the internal state of the CDM due to caching

Referenced by globalAttributeNS().

boost::shared_ptr<const Projection> MetNoFimex::CDM::getProjectionOf ( std::string  varName) const

get the projection of a variable

This is the same as using the CoordinateSystem::getProjection().

Parameters
varNamename of variable
Returns
projection
Warning
not thread-safe, though read-only, it might change the internal state of the CDM due to caching

Referenced by globalAttributeNS().

double MetNoFimex::CDM::getScaleFactor ( const std::string varName) const

find scale_factor value for a variable

Parameters
varName
Returns
double value of "scale_factor" attribute, or 1 if there is no such attribute

Referenced by globalAttributeNS().

std::string MetNoFimex::CDM::getTimeAxis ( std::string  varName) const

get the time axis of the variable

This is the same as using the CoordinateSystem::getTimeAxis().

Parameters
varNamename of variable
Returns
name of time dimension (or "" if not defined)
Warning
not thread-safe, though read-only, it might change the internal state of the CDM due to caching

Referenced by globalAttributeNS().

std::string MetNoFimex::CDM::getUnits ( const std::string varName) const

get the value of the "units" attribute

Returns
unitsString or ""

Referenced by globalAttributeNS().

const CDMDimension* MetNoFimex::CDM::getUnlimitedDim ( ) const

retrieve the unlimited dimension

Returns
unLimDim pointer with the unlimited dimension, the pointer will be deleted with the CDM
Examples:
parallelRead.cpp.
double MetNoFimex::CDM::getValidMax ( const std::string varName) const

get the valid maximum value of an variable

Returns
value of valid_max or valid_range attribute, or MIFI_UNDEFINED_D

Referenced by globalAttributeNS().

double MetNoFimex::CDM::getValidMin ( const std::string varName) const

get the valid minimum value of an variable

Returns
value of valid_min or valid_range attribute, or MIFI_UNDEFINED_D

Referenced by globalAttributeNS().

CDMVariable& MetNoFimex::CDM::getVariable ( const std::string varName)
throw (CDMException
)

get a reference of a variable

Parameters
varNamename of the variable
Exceptions
CDMExceptionif varName doesn't exist
const CDMVariable& MetNoFimex::CDM::getVariable ( const std::string varName) const
throw (CDMException
)

get a reference of a variable

this is a constant version of getVariable(const std::string&)

Parameters
varNamename of the variable
Exceptions
CDMExceptionif varName doesn't exist
const VarVec& MetNoFimex::CDM::getVariables ( ) const

get the variables

Referenced by globalAttributeNS().

std::string MetNoFimex::CDM::getVerticalAxis ( std::string  varName) const

get the vertical axis of the variable

This is the same as using the CoordinateSystem::getGeoZAxis().

Parameters
varNamename of variable
Returns
name of vertical dimension (or "" if not defined)
Warning
not thread-safe, though read-only, it might change the internal state of the CDM due to caching

Referenced by globalAttributeNS().

static const std::string& MetNoFimex::CDM::globalAttributeNS ( )
inlinestatic
bool MetNoFimex::CDM::hasDimension ( const std::string dimName) const

check if the dimension exists

Parameters
dimNamename of the dimension
bool MetNoFimex::CDM::hasUnlimitedDim ( const CDMVariable var) const

test if a variable contains the unlimited dim

Returns
true/false
bool MetNoFimex::CDM::hasVariable ( const std::string varName) const

test if variable exists

Parameters
varNamename of variable
MetNoFimex::CDM::MIFI_DEPRECATED ( bool   getProjectionAndAxesUnitsstd::string &projectionName, std::string &xAxis, std::string &yAxis, std::string &xAxisUnits, std::string &yAxisUnits) const throw(CDMException)

generate the projection coordinates (usually named "lat lon")

Parameters
projectionVariablethe variable containing the projection information
xDimthe x dimension (the corresponding variable needs to contain data and units in this CDM (not the data-reader))
yDimthe y dimension (the corresponding variable needs to contain data and units in this CDM (not the data-reader))
lonDimname of the longitude variable
latDimname of the latitude variable
Exceptions
CDMExceptionif any information is missing
Deprecated:
use generateProjectionCoordinate with projection and get the projection by Projection::create(getAttributes(projectionVariable));

extract the names of the projection-variable and the corresponding projection-axes

Parameters
projectionNameoutput of the projection variables name
xAxisoutput of the spatial x axis
yAxisoutput of the spation y axis
xAxisUnitsoutput of unit for x axis
yAxisUnitsoutput of unit for y axis
Returns
true if unique result, false (and print warning) if results are not unique
Exceptions
CDMExceptionif no projection with corresponding axes can be found

Referenced by globalAttributeNS().

MetNoFimex::CDM::MIFI_DEPRECATED ( AttrVec getProjection(std::string varName)  const)

get the projection attributes (as of CF-1.0) of a variable

Parameters
varNamename of variable
Returns
vector of attributes of the projection, an empty vector if no projection found
Deprecated:
use the getProjectionOf() method
CDM& MetNoFimex::CDM::operator= ( const CDM rhs)
void MetNoFimex::CDM::removeAttribute ( const std::string varName,
const std::string attrName 
)

remove an attribute from the cdm

Parameters
varNamename of variable the attribute belongs to
attrNamethe CDMAttribute
bool MetNoFimex::CDM::removeDimension ( const std::string name)
throw (CDMException
)

remove a dimension

Remove a dimension, if it is not in use by a variable.

Returns
true if dimension existed, false otherwise
Exceptions
CDMExceptionif dimension in us in a variable
void MetNoFimex::CDM::removeVariable ( const std::string variableName)

remove a variable and corresponding attributes

Parameters
variableNamethe variable to remove
bool MetNoFimex::CDM::renameDimension ( const std::string oldName,
const std::string newName 
)
throw (CDMException
)

rename a dimension

Rename a dimension.

Returns
false if the original name does not exist.
Exceptions
CDMExceptionif newName already in use in a variable but for a different dimension
bool MetNoFimex::CDM::renameVariable ( const std::string oldName,
const std::string newName 
)

rename a variable

Parameters
oldNamethe old name of the variable
newNamethe new name of the variable
Returns
1 on success (oldName exists), 0 on failure
Warning
this will not change the spatialVectorCounterPart of all other variables
bool MetNoFimex::CDM::testDimensionInUse ( const std::string name) const

test if a dimension is actively in use

Parameters
namedimensionName
void MetNoFimex::CDM::toXMLStream ( std::ostream os) const

print a xml representation to the stream


The documentation for this class was generated from the following file: