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 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 )
231 if( !var_names.empty() )
233 std::cerr <<
"Variables requested: ";
234 for(
unsigned int i = 0; i < var_names.size(); i++ )
235 std::cerr << var_names[i];
236 std::cerr << std::endl;
239 if( !tstep_nums.empty() )
241 std::cerr <<
"Timesteps requested: ";
242 for(
unsigned int i = 0; i < tstep_nums.size(); i++ )
243 std::cerr << tstep_nums[i];
244 std::cerr << std::endl;
247 if( !tstep_vals.empty() )
249 std::cerr <<
"Time vals requested: ";
250 for(
unsigned int i = 0; i < tstep_vals.size(); i++ )
251 std::cerr << tstep_vals[i];
252 std::cerr << std::endl;
259 MB_SET_ERR( rval,
"Invalid value for GATHER_SET option" );
265 MB_SET_ERR( rval,
"Invalid value for TIMESTEPBASE option" );
271 MB_SET_ERR( rval,
"Invalid value for TRIVIAL_PARTITION_SHIFT option" );
287 MB_SET_ERR( rval,
"Invalid value for PARALLEL_COMM option" );
294 const int rank = myPcomm->proc_config().proc_rank();
299 if( MB_FAILURE == rval )
301 MB_SET_ERR( rval,
"Unknown partition method specified" );
320 if( success )
MB_SET_ERR( MB_FAILURE,
"Couldn't get number of global attributes" );
341 for(
int i = 0; i < num_atts; i++ )
344 int success =
NCFUNC( inq_attname )(
fileId, var_id, i, dum_name );
345 if( success )
MB_SET_ERR( MB_FAILURE,
"Trouble getting attribute name" );
347 AttData& data = atts[std::string( dum_name )];
348 data.
attName = std::string( dum_name );
350 if( success )
MB_SET_ERR( MB_FAILURE,
"Trouble getting info for attribute " << data.
attName );
353 dbgOut.
tprintf( 2,
"%sAttribute %s: length=%u, varId=%d, type=%d\n", ( prefix ? prefix :
"" ),
364 int success =
NCFUNC( inq_ndims )( file_id, &num_dims );
365 if( success )
MB_SET_ERR( MB_FAILURE,
"Trouble getting number of dimensions" );
367 if( num_dims > NC_MAX_DIMS )
370 "ReadNC: File contains " << num_dims <<
" dims but NetCDF library supports only " << NC_MAX_DIMS );
373 char dim_name[NC_MAX_NAME + 1];
375 dim_names.resize( num_dims );
376 dim_lens.resize( num_dims );
378 for(
int i = 0; i < num_dims; i++ )
380 success =
NCFUNC( inq_dim )( file_id, i, dim_name, &dim_len );
381 if( success )
MB_SET_ERR( MB_FAILURE,
"Trouble getting dimension info" );
383 dim_names[i] = std::string( dim_name );
384 dim_lens[i] = dim_len;
386 dbgOut.
tprintf( 2,
"Dimension %s, length=%u\n", dim_name, (
unsigned int)dim_len );
395 std::vector< std::string >::iterator vit = std::find(
dimNames.begin(),
dimNames.end(),
"time" );
400 if( !ntimes ) ntimes = 1;
405 if( success )
MB_SET_ERR( MB_FAILURE,
"Trouble getting number of variables" );
407 if( num_vars > NC_MAX_VARS )
410 "ReadNC: File contains " << num_vars <<
" vars but NetCDF library supports only " << NC_MAX_VARS );
413 char var_name[NC_MAX_NAME + 1];
416 for(
int i = 0; i < num_vars; i++ )
420 if( success )
MB_SET_ERR( MB_FAILURE,
"Trouble getting variable name" );
422 data.
varName = std::string( var_name );
424 data.
varTags.resize( ntimes, 0 );
428 if( success )
MB_SET_ERR( MB_FAILURE,
"Trouble getting data type for variable " << data.
varName );
431 success =
NCFUNC( inq_varndims )(
fileId, i, &var_ndims );
432 if( success )
MB_SET_ERR( MB_FAILURE,
"Trouble getting number of dims for variable " << data.
varName );
433 data.
varDims.resize( var_ndims );
436 if( success )
MB_SET_ERR( MB_FAILURE,
"Trouble getting dimensions for variable " << data.
varName );
440 if( success )
MB_SET_ERR( MB_FAILURE,
"Trouble getting number of dims for variable " << data.
varName );
443 dbgOut.
tprintf( 2,
"Variable %s: Id=%d, numAtts=%d, datatype=%d, num_dims=%u\n", data.
varName.c_str(),