moab
ReadNC.hpp
Go to the documentation of this file.
00001 //-------------------------------------------------------------------------
00002 // Filename      : ReadNC.hpp
00003 //
00004 // Purpose       : Climate NC file reader
00005 //
00006 // Creator       : Tim Tautges
00007 //-------------------------------------------------------------------------
00008 
00009 #ifndef READNC_HPP
00010 #define READNC_HPP
00011 
00012 #ifndef IS_BUILDING_MB
00013 //#error "ReadNC.hpp isn't supposed to be included into an application"
00014 #endif
00015 
00016 #include <vector>
00017 #include <map>
00018 #include <set>
00019 #include <string>
00020 
00021 #include "moab/ReaderIface.hpp"
00022 #include "moab/ScdInterface.hpp"
00023 #include "DebugOutput.hpp"
00024 
00025 #ifdef USE_MPI
00026 #include "moab_mpi.h"
00027 #include "moab/ParallelComm.hpp"
00028 #endif 
00029 
00030 #ifdef PNETCDF_FILE
00031 #include "pnetcdf.h"
00032 #define NCFUNC(func) ncmpi_ ## func
00033 
00035 #define NCFUNCAG(func) ncmpi_get ## func ## _all
00036 
00038 #define NCFUNCG(func) ncmpi_get ## func
00039 
00041 #define NCFUNCREQG(func) ncmpi_iget ## func
00042 
00043 #define NCDF_SIZE MPI_Offset
00044 #define NCDF_DIFF MPI_Offset
00045 #else
00046 #include "netcdf.h"
00047 #define NCFUNC(func) nc_ ## func
00048 #define NCFUNCAG(func) nc_get ## func
00049 #define NCFUNCG(func) nc_get ## func
00050 #define NCDF_SIZE size_t
00051 #define NCDF_DIFF ptrdiff_t
00052 #endif
00053 
00054 namespace moab {
00055 
00056 class ReadUtilIface;
00057 class ScdInterface;
00058 class NCHelper;
00059 
00061 class ReadNC : public ReaderIface
00062 {
00063   friend class NCHelper;
00064   friend class ScdNCHelper;
00065   friend class UcdNCHelper;
00066   friend class NCHelperEuler;
00067   friend class NCHelperFV;
00068   friend class NCHelperHOMME;
00069   friend class NCHelperMPAS;
00070 
00071 public:
00072 
00073   static ReaderIface* factory(Interface*);
00074 
00076   ErrorCode load_file(const char* file_name,
00077                        const EntityHandle* file_set,
00078                        const FileOptions& opts,
00079                        const SubsetList* subset_list = 0,
00080                        const Tag* file_id_tag = 0);
00081 
00083   ReadNC(Interface* impl = NULL);
00084 
00086   virtual ~ReadNC();
00087 
00088   virtual ErrorCode read_tag_values(const char* file_name,
00089                                     const char* tag_name,
00090                                     const FileOptions& opts,
00091                                     std::vector<int>& tag_values_out,
00092                                     const SubsetList* subset_list = 0);
00093 
00096   enum EntityLocation {ENTLOCVERT = 0, ENTLOCNSEDGE, ENTLOCEWEDGE, ENTLOCFACE, ENTLOCSET, ENTLOCEDGE, ENTLOCREGION};
00097 
00098 private:
00099 
00100   class AttData
00101   {
00102     public:
00103     AttData() : attId(-1), attLen(0), attVarId(-2) {}
00104     int attId;
00105     NCDF_SIZE attLen;
00106     int attVarId;
00107     nc_type attDataType;
00108     std::string attName;
00109   };
00110 
00111   class VarData
00112   {
00113     public:
00114     VarData() : varId(-1), numAtts(-1), entLoc(ENTLOCSET), numLev(1), sz(0), has_tsteps(false) {}
00115     int varId;
00116     int numAtts;
00117     nc_type varDataType;
00118     std::vector<int> varDims; // The dimension indices making up this multi-dimensional variable
00119     std::map<std::string, AttData> varAtts;
00120     std::string varName;
00121     std::vector<Tag> varTags; // Tags created for this variable, e.g. one tag per timestep
00122     std::vector<void*> varDatas;
00123     std::vector<NCDF_SIZE> readStarts; // Starting index for reading data values along each dimension
00124     std::vector<NCDF_SIZE> readCounts; // Number of data values to be read along each dimension
00125     int entLoc;
00126     int numLev;
00127     int sz;
00128     bool has_tsteps; // Indicate whether timestep numbers are appended to tag names
00129   };
00130 
00131   ReadUtilIface* readMeshIface;
00132 
00134   ErrorCode read_header();
00135 
00137   ErrorCode get_attributes(int var_id, int num_atts, std::map<std::string, AttData>& atts,
00138                            const char* prefix = "");
00139 
00141   ErrorCode get_dimensions(int file_id, std::vector<std::string>& dim_names, std::vector<int>& dim_lens);
00142 
00144   ErrorCode get_variables();
00145 
00146   ErrorCode parse_options(const FileOptions& opts,
00147                           std::vector<std::string>& var_names,
00148                           std::vector<int>& tstep_nums,
00149                           std::vector<double>& tstep_vals);
00150 
00151 //------------member variables ------------//
00152 
00154   Interface* mbImpl;
00155 
00157   std::string fileName;
00158 
00160   int fileId;
00161 
00163   std::vector<std::string> dimNames;
00164 
00166   std::vector<int> dimLens;
00167 
00169   std::map<std::string, AttData> globalAtts;
00170 
00172   std::map<std::string, VarData> varInfo;
00173 
00176   Tag mGlobalIdTag;
00177 
00182   const Tag* mpFileIdTag;
00183 
00185   DebugOutput dbgOut;
00186 
00188   bool isParallel;
00189 
00191   int partMethod;
00192 
00194   ScdInterface* scdi;
00195 
00197   ScdParData parData;
00198 
00199 #ifdef USE_MPI
00200   ParallelComm* myPcomm;
00201 #endif
00202 
00204   bool noMesh;
00205   bool noVars;
00206   bool spectralMesh;
00207   bool noMixedElements;
00208   bool noEdges;
00209   int gatherSetRank;
00210 
00212   NCHelper* myHelper;
00213 };
00214 
00215 } // namespace moab
00216 
00217 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines