35 static int id_contained(
long file_id,
const long* ranges,
int num_range );
38 static int ids_contained(
const long* ids,
int num_ids,
const long* ranges,
int num_ranges );
41 static int ranges_contained(
const long* id_ranges,
int num_id_ranges,
const long* ranges,
int num_ranges );
44 static int string_contained(
const char* str,
const char*
const*
const list );
96 const long* valid_ranges,
97 long num_valid_ranges,
119 static int lcomp(
const void* p1,
const void* p2 )
121 long l1 = *(
const long*)p1;
122 long l2 = *(
const long*)p2;
123 return l1 < l2 ? -1 : l1 > l2 ? 1 : 0;
127 static int dcomp(
const void* p1,
const void* p2 )
136 int main(
int argc,
char* argv[] )
141 unsigned long max_id;
144 if( argc < 2 || argc > 3 )
146 fprintf( stderr,
"Usage: %s <filename> <verbose_option> \n", argv[0] );
153 fprintf( stderr,
"%s: %s\n", argv[1],
mhdf_message( &status ) );
163 fprintf( stderr,
"%s: %s\n", argv[1],
mhdf_message( &status ) );
167 if( desc->
nodes.
count < 1 ) puts(
"WARNING: file contains no vertices." );
168 if( desc->
num_elem_desc < 1 ) puts(
"WARNING: file contains no elements." );
185 const size_t diff = (
char*)&junk.
desc - (
char*)&junk;
186 static const char nodes[] =
"Vertices";
187 static const char sets[] =
"Sets";
188 if( grp == &
desc->nodes )
return nodes;
189 if( grp == &
desc->sets )
return sets;
197 const int ngrp = 2 +
desc->num_elem_desc;
202 sorted[i++] = &desc->
nodes;
203 sorted[i] = &desc->
sets;
205 for( i = 0; i < ngrp; ++i )
207 if( sorted[i]->
count < 0 )
209 printf(
"Group \"%s\" has negative count!\n",
desc_name( desc, sorted[i] ) );
214 printf(
"Group \"%s\" contains NULL ID!\n",
desc_name( desc, sorted[i] ) );
220 printf(
"Conflicting group IDs for \"%s\" [%ld,%ld] and \"%s\" [%ld,%ld]\n",
234 const int blocksize = 512;
239 errorcode = stat( filename, &buf );
247 if( buf.st_size / blocksize > buf.st_blocks + 1 )
249 printf(
"File \"%s\" contains holes. This indicates that portions of the file were never "
261 int idx,
dim, result = 0;
279 static int id_contained(
long file_id,
const long* ranges,
int num_range )
281 const long* end = ranges + 2 * num_range;
282 for( ; ranges != end; ranges += 2 )
284 if( file_id >= ranges[0] && ( file_id - ranges[0] ) < ranges[1] )
return 1;
289 static int ids_contained(
const long* ids,
int num_ids,
const long* ranges,
int num_ranges )
292 for( i = 0; i < num_ids; ++i )
293 if( !
id_contained( ids[i], ranges, num_ranges ) )
return 0;
297 static int ranges_contained(
const long* id_ranges,
int num_id_ranges,
const long* ranges,
int num_ranges )
300 long start, count, avail;
301 const long* end = ranges + 2 * num_ranges;
303 for( i = 0; i < num_id_ranges; ++i )
305 start = id_ranges[2 * i];
306 count = id_ranges[2 * i + 1];
309 for( iter = ranges; iter != end; iter += 2 )
311 if( start >= iter[0] && ( start - iter[0] ) < iter[1] )
break;
313 if( iter == end )
return 0;
314 avail = iter[1] - ( start - iter[0] );
324 for( ; *list; ++list )
325 if( !strcmp( str, *list ) )
return 1;
340 char const*
const* typelist;
345 ranges = malloc( 2 *
sizeof(
long ) );
359 fprintf( stderr,
"Internal error at %s:%d: request for entities of dimesion %d\n", __FILE__, __LINE__,
367 ranges = malloc( *num_ranges_out * 2 *
sizeof(
long ) );
375 *num_ranges_out =
merge_ranges( ranges, *num_ranges_out );
381 long *ranges, *
buffer, *iter;
393 fprintf( stderr,
"Internal error opening connectivity for %s: %s\n", desc->
elems[idx].
handle,
399 buffer = malloc(
sizeof(
long ) * count * len );
403 fprintf( stderr,
"Internal error reading connectivity for %s: %s\n", desc->
elems[idx].
handle,
413 for( i = 0; i < count; ++i, iter += len )
418 printf(
"Invalid connectivity for element %ld (ID %ld) in %s\n", i, i + desc->
elems[idx].
desc.
start_id,
428 printf(
"%ld elements with invalid connectivity in %s\n", invalid, desc->
elems[idx].
handle );
442 long i, invalid = 0, prev = -1;
446 printf(
"WARNING: Empty index list for %s %s\n", name, typestr );
450 for( i = 0; i < num_idx; ++i )
452 if( indices[i] < prev )
457 printf(
"Invalid end index %ld for %s %ld (ID %ld). Prev index is %ld\n", indices[i], name, i,
458 i + start_id, prev );
460 printf(
"Invalid end index %ld for entry %ld in %s %s. Prev index is %ld\n", indices[i], i, name,
465 else if( indices[i] - prev < min_len )
470 printf(
"%s %ld (ID %ld) has only %ld values\n", name, i, start_id, indices[i] - prev );
472 printf(
"Entry %ld in %s %s has only %ld values\n", i, name, typestr, indices[i] - prev );
476 else if( indices[i] >= max_value )
481 printf(
"%s %ld (ID %ld) end index exceeds upper bound of %ld\n", name, i, start_id, max_value );
483 printf(
"Entry %ld in %s %s end index exceeds uppper bound of %ld\n", i, name, typestr, max_value );
492 printf(
"%ld invalid end indices for %s %s\n", invalid, typestr, name );
500 long *ranges, *
buffer, *indices, *iter;
502 long i, invalid, num_poly, num_conn, first_id, prev, len;
514 fprintf( stderr,
"Internal error opening connectivity for %s: %s\n", desc->
elems[idx].
handle,
519 indices = malloc(
sizeof(
long ) * num_poly );
523 fprintf( stderr,
"Internal error reading poly indices for %s: %s\n", desc->
elems[idx].
handle,
543 buffer = malloc(
sizeof(
long ) * num_conn );
547 fprintf( stderr,
"Internal error reading connectivity for %s: %s\n", desc->
elems[idx].
handle,
559 for( i = 0; i < num_poly; ++i )
561 len = indices[i] - prev;
566 printf(
"Invalid connectivity for element %ld (ID %ld) in %s\n", i, i + first_id,
578 printf(
"%ld elements with invalid connectivity in %s\n", invalid, desc->
elems[idx].
handle );
596 ranges = malloc(
sizeof(
long ) * 2 * num_ranges );
597 for( i = 0; i < num_ranges; ++i )
603 for( i = 0; i < num_ranges; ++i )
610 fprintf( stderr,
"Internal error openening adjacency list for %s: %s\n", desc->
elems[i].
handle,
616 buffer = malloc(
sizeof(
long ) * count );
620 fprintf( stderr,
"Internal error reading adjacency list for %s: %s\n", desc->
elems[i].
handle,
641 const long* valid_ranges,
642 long num_valid_ranges,
645 long i, n, id, invalid_id = 0, invalid_vals = 0;
646 const long* iter = data;
647 const long*
const end = data + data_len;
650 for( i = 0; iter != end; ++i )
656 printf(
"Entry %ld in %s adjacency data (ID %ld) is truncated by the end of the "
663 if(
id < start_id || (
id - start_id ) >= count )
666 printf(
"Entry %ld in %s adjacency data has ID %ld outside of group range [%ld,%ld].\n", i, name,
id,
667 start_id, start_id + count - 1 );
675 printf(
"Entry %ld in %s adjacency data (ID %ld) has %ld adjacency entries.\n", i, name,
id, n );
682 printf(
"Entry %ld in %s adjacency data (ID %ld) is truncated by the end of the "
689 if( !
ids_contained( iter, n, valid_ranges, num_valid_ranges ) )
692 printf(
"Entry %ld in %s adjacency data (ID %ld) has invalid IDs in its adjacency "
703 printf(
"%ld entries in %s adjacency data were for entities not in %s\n", invalid_id, name, name );
708 printf(
"%ld entries in %s adjacency data contained invalid adjacent entity ids\n", invalid_id, name );
716 long count, start_id, data_len;
726 fprintf( stderr,
"Internal error opening set description table: %s\n",
mhdf_message( &status ) );
735 fprintf( stderr,
"Internal error opening set contents table: %s\n",
mhdf_message( &status ) );
749 fprintf( stderr,
"Internal error opening set child table: %s\n",
mhdf_message( &status ) );
764 fprintf( stderr,
"Internal error opening set child table: %s\n",
mhdf_message( &status ) );
781 qsort( array, n,
sizeof(
long ), &
lcomp );
782 for( i = 1; i < n; ++i )
783 if( array[i - 1] == array[i] )
return 1;
790 qsort( ranges, nranges, 2 *
sizeof(
long ), &
lcomp );
791 for( i = 1; i < nranges; ++i )
792 if( ranges[2 * i - 2] + ranges[2 * i - 1] > ranges[2 * i] )
return 1;
804 long *indices, *contents;
805 const char parstr[] =
"Parent";
806 const char cldstr[] =
"Child";
807 const char* name = parents ? parstr : cldstr;
808 long i, prev, start, n;
809 long invalid = 0, invalid_dup = 0;
815 indices = malloc(
sizeof(
long ) * count );
822 fprintf( stderr,
"Internal error reading set %s end indices: %s\n", name,
mhdf_message( &status ) );
833 contents = malloc(
sizeof(
long ) * data_len );
837 fprintf( stderr,
"Internal error reading set %s IDs: %s\n", name,
mhdf_message( &status ) );
844 for( i = 0; i < count; ++i )
847 n = indices[i] - prev;
852 if(
verbose ) printf(
"Set %ld (ID %ld) has invalid %s IDs.\n", i, start_id + i, name );
857 if(
verbose ) printf(
"Set %ld (ID %ld) %s list contains duplicate IDs.\n", i, start_id + i, name );
867 printf(
"%ld sets had invalid %s lists.\n", invalid, name );
873 printf(
"%ld sets had duplicate handles in %s lists.\n", invalid_dup, name );
884 if( nranges < 1 )
return 0;
887 qsort( ranges, nranges, 2 *
sizeof(
long ), &
lcomp );
889 for( i = 1; i < nranges; ++i )
891 if( ranges[2 * n - 2] + ranges[2 * n - 1] == ranges[2 * i] )
893 ranges[2 * n - 1] += ranges[2 * i + 1];
898 ranges[2 * n] = ranges[2 * i];
899 ranges[2 * n + 1] = ranges[2 * i + 1];
909 int i, num_ranges = 0;
911 long* ranges = malloc( 2 *
sizeof(
long ) * ( desc->
num_elem_desc + 2 + !!include_null ) );
921 group = &desc->
nodes;
927 if( num_ranges && ranges[2 * num_ranges - 2] + ranges[2 * num_ranges - 1] == group->
start_id )
929 ranges[2 * num_ranges - 1] += group->
count;
933 ranges[2 * num_ranges] = group->
start_id;
934 ranges[2 * num_ranges + 1] = group->
count;
951 long *indices, *contents;
953 long i, prev, start, n;
954 long invalid_len = 0, invalid_handle = 0, invalid_dup = 0;
959 indices = malloc(
sizeof(
long ) *
count );
963 fprintf( stderr,
"Internal error reading set content end indices: %s\n",
mhdf_message( &status ) );
976 flags = malloc(
sizeof(
short ) *
count );
980 fprintf( stderr,
"Internal error reading set flags: %s\n",
mhdf_message( &status ) );
987 contents = malloc(
sizeof(
long ) * data_len );
988 mhdf_readSetData( data_handle, 0, data_len, H5T_NATIVE_LONG, contents, &status );
991 fprintf( stderr,
"Internal error reading set content IDs: %s\n",
mhdf_message( &status ) );
1000 for( i = 0; i <
count; ++i )
1003 n = indices[i] - prev;
1011 printf(
"Set %ld (ID %ld) is marked as range-compressed but has odd number of "
1012 "content values.\n",
1017 tmpresult =
ranges_contained( contents + start, n / 2, ranges, num_ranges );
1021 tmpresult =
ids_contained( contents + start, n, ranges, num_ranges );
1025 if(
verbose ) printf(
"Set %ld (ID %ld) has invalid content IDs.\n", i + 1,
start_id + i );
1039 printf(
"Set %ld (ID %ld) is not ordered but contains duplicate handles.\n", i + 1,
start_id + i );
1052 printf(
"%ld ranged sets had invalid (odd) content list lengths.\n", invalid_len );
1055 if( invalid_handle )
1057 printf(
"%ld sets had invalid IDs in their content lists.\n", invalid_handle );
1062 printf(
"%ld unordered sets had duplicate IDs in their content lists.\n", invalid_dup );
1084 long *ids = 0,
count, junk;
1091 long srange[2] = { 0, 0 };
1102 fprintf( stderr,
"Internal error opening sparse data for tag \"%s\": %s\n", tag->
name,
1107 ids = malloc(
sizeof(
long ) *
count );
1111 fprintf( stderr,
"Internal error reading sparse entities for tag \"%s\": %s\n", tag->
name,
1124 printf(
"Sparse data for tag \"%s\" has values for invalid IDs\n", tag->
name );
1129 printf(
"Sparse data for tag \"%s\" has duplicate values for one or more entities\n", tag->
name );
1138 group = &desc->
sets;
1143 group = &desc->
nodes;
1152 srange[1] = group->
count;
1156 printf(
"Tag \"%s\" has both sparse values and dense values for one or more "
1157 "entities in \"%s\"\n",
1175 printf(
"Handle tag \"%s\" has invalid ID(s) in its default value.\n", tag->
name );
1180 printf(
"Handle tag \"%s\" has invalid ID(s) in its global/mesh value.\n", tag->
name );
1183 h5type = H5T_NATIVE_LONG;
1187 #if defined( H5Tarray_create_vers ) && H5Tarray_create_vers > 1
1188 h5type = H5Tarray_create( H5T_NATIVE_LONG, 1, &
size );
1190 h5type = H5Tarray_create( H5T_NATIVE_LONG, 1, &
size, NULL );
1196 ids = malloc( tag->
size *
count *
sizeof(
long ) );
1200 fprintf( stderr,
"Internal error reading sparse values for handle tag \"%s\": %s\n", tag->
name,
1205 if( tag->
size > 1 ) H5Tclose( h5type );
1213 printf(
"Sparse data for one or more entities with handle tag \"%s\" has invalid ID(s).\n", tag->
name );
1239 fprintf( stderr,
"Internal dense values for handle tag \"%s\" on \"%s\": %s\n", tag->
name, name,
1245 ids = malloc( tag->
size *
count *
sizeof(
long ) );
1249 fprintf( stderr,
"Internal error reading dense values for handle tag \"%s\" on \"%s\": %s\n", tag->
name,
1261 printf(
"Dense data on \"%s\" for handle tag \"%s\" has invalid ID(s) for one or more "
1268 if( tag->
size > 1 ) H5Tclose( h5type );
1275 long *ids = 0,
count, num_val;
1285 printf(
"Dense data for tag \"%s\" not allowed for variable-length tags\n", tag->
name );
1294 fprintf( stderr,
"Internal error opening sparse data for tag \"%s\": %s\n", tag->
name,
1299 ids = malloc(
sizeof(
long ) * count );
1303 fprintf( stderr,
"Internal error reading sparse entities for tag \"%s\": %s\n", tag->
name,
1317 printf(
"Sparse data for tag \"%s\" has values for invalid IDs\n", tag->
name );
1322 printf(
"Sparse data for tag \"%s\" has duplicate values for one or more entities\n", tag->
name );
1329 fprintf( stderr,
"Internal error reading indices for variable length tag \"%s\": %s\n", tag->
name,
1352 printf(
"Handle tag \"%s\" has invalid ID(s) in its default value.\n", tag->
name );
1357 printf(
"Handle tag \"%s\" has invalid ID(s) in its global/mesh value.\n", tag->
name );
1362 ids = malloc( num_val *
sizeof(
long ) );
1366 fprintf( stderr,
"Internal error reading values for variable-length handle tag \"%s\": %s\n", tag->
name,
1378 printf(
"Data for one or more entities with variable-length handle tag \"%s\" has "