MI - Fimex
NetCDF_CDMWriter.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 NETCDF_CDMWRITER_H_
25 #define NETCDF_CDMWRITER_H_
26 
27 #include "fimex/CDMWriter.h"
28 #include "fimex/CDM.h"
29 #include <map>
30 #include <string>
31 
32 namespace MetNoFimex
33 {
34 /* forward declarations */
35 class XMLDoc;
36 class Nc;
37 
39 {
42 
43 public:
50  NetCDF_CDMWriter(const boost::shared_ptr<CDMReader> cdmReader, const std::string& outputFile, std::string configFile = "", int version = 3);
51  virtual ~NetCDF_CDMWriter();
56  const std::string& getVariableName(const std::string& varName) const;
61  const std::string& getDimensionName(const std::string& dimName) const;
68  const CDMAttribute& getAttribute(const std::string& varName, const std::string& attName) const;
69 
70 
71 
72 private:
73  void init();
74  void initNcmlReader(std::auto_ptr<XMLDoc>& doc);
75  void initFillRenameDimension(std::auto_ptr<XMLDoc>& doc);
76  void initFillRenameVariable(std::auto_ptr<XMLDoc>& doc);
77  void initFillRenameAttribute(std::auto_ptr<XMLDoc>& doc);
79  void initRemove(std::auto_ptr<XMLDoc>& doc);
81  void testVariableExists(const std::string& varName);
82 
83  NcDimIdMap defineDimensions();
84  NcVarIdMap defineVariables(const NcDimIdMap& dimMap);
85  void writeAttributes(const NcVarIdMap& varMap);
86  void writeData(const NcVarIdMap& varMap);
87  double getOldAttribute(const std::string& varName, const std::string& attName, double defaultValue) const;
88  double getNewAttribute(const std::string& varName, const std::string& attName, double defaultValue) const;
89  CDM cdm; /* local storage of the changed cdm-outline, except variable name changes */
90  std::auto_ptr<Nc> ncFile;
91  std::map<std::string, std::string> variableNameChanges;
92  std::map<std::string, CDMDataType> variableTypeChanges;
93  std::map<std::string, unsigned int> variableCompression;
94  std::map<std::string, unsigned int> dimensionChunkSize;
95  std::map<std::string, std::string> dimensionNameChanges;
96 };
97 
98 }
99 
100 #endif /*NETCDF_CDMWRITER_H_*/
Definition: CDMWriter.h:37
basic_string< char > string
STL class.
boost::shared_ptr< CDMReader > cdmReader
Definition: CDMWriter.h:45
Definition: NetCDF_CDMWriter.h:38
Data structure of the Common Data Model.
Definition: CDM.h:54
const std::string & getVariableName(const std::string &varName) const
const std::string & getDimensionName(const std::string &dimName) const
Definition: C_CDMReader.h:35
Definition: CDMAttribute.h:43
const CDMAttribute & getAttribute(const std::string &varName, const std::string &attName) const
const std::string outputFile
Definition: CDMWriter.h:46
STL class.
NetCDF_CDMWriter(const boost::shared_ptr< CDMReader > cdmReader, const std::string &outputFile, std::string configFile="", int version=3)