Loading [MathJax]/extensions/tex2jax.js
Mesh Oriented datABase  (version 5.5.1)
An array-based unstructured mesh library
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ReadNC.hpp
Go to the documentation of this file.
1 //------------------------------------------------------------------------- 2 // Filename : ReadNC.hpp 3 // 4 // Purpose : Climate NC file reader 5 // 6 // Creator : Tim Tautges 7 //------------------------------------------------------------------------- 8  9 #ifndef READNC_HPP 10 #define READNC_HPP 11  12 #ifndef IS_BUILDING_MB 13 #error "ReadNC.hpp isn't supposed to be included into an application" 14 #endif 15  16 #include <vector> 17 #include <map> 18 #include <set> 19 #include <string> 20  21 #include "moab/ReaderIface.hpp" 22 #include "moab/ScdInterface.hpp" 23 #include "DebugOutput.hpp" 24  25 #ifdef MOAB_HAVE_MPI 26 #include "moab_mpi.h" 27 #include "moab/ParallelComm.hpp" 28 #endif 29  30 #ifdef MOAB_HAVE_PNETCDF 31 #include "pnetcdf.h" 32 #define NCFUNC( func ) ncmpi_##func 33  34 //! Collective I/O mode get 35 #define NCFUNCAG( func ) ncmpi_get##func##_all 36  37 //! Independent I/O mode get 38 #define NCFUNCG( func ) ncmpi_get##func 39  40 //! Nonblocking get (request aggregation), used so far only for ucd mesh 41 #define NCFUNCREQG( func ) ncmpi_iget##func 42  43 #define NCDF_SIZE MPI_Offset 44 #define NCDF_DIFF MPI_Offset 45 #else 46 #include "netcdf.h" 47 #define NCFUNC( func ) nc_##func 48 #define NCFUNCAG( func ) nc_get##func 49 #define NCFUNCG( func ) nc_get##func 50 #define NCDF_SIZE size_t 51 #define NCDF_DIFF ptrdiff_t 52 #endif 53  54 namespace moab 55 { 56  57 class ReadUtilIface; 58 class ScdInterface; 59 class NCHelper; 60  61 //! Output Exodus File for VERDE 62 class ReadNC : public ReaderIface 63 { 64  friend class NCHelper; 65  friend class ScdNCHelper; 66  friend class UcdNCHelper; 67  friend class NCHelperEuler; 68  friend class NCHelperFV; 69  friend class NCHelperDomain; 70  friend class NCHelperScrip; 71  friend class NCHelperHOMME; 72  friend class NCHelperMPAS; 73  friend class NCHelperESMF; 74  friend class NCHelperGCRM; 75  76  public: 77  static ReaderIface* factory( Interface* ); 78  79  enum NCFormatType 80  { 81  NC_FORMAT_UNKNOWN_TYPE = 0, 82  NC_FORMAT_MPAS = 1, 83  NC_FORMAT_SCRIP = 2, 84  NC_FORMAT_ESMF = 3, 85  NC_FORMAT_DOMAIN = 4, 86  NC_FORMAT_HOMME = 5, 87  NC_FORMAT_GCRM = 6, 88  NC_FORMAT_EULER = 7, 89  NC_FORMAT_FV = 8 90  }; 91  92  //! Load an NC file 93  ErrorCode load_file( const char* file_name, 94  const EntityHandle* file_set, 95  const FileOptions& opts, 96  const SubsetList* subset_list = nullptr, 97  const Tag* file_id_tag = nullptr ); 98  99  //! Constructor 100  explicit ReadNC( Interface* impl = nullptr ); 101  102  //! Destructor 103  virtual ~ReadNC(); 104  105  virtual ErrorCode read_tag_values( const char* file_name, 106  const char* tag_name, 107  const FileOptions& opts, 108  std::vector< int >& tag_values_out, 109  const SubsetList* subset_list = nullptr ); 110  111  //! ENTLOCNSEDGE for north/south edge 112  //! ENTLOCWEEDGE for west/east edge 113  enum EntityLocation 114  { 115  ENTLOCVERT = 0, 116  ENTLOCNSEDGE, 117  ENTLOCEWEDGE, 118  ENTLOCFACE, 119  ENTLOCSET, 120  ENTLOCEDGE, 121  ENTLOCREGION 122  }; 123  124  private: 125  class AttData 126  { 127  public: 128  AttData() : attId( -1 ), attLen( 0 ), attVarId( -2 ) {} 129  int attId; 130  NCDF_SIZE attLen; 131  int attVarId; 132  nc_type attDataType; 133  std::string attName; 134  }; 135  136  class VarData 137  { 138  public: 139  VarData() : varId( -1 ), numAtts( -1 ), entLoc( ENTLOCSET ), numLev( 0 ), sz( 0 ), has_tsteps( false ) {} 140  int varId; 141  int numAtts; 142  nc_type varDataType; 143  std::vector< int > varDims; // The dimension indices making up this multi-dimensional variable 144  std::map< std::string, AttData > varAtts; 145  std::string varName; 146  std::vector< Tag > varTags; // Tags created for this variable, e.g. one tag per timestep 147  std::vector< void* > varDatas; 148  std::vector< NCDF_SIZE > readStarts; // Starting index for reading data values along each dimension 149  std::vector< NCDF_SIZE > readCounts; // Number of data values to be read along each dimension 150  int entLoc; 151  int numLev; 152  int sz; 153  bool has_tsteps; // Indicate whether timestep numbers are appended to tag names 154  }; 155  156  ReadUtilIface* readMeshIface; 157  158  //! Read the header information 159  ErrorCode read_header(); 160  161  //! Get all global attributes in the file 162  ErrorCode get_attributes( int var_id, 163  int num_atts, 164  std::map< std::string, AttData >& atts, 165  const char* prefix = "" ); 166  167  //! Get all dimensions in the file 168  ErrorCode get_dimensions( int file_id, std::vector< std::string >& dim_names, std::vector< int >& dim_lens ); 169  170  //! Get the variable names and other info defined for this file 171  ErrorCode get_variables(); 172  173  ErrorCode parse_options( const FileOptions& opts, 174  std::vector< std::string >& var_names, 175  std::vector< int >& tstep_nums, 176  std::vector< double >& tstep_vals ); 177  178  //------------member variables ------------// 179  180  //! Interface instance 181  Interface* mbImpl; 182  183  //! File name 184  std::string fileName; 185  186  //! File numbers assigned by netcdf 187  int fileId; 188  189  //! Dimension names 190  std::vector< std::string > dimNames; 191  192  //! Dimension lengths 193  std::vector< int > dimLens; 194  195  //! Global attribs 196  std::map< std::string, AttData > globalAtts; 197  198  //! Variable info 199  std::map< std::string, VarData > varInfo; 200  201  //! Cached tags for reading. Note that all these tags are defined when the 202  //! core is initialized. 203  Tag mGlobalIdTag; 204  205  //! This is a pointer to the file id tag that is passed from ReadParallel 206  //! it gets deleted at the end of resolve sharing, but it will have same data 207  //! as the global id tag 208  //! global id tag is preserved, and is needed later on. 209  const Tag* mpFileIdTag; 210  211  //! Debug stuff 212  DebugOutput dbgOut; 213  214  //! Are we reading in parallel? 215  bool isParallel; 216  217  //! Partitioning method 218  int partMethod; 219  220  //! Scd interface 221  ScdInterface* scdi; 222  223  //! Parallel data object, to be cached with ScdBox 224  ScdParData parData; 225  226 #ifdef MOAB_HAVE_MPI 227  ParallelComm* myPcomm; 228 #endif 229  230  //! Read options 231  bool noMesh; 232  bool noVars; 233  bool spectralMesh; 234  bool noMixedElements; 235  bool noEdges; 236  bool culling; 237  bool repartition; // with zoltan rcb 238  int gatherSetRank; 239  int tStepBase; 240  int trivialPartitionShift; 241  242  //! Helper class instance 243  NCHelper* myHelper; 244 }; 245  246 } // namespace moab 247  248 #endif