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 "fimex/config.h"
00030 #include <map>
00031 #include <string>
00032
00033
00034 class NcFile;
00035 class NcError;
00036 class NcDim;
00037 class NcVar;
00038
00039 namespace MetNoFimex
00040 {
00041
00042 class XMLDoc;
00043
00044 class NetCDF_CDMWriter : public CDMWriter
00045 {
00046 typedef std::map<std::string, NcDim*> NcDimMap;
00047 typedef std::map<std::string, NcVar*> NcVarMap;
00048
00049 public:
00056 NetCDF_CDMWriter(const boost::shared_ptr<CDMReader> cdmReader, const std::string& outputFile, std::string configFile = "", int version = 3);
00057 virtual ~NetCDF_CDMWriter();
00059 const std::string& getVariableName(const std::string& varName) const;
00061 const std::string& getDimensionName(const std::string& dimName) const;
00067 const CDMAttribute& getAttribute(const std::string& varName, const std::string& attName) const throw(CDMException);
00068
00069
00070
00071 private:
00072 void init() throw(CDMException);
00073 void initNcmlReader(std::auto_ptr<XMLDoc>& doc) throw(CDMException);
00074 void initFillRenameDimension(std::auto_ptr<XMLDoc>& doc) throw(CDMException);
00075 void initFillRenameVariable(std::auto_ptr<XMLDoc>& doc) throw(CDMException);
00076 void initFillRenameAttribute(std::auto_ptr<XMLDoc>& doc) throw(CDMException);
00078 void initRemove(std::auto_ptr<XMLDoc>& doc) throw(CDMException);
00080 void testVariableExists(const std::string& varName) throw(CDMException);
00081
00082 NcDimMap defineDimensions();
00083 NcVarMap defineVariables(const NcDimMap& dimMap);
00084 void writeAttributes(const NcVarMap& varMap);
00085 void writeData(const NcVarMap& varMap);
00086 double getOldAttribute(const std::string& varName, const std::string& attName, double defaultValue) const;
00087 double getNewAttribute(const std::string& varName, const std::string& attName, double defaultValue) const;
00088 CDM cdm;
00089 std::auto_ptr<NcFile> ncFile;
00090 std::auto_ptr<NcError> ncErr;
00091 std::map<std::string, std::string> variableNameChanges;
00092 std::map<std::string, CDMDataType> variableTypeChanges;
00093 std::map<std::string, unsigned int> variableCompression;
00094 std::map<std::string, std::string> dimensionNameChanges;
00095 };
00096
00097 }
00098
00099 #endif