MOAB: Mesh Oriented datABase  (version 5.2.1)
netcdfcpp_par.hpp
Go to the documentation of this file.
00001 //-------------------------------------------------------------------------
00002 // Filename      : netcdfcpp_par.hpp
00003 //
00004 // Purpose       : Parallel C++ Climate NC file read/write
00005 //
00006 // Creator       : Vijay Mahadevan
00007 //-------------------------------------------------------------------------
00008 
00009 #if defined( MOAB_HAVE_NETCDFPAR ) && defined( MOAB_HAVE_TEMPESTREMAP )
00010 #include "netcdf_par.h"
00011 #include "netcdfcpp.h"
00012 
00013 class ParNcFile : public NcFile
00014 {
00015   public:
00016     ParNcFile( MPI_Comm comm, MPI_Info comm_info, const char* path, FileMode fmode = ReadOnly,
00017                FileFormat fformat = Classic )
00018         : NcFile(), m_comm( comm )
00019     {
00020         NcError err( NcError::verbose_nonfatal );  // constructor must not fail
00021 
00022         int mode      = NC_NOWRITE;
00023         the_fill_mode = Fill;
00024         int status;
00025 
00026         // If the user wants a 64-bit offset format, set that flag.
00027         if( fformat == Offset64Bits ) mode |= NC_64BIT_OFFSET;
00028 #ifndef NETCDF3_ONLY
00029         else if( fformat == Netcdf4 )
00030             mode |= NC_NETCDF4;
00031         else if( fformat == Netcdf4Classic )
00032             mode |= NC_NETCDF4 | NC_CLASSIC_MODEL;
00033 #endif
00034         mode |= NC_MPIIO;
00035 
00036         switch( fmode )
00037         {
00038             case Write:
00039                 mode |= NC_WRITE;
00040             /*FALLTHRU*/
00041             case ReadOnly:
00042                 // use netcdf-3 interface to permit specifying tuning parameter
00043                 status = NcError::set_err( nc_open_par( path, mode, comm, comm_info, &the_id ) );
00044                 if( status != NC_NOERR )
00045                 {
00046                     NcError::set_err( status );
00047                     the_id = -1;
00048                 }
00049                 in_define_mode = 0;
00050                 break;
00051             case New:
00052                 mode |= NC_NOCLOBBER;
00053             /*FALLTHRU*/
00054             case Replace:
00055                 // use netcdf-3 interface to permit specifying tuning parameters
00056                 status = NcError::set_err( nc_create_par( path, mode, comm, comm_info, &the_id ) );
00057                 if( status != NC_NOERR )
00058                 {
00059                     NcError::set_err( status );
00060                     the_id = -1;
00061                 }
00062                 in_define_mode = 1;
00063                 break;
00064             default:
00065                 the_id         = ncBad;
00066                 in_define_mode = 0;
00067                 break;
00068         }
00069         if( is_valid() )
00070         {
00071             dimensions = new NcDim*[NC_MAX_DIMS];
00072             variables  = new NcVar*[NC_MAX_VARS];
00073             int i;
00074             for( i = 0; i < num_dims(); i++ )
00075                 dimensions[i] = new NcDim( this, i );
00076             for( i = 0; i < num_vars(); i++ )
00077                 variables[i] = new NcVar( this, i );
00078             globalv = new NcVar( this, ncGlobal );
00079         }
00080         else
00081         {
00082             dimensions = 0;
00083             variables  = 0;
00084             globalv    = 0;
00085         }
00086     }
00087 
00088     virtual ~ParNcFile( void ){};
00089 
00090     NcBool enable_var_par_access( NcVar* var, bool is_independent = true )  // synchronize to disk
00091     {
00092         int status;
00093         status = NcError::set_err(
00094             nc_var_par_access( the_id, var->id(), ( is_independent ? NC_INDEPENDENT : NC_COLLECTIVE ) ) );
00095         if( status != NC_NOERR )
00096         {
00097             NcError::set_err( status );
00098             return 0;
00099         }
00100         return 1;
00101     }
00102 
00103   protected:
00104     MPI_Comm m_comm;
00105     static const int ncGlobal = NC_GLOBAL;  // psuedo-variable for global attributes
00106     static const int ncBad    = -1;         // failure return for netCDF C interface
00107 };
00108 
00109 #endif  // #if defined(MOAB_HAVE_NETCDFPAR) && defined(MOAB_HAVE_TEMPESTREMAP)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines