24 #define filename "h5test.h5m"
33 #define tagname "foo/\\/\\"
34 #define bitname "bar\n"
35 #define intname "int tag"
36 #define dblname " dbl "
37 #define handlename "hanlde"
53 int main(
int argc,
char* argv[] )
59 std::string write_opt(
"DEBUG_BINIO" );
61 for(
int i = 1; i < argc; ++i )
65 if( argv[i][0] ==
'-' && ( argv[i][1] ==
'r' || argv[i][1] ==
'w' ) && i + 1 < argc &&
66 ( val = strtol( argv[i + 1], &endptr, 0 ) ) >= 0 && !*endptr )
68 std::string& s = argv[i][1] ==
'r' ? read_opt : write_opt;
69 std::ostringstream str;
70 str <<
"DEBUG_IO=" << val;
82 std::cerr <<
"Usage: " << argv[0] <<
" [-r <n>] [-w <n>]" << std::endl;
90 fprintf( stderr,
"creating... " );
94 fprintf( stderr,
"writing... " );
98 fprintf( stderr,
"Failed to write \"%s\"\n",
filename );
105 fprintf( stderr,
"reading... " );
109 fprintf( stderr,
"Failed to read \"%s\"\n",
filename );
116 fprintf( stderr,
"comparing... " );
119 fprintf( stderr,
"Comparison failed.\n" );
123 fprintf( stderr,
"success!\n" );
126 fprintf( stderr,
"writing... " );
130 fprintf( stderr,
"Failed to write \"%s\"\n",
filename );
137 fprintf( stderr,
"clearing db... " );
142 fprintf( stderr,
"reading... " );
146 fprintf( stderr,
"Failed to read \"%s\"\n",
filename );
153 fprintf( stderr,
"comparing... " );
156 fprintf( stderr,
"Comparison failed.\n" );
160 fprintf( stderr,
"success!\n" );
163 fprintf( stderr,
"cleaning up... " );
169 fprintf( stderr,
"done.\n" );
176 const double p[3] = { x, y, z };
184 const EntityHandle conn[5] = { vtx_list[i1], vtx_list[i2], vtx_list[i3], vtx_list[i4], vtx_list[i5] };
203 for(
int i = (
int)num_entities - 1; i >= 0; --i )
222 const double r = 50.;
224 const double x = 0., y = 0., z = 0.;
226 const double cube = r * ( 2.0 / sqrt( 3.0 ) );
228 const double edge = cube * ( 2.0 / ( 1.0 + sqrt( 5.0 ) ) );
231 const double p = ( cube -
edge ) / 2.0;
234 const double d = sqrt(
edge *
edge - cube * cube / 4 - p );
236 const double c = cube / 2.0;
237 const double a = c + d;
238 const double b =
edge / 2.0;
250 vertices[0] =
vtx( x - c, y + c, z + c );
251 vertices[1] =
vtx( x + c, y + c, z + c );
252 vertices[2] =
vtx( x + c, y - c, z + c );
253 vertices[3] =
vtx( x - c, y - c, z + c );
254 vertices[4] =
vtx( x - c, y + c, z - c );
255 vertices[5] =
vtx( x + c, y + c, z - c );
256 vertices[6] =
vtx( x + c, y - c, z - c );
257 vertices[7] =
vtx( x - c, y - c, z - c );
264 vertices[8] =
vtx( x - b, y, z + a );
265 vertices[9] =
vtx( x + b, y, z + a );
267 vertices[10] =
vtx( x + a, y + b, z );
268 vertices[11] =
vtx( x + a, y - b, z );
270 vertices[12] =
vtx( x - b, y, z - a );
271 vertices[13] =
vtx( x + b, y, z - a );
273 vertices[14] =
vtx( x - a, y + b, z );
274 vertices[15] =
vtx( x - a, y - b, z );
276 vertices[16] =
vtx( x, y + a, z + b );
277 vertices[17] =
vtx( x, y + a, z - b );
279 vertices[18] =
vtx( x, y - a, z + b );
280 vertices[19] =
vtx( x, y - a, z - b );
283 faces[0] =
pent( vertices, 0, 8, 9, 1, 16 );
284 faces[1] =
pent( vertices, 3, 18, 2, 9, 8 );
285 faces[2] =
pent( vertices, 2, 11, 10, 1, 9 );
286 faces[3] =
pent( vertices, 2, 18, 19, 6, 11 );
287 faces[4] =
pent( vertices, 1, 10, 5, 17, 16 );
288 faces[5] =
pent( vertices, 5, 10, 11, 6, 13 );
289 faces[6] =
pent( vertices, 4, 17, 5, 13, 12 );
290 faces[7] =
pent( vertices, 7, 12, 13, 6, 19 );
291 faces[8] =
pent( vertices, 4, 12, 7, 15, 14 );
292 faces[9] =
pent( vertices, 0, 16, 17, 4, 14 );
293 faces[10] =
pent( vertices, 3, 15, 7, 19, 18 );
294 faces[11] =
pent( vertices, 0, 14, 15, 3, 8 );
306 for(
int i = 0; i < 20; ++i )
326 int idata[] = {
static_cast< int >( 0xDEADBEEF ),
static_cast< int >( 0xDEFACED ) };
331 double ddef = 3.14159;
351 EntityHandle face_set, vertex_set, region_set, empty_set;
358 EntityHandle sets[] = { face_set, vertex_set, region_set, empty_set };
367 bool compare_conn( std::vector< EntityHandle >& conn1, std::vector< EntityHandle >& conn2 )
371 if( conn1.size() != conn2.size() || conn1.size() == 0 )
373 fprintf( stderr,
"Error comparing connectivity: sizes %lu and %lu\n", (
unsigned long)conn1.size(),
374 (
unsigned long)conn2.size() );
378 std::vector< double > coords[2];
379 coords[0].resize( 3 * conn1.size() );
380 coords[1].resize( 3 * conn2.size() );
383 coords[0].size() != coords[1].size() )
386 std::vector< double >::iterator citer1 = coords[0].begin(), citer2 = coords[1].begin();
387 for( i = 0; i < conn1.size(); i++ )
389 double x1 = *( citer1++ ), y1 = *( citer1++ ), z1 = *( citer1++ );
390 double x2 = *( citer2++ ), y2 = *( citer2++ ), z2 = *( citer2++ );
391 if( x1 != x2 || y1 != y2 || z1 != z2 )
393 fprintf( stderr,
"Vertex coords don't match: ( %f, %f, %f ) and ( %f, %f, %f )\n", x1, y1, z1, x2, y2, z2 );
398 std::vector< int > tags[2];
399 tags[0].resize( conn1.size() );
400 tags[1].resize( conn2.size() );
407 std::vector< int >::iterator titer1 = tags[0].begin(), titer2 = tags[1].begin();
408 for( i = 0; i < conn1.size(); i++ )
410 int t1 = *( titer1++ );
411 int t2 = *( titer2++ );
414 fprintf( stderr,
"Vertex tags don't match: %d != %d\n", t1, t2 );
437 const void* tag_data[] = { &
id };
441 fprintf( stderr,
"Could not find set with id %d pair in file\n",
id );
451 unsigned opt1 = 0, opt2 = 0;
460 "Sets with id %d do not have matching options.\n"
461 "Set 1: track_owner=%s set=%s ordered=%s\n"
462 "Set 2: track_owner=%s set=%s ordered=%s\n",
465 opt2 &
MESHSET_SET ?
"yes" :
"no", opt2 & MESHSET_ORDERED ?
"yes" :
"no" );
475 std::vector< EntityHandle > list1, list2;
481 if( list1.size() != list2.size() )
484 "Sets with id %d do not have the same number of entities.\n"
485 "Set 1 : %u Set 2 : %u\n",
486 id, (
unsigned)list1.size(), (
unsigned)list2.size() );
495 fprintf( stderr,
"Could not find tag \"%s\" in file.\n", tag_name );
504 std::vector< int > data1( list1.size() ), data2( list2.size() );
509 if( !( opt1 & MESHSET_ORDERED ) )
511 std::sort( data1.begin(), data1.end() );
512 std::sort( data2.begin(), data2.end() );
515 for(
unsigned i = 0; i < data1.size(); ++i )
516 if( data1[i] != data2[i] )
518 fprintf( stderr,
"Entities in sets with id %d do not have matching tag values.\n",
id );
522 else if( opt1 & MESHSET_ORDERED )
525 for(
unsigned i = 0; i < list1.size(); ++i )
529 "Entities at position %u in ordered sets with id %d\n"
530 "have different types.\n",
534 if( !ok )
return false;
539 memset( counts1, 0,
MBMAXTYPE *
sizeof(
unsigned ) );
540 memset( counts2, 0,
MBMAXTYPE *
sizeof(
unsigned ) );
541 for(
unsigned i = 0; i < list1.size(); ++i )
549 if( counts1[j] != counts2[j] )
551 fprintf( stderr,
"Sets with id %d have differing numbers of %s: %u and %u\n",
id,
555 if( !ok )
return false;
561 const char* words[] = {
"children",
"parents" };
562 std::vector< EntityHandle > adj1, adj2;
563 for(
unsigned two = 0; two < 2; ++two )
580 if( adj1.size() != adj2.size() )
582 fprintf( stderr,
"Sets with id %d have different number of %s: %u and %u\n",
id, words[two],
583 (
unsigned)adj1.size(), (
unsigned)adj2.size() );
588 std::vector< int > ids1( adj1.size() ), ids2( adj2.size() );
590 for( i = 0; i < adj1.size(); ++i )
605 std::sort( ids1.begin(), ids1.end() );
606 std::sort( ids2.begin(), ids2.end() );
607 for( i = 0; i < ids1.size(); ++i )
609 if( ids1[i] != ids2[i] )
611 fprintf( stderr,
"Sets with id %d have non-matching %s\n",
id, words[two] );
632 fprintf( stderr,
"tag_get_default_value() for nonexistant default integer tag value did "
633 "not fail correctly.\n" );
639 if( idata[0] != (
int)0xDEADBEEF || idata[1] != (
int)0xDEFACED || idata[2] != idata[0] || idata[3] != idata[1] )
641 fprintf( stderr,
"Incorrect values for integer tag data.\n" );
652 if( ddata[0] != 3.14159 )
654 fprintf( stderr,
"incorrect default value for double tag.\n" );
660 if( ddata[0] != .333 || ddata[0] != ddata[1] )
662 fprintf( stderr,
"Incorrect values for double tag data.\n" );
679 fprintf( stderr,
"incorrect default value for handle tag '%s'\n",
handlename );
690 fprintf( stderr,
"incorrect global/mesh value for handle tag.\n" );
701 fprintf( stderr,
"Incorrect values for handle tag data.\n" );
705 if( memcmp( conn, hdata + 3, 3 *
sizeof(
EntityHandle ) ) )
707 fprintf( stderr,
"Incorrect values for handle tag data.\n" );
727 const void* tarray[] = { &two };
730 if( range.
size() != 2 )
732 fprintf( stderr,
"Expected 2 Hexes. Got %lu\n", (
unsigned long)range.
size() );
735 iter = range.
begin();
742 const void* oarray[] = { &one };
745 if( range.
size() != 2 )
747 fprintf( stderr,
"Expected 2 Polyhedra. Got %lu\n", (
unsigned long)range.
size() );
750 iter = range.
begin();
755 std::vector< EntityHandle > conn[2];
763 std::vector< EntityHandle >
face[2];
769 if( conn[0].
size() != 12 || conn[1].
size() != 12 )
772 "Expected two dodecahedrons. Got polyhedrons with "
773 "%lu and %lu faces respectively.\n",
774 (
unsigned long)conn[0].
size(), (
unsigned long)conn[1].
size() );
778 for(
int i = 0; i < 12; ++i )
803 fprintf( stderr,
"%s() failed.\n", str );