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