Go to the documentation of this file. 1
2
3
4
5
6
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 );
24
25 int mode = NC_NOWRITE;
26 the_fill_mode = Fill;
27 int status;
28
29
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
44 case ReadOnly:
45
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
57 case Replace:
58
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 )
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;
109 static const int ncBad = -1;
110 };
111
112 #endif