MI - Fimex
CDM.h
Go to the documentation of this file.
1 /*
2  * Fimex
3  *
4  * (C) Copyright 2008, met.no
5  *
6  * Project Info: https://wiki.met.no/fimex/start
7  *
8  * This library is free software; you can redistribute it and/or modify it
9  * under the terms of the GNU Lesser General Public License as published by
10  * the Free Software Foundation; either version 2.1 of the License, or
11  * (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful, but
14  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
16  * License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
21  * USA.
22  */
23 
24 #ifndef CDM_H_
25 #define CDM_H_
26 
27 #include <map>
28 #include <vector>
29 #include <string>
30 #include <ostream>
31 #include <boost/regex_fwd.hpp>
32 #include "fimex/CDMAttribute.h"
33 #include "fimex/CDMVariable.h"
34 #include "fimex/CDMDimension.h"
35 #include "fimex/CDMException.h"
36 #include "fimex/CDMconstants.h"
38 
39 namespace MetNoFimex
40 {
41 //forward declaration
42 struct CDMImpl;
43 
54 class CDM
55 {
56 public:
61  CDM();
62  CDM(const CDM& rhs);
63  virtual ~CDM();
64  CDM& operator=(const CDM& rhs);
71  void addVariable(const CDMVariable& var) throw(CDMException);
78  CDMVariable& getVariable(const std::string& varName) throw(CDMException);
87  const CDMVariable& getVariable(const std::string& varName) const throw(CDMException);
93  bool hasVariable(const std::string& varName) const;
101  std::vector<std::string> findVariables(const std::string& attrName, const std::string& attrValueRegExp) const;
121  bool renameVariable(const std::string& oldName, const std::string& newName);
129  bool checkVariableAttribute(const std::string& varName, const std::string& attribute, const boost::regex& attrValue) const;
135  void removeVariable(const std::string& variableName);
136 
143  void addDimension(const CDMDimension& dim) throw(CDMException);
148  bool hasDimension(const std::string& dimName) const;
149 
156  CDMDimension& getDimension(const std::string& dimName) throw(CDMException);
157  const CDMDimension& getDimension(const std::string& dimName) const throw(CDMException);
158 
164  bool testDimensionInUse(const std::string& name) const;
165 
174  bool renameDimension(const std::string& oldName, const std::string& newName) throw(CDMException);
175 
184  bool removeDimension(const std::string& name) throw(CDMException);
185 
190  const CDMDimension* getUnlimitedDim() const;
195  bool hasUnlimitedDim(const CDMVariable& var) const;
196 
204  void addAttribute(const std::string& varName, const CDMAttribute& attr) throw(CDMException);
212  void addOrReplaceAttribute(const std::string& varName, const CDMAttribute& attr) throw(CDMException);
219  void removeAttribute(const std::string& varName, const std::string& attrName);
220 
221 
223  void toXMLStream(std::ostream& os) const;
225  const static std::string& globalAttributeNS() {const static std::string global("_GLOBAL"); return global;}
226 
228  const DimVec& getDimensions() const;
230  const VarVec& getVariables() const;
235  const StrAttrVecMap& getAttributes() const;
241 
242 
250  CDMAttribute& getAttribute(const std::string& varName, const std::string& attrName) throw(CDMException);
257  const CDMAttribute& getAttribute(const std::string& varName, const std::string& attrName) const throw(CDMException);
269  bool getAttribute(const std::string& varName, const std::string& attrName, CDMAttribute& retAttribute) const;
276  double getFillValue(const std::string& varName) const;
282  double getValidMin(const std::string& varName) const;
288  double getValidMax(const std::string& varName) const;
289 
295  double getAddOffset(const std::string& varName) const;
296 
302  double getScaleFactor(const std::string& varName) const;
303 
308  std::string getUnits(const std::string& varName) const;
319  void generateProjectionCoordinates(boost::shared_ptr<const Projection> projection, const std::string& xDim, const std::string& yDim, const std::string& lonDim, const std::string& latDim);
332  MIFI_DEPRECATED(void generateProjectionCoordinates(const std::string& projectionVariable, const std::string& xDim, const std::string& yDim, const std::string& lonDim, const std::string& latDim);)
344  MIFI_DEPRECATED(bool getProjectionAndAxesUnits(std::string& projectionName, std::string& xAxis, std::string& yAxis, std::string& xAxisUnits, std::string& yAxisUnits) const throw(CDMException));
345 
346 
354  MIFI_DEPRECATED(AttrVec getProjection(std::string varName) const);
364  boost::shared_ptr<const Projection> getProjectionOf(std::string varName) const;
365 
397  bool getLatitudeLongitude(std::string varName, std::string& latitude, std::string& longitude) const;
407  std::string getTimeAxis(std::string varName) const;
417  std::string getVerticalAxis(std::string varName) const;
418 
419 private:
420  CDMImpl* pimpl_;
421 };
422 
423 }
424 
425 #endif /*CDM_H_*/
const CDMDimension * getUnlimitedDim() const
retrieve the unlimited dimension
void removeAttribute(const std::string &varName, const std::string &attrName)
std::string getHorizontalYAxis(std::string varName) const
get the y-(lat) axis of the variable
basic_string< char > string
const VarVec & getVariables() const
get the variables
void addOrReplaceAttribute(const std::string &varName, const CDMAttribute &attr)
const StrAttrVecMap & getAttributes() const
get the attributes
void addVariable(const CDMVariable &var)
add variable to cdm
std::string getUnits(const std::string &varName) const
double getFillValue(const std::string &varName) const
STL class.
std::string getVerticalAxis(std::string varName) const
get the vertical axis of the variable
double getAddOffset(const std::string &varName) const
std::vector< CDMVariable > VarVec
Definition: CDM.h:60
basic_ostream< char > ostream
bool renameDimension(const std::string &oldName, const std::string &newName)
rename a dimension
bool hasDimension(const std::string &dimName) const
Definition: CDMException.h:36
STL class.
Data structure of the Common Data Model.
Definition: CDM.h:54
CDM & operator=(const CDM &rhs)
CDMAttribute & getAttribute(const std::string &varName, const std::string &attrName)
get an attribute
bool testDimensionInUse(const std::string &name) const
test if a dimension is actively in use
CDMDimension & getDimension(const std::string &dimName)
get a reference to a dimension
Definition: C_CDMReader.h:35
std::string getHorizontalXAxis(std::string varName) const
get the x-(lon) axis of the variable
Definition: CDMAttribute.h:43
CDMVariable & getVariable(const std::string &varName)
get a reference of a variable
std::vector< std::string > findVariables(const std::string &attrName, const std::string &attrValueRegExp) const
search for variable with certain attribute-value
std::map< std::string, AttrVec > StrAttrVecMap
Definition: CDM.h:58
void addAttribute(const std::string &varName, const CDMAttribute &attr)
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")
bool getLatitudeLongitude(std::string varName, std::string &latitude, std::string &longitude) const
detect the latitude and longitude coordinates of the variable
std::vector< CDMDimension > DimVec
Definition: CDM.h:59
Definition: CDMDimension.h:37
bool hasVariable(const std::string &varName) const
test if variable exists
boost::shared_ptr< const Projection > getProjectionOf(std::string varName) const
get the projection of a variable
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")
void removeVariable(const std::string &variableName)
remove a variable and corresponding attributes
bool renameVariable(const std::string &oldName, const std::string &newName)
rename a variable
virtual ~CDM()
void toXMLStream(std::ostream &os) const
print a xml representation to the stream
bool checkVariableAttribute(const std::string &varName, const std::string &attribute, const boost::regex &attrValue) const
static const std::string & globalAttributeNS()
the namespace for global attributes
Definition: CDM.h:225
bool removeDimension(const std::string &name)
remove a dimension
const DimVec & getDimensions() const
get the dimension
double getValidMin(const std::string &varName) const
std::vector< CDMAttribute > AttrVec
Definition: CDM.h:57
void addDimension(const CDMDimension &dim)
add a dimension to cdm
Definition: CDMVariable.h:41
bool hasUnlimitedDim(const CDMVariable &var) const
test if a variable contains the unlimited dim
std::string getTimeAxis(std::string varName) const
get the time axis of the variable
double getValidMax(const std::string &varName) const
double getScaleFactor(const std::string &varName) const