17 : mbImpl( impl ), fileId( -1 ), mGlobalIdTag( 0 ), mpFileIdTag( NULL ), dbgOut( stderr ), isParallel( false ),
18 partMethod(
ScdParData::ALLJORKORI ), scdi( NULL ),
22 noMesh( false ), noVars( false ), spectralMesh( false ), noMixedElements( false ), noEdges( false ),
23 culling( true ), repartition( false ), gatherSetRank( -1 ), tStepBase( -1 ), trivialPartitionShift( 0 ),
26 assert( impl != NULL );
40 const Tag* file_id_tag )
43 std::vector< std::string > var_names;
44 std::vector< int > tstep_nums;
45 std::vector< double > tstep_vals;
60 #ifdef MOAB_HAVE_PNETCDF
62 success =
NCFUNC( open )( myPcomm->proc_config().proc_comm(), file_name, 0, MPI_INFO_NULL, &
fileId );
64 success =
NCFUNC( open )( MPI_COMM_SELF, file_name, 0, MPI_INFO_NULL, &
fileId );
68 if( success )
MB_SET_ERR( MB_FAILURE,
"Trouble opening file " << file_name );
77 MB_SET_ERR( MB_FAILURE,
"NOMESH option requires non-NULL file set on input" );
79 else if( !file_set || ( file_set && *file_set == 0 ) )
89 if(
nullptr ==
scdi )
return MB_FAILURE;
97 MB_SET_ERR( MB_FAILURE,
"Failed to get NCHelper class instance" );
113 Tag convTagsCreated = 0;
117 "Trouble getting _CONV_TAGS_CREATED tag" );
118 int create_conv_tags_flag = 0;
120 "failed to get conventional tags" );
122 if( 0 == create_conv_tags_flag )
131 create_conv_tags_flag = 1;
133 "Trouble setting data to _CONV_TAGS_CREATED tag" );
155 if( var_names.empty() )
163 std::vector< std::string > non_dim_var_names;
164 for(
unsigned int i = 0; i < var_names.size(); i++ )
167 non_dim_var_names.push_back( var_names[i] );
170 if( !non_dim_var_names.empty() )
173 "Trouble reading specified variables" );
183 Tag part_tag = myPcomm->partition_tag();
184 int dum_rank = myPcomm->proc_config().proc_rank();
187 "Trouble writing partition tag name on partition set" );
196 if( success )
MB_SET_ERR( MB_FAILURE,
"Trouble closing file" );
202 std::vector< std::string >& var_names,
203 std::vector< int >& tstep_nums,
204 std::vector< double >& tstep_vals )
242 if( !var_names.empty() )
244 std::cerr <<
"Variables requested: ";
245 for(
unsigned int i = 0; i < var_names.size(); i++ )
246 std::cerr << var_names[i];
247 std::cerr << std::endl;
250 if( !tstep_nums.empty() )
252 std::cerr <<
"Timesteps requested: ";
253 for(
unsigned int i = 0; i < tstep_nums.size(); i++ )
254 std::cerr << tstep_nums[i];
255 std::cerr << std::endl;
258 if( !tstep_vals.empty() )
260 std::cerr <<
"Time vals requested: ";
261 for(
unsigned int i = 0; i < tstep_vals.size(); i++ )
262 std::cerr << tstep_vals[i];
263 std::cerr << std::endl;
270 MB_SET_ERR( rval,
"Invalid value for GATHER_SET option" );
276 MB_SET_ERR( rval,
"Invalid value for TIMESTEPBASE option" );
282 MB_SET_ERR( rval,
"Invalid value for TRIVIAL_PARTITION_SHIFT option" );
298 MB_SET_ERR( rval,
"Invalid value for PARALLEL_COMM option" );
305 const int rank = myPcomm->proc_config().proc_rank();
310 if( MB_FAILURE == rval )
312 MB_SET_ERR( rval,
"Unknown partition method specified" );
331 if( success )
MB_SET_ERR( MB_FAILURE,
"Couldn't get number of global attributes" );
355 for(
int i = 0; i < num_atts; i++ )
358 int success =
NCFUNC( inq_attname )(
fileId, var_id, i, dum_name );
359 if( success )
MB_SET_ERR( MB_FAILURE,
"Trouble getting attribute name" );
361 AttData& data = atts[std::string( dum_name )];
362 data.
attName = std::string( dum_name );
364 if( success )
MB_SET_ERR( MB_FAILURE,
"Trouble getting info for attribute " << data.
attName );
367 dbgOut.
tprintf( 2,
"%sAttribute %s: length=%u, varId=%d, type=%d\n", ( prefix ? prefix :
"" ),
378 int success =
NCFUNC( inq_ndims )( file_id, &num_dims );
379 if( success )
MB_SET_ERR( MB_FAILURE,
"Trouble getting number of dimensions" );
381 if( num_dims > NC_MAX_DIMS )
384 "ReadNC: File contains " << num_dims <<
" dims but NetCDF library supports only " << NC_MAX_DIMS );
387 char dim_name[NC_MAX_NAME + 1];
389 dim_names.resize( num_dims );
390 dim_lens.resize( num_dims );
392 for(
int i = 0; i < num_dims; i++ )
394 success =
NCFUNC( inq_dim )( file_id, i, dim_name, &dim_len );
395 if( success )
MB_SET_ERR( MB_FAILURE,
"Trouble getting dimension info" );
397 dim_names[i] = std::string( dim_name );
398 dim_lens[i] = dim_len;
400 dbgOut.
tprintf( 2,
"Dimension %s, length=%u\n", dim_name, (
unsigned int)dim_len );
409 std::vector< std::string >::iterator vit = std::find(
dimNames.begin(),
dimNames.end(),
"time" );
414 if( !ntimes ) ntimes = 1;
419 if( success )
MB_SET_ERR( MB_FAILURE,
"Trouble getting number of variables" );
421 if( num_vars > NC_MAX_VARS )
424 "ReadNC: File contains " << num_vars <<
" vars but NetCDF library supports only " << NC_MAX_VARS );
427 char var_name[NC_MAX_NAME + 1];
430 for(
int i = 0; i < num_vars; i++ )
434 if( success )
MB_SET_ERR( MB_FAILURE,
"Trouble getting variable name" );
436 data.
varName = std::string( var_name );
438 data.
varTags.resize( ntimes, 0 );
442 if( success )
MB_SET_ERR( MB_FAILURE,
"Trouble getting data type for variable " << data.
varName );
445 success =
NCFUNC( inq_varndims )(
fileId, i, &var_ndims );
446 if( success )
MB_SET_ERR( MB_FAILURE,
"Trouble getting number of dims for variable " << data.
varName );
447 data.
varDims.resize( var_ndims );
450 if( success )
MB_SET_ERR( MB_FAILURE,
"Trouble getting dimensions for variable " << data.
varName );
454 if( success )
MB_SET_ERR( MB_FAILURE,
"Trouble getting number of dims for variable " << data.
varName );
457 dbgOut.
tprintf( 2,
"Variable %s: Id=%d, numAtts=%d, datatype=%d, num_dims=%u\n", data.
varName.c_str(),
461 "Trouble getting attributes for variable " << data.
varName );