MOAB: Mesh Oriented datABase  (version 5.2.1)
write_nc.cpp
Go to the documentation of this file.
00001 #include "TestUtil.hpp"
00002 #include "moab/Core.hpp"
00003 
00004 using namespace moab;
00005 
00006 std::string example_eul    = TestDir + "/io/eul3x48x96.t.3.nc";
00007 std::string example_eul_t0 = TestDir + "/io/eul3x48x96.t0.nc";
00008 std::string example_eul_t1 = TestDir + "/io/eul3x48x96.t1.nc";
00009 std::string example_eul_t2 = TestDir + "/io/eul3x48x96.t2.nc";
00010 std::string example_fv     = TestDir + "/io/fv3x46x72.t.3.nc";
00011 std::string example_homme  = TestDir + "/io/homme3x3458.t.3.nc";
00012 std::string example_mpas   = TestDir + "/io/mpasx1.642.t.2.nc";
00013 std::string example_gcrm   = TestDir + "/io/gcrm_r3.nc";
00014 
00015 #ifdef MOAB_HAVE_MPI
00016 #include "moab_mpi.h"
00017 #include "moab/ParallelComm.hpp"
00018 #endif
00019 
00020 #ifdef MOAB_HAVE_PNETCDF
00021 #include "pnetcdf.h"
00022 #define NCFUNC( func ) ncmpi_##func
00023 #define NCDF_SIZE      MPI_Offset
00024 #else
00025 #include "netcdf.h"
00026 #define NCFUNC( func ) nc_##func
00027 #define NCDF_SIZE      size_t
00028 #endif
00029 
00030 // CAM-EUL
00031 void test_eul_read_write_T();
00032 void test_eul_check_T();
00033 
00034 // CAM-FV
00035 void test_fv_read_write_T();
00036 void test_fv_check_T();
00037 
00038 // CAM-SE (HOMME)
00039 void test_homme_read_write_T();
00040 void test_homme_check_T();
00041 
00042 // MPAS
00043 void test_mpas_read_write_vars();
00044 void test_mpas_check_vars();
00045 
00046 // GCRM
00047 void test_gcrm_read_write_vars();
00048 void test_gcrm_check_vars();
00049 
00050 // Test timestep option
00051 void test_eul_read_write_timestep();
00052 void test_eul_check_timestep();
00053 
00054 // Test append option
00055 void test_eul_read_write_append();
00056 void test_eul_check_append();
00057 
00058 // Test writing variables with timesteps spread across files
00059 void test_eul_read_write_across_files();
00060 void test_eul_check_across_files();
00061 
00062 #ifdef MOAB_HAVE_MPI
00063 // Test mesh with ghosted entities
00064 void test_eul_read_write_ghosting();
00065 void test_eul_check_ghosting();
00066 #endif
00067 
00068 void get_eul_read_options( std::string& opts );
00069 void get_fv_read_options( std::string& opts );
00070 void get_homme_read_options( std::string& opts );
00071 void get_mpas_read_options( std::string& opts );
00072 
00073 const double eps      = 1e-10;
00074 const int levels      = 3;
00075 const int mpas_levels = 1;
00076 
00077 int main( int argc, char* argv[] )
00078 {
00079     int result = 0;
00080 
00081 #ifdef MOAB_HAVE_MPI
00082     int fail = MPI_Init( &argc, &argv );
00083     if( fail ) return 1;
00084 #else
00085     argv[0] = argv[argc - argc];  // To remove the warnings in serial mode about unused variables
00086 #endif
00087 
00088     result += RUN_TEST( test_eul_read_write_T );
00089     result += RUN_TEST( test_eul_check_T );
00090 
00091     result += RUN_TEST( test_fv_read_write_T );
00092     result += RUN_TEST( test_fv_check_T );
00093 
00094     result += RUN_TEST( test_homme_read_write_T );
00095     result += RUN_TEST( test_homme_check_T );
00096 
00097     result += RUN_TEST( test_mpas_read_write_vars );
00098     result += RUN_TEST( test_mpas_check_vars );
00099 
00100     result += RUN_TEST( test_gcrm_read_write_vars );
00101     result += RUN_TEST( test_gcrm_check_vars );
00102 
00103     result += RUN_TEST( test_eul_read_write_timestep );
00104     result += RUN_TEST( test_eul_check_timestep );
00105 
00106     result += RUN_TEST( test_eul_read_write_append );
00107     result += RUN_TEST( test_eul_check_append );
00108 
00109     result += RUN_TEST( test_eul_read_write_across_files );
00110     result += RUN_TEST( test_eul_check_across_files );
00111 
00112 #ifdef MOAB_HAVE_MPI
00113     result += RUN_TEST( test_eul_read_write_ghosting );
00114     result += RUN_TEST( test_eul_check_ghosting );
00115 #endif
00116 
00117 #ifdef MOAB_HAVE_MPI
00118     fail = MPI_Finalize();
00119     if( fail ) return 1;
00120 #endif
00121 
00122     return result;
00123 }
00124 
00125 // We also read and write gw (test writing a set variable without timesteps)
00126 void test_eul_read_write_T()
00127 {
00128     int procs = 1;
00129 #ifdef MOAB_HAVE_MPI
00130     MPI_Comm_size( MPI_COMM_WORLD, &procs );
00131 #endif
00132 
00133 // We will not test NC writer in parallel without pnetcdf support
00134 #ifndef MOAB_HAVE_PNETCDF
00135     if( procs > 1 ) return;
00136 #endif
00137 
00138     Core moab;
00139     Interface& mb = moab;
00140 
00141     std::string read_opts;
00142     get_eul_read_options( read_opts );
00143 
00144     EntityHandle set;
00145     ErrorCode rval = mb.create_meshset( MESHSET_SET, set );CHECK_ERR( rval );
00146 
00147     // Read non-set variable T and set variable gw
00148     read_opts += ";VARIABLE=T,gw;DEBUG_IO=0";
00149     rval = mb.load_file( example_eul.c_str(), &set, read_opts.c_str() );CHECK_ERR( rval );
00150 
00151     // Write variables T and gw
00152     std::string write_opts = ";;VARIABLE=T,gw;DEBUG_IO=0";
00153 #ifdef MOAB_HAVE_MPI
00154     // Use parallel options
00155     write_opts += ";PARALLEL=WRITE_PART";
00156 #endif
00157     if( procs > 1 )
00158         rval = mb.write_file( "test_par_eul_T.nc", 0, write_opts.c_str(), &set, 1 );
00159     else
00160         rval = mb.write_file( "test_eul_T.nc", 0, write_opts.c_str(), &set, 1 );CHECK_ERR( rval );
00161 }
00162 
00163 // Check non-set variable T
00164 // Also check set variable gw
00165 void test_eul_check_T()
00166 {
00167     int rank  = 0;
00168     int procs = 1;
00169 #ifdef MOAB_HAVE_MPI
00170     MPI_Comm_rank( MPI_COMM_WORLD, &rank );
00171     MPI_Comm_size( MPI_COMM_WORLD, &procs );
00172 #endif
00173 
00174 // We will not test NC writer in parallel without pnetcdf support
00175 #ifndef MOAB_HAVE_PNETCDF
00176     if( procs > 1 ) return;
00177 #endif
00178 
00179     if( 0 == rank )
00180     {
00181         int ncid;
00182         int ncid_ref;
00183         int success;
00184 
00185         std::string filename;
00186         if( procs > 1 )
00187             filename = "test_par_eul_T.nc";
00188         else
00189             filename = "test_eul_T.nc";
00190 
00191 #ifdef MOAB_HAVE_PNETCDF
00192         success = NCFUNC( open )( MPI_COMM_SELF, filename.c_str(), NC_NOWRITE, MPI_INFO_NULL, &ncid );
00193 #else
00194         success = NCFUNC( open )( filename.c_str(), NC_NOWRITE, &ncid );
00195 #endif
00196         CHECK_EQUAL( 0, success );
00197 
00198 #ifdef MOAB_HAVE_PNETCDF
00199         success = NCFUNC( open )( MPI_COMM_SELF, example_eul.c_str(), NC_NOWRITE, MPI_INFO_NULL, &ncid_ref );
00200 #else
00201         success = NCFUNC( open )( example_eul.c_str(), NC_NOWRITE, &ncid_ref );
00202 #endif
00203         CHECK_EQUAL( 0, success );
00204 
00205         int T_id;
00206         success = NCFUNC( inq_varid )( ncid, "T", &T_id );
00207         CHECK_EQUAL( 0, success );
00208 
00209         int T_id_ref;
00210         success = NCFUNC( inq_varid )( ncid_ref, "T", &T_id_ref );
00211         CHECK_EQUAL( 0, success );
00212 
00213         int gw_id;
00214         success = NCFUNC( inq_varid )( ncid, "gw", &gw_id );
00215         CHECK_EQUAL( 0, success );
00216 
00217         int gw_id_ref;
00218         success = NCFUNC( inq_varid )( ncid_ref, "gw", &gw_id_ref );
00219         CHECK_EQUAL( 0, success );
00220 
00221 #ifdef MOAB_HAVE_PNETCDF
00222         // Enter independent I/O mode
00223         success = NCFUNC( begin_indep_data )( ncid );
00224         CHECK_EQUAL( 0, success );
00225 #endif
00226 
00227 #ifdef MOAB_HAVE_PNETCDF
00228         // Enter independent I/O mode
00229         success = NCFUNC( begin_indep_data )( ncid_ref );
00230         CHECK_EQUAL( 0, success );
00231 #endif
00232 
00233         NCDF_SIZE start[] = { 0, 0, 0, 0 };
00234         NCDF_SIZE count[] = { 3, levels, 48, 96 };
00235         const int size    = 3 * levels * 48 * 96;
00236 
00237         // Read variable T from output file
00238         double T_vals[size];
00239         success = NCFUNC( get_vara_double )( ncid, T_id, start, count, T_vals );
00240         CHECK_EQUAL( 0, success );
00241 
00242         // Read variable T from reference file
00243         double T_vals_ref[size];
00244         success = NCFUNC( get_vara_double )( ncid_ref, T_id_ref, start, count, T_vals_ref );
00245         CHECK_EQUAL( 0, success );
00246 
00247         // Read variable gw (on lat) from output file
00248         count[0] = 48;
00249         double gw_vals[48];
00250         success = NCFUNC( get_vara_double )( ncid, gw_id, start, count, gw_vals );
00251         CHECK_EQUAL( 0, success );
00252 
00253         // Read variable gw (on lat) from reference file
00254         double gw_vals_ref[48];
00255         success = NCFUNC( get_vara_double )( ncid_ref, gw_id_ref, start, count, gw_vals_ref );
00256         CHECK_EQUAL( 0, success );
00257 
00258 #ifdef MOAB_HAVE_PNETCDF
00259         // End independent I/O mode
00260         success = NCFUNC( end_indep_data )( ncid );
00261         CHECK_EQUAL( 0, success );
00262 #endif
00263 
00264 #ifdef MOAB_HAVE_PNETCDF
00265         // End independent I/O mode
00266         success = NCFUNC( end_indep_data )( ncid_ref );
00267         CHECK_EQUAL( 0, success );
00268 #endif
00269 
00270         success = NCFUNC( close )( ncid );
00271         CHECK_EQUAL( 0, success );
00272 
00273         success = NCFUNC( close )( ncid_ref );
00274         CHECK_EQUAL( 0, success );
00275 
00276         // Check T values
00277         for( int i = 0; i < size; i++ )
00278             CHECK_REAL_EQUAL( T_vals_ref[i], T_vals[i], eps );
00279 
00280         // Check gw values
00281         for( int i = 0; i < 48; i++ )
00282             CHECK_REAL_EQUAL( gw_vals_ref[i], gw_vals[i], eps );
00283     }
00284 }
00285 
00286 void test_fv_read_write_T()
00287 {
00288     int procs = 1;
00289 #ifdef MOAB_HAVE_MPI
00290     MPI_Comm_size( MPI_COMM_WORLD, &procs );
00291 #endif
00292 
00293 // We will not test NC writer in parallel without pnetcdf support
00294 #ifndef MOAB_HAVE_PNETCDF
00295     if( procs > 1 ) return;
00296 #endif
00297 
00298     Core moab;
00299     Interface& mb = moab;
00300 
00301     std::string read_opts;
00302     get_fv_read_options( read_opts );
00303 
00304     EntityHandle set;
00305     ErrorCode rval = mb.create_meshset( MESHSET_SET, set );CHECK_ERR( rval );
00306 
00307     // Read non-set variable T
00308     read_opts += ";VARIABLE=T;DEBUG_IO=0";
00309     rval = mb.load_file( example_fv.c_str(), &set, read_opts.c_str() );CHECK_ERR( rval );
00310 
00311     // Write variable T
00312     std::string write_opts = ";;VARIABLE=T;DEBUG_IO=0";
00313 #ifdef MOAB_HAVE_MPI
00314     // Use parallel options
00315     write_opts += ";PARALLEL=WRITE_PART";
00316 #endif
00317     if( procs > 1 )
00318         rval = mb.write_file( "test_par_fv_T.nc", 0, write_opts.c_str(), &set, 1 );
00319     else
00320         rval = mb.write_file( "test_fv_T.nc", 0, write_opts.c_str(), &set, 1 );CHECK_ERR( rval );
00321 }
00322 
00323 // Check non-set variable T
00324 void test_fv_check_T()
00325 {
00326     int rank  = 0;
00327     int procs = 1;
00328 #ifdef MOAB_HAVE_MPI
00329     MPI_Comm_rank( MPI_COMM_WORLD, &rank );
00330     MPI_Comm_size( MPI_COMM_WORLD, &procs );
00331 #endif
00332 
00333 // We will not test NC writer in parallel without pnetcdf support
00334 #ifndef MOAB_HAVE_PNETCDF
00335     if( procs > 1 ) return;
00336 #endif
00337 
00338     if( 0 == rank )
00339     {
00340         int ncid;
00341         int ncid_ref;
00342         int success;
00343 
00344         std::string filename;
00345         if( procs > 1 )
00346             filename = "test_par_fv_T.nc";
00347         else
00348             filename = "test_fv_T.nc";
00349 
00350 #ifdef MOAB_HAVE_PNETCDF
00351         success = NCFUNC( open )( MPI_COMM_SELF, filename.c_str(), NC_NOWRITE, MPI_INFO_NULL, &ncid );
00352 #else
00353         success = NCFUNC( open )( filename.c_str(), NC_NOWRITE, &ncid );
00354 #endif
00355         CHECK_EQUAL( 0, success );
00356 
00357 #ifdef MOAB_HAVE_PNETCDF
00358         success = NCFUNC( open )( MPI_COMM_SELF, example_fv.c_str(), NC_NOWRITE, MPI_INFO_NULL, &ncid_ref );
00359 #else
00360         success = NCFUNC( open )( example_fv.c_str(), NC_NOWRITE, &ncid_ref );
00361 #endif
00362         CHECK_EQUAL( 0, success );
00363 
00364         int T_id;
00365         success = NCFUNC( inq_varid )( ncid, "T", &T_id );
00366         CHECK_EQUAL( 0, success );
00367 
00368         int T_id_ref;
00369         success = NCFUNC( inq_varid )( ncid_ref, "T", &T_id_ref );
00370         CHECK_EQUAL( 0, success );
00371 
00372 #ifdef MOAB_HAVE_PNETCDF
00373         // Enter independent I/O mode
00374         success = NCFUNC( begin_indep_data )( ncid );
00375         CHECK_EQUAL( 0, success );
00376 #endif
00377 
00378 #ifdef MOAB_HAVE_PNETCDF
00379         // Enter independent I/O mode
00380         success = NCFUNC( begin_indep_data )( ncid_ref );
00381         CHECK_EQUAL( 0, success );
00382 #endif
00383 
00384         NCDF_SIZE start[] = { 0, 0, 0, 0 };
00385         NCDF_SIZE count[] = { 3, levels, 46, 72 };
00386         const int size    = 3 * levels * 46 * 72;
00387 
00388         // Read variable T from output file
00389         double T_vals[size];
00390         success = NCFUNC( get_vara_double )( ncid, T_id, start, count, T_vals );
00391         CHECK_EQUAL( 0, success );
00392 
00393         // Read variable T from reference file
00394         double T_vals_ref[size];
00395         success = NCFUNC( get_vara_double )( ncid_ref, T_id_ref, start, count, T_vals_ref );
00396         CHECK_EQUAL( 0, success );
00397 
00398 #ifdef MOAB_HAVE_PNETCDF
00399         // End independent I/O mode
00400         success = NCFUNC( end_indep_data )( ncid );
00401         CHECK_EQUAL( 0, success );
00402 #endif
00403 
00404 #ifdef MOAB_HAVE_PNETCDF
00405         // End independent I/O mode
00406         success = NCFUNC( end_indep_data )( ncid_ref );
00407         CHECK_EQUAL( 0, success );
00408 #endif
00409 
00410         success = NCFUNC( close )( ncid );
00411         CHECK_EQUAL( 0, success );
00412 
00413         success = NCFUNC( close )( ncid_ref );
00414         CHECK_EQUAL( 0, success );
00415 
00416         // Check T values
00417         for( int i = 0; i < size; i++ )
00418             CHECK_REAL_EQUAL( T_vals_ref[i], T_vals[i], eps );
00419     }
00420 }
00421 
00422 // We also read and write lat (test writing a set variable without timesteps)
00423 void test_homme_read_write_T()
00424 {
00425     int procs = 1;
00426 #ifdef MOAB_HAVE_MPI
00427     MPI_Comm_size( MPI_COMM_WORLD, &procs );
00428 #endif
00429 
00430 // We will not test NC writer in parallel without pnetcdf support
00431 #ifndef MOAB_HAVE_PNETCDF
00432     if( procs > 1 ) return;
00433 #endif
00434 
00435     Core moab;
00436     Interface& mb = moab;
00437 
00438     std::string read_opts;
00439     get_homme_read_options( read_opts );
00440 
00441     EntityHandle set;
00442     ErrorCode rval = mb.create_meshset( MESHSET_SET, set );CHECK_ERR( rval );
00443 
00444     // Read non-set variable T and set variable lat
00445     read_opts += ";VARIABLE=T,lat;DEBUG_IO=0";
00446     if( procs > 1 )
00447     {
00448         // Rotate trivial partition, otherwise localGidVertsOwned.psize() is always 1
00449         read_opts += ";PARALLEL_RESOLVE_SHARED_ENTS;TRIVIAL_PARTITION_SHIFT=1";
00450     }
00451     rval = mb.load_file( example_homme.c_str(), &set, read_opts.c_str() );CHECK_ERR( rval );
00452 
00453     // Write variables T and lat
00454     std::string write_opts = ";;VARIABLE=T,lat;DEBUG_IO=0";
00455 #ifdef MOAB_HAVE_MPI
00456     // Use parallel options
00457     write_opts += ";PARALLEL=WRITE_PART";
00458 #endif
00459     if( procs > 1 )
00460         rval = mb.write_file( "test_par_homme_T.nc", 0, write_opts.c_str(), &set, 1 );
00461     else
00462         rval = mb.write_file( "test_homme_T.nc", 0, write_opts.c_str(), &set, 1 );CHECK_ERR( rval );
00463 }
00464 
00465 // Check non-set variable T
00466 // Also check set variable lat
00467 void test_homme_check_T()
00468 {
00469     int rank  = 0;
00470     int procs = 1;
00471 #ifdef MOAB_HAVE_MPI
00472     MPI_Comm_rank( MPI_COMM_WORLD, &rank );
00473     MPI_Comm_size( MPI_COMM_WORLD, &procs );
00474 #endif
00475 
00476 // We will not test NC writer in parallel without pnetcdf support
00477 #ifndef MOAB_HAVE_PNETCDF
00478     if( procs > 1 ) return;
00479 #endif
00480 
00481     if( 0 == rank )
00482     {
00483         int ncid;
00484         int ncid_ref;
00485         int success;
00486 
00487         std::string filename;
00488         if( procs > 1 )
00489             filename = "test_par_homme_T.nc";
00490         else
00491             filename = "test_homme_T.nc";
00492 
00493 #ifdef MOAB_HAVE_PNETCDF
00494         success = NCFUNC( open )( MPI_COMM_SELF, filename.c_str(), NC_NOWRITE, MPI_INFO_NULL, &ncid );
00495 #else
00496         success = NCFUNC( open )( filename.c_str(), NC_NOWRITE, &ncid );
00497 #endif
00498         CHECK_EQUAL( 0, success );
00499 
00500 #ifdef MOAB_HAVE_PNETCDF
00501         success = NCFUNC( open )( MPI_COMM_SELF, example_homme.c_str(), NC_NOWRITE, MPI_INFO_NULL, &ncid_ref );
00502 #else
00503         success = NCFUNC( open )( example_homme.c_str(), NC_NOWRITE, &ncid_ref );
00504 #endif
00505         CHECK_EQUAL( 0, success );
00506 
00507         int T_id;
00508         success = NCFUNC( inq_varid )( ncid, "T", &T_id );
00509         CHECK_EQUAL( 0, success );
00510 
00511         int T_id_ref;
00512         success = NCFUNC( inq_varid )( ncid_ref, "T", &T_id_ref );
00513         CHECK_EQUAL( 0, success );
00514 
00515         int lat_id;
00516         success = NCFUNC( inq_varid )( ncid, "lat", &lat_id );
00517         CHECK_EQUAL( 0, success );
00518 
00519         int lat_id_ref;
00520         success = NCFUNC( inq_varid )( ncid_ref, "lat", &lat_id_ref );
00521         CHECK_EQUAL( 0, success );
00522 
00523 #ifdef MOAB_HAVE_PNETCDF
00524         // Enter independent I/O mode
00525         success = NCFUNC( begin_indep_data )( ncid );
00526         CHECK_EQUAL( 0, success );
00527 #endif
00528 
00529 #ifdef MOAB_HAVE_PNETCDF
00530         // Enter independent I/O mode
00531         success = NCFUNC( begin_indep_data )( ncid_ref );
00532         CHECK_EQUAL( 0, success );
00533 #endif
00534 
00535         NCDF_SIZE start[] = { 0, 0, 0 };
00536         NCDF_SIZE count[] = { 3, levels, 3458 };
00537         const int size    = 3 * levels * 3458;
00538 
00539         // Read variable T from output file
00540         double T_vals[size];
00541         success = NCFUNC( get_vara_double )( ncid, T_id, start, count, T_vals );
00542         CHECK_EQUAL( 0, success );
00543 
00544         // Read variable T from reference file
00545         double T_vals_ref[size];
00546         success = NCFUNC( get_vara_double )( ncid_ref, T_id_ref, start, count, T_vals_ref );
00547         CHECK_EQUAL( 0, success );
00548 
00549         // Read variable lat from output file
00550         count[0] = 3458;
00551         double lat_vals[3458];
00552         success = NCFUNC( get_vara_double )( ncid, lat_id, start, count, lat_vals );
00553         CHECK_EQUAL( 0, success );
00554 
00555         // Read variable lat from reference file
00556         double lat_vals_ref[3458];
00557         success = NCFUNC( get_vara_double )( ncid_ref, lat_id_ref, start, count, lat_vals_ref );
00558         CHECK_EQUAL( 0, success );
00559 
00560 #ifdef MOAB_HAVE_PNETCDF
00561         // End independent I/O mode
00562         success = NCFUNC( end_indep_data )( ncid );
00563         CHECK_EQUAL( 0, success );
00564 #endif
00565 
00566 #ifdef MOAB_HAVE_PNETCDF
00567         // End independent I/O mode
00568         success = NCFUNC( end_indep_data )( ncid_ref );
00569         CHECK_EQUAL( 0, success );
00570 #endif
00571 
00572         success = NCFUNC( close )( ncid );
00573         CHECK_EQUAL( 0, success );
00574 
00575         success = NCFUNC( close )( ncid_ref );
00576         CHECK_EQUAL( 0, success );
00577 
00578         // Check T values
00579         for( int i = 0; i < size; i++ )
00580             CHECK_REAL_EQUAL( T_vals_ref[i], T_vals[i], eps );
00581 
00582         // Check gw values
00583         for( int i = 0; i < 3458; i++ )
00584             CHECK_REAL_EQUAL( lat_vals_ref[i], lat_vals[i], eps );
00585     }
00586 }
00587 
00588 // Write vertex variable vorticity, edge variable u and cell variable ke
00589 void test_mpas_read_write_vars()
00590 {
00591     int procs = 1;
00592 #ifdef MOAB_HAVE_MPI
00593     MPI_Comm_size( MPI_COMM_WORLD, &procs );
00594 #endif
00595 
00596 // We will not test NC writer in parallel without pnetcdf support
00597 #ifndef MOAB_HAVE_PNETCDF
00598     if( procs > 1 ) return;
00599 #endif
00600 
00601     Core moab;
00602     Interface& mb = moab;
00603 
00604     std::string read_opts;
00605     get_mpas_read_options( read_opts );
00606 
00607     EntityHandle set;
00608     ErrorCode rval = mb.create_meshset( MESHSET_SET, set );CHECK_ERR( rval );
00609 
00610     // Read non-set variables vorticity, u and ke
00611     read_opts += ";VARIABLE=vorticity,u,ke;DEBUG_IO=0";
00612     if( procs > 1 ) read_opts += ";PARALLEL_RESOLVE_SHARED_ENTS";
00613     rval = mb.load_file( example_mpas.c_str(), &set, read_opts.c_str() );CHECK_ERR( rval );
00614 
00615     // Write variables vorticity, u and ke
00616     std::string write_opts = ";;VARIABLE=vorticity,u,ke;DEBUG_IO=0";
00617 #ifdef MOAB_HAVE_MPI
00618     // Use parallel options
00619     write_opts += ";PARALLEL=WRITE_PART";
00620 #endif
00621     if( procs > 1 )
00622         rval = mb.write_file( "test_par_mpas_vars.nc", 0, write_opts.c_str(), &set, 1 );
00623     else
00624         rval = mb.write_file( "test_mpas_vars.nc", 0, write_opts.c_str(), &set, 1 );CHECK_ERR( rval );
00625 }
00626 
00627 // Check vertex variable vorticity, edge variable u and cell variable ke
00628 void test_mpas_check_vars()
00629 {
00630     int rank  = 0;
00631     int procs = 1;
00632 #ifdef MOAB_HAVE_MPI
00633     MPI_Comm_rank( MPI_COMM_WORLD, &rank );
00634     MPI_Comm_size( MPI_COMM_WORLD, &procs );
00635 #endif
00636 
00637 // We will not test NC writer in parallel without pnetcdf support
00638 #ifndef MOAB_HAVE_PNETCDF
00639     if( procs > 1 ) return;
00640 #endif
00641 
00642     if( 0 == rank )
00643     {
00644         int ncid;
00645         int ncid_ref;
00646         int success;
00647 
00648         std::string filename;
00649         if( procs > 1 )
00650             filename = "test_par_mpas_vars.nc";
00651         else
00652             filename = "test_mpas_vars.nc";
00653 
00654 #ifdef MOAB_HAVE_PNETCDF
00655         success = NCFUNC( open )( MPI_COMM_SELF, filename.c_str(), NC_NOWRITE, MPI_INFO_NULL, &ncid );
00656 #else
00657         success = NCFUNC( open )( filename.c_str(), NC_NOWRITE, &ncid );
00658 #endif
00659         CHECK_EQUAL( 0, success );
00660 
00661 #ifdef MOAB_HAVE_PNETCDF
00662         success = NCFUNC( open )( MPI_COMM_SELF, example_mpas.c_str(), NC_NOWRITE, MPI_INFO_NULL, &ncid_ref );
00663 #else
00664         success = NCFUNC( open )( example_mpas.c_str(), NC_NOWRITE, &ncid_ref );
00665 #endif
00666         CHECK_EQUAL( 0, success );
00667 
00668         int vorticity_id;
00669         success = NCFUNC( inq_varid )( ncid, "vorticity", &vorticity_id );
00670         CHECK_EQUAL( 0, success );
00671 
00672         int vorticity_id_ref;
00673         success = NCFUNC( inq_varid )( ncid_ref, "vorticity", &vorticity_id_ref );
00674         CHECK_EQUAL( 0, success );
00675 
00676         int u_id;
00677         success = NCFUNC( inq_varid )( ncid, "u", &u_id );
00678         CHECK_EQUAL( 0, success );
00679 
00680         int u_id_ref;
00681         success = NCFUNC( inq_varid )( ncid_ref, "u", &u_id_ref );
00682         CHECK_EQUAL( 0, success );
00683 
00684         int ke_id;
00685         success = NCFUNC( inq_varid )( ncid, "ke", &ke_id );
00686         CHECK_EQUAL( 0, success );
00687 
00688         int ke_id_ref;
00689         success = NCFUNC( inq_varid )( ncid_ref, "ke", &ke_id_ref );
00690         CHECK_EQUAL( 0, success );
00691 
00692 #ifdef MOAB_HAVE_PNETCDF
00693         // Enter independent I/O mode
00694         success = NCFUNC( begin_indep_data )( ncid );
00695         CHECK_EQUAL( 0, success );
00696 #endif
00697 
00698 #ifdef MOAB_HAVE_PNETCDF
00699         // Enter independent I/O mode
00700         success = NCFUNC( begin_indep_data )( ncid_ref );
00701         CHECK_EQUAL( 0, success );
00702 #endif
00703 
00704         NCDF_SIZE start[] = { 0, 0, 0 };
00705         NCDF_SIZE count[] = { 2, 1, mpas_levels };
00706         const int size1   = 2 * 1280 * mpas_levels;
00707         const int size2   = 2 * 1920 * mpas_levels;
00708         const int size3   = 2 * 642 * mpas_levels;
00709 
00710         // Read vertex variable vorticity from output file
00711         count[1] = 1280;
00712         double vorticity_vals[size1];
00713         success = NCFUNC( get_vara_double )( ncid, vorticity_id, start, count, vorticity_vals );
00714         CHECK_EQUAL( 0, success );
00715 
00716         // Read vertex variable vorticity from reference file
00717         double vorticity_vals_ref[size1];
00718         success = NCFUNC( get_vara_double )( ncid_ref, vorticity_id_ref, start, count, vorticity_vals_ref );
00719         CHECK_EQUAL( 0, success );
00720 
00721         // Read edge variable u from output file
00722         count[1] = 1920;
00723         double u_vals[size2];
00724         success = NCFUNC( get_vara_double )( ncid, u_id, start, count, u_vals );
00725         CHECK_EQUAL( 0, success );
00726 
00727         // Read edge variable u from reference file
00728         double u_vals_ref[size2];
00729         success = NCFUNC( get_vara_double )( ncid_ref, u_id_ref, start, count, u_vals_ref );
00730         CHECK_EQUAL( 0, success );
00731 
00732         // Read cell variable ke from output file
00733         count[1] = 642;
00734         double ke_vals[size3];
00735         success = NCFUNC( get_vara_double )( ncid, ke_id, start, count, ke_vals );
00736         CHECK_EQUAL( 0, success );
00737 
00738         // Read cell variable ke from reference file
00739         double ke_vals_ref[size3];
00740         success = NCFUNC( get_vara_double )( ncid_ref, ke_id_ref, start, count, ke_vals_ref );
00741         CHECK_EQUAL( 0, success );
00742 
00743 #ifdef MOAB_HAVE_PNETCDF
00744         // End independent I/O mode
00745         success = NCFUNC( end_indep_data )( ncid );
00746         CHECK_EQUAL( 0, success );
00747 #endif
00748 
00749 #ifdef MOAB_HAVE_PNETCDF
00750         // End independent I/O mode
00751         success = NCFUNC( end_indep_data )( ncid_ref );
00752         CHECK_EQUAL( 0, success );
00753 #endif
00754 
00755         success = NCFUNC( close )( ncid );
00756         CHECK_EQUAL( 0, success );
00757 
00758         success = NCFUNC( close )( ncid_ref );
00759         CHECK_EQUAL( 0, success );
00760 
00761         // Check vorticity values
00762         for( int i = 0; i < size1; i++ )
00763             CHECK_REAL_EQUAL( vorticity_vals_ref[i], vorticity_vals[i], eps );
00764 
00765         // Check u values
00766         for( int i = 0; i < size2; i++ )
00767             CHECK_REAL_EQUAL( u_vals_ref[i], u_vals[i], eps );
00768 
00769         // Check ke values
00770         for( int i = 0; i < size3; i++ )
00771             CHECK_REAL_EQUAL( ke_vals_ref[i], ke_vals[i], eps );
00772     }
00773 }
00774 
00775 // Write vertex variable u, edge variable wind, cell variable vorticity (on layers),
00776 // and cell variable pressure (on interfaces)
00777 void test_gcrm_read_write_vars()
00778 {
00779     int procs = 1;
00780 #ifdef MOAB_HAVE_MPI
00781     MPI_Comm_size( MPI_COMM_WORLD, &procs );
00782 #endif
00783 
00784 // We will not test NC writer in parallel without pnetcdf support
00785 #ifndef MOAB_HAVE_PNETCDF
00786     if( procs > 1 ) return;
00787 #endif
00788 
00789     Core moab;
00790     Interface& mb = moab;
00791 
00792     std::string read_opts;
00793     // we can use the same base options as mpas, because the zoltan can apply too
00794     get_mpas_read_options( read_opts );
00795 
00796     EntityHandle set;
00797     ErrorCode rval = mb.create_meshset( MESHSET_SET, set );CHECK_ERR( rval );
00798 
00799     // Read non-set variables u, wind, vorticity and pressure
00800     read_opts += ";VARIABLE=u,wind,vorticity,pressure;DEBUG_IO=0";
00801     if( procs > 1 ) read_opts += ";PARALLEL_RESOLVE_SHARED_ENTS";
00802     rval = mb.load_file( example_gcrm.c_str(), &set, read_opts.c_str() );CHECK_ERR( rval );
00803 
00804     // Write variables u, wind, vorticity and pressure
00805     std::string write_opts = ";;VARIABLE=u,wind,vorticity,pressure;DEBUG_IO=0";
00806 #ifdef MOAB_HAVE_MPI
00807     // Use parallel options
00808     write_opts += ";PARALLEL=WRITE_PART";
00809 #endif
00810     if( procs > 1 )
00811         rval = mb.write_file( "test_par_gcrm_vars.nc", 0, write_opts.c_str(), &set, 1 );
00812     else
00813         rval = mb.write_file( "test_gcrm_vars.nc", 0, write_opts.c_str(), &set, 1 );CHECK_ERR( rval );
00814 }
00815 
00816 // Check vertex variable u, edge variable wind, cell variable vorticity (on layers),
00817 // and cell variable pressure (on interfaces)
00818 void test_gcrm_check_vars()
00819 {
00820     int rank  = 0;
00821     int procs = 1;
00822 #ifdef MOAB_HAVE_MPI
00823     MPI_Comm_rank( MPI_COMM_WORLD, &rank );
00824     MPI_Comm_size( MPI_COMM_WORLD, &procs );
00825 #endif
00826 
00827 // We will not test NC writer in parallel without pnetcdf support
00828 #ifndef MOAB_HAVE_PNETCDF
00829     if( procs > 1 ) return;
00830 #endif
00831 
00832     if( 0 == rank )
00833     {
00834         int ncid;
00835         int ncid_ref;
00836         int success;
00837 
00838         std::string filename;
00839         if( procs > 1 )
00840             filename = "test_par_gcrm_vars.nc";
00841         else
00842             filename = "test_gcrm_vars.nc";
00843 
00844 #ifdef MOAB_HAVE_PNETCDF
00845         success = NCFUNC( open )( MPI_COMM_SELF, filename.c_str(), NC_NOWRITE, MPI_INFO_NULL, &ncid );
00846 #else
00847         success = NCFUNC( open )( filename.c_str(), NC_NOWRITE, &ncid );
00848 #endif
00849         CHECK_EQUAL( 0, success );
00850 
00851 #ifdef MOAB_HAVE_PNETCDF
00852         success = NCFUNC( open )( MPI_COMM_SELF, example_gcrm.c_str(), NC_NOWRITE, MPI_INFO_NULL, &ncid_ref );
00853 #else
00854         success = NCFUNC( open )( example_gcrm.c_str(), NC_NOWRITE, &ncid_ref );
00855 #endif
00856         CHECK_EQUAL( 0, success );
00857 
00858         int u_id;
00859         success = NCFUNC( inq_varid )( ncid, "u", &u_id );
00860         CHECK_EQUAL( 0, success );
00861 
00862         int u_id_ref;
00863         success = NCFUNC( inq_varid )( ncid_ref, "u", &u_id_ref );
00864         CHECK_EQUAL( 0, success );
00865 
00866         int wind_id;
00867         success = NCFUNC( inq_varid )( ncid, "wind", &wind_id );
00868         CHECK_EQUAL( 0, success );
00869 
00870         int wind_id_ref;
00871         success = NCFUNC( inq_varid )( ncid_ref, "wind", &wind_id_ref );
00872         CHECK_EQUAL( 0, success );
00873 
00874         int vorticity_id;
00875         success = NCFUNC( inq_varid )( ncid, "vorticity", &vorticity_id );
00876         CHECK_EQUAL( 0, success );
00877 
00878         int vorticity_id_ref;
00879         success = NCFUNC( inq_varid )( ncid_ref, "vorticity", &vorticity_id_ref );
00880         CHECK_EQUAL( 0, success );
00881 
00882         int pressure_id;
00883         success = NCFUNC( inq_varid )( ncid, "pressure", &pressure_id );
00884         CHECK_EQUAL( 0, success );
00885 
00886         int pressure_id_ref;
00887         success = NCFUNC( inq_varid )( ncid_ref, "pressure", &pressure_id_ref );
00888         CHECK_EQUAL( 0, success );
00889 
00890 #ifdef MOAB_HAVE_PNETCDF
00891         // Enter independent I/O mode
00892         success = NCFUNC( begin_indep_data )( ncid );
00893         CHECK_EQUAL( 0, success );
00894 #endif
00895 
00896 #ifdef MOAB_HAVE_PNETCDF
00897         // Enter independent I/O mode
00898         success = NCFUNC( begin_indep_data )( ncid_ref );
00899         CHECK_EQUAL( 0, success );
00900 #endif
00901 
00902         NCDF_SIZE start[] = { 0, 0, 0 };
00903         NCDF_SIZE count[] = { 2, 1, levels };
00904         const int size1   = 2 * 1280 * levels;
00905         const int size2   = 2 * 1920 * levels;
00906         const int size3   = 2 * 642 * levels;
00907 
00908         // Read vertex variable u from output file
00909         count[1] = 1280;
00910         double u_vals[size1];
00911         success = NCFUNC( get_vara_double )( ncid, u_id, start, count, u_vals );
00912         CHECK_EQUAL( 0, success );
00913 
00914         // Read vertex variable u from reference file
00915         double u_vals_ref[size1];
00916         success = NCFUNC( get_vara_double )( ncid_ref, u_id_ref, start, count, u_vals_ref );
00917         CHECK_EQUAL( 0, success );
00918 
00919         // Read edge variable wind from output file
00920         count[1] = 1920;
00921         double wind_vals[size2];
00922         success = NCFUNC( get_vara_double )( ncid, wind_id, start, count, wind_vals );
00923         CHECK_EQUAL( 0, success );
00924 
00925         // Read edge variable wind from reference file
00926         double wind_vals_ref[size2];
00927         success = NCFUNC( get_vara_double )( ncid_ref, wind_id_ref, start, count, wind_vals_ref );
00928         CHECK_EQUAL( 0, success );
00929 
00930         // Read cell variable vorticity from output file
00931         count[1] = 642;
00932         double vorticity_vals[size3];
00933         success = NCFUNC( get_vara_double )( ncid, vorticity_id, start, count, vorticity_vals );
00934         CHECK_EQUAL( 0, success );
00935 
00936         // Read cell variable vorticity from reference file
00937         double vorticity_vals_ref[size3];
00938         success = NCFUNC( get_vara_double )( ncid_ref, vorticity_id_ref, start, count, vorticity_vals_ref );
00939         CHECK_EQUAL( 0, success );
00940 
00941         // Read cell variable pressure from output file
00942         double pressure_vals[size3];
00943         success = NCFUNC( get_vara_double )( ncid, pressure_id, start, count, pressure_vals );
00944         CHECK_EQUAL( 0, success );
00945 
00946         // Read cell variable pressure from reference file
00947         double pressure_vals_ref[size3];
00948         success = NCFUNC( get_vara_double )( ncid_ref, pressure_id_ref, start, count, pressure_vals_ref );
00949         CHECK_EQUAL( 0, success );
00950 
00951 #ifdef MOAB_HAVE_PNETCDF
00952         // End independent I/O mode
00953         success = NCFUNC( end_indep_data )( ncid );
00954         CHECK_EQUAL( 0, success );
00955 #endif
00956 
00957 #ifdef MOAB_HAVE_PNETCDF
00958         // End independent I/O mode
00959         success = NCFUNC( end_indep_data )( ncid_ref );
00960         CHECK_EQUAL( 0, success );
00961 #endif
00962 
00963         success = NCFUNC( close )( ncid );
00964         CHECK_EQUAL( 0, success );
00965 
00966         success = NCFUNC( close )( ncid_ref );
00967         CHECK_EQUAL( 0, success );
00968 
00969         // Check u values
00970         for( int i = 0; i < size1; i++ )
00971             CHECK_REAL_EQUAL( u_vals_ref[i], u_vals[i], eps );
00972 
00973         // Check wind values
00974         for( int i = 0; i < size2; i++ )
00975             CHECK_REAL_EQUAL( wind_vals_ref[i], wind_vals[i], eps );
00976 
00977         // Check vorticity and pressure values
00978         for( int i = 0; i < size3; i++ )
00979         {
00980             CHECK_REAL_EQUAL( vorticity_vals_ref[i], vorticity_vals[i], eps );
00981             CHECK_REAL_EQUAL( pressure_vals_ref[i], pressure_vals[i], eps );
00982         }
00983     }
00984 }
00985 
00986 // Read non-set variable T on all 3 timesteps, and write only timestep 2
00987 void test_eul_read_write_timestep()
00988 {
00989     int procs = 1;
00990 #ifdef MOAB_HAVE_MPI
00991     MPI_Comm_size( MPI_COMM_WORLD, &procs );
00992 #endif
00993 
00994 // We will not test NC writer in parallel without pnetcdf support
00995 #ifndef MOAB_HAVE_PNETCDF
00996     if( procs > 1 ) return;
00997 #endif
00998 
00999     Core moab;
01000     Interface& mb = moab;
01001 
01002     std::string read_opts;
01003     get_eul_read_options( read_opts );
01004 
01005     EntityHandle set;
01006     ErrorCode rval = mb.create_meshset( MESHSET_SET, set );CHECK_ERR( rval );
01007 
01008     // Read non-set variable T
01009     read_opts += ";VARIABLE=T;DEBUG_IO=0";
01010     rval = mb.load_file( example_eul.c_str(), &set, read_opts.c_str() );CHECK_ERR( rval );
01011 
01012     // Write variable T on timestep 2
01013     std::string write_opts = ";;VARIABLE=T;TIMESTEP=2;DEBUG_IO=0";
01014 #ifdef MOAB_HAVE_MPI
01015     // Use parallel options
01016     write_opts += ";PARALLEL=WRITE_PART";
01017 #endif
01018     if( procs > 1 )
01019         rval = mb.write_file( "test_par_eul_T2.nc", 0, write_opts.c_str(), &set, 1 );
01020     else
01021         rval = mb.write_file( "test_eul_T2.nc", 0, write_opts.c_str(), &set, 1 );CHECK_ERR( rval );
01022 }
01023 
01024 void test_eul_check_timestep()
01025 {
01026     int rank  = 0;
01027     int procs = 1;
01028 #ifdef MOAB_HAVE_MPI
01029     MPI_Comm_rank( MPI_COMM_WORLD, &rank );
01030     MPI_Comm_size( MPI_COMM_WORLD, &procs );
01031 #endif
01032 
01033 // We will not test NC writer in parallel without pnetcdf support
01034 #ifndef MOAB_HAVE_PNETCDF
01035     if( procs > 1 ) return;
01036 #endif
01037 
01038     if( 0 == rank )
01039     {
01040         int ncid;
01041         int ncid_ref;
01042         int success;
01043 
01044         std::string filename;
01045         if( procs > 1 )
01046             filename = "test_par_eul_T2.nc";
01047         else
01048             filename = "test_eul_T2.nc";
01049 
01050 #ifdef MOAB_HAVE_PNETCDF
01051         success = NCFUNC( open )( MPI_COMM_SELF, filename.c_str(), NC_NOWRITE, MPI_INFO_NULL, &ncid );
01052 #else
01053         success = NCFUNC( open )( filename.c_str(), NC_NOWRITE, &ncid );
01054 #endif
01055         CHECK_EQUAL( 0, success );
01056 
01057 #ifdef MOAB_HAVE_PNETCDF
01058         success = NCFUNC( open )( MPI_COMM_SELF, example_eul.c_str(), NC_NOWRITE, MPI_INFO_NULL, &ncid_ref );
01059 #else
01060         success = NCFUNC( open )( example_eul.c_str(), NC_NOWRITE, &ncid_ref );
01061 #endif
01062         CHECK_EQUAL( 0, success );
01063 
01064         int T_id;
01065         success = NCFUNC( inq_varid )( ncid, "T", &T_id );
01066         CHECK_EQUAL( 0, success );
01067 
01068         int T_id_ref;
01069         success = NCFUNC( inq_varid )( ncid_ref, "T", &T_id_ref );
01070         CHECK_EQUAL( 0, success );
01071 
01072 #ifdef MOAB_HAVE_PNETCDF
01073         // Enter independent I/O mode
01074         success = NCFUNC( begin_indep_data )( ncid );
01075         CHECK_EQUAL( 0, success );
01076 #endif
01077 
01078 #ifdef MOAB_HAVE_PNETCDF
01079         // Enter independent I/O mode
01080         success = NCFUNC( begin_indep_data )( ncid_ref );
01081         CHECK_EQUAL( 0, success );
01082 #endif
01083 
01084         NCDF_SIZE start[] = { 0, 0, 0, 0 };
01085         NCDF_SIZE count[] = { 1, levels, 48, 96 };
01086         const int size    = levels * 48 * 96;
01087 
01088         // Read variable T from output file (timestep 0)
01089         double T_vals[size];
01090         success = NCFUNC( get_vara_double )( ncid, T_id, start, count, T_vals );
01091         CHECK_EQUAL( 0, success );
01092 
01093         // Read variable T from reference file (timestep 2)
01094         start[0] = 2;
01095         double T_vals_ref[size];
01096         success = NCFUNC( get_vara_double )( ncid_ref, T_id_ref, start, count, T_vals_ref );
01097         CHECK_EQUAL( 0, success );
01098 
01099 #ifdef MOAB_HAVE_PNETCDF
01100         // End independent I/O mode
01101         success = NCFUNC( end_indep_data )( ncid );
01102         CHECK_EQUAL( 0, success );
01103 #endif
01104 
01105 #ifdef MOAB_HAVE_PNETCDF
01106         // End independent I/O mode
01107         success = NCFUNC( end_indep_data )( ncid_ref );
01108         CHECK_EQUAL( 0, success );
01109 #endif
01110 
01111         success = NCFUNC( close )( ncid );
01112         CHECK_EQUAL( 0, success );
01113 
01114         success = NCFUNC( close )( ncid_ref );
01115         CHECK_EQUAL( 0, success );
01116 
01117         // Check T values
01118         for( int i = 0; i < size; i++ )
01119             CHECK_REAL_EQUAL( T_vals_ref[i], T_vals[i], eps );
01120     }
01121 }
01122 
01123 // Read non-set variables T, U and V
01124 // Write variable T, append U, and then append V (with a new name)
01125 void test_eul_read_write_append()
01126 {
01127     int procs = 1;
01128 #ifdef MOAB_HAVE_MPI
01129     MPI_Comm_size( MPI_COMM_WORLD, &procs );
01130 #endif
01131 
01132 // We will not test NC writer in parallel without pnetcdf support
01133 #ifndef MOAB_HAVE_PNETCDF
01134     if( procs > 1 ) return;
01135 #endif
01136 
01137     Core moab;
01138     Interface& mb = moab;
01139 
01140     std::string read_opts;
01141     get_eul_read_options( read_opts );
01142 
01143     EntityHandle set;
01144     ErrorCode rval = mb.create_meshset( MESHSET_SET, set );CHECK_ERR( rval );
01145 
01146     // Load non-set variables T, U, V, and the mesh
01147     read_opts += ";VARIABLE=T,U,V;DEBUG_IO=0";
01148     rval = mb.load_file( example_eul.c_str(), &set, read_opts.c_str() );CHECK_ERR( rval );
01149 
01150     // Write variable T
01151     std::string write_opts = ";;VARIABLE=T;DEBUG_IO=0";
01152 #ifdef MOAB_HAVE_MPI
01153     // Use parallel options
01154     write_opts += ";PARALLEL=WRITE_PART";
01155 #endif
01156     if( procs > 1 )
01157         rval = mb.write_file( "test_par_eul_append.nc", 0, write_opts.c_str(), &set, 1 );
01158     else
01159         rval = mb.write_file( "test_eul_append.nc", 0, write_opts.c_str(), &set, 1 );CHECK_ERR( rval );
01160 
01161     // Append to the file variable U
01162     write_opts = ";;VARIABLE=U;APPEND;DEBUG_IO=0";
01163 #ifdef MOAB_HAVE_MPI
01164     // Use parallel options
01165     write_opts += ";PARALLEL=WRITE_PART";
01166 #endif
01167     if( procs > 1 )
01168         rval = mb.write_file( "test_par_eul_append.nc", 0, write_opts.c_str(), &set, 1 );
01169     else
01170         rval = mb.write_file( "test_eul_append.nc", 0, write_opts.c_str(), &set, 1 );CHECK_ERR( rval );
01171 
01172     // Append to the file variable V, renamed to VNEWNAME
01173     write_opts = ";;VARIABLE=V;RENAME=VNEWNAME;APPEND;DEBUG_IO=0";
01174 #ifdef MOAB_HAVE_MPI
01175     // Use parallel options
01176     write_opts += ";PARALLEL=WRITE_PART";
01177 #endif
01178     if( procs > 1 )
01179         rval = mb.write_file( "test_par_eul_append.nc", 0, write_opts.c_str(), &set, 1 );
01180     else
01181         rval = mb.write_file( "test_eul_append.nc", 0, write_opts.c_str(), &set, 1 );CHECK_ERR( rval );
01182 }
01183 
01184 void test_eul_check_append()
01185 {
01186     int rank  = 0;
01187     int procs = 1;
01188 #ifdef MOAB_HAVE_MPI
01189     MPI_Comm_rank( MPI_COMM_WORLD, &rank );
01190     MPI_Comm_size( MPI_COMM_WORLD, &procs );
01191 #endif
01192 
01193 // We will not test NC writer in parallel without pnetcdf support
01194 #ifndef MOAB_HAVE_PNETCDF
01195     if( procs > 1 ) return;
01196 #endif
01197 
01198     if( 0 == rank )
01199     {
01200         int ncid;
01201         int ncid_ref;
01202         int success;
01203 
01204         std::string filename;
01205         if( procs > 1 )
01206             filename = "test_par_eul_append.nc";
01207         else
01208             filename = "test_eul_append.nc";
01209 
01210 #ifdef MOAB_HAVE_PNETCDF
01211         success = NCFUNC( open )( MPI_COMM_SELF, filename.c_str(), NC_NOWRITE, MPI_INFO_NULL, &ncid );
01212 #else
01213         success = NCFUNC( open )( filename.c_str(), NC_NOWRITE, &ncid );
01214 #endif
01215         CHECK_EQUAL( 0, success );
01216 
01217 #ifdef MOAB_HAVE_PNETCDF
01218         success = NCFUNC( open )( MPI_COMM_SELF, example_eul.c_str(), NC_NOWRITE, MPI_INFO_NULL, &ncid_ref );
01219 #else
01220         success = NCFUNC( open )( example_eul.c_str(), NC_NOWRITE, &ncid_ref );
01221 #endif
01222         CHECK_EQUAL( 0, success );
01223 
01224         int T_id;
01225         success = NCFUNC( inq_varid )( ncid, "T", &T_id );
01226         CHECK_EQUAL( 0, success );
01227 
01228         int T_id_ref;
01229         success = NCFUNC( inq_varid )( ncid_ref, "T", &T_id_ref );
01230         CHECK_EQUAL( 0, success );
01231 
01232         int U_id;
01233         success = NCFUNC( inq_varid )( ncid, "U", &U_id );
01234         CHECK_EQUAL( 0, success );
01235 
01236         int U_id_ref;
01237         success = NCFUNC( inq_varid )( ncid_ref, "U", &U_id_ref );
01238         CHECK_EQUAL( 0, success );
01239 
01240         int V_id;
01241         success = NCFUNC( inq_varid )( ncid, "VNEWNAME", &V_id );
01242         CHECK_EQUAL( 0, success );
01243 
01244         int V_id_ref;
01245         success = NCFUNC( inq_varid )( ncid_ref, "V", &V_id_ref );
01246         CHECK_EQUAL( 0, success );
01247 
01248 #ifdef MOAB_HAVE_PNETCDF
01249         // Enter independent I/O mode
01250         success = NCFUNC( begin_indep_data )( ncid );
01251         CHECK_EQUAL( 0, success );
01252 #endif
01253 
01254 #ifdef MOAB_HAVE_PNETCDF
01255         // Enter independent I/O mode
01256         success = NCFUNC( begin_indep_data )( ncid_ref );
01257         CHECK_EQUAL( 0, success );
01258 #endif
01259 
01260         NCDF_SIZE start[] = { 0, 0, 0, 0 };
01261         NCDF_SIZE count[] = { 3, levels, 48, 96 };
01262         const int size    = 3 * levels * 48 * 96;
01263 
01264         // Read variable T from output file
01265         double T_vals[size];
01266         success = NCFUNC( get_vara_double )( ncid, T_id, start, count, T_vals );
01267         CHECK_EQUAL( 0, success );
01268 
01269         // Read variable T from reference file
01270         double T_vals_ref[size];
01271         success = NCFUNC( get_vara_double )( ncid_ref, T_id_ref, start, count, T_vals_ref );
01272         CHECK_EQUAL( 0, success );
01273 
01274         // Read variable U from output file
01275         double U_vals[size];
01276         success = NCFUNC( get_vara_double )( ncid, U_id, start, count, U_vals );
01277         CHECK_EQUAL( 0, success );
01278 
01279         // Read variable U from reference file
01280         double U_vals_ref[size];
01281         success = NCFUNC( get_vara_double )( ncid_ref, U_id_ref, start, count, U_vals_ref );
01282         CHECK_EQUAL( 0, success );
01283 
01284         // Read variable VNEWNAME from output file
01285         double V_vals[size];
01286         success = NCFUNC( get_vara_double )( ncid, V_id, start, count, V_vals );
01287         CHECK_EQUAL( 0, success );
01288 
01289         // Read variable V from reference file
01290         double V_vals_ref[size];
01291         success = NCFUNC( get_vara_double )( ncid_ref, V_id_ref, start, count, V_vals_ref );
01292         CHECK_EQUAL( 0, success );
01293 
01294 #ifdef MOAB_HAVE_PNETCDF
01295         // End independent I/O mode
01296         success = NCFUNC( end_indep_data )( ncid );
01297         CHECK_EQUAL( 0, success );
01298 #endif
01299 
01300 #ifdef MOAB_HAVE_PNETCDF
01301         // End independent I/O mode
01302         success = NCFUNC( end_indep_data )( ncid_ref );
01303         CHECK_EQUAL( 0, success );
01304 #endif
01305 
01306         success = NCFUNC( close )( ncid );
01307         CHECK_EQUAL( 0, success );
01308 
01309         success = NCFUNC( close )( ncid_ref );
01310         CHECK_EQUAL( 0, success );
01311 
01312         // Check T, U, and V values
01313         for( int i = 0; i < size; i++ )
01314         {
01315             CHECK_REAL_EQUAL( T_vals_ref[i], T_vals[i], eps );
01316             CHECK_REAL_EQUAL( U_vals_ref[i], U_vals[i], eps );
01317             CHECK_REAL_EQUAL( V_vals_ref[i], V_vals[i], eps );
01318         }
01319     }
01320 }
01321 
01322 void test_eul_read_write_across_files()
01323 {
01324     int procs = 1;
01325 #ifdef MOAB_HAVE_MPI
01326     MPI_Comm_size( MPI_COMM_WORLD, &procs );
01327 #endif
01328 
01329 // We will not test NC writer in parallel without pnetcdf support
01330 #ifndef MOAB_HAVE_PNETCDF
01331     if( procs > 1 ) return;
01332 #endif
01333 
01334     Core moab;
01335     Interface& mb = moab;
01336 
01337     std::string read_opts;
01338 
01339     EntityHandle set;
01340     ErrorCode rval = mb.create_meshset( MESHSET_SET, set );CHECK_ERR( rval );
01341 
01342     // This file contains single timestep 2 (option TIMESTEP=0 will be implicitly used)
01343     // Read T as tag T2 with option TIMESTEPBASE=2
01344     get_eul_read_options( read_opts );
01345     read_opts += ";VARIABLE=T;TIMESTEPBASE=2;DEBUG_IO=0";
01346     rval = mb.load_file( example_eul_t2.c_str(), &set, read_opts.c_str() );CHECK_ERR( rval );
01347 
01348     // This file contains single timestep 0 (option TIMESTEP=0 will be implicitly used)
01349     // Read T as tag T0 with option TIMESTEPBASE=0
01350     get_eul_read_options( read_opts );
01351     read_opts += ";VARIABLE=T;TIMESTEPBASE=0;NOMESH;DEBUG_IO=0";
01352     rval = mb.load_file( example_eul_t0.c_str(), &set, read_opts.c_str() );CHECK_ERR( rval );
01353 
01354     // This file contains single timestep 1 (option TIMESTEP=0 will be implicitly used)
01355     // Read T as tag T1 with option TIMESTEPBASE=1
01356     get_eul_read_options( read_opts );
01357     read_opts += ";VARIABLE=T;TIMESTEPBASE=1;NOMESH;DEBUG_IO=0";
01358     rval = mb.load_file( example_eul_t1.c_str(), &set, read_opts.c_str() );CHECK_ERR( rval );
01359 
01360     // Write variable T with 3 timesteps
01361     std::string write_opts = ";;VARIABLE=T;TIMESTEP=0,1,2;DEBUG_IO=0";
01362 #ifdef MOAB_HAVE_MPI
01363     // Use parallel options
01364     write_opts += ";PARALLEL=WRITE_PART";
01365 #endif
01366     if( procs > 1 )
01367         rval = mb.write_file( "test_par_eul_across_files.nc", 0, write_opts.c_str(), &set, 1 );
01368     else
01369         rval = mb.write_file( "test_eul_across_files.nc", 0, write_opts.c_str(), &set, 1 );CHECK_ERR( rval );
01370 }
01371 
01372 void test_eul_check_across_files()
01373 {
01374     int rank  = 0;
01375     int procs = 1;
01376 #ifdef MOAB_HAVE_MPI
01377     MPI_Comm_rank( MPI_COMM_WORLD, &rank );
01378     MPI_Comm_size( MPI_COMM_WORLD, &procs );
01379 #endif
01380 
01381 // We will not test NC writer in parallel without pnetcdf support
01382 #ifndef MOAB_HAVE_PNETCDF
01383     if( procs > 1 ) return;
01384 #endif
01385 
01386     if( 0 == rank )
01387     {
01388         int ncid;
01389         int ncid_ref;
01390         int success;
01391 
01392         std::string filename;
01393         if( procs > 1 )
01394             filename = "test_par_eul_across_files.nc";
01395         else
01396             filename = "test_eul_across_files.nc";
01397 
01398 #ifdef MOAB_HAVE_PNETCDF
01399         success = NCFUNC( open )( MPI_COMM_SELF, filename.c_str(), NC_NOWRITE, MPI_INFO_NULL, &ncid );
01400 #else
01401         success = NCFUNC( open )( filename.c_str(), NC_NOWRITE, &ncid );
01402 #endif
01403         CHECK_EQUAL( 0, success );
01404 
01405 #ifdef MOAB_HAVE_PNETCDF
01406         success = NCFUNC( open )( MPI_COMM_SELF, example_eul.c_str(), NC_NOWRITE, MPI_INFO_NULL, &ncid_ref );
01407 #else
01408         success = NCFUNC( open )( example_eul.c_str(), NC_NOWRITE, &ncid_ref );
01409 #endif
01410         CHECK_EQUAL( 0, success );
01411 
01412         int T_id;
01413         success = NCFUNC( inq_varid )( ncid, "T", &T_id );
01414         CHECK_EQUAL( 0, success );
01415 
01416         int T_id_ref;
01417         success = NCFUNC( inq_varid )( ncid_ref, "T", &T_id_ref );
01418         CHECK_EQUAL( 0, success );
01419 
01420 #ifdef MOAB_HAVE_PNETCDF
01421         // Enter independent I/O mode
01422         success = NCFUNC( begin_indep_data )( ncid );
01423         CHECK_EQUAL( 0, success );
01424 #endif
01425 
01426 #ifdef MOAB_HAVE_PNETCDF
01427         // Enter independent I/O mode
01428         success = NCFUNC( begin_indep_data )( ncid_ref );
01429         CHECK_EQUAL( 0, success );
01430 #endif
01431 
01432         NCDF_SIZE start[] = { 0, 0, 0, 0 };
01433         NCDF_SIZE count[] = { 3, levels, 48, 96 };
01434         const int size    = 3 * levels * 48 * 96;
01435 
01436         // Read variable T from output file (with 3 timesteps)
01437         double T_vals[size];
01438         success = NCFUNC( get_vara_double )( ncid, T_id, start, count, T_vals );
01439         CHECK_EQUAL( 0, success );
01440 
01441         // Read variable T from reference file (with 3 timesteps)
01442         double T_vals_ref[size];
01443         success = NCFUNC( get_vara_double )( ncid_ref, T_id_ref, start, count, T_vals_ref );
01444         CHECK_EQUAL( 0, success );
01445 
01446 #ifdef MOAB_HAVE_PNETCDF
01447         // End independent I/O mode
01448         success = NCFUNC( end_indep_data )( ncid );
01449         CHECK_EQUAL( 0, success );
01450 #endif
01451 
01452 #ifdef MOAB_HAVE_PNETCDF
01453         // End independent I/O mode
01454         success = NCFUNC( end_indep_data )( ncid_ref );
01455         CHECK_EQUAL( 0, success );
01456 #endif
01457 
01458         success = NCFUNC( close )( ncid );
01459         CHECK_EQUAL( 0, success );
01460 
01461         success = NCFUNC( close )( ncid_ref );
01462         CHECK_EQUAL( 0, success );
01463 
01464         // Check T values
01465         for( int i = 0; i < size; i++ )
01466             CHECK_REAL_EQUAL( T_vals_ref[i], T_vals[i], eps );
01467     }
01468 }
01469 
01470 #ifdef MOAB_HAVE_MPI
01471 // NC writer should filter entities that are not owned, e.g. ghosted elements
01472 void test_eul_read_write_ghosting()
01473 {
01474     int procs = 1;
01475     MPI_Comm_size( MPI_COMM_WORLD, &procs );
01476 
01477 // We will not test NC writer in parallel without pnetcdf support
01478 #ifndef MOAB_HAVE_PNETCDF
01479     if( procs > 1 ) return;
01480 #endif
01481 
01482     Core moab;
01483     Interface& mb = moab;
01484 
01485     EntityHandle set;
01486     ErrorCode rval = mb.create_meshset( MESHSET_SET, set );CHECK_ERR( rval );
01487 
01488     std::string read_opts = "PARALLEL=READ_PART;PARTITION;PARALLEL_RESOLVE_SHARED_ENTS;PARALLEL_"
01489                             "GHOSTS=2.0.1;PARTITION_METHOD=SQIJ;VARIABLE=";
01490     rval = mb.load_file( example_eul.c_str(), &set, read_opts.c_str() );CHECK_ERR( rval );
01491 
01492     read_opts = "PARALLEL=READ_PART;PARTITION;PARTITION_METHOD=SQIJ;VARIABLE=T;NOMESH";
01493     rval      = mb.load_file( example_eul.c_str(), &set, read_opts.c_str() );CHECK_ERR( rval );
01494 
01495     // Write variable T
01496     std::string write_opts = ";;PARALLEL=WRITE_PART;VARIABLE=T;DEBUG_IO=0";
01497     if( procs > 1 )
01498         rval = mb.write_file( "test_par_eul_ghosting.nc", 0, write_opts.c_str(), &set, 1 );
01499     else
01500         rval = mb.write_file( "test_eul_ghosting.nc", 0, write_opts.c_str(), &set, 1 );CHECK_ERR( rval );
01501 }
01502 
01503 void test_eul_check_ghosting()
01504 {
01505     int rank  = 0;
01506     int procs = 1;
01507 #ifdef MOAB_HAVE_MPI
01508     MPI_Comm_rank( MPI_COMM_WORLD, &rank );
01509     MPI_Comm_size( MPI_COMM_WORLD, &procs );
01510 #endif
01511 
01512 // We will not test NC writer in parallel without pnetcdf support
01513 #ifndef MOAB_HAVE_PNETCDF
01514     if( procs > 1 ) return;
01515 #endif
01516 
01517     if( 0 == rank )
01518     {
01519         int ncid;
01520         int ncid_ref;
01521         int success;
01522 
01523         std::string filename;
01524         if( procs > 1 )
01525             filename = "test_par_eul_ghosting.nc";
01526         else
01527             filename = "test_eul_ghosting.nc";
01528 
01529 #ifdef MOAB_HAVE_PNETCDF
01530         success = NCFUNC( open )( MPI_COMM_SELF, filename.c_str(), NC_NOWRITE, MPI_INFO_NULL, &ncid );
01531 #else
01532         success = NCFUNC( open )( filename.c_str(), NC_NOWRITE, &ncid );
01533 #endif
01534         CHECK_EQUAL( 0, success );
01535 
01536 #ifdef MOAB_HAVE_PNETCDF
01537         success = NCFUNC( open )( MPI_COMM_SELF, example_eul.c_str(), NC_NOWRITE, MPI_INFO_NULL, &ncid_ref );
01538 #else
01539         success = NCFUNC( open )( example_eul.c_str(), NC_NOWRITE, &ncid_ref );
01540 #endif
01541         CHECK_EQUAL( 0, success );
01542 
01543         int T_id;
01544         success = NCFUNC( inq_varid )( ncid, "T", &T_id );
01545         CHECK_EQUAL( 0, success );
01546 
01547         int T_id_ref;
01548         success = NCFUNC( inq_varid )( ncid_ref, "T", &T_id_ref );
01549         CHECK_EQUAL( 0, success );
01550 
01551 #ifdef MOAB_HAVE_PNETCDF
01552         // Enter independent I/O mode
01553         success = NCFUNC( begin_indep_data )( ncid );
01554         CHECK_EQUAL( 0, success );
01555 #endif
01556 
01557 #ifdef MOAB_HAVE_PNETCDF
01558         // Enter independent I/O mode
01559         success = NCFUNC( begin_indep_data )( ncid_ref );
01560         CHECK_EQUAL( 0, success );
01561 #endif
01562 
01563         NCDF_SIZE start[] = { 0, 0, 0, 0 };
01564         NCDF_SIZE count[] = { 3, levels, 48, 96 };
01565         const int size    = 3 * levels * 48 * 96;
01566 
01567         // Read variable T from output file
01568         double T_vals[size];
01569         success = NCFUNC( get_vara_double )( ncid, T_id, start, count, T_vals );
01570         CHECK_EQUAL( 0, success );
01571 
01572         // Read variable T from reference file
01573         double T_vals_ref[size];
01574         success = NCFUNC( get_vara_double )( ncid_ref, T_id_ref, start, count, T_vals_ref );
01575         CHECK_EQUAL( 0, success );
01576 
01577 #ifdef MOAB_HAVE_PNETCDF
01578         // End independent I/O mode
01579         success = NCFUNC( end_indep_data )( ncid );
01580         CHECK_EQUAL( 0, success );
01581 #endif
01582 
01583 #ifdef MOAB_HAVE_PNETCDF
01584         // End independent I/O mode
01585         success = NCFUNC( end_indep_data )( ncid_ref );
01586         CHECK_EQUAL( 0, success );
01587 #endif
01588 
01589         success = NCFUNC( close )( ncid );
01590         CHECK_EQUAL( 0, success );
01591 
01592         success = NCFUNC( close )( ncid_ref );
01593         CHECK_EQUAL( 0, success );
01594 
01595         // Check T values
01596         for( int i = 0; i < size; i++ )
01597             CHECK_REAL_EQUAL( T_vals_ref[i], T_vals[i], eps );
01598     }
01599 }
01600 #endif
01601 
01602 void get_eul_read_options( std::string& opts )
01603 {
01604 #ifdef MOAB_HAVE_MPI
01605     // Use parallel options
01606     opts = ";;PARALLEL=READ_PART;PARTITION_METHOD=SQIJ";
01607 #else
01608     opts = ";;";
01609 #endif
01610 }
01611 
01612 void get_fv_read_options( std::string& opts )
01613 {
01614 #ifdef MOAB_HAVE_MPI
01615     // Use parallel options
01616     opts = ";;PARALLEL=READ_PART;PARTITION_METHOD=SQIJ";
01617 #else
01618     opts = ";;";
01619 #endif
01620 }
01621 
01622 void get_homme_read_options( std::string& opts )
01623 {
01624 #ifdef MOAB_HAVE_MPI
01625     // Use parallel options
01626     opts = ";;PARALLEL=READ_PART;PARTITION_METHOD=TRIVIAL";
01627 #else
01628     opts = ";;";
01629 #endif
01630 }
01631 
01632 void get_mpas_read_options( std::string& opts )
01633 {
01634 #ifdef MOAB_HAVE_MPI
01635     // Use parallel options
01636 #ifdef MOAB_HAVE_ZOLTAN
01637     opts = ";;PARALLEL=READ_PART;PARTITION_METHOD=RCBZOLTAN";
01638 #else
01639     opts = ";;PARALLEL=READ_PART;PARTITION_METHOD=TRIVIAL";
01640 #endif
01641 #else
01642     opts = ";;";
01643 #endif
01644 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines