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 ), culling(true),
23 repartition(false), gatherSetRank( -1 ), tStepBase( -1 ), trivialPartitionShift( 0 ), myHelper( NULL )
25 assert( impl != NULL );
39 const Tag* file_id_tag )
42 std::vector< std::string > var_names;
43 std::vector< int > tstep_nums;
44 std::vector< double > tstep_vals;
59 #ifdef MOAB_HAVE_PNETCDF
61 success =
NCFUNC( open )( myPcomm->proc_config().proc_comm(), file_name, 0, MPI_INFO_NULL, &
fileId );
63 success =
NCFUNC( open )( MPI_COMM_SELF, file_name, 0, MPI_INFO_NULL, &
fileId );
67 if( success )
MB_SET_ERR( MB_FAILURE,
"Trouble opening file " << file_name );
76 MB_SET_ERR( MB_FAILURE,
"NOMESH option requires non-NULL file set on input" );
78 else if( !file_set || ( file_set && *file_set == 0 ) )
88 if( NULL ==
scdi )
return MB_FAILURE;
96 MB_SET_ERR( MB_FAILURE,
"Failed to get NCHelper class instance" );
112 Tag convTagsCreated = 0;
116 int create_conv_tags_flag = 0;
119 if( 0 == create_conv_tags_flag )
128 create_conv_tags_flag = 1;
129 rval =
mbImpl->
tag_set_data( convTagsCreated, &tmp_set, 1, &create_conv_tags_flag );
MB_CHK_SET_ERR( rval,
"Trouble setting data to _CONV_TAGS_CREATED tag" );
152 if( var_names.empty() )
160 std::vector< std::string > non_dim_var_names;
161 for(
unsigned int i = 0; i < var_names.size(); i++ )
164 non_dim_var_names.push_back( var_names[i] );
167 if( !non_dim_var_names.empty() )
179 Tag part_tag = myPcomm->partition_tag();
180 int dum_rank = myPcomm->proc_config().proc_rank();
191 if( success )
MB_SET_ERR( MB_FAILURE,
"Trouble closing file" );
197 std::vector< std::string >& var_names,
198 std::vector< int >& tstep_nums,
199 std::vector< double >& tstep_vals )
237 if( !var_names.empty() )
239 std::cerr <<
"Variables requested: ";
240 for(
unsigned int i = 0; i < var_names.size(); i++ )
241 std::cerr << var_names[i];
242 std::cerr << std::endl;
245 if( !tstep_nums.empty() )
247 std::cerr <<
"Timesteps requested: ";
248 for(
unsigned int i = 0; i < tstep_nums.size(); i++ )
249 std::cerr << tstep_nums[i];
250 std::cerr << std::endl;
253 if( !tstep_vals.empty() )
255 std::cerr <<
"Time vals requested: ";
256 for(
unsigned int i = 0; i < tstep_vals.size(); i++ )
257 std::cerr << tstep_vals[i];
258 std::cerr << std::endl;
265 MB_SET_ERR( rval,
"Invalid value for GATHER_SET option" );
271 MB_SET_ERR( rval,
"Invalid value for TIMESTEPBASE option" );
277 MB_SET_ERR( rval,
"Invalid value for TRIVIAL_PARTITION_SHIFT option" );
293 MB_SET_ERR( rval,
"Invalid value for PARALLEL_COMM option" );
300 const int rank = myPcomm->proc_config().proc_rank();
305 if( MB_FAILURE == rval )
307 MB_SET_ERR( rval,
"Unknown partition method specified" );
326 if( success )
MB_SET_ERR( MB_FAILURE,
"Couldn't get number of global attributes" );
347 for(
int i = 0; i < num_atts; i++ )
350 int success =
NCFUNC( inq_attname )(
fileId, var_id, i, dum_name );
351 if( success )
MB_SET_ERR( MB_FAILURE,
"Trouble getting attribute name" );
353 AttData& data = atts[std::string( dum_name )];
354 data.
attName = std::string( dum_name );
356 if( success )
MB_SET_ERR( MB_FAILURE,
"Trouble getting info for attribute " << data.
attName );
359 dbgOut.
tprintf( 2,
"%sAttribute %s: length=%u, varId=%d, type=%d\n", ( prefix ? prefix :
"" ),
370 int success =
NCFUNC( inq_ndims )( file_id, &num_dims );
371 if( success )
MB_SET_ERR( MB_FAILURE,
"Trouble getting number of dimensions" );
373 if( num_dims > NC_MAX_DIMS )
376 "ReadNC: File contains " << num_dims <<
" dims but NetCDF library supports only " << NC_MAX_DIMS );
379 char dim_name[NC_MAX_NAME + 1];
381 dim_names.resize( num_dims );
382 dim_lens.resize( num_dims );
384 for(
int i = 0; i < num_dims; i++ )
386 success =
NCFUNC( inq_dim )( file_id, i, dim_name, &dim_len );
387 if( success )
MB_SET_ERR( MB_FAILURE,
"Trouble getting dimension info" );
389 dim_names[i] = std::string( dim_name );
390 dim_lens[i] = dim_len;
392 dbgOut.
tprintf( 2,
"Dimension %s, length=%u\n", dim_name, (
unsigned int)dim_len );
401 std::vector< std::string >::iterator vit = std::find(
dimNames.begin(),
dimNames.end(),
"time" );
406 if( !ntimes ) ntimes = 1;
411 if( success )
MB_SET_ERR( MB_FAILURE,
"Trouble getting number of variables" );
413 if( num_vars > NC_MAX_VARS )
416 "ReadNC: File contains " << num_vars <<
" vars but NetCDF library supports only " << NC_MAX_VARS );
419 char var_name[NC_MAX_NAME + 1];
422 for(
int i = 0; i < num_vars; i++ )
426 if( success )
MB_SET_ERR( MB_FAILURE,
"Trouble getting variable name" );
428 data.
varName = std::string( var_name );
430 data.
varTags.resize( ntimes, 0 );
434 if( success )
MB_SET_ERR( MB_FAILURE,
"Trouble getting data type for variable " << data.
varName );
437 success =
NCFUNC( inq_varndims )(
fileId, i, &var_ndims );
438 if( success )
MB_SET_ERR( MB_FAILURE,
"Trouble getting number of dims for variable " << data.
varName );
439 data.
varDims.resize( var_ndims );
442 if( success )
MB_SET_ERR( MB_FAILURE,
"Trouble getting dimensions for variable " << data.
varName );
446 if( success )
MB_SET_ERR( MB_FAILURE,
"Trouble getting number of dims for variable " << data.
varName );
449 dbgOut.
tprintf( 2,
"Variable %s: Id=%d, numAtts=%d, datatype=%d, num_dims=%u\n", data.
varName.c_str(),