# MI - Fimex: include/fimex/NetCDF_CDMWriter.h Source File

- Main Page
- Related Pages
- Namespaces
- Classes
- Files
- Examples

# include/fimex/NetCDF_CDMWriter.h

Go to the documentation of this file.

    00001 /*
    00002  * Fimex
    00003  *
    00004  * (C) Copyright 2008, met.no
    00005  *
    00006  * Project Info:  https://wiki.met.no/fimex/start
    00007  *
    00008  * This library is free software; you can redistribute it and/or modify it
    00009  * under the terms of the GNU Lesser General Public License as published by
    00010  * the Free Software Foundation; either version 2.1 of the License, or
    00011  * (at your option) any later version.
    00012  *
    00013  * This library is distributed in the hope that it will be useful, but
    00014  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
    00015  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
    00016  * License for more details.
    00017  *
    00018  * You should have received a copy of the GNU Lesser General Public
    00019  * License along with this library; if not, write to the Free Software
    00020  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
    00021  * USA.
    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 /* forward declarations */
    00033 class NcFile;
    00034 class NcError;
    00035 class NcDim;
    00036 class NcVar;
    00037
    00038 namespace MetNoFimex
    00039 {
    00040 /* forward declarations */
    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; /* local storage of the changed cdm-outline, except variable name changes */
    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 /*NETCDF_CDMWRITER_H_*/