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;
70 int rank = myPcomm->proc_config().proc_rank();
72 MPI_Bcast( &fileFormat, 1, MPI_INT, 0, myPcomm->proc_config().proc_comm() );
81 const int mpi_size =
isParallel ? myPcomm->proc_config().proc_size() : 1;
83 const int mpi_size = 1;
89 const char* fmtName = ( fileFormat ==
NCFMT_CLASSIC ) ?
"classic CDF-1/2/5"
91 :
"unrecognized / non-NetCDF";
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." );
107 success = mbnc_open_par( backend, myPcomm->proc_config().proc_comm(), MPI_INFO_NULL, file_name, 0, &
fileId );
112 if( success )
MB_SET_ERR( MB_FAILURE,
"Trouble opening file " << file_name );
121 MB_SET_ERR( MB_FAILURE,
"NOMESH option requires non-NULL file set on input" );
123 else if( !file_set || ( file_set && *file_set == 0 ) )
133 if(
nullptr ==
scdi )
return MB_FAILURE;
141 MB_SET_ERR( MB_FAILURE,
"Failed to get NCHelper class instance" );
157 Tag convTagsCreated = 0;
161 "Trouble getting _CONV_TAGS_CREATED tag" );
162 int create_conv_tags_flag = 0;
164 "failed to get conventional tags" );
166 if( 0 == create_conv_tags_flag )
175 create_conv_tags_flag = 1;
177 "Trouble setting data to _CONV_TAGS_CREATED tag" );
199 if( var_names.empty() )
207 std::vector< std::string > non_dim_var_names;
208 for(
unsigned int i = 0; i < var_names.size(); i++ )
211 non_dim_var_names.push_back( var_names[i] );
214 if( !non_dim_var_names.empty() )
217 "Trouble reading specified variables" );
227 Tag part_tag = myPcomm->partition_tag();
228 int dum_rank = myPcomm->proc_config().proc_rank();
231 "Trouble writing partition tag name on partition set" );
240 if( success )
MB_SET_ERR( MB_FAILURE,
"Trouble closing file" );
246 std::vector< std::string >& var_names,
247 std::vector< int >& tstep_nums,
248 std::vector< double >& tstep_vals )
286 if( !var_names.empty() )
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;
294 if( !tstep_nums.empty() )
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;
302 if( !tstep_vals.empty() )
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;
314 MB_SET_ERR( rval,
"Invalid value for GATHER_SET option" );
320 MB_SET_ERR( rval,
"Invalid value for TIMESTEPBASE option" );
326 MB_SET_ERR( rval,
"Invalid value for TRIVIAL_PARTITION_SHIFT option" );
342 MB_SET_ERR( rval,
"Invalid value for PARALLEL_COMM option" );
349 const int rank = myPcomm->proc_config().proc_rank();
354 if( MB_FAILURE == rval )
356 MB_SET_ERR( rval,
"Unknown partition method specified" );
375 if( success )
MB_SET_ERR( MB_FAILURE,
"Couldn't get number of global attributes" );
399 for(
int i = 0; i < num_atts; i++ )
402 int success =
NCFUNC( inq_attname )(
fileId, var_id, i, dum_name );
403 if( success )
MB_SET_ERR( MB_FAILURE,
"Trouble getting attribute name" );
405 AttData& data = atts[std::string( dum_name )];
406 data.
attName = std::string( dum_name );
408 if( success )
MB_SET_ERR( MB_FAILURE,
"Trouble getting info for attribute " << data.
attName );
411 dbgOut.
tprintf( 2,
"%sAttribute %s: length=%u, varId=%d, type=%d\n", ( prefix ? prefix :
"" ),
422 int success =
NCFUNC( inq_ndims )( file_id, &num_dims );
423 if( success )
MB_SET_ERR( MB_FAILURE,
"Trouble getting number of dimensions" );
425 if( num_dims > NC_MAX_DIMS )
428 "ReadNC: File contains " << num_dims <<
" dims but NetCDF library supports only " << NC_MAX_DIMS );
431 char dim_name[NC_MAX_NAME + 1];
433 dim_names.resize( num_dims );
434 dim_lens.resize( num_dims );
436 for(
int i = 0; i < num_dims; i++ )
438 success =
NCFUNC( inq_dim )( file_id, i, dim_name, &dim_len );
439 if( success )
MB_SET_ERR( MB_FAILURE,
"Trouble getting dimension info" );
441 dim_names[i] = std::string( dim_name );
442 dim_lens[i] = dim_len;
444 dbgOut.
tprintf( 2,
"Dimension %s, length=%u\n", dim_name, (
unsigned int)dim_len );
453 std::vector< std::string >::iterator vit = std::find(
dimNames.begin(),
dimNames.end(),
"time" );
458 if( !ntimes ) ntimes = 1;
463 if( success )
MB_SET_ERR( MB_FAILURE,
"Trouble getting number of variables" );
465 if( num_vars > NC_MAX_VARS )
468 "ReadNC: File contains " << num_vars <<
" vars but NetCDF library supports only " << NC_MAX_VARS );
471 char var_name[NC_MAX_NAME + 1];
474 for(
int i = 0; i < num_vars; i++ )
478 if( success )
MB_SET_ERR( MB_FAILURE,
"Trouble getting variable name" );
480 data.
varName = std::string( var_name );
482 data.
varTags.resize( ntimes, 0 );
486 if( success )
MB_SET_ERR( MB_FAILURE,
"Trouble getting data type for variable " << data.
varName );
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 );
494 if( success )
MB_SET_ERR( MB_FAILURE,
"Trouble getting dimensions for variable " << data.
varName );
498 if( success )
MB_SET_ERR( MB_FAILURE,
"Trouble getting number of dims for variable " << data.
varName );
501 dbgOut.
tprintf( 2,
"Variable %s: Id=%d, numAtts=%d, datatype=%d, num_dims=%u\n", data.
varName.c_str(),
505 "Trouble getting attributes for variable " << data.
varName );