29 #if defined( _MSC_VER )
31 #elif defined( __MINGW32__ )
44 #include <H5Tpublic.h>
45 #include <H5Ppublic.h>
46 #include <H5Epublic.h>
56 #ifndef MOAB_HAVE_HDF5
57 #error Attempt to compile WriteHDF5 with HDF5 support disabled
60 #undef BLOCKED_COORD_IO
62 #ifdef MOAB_HAVE_VALGRIND
63 #include <valgrind/memcheck.h>
65 template <
typename T >
72 #ifndef VALGRIND_CHECK_MEM_IS_DEFINED
73 #define VALGRIND_CHECK_MEM_IS_DEFINED( a, b ) ( (void)0 )
75 #ifndef VALGRIND_CHECK_MEM_IS_ADDRESSABLE
76 #define VALGRIND_CHECK_MEM_IS_ADDRESSABLE( a, b ) ( (void)0 )
78 #ifndef VALGRIND_MAKE_MEM_UNDEFINED
79 #define VALGRIND_MAKE_MEM_UNDEFINED( a, b ) ( (void)0 )
82 template <
typename T >
93 #define WRITE_HDF5_BUFFER_SIZE ( 40 * 1024 * 1024 )
99 if( 8 ==
sizeof(
long ) )
100 return H5T_NATIVE_ULONG;
102 return H5T_NATIVE_UINT64;
106 if( 4 ==
sizeof(
int ) )
107 return H5T_NATIVE_UINT;
109 return H5T_NATIVE_UINT32;
133 #if defined( H5E_auto_t_vers ) && H5E_auto_t_vers > 1
136 WriteHDF5::HDF5ErrorHandler* h =
reinterpret_cast< WriteHDF5::HDF5ErrorHandler*
>( data );
138 if( h->func ) result = ( *h->func )( stack, h->data );
164 #define CHK_MHDF_ERR_0( A ) \
167 if( mhdf_isError( &( A ) ) ) \
169 MB_SET_ERR_CONT( mhdf_message( &( A ) ) ); \
171 return error( MB_FAILURE ); \
175 #define CHK_MHDF_ERR_1( A, B ) \
178 if( mhdf_isError( &( A ) ) ) \
180 MB_SET_ERR_CONT( mhdf_message( &( A ) ) ); \
182 mhdf_closeData( filePtr, ( B ), &( A ) ); \
183 return error( MB_FAILURE ); \
187 #define CHK_MHDF_ERR_2( A, B ) \
190 if( mhdf_isError( &( A ) ) ) \
192 MB_SET_ERR_CONT( mhdf_message( &( A ) ) ); \
194 mhdf_closeData( filePtr, ( B )[0], &( A ) ); \
195 mhdf_closeData( filePtr, ( B )[1], &( A ) ); \
196 return error( MB_FAILURE ); \
200 #define CHK_MHDF_ERR_3( A, B ) \
203 if( mhdf_isError( &( A ) ) ) \
205 MB_SET_ERR_CONT( mhdf_message( &( A ) ) ); \
207 mhdf_closeData( filePtr, ( B )[0], &( A ) ); \
208 mhdf_closeData( filePtr, ( B )[1], &( A ) ); \
209 mhdf_closeData( filePtr, ( B )[2], &( A ) ); \
210 return error( MB_FAILURE ); \
214 #define CHK_MHDF_ERR_2C( A, B, C, D ) \
217 if( mhdf_isError( &( A ) ) ) \
219 MB_SET_ERR_CONT( mhdf_message( &( A ) ) ); \
221 mhdf_closeData( filePtr, ( B ), &( A ) ); \
222 if( C ) mhdf_closeData( filePtr, ( D ), &( A ) ); \
223 return error( MB_FAILURE ); \
227 #define CHK_MB_ERR_0( A ) \
230 if( MB_SUCCESS != ( A ) ) \
232 MB_CHK_ERR_CONT( ( A ) ); \
237 #define CHK_MB_ERR_1( A, B, C ) \
240 if( MB_SUCCESS != ( A ) ) \
242 MB_CHK_ERR_CONT( ( A ) ); \
243 mhdf_closeData( filePtr, ( B ), &( C ) ); \
249 #define CHK_MB_ERR_2( A, B, C ) \
252 if( MB_SUCCESS != ( A ) ) \
254 MB_CHK_ERR_CONT( ( A ) ); \
255 mhdf_closeData( filePtr, ( B )[0], &( C ) ); \
256 mhdf_closeData( filePtr, ( B )[1], &( C ) ); \
263 #define CHK_MB_ERR_3( A, B, C ) \
266 if( MB_SUCCESS != ( A ) ) \
268 MB_CHK_ERR_CONT( ( A ) ); \
269 mhdf_closeData( filePtr, ( B )[0], &( C ) ); \
270 mhdf_closeData( filePtr, ( B )[1], &( C ) ); \
271 mhdf_closeData( filePtr, ( B )[2], &( C ) ); \
278 #define CHK_MB_ERR_2C( A, B, C, D, E ) \
281 if( MB_SUCCESS != ( A ) ) \
283 MB_CHK_ERR_CONT( ( A ) ); \
284 mhdf_closeData( filePtr, ( B ), &( E ) ); \
285 if( C ) mhdf_closeData( filePtr, ( D ), &( E ) ); \
292 #define debug_barrier() debug_barrier_line( __LINE__ )
312 std::cout <<
"Leaked HDF5 object handle in function at " << __FILE__ <<
":" <<
fileline << std::endl
313 <<
"Open at entrance: " <<
enter_count << std::endl
314 <<
"Open at exit: " << new_count << std::endl;
323 #define CHECK_OPEN_HANDLES
325 #define CHECK_OPEN_HANDLES CheckOpenWriteHDF5Handles check_open_handles_( filePtr, __LINE__ )
330 bool some_valid =
false;
331 for(
size_t i = 0; i < count; ++i )
338 if( dest[i] ) some_valid =
true;
354 for( pi =
entities.const_pair_begin(); pi !=
entities.const_pair_end(); ++pi )
357 dbgOut.
printf( 3,
"Assigning %s %lu to %lu to file IDs [%lu,%lu]\n",
360 (
unsigned long)(
ID_FROM_HANDLE( pi->first ) + n - 1 ), (
unsigned long)
id,
361 (
unsigned long)(
id + n - 1 ) );
364 int num_vertices = 0;
367 dbgOut.
printf( 3,
" poly with %d verts/faces \n", num_vertices );
426 #if defined( H5Eget_auto_vers ) && H5Eget_auto_vers > 1
438 #if defined( H5Eset_auto_vers ) && H5Eset_auto_vers > 1
451 if( !
subState.valid() )
subState = MPEState(
"WriteHDF5 subevent",
"cyan" );
466 #if defined( H5Eget_auto_vers ) && H5Eget_auto_vers > 1
467 herr_t err = H5Eget_auto( H5E_DEFAULT, &handler.
func, &handler.
data );
469 herr_t err = H5Eget_auto( &handler.
func, &handler.
data );
474 #if defined( H5Eget_auto_vers ) && H5Eget_auto_vers > 1
497 const std::vector< std::string >& qa_records,
543 bool created_file =
false;
552 if(
MB_SUCCESS == result ) result = MB_FAILURE;
574 const std::vector< std::string >& qa_records,
580 std::list< TagDesc >::const_iterator t_itor;
581 std::list< ExportSet >::iterator ex_itor;
588 bool cputime =
false;
599 if( 0 == num_sets || ( 1 == num_sets && set_array[0] == 0 ) )
607 std::vector< EntityHandle > passed_export_list( set_array, set_array + num_sets );
623 elem_count += ex_itor->range.size();
625 if( elem_count > max_id )
628 return error( result );
638 if( user_dimension < 1 ) user_dimension = mesh_dim;
639 user_dimension = user_dimension > mesh_dim ? mesh_dim : user_dimension;
643 const char* optnames[] = {
"WRITE_PART",
"FORMAT", 0 };
655 parallel_create_file( filename, overwrite, qa_records, opts, tag_list, num_tags, user_dimension, times );
659 result =
serial_create_file( filename, overwrite, qa_records, tag_list, num_tags, user_dimension );
682 topState.start(
"writing connectivity for ", ex_itor->name() );
701 #ifdef MB_H5M_WRITE_NODE_ADJACENCIES
707 topState.start(
"writing adjacencies for ", ex_itor->name() );
717 for( t_itor =
tagList.begin(); t_itor !=
tagList.end(); ++t_itor )
721 topState.start(
"writing tag: ", name.c_str() );
742 if( !ranges[0].all_of_type(
MBVERTEX ) )
return error( MB_FAILURE );
756 std::vector< Range > bins( 1024 );
766 assert(
dim >= 0 &&
dim <= 4 );
767 std::pair< Range::const_iterator, Range::const_iterator > p = ranges[
dim].
equal_range( type );
769 while( i != p.second )
776 std::vector< EntityHandle > storage;
781 for( ++i; i != p.second; ++i )
786 if( len != firstlen )
break;
789 if( firstlen >= (
int)bins.size() ) bins.resize( firstlen + 1 );
790 bins[firstlen].merge(
first, i );
793 for( std::vector< Range >::iterator j = bins.begin(); j != bins.end(); ++j )
795 if( j->empty() )
continue;
818 std::vector< EntityHandle > stack( export_sets );
819 std::copy( export_sets.begin(), export_sets.end(), stack.begin() );
820 std::vector< EntityHandle > set_children;
821 while( !stack.empty() )
825 ranges[4].
insert( meshset );
833 if( ranges[4].
find( *ritor ) == ranges[4].end() ) stack.push_back( *ritor );
837 set_children.clear();
840 for( std::vector< EntityHandle >::iterator vitor = set_children.begin(); vitor != set_children.end(); ++vitor )
842 if( ranges[4].
find( *vitor ) == ranges[4].end() ) stack.push_back( *vitor );
848 for(
Range::iterator setitor = ranges[4].begin(); setitor != ranges[4].
end(); ++setitor )
864 for(
int cdim = 1; cdim <
dim; ++cdim )
869 ranges[cdim].
merge( range );
874 ranges[0].
merge( range );
910 long first_id, num_nodes;
926 #ifdef BLOCKED_COORD_IO
927 int chunk_size =
bufferSize /
sizeof( double );
929 int chunk_size =
bufferSize / ( 3 *
sizeof( double ) );
933 long num_writes = ( remaining + chunk_size - 1 ) / chunk_size;
939 long remaining_writes = num_writes;
943 dbgOut.
printf( 3,
"Writing %ld nodes in %ld blocks of %d\n", remaining, ( remaining + chunk_size - 1 ) / chunk_size,
948 long count = chunk_size < remaining ? chunk_size : remaining;
953 #ifdef BLOCKED_COORD_IO
954 for(
int d = 0; d <
dim; d++ )
962 memset(
buffer, 0, count *
sizeof(
double ) );
964 dbgOut.
printf( 3,
" writing %c node chunk %ld of %ld, %ld values at %ld\n", (
char)(
'X' + d ),
965 num_writes - remaining_writes + 1, num_writes, count, offset );
972 dbgOut.
printf( 3,
" writing node chunk %ld of %ld, %ld values at %ld\n", num_writes - remaining_writes + 1,
973 num_writes, count, offset );
987 while( remaining_writes-- )
990 #ifdef BLOCKED_COORD_IO
991 for(
int d = 0; d <
dim; ++d )
993 dbgOut.
printf( 3,
" writing (empty) %c node chunk %ld of %ld.\n", (
char)(
'X' + d ),
994 num_writes - remaining_writes, num_writes );
999 dbgOut.
printf( 3,
" writing (empty) node chunk %ld of %ld.\n", num_writes - remaining_writes, num_writes );
1033 assert( (
unsigned long)first_id <= elems.
first_id );
1034 assert( (
unsigned long)table_size >= elems.
offset + elems.
range.
size() );
1038 long offset = elems.
offset;
1040 long num_writes = ( remaining + chunk_size - 1 ) / chunk_size;
1044 num_writes = ( elems.
max_num_ents + chunk_size - 1 ) / chunk_size;
1046 long remaining_writes = num_writes;
1052 long count = chunk_size < remaining ? chunk_size : remaining;
1061 for(
long i = 0; i < count * nodes_per_elem; ++i )
1068 return error( MB_FAILURE );
1072 dbgOut.
printf( 3,
" writing node connectivity %ld of %ld, %ld values at %ld\n",
1073 num_writes - remaining_writes + 1, num_writes, count, offset );
1085 while( remaining_writes-- )
1088 dbgOut.
printf( 3,
" writing (empty) connectivity chunk %ld of %ld.\n", num_writes - remaining_writes + 1,
1106 unsigned long& flags )
1135 Range* null_stripped,
1136 std::vector< long >* set_sizes )
1146 void ( *write_func )( hid_t, long, long, hid_t,
const void*, hid_t,
mhdf_Status* );
1149 switch( which_data )
1152 assert( ranged != 0 && null_stripped != 0 && set_sizes != 0 );
1159 assert( !ranged && !null_stripped && !set_sizes );
1166 assert( !ranged && !null_stripped && !set_sizes );
1183 const size_t num_total_writes = ( max_vals + buffer_size - 1 ) / buffer_size;
1185 std::vector< SpecialSetData >::iterator si =
specialSets.begin();
1187 std::vector< wid_t > remaining;
1188 size_t remaining_offset = 0;
1190 size_t remaining_count = 0;
1191 const wid_t* special_rem_ptr = 0;
1193 if( ranged ) rhint = ranged->
begin();
1194 if( null_stripped ) nshint = null_stripped->
begin();
1195 for(
size_t w = 0; w < num_total_writes; ++w )
1197 if( i ==
setSet.
range.
end() && !remaining.empty() && !remaining_ptr )
1210 if( !remaining.empty() )
1212 count = remaining.size() - remaining_offset;
1213 if( count > buffer_size )
1215 memcpy(
buffer, &remaining[remaining_offset], buffer_size *
sizeof(
wid_t ) );
1216 count = buffer_size;
1217 remaining_offset += buffer_size;
1221 memcpy(
buffer, &remaining[remaining_offset], count *
sizeof(
wid_t ) );
1222 remaining_offset = 0;
1228 else if( remaining_ptr )
1230 if( remaining_count > buffer_size )
1234 count = buffer_size;
1235 remaining_ptr += count;
1236 remaining_count -= count;
1242 count = remaining_count;
1244 remaining_count = 0;
1249 else if( special_rem_ptr )
1251 if( remaining_count > buffer_size )
1253 memcpy(
buffer, special_rem_ptr, buffer_size *
sizeof(
wid_t ) );
1254 count = buffer_size;
1255 special_rem_ptr += count;
1256 remaining_count -= count;
1260 memcpy(
buffer, special_rem_ptr, remaining_count *
sizeof(
wid_t ) );
1261 count = remaining_count;
1262 special_rem_ptr = 0;
1263 remaining_count = 0;
1274 if( si !=
specialSets.end() && si->setHandle == *i )
1279 size_t append = list.size();
1280 if( count + list.size() > buffer_size )
1282 append = buffer_size - count;
1283 special_rem_ptr = &list[append];
1284 remaining_count = list.size() - append;
1286 memcpy(
buffer + count, &list[0], append *
sizeof(
wid_t ) );
1297 unsigned char flags;
1308 assert( !( len % 2 ) );
1314 rhint = ranged->
insert( rhint, *j );
1315 set_sizes->push_back( remaining.size() );
1317 else if( remaining.size() != (
unsigned)len )
1319 nshint = null_stripped->
insert( nshint, *j );
1320 set_sizes->push_back( remaining.size() );
1323 if( count + remaining.size() <= buffer_size )
1325 if( !remaining.empty() )
1326 memcpy(
buffer + count, &remaining[0],
sizeof(
wid_t ) * remaining.size() );
1327 count += remaining.size();
1329 remaining_offset = 0;
1333 remaining_offset = buffer_size - count;
1334 memcpy(
buffer + count, &remaining[0],
sizeof(
wid_t ) * remaining_offset );
1335 count += remaining_offset;
1340 if( count + len > buffer_size )
1342 size_t append = buffer_size - count;
1343 remaining_ptr = ptr + append;
1344 remaining_count = len - append;
1367 long first_id,
size;
1382 topState.start(
"writing parent lists for local sets" );
1401 topState.start(
"writing child lists for local sets" );
1418 Range ranged_sets, null_stripped_sets;
1419 std::vector< long > set_sizes;
1422 topState.start(
"writing content lists for local sets" );
1437 assert( ranged_sets.
size() + null_stripped_sets.
size() == set_sizes.size() );
1442 topState.start(
"writing descriptions of local sets" );
1459 const size_t num_local_writes = (
setSet.
range.
size() + buffer_size - 1 ) / buffer_size;
1460 const size_t num_global_writes = (
setSet.
max_num_ents + buffer_size - 1 ) / buffer_size;
1461 assert( num_local_writes <= num_global_writes );
1462 assert( num_global_writes > 0 );
1471 std::vector< mhdf_index_t >::const_iterator n = set_sizes.begin();
1472 assert( ranged_sets.
size() + null_stripped_sets.
size() == set_sizes.size() );
1481 std::vector< SpecialSetData >::const_iterator si =
specialSets.begin();
1482 for(
size_t w = 0; w < num_local_writes; ++w )
1489 long num_ent, num_child, num_parent;
1490 unsigned long flags;
1491 if( si !=
specialSets.end() && si->setHandle == *i )
1493 flags = si->setFlags;
1494 num_ent = si->contentIds.size();
1495 num_child = si->childIds.size();
1496 num_parent = si->parentIds.size();
1498 if( r != ranged_sets.
end() && *i == *r )
1504 else if( s != null_stripped_sets.
end() && *i == *s )
1512 assert( si ==
specialSets.end() || si->setHandle > *i );
1515 rval =
get_set_info( *i, num_ent, num_child, num_parent, flags );
1519 if( r != ranged_sets.
end() && *i == *r )
1526 else if( s != null_stripped_sets.
end() && *i == *s )
1536 prev_contents_end += num_ent;
1537 prev_children_end += num_child;
1538 prev_parents_end += num_parent;
1539 local[0] = prev_contents_end;
1540 local[1] = prev_children_end;
1541 local[2] = prev_parents_end;
1555 assert( r == ranged_sets.
end() );
1556 assert( s == null_stripped_sets.
end() );
1557 assert( n == set_sizes.end() );
1562 for(
size_t w = num_local_writes; w != num_global_writes; ++w )
1578 template <
class HandleRangeIter >
1582 for( ; iter != end; ++iter )
1583 result += iter->second - iter->first + 1;
1588 template <
class HandleRangeIter >
1590 HandleRangeIter end,
1597 for( HandleRangeIter pi = begin; pi != end; ++pi )
1600 while( h <= pi->second )
1603 if( ri == idMap.
end() || ri->
begin > h )
1616 WriteHDF5::wid_t step_until = std::min( last_valid_input_value_in_current_map_range, pi->second );
1631 template <
class HandleRangeIter >
1633 HandleRangeIter end,
1635 std::vector< WriteHDF5::wid_t >& output_id_list,
1638 output_id_list.clear();
1641 ranged_list =
false;
1652 size_t pairs_remaining = num_handles / 2;
1653 for( HandleRangeIter pi = begin; pi != end; ++pi )
1657 while( h <= pi->second )
1660 if( ri == idMap.
end() || ri->
begin > h )
1666 WriteHDF5::wid_t n = pi->second - pi->first + 1 - local_mapped_from_subrange;
1667 if( n > ri->count ) n = ri->count;
1671 if(
id + n > ri->value + ri->count )
1673 if( ri->value + ri->count -
id > 0 ) n = ri->value + ri->count - id;
1677 if( !output_id_list.empty() && output_id_list[output_id_list.size() - 2] + output_id_list.back() == id )
1679 output_id_list.
back() += n;
1683 else if( !pairs_remaining )
1685 ranged_list =
false;
1686 output_id_list.resize( num_handles );
1688 output_id_list.erase( std::remove( output_id_list.begin(), output_id_list.end(), 0u ),
1689 output_id_list.end() );
1697 output_id_list.push_back(
id );
1698 output_id_list.push_back( n );
1700 local_mapped_from_subrange += n;
1710 std::vector< wid_t >& output_id_list,
1714 output_id_list, ranged_list );
1718 size_t num_input_ranges,
1719 std::vector< wid_t >& output_id_list,
1723 typedef std::pair< EntityHandle, EntityHandle > mtype;
1724 assert(
sizeof( mtype ) == 2 *
sizeof(
EntityHandle ) );
1725 const mtype* arr =
reinterpret_cast< const mtype*
>( array );
1743 for( ; i_iter != i_end; ++i_iter )
1746 if( !remove_zeros ||
id != 0 )
1752 output_len = o_iter -
output;
1758 std::vector< wid_t >&
output,
1761 output.resize( input.size() );
1762 size_t output_size = 0;
1764 output.resize( output_size );
1782 adj.resize( num_adj );
1783 for(
int i = 0; i < num_adj; ++i )
1796 std::vector< wid_t > adj_list;
1826 long num_writes = ( elements.
max_num_adjs + chunk_size - 1 ) / chunk_size;
1829 for( iter = elements.
range.
begin(); iter != end; ++iter )
1834 if( adj_list.size() == 0 )
continue;
1837 if( count + adj_list.size() + 2 > (
unsigned long)chunk_size )
1850 buffer[count++] = adj_list.size();
1852 assert( adj_list.size() + 2 < (
unsigned long)chunk_size );
1853 memcpy(
buffer + count, &adj_list[0], adj_list.size() *
sizeof(
wid_t ) );
1854 count += adj_list.size();
1859 dbgOut.
print( 2,
" writing final adjacency chunk.\n" );
1871 while( num_writes > 0 )
1875 dbgOut.
print( 2,
" writing empty adjacency chunk.\n" );
1898 int moab_size, elem_size, array_len;
1902 rval =
get_tag_size( tag_data.
tag_id, moab_type, moab_size, elem_size, array_len, mhdf_type, hdf5_type );
1908 dbgOut.
printf( 2,
"Writing sparse data for var-len tag: \"%s\"\n", name.c_str() );
1914 int data_len = elem_size;
1915 if( moab_type !=
MB_TYPE_BIT ) data_len *= array_len;
1918 dbgOut.
printf( 2,
"Writing sparse data for tag: \"%s\"\n", name.c_str() );
1927 dbgOut.
printf( 2,
"Writing dense data for tag: \"%s\" on group \"%s\"\n", name.c_str(), set->
name() );
1928 subState.start(
"writing dense data for tag: ", ( name +
":" + set->
name() ).c_str() );
1929 rval =
write_dense_tag( tag_data, *set, name, moab_type, hdf5_type, data_len );
1935 H5Tclose( hdf5_type );
1950 std::string tname( name ? name :
"<UNKNOWN TAG?>" );
1959 long remaining = range.
size();
1961 long num_writes = ( remaining + chunk_size - 1 ) / chunk_size;
1964 assert( tag_data.
max_num_ents >= (
unsigned long)remaining );
1965 num_writes = ( tag_data.
max_num_ents + chunk_size - 1 ) / chunk_size;
1973 long count = (
unsigned long)remaining > chunk_size ? chunk_size : remaining;
1979 tmp.
merge( iter, stop );
1981 assert( tmp.
size() == (
unsigned)count );
1987 dbgOut.
print( 3,
" writing sparse tag entity chunk.\n" );
1999 while( num_writes-- )
2002 dbgOut.
print( 3,
" writing empty sparse tag entity chunk.\n" );
2013 const std::string& name,
2016 int value_type_size )
2021 long table_size, data_size;
2034 assert( table_size == data_size );
2037 subState.start(
"writing sparse ids for tag: ", name.c_str() );
2038 rval =
write_sparse_ids( tag_data, range, tables[0], table_size, name.c_str() );
2046 subState.start(
"writing sparse values for tag: ", name.c_str() );
2070 std::string tname( name ? name :
"<UNKNOWN TAG?>" );
2071 tname +=
" - End Indices";
2075 size_t chunk_size =
bufferSize / ( std::max(
sizeof(
void* ),
sizeof(
long ) ) +
sizeof( int ) );
2077 const void** junk = (
const void**)
dataBuffer;
2078 int* size_buffer = (
int*)(
dataBuffer + chunk_size * std::max(
sizeof(
void* ),
sizeof(
mhdf_index_t ) ) );
2082 size_t remaining = range.
size();
2084 size_t num_writes = ( remaining + chunk_size - 1 ) / chunk_size;
2087 assert( tag_data.
max_num_ents >= (
unsigned long)remaining );
2088 num_writes = ( tag_data.
max_num_ents + chunk_size - 1 ) / chunk_size;
2096 size_t count = remaining > chunk_size ? chunk_size : remaining;
2101 tmp.
merge( iter, stop );
2103 assert( tmp.
size() == (
unsigned)count );
2109 dbgOut.
print( 3,
" writing var-len tag offset chunk.\n" );
2111 for(
size_t i = 0; i < count; ++i )
2113 data_offset += size_buffer[i];
2114 idx_buffer[i] = data_offset;
2128 while( num_writes-- )
2131 dbgOut.
print( 3,
" writing empty sparse tag entity chunk.\n" );
2154 assert( !handle_tag ||
sizeof(
EntityHandle ) == type_size );
2156 std::string tname( name ? name :
"<UNKNOWN TAG?>" );
2157 tname +=
" - Values";
2160 const size_t buffer_size =
bufferSize / type_size;
2162 size_t num_writes = ( table_size + buffer_size - 1 ) / buffer_size;
2166 num_writes = ( tag_data.
max_num_vals + buffer_size - 1 ) / buffer_size;
2170 const void* prev_data = 0;
2171 size_t prev_len = 0;
2174 while( prev_data || iter != range.
end() )
2180 const void* ptr = prev_data;
2181 if( prev_len <= buffer_size )
2190 prev_data = ( (
const char*)prev_data ) + buffer_size * type_size;
2191 prev_len -= buffer_size;
2197 memcpy(
buffer, ptr, len * type_size );
2201 for( ; count < buffer_size && iter != range.
end(); ++iter )
2207 if( len + count > buffer_size )
2209 prev_len = len + count - buffer_size;
2210 len = buffer_size - count;
2211 prev_data = ( (
const char*)ptr ) + len * type_size;
2217 memcpy(
buffer + count * type_size, ptr, len * type_size );
2231 while( num_writes-- )
2234 dbgOut.
print( 3,
" writing empty var-len tag data chunk.\n" );
2245 const std::string& name,
2254 long data_table_size;
2268 subState.start(
"writing ids for var-len tag: ", name.c_str() );
2269 rval =
write_sparse_ids( tag_data, range, tables[0], table_size, name.c_str() );
2276 subState.start(
"writing indices for var-len tag: ", name.c_str() );
2284 subState.start(
"writing values for var-len tag: ", name.c_str() );
2286 type_size, name.c_str() );
2297 const std::string& name,
2300 int value_type_size )
2309 assert( elem_data.
range.
size() + elem_data.
offset <= (
unsigned long)table_size );
2313 value_type, value_type_size, elem_data.
max_num_ents, track );
2323 unsigned long offset_in,
2324 const Range& range_in,
2327 int value_type_size,
2328 unsigned long max_num_ents,
2336 size_t chunk_size =
bufferSize / value_type_size;
2337 assert( chunk_size > 0 );
2341 size_t remaining = range_in.
size();
2342 size_t offset = offset_in;
2344 long num_writes = ( remaining + chunk_size - 1 ) / chunk_size;
2347 assert( max_num_ents >= remaining );
2348 num_writes = ( max_num_ents + chunk_size - 1 ) / chunk_size;
2355 long count = (
unsigned long)remaining > chunk_size ? chunk_size : remaining;
2357 memset( tag_buffer, 0, count * value_type_size );
2361 range.
merge( iter, stop );
2363 assert( range.
size() == (
unsigned)count );
2376 assert( value_type > 0 );
2387 while( num_writes-- )
2390 dbgOut.
print( 2,
" writing empty tag value chunk.\n" );
2391 assert( value_type > 0 );
2403 const char* app =
"MOAB";
2410 std::vector< const char* > strs( list.size() ? list.size() : 4 );
2411 if( list.size() == 0 )
2413 time_t t = time( NULL );
2414 tm* lt = localtime( &t );
2416 strftime( date_str,
sizeof( date_str ),
"%m/%d/%y", lt );
2417 strftime( time_str,
sizeof( time_str ),
"%H:%M:%S", lt );
2419 strftime( date_str,
sizeof( date_str ),
"%D", lt );
2420 strftime( time_str,
sizeof( time_str ),
"%T", lt );
2430 for(
unsigned int i = 0; i < list.size(); ++i )
2431 strs[i] = list[i].c_str();
2507 std::vector< Tag > tag_list;
2508 std::vector< Tag >::iterator t_itor;
2516 for( t_itor = tag_list.begin(); t_itor != tag_list.end(); ++t_itor )
2521 tag_data.
tag_id = *t_itor;
2526 tagList.push_back( tag_data );
2538 const std::vector< std::string >& ,
2550 const std::vector< std::string >& qa_records,
2551 const Tag* user_tag_list,
2558 std::list< ExportSet >::iterator ex_itor;
2564 memset( type_names, 0,
MBMAXTYPE *
sizeof(
char* ) );
2597 ex_itor->total_num_ents = ex_itor->range.size();
2601 ex_itor->first_id = (
wid_t)first_id;
2602 ex_itor->offset = 0;
2603 rval =
assign_ids( ex_itor->range, ex_itor->first_id );
2610 long contents_len, children_len, parents_len;
2643 wid_t num_adjacencies;
2644 #ifdef MB_H5M_WRITE_NODE_ADJACENCIES
2649 if( num_adjacencies > 0 )
2663 ex_itor->adj_offset = 0;
2664 ex_itor->max_num_adjs = num_adjacencies;
2665 if( num_adjacencies > 0 )
2675 rval =
gather_tags( user_tag_list, num_user_tags );
2679 std::list< TagDesc >::iterator tag_iter =
tagList.begin();
2680 for( ; tag_iter !=
tagList.end(); ++tag_iter )
2702 bool prefer_dense =
false;
2708 const void* defval = 0;
2710 if(
MB_SUCCESS == rval ) prefer_dense =
true;
2716 tag_iter->dense_list.push_back(
nodeSet );
2719 std::list< ExportSet >::const_iterator ex =
exportList.begin();
2725 tag_iter->dense_list.push_back( *ex );
2732 tag_iter->dense_list.push_back(
setSet );
2736 tag_iter->write_sparse = !range.
empty();
2738 unsigned long var_len_total = 0;
2762 if( !prefer_dense )
return false;
2775 std::vector< wid_t > adj_list;
2779 for( ; iter != end; ++iter )
2785 if( adj_list.size() > 0 ) result += 2 + adj_list.size();
2810 long& contents_length_out,
2811 long& children_length_out,
2812 long& parents_length_out )
2816 long contents_length_set, children_length_set, parents_length_set;
2817 unsigned long flags;
2818 std::vector< wid_t > set_contents_ids;
2819 std::vector< SpecialSetData >::const_iterator si =
specialSets.begin();
2821 contents_length_out = 0;
2822 children_length_out = 0;
2823 parents_length_out = 0;
2827 while( si !=
specialSets.end() && si->setHandle < *iter )
2830 if( si !=
specialSets.end() && si->setHandle == *iter )
2832 contents_length_out += si->contentIds.size();
2833 children_length_out += si->childIds.size();
2834 parents_length_out += si->parentIds.size();
2839 rval =
get_set_info( *iter, contents_length_set, children_length_set, parents_length_set, flags );
2843 if( !( flags & MESHSET_ORDERED ) && contents_length_set )
2845 set_contents.
clear();
2855 assert( set_contents_ids.size() % 2 == 0 );
2856 contents_length_set = set_contents_ids.size();
2860 contents_length_out += contents_length_set;
2861 children_length_out += children_length_set;
2862 parents_length_out += parents_length_set;
2886 std::vector< SpecialSetData >::iterator i;
2888 return ( i ==
specialSets.end() || i->setHandle != h ) ? 0 : &*i;
2898 if( num_set_contents > 0 )
2905 if( num_set_children > 0 )
2912 if( num_set_parents > 0 )
2939 hdf_type = (hid_t)0;
2940 bool close_hdf_type =
false;
2950 return error( rval );
2955 return error( rval );
2960 type_size =
sizeof( int );
2962 hdf_type = H5T_NATIVE_INT;
2963 close_hdf_type =
false;
2966 type_size =
sizeof( double );
2968 hdf_type = H5T_NATIVE_DOUBLE;
2969 close_hdf_type =
false;
2972 type_size =
sizeof( bool );
2974 assert( array_length <= 8 );
2975 hdf_type = H5Tcopy( H5T_NATIVE_B8 );
2976 H5Tset_precision( hdf_type, array_length );
2977 close_hdf_type =
true;
2983 close_hdf_type =
false;
2997 type_size = num_bytes;
2998 hdf_type = H5Tcreate( H5T_OPAQUE, type_size );
2999 close_hdf_type =
true;
3005 if( hsize !=
sizeof( hid_t ) )
return error( MB_FAILURE );
3011 type_size = H5Tget_size( hdf_type );
3012 if( type_size != num_bytes )
return error( MB_FAILURE );
3014 close_hdf_type =
false;
3017 return error( rval );
3018 num_bytes = array_length;
3026 array_length * type_size == num_bytes );
3031 if( !close_hdf_type )
3033 hdf_type = H5Tcopy( hdf_type );
3037 else if( array_length > 1 && moab_type !=
MB_TYPE_BIT )
3039 hsize_t len = array_length;
3040 #if defined( H5Tarray_create_vers ) && ( H5Tarray_create_vers > 1 )
3041 hid_t temp_id = H5Tarray_create2( hdf_type, 1, &len );
3043 hid_t temp_id = H5Tarray_create( hdf_type, 1, &len, NULL );
3045 if( close_hdf_type ) H5Tclose( hdf_type );
3048 else if( !close_hdf_type )
3050 hdf_type = H5Tcopy( hdf_type );
3063 size_t step, remaining;
3064 step =
bufferSize / (
sizeof( int ) +
sizeof(
void* ) );
3065 const void** ptr_buffer =
reinterpret_cast< const void**
>(
dataBuffer );
3066 int* size_buffer =
reinterpret_cast< int*
>( ptr_buffer + step );
3069 for( remaining = range.
size(); remaining >= step; remaining -= step )
3075 subrange.
merge( iter, end );
3081 for(
size_t i = 0; i < step; ++i )
3082 result += size_buffer[i];
3086 subrange.
merge( iter, range.
end() );
3087 assert( subrange.
size() == remaining );
3090 for(
size_t i = 0; i < remaining; ++i )
3091 result += size_buffer[i];
3097 unsigned long num_sparse_entities,
3098 unsigned long data_table_size )
3103 int tag_bytes, type_size, num_vals, storage;
3104 hid_t hdf_type = (hid_t)0;
3106 std::string tag_name;
3115 switch( mb_storage )
3130 return error( MB_FAILURE );
3134 rval =
get_tag_size( tag_data.
tag_id, mb_type, tag_bytes, type_size, num_vals, mhdf_type, hdf_type );
3138 const void *def_value, *mesh_value;
3139 int def_val_len, mesh_val_len;
3148 H5Tclose( hdf_type );
3149 return error( rval );
3172 H5Tclose( hdf_type );
3173 return error( rval );
3180 assert( ( def_val_len + mesh_val_len ) *
sizeof(
long ) < (
size_t)
bufferSize );
3194 memcpy( ptr, mesh_value, mesh_val_len *
sizeof(
EntityHandle ) );
3205 mhdf_createTag(
filePtr, tag_name.c_str(), mhdf_type, num_vals, storage, def_value, mesh_value, hdf_type,
3208 H5Tclose( hdf_type );
3211 if( num_sparse_entities )
3219 for(
size_t i = 0; i < tag_data.
dense_list.size(); ++i )
3233 H5Tclose( hdf_type );
3236 if( num_sparse_entities )
3262 std::list< ExportSet >::reverse_iterator e;
3277 std::list< ExportSet >::reverse_iterator e;
3279 range.
merge( e->range );
3297 s << pfx << n1 <<
" " <<
id <<
" -> " << i->value << std::endl;
3304 s << pfx << n1 <<
" " <<
id <<
"-" <<
id + i->count - 1 <<
" -> " << i->value <<
"-"
3305 << i->value + i->count - 1 << std::endl;
3309 s << pfx << n1 <<
" " <<
id <<
"-" << n1 <<
" " <<
ID_FROM_HANDLE( i->
begin + i->count - 1 ) <<
" -> "
3310 << i->value <<
"-" << i->value + i->count - 1 << std::endl;
3318 std::cout <<
"WriteHDF5: " << t[
TOTAL_TIME] << std::endl
3319 <<
" gather mesh: " << t[
GATHER_TIME] << std::endl
3320 <<
" create file: " << t[
CREATE_TIME] << std::endl
3331 <<
" coordinates: " << t[
COORD_TIME] << std::endl
3332 <<
" connectivity: " << t[
CONN_TIME] << std::endl
3333 <<
" sets: " << t[
SET_TIME] << std::endl
3334 <<
" set descrip: " << t[
SET_META] << std::endl
3335 <<
" set content: " << t[
SET_CONTENT] << std::endl
3336 <<
" set parent: " << t[
SET_PARENT] << std::endl
3337 <<
" set child: " << t[
SET_CHILD] << std::endl
3338 <<
" adjacencies: " << t[
ADJ_TIME] << std::endl
3339 <<
" tags: " << t[
TAG_TIME] << std::endl