MOAB: Mesh Oriented datABase  (version 5.2.1)
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 MOAB_HAVE_MPI
00026 #include "moab_mpi.h"
00027 #include "moab/ParallelComm.hpp"
00028 #endif
00029 
00030 #ifdef MOAB_HAVE_PNETCDF
00031 #include "pnetcdf.h"
00032 #define NCFUNC( func ) ncmpi_##func
00033 
00034 //! Collective I/O mode get
00035 #define NCFUNCAG( func ) ncmpi_get##func##_all
00036 
00037 //! Independent I/O mode get
00038 #define NCFUNCG( func ) ncmpi_get##func
00039 
00040 //! Nonblocking get (request aggregation), used so far only for ucd mesh
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 
00057 class ReadUtilIface;
00058 class ScdInterface;
00059 class NCHelper;
00060 
00061 //! Output Exodus File for VERDE
00062 class ReadNC : public ReaderIface
00063 {
00064     friend class NCHelper;
00065     friend class ScdNCHelper;
00066     friend class UcdNCHelper;
00067     friend class NCHelperEuler;
00068     friend class NCHelperFV;
00069     friend class NCHelperDomain;
00070     friend class NCHelperHOMME;
00071     friend class NCHelperMPAS;
00072     friend class NCHelperGCRM;
00073 
00074   public:
00075     static ReaderIface* factory( Interface* );
00076 
00077     //! Load an NC file
00078     ErrorCode load_file( const char* file_name, const EntityHandle* file_set, const FileOptions& opts,
00079                          const SubsetList* subset_list = 0, const Tag* file_id_tag = 0 );
00080 
00081     //! Constructor
00082     ReadNC( Interface* impl = NULL );
00083 
00084     //! Destructor
00085     virtual ~ReadNC();
00086 
00087     virtual ErrorCode read_tag_values( const char* file_name, const char* tag_name, const FileOptions& opts,
00088                                        std::vector< int >& tag_values_out, const SubsetList* subset_list = 0 );
00089 
00090     //! ENTLOCNSEDGE for north/south edge
00091     //! ENTLOCWEEDGE for west/east edge
00092     enum EntityLocation
00093     {
00094         ENTLOCVERT = 0,
00095         ENTLOCNSEDGE,
00096         ENTLOCEWEDGE,
00097         ENTLOCFACE,
00098         ENTLOCSET,
00099         ENTLOCEDGE,
00100         ENTLOCREGION
00101     };
00102 
00103   private:
00104     class AttData
00105     {
00106       public:
00107         AttData() : attId( -1 ), attLen( 0 ), attVarId( -2 ) {}
00108         int attId;
00109         NCDF_SIZE attLen;
00110         int attVarId;
00111         nc_type attDataType;
00112         std::string attName;
00113     };
00114 
00115     class VarData
00116     {
00117       public:
00118         VarData() : varId( -1 ), numAtts( -1 ), entLoc( ENTLOCSET ), numLev( 0 ), sz( 0 ), has_tsteps( false ) {}
00119         int varId;
00120         int numAtts;
00121         nc_type varDataType;
00122         std::vector< int > varDims;  // The dimension indices making up this multi-dimensional variable
00123         std::map< std::string, AttData > varAtts;
00124         std::string varName;
00125         std::vector< Tag > varTags;  // Tags created for this variable, e.g. one tag per timestep
00126         std::vector< void* > varDatas;
00127         std::vector< NCDF_SIZE > readStarts;  // Starting index for reading data values along each dimension
00128         std::vector< NCDF_SIZE > readCounts;  // Number of data values to be read along each dimension
00129         int entLoc;
00130         int numLev;
00131         int sz;
00132         bool has_tsteps;  // Indicate whether timestep numbers are appended to tag names
00133     };
00134 
00135     ReadUtilIface* readMeshIface;
00136 
00137     //! Read the header information
00138     ErrorCode read_header();
00139 
00140     //! Get all global attributes in the file
00141     ErrorCode get_attributes( int var_id, int num_atts, std::map< std::string, AttData >& atts,
00142                               const char* prefix = "" );
00143 
00144     //! Get all dimensions in the file
00145     ErrorCode get_dimensions( int file_id, std::vector< std::string >& dim_names, std::vector< int >& dim_lens );
00146 
00147     //! Get the variable names and other info defined for this file
00148     ErrorCode get_variables();
00149 
00150     ErrorCode parse_options( const FileOptions& opts, std::vector< std::string >& var_names,
00151                              std::vector< int >& tstep_nums, std::vector< double >& tstep_vals );
00152 
00153     //------------member variables ------------//
00154 
00155     //! Interface instance
00156     Interface* mbImpl;
00157 
00158     //! File name
00159     std::string fileName;
00160 
00161     //! File numbers assigned by netcdf
00162     int fileId;
00163 
00164     //! Dimension names
00165     std::vector< std::string > dimNames;
00166 
00167     //! Dimension lengths
00168     std::vector< int > dimLens;
00169 
00170     //! Global attribs
00171     std::map< std::string, AttData > globalAtts;
00172 
00173     //! Variable info
00174     std::map< std::string, VarData > varInfo;
00175 
00176     //! Cached tags for reading. Note that all these tags are defined when the
00177     //! core is initialized.
00178     Tag mGlobalIdTag;
00179 
00180     //! This is a pointer to the file id tag that is passed from ReadParallel
00181     //! it gets deleted at the end of resolve sharing, but it will have same data
00182     //! as the global id tag
00183     //! global id tag is preserved, and is needed later on.
00184     const Tag* mpFileIdTag;
00185 
00186     //! Debug stuff
00187     DebugOutput dbgOut;
00188 
00189     //! Are we reading in parallel?
00190     bool isParallel;
00191 
00192     //! Partitioning method
00193     int partMethod;
00194 
00195     //! Scd interface
00196     ScdInterface* scdi;
00197 
00198     //! Parallel data object, to be cached with ScdBox
00199     ScdParData parData;
00200 
00201 #ifdef MOAB_HAVE_MPI
00202     ParallelComm* myPcomm;
00203 #endif
00204 
00205     //! Read options
00206     bool noMesh;
00207     bool noVars;
00208     bool spectralMesh;
00209     bool noMixedElements;
00210     bool noEdges;
00211     int gatherSetRank;
00212     int tStepBase;
00213     int trivialPartitionShift;
00214 
00215     //! Helper class instance
00216     NCHelper* myHelper;
00217 };
00218 
00219 }  // namespace moab
00220 
00221 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines