Loading [MathJax]/extensions/tex2jax.js
Mesh Oriented datABase  (version 5.5.1)
An array-based unstructured mesh library
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
netcdfcpp_par.hpp
Go to the documentation of this file.
1 //------------------------------------------------------------------------- 2 // Filename : netcdfcpp_par.hpp 3 // 4 // Purpose : Parallel C++ Climate NC file read/write 5 // 6 // Creator : Vijay Mahadevan 7 //------------------------------------------------------------------------- 8  9 #if defined( MOAB_HAVE_NETCDFPAR ) && defined( MOAB_HAVE_TEMPESTREMAP ) 10 #include "netcdf_par.h" 11 #include "netcdfcpp.h" 12  13 class ParNcFile : public NcFile 14 { 15  public: 16  ParNcFile( MPI_Comm comm, 17  MPI_Info comm_info, 18  const char* path, 19  FileMode fmode = ReadOnly, 20  FileFormat fformat = Classic ) 21  : NcFile(), m_comm( comm ) 22  { 23  NcError err( NcError::silent_nonfatal ); // constructor must not fail 24  25  int mode = NC_NOWRITE; 26  the_fill_mode = Fill; 27  int status; 28  29  // If the user wants a 64-bit offset format, set that flag. 30  if( fformat == Offset64Bits ) mode |= NC_64BIT_OFFSET; 31 #ifndef NETCDF3_ONLY 32  else if( fformat == Netcdf4 ) 33  mode |= NC_NETCDF4; 34  else if( fformat == Netcdf4Classic ) 35  mode |= NC_NETCDF4 | NC_CLASSIC_MODEL; 36 #endif 37  mode |= NC_MPIIO; 38  39  switch( fmode ) 40  { 41  case Write: 42  mode |= NC_WRITE; 43  /*FALLTHRU*/ 44  case ReadOnly: 45  // use netcdf-3 interface to permit specifying tuning parameter 46  status = NcError::set_err( nc_open_par( path, mode, comm, comm_info, &the_id ) ); 47  if( status != NC_NOERR ) 48  { 49  NcError::set_err( status ); 50  the_id = -1; 51  } 52  in_define_mode = 0; 53  break; 54  case New: 55  mode |= NC_NOCLOBBER; 56  /*FALLTHRU*/ 57  case Replace: 58  // use netcdf-3 interface to permit specifying tuning parameters 59  status = NcError::set_err( nc_create_par( path, mode, comm, comm_info, &the_id ) ); 60  if( status != NC_NOERR ) 61  { 62  NcError::set_err( status ); 63  the_id = -1; 64  } 65  in_define_mode = 1; 66  break; 67  default: 68  the_id = ncBad; 69  in_define_mode = 0; 70  break; 71  } 72  if( is_valid() ) 73  { 74  dimensions = new NcDim*[NC_MAX_DIMS]; 75  variables = new NcVar*[NC_MAX_VARS]; 76  int i; 77  for( i = 0; i < num_dims(); i++ ) 78  dimensions[i] = new NcDim( this, i ); 79  for( i = 0; i < num_vars(); i++ ) 80  variables[i] = new NcVar( this, i ); 81  globalv = new NcVar( this, ncGlobal ); 82  } 83  else 84  { 85  dimensions = 0; 86  variables = 0; 87  globalv = 0; 88  } 89  } 90  91  virtual ~ParNcFile( void ){}; 92  93  NcBool enable_var_par_access( NcVar* var, bool is_independent = true ) // synchronize to disk 94  { 95  int status; 96  status = NcError::set_err( 97  nc_var_par_access( the_id, var->id(), ( is_independent ? NC_INDEPENDENT : NC_COLLECTIVE ) ) ); 98  if( status != NC_NOERR ) 99  { 100  NcError::set_err( status ); 101  return 0; 102  } 103  return 1; 104  } 105  106  protected: 107  MPI_Comm m_comm; 108  static const int ncGlobal = NC_GLOBAL; // psuedo-variable for global attributes 109  static const int ncBad = -1; // failure return for netCDF C interface 110 }; 111  112 #endif // #if defined(MOAB_HAVE_NETCDFPAR) && defined(MOAB_HAVE_TEMPESTREMAP)