Mesh Oriented datABase  (version 5.6.0)
An array-based unstructured mesh library
moab::ReadNC Class Reference

Output Exodus File for VERDE. More...

#include <ReadNC.hpp>

+ Inheritance diagram for moab::ReadNC:
+ Collaboration diagram for moab::ReadNC:

Classes

class  AttData
 
class  VarData
 

Public Types

enum  NCFormatType {
  NC_FORMAT_UNKNOWN_TYPE = 0 , NC_FORMAT_MPAS = 1 , NC_FORMAT_SCRIP = 2 , NC_FORMAT_ESMF = 3 ,
  NC_FORMAT_DOMAIN = 4 , NC_FORMAT_HOMME = 5 , NC_FORMAT_GCRM = 6 , NC_FORMAT_EULER = 7 ,
  NC_FORMAT_FV = 8
}
 
enum  EntityLocation {
  ENTLOCVERT = 0 , ENTLOCNSEDGE , ENTLOCEWEDGE , ENTLOCFACE ,
  ENTLOCSET , ENTLOCEDGE , ENTLOCREGION
}
 ENTLOCNSEDGE for north/south edge ENTLOCWEEDGE for west/east edge. More...
 

Public Member Functions

ErrorCode load_file (const char *file_name, const EntityHandle *file_set, const FileOptions &opts, const SubsetList *subset_list=nullptr, const Tag *file_id_tag=nullptr)
 Load an NC file. More...
 
 ReadNC (Interface *impl=nullptr)
 Constructor. More...
 
virtual ~ReadNC ()
 Destructor. More...
 
virtual ErrorCode read_tag_values (const char *file_name, const char *tag_name, const FileOptions &opts, std::vector< int > &tag_values_out, const SubsetList *subset_list=nullptr)
 Read tag values from a file. More...
 
- Public Member Functions inherited from moab::ReaderIface
virtual ~ReaderIface ()
 

Static Public Member Functions

static ReaderIfacefactory (Interface *)
 

Private Member Functions

ErrorCode read_header ()
 Read the header information. More...
 
ErrorCode get_attributes (int var_id, int num_atts, std::map< std::string, AttData > &atts, const char *prefix="")
 Get all global attributes in the file. More...
 
ErrorCode get_dimensions (int file_id, std::vector< std::string > &dim_names, std::vector< int > &dim_lens)
 Get all dimensions in the file. More...
 
ErrorCode get_variables ()
 Get the variable names and other info defined for this file. More...
 
ErrorCode parse_options (const FileOptions &opts, std::vector< std::string > &var_names, std::vector< int > &tstep_nums, std::vector< double > &tstep_vals)
 

Private Attributes

ReadUtilIfacereadMeshIface
 
InterfacembImpl
 Interface instance. More...
 
std::string fileName
 File name. More...
 
int fileId
 File numbers assigned by netcdf. More...
 
std::vector< std::string > dimNames
 Dimension names. More...
 
std::vector< int > dimLens
 Dimension lengths. More...
 
std::map< std::string, AttDataglobalAtts
 Global attribs. More...
 
std::map< std::string, VarDatavarInfo
 Variable info. More...
 
Tag mGlobalIdTag
 Cached tags for reading. Note that all these tags are defined when the core is initialized. More...
 
const TagmpFileIdTag
 This is a pointer to the file id tag that is passed from ReadParallel it gets deleted at the end of resolve sharing, but it will have same data as the global id tag global id tag is preserved, and is needed later on. More...
 
DebugOutput dbgOut
 Debug stuff. More...
 
bool isParallel
 Are we reading in parallel? More...
 
int partMethod
 Partitioning method. More...
 
ScdInterfacescdi
 Scd interface. More...
 
ScdParData parData
 Parallel data object, to be cached with ScdBox. More...
 
bool noMesh
 Read options. More...
 
bool noVars
 
bool spectralMesh
 
bool noMixedElements
 
bool noEdges
 
bool culling
 
bool repartition
 
int gatherSetRank
 
int tStepBase
 
int trivialPartitionShift
 
NCHelpermyHelper
 Helper class instance. More...
 

Friends

class NCHelper
 
class ScdNCHelper
 
class UcdNCHelper
 
class NCHelperEuler
 
class NCHelperFV
 
class NCHelperDomain
 
class NCHelperScrip
 
class NCHelperHOMME
 
class NCHelperMPAS
 
class NCHelperESMF
 
class NCHelperGCRM
 

Detailed Description

Output Exodus File for VERDE.

Definition at line 75 of file ReadNC.hpp.

Member Enumeration Documentation

◆ EntityLocation

ENTLOCNSEDGE for north/south edge ENTLOCWEEDGE for west/east edge.

Enumerator
ENTLOCVERT 
ENTLOCNSEDGE 
ENTLOCEWEDGE 
ENTLOCFACE 
ENTLOCSET 
ENTLOCEDGE 
ENTLOCREGION 

Definition at line 126 of file ReadNC.hpp.

127  {
128  ENTLOCVERT = 0,
129  ENTLOCNSEDGE,
130  ENTLOCEWEDGE,
131  ENTLOCFACE,
132  ENTLOCSET,
133  ENTLOCEDGE,
135  };

◆ NCFormatType

Enumerator
NC_FORMAT_UNKNOWN_TYPE 
NC_FORMAT_MPAS 
NC_FORMAT_SCRIP 
NC_FORMAT_ESMF 
NC_FORMAT_DOMAIN 
NC_FORMAT_HOMME 
NC_FORMAT_GCRM 
NC_FORMAT_EULER 
NC_FORMAT_FV 

Definition at line 92 of file ReadNC.hpp.

93  {
95  NC_FORMAT_MPAS = 1,
96  NC_FORMAT_SCRIP = 2,
97  NC_FORMAT_ESMF = 3,
98  NC_FORMAT_DOMAIN = 4,
99  NC_FORMAT_HOMME = 5,
100  NC_FORMAT_GCRM = 6,
101  NC_FORMAT_EULER = 7,
102  NC_FORMAT_FV = 8
103  };

Constructor & Destructor Documentation

◆ ReadNC()

moab::ReadNC::ReadNC ( Interface impl = nullptr)
explicit

Constructor.

Definition at line 16 of file ReadNC.cpp.

17  : mbImpl( impl ), fileId( -1 ), mGlobalIdTag( 0 ), mpFileIdTag( NULL ), dbgOut( stderr ), isParallel( false ),
19 #ifdef MOAB_HAVE_MPI
20  myPcomm( NULL ),
21 #endif
22  noMesh( false ), noVars( false ), spectralMesh( false ), noMixedElements( false ), noEdges( false ),
23  culling( true ), repartition( false ), gatherSetRank( -1 ), tStepBase( -1 ), trivialPartitionShift( 0 ),
24  myHelper( NULL )
25 {
26  assert( impl != NULL );
27  impl->query_interface( readMeshIface );
28 }

References moab::Interface::query_interface(), and readMeshIface.

Referenced by factory().

◆ ~ReadNC()

moab::ReadNC::~ReadNC ( )
virtual

Destructor.

Definition at line 30 of file ReadNC.cpp.

31 {
33  if( myHelper != NULL ) delete myHelper;
34 }

References mbImpl, myHelper, readMeshIface, and moab::Interface::release_interface().

Member Function Documentation

◆ factory()

ReaderIface * moab::ReadNC::factory ( Interface iface)
static

Definition at line 11 of file ReadNC.cpp.

12 {
13  return new ReadNC( iface );
14 }

References iface, and ReadNC().

Referenced by moab::ReaderWriterSet::ReaderWriterSet().

◆ get_attributes()

ErrorCode moab::ReadNC::get_attributes ( int  var_id,
int  num_atts,
std::map< std::string, AttData > &  atts,
const char *  prefix = "" 
)
private

Get all global attributes in the file.

Definition at line 395 of file ReadNC.cpp.

396 {
397  char dum_name[120];
398 
399  for( int i = 0; i < num_atts; i++ )
400  {
401  // Get the name
402  int success = NCFUNC( inq_attname )( fileId, var_id, i, dum_name );
403  if( success ) MB_SET_ERR( MB_FAILURE, "Trouble getting attribute name" );
404 
405  AttData& data = atts[std::string( dum_name )];
406  data.attName = std::string( dum_name );
407  success = NCFUNC( inq_att )( fileId, var_id, dum_name, &data.attDataType, &data.attLen );
408  if( success ) MB_SET_ERR( MB_FAILURE, "Trouble getting info for attribute " << data.attName );
409  data.attVarId = var_id;
410 
411  dbgOut.tprintf( 2, "%sAttribute %s: length=%u, varId=%d, type=%d\n", ( prefix ? prefix : "" ),
412  data.attName.c_str(), (unsigned int)data.attLen, data.attVarId, data.attDataType );
413  }
414 
415  return MB_SUCCESS;
416 }

References moab::ReadNC::AttData::attDataType, moab::ReadNC::AttData::attLen, moab::ReadNC::AttData::attName, moab::ReadNC::AttData::attVarId, dbgOut, fileId, MB_SET_ERR, MB_SUCCESS, NCFUNC, and moab::DebugOutput::tprintf().

Referenced by get_variables(), and read_header().

◆ get_dimensions()

ErrorCode moab::ReadNC::get_dimensions ( int  file_id,
std::vector< std::string > &  dim_names,
std::vector< int > &  dim_lens 
)
private

Get all dimensions in the file.

Definition at line 418 of file ReadNC.cpp.

419 {
420  // Get the number of dimensions
421  int num_dims;
422  int success = NCFUNC( inq_ndims )( file_id, &num_dims );
423  if( success ) MB_SET_ERR( MB_FAILURE, "Trouble getting number of dimensions" );
424 
425  if( num_dims > NC_MAX_DIMS )
426  {
427  MB_SET_ERR( MB_FAILURE,
428  "ReadNC: File contains " << num_dims << " dims but NetCDF library supports only " << NC_MAX_DIMS );
429  }
430 
431  char dim_name[NC_MAX_NAME + 1];
432  NCDF_SIZE dim_len;
433  dim_names.resize( num_dims );
434  dim_lens.resize( num_dims );
435 
436  for( int i = 0; i < num_dims; i++ )
437  {
438  success = NCFUNC( inq_dim )( file_id, i, dim_name, &dim_len );
439  if( success ) MB_SET_ERR( MB_FAILURE, "Trouble getting dimension info" );
440 
441  dim_names[i] = std::string( dim_name );
442  dim_lens[i] = dim_len;
443 
444  dbgOut.tprintf( 2, "Dimension %s, length=%u\n", dim_name, (unsigned int)dim_len );
445  }
446 
447  return MB_SUCCESS;
448 }

References dbgOut, MB_SET_ERR, MB_SUCCESS, NCDF_SIZE, NCFUNC, and moab::DebugOutput::tprintf().

Referenced by moab::NCHelperHOMME::create_mesh(), and read_header().

◆ get_variables()

ErrorCode moab::ReadNC::get_variables ( )
private

Get the variable names and other info defined for this file.

Definition at line 450 of file ReadNC.cpp.

451 {
452  // First cache the number of time steps
453  std::vector< std::string >::iterator vit = std::find( dimNames.begin(), dimNames.end(), "time" );
454  if( vit == dimNames.end() ) vit = std::find( dimNames.begin(), dimNames.end(), "t" );
455 
456  int ntimes = 0;
457  if( vit != dimNames.end() ) ntimes = dimLens[vit - dimNames.begin()];
458  if( !ntimes ) ntimes = 1;
459 
460  // Get the number of variables
461  int num_vars;
462  int success = NCFUNC( inq_nvars )( fileId, &num_vars );
463  if( success ) MB_SET_ERR( MB_FAILURE, "Trouble getting number of variables" );
464 
465  if( num_vars > NC_MAX_VARS )
466  {
467  MB_SET_ERR( MB_FAILURE,
468  "ReadNC: File contains " << num_vars << " vars but NetCDF library supports only " << NC_MAX_VARS );
469  }
470 
471  char var_name[NC_MAX_NAME + 1];
472  int var_ndims;
473 
474  for( int i = 0; i < num_vars; i++ )
475  {
476  // Get the name first, so we can allocate a map iterate for this var
477  success = NCFUNC( inq_varname )( fileId, i, var_name );
478  if( success ) MB_SET_ERR( MB_FAILURE, "Trouble getting variable name" );
479  VarData& data = varInfo[std::string( var_name )];
480  data.varName = std::string( var_name );
481  data.varId = i;
482  data.varTags.resize( ntimes, 0 );
483 
484  // Get the data type
485  success = NCFUNC( inq_vartype )( fileId, i, &data.varDataType );
486  if( success ) MB_SET_ERR( MB_FAILURE, "Trouble getting data type for variable " << data.varName );
487 
488  // Get the number of dimensions, then the dimensions
489  success = NCFUNC( inq_varndims )( fileId, i, &var_ndims );
490  if( success ) MB_SET_ERR( MB_FAILURE, "Trouble getting number of dims for variable " << data.varName );
491  data.varDims.resize( var_ndims );
492 
493  success = NCFUNC( inq_vardimid )( fileId, i, &data.varDims[0] );
494  if( success ) MB_SET_ERR( MB_FAILURE, "Trouble getting dimensions for variable " << data.varName );
495 
496  // Finally, get the number of attributes, then the attributes
497  success = NCFUNC( inq_varnatts )( fileId, i, &data.numAtts );
498  if( success ) MB_SET_ERR( MB_FAILURE, "Trouble getting number of dims for variable " << data.varName );
499 
500  // Print debug info here so attribute info comes afterwards
501  dbgOut.tprintf( 2, "Variable %s: Id=%d, numAtts=%d, datatype=%d, num_dims=%u\n", data.varName.c_str(),
502  data.varId, data.numAtts, data.varDataType, (unsigned int)data.varDims.size() );
503 
504  MB_CHK_SET_ERR( get_attributes( i, data.numAtts, data.varAtts, " " ),
505  "Trouble getting attributes for variable " << data.varName );
506  }
507 
508  return MB_SUCCESS;
509 }

References dbgOut, dimLens, dimNames, fileId, get_attributes(), MB_CHK_SET_ERR, MB_SET_ERR, MB_SUCCESS, NCFUNC, moab::ReadNC::VarData::numAtts, moab::DebugOutput::tprintf(), moab::ReadNC::VarData::varAtts, moab::ReadNC::VarData::varDataType, moab::ReadNC::VarData::varDims, moab::ReadNC::VarData::varId, varInfo, moab::ReadNC::VarData::varName, and moab::ReadNC::VarData::varTags.

Referenced by read_header().

◆ load_file()

ErrorCode moab::ReadNC::load_file ( const char *  file_name,
const EntityHandle file_set,
const FileOptions opts,
const SubsetList subset_list = nullptr,
const Tag file_id_tag = nullptr 
)
virtual

Load an NC file.

Implements moab::ReaderIface.

Definition at line 36 of file ReadNC.cpp.

41 {
42  // See if opts has variable(s) specified
43  std::vector< std::string > var_names;
44  std::vector< int > tstep_nums;
45  std::vector< double > tstep_vals;
46 
47  // Get and cache predefined tag handles
49  // Store the pointer to the tag; if not null, set when global id tag
50  // is set too, with the same data, duplicated
51  mpFileIdTag = file_id_tag;
52 
53  MB_CHK_SET_ERR( parse_options( opts, var_names, tstep_nums, tstep_vals ), "Trouble parsing option string" );
54 
55  // Open the file
56  dbgOut.tprintf( 1, "Opening file %s\n", file_name );
57  fileName = std::string( file_name );
58  int success;
59 
60  // Probe on-disk format and select the backend that can actually read it.
61  // This replaces the old compile-time choice between nc_open and ncmpi_open
62  // (which silently failed on NetCDF-4/HDF5 files under PNetCDF-only builds).
63  // For parallel reads the probe runs on rank 0 and the answer is
64  // broadcast; the file header read is cheap (8 bytes) so the cost is
65  // negligible vs. doing the probe collectively on every rank.
66  int fileFormat = NCFMT_UNKNOWN;
67 #ifdef MOAB_HAVE_MPI
68  if( isParallel )
69  {
70  int rank = myPcomm->proc_config().proc_rank();
71  if( rank == 0 ) fileFormat = mbnc_detect_format( file_name );
72  MPI_Bcast( &fileFormat, 1, MPI_INT, 0, myPcomm->proc_config().proc_comm() );
73  }
74  else
75 #endif
76  {
77  fileFormat = mbnc_detect_format( file_name );
78  }
79 
80 #ifdef MOAB_HAVE_MPI
81  const int mpi_size = isParallel ? myPcomm->proc_config().proc_size() : 1;
82 #else
83  const int mpi_size = 1;
84 #endif
85 
86  const NcBackend backend = mbnc_choose_backend_for_read( fileFormat, mpi_size );
87  if( backend == NCB_NONE )
88  {
89  const char* fmtName = ( fileFormat == NCFMT_CLASSIC ) ? "classic CDF-1/2/5"
90  : ( fileFormat == NCFMT_NETCDF4 ) ? "NetCDF-4 / HDF5"
91  : "unrecognized / non-NetCDF";
92  MB_SET_ERR( MB_FAILURE,
93  "Cannot find a compatible parallel reader for file '"
94  << file_name << "' (detected format: " << fmtName
95  << "). PNetCDF cannot read NetCDF-4 files; libnetcdf parallel "
96  "must be configured for that case. Classic-format files require "
97  "either PNetCDF or libnetcdf built with --enable-pnetcdf." );
98  }
99 
100 #ifdef MOAB_HAVE_MPI
101  if( backend == NCB_NETCDF_SERIAL || mpi_size == 1 )
102  {
103  success = mbnc_open( file_name, 0, &fileId );
104  }
105  else
106  {
107  success = mbnc_open_par( backend, myPcomm->proc_config().proc_comm(), MPI_INFO_NULL, file_name, 0, &fileId );
108  }
109 #else
110  success = mbnc_open( file_name, 0, &fileId );
111 #endif
112  if( success ) MB_SET_ERR( MB_FAILURE, "Trouble opening file " << file_name );
113 
114  // Read the header (num dimensions, dimensions, num variables, global attribs)
115  MB_CHK_SET_ERR( read_header(), "Trouble reading file header" );
116 
117  // Make sure there's a file set to put things in
118  EntityHandle tmp_set;
119  if( noMesh && !file_set )
120  {
121  MB_SET_ERR( MB_FAILURE, "NOMESH option requires non-NULL file set on input" );
122  }
123  else if( !file_set || ( file_set && *file_set == 0 ) )
124  {
125  MB_CHK_SET_ERR( mbImpl->create_meshset( MESHSET_SET, tmp_set ), "Trouble creating file set" );
126  }
127  else
128  tmp_set = *file_set;
129 
130  // Get the scd interface
131  scdi = nullptr;
132  MB_CHK_SET_ERR( mbImpl->query_interface( scdi ), "failed to get SCD interface from query" );
133  if( nullptr == scdi ) return MB_FAILURE;
134 
135  if( nullptr != myHelper ) delete myHelper;
136 
137  // Get appropriate NC helper instance based on information read from the header
138  myHelper = NCHelper::get_nc_helper( this, fileId, opts, tmp_set );
139  if( nullptr == myHelper )
140  {
141  MB_SET_ERR( MB_FAILURE, "Failed to get NCHelper class instance" );
142  }
143 
144  // Initialize mesh values
145  MB_CHK_SET_ERR( myHelper->init_mesh_vals(), "Trouble initializing mesh values" );
146 
147  // Check existing mesh from last read
148  if( noMesh && !noVars )
149  {
150  MB_CHK_SET_ERR( myHelper->check_existing_mesh(), "Trouble checking mesh from last read" );
151  }
152 
153  // Create some conventional tags, e.g. __NUM_DIMS
154  // For multiple reads to a specified file set, we assume a single file, or a series of
155  // files with separated timesteps. Keep a flag on the file set to prevent conventional
156  // tags from being created again on a second read
157  Tag convTagsCreated = 0;
158  int def_val = 0;
159  MB_CHK_SET_ERR( mbImpl->tag_get_handle( "__CONV_TAGS_CREATED", 1, MB_TYPE_INTEGER, convTagsCreated,
160  MB_TAG_SPARSE | MB_TAG_CREAT, &def_val ),
161  "Trouble getting _CONV_TAGS_CREATED tag" );
162  int create_conv_tags_flag = 0;
163  MB_CHK_SET_ERR( mbImpl->tag_get_data( convTagsCreated, &tmp_set, 1, &create_conv_tags_flag ),
164  "failed to get conventional tags" );
165  // The first read to the file set
166  if( 0 == create_conv_tags_flag )
167  {
168  // Read dimensions (coordinate variables) by default to create tags like __<var_name>_DIMS
169  // This is done only once (assume that all files read to the file set have the same
170  // dimensions)
171  MB_CHK_SET_ERR( myHelper->read_variables( dimNames, tstep_nums ), "Trouble reading dimensions" );
172 
173  MB_CHK_SET_ERR( myHelper->create_conventional_tags( tstep_nums ), "Trouble creating NC conventional tags" );
174 
175  create_conv_tags_flag = 1;
176  MB_CHK_SET_ERR( mbImpl->tag_set_data( convTagsCreated, &tmp_set, 1, &create_conv_tags_flag ),
177  "Trouble setting data to _CONV_TAGS_CREATED tag" );
178  }
179  else // Another read to the file set
180  {
181  if( tStepBase > -1 )
182  {
183  // If timesteps spread across files, merge time values read
184  // from current file to existing time tag
185  MB_CHK_SET_ERR( myHelper->update_time_tag_vals(), "Trouble updating time tag values" );
186  }
187  }
188 
189  // Create mesh vertex/edge/face sequences
190  Range faces;
191  if( !noMesh )
192  {
193  MB_CHK_SET_ERR( myHelper->create_mesh( faces ), "Trouble creating mesh" );
194  }
195 
196  // Read specified variables onto grid
197  if( !noVars )
198  {
199  if( var_names.empty() )
200  {
201  // If VARIABLE option is missing, read all variables
202  MB_CHK_SET_ERR( myHelper->read_variables( var_names, tstep_nums ), "Trouble reading all variables" );
203  }
204  else
205  {
206  // Exclude dimensions that are read to the file set by default
207  std::vector< std::string > non_dim_var_names;
208  for( unsigned int i = 0; i < var_names.size(); i++ )
209  {
210  if( std::find( dimNames.begin(), dimNames.end(), var_names[i] ) == dimNames.end() )
211  non_dim_var_names.push_back( var_names[i] );
212  }
213 
214  if( !non_dim_var_names.empty() )
215  {
216  MB_CHK_SET_ERR( myHelper->read_variables( non_dim_var_names, tstep_nums ),
217  "Trouble reading specified variables" );
218  }
219  }
220  }
221 
222 #ifdef MOAB_HAVE_MPI
223  // Create partition set, and populate with elements
224  if( isParallel )
225  {
226  // Write partition tag name on partition set
227  Tag part_tag = myPcomm->partition_tag();
228  int dum_rank = myPcomm->proc_config().proc_rank();
229  // the tmp_set is the file_set
230  MB_CHK_SET_ERR( mbImpl->tag_set_data( part_tag, &tmp_set, 1, &dum_rank ),
231  "Trouble writing partition tag name on partition set" );
232  }
233 #endif
234 
236  scdi = NULL;
237 
238  // Close the file
239  success = NCFUNC( close )( fileId );
240  if( success ) MB_SET_ERR( MB_FAILURE, "Trouble closing file" );
241 
242  return MB_SUCCESS;
243 }

References moab::NCHelper::check_existing_mesh(), moab::NCHelper::create_conventional_tags(), moab::NCHelper::create_mesh(), moab::Interface::create_meshset(), dbgOut, dimNames, fileId, fileName, moab::NCHelper::get_nc_helper(), moab::Interface::globalId_tag(), moab::NCHelper::init_mesh_vals(), isParallel, MB_CHK_SET_ERR, MB_SET_ERR, MB_SUCCESS, MB_TAG_CREAT, MB_TAG_SPARSE, MB_TYPE_INTEGER, mbImpl, moab::mbnc_choose_backend_for_read(), moab::mbnc_detect_format(), moab::mbnc_open(), MESHSET_SET, mGlobalIdTag, mpFileIdTag, myHelper, moab::NCB_NETCDF_SERIAL, moab::NCB_NONE, moab::NCFMT_CLASSIC, moab::NCFMT_NETCDF4, moab::NCFMT_UNKNOWN, NCFUNC, noMesh, noVars, parse_options(), moab::Interface::query_interface(), read_header(), moab::NCHelper::read_variables(), moab::Interface::release_interface(), scdi, moab::Interface::tag_get_data(), moab::Interface::tag_get_handle(), moab::Interface::tag_set_data(), moab::DebugOutput::tprintf(), tStepBase, and moab::NCHelper::update_time_tag_vals().

◆ parse_options()

ErrorCode moab::ReadNC::parse_options ( const FileOptions opts,
std::vector< std::string > &  var_names,
std::vector< int > &  tstep_nums,
std::vector< double > &  tstep_vals 
)
private

Definition at line 245 of file ReadNC.cpp.

249 {
250  int tmpval;
251  if( MB_SUCCESS == opts.get_int_option( "DEBUG_IO", 1, tmpval ) )
252  {
253  dbgOut.set_verbosity( tmpval );
254  dbgOut.set_prefix( "NC " );
255  }
256 
257  ErrorCode rval = opts.get_strs_option( "VARIABLE", var_names );
258  if( MB_TYPE_OUT_OF_RANGE == rval )
259  noVars = true;
260  else
261  noVars = false;
262 
263  opts.get_ints_option( "TIMESTEP", tstep_nums );
264  opts.get_reals_option( "TIMEVAL", tstep_vals );
265 
266  rval = opts.get_null_option( "NOMESH" );
267  if( MB_SUCCESS == rval ) noMesh = true;
268 
269  rval = opts.get_null_option( "SPECTRAL_MESH" );
270  if( MB_SUCCESS == rval ) spectralMesh = true;
271 
272  rval = opts.get_null_option( "NO_MIXED_ELEMENTS" );
273  if( MB_SUCCESS == rval ) noMixedElements = true;
274 
275  rval = opts.get_null_option( "NO_EDGES" );
276  if( MB_SUCCESS == rval ) noEdges = true;
277 
278  rval = opts.get_null_option( "NO_CULLING" ); // used now only for domain nc convention
279  if( MB_SUCCESS == rval ) culling = false;
280 
281  rval = opts.get_null_option( "REPARTITION" ); // used now only for domain nc, to repartition with zoltan
282  if( MB_SUCCESS == rval ) repartition = true;
283 
284  if( 2 <= dbgOut.get_verbosity() )
285  {
286  if( !var_names.empty() )
287  {
288  std::cerr << "Variables requested: ";
289  for( unsigned int i = 0; i < var_names.size(); i++ )
290  std::cerr << var_names[i];
291  std::cerr << std::endl;
292  }
293 
294  if( !tstep_nums.empty() )
295  {
296  std::cerr << "Timesteps requested: ";
297  for( unsigned int i = 0; i < tstep_nums.size(); i++ )
298  std::cerr << tstep_nums[i];
299  std::cerr << std::endl;
300  }
301 
302  if( !tstep_vals.empty() )
303  {
304  std::cerr << "Time vals requested: ";
305  for( unsigned int i = 0; i < tstep_vals.size(); i++ )
306  std::cerr << tstep_vals[i];
307  std::cerr << std::endl;
308  }
309  }
310 
311  rval = opts.get_int_option( "GATHER_SET", 0, gatherSetRank );
312  if( MB_TYPE_OUT_OF_RANGE == rval )
313  {
314  MB_SET_ERR( rval, "Invalid value for GATHER_SET option" );
315  }
316 
317  rval = opts.get_int_option( "TIMESTEPBASE", 0, tStepBase );
318  if( MB_TYPE_OUT_OF_RANGE == rval )
319  {
320  MB_SET_ERR( rval, "Invalid value for TIMESTEPBASE option" );
321  }
322 
323  rval = opts.get_int_option( "TRIVIAL_PARTITION_SHIFT", 1, trivialPartitionShift );
324  if( MB_TYPE_OUT_OF_RANGE == rval )
325  {
326  MB_SET_ERR( rval, "Invalid value for TRIVIAL_PARTITION_SHIFT option" );
327  }
328 
329 #ifdef MOAB_HAVE_MPI
330  isParallel = ( opts.match_option( "PARALLEL", "READ_PART" ) != MB_ENTITY_NOT_FOUND );
331 
332  if( !isParallel )
333  // Return success here, since rval still has _NOT_FOUND from not finding option
334  // in this case, myPcomm will be NULL, so it can never be used; always check for isParallel
335  // before any use for myPcomm
336  return MB_SUCCESS;
337 
338  int pcomm_no = 0;
339  rval = opts.get_int_option( "PARALLEL_COMM", pcomm_no );
340  if( MB_TYPE_OUT_OF_RANGE == rval )
341  {
342  MB_SET_ERR( rval, "Invalid value for PARALLEL_COMM option" );
343  }
344  myPcomm = ParallelComm::get_pcomm( mbImpl, pcomm_no );
345  if( 0 == myPcomm )
346  {
347  myPcomm = new ParallelComm( mbImpl, MPI_COMM_WORLD );
348  }
349  const int rank = myPcomm->proc_config().proc_rank();
350  dbgOut.set_rank( rank );
351 
352  int dum;
353  rval = opts.match_option( "PARTITION_METHOD", ScdParData::PartitionMethodNames, dum );
354  if( MB_FAILURE == rval )
355  {
356  MB_SET_ERR( rval, "Unknown partition method specified" );
357  }
358  else if( MB_ENTITY_NOT_FOUND == rval )
360  else
361  partMethod = dum;
362 #endif
363 
364  return MB_SUCCESS;
365 }

References moab::ScdParData::ALLJORKORI, culling, dbgOut, moab::dum, ErrorCode, gatherSetRank, moab::FileOptions::get_int_option(), moab::FileOptions::get_ints_option(), moab::FileOptions::get_null_option(), moab::ParallelComm::get_pcomm(), moab::FileOptions::get_reals_option(), moab::FileOptions::get_strs_option(), moab::DebugOutput::get_verbosity(), isParallel, moab::FileOptions::match_option(), MB_ENTITY_NOT_FOUND, MB_SET_ERR, MB_SUCCESS, MB_TYPE_OUT_OF_RANGE, mbImpl, noEdges, noMesh, noMixedElements, noVars, moab::ScdParData::PartitionMethodNames, partMethod, repartition, moab::DebugOutput::set_prefix(), moab::DebugOutput::set_rank(), moab::DebugOutput::set_verbosity(), spectralMesh, trivialPartitionShift, and tStepBase.

Referenced by load_file().

◆ read_header()

ErrorCode moab::ReadNC::read_header ( )
private

Read the header information.

Definition at line 367 of file ReadNC.cpp.

368 {
369  dbgOut.tprint( 1, "Reading header...\n" );
370 
371  // Get the global attributes
372  int numgatts;
373  int success;
374  success = NCFUNC( inq_natts )( fileId, &numgatts );
375  if( success ) MB_SET_ERR( MB_FAILURE, "Couldn't get number of global attributes" );
376 
377  // Read attributes into globalAtts
378  ErrorCode result = get_attributes( NC_GLOBAL, numgatts, globalAtts );
379  MB_CHK_SET_ERR( result, "Trouble getting global attributes" );
380  dbgOut.tprintf( 1, "Read %u attributes\n", (unsigned int)globalAtts.size() );
381 
382  // Read in dimensions into dimNames and dimLens
383  result = get_dimensions( fileId, dimNames, dimLens );
384  MB_CHK_SET_ERR( result, "Trouble getting dimensions" );
385  dbgOut.tprintf( 1, "Read %u dimensions\n", (unsigned int)dimNames.size() );
386 
387  // Read in variables into varInfo
388  result = get_variables();
389  MB_CHK_SET_ERR( result, "Trouble getting variables" );
390  dbgOut.tprintf( 1, "Read %u variables\n", (unsigned int)varInfo.size() );
391 
392  return MB_SUCCESS;
393 }

References dbgOut, dimLens, dimNames, ErrorCode, fileId, get_attributes(), get_dimensions(), get_variables(), globalAtts, MB_CHK_SET_ERR, MB_SET_ERR, MB_SUCCESS, NCFUNC, moab::DebugOutput::tprint(), moab::DebugOutput::tprintf(), and varInfo.

Referenced by load_file().

◆ read_tag_values()

ErrorCode moab::ReadNC::read_tag_values ( const char *  file_name,
const char *  tag_name,
const FileOptions opts,
std::vector< int > &  tag_values_out,
const SubsetList subset_list = nullptr 
)
virtual

Read tag values from a file.

Read the list if all integer tag values from the file for a tag that is a single integer value per entity.

Parameters
file_nameThe file to read.
tag_nameThe tag for which to read values
tag_values_outOutput: The list of tag values.
subset_listAn array of tag name and value sets specifying the subset of the file to read. If multiple tags are specified, the sets that match all tags (intersection) should be read.
subset_list_lengthThe length of the 'subset_list' array.

Implements moab::ReaderIface.

Definition at line 511 of file ReadNC.cpp.

516 {
517  return MB_FAILURE;
518 }

Friends And Related Function Documentation

◆ NCHelper

friend class NCHelper
friend

Definition at line 77 of file ReadNC.hpp.

◆ NCHelperDomain

friend class NCHelperDomain
friend

Definition at line 82 of file ReadNC.hpp.

◆ NCHelperESMF

friend class NCHelperESMF
friend

Definition at line 86 of file ReadNC.hpp.

◆ NCHelperEuler

friend class NCHelperEuler
friend

Definition at line 80 of file ReadNC.hpp.

◆ NCHelperFV

friend class NCHelperFV
friend

Definition at line 81 of file ReadNC.hpp.

◆ NCHelperGCRM

friend class NCHelperGCRM
friend

Definition at line 87 of file ReadNC.hpp.

◆ NCHelperHOMME

friend class NCHelperHOMME
friend

Definition at line 84 of file ReadNC.hpp.

◆ NCHelperMPAS

friend class NCHelperMPAS
friend

Definition at line 85 of file ReadNC.hpp.

◆ NCHelperScrip

friend class NCHelperScrip
friend

Definition at line 83 of file ReadNC.hpp.

◆ ScdNCHelper

friend class ScdNCHelper
friend

Definition at line 78 of file ReadNC.hpp.

◆ UcdNCHelper

friend class UcdNCHelper
friend

Definition at line 79 of file ReadNC.hpp.

Member Data Documentation

◆ culling

bool moab::ReadNC::culling
private

Definition at line 249 of file ReadNC.hpp.

Referenced by moab::NCHelperDomain::create_mesh(), and parse_options().

◆ dbgOut

◆ dimLens

◆ dimNames

◆ fileId

int moab::ReadNC::fileId
private

File numbers assigned by netcdf.

Definition at line 200 of file ReadNC.hpp.

Referenced by moab::NCHelperHOMME::create_mesh(), get_attributes(), get_variables(), load_file(), moab::NCHelperHOMME::NCHelperHOMME(), and read_header().

◆ fileName

std::string moab::ReadNC::fileName
private

File name.

Definition at line 197 of file ReadNC.hpp.

Referenced by moab::NCHelperHOMME::create_mesh(), and load_file().

◆ gatherSetRank

int moab::ReadNC::gatherSetRank
private

◆ globalAtts

◆ isParallel

◆ mbImpl

Interface* moab::ReadNC::mbImpl
private

Interface instance.

Definition at line 194 of file ReadNC.hpp.

Referenced by moab::ScdNCHelper::check_existing_mesh(), moab::NCHelperGCRM::check_existing_mesh(), moab::NCHelperHOMME::check_existing_mesh(), moab::NCHelperMPAS::check_existing_mesh(), moab::NCHelper::create_conventional_tags(), moab::NCHelper::create_dummy_variables(), moab::NCHelperMPAS::create_gather_set_cells(), moab::NCHelperGCRM::create_gather_set_edges(), moab::NCHelperMPAS::create_gather_set_edges(), moab::NCHelperGCRM::create_gather_set_vertices(), moab::NCHelperMPAS::create_gather_set_vertices(), moab::NCHelperESMF::create_local_cells(), moab::NCHelperMPAS::create_local_cells(), moab::NCHelperGCRM::create_local_edges(), moab::NCHelperMPAS::create_local_edges(), moab::NCHelperESMF::create_local_vertices(), moab::NCHelperGCRM::create_local_vertices(), moab::NCHelperMPAS::create_local_vertices(), moab::ScdNCHelper::create_mesh(), moab::NCHelperDomain::create_mesh(), moab::NCHelperHOMME::create_mesh(), moab::NCHelperMPAS::create_mesh(), moab::NCHelperScrip::create_mesh(), moab::NCHelperGCRM::create_padded_gather_set_cells(), moab::NCHelperMPAS::create_padded_gather_set_cells(), moab::NCHelperESMF::create_padded_local_cells(), moab::NCHelperGCRM::create_padded_local_cells(), moab::NCHelperMPAS::create_padded_local_cells(), moab::ScdNCHelper::create_quad_coordinate_tag(), moab::NCHelper::get_tag_to_nonset(), moab::NCHelper::get_tag_to_set(), moab::NCHelperDomain::init_mesh_vals(), moab::NCHelperEuler::init_mesh_vals(), moab::NCHelperFV::init_mesh_vals(), moab::NCHelperScrip::init_mesh_vals(), load_file(), parse_options(), moab::ScdNCHelper::read_scd_variables_to_nonset_allocate(), moab::NCHelperMPAS::read_ucd_variables_to_nonset(), moab::NCHelperGCRM::read_ucd_variables_to_nonset_allocate(), moab::NCHelperHOMME::read_ucd_variables_to_nonset_allocate(), moab::NCHelperMPAS::read_ucd_variables_to_nonset_allocate(), moab::NCHelper::read_variables_to_set(), moab::NCHelper::update_time_tag_vals(), and ~ReadNC().

◆ mGlobalIdTag

◆ mpFileIdTag

const Tag* moab::ReadNC::mpFileIdTag
private

This is a pointer to the file id tag that is passed from ReadParallel it gets deleted at the end of resolve sharing, but it will have same data as the global id tag global id tag is preserved, and is needed later on.

Definition at line 222 of file ReadNC.hpp.

Referenced by moab::NCHelperGCRM::create_gather_set_vertices(), moab::NCHelperMPAS::create_gather_set_vertices(), moab::NCHelperESMF::create_local_vertices(), moab::NCHelperGCRM::create_local_vertices(), moab::NCHelperMPAS::create_local_vertices(), moab::ScdNCHelper::create_mesh(), moab::NCHelperHOMME::create_mesh(), and load_file().

◆ myHelper

NCHelper* moab::ReadNC::myHelper
private

Helper class instance.

Definition at line 256 of file ReadNC.hpp.

Referenced by load_file(), and ~ReadNC().

◆ noEdges

◆ noMesh

◆ noMixedElements

bool moab::ReadNC::noMixedElements
private

◆ noVars

bool moab::ReadNC::noVars
private

Definition at line 245 of file ReadNC.hpp.

Referenced by load_file(), and parse_options().

◆ parData

ScdParData moab::ReadNC::parData
private

◆ partMethod

◆ readMeshIface

◆ repartition

bool moab::ReadNC::repartition
private

Definition at line 250 of file ReadNC.hpp.

Referenced by moab::NCHelperDomain::create_mesh(), and parse_options().

◆ scdi

ScdInterface* moab::ReadNC::scdi
private

Scd interface.

Definition at line 234 of file ReadNC.hpp.

Referenced by moab::NCHelper::create_conventional_tags(), moab::ScdNCHelper::create_mesh(), and load_file().

◆ spectralMesh

bool moab::ReadNC::spectralMesh
private

Definition at line 246 of file ReadNC.hpp.

Referenced by moab::NCHelperHOMME::create_mesh(), and parse_options().

◆ trivialPartitionShift

◆ tStepBase

int moab::ReadNC::tStepBase
private

◆ varInfo


The documentation for this class was generated from the following files: