00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef NETCDF_CDMWRITER_H_
00025 #define NETCDF_CDMWRITER_H_
00026
00027 #include "fimex/CDMWriter.h"
00028 #include "fimex/CDM.h"
00029 #include <map>
00030 #include <string>
00031
00032
00033 class NcFile;
00034 class NcError;
00035 class NcDim;
00036 class NcVar;
00037
00038 namespace MetNoFimex
00039 {
00040
00041 class XMLDoc;
00042
00043 class NetCDF_CDMWriter : public CDMWriter
00044 {
00045 typedef std::map<std::string, NcDim*> NcDimMap;
00046 typedef std::map<std::string, NcVar*> NcVarMap;
00047
00048 public:
00055 NetCDF_CDMWriter(const boost::shared_ptr<CDMReader> cdmReader, const std::string& outputFile, std::string configFile = "", int version = 3);
00056 virtual ~NetCDF_CDMWriter();
00061 const std::string& getVariableName(const std::string& varName) const;
00066 const std::string& getDimensionName(const std::string& dimName) const;
00073 const CDMAttribute& getAttribute(const std::string& varName, const std::string& attName) const throw(CDMException);
00074
00075
00076
00077 private:
00078 void init() throw(CDMException);
00079 void initNcmlReader(std::auto_ptr<XMLDoc>& doc) throw(CDMException);
00080 void initFillRenameDimension(std::auto_ptr<XMLDoc>& doc) throw(CDMException);
00081 void initFillRenameVariable(std::auto_ptr<XMLDoc>& doc) throw(CDMException);
00082 void initFillRenameAttribute(std::auto_ptr<XMLDoc>& doc) throw(CDMException);
00084 void initRemove(std::auto_ptr<XMLDoc>& doc) throw(CDMException);
00086 void testVariableExists(const std::string& varName) throw(CDMException);
00087
00088 NcDimMap defineDimensions();
00089 NcVarMap defineVariables(const NcDimMap& dimMap);
00090 void writeAttributes(const NcVarMap& varMap);
00091 void writeData(const NcVarMap& varMap);
00092 double getOldAttribute(const std::string& varName, const std::string& attName, double defaultValue) const;
00093 double getNewAttribute(const std::string& varName, const std::string& attName, double defaultValue) const;
00094 CDM cdm;
00095 std::auto_ptr<NcFile> ncFile;
00096 std::auto_ptr<NcError> ncErr;
00097 std::map<std::string, std::string> variableNameChanges;
00098 std::map<std::string, CDMDataType> variableTypeChanges;
00099 std::map<std::string, unsigned int> variableCompression;
00100 std::map<std::string, std::string> dimensionNameChanges;
00101 };
00102
00103 }
00104
00105 #endif