MOAB: Mesh Oriented datABase  (version 5.4.1)
h5varlen.cpp
Go to the documentation of this file.
00001 #include "moab/Core.hpp"
00002 #include "TestUtil.hpp"
00003 #include "moab/Range.hpp"
00004 
00005 #ifdef MOAB_HAVE_MPI
00006 #include "moab_mpi.h"
00007 #endif
00008 
00009 #include <cstdlib>
00010 #include <cstdio>
00011 
00012 using namespace moab;
00013 
00014 static bool keep_files = false;
00015 
00016 void test_var_length_no_data();
00017 
00018 void test_var_length_data();
00019 
00020 void test_var_length_data_big();
00021 
00022 void test_var_length_big_data();
00023 
00024 void test_var_length_opaque();
00025 
00026 void test_var_length_mesh_data();
00027 
00028 void test_var_length_default_data();
00029 
00030 void test_var_length_mesh_opaque();
00031 
00032 void test_var_length_default_opaque();
00033 
00034 void test_var_length_handle_tag();
00035 
00036 void test_huge_var_length();
00037 
00038 void create_mesh( Interface& mb );
00039 
00040 void create_big_mesh( Interface& mb );
00041 
00042 void compare_tags( const char* name, Interface& mb1, Interface& mb2 );
00043 
00044 void read_write( const char* filename, Interface& write, Interface& reader );
00045 
00046 #define CHECK_ERR_FILE( ERRCODE, FILENAME )                                \
00047     do                                                                     \
00048     {                                                                      \
00049         if( MB_SUCCESS != ( ERRCODE ) && !keep_files ) remove( FILENAME ); \
00050         CHECK_ERR( ERRCODE );                                              \
00051         while( false )
00052 
00053 int main( int argc, char* argv[] )
00054 {
00055 #ifdef MOAB_HAVE_MPI
00056     int fail = MPI_Init( &argc, &argv );
00057     if( fail ) return fail;
00058 #endif
00059 
00060     if( argc != 1 )
00061     {
00062         if( argc != 2 || strcmp( argv[1], "-k" ) != 0 )
00063         {
00064             fprintf( stderr, "Usage: %s [-k]\n", argv[0] );
00065             abort();
00066         }
00067         keep_files = true;
00068     }
00069 
00070     int err_count = 0;
00071     err_count += RUN_TEST( test_var_length_no_data );
00072     err_count += RUN_TEST( test_var_length_data );
00073     err_count += RUN_TEST( test_var_length_big_data );
00074     err_count += RUN_TEST( test_var_length_opaque );
00075     err_count += RUN_TEST( test_var_length_mesh_data );
00076     err_count += RUN_TEST( test_var_length_default_data );
00077     err_count += RUN_TEST( test_var_length_mesh_opaque );
00078     err_count += RUN_TEST( test_var_length_default_opaque );
00079     err_count += RUN_TEST( test_var_length_handle_tag );
00080     err_count += RUN_TEST( test_var_length_data_big );
00081 
00082     err_count += RUN_TEST( test_huge_var_length );
00083 
00084 #ifdef MOAB_HAVE_MPI
00085     fail = MPI_Finalize();
00086     if( fail ) return fail;
00087 #endif
00088 
00089     return err_count;
00090 }
00091 
00092 void test_var_length_no_data()
00093 {
00094     ErrorCode rval;
00095     Core moab1, moab2;
00096     Interface &mb1 = moab1, &mb2 = moab2;
00097     Tag tag;
00098 
00099     create_mesh( mb1 );
00100     rval = mb1.tag_get_handle( "test_tag", 0, MB_TYPE_DOUBLE, tag, MB_TAG_EXCL | MB_TAG_VARLEN | MB_TAG_DENSE );CHECK_ERR( rval );
00101 
00102     read_write( "test_var_length_no_data.h5m", mb1, mb2 );
00103     compare_tags( "test_tag", mb1, mb2 );
00104 }
00105 
00106 void test_var_length_data_common( const char* filename, Interface& mb1, bool opaque = false )
00107 {
00108     // create tag
00109     ErrorCode rval;
00110     Tag tag;
00111     DataType type = opaque ? MB_TYPE_OPAQUE : MB_TYPE_INTEGER;
00112     rval          = mb1.tag_get_handle( "test_tag", 0, type, tag, MB_TAG_EXCL | MB_TAG_VARLEN | MB_TAG_SPARSE );CHECK_ERR( rval );
00113 
00114     // get all entities
00115     Range entities;
00116     rval = mb1.get_entities_by_handle( 0, entities );CHECK_ERR( rval );
00117 
00118     // Set tag data.
00119     // Tag data will be list of integer data as follows:
00120     //   number of values (counting this value)
00121     //   step, 2*step, 3*step, ...
00122     for( Range::const_iterator i = entities.begin(); i != entities.end(); ++i )
00123     {
00124         EntityHandle h = *i;
00125         // generate some data to write
00126         int num_values   = h % 6 + 1;
00127         EntityType etype = mb1.type_from_handle( h );
00128         int step         = ( h % 2 ) ? 1 + (int)etype : -1 - (int)etype;
00129         std::vector< int > tag_data( num_values, num_values );
00130         for( int j = 1; j < num_values; ++j )
00131             tag_data[j] = j * step;
00132         // set tag data
00133         const void* ptrarr[] = { &tag_data[0] };
00134         if( opaque ) num_values *= sizeof( int );
00135         rval = mb1.tag_set_by_ptr( tag, &h, 1, ptrarr, &num_values );CHECK_ERR( rval );
00136     }
00137 
00138     // write and read tag data
00139     Core moab;
00140     Interface& mb2 = moab;
00141     read_write( filename, mb1, mb2 );
00142     compare_tags( "test_tag", mb1, mb2 );
00143 
00144     // get new tag handle
00145     tag  = 0;
00146     rval = mb2.tag_get_handle( "test_tag", 0, type, tag );CHECK_ERR( rval );
00147 
00148     // check consistency of tag values
00149     entities.clear();
00150     mb2.get_entities_by_handle( 0, entities );
00151     // remove sets created during read/write process
00152     Range sets;
00153     mb2.get_entities_by_type( 0, MBENTITYSET, sets );
00154     entities = subtract( entities, sets );
00155     for( Range::const_iterator i = entities.begin(); i != entities.end(); ++i )
00156     {
00157         // get data
00158         const void* ptrarr[] = { NULL };
00159         int size;
00160         rval = mb2.tag_get_by_ptr( tag, &*i, 1, ptrarr, &size );CHECK_ERR( rval );
00161         if( opaque )
00162         {
00163             CHECK_EQUAL( (size_t)0, size % sizeof( int ) );
00164             size /= sizeof( int );
00165         }
00166         const int* dataptr = reinterpret_cast< const int* >( ptrarr[0] );
00167         CHECK( NULL != dataptr );
00168         // check size
00169         CHECK( size > 0 );
00170         CHECK_EQUAL( size, dataptr[0] );
00171         // check other values
00172         if( size > 2 )
00173         {
00174             int step = dataptr[1];
00175             for( int j = 2; j < size; ++j )
00176                 CHECK_EQUAL( j * step, dataptr[j] );
00177         }
00178     }
00179 }
00180 
00181 void test_var_length_data()
00182 {
00183     Core moab;
00184     create_mesh( moab );
00185     test_var_length_data_common( "test_var_length_data.h5m", moab );
00186 }
00187 
00188 void test_var_length_data_big()
00189 {
00190     Core moab;
00191     create_big_mesh( moab );
00192     test_var_length_data_common( "test_var_length_data_big.h5m", moab );
00193 }
00194 
00195 void calculate_big_value( Interface& moab, EntityHandle vert, size_t size, double* data )
00196 {
00197     // Make values like Fibonacci numbers, except use X and Y coords
00198     // rather than 0 and 1 as first two values.
00199 
00200     CHECK( size >= 3 );
00201     ErrorCode rval = moab.get_coords( &vert, 1, data );CHECK_ERR( rval );
00202 
00203     for( size_t j = 2; j < size; ++j )
00204         data[j] = data[j - 2] + data[j - 1];CHECK_ERR( rval );
00205 }
00206 
00207 void test_var_length_big_data()
00208 {
00209     ErrorCode rval;
00210     Core moab1, moab2;
00211     Interface &mb1 = moab1, &mb2 = moab2;
00212     Tag tag;
00213 
00214     create_mesh( mb1 );
00215     rval = mb1.tag_get_handle( "test_tag", 0, MB_TYPE_DOUBLE, tag, MB_TAG_SPARSE | MB_TAG_VARLEN | MB_TAG_EXCL );CHECK_ERR( rval );
00216 
00217     // choose 3 vertices upon which to set data
00218     Range range;
00219     rval = mb1.get_entities_by_type( 0, MBVERTEX, range );CHECK_ERR( rval );
00220     EntityHandle verts[3] = { range.front(), *( range.begin() += range.size() / 3 ),
00221                               *( range.begin() += 2 * range.size() / 3 ) };
00222 
00223     // set 1-millon value tag data on three vertices
00224     std::vector< double > data( 1000000 );
00225     for( int i = 0; i < 3; ++i )
00226     {
00227         calculate_big_value( mb1, verts[i], data.size(), &data[0] );
00228         const void* ptr = &data[0];
00229         const int size  = data.size();
00230         rval            = mb1.tag_set_by_ptr( tag, verts + i, 1, &ptr, &size );CHECK_ERR( rval );
00231     }
00232 
00233     read_write( "test_var_length_big_data.h5m", mb1, mb2 );
00234     compare_tags( "test_tag", mb1, mb2 );
00235 
00236     // check 3 tagged vertices
00237     rval = mb2.tag_get_handle( "test_tag", 0, MB_TYPE_DOUBLE, tag );CHECK_ERR( rval );
00238     range.clear();
00239     rval = mb2.get_entities_by_type_and_tag( 0, MBVERTEX, &tag, 0, 1, range, Interface::UNION );CHECK_ERR( rval );
00240     CHECK_EQUAL( (size_t)3, range.size() );
00241 
00242     // check tag values
00243     for( Range::const_iterator i = range.begin(); i != range.end(); ++i )
00244     {
00245         // calculate expected value
00246         const EntityHandle h = *i;
00247         calculate_big_value( mb2, h, data.size(), &data[0] );
00248 
00249         // get actual value
00250         const void* ptr;
00251         int size;
00252         rval = mb2.tag_get_by_ptr( tag, &h, 1, &ptr, &size );CHECK_ERR( rval );
00253         CHECK_EQUAL( data.size(), (size_t)size );
00254 
00255         // compare values
00256         const double* act_data = reinterpret_cast< const double* >( ptr );
00257         int wrong_count        = 0;
00258         for( size_t j = 0; j < data.size(); ++j )
00259             if( act_data[j] != data[j] ) ++wrong_count;
00260         CHECK_EQUAL( 0, wrong_count );
00261     }
00262 }
00263 
00264 void test_var_length_opaque()
00265 {
00266     Core moab;
00267     create_mesh( moab );
00268     test_var_length_data_common( "test_var_length_opaque.h5m", moab, true );
00269 }
00270 
00271 void test_global_value_common( bool mesh_value )
00272 {
00273     Core moab;
00274     Interface& mb = moab;
00275     create_mesh( mb );
00276 
00277     // get three vertices
00278     Range vertices;
00279     ErrorCode rval = mb.get_entities_by_type( 0, MBVERTEX, vertices );CHECK_ERR( rval );
00280     CHECK( vertices.size() >= 3 );
00281     EntityHandle handles[3];
00282     Range::const_iterator i = vertices.begin();
00283     handles[0]              = *i;
00284     ++i;
00285     handles[1] = *i;
00286     ++i;
00287     handles[2] = *i;
00288     ++i;
00289 
00290     // get vertex coordinates
00291     double coords[9];
00292     rval = mb.get_coords( handles, 3, coords );CHECK_ERR( rval );
00293 
00294     // create tag to hold vertex data
00295     Tag handle_tag       = 0;
00296     void* default_val    = mesh_value ? 0 : handles;
00297     int default_val_size = mesh_value ? 0 : 3;
00298     rval                 = mb.tag_get_handle( "handle_tag", default_val_size, MB_TYPE_HANDLE, handle_tag,
00299                                               MB_TAG_DENSE | MB_TAG_VARLEN | MB_TAG_EXCL, default_val );CHECK_ERR( rval );
00300 
00301     // create tag to hold vertex coordinates
00302     Tag coord_tag    = 0;
00303     default_val      = mesh_value ? 0 : coords;
00304     default_val_size = mesh_value ? 0 : 9;
00305     rval             = mb.tag_get_handle( "coord_tag", default_val_size, MB_TYPE_DOUBLE, coord_tag,
00306                                           MB_TAG_SPARSE | MB_TAG_VARLEN | MB_TAG_EXCL, default_val );CHECK_ERR( rval );
00307 
00308     // if doing mesh tag, set it
00309     if( mesh_value )
00310     {
00311         int size                = 3;
00312         const void* ptrarr[]    = { handles };
00313         const EntityHandle root = 0;
00314         rval                    = mb.tag_set_by_ptr( handle_tag, &root, 1, ptrarr, &size );CHECK_ERR( rval );
00315 
00316         size      = 9;
00317         ptrarr[0] = coords;
00318         rval      = mb.tag_set_by_ptr( coord_tag, &root, 1, ptrarr, &size );CHECK_ERR( rval );
00319     }
00320 
00321     // write and read file
00322     Core moab2;
00323     Interface& mb2 = moab2;
00324     read_write( mesh_value ? "test_var_length_mesh_data.h5m" : "test_var_length_default_data.h5m", mb, mb2 );
00325     compare_tags( "handle_tag", mb, mb2 );
00326     compare_tags( "coord_tag", mb, mb2 );
00327 
00328     // get tag handles
00329     handle_tag = coord_tag = 0;
00330     rval                   = mb2.tag_get_handle( "handle_tag", 0, MB_TYPE_HANDLE, handle_tag );CHECK_ERR( rval );
00331     rval = mb2.tag_get_handle( "coord_tag", 0, MB_TYPE_DOUBLE, coord_tag );CHECK_ERR( rval );
00332 
00333     // get tag data
00334     int handle_tag_size = 0, coord_tag_size = 0;
00335     const void* ptrs[2];
00336     if( mesh_value )
00337     {
00338         const EntityHandle root = 0;
00339         rval                    = mb2.tag_get_by_ptr( handle_tag, &root, 1, ptrs, &handle_tag_size );CHECK_ERR( rval );
00340         rval = mb2.tag_get_by_ptr( coord_tag, &root, 1, ptrs + 1, &coord_tag_size );CHECK_ERR( rval );
00341     }
00342     else
00343     {
00344         rval = mb2.tag_get_default_value( handle_tag, ptrs[0], handle_tag_size );CHECK_ERR( rval );
00345         rval = mb2.tag_get_default_value( coord_tag, ptrs[1], coord_tag_size );CHECK_ERR( rval );
00346     }
00347 
00348     // check expected sizes
00349     CHECK_EQUAL( 3, handle_tag_size );
00350     CHECK_EQUAL( 9, coord_tag_size );
00351     CHECK( ptrs[0] != NULL );
00352     CHECK( ptrs[1] != NULL );
00353 
00354     // check valid handles
00355     const EntityHandle* handle_vals = reinterpret_cast< const EntityHandle* >( ptrs[0] );
00356     CHECK( handle_vals[0] != 0 );
00357     CHECK( handle_vals[1] != 0 );
00358     CHECK( handle_vals[2] != 0 );
00359     CHECK_EQUAL( MBVERTEX, mb2.type_from_handle( handle_vals[0] ) );
00360     CHECK_EQUAL( MBVERTEX, mb2.type_from_handle( handle_vals[1] ) );
00361     CHECK_EQUAL( MBVERTEX, mb2.type_from_handle( handle_vals[2] ) );
00362 
00363     // check correct coordinate values
00364     const double* coord_vals = reinterpret_cast< const double* >( ptrs[1] );
00365     rval                     = mb2.get_coords( handle_vals, 3, coords );CHECK_ERR( rval );
00366     CHECK_REAL_EQUAL( coords[0], coord_vals[0], 1e-12 );
00367     CHECK_REAL_EQUAL( coords[1], coord_vals[1], 1e-12 );
00368     CHECK_REAL_EQUAL( coords[2], coord_vals[2], 1e-12 );
00369     CHECK_REAL_EQUAL( coords[3], coord_vals[3], 1e-12 );
00370     CHECK_REAL_EQUAL( coords[4], coord_vals[4], 1e-12 );
00371     CHECK_REAL_EQUAL( coords[5], coord_vals[5], 1e-12 );
00372     CHECK_REAL_EQUAL( coords[6], coord_vals[6], 1e-12 );
00373     CHECK_REAL_EQUAL( coords[7], coord_vals[7], 1e-12 );
00374     CHECK_REAL_EQUAL( coords[8], coord_vals[8], 1e-12 );
00375 }
00376 
00377 void test_var_length_mesh_data()
00378 {
00379     test_global_value_common( true );
00380 }
00381 
00382 void test_var_length_default_data()
00383 {
00384     test_global_value_common( false );
00385 }
00386 
00387 void test_global_opaque_common( bool mesh_value )
00388 {
00389     ErrorCode rval;
00390     Core moab;
00391     Interface& mb = moab;
00392     create_mesh( mb );
00393 
00394     const char data[] = { 'J', 'A', 'S', 'O', 'N' };
00395     const int datalen = sizeof( data );
00396     CHECK_EQUAL( 5, datalen );
00397 
00398     // create tag
00399     Tag tag                 = 0;
00400     const void* default_val = mesh_value ? 0 : data;
00401     int default_val_size    = mesh_value ? 0 : datalen;
00402     rval                    = mb.tag_get_handle( "opaque_tag", default_val_size, MB_TYPE_OPAQUE, tag,
00403                                                  MB_TAG_DENSE | MB_TAG_VARLEN | MB_TAG_EXCL, default_val );CHECK_ERR( rval );
00404 
00405     // if doing mesh tag, set it
00406     if( mesh_value )
00407     {
00408         const void* ptrarr[]    = { data };
00409         const EntityHandle root = 0;
00410         rval                    = mb.tag_set_by_ptr( tag, &root, 1, ptrarr, &datalen );CHECK_ERR( rval );
00411     }
00412 
00413     // write and read file
00414     Core moab2;
00415     Interface& mb2 = moab2;
00416     read_write( mesh_value ? "test_var_length_mesh_opaque.h5m" : "test_var_length_default_opaque.h5m", mb, mb2 );
00417     compare_tags( "opaque_tag", mb, mb2 );
00418 
00419     // get tag handles
00420     tag  = 0;
00421     rval = mb2.tag_get_handle( "opaque_tag", 0, MB_TYPE_OPAQUE, tag );CHECK_ERR( rval );
00422 
00423     // get tag data
00424     int tag_size = 0;
00425     const void* ptrs[1];
00426     if( mesh_value )
00427     {
00428         const EntityHandle root = 0;
00429         rval                    = mb2.tag_get_by_ptr( tag, &root, 1, ptrs, &tag_size );CHECK_ERR( rval );
00430     }
00431     else
00432     {
00433         rval = mb2.tag_get_default_value( tag, ptrs[0], tag_size );CHECK_ERR( rval );
00434     }
00435 
00436     // check size
00437     CHECK_EQUAL( datalen, tag_size );
00438     CHECK( ptrs[0] != NULL );
00439 
00440     // check values
00441     const char* tag_data = reinterpret_cast< const char* >( ptrs[0] );
00442     for( int i = 0; i < datalen; ++i )
00443         CHECK_EQUAL( data[i], tag_data[i] );
00444 }
00445 
00446 void test_var_length_mesh_opaque()
00447 {
00448     test_global_opaque_common( true );
00449 }
00450 
00451 void test_var_length_default_opaque()
00452 {
00453     test_global_opaque_common( false );
00454 }
00455 
00456 void test_var_length_handle_tag()
00457 {
00458     ErrorCode rval;
00459     Core moab1, moab2;
00460     Interface &mb1 = moab1, &mb2 = moab2;
00461     Tag tag;
00462     Range::const_iterator i;
00463 
00464     create_mesh( mb1 );
00465     rval = mb1.tag_get_handle( "test_tag", 0, MB_TYPE_HANDLE, tag, MB_TAG_SPARSE | MB_TAG_VARLEN | MB_TAG_EXCL );CHECK_ERR( rval );
00466 
00467     // Get all entities
00468     Range range;
00469     rval = mb1.get_entities_by_handle( 0, range );CHECK_ERR( rval );
00470 
00471     // For each entity, if it is a vertex store its own handle
00472     // in its tag.  Otherwise store the element connectivity list
00473     // in the tag.  Skip entity sets.
00474     size_t num_tagged_entities = 0;
00475     for( i = range.begin(); i != range.end(); ++i )
00476     {
00477         EntityHandle h  = *i;
00478         EntityType type = mb1.type_from_handle( h );
00479         if( type == MBVERTEX )
00480         {
00481             const int size  = 1;
00482             const void* ptr = &h;
00483             rval            = mb1.tag_set_by_ptr( tag, &h, 1, &ptr, &size );CHECK_ERR( rval );
00484             ++num_tagged_entities;
00485         }
00486         else if( type != MBENTITYSET )
00487         {
00488             int size                 = 0;
00489             const EntityHandle* conn = 0;
00490             rval                     = mb1.get_connectivity( h, conn, size );CHECK_ERR( rval );
00491             const void* ptr = conn;
00492             rval            = mb1.tag_set_by_ptr( tag, &h, 1, &ptr, &size );CHECK_ERR( rval );
00493             ++num_tagged_entities;
00494         }
00495     }
00496 
00497     read_write( "test_var_length_handle_tag.h5m", mb1, mb2 );
00498     compare_tags( "test_tag", mb1, mb2 );
00499 
00500     // check number of tagged entities
00501     rval = mb2.tag_get_handle( "test_tag", 0, MB_TYPE_HANDLE, tag );CHECK_ERR( rval );
00502     range.clear();
00503     for( EntityType t = MBVERTEX; t != MBENTITYSET; ++t )
00504     {
00505         rval = mb2.get_entities_by_type_and_tag( 0, t, &tag, 0, 1, range, Interface::UNION );CHECK_ERR( rval );
00506     }
00507     CHECK_EQUAL( num_tagged_entities, range.size() );
00508 
00509     // check tag values
00510     for( i = range.begin(); i != range.end(); ++i )
00511     {
00512         EntityHandle h = *i;
00513 
00514         const void* ptr;
00515         int size;
00516         rval = mb2.tag_get_by_ptr( tag, &h, 1, &ptr, &size );CHECK_ERR( rval );
00517 
00518         const EntityHandle* handles = reinterpret_cast< const EntityHandle* >( ptr );
00519 
00520         if( mb2.type_from_handle( h ) == MBVERTEX )
00521         {
00522             CHECK_EQUAL( 1, size );
00523             CHECK_EQUAL( h, *handles );
00524         }
00525         else
00526         {
00527             int len;
00528             const EntityHandle* conn;
00529             rval = mb2.get_connectivity( h, conn, len );CHECK_ERR( rval );
00530             CHECK_EQUAL( len, size );
00531             for( int j = 0; j < len; ++j )
00532                 CHECK_EQUAL( conn[j], handles[j] );
00533         }
00534     }
00535 }
00536 
00537 void test_huge_var_length()
00538 {
00539     ErrorCode rval;
00540     Core moab1, moab2;
00541     Interface &mb1 = moab1, &mb2 = moab2;
00542     Tag tag;
00543     Range::const_iterator i;
00544 
00545     create_mesh( mb1 );
00546     rval = mb1.tag_get_handle( "test_tag", 0, MB_TYPE_DOUBLE, tag, MB_TAG_SPARSE | MB_TAG_VARLEN | MB_TAG_EXCL );CHECK_ERR( rval );
00547 
00548     // Get all entities
00549     Range range;
00550     rval = mb1.get_entities_by_handle( 0, range );CHECK_ERR( rval );
00551 
00552     // For each entity, if it is a vertex store its own handle
00553     // in its tag.  Otherwise store the element connectivity list
00554     // in the tag.  Skip entity sets.
00555     EntityHandle v1 = range[0];  // first vertex
00556     // huge data
00557     std::vector< double > dataArr;  // larger than the buffer
00558     int N = 2000;
00559     dataArr.resize( N );  // size will be 8 * N > bufferSize = 10000 set by option during writing
00560     for( int j = 0; j < N; j++ )
00561         dataArr[j] = j;
00562     const void* ptr = &dataArr[0];
00563     rval            = mb1.tag_set_by_ptr( tag, &v1, 1, &ptr, &N );CHECK_ERR( rval );
00564     // second vertex, do a smaller N
00565     v1    = range[1];
00566     int M = N - 5;
00567     ptr   = &dataArr[2];  // start with 2
00568     rval  = mb1.tag_set_by_ptr( tag, &v1, 1, &ptr, &M );CHECK_ERR( rval );
00569 
00570     // write with a smaller buffer, size controlled by option to test
00571     const char* writeOptions = "BUFFER_SIZE=4000;DEBUG_IO=5";
00572     rval                     = mb1.write_file( "test_huge_var_tag.h5m", NULL, writeOptions );CHECK_ERR( rval );
00573     rval = mb2.load_file( "test_huge_var_tag.h5m" );CHECK_ERR( rval );
00574     compare_tags( "test_tag", mb1, mb2 );
00575     // compare some values for the 2nd vertex
00576     Tag tag2;
00577     rval = mb2.tag_get_handle( "test_tag", tag2 );CHECK_ERR( rval );
00578     EntityHandle vertex2 = 2;
00579     int len2;
00580     const void* ptr2;
00581     rval = mb2.tag_get_by_ptr( tag2, &vertex2, 1, &ptr2, &len2 );CHECK_ERR( rval );
00582     CHECK_EQUAL( len2, M );
00583 
00584     CHECK_REAL_EQUAL( dataArr[2], ( (double*)ptr2 )[0], 0.000000001 );
00585 
00586     if( !keep_files ) remove( "test_huge_var_tag.h5m" );CHECK_ERR( rval );
00587 }
00588 void create_structured_quad_mesh( Interface& mb, int x, int y )
00589 {
00590     ErrorCode rval;
00591 
00592     const double z = 2.1;
00593     std::vector< EntityHandle > verts( ( x + 1 ) * ( y + 1 ) );
00594     for( int i = 0; i <= x; ++i )
00595     {
00596         for( int j = 0; j <= y; ++j )
00597         {
00598             double coords[3] = { static_cast< double >( i ), static_cast< double >( j ), static_cast< double >( z ) };
00599             rval             = mb.create_vertex( coords, verts[i + ( x + 1 ) * j] );CHECK_ERR( rval );
00600         }
00601     }
00602 
00603     std::vector< EntityHandle > elems( x * y );
00604     for( int i = 0; i < x; ++i )
00605     {
00606         for( int j = 0; j < y; ++j )
00607         {
00608             EntityHandle conn[4] = { verts[i + ( x + 1 ) * j], verts[i + 1 + ( x + 1 ) * j],
00609                                      verts[i + 1 + ( x + 1 ) * ( j + 1 )], verts[i + ( x + 1 ) * ( j + 1 )] };
00610             rval                 = mb.create_element( MBQUAD, conn, 4, elems[i + x * j] );CHECK_ERR( rval );
00611         }
00612     }
00613 }
00614 
00615 void create_mesh( Interface& mb )
00616 {
00617     create_structured_quad_mesh( mb, 2, 2 );
00618 }
00619 
00620 void create_big_mesh( Interface& mb )
00621 {
00622     create_structured_quad_mesh( mb, 300, 300 );
00623 }
00624 
00625 void compare_tags( const char* name, Interface& mb1, Interface& mb2 )
00626 {
00627     ErrorCode rval;
00628     Tag tag1, tag2;
00629     rval = mb1.tag_get_handle( name, 0, MB_TYPE_OPAQUE, tag1, MB_TAG_ANY );CHECK_ERR( rval );
00630     rval = mb2.tag_get_handle( name, 0, MB_TYPE_OPAQUE, tag2, MB_TAG_ANY );CHECK_ERR( rval );
00631 
00632     int size;
00633     CHECK_EQUAL( MB_VARIABLE_DATA_LENGTH, mb1.tag_get_length( tag1, size ) );
00634     CHECK_EQUAL( MB_VARIABLE_DATA_LENGTH, mb2.tag_get_length( tag2, size ) );
00635 
00636     TagType storage1, storage2;
00637     rval = mb1.tag_get_type( tag1, storage1 );CHECK_ERR( rval );
00638     rval = mb2.tag_get_type( tag2, storage2 );CHECK_ERR( rval );
00639     CHECK_EQUAL( storage1, storage2 );
00640 
00641     DataType type1, type2;
00642     rval = mb1.tag_get_data_type( tag1, type1 );CHECK_ERR( rval );
00643     rval = mb2.tag_get_data_type( tag2, type2 );CHECK_ERR( rval );
00644 
00645     const void *defval1, *defval2;
00646     int defsize1, defsize2;
00647     ErrorCode rval1 = mb1.tag_get_default_value( tag1, defval1, defsize1 );
00648     ErrorCode rval2 = mb2.tag_get_default_value( tag2, defval2, defsize2 );
00649     if( MB_SUCCESS == rval1 )
00650     {
00651         CHECK_ERR( rval2 );
00652 
00653         CHECK_EQUAL( defsize1, defsize2 );
00654         CHECK( !memcmp( defval1, defval2, defsize1 ) );
00655     }
00656     else if( MB_ENTITY_NOT_FOUND == rval1 || MB_TAG_NOT_FOUND == rval1 )
00657         CHECK_EQUAL( rval1, rval2 );
00658     else
00659         CHECK_ERR( rval1 );
00660 }
00661 
00662 void read_write( const char* filename, Interface& writer, Interface& reader )
00663 {
00664     ErrorCode rval = writer.write_file( filename );
00665     if( !keep_files && MB_SUCCESS != rval ) remove( filename );CHECK_ERR( rval );
00666     rval = reader.load_mesh( filename );
00667     if( !keep_files ) remove( filename );CHECK_ERR( rval );
00668 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines