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