43 static bool debug =
false;
107 if( MB_SUCCESS != result ) return result
112 #define IO_ASSERT( C ) INT_IO_ERROR( C, __LINE__ )
118 char buffer[] = __FILE__
" ";
119 snprintf(
buffer, strlen(
buffer),
"%s:%u", __FILE__, line );
128 int rval = fseek(
cubFile, offset, SEEK_SET );
157 unsigned char tmp, *cdat = (
unsigned char*)data;
159 cdat[0] = cdat[7], cdat[7] = tmp;
161 cdat[1] = cdat[6], cdat[6] = tmp;
163 cdat[2] = cdat[5], cdat[5] = tmp;
165 cdat[3] = cdat[4], cdat[4] = tmp;
170 unsigned char tmp, *cdat = (
unsigned char*)data;
172 cdat[0] = cdat[3], cdat[3] = tmp;
174 cdat[1] = cdat[2], cdat[2] = tmp;
187 unsigned rval = fread( array,
sizeof(
unsigned int ), num_ents,
cubFile );
191 unsigned int* pt = array;
192 for(
unsigned int i = 0; i < num_ents; i++ )
202 unsigned rval = fread( array,
sizeof(
double ), num_ents,
cubFile );
207 for(
unsigned int i = 0; i < num_ents; i++ )
217 unsigned rval = fread( array,
sizeof(
char ), num_ents,
cubFile );
223 for(
unsigned int i = 0; i < num_ents; i++ )
233 : cubFile( NULL ), globalIdTag( 0 ), cubIdTag( 0 ),
geomTag( 0 ), uniqueIdTag( 0 ),
blockTag( 0 ), nsTag( 0 ),
234 ssTag( 0 ), attribVectorTag( 0 ), entityNameTag( 0 ), categoryTag( 0 ), hasMidNodesTag( 0 ),
235 swapForEndianness( false ), int_buf( NULL ), mFileSet( 0 ), printedSeqWarning( false ),
236 printedElemWarning( false ), acisDumpFile( NULL )
238 assert( NULL != impl );
272 if( rval !=
MB_SUCCESS ) std::cerr <<
"WARNING: Could not get_entities_by_type" << std::endl;
276 std::vector< std::string >* dum_vec;
279 if( rval !=
MB_SUCCESS ) std::cerr <<
"WARNING: Could not tag_get_data" << std::endl;
280 if( NULL != dum_vec )
delete dum_vec;
290 std::vector< int >& ,
300 const Tag* file_id_tag )
307 if( 0 < tmpval )
debug =
true;
316 cubFile = fopen( file_name,
"rb" );
327 MB_SET_ERR( MB_FAILURE,
"This doesn't appear to be a .cub file" );
336 if(
debug ) std::cout <<
"Reading file header." << std::endl;
339 if(
debug ) std::cout <<
"Reading model entries." << std::endl;
343 if(
debug ) std::cout <<
"Reading model metadata." << std::endl;
363 if( -1 == index )
return MB_FAILURE;
367 if(
debug ) std::cout <<
"Reading mesh model header and metadata." << std::endl;
381 if( geom_header->
maxDim !=
dim )
continue;
384 if(
debug ) std::cout <<
"Reading geom index " << gindex <<
" mesh: nodes... ";
385 result =
read_nodes( gindex, mesh_model, geom_header );
389 if(
debug ) std::cout <<
"elements... ";
392 if(
debug ) std::cout << std::endl;
399 std::string sat_file_name;
406 if(
debug ) std::cout <<
"Reading groups... ";
410 result =
read_group( grindex, mesh_model, group_header );
418 if(
debug ) std::cout <<
"Reading blocks... ";
423 result =
read_block( blindex, data_version, mesh_model, block_header );
432 if(
debug ) std::cout <<
"Reading nodesets... ";
436 result =
read_nodeset( nsindex, mesh_model, nodeset_header );
444 if(
debug ) std::cout <<
"Reading sidesets...";
448 result =
read_sideset( ssindex, data_version, mesh_model, sideset_header );
455 std::cout <<
"Read the following mesh:" << std::endl;
480 std::cout <<
"Failed to restore topology " << std::endl;
494 unsigned int nodeset_offset, sideset_offset;
514 if( 0 == nodeset_offset && 0 == sideset_offset )
return MB_SUCCESS;
522 std::vector< int > block_ids( blocks.
size() );
528 Range new_nodesets, new_sidesets;
529 std::vector< int > new_nodeset_ids, new_sideset_ids;
530 for( ; rit != blocks.
end(); i++, ++rit )
532 if( 0 != nodeset_offset && block_ids[i] >= (
int)nodeset_offset &&
533 ( nodeset_offset > sideset_offset || block_ids[i] < (
int)sideset_offset ) )
536 new_nodesets.
insert( *rit );
537 new_nodeset_ids.push_back( block_ids[i] );
539 else if( 0 != sideset_offset && block_ids[i] >= (
int)sideset_offset &&
540 ( sideset_offset > nodeset_offset || block_ids[i] < (
int)nodeset_offset ) )
543 new_sidesets.
insert( *rit );
544 new_sideset_ids.push_back( block_ids[i] );
551 if( 0 != nodeset_offset )
558 if(
MB_SUCCESS != tmp_result ) result = tmp_result;
561 if(
MB_SUCCESS != tmp_result ) result = tmp_result;
563 if(
MB_SUCCESS != tmp_result ) result = tmp_result;
565 if( 0 != sideset_offset )
572 if(
MB_SUCCESS != tmp_result ) result = tmp_result;
575 if(
MB_SUCCESS != tmp_result ) result = tmp_result;
577 if(
MB_SUCCESS != tmp_result ) result = tmp_result;
591 unsigned int this_type, num_ents;
592 std::vector< char > bc_data;
593 unsigned int num_read = 0;
594 std::vector< EntityHandle > ns_entities, excl_entities;
595 for(
unsigned int i = 0; i < nodeseth->
memTypeCt; i++ )
599 num_read += 2 *
sizeof( int );
605 num_read +=
sizeof( int );
612 if( num_read < nodeseth->nsLength )
626 bc_data.resize( num_bcs );
627 FREADCA( num_bcs, &bc_data[0] );
635 if( !bc_data.empty() )
637 std::cout <<
"bc_data = ";
638 std::vector< char >::iterator vit = bc_data.begin();
639 for( ; vit != bc_data.end(); ++vit )
641 std::cout << std::hex << (int)( (
unsigned char)*vit ) <<
" ";
644 vit = bc_data.begin();
645 for( ; vit != bc_data.end(); ++vit )
649 std::cout << std::endl;
660 const int def_bc_data_len = 0;
666 void const* tag_data[] = { ( bc_data.empty() ) ? NULL : &( bc_data[0] ) };
667 int tag_size = bc_data.size();
675 const double data_version,
687 unsigned int this_type, num_ents, sense_size;
689 std::vector< char > bc_data;
690 unsigned int num_read = 0;
691 std::vector< EntityHandle > ss_entities, excl_entities;
692 if( data_version <= 1.0 )
694 for(
unsigned int i = 0; i < sideseth->
memTypeCt; i++ )
698 num_read += 3 *
sizeof( int );
705 num_read +=
sizeof( int );
711 if( sense_size == 1 )
714 unsigned int read_length = ( num_ents / 8 ) * 8;
715 if( read_length < num_ents ) read_length += 8;
717 num_read += read_length;
719 else if( sense_size == 2 )
723 num_read +=
sizeof( int );
732 for(
unsigned int i = 0; i < sideseth->
memTypeCt; i++ )
736 num_read +=
sizeof( int );
740 std::vector< unsigned int > mem_types( num_ents ), mem_ids( num_ents );
741 FREADIA( num_ents, &mem_types[0] );
742 num_read += num_ents *
sizeof( int );
744 num_read +=
sizeof( int );
750 unsigned int read_length = ( num_ents / 8 ) * 8;
751 if( read_length < num_ents ) read_length += 8;
753 num_read += read_length;
757 num_read +=
sizeof( int );
760 num_read += num_wrts *
sizeof( int );
768 if( sideseth->
numDF > 0 )
772 num_read += sideseth->
numDF *
sizeof( double );
777 const void* dist_data = &
dbl_buf[0];
778 const int dist_size = sideseth->
numDF;
784 if( data_version > 1.0 && num_read < sideseth->ssLength )
799 bc_data.resize( num_bcs );
800 FREADCA( num_bcs, &bc_data[0] );
808 if( !bc_data.empty() )
810 std::cout <<
"bc_data = ";
811 std::vector< char >::iterator vit = bc_data.begin();
812 for( ; vit != bc_data.end(); ++vit )
814 std::cout << std::hex << (int)( (
unsigned char)*vit ) <<
" ";
817 vit = bc_data.begin();
818 for( ; vit != bc_data.end(); ++vit )
822 std::cout << std::endl;
829 const int def_bc_data_len = 0;
835 void const* tag_data[] = { ( bc_data.empty() ) ? NULL : &( bc_data[0] ) };
836 int tag_size = bc_data.size();
845 const int sense_size,
846 std::vector< EntityHandle >& ss_entities,
849 std::vector< EntityHandle > forward, reverse;
855 for(
int i = 0; i < num_ents; i++ )
858 forward.push_back( ss_entities[i] );
860 reverse.push_back( ss_entities[i] );
863 forward.push_back( ss_entities[i] );
864 reverse.push_back( ss_entities[i] );
868 else if( this_type == 4
872 for(
int i = 0; i < num_ents; i++ )
875 forward.push_back( ss_entities[i] );
877 reverse.push_back( ss_entities[i] );
878 else if( *( (
int*)&
uint_buf[i] ) == -1 )
880 forward.push_back( ss_entities[i] );
881 reverse.push_back( ss_entities[i] );
888 if( !forward.empty() )
891 if( tmp_result !=
MB_SUCCESS ) result = tmp_result;
893 if( !reverse.empty() )
898 if(
MB_SUCCESS != tmp_result ) result = tmp_result;
900 if( tmp_result !=
MB_SUCCESS ) result = tmp_result;
905 if( tmp_result !=
MB_SUCCESS ) result = tmp_result;
908 if( tmp_result !=
MB_SUCCESS ) result = tmp_result;
910 if( tmp_result !=
MB_SUCCESS ) result = tmp_result;
920 std::vector< EntityHandle > forward, reverse;
922 unsigned int num_ents = ss_entities.size();
923 unsigned int* wrt_it = &
uint_buf[0];
925 for(
unsigned int i = 0; i < num_ents; i++ )
927 unsigned int num_wrt = 0;
928 if( 0 != num_wrts ) num_wrt = *wrt_it++;
929 for(
unsigned int j = 0; j < num_wrt; j++ )
934 forward.push_back( ss_entities[i] );
935 reverse.push_back( ss_entities[i] );
941 forward.push_back( ss_entities[i] );
943 reverse.push_back( ss_entities[i] );
946 forward.push_back( ss_entities[i] );
947 reverse.push_back( ss_entities[i] );
954 if( !forward.empty() )
957 if( tmp_result !=
MB_SUCCESS ) result = tmp_result;
959 if( !reverse.empty() )
964 if(
MB_SUCCESS != tmp_result ) result = tmp_result;
966 if( tmp_result !=
MB_SUCCESS ) result = tmp_result;
974 if( tmp_result !=
MB_SUCCESS ) result = tmp_result;
976 if( tmp_result !=
MB_SUCCESS ) result = tmp_result;
993 unsigned int num_read = 0;
994 int this_type, num_ents;
995 std::vector< EntityHandle > block_entities, excl_entities;
996 for(
unsigned int i = 0; i < blockh->
memTypeCt; i++ )
1000 num_read += 2 *
sizeof( int );
1006 num_read += num_ents *
sizeof( int );
1020 int def_block_attributes_length = 0;
1029 num_read +=
sizeof( double );
1030 void const* tag_data[] = { &
dbl_buf[0] };
1031 int tag_sizes[] = {
static_cast< int >( blockh->
attribOrder ) };
1037 if( num_read < blockh->blockLength )
1088 assert( mbcore != NULL );
1099 if( -1 == md_index )
return result;
1109 md_index = md.
get_md_entry( set_index,
"NumExtraNames" );
1110 if( -1 == md_index )
return result;
1112 for(
int i = 0; i < num_names; i++ )
1114 std::ostringstream extra_name_label(
"ExtraName" );
1115 extra_name_label << i;
1116 std::ostringstream moab_extra_name(
"EXTRA_" );
1118 md_index = md.
get_md_entry( set_index, extra_name_label.str().c_str() );
1119 if( -1 != md_index )
1142 int this_type, num_ents;
1143 std::vector< EntityHandle > grp_entities, excl_entities;
1144 for(
unsigned int i = 0; i < grouph->
memTypeCt; i++ )
1166 if( -1 != md_index )
1184 if( -1 != md_index )
1187 for(
int i = 0; i < num_names; i++ )
1189 std::ostringstream extra_name_label(
"ExtraName" );
1190 extra_name_label << i;
1191 std::ostringstream moab_extra_name(
"EXTRA_" );
1194 if( -1 != md_index )
1215 std::vector< EntityHandle >&
entities,
1216 std::vector< EntityHandle >& excl_entities )
1224 if( !excl_entities.empty() )
1229 std::vector< EntityHandle >* new_vector =
new std::vector< EntityHandle >;
1230 new_vector->swap( excl_entities );
1244 const unsigned int id_buf_size,
1245 const bool is_group,
1246 std::vector< EntityHandle >&
entities )
1250 for(
unsigned int i = 0; i < id_buf_size; i++ )
1258 if(
MB_SUCCESS != tmp_result ) result = tmp_result;
1266 const unsigned int id_buf_size,
1267 std::vector< EntityHandle >&
entities,
1268 std::vector< EntityHandle >& excl_entities )
1272 if( this_type <=
VERTEX )
1274 else if( this_type >=
HEX && this_type <=
NODE )
1282 const unsigned int id_buf_size,
1283 std::vector< EntityHandle >&
entities )
1285 for(
unsigned int i = 0; i < id_buf_size; i++ )
1293 const unsigned int id_buf_size,
1294 std::vector< EntityHandle >&
entities,
1295 std::vector< EntityHandle >& excl_entities )
1298 std::vector< EntityHandle >* ent_list = NULL;
1299 EntityType this_ent_type =
MBVERTEX;
1301 if( this_type > 1000 )
1303 if( this_type - 1000 < arr_len )
1306 ent_list = &excl_entities;
1311 if( this_type < arr_len )
1317 if( NULL == ent_list )
1319 MB_SET_ERR( MB_FAILURE,
"Entities list is NULL" );
1328 for(
unsigned int i = 0; i < id_buf_size; i++ )
1333 for(
unsigned int i = 0; i < id_buf_size; i++ )
1345 if( tmp_ents.
empty() && 0 != id_buf_size )
return MB_FAILURE;
1347 std::vector< int > cub_ids( tmp_ents.
size() );
1352 for(
unsigned int i = 0; i < id_buf_size; i++ )
1354 std::vector< int >::iterator vit = std::find( cub_ids.begin(), cub_ids.end(), id_buf[i] );
1355 if( vit != cub_ids.end() )
1357 EntityHandle this_ent = tmp_ents[vit - cub_ids.begin()];
1362 std::cout <<
"Warning: didn't find " <<
CN::EntityTypeName( this_ent_type ) <<
" " << id_buf[i]
1373 if( entity->
nodeCt == 0 )
1375 if(
debug ) std::cout <<
"(no nodes) ";
1388 for(
unsigned int i = 0; i < entity->
nodeCt; i++ )
1391 if( i != entity->
nodeCt - 1 ) std::cout <<
", ";
1393 std::cout <<
")...";
1398 std::vector< double* > arrays;
1410 Range dum_range( vhandle, vhandle + entity->
nodeCt - 1 );
1416 unsigned int max_cid, min_cid;
1421 long vhandle_offset = vhandle - min_cid;
1430 Range vrange, tmp_range( dum_range );
1433 vrange =
subtract( vrange, tmp_range );
1435 #define MAX( a, b ) ( ( a ) > ( b ) ? ( a ) : ( b ) )
1436 #define MIN( a, b ) ( ( a ) < ( b ) ? ( a ) : ( b ) )
1440 max_cid =
MAX( max_cid, ( (
unsigned int)new_max ) );
1445 for( rit = vrange.
begin(); rit != vrange.
end(); ++rit )
1465 if( -1 == contig || -2 == contig )
1468 std::vector< double > tmp_coords( entity->
nodeCt );
1469 for(
unsigned int j = 0; j < 3; j++ )
1472 for(
unsigned int i = 0; i < entity->
nodeCt; i++ )
1475 tmp_coords[
uint_buf[i] - min_cid] = arrays[j][i];
1478 std::copy( &tmp_coords[0], &tmp_coords[0] + entity->
nodeCt, arrays[j] );
1481 for(
unsigned int i = 0; i < entity->
nodeCt; i++ )
1494 for( ; rit != dum_range.
end(); vit++, ++rit )
1496 assert( *vit < cubMOABVertexMap->
size() );
1497 ( *cubMOABVertexMap )[*vit] = *rit;
1520 std::vector< int > fixed_flags( entity->
nodeCt );
1521 std::fill( fixed_flags.begin(), fixed_flags.end(), 0 );
1522 if( md_entry->
mdDataType != 3 )
return MB_FAILURE;
1524 for( std::vector< unsigned int >::iterator vit = md_entry->
mdIntArrayValue.begin();
1530 assert( fixed_v >= *dum_range.
begin() && fixed_v <= *dum_range.
rbegin() );
1532 fixed_flags[*vit - *dum_range.
begin()] = 1;
1548 const int in_order_map[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13,
1549 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27 };
1555 int int_type, nodes_per_elem, num_elem;
1558 for(
unsigned int i = 0; i < entity->
elemTypeCt; i++ )
1573 if( !node_order ) node_order = in_order_map;
1580 unsigned int max_id, min_id;
1584 std::cout <<
"Element ids are not contiguous!" << std::endl;
1595 Range dum_range( start_handle, start_handle + num_elem - 1 );
1598 elem_offset = ( 1 == contig ? start_handle -
int_buf[0] :
int_buf[num_elem - 1] );
1607 unsigned int total_conn = num_elem * nodes_per_elem;
1614 for(
int e = 0; e < num_elem; ++e )
1616 for(
int k = 0; k < nodes_per_elem; ++k, ++j )
1620 if( 0 == j ) std::cout <<
"Conn=";
1628 new_handle = ( *cubMOABVertexMap )[
uint_buf[j]];
1635 conn[e * nodes_per_elem + node_order[k]] = new_handle;
1662 unsigned int *id_it, curr_id, i;
1666 curr_id = *id_it++ + 1;
1670 for( i = 1; i < num_ents; id_it++, i++, curr_id++ )
1672 if( *id_it != curr_id )
1681 if( 1 == contig )
return;
1686 curr_id = *id_it++ - 1;
1687 for( i = 1; i < num_ents; id_it++, i++, curr_id-- )
1689 if( *id_it != curr_id )
1697 if( -1 == contig )
return;
1700 if( max_id - min_id + 1 == num_ents ) contig = -2;
1708 instance->
FSEEK( offset );
1738 #ifdef WORDS_BIGENDIAN
1763 std::vector< unsigned int >::iterator int_it =
uint_buf.begin();
1783 if(
modelEntries[i].modelType == model_type )
return i;
1792 FSEEK( metadata_offset );
1860 if(
char_buf.size() <= (
unsigned int)str_size )
char_buf.resize( str_size + 1 );
1864 int extra = str_size %
sizeof( int );
1868 str_size =
sizeof( int ) - extra;
1894 for(
unsigned int i = 0; i < info.
numEntities; i++ )
1906 if( geom_headers[i].nodeCt == 0 && geom_headers[i].elemCt == 0 )
continue;
1909 result = instance->
create_set( geom_headers[i].setHandle );
1919 &( geom_headers[i].
geomID ) );
1927 for(
unsigned int i = 0; i < info.
numEntities; i++ )
1929 if( geom_headers[i].elemTypeCt == 0 )
continue;
1930 instance->
FSEEK( model_offset + geom_headers[i].elemOffset );
1931 for(
unsigned int j = 0; j < geom_headers[i].
elemTypeCt; j++ )
1935 int int_type = instance->
uint_buf[0];
1936 int nodes_per_elem = instance->
uint_buf[1];
1937 int num_elem = instance->
uint_buf[2];
1939 geom_headers[i].
maxDim = std::max( geom_headers[i].maxDim, (
int)
CN::Dimension( elem_type ) );
1940 if( j < geom_headers[i].elemTypeCt - 1 )
1942 int num_skipped_ints = num_elem + num_elem * nodes_per_elem;
1943 if(
major >= 14 ) num_skipped_ints += num_elem;
1944 instance->
FREADI( num_skipped_ints );
1969 for(
unsigned int i = 0; i < info.
numEntities; i++ )
1972 result = instance->
create_set( group_headers[i].setHandle );
1991 &( group_headers[i].
grpID ) );
2001 const unsigned int model_offset,
2018 for(
unsigned int i = 0; i < info.
numEntities; i++ )
2021 result = instance->
create_set( block_headers[i].setHandle );
2041 std::vector< int > def_uint_zero( 3, 0 );
2044 &def_uint_zero[0] );
2046 int block_header_data[] = {
static_cast< int >( block_headers[i].
blockCol ),
2047 static_cast< int >( block_headers[i].blockMat ),
2048 static_cast< int >( block_headers[i].
blockDim ) };
2050 instance->
mdbImpl->
tag_set_data( bhTag_header, &( block_headers[i].setHandle ), 1, block_header_data );
2057 if( data_version <= 1.0 && block_headers[i].blockElemType >= 15 ) block_headers[i].
blockElemType += 4;
2065 if( 55 != block_headers[i].blockElemType )
2066 MB_SET_ERR( MB_FAILURE,
"Invalid block element type: " << block_headers[i].blockElemType );
2070 if( 52 != block_headers[i].blockElemType )
2071 MB_SET_ERR( MB_FAILURE,
"Invalid block element type: " << block_headers[i].blockElemType );
2077 &( block_headers[i].
blockID ) );
2080 &( block_headers[i].
blockID ) );
2083 material_category );
2087 if( !block_headers[i].memCt )
continue;
2092 if( 52 != block_headers[i].blockElemType && 55 != block_headers[i].blockElemType )
2096 if( ( block_headers[i].blockEntityType <
MBMAXTYPE ) &&
2100 for(
int j = 0; j < 4; j++ )
2101 block_headers[i].hasMidNodes[j] = 0;
2106 block_headers[i].hasMidNodes );
2110 CN::HasMidNodes( block_headers[i].blockEntityType, num_verts, block_headers[i].hasMidNodes );
2114 block_headers[i].hasMidNodes );
2140 for(
unsigned int i = 0; i < info.
numEntities; i++ )
2143 result = instance->
create_set( nodeset_headers[i].setHandle );
2159 &( nodeset_headers[i].
nsID ) );
2162 &( nodeset_headers[i].
nsID ) );
2165 dirichlet_category );
2189 for(
unsigned int i = 0; i < info.
numEntities; i++ )
2192 result = instance->
create_set( sideset_headers[i].setHandle );
2208 &( sideset_headers[i].
ssID ) );
2211 &( sideset_headers[i].
ssID ) );
2223 if( !
debug )
return;
2224 std::cout << prefix << std::endl;
2225 if( NULL != header )
2227 for(
unsigned int i = 0; i < num_headers; i++ )
2229 std::cout <<
"Index " << i << std::endl;
2237 if( !
debug )
return;
2238 std::cout << prefix << std::endl;
2239 if( NULL != header )
2241 for(
unsigned int i = 0; i < num_headers; i++ )
2248 if( !
debug )
return;
2249 std::cout << prefix << std::endl;
2250 if( NULL != header )
2252 for(
unsigned int i = 0; i < num_headers; i++ )
2259 const unsigned int num_headers )
2261 if( !
debug )
return;
2262 std::cout << prefix << std::endl;
2263 if( NULL != header )
2265 for(
unsigned int i = 0; i < num_headers; i++ )
2272 const unsigned int num_headers )
2274 if( !
debug )
return;
2275 std::cout << prefix << std::endl;
2276 if( NULL != header )
2278 for(
unsigned int i = 0; i < num_headers; i++ )
2285 feModelHeader.init( modelOffset, instance );
2290 if( feModelHeader.geomArray.numEntities > 0 )
2301 print_geom_headers(
"Geom headers:", feGeomH, feModelHeader.geomArray.numEntities );
2305 if( feModelHeader.groupArray.numEntities > 0 )
2308 print_group_headers(
"Group headers:", feGroupH, feModelHeader.groupArray.numEntities );
2312 if( feModelHeader.blockArray.numEntities > 0 )
2320 print_block_headers(
"Block headers:", feBlockH, feModelHeader.blockArray.numEntities );
2323 if( feModelHeader.nodesetArray.numEntities > 0 )
2332 print_nodeset_headers(
"Nodeset headers:", feNodeSetH, feModelHeader.nodesetArray.numEntities );
2334 if( feModelHeader.sidesetArray.numEntities > 0 )
2342 print_sideset_headers(
"SideSet headers:", feSideSetH, feModelHeader.sidesetArray.numEntities );
2350 if(
debug ) std::cout <<
"Geom metadata:" << std::endl;
2351 tqd->
read_meta_data( modelOffset + feModelHeader.geomArray.metaDataOffset, geomMD );
2352 if(
debug ) std::cout <<
"Node metadata:" << std::endl;
2353 tqd->
read_meta_data( modelOffset + feModelHeader.nodeArray.metaDataOffset, nodeMD );
2354 if(
debug ) std::cout <<
"Elem metadata:" << std::endl;
2355 tqd->
read_meta_data( modelOffset + feModelHeader.elementArray.metaDataOffset, elementMD );
2356 if(
debug ) std::cout <<
"Group metadata:" << std::endl;
2357 tqd->
read_meta_data( modelOffset + feModelHeader.groupArray.metaDataOffset, groupMD );
2358 if(
debug ) std::cout <<
"Block metadata:" << std::endl;
2359 tqd->
read_meta_data( modelOffset + feModelHeader.blockArray.metaDataOffset, blockMD );
2360 if(
debug ) std::cout <<
"Nodeset metadata:" << std::endl;
2361 tqd->
read_meta_data( modelOffset + feModelHeader.nodesetArray.metaDataOffset, nodesetMD );
2362 if(
debug ) std::cout <<
"Sideset metadata:" << std::endl;
2363 tqd->
read_meta_data( modelOffset + feModelHeader.sidesetArray.metaDataOffset, sidesetMD );
2371 unsigned int acis_model_offset = 0, acis_model_length = 0, acis_model_handle = 1, acis_sat_type = 1;
2382 if( acis_model_length == 0 )
return MB_SUCCESS;
2384 std::vector< AcisRecord > records;
2394 FSEEK( acis_model_offset );
2396 unsigned int bytes_left = acis_model_length;
2403 const unsigned int buf_size = 1023;
2408 while( 0 != bytes_left )
2411 unsigned int next_buf = ( bytes_left > buf_size ? buf_size : bytes_left );
2419 unsigned int buf_pos = 0;
2422 if( bytes_left == acis_model_length )
2425 ret = strchr( &(
char_buf[0] ),
'\n' );
2426 ret = strchr( ret + 1,
'\n' );
2427 ret = strchr( ret + 1,
'\n' );
2428 if( NULL == ret )
return MB_FAILURE;
2429 buf_pos += ret - &(
char_buf[0] ) + 1;
2432 bytes_left -= next_buf;
2438 ret = strchr( &(
char_buf[buf_pos] ),
'#' );
2439 while( ret && (
unsigned int)( ret + 1 - &
char_buf[0] ) < bytes_left && *( ret + 1 ) !=
'\n' &&
2440 *( ret + 1 ) !=
'\r' && *( ret + 1 ) != 0 )
2441 ret = strchr( ret + 1,
'#' );
2446 int num_chars = ret - &(
char_buf[buf_pos] ) + 2;
2447 if( *( ret + 1 ) ==
'\r' ) num_chars++;
2449 buf_pos += num_chars;
2453 records.push_back( this_record );
2465 }
while( buf_pos < next_buf );
2469 fwrite(
"\n======================\nSorted acis records:\n======================\n", 1, 68,
acisDumpFile );
2482 void* default_val = NULL;
2487 unsigned int current_record = 0;
2489 #define REC records[current_record]
2491 while( current_record != records.size() )
2502 REC.processed =
true;
2510 REC.processed =
true;
2520 unsigned int num_read;
2521 std::vector< std::string > attrib_vec;
2522 char temp_name[1024];
2524 std::string name_tag;
2527 int next_attrib = -1;
2530 int current_attrib = records[entity_rec_num].first_attrib;
2531 if( -1 == current_attrib )
return MB_SUCCESS;
2535 fwrite(
"-----------------------------------------------------------------------\n", 1, 72,
acisDumpFile );
2536 fwrite( records[entity_rec_num].att_string.c_str(),
sizeof(
char ), records[entity_rec_num].att_string.length(),
2540 while( -1 != current_attrib )
2543 ( records[current_attrib].att_next != next_attrib ||
2544 records[current_attrib].att_ent_num != (
int)entity_rec_num ) )
2548 fwrite( records[current_attrib].att_string.c_str(),
sizeof(
char ),
2549 records[current_attrib].att_string.length(),
acisDumpFile );
2552 if( strncmp( records[current_attrib].att_string.c_str(),
"ENTITY_NAME", 11 ) == 0 )
2557 sscanf( records[current_attrib].att_string.c_str(),
"ENTITY_NAME @%d %s", &num_chars, temp_name );
2560 sscanf( records[current_attrib].att_string.c_str(),
"ENTITY_NAME %d %s", &num_chars, temp_name );
2561 if( num_read != 2 )
return MB_FAILURE;
2564 name_tag = std::string( temp_name, num_chars );
2566 else if( strncmp( records[current_attrib].att_string.c_str(),
"ENTITY_ID", 9 ) == 0 )
2569 int bounding_uid, bounding_sense;
2570 num_read = sscanf( records[current_attrib].att_string.c_str(),
"ENTITY_ID 0 3 %d %d %d", &
id, &bounding_uid,
2576 float dumx, dumy, dumz;
2577 num_read = sscanf( records[current_attrib].att_string.c_str(),
"ENTITY_ID 3 %f %f %f 3 %d %d %d", &dumx,
2578 &dumy, &dumz, &
id, &bounding_uid, &bounding_sense );
2583 std::cout <<
"Warning: bad ENTITY_ID attribute in .sat file, record number " << entity_rec_num
2584 <<
", record follows:" << std::endl
2585 << records[current_attrib].att_string.c_str() << std::endl;
2587 else if( strncmp( records[current_attrib].att_string.c_str(),
"UNIQUE_ID", 9 ) == 0 )
2591 num_read = sscanf( records[current_attrib].att_string.c_str(),
"UNIQUE_ID 0 1 %d", &uid );
2593 num_read = sscanf( records[current_attrib].att_string.c_str(),
"UNIQUE_ID 1 0 1 %d", &uid );
2594 if( 1 != num_read )
return MB_FAILURE;
2596 else if( strncmp( records[current_attrib].att_string.c_str(),
"COMPOSITE_ATTRIB @9 UNIQUE_ID", 29 ) == 0 )
2599 int dum1, dum2, dum3, dum4;
2600 num_read = sscanf( records[current_attrib].att_string.c_str(),
2601 "COMPOSITE_ATTRIB @9 UNIQUE_ID %d %d %d %d %d", &dum1, &dum2, &dum3, &dum4, &uid );
2602 if( 5 != num_read )
return MB_FAILURE;
2604 else if( strncmp( records[current_attrib].att_string.c_str(),
"COMPOSITE_ATTRIB @9 ENTITY_ID", 29 ) == 0 )
2607 int dum1, dum2, dum3;
2608 num_read = sscanf( records[current_attrib].att_string.c_str(),
"COMPOSITE_ATTRIB @9 ENTITY_ID %d %d %d %d",
2609 &dum1, &dum2, &dum3, &
id );
2610 if( 4 != num_read )
return MB_FAILURE;
2614 attrib_vec.push_back( records[current_attrib].att_string );
2617 records[current_attrib].processed =
true;
2618 next_attrib = current_attrib;
2619 current_attrib = records[current_attrib].att_prev;
2624 if( records[entity_rec_num].rec_type ==
aBODY || ( records[entity_rec_num].entity == 0 && uid == -1 ) )
2633 if( records[entity_rec_num].entity == 0 )
2635 records[entity_rec_num].entity =
uidSetMap[uid];
2638 if( 0 == records[entity_rec_num].entity )
return MB_SUCCESS;
2649 if( records[entity_rec_num].rec_type ==
aBODY )
2651 else if( records[entity_rec_num].rec_type ==
LUMP )
2653 else if( records[entity_rec_num].rec_type ==
FACE )
2655 else if( records[entity_rec_num].rec_type ==
aEDGE )
2657 else if( records[entity_rec_num].rec_type ==
aVERTEX )
2659 if( -1 != ent_dim )
gidSetMap[ent_dim][id] = records[entity_rec_num].entity;
2663 if( !name_tag.empty() )
2673 size_t len = name_tag.size();
2675 memcpy( name_tag_val, name_tag.c_str(), len );
2681 if( !attrib_vec.empty() )
2684 std::vector< std::string >* dum_vec;
2690 dum_vec =
new std::vector< std::string >;
2691 dum_vec->swap( attrib_vec );
2702 std::copy( attrib_vec.begin(), attrib_vec.end(), std::back_inserter( *dum_vec ) );
2723 const char* type_substr;
2726 if( ( type_substr = strstr( this_record.
att_string.c_str(),
"attrib" ) ) != NULL &&
2727 type_substr - this_record.
att_string.c_str() < 20 )
2730 bool simple_attrib =
false;
2731 bool generic_attrib =
false;
2732 if( ( type_substr = strstr( this_record.
att_string.c_str(),
"simple-snl-attrib" ) ) != NULL )
2733 simple_attrib =
true;
2734 else if( ( type_substr = strstr( this_record.
att_string.c_str(),
"integer_attrib-name_attrib-gen-attrib" ) ) !=
2736 generic_attrib =
true;
2744 type_substr = strchr( type_substr,
' ' );
2745 if( NULL == type_substr )
return MB_FAILURE;
2748 int num_converted = sscanf( type_substr,
" $-1 -1 $%d $%d $%d -1", &( this_record.
att_prev ),
2750 if( num_converted != 3 )
return MB_FAILURE;
2755 type_substr = strstr( this_record.
att_string.c_str(),
"NEW_SIMPLE_ATTRIB" );
2756 if( NULL == type_substr )
return MB_FAILURE;
2757 type_substr = strstr( type_substr,
"@" );
2758 if( NULL == type_substr )
return MB_FAILURE;
2759 type_substr = strstr( type_substr,
" " ) + 1;
2761 std::string dum_str( type_substr );
2764 else if( generic_attrib )
2766 type_substr = strstr( this_record.
att_string.c_str(),
"CUBIT_ID" );
2767 if( NULL == type_substr )
return MB_FAILURE;
2769 std::string dum_str( type_substr );
2776 if( ( type_substr = strstr( this_record.
att_string.c_str(),
"body" ) ) != NULL &&
2777 type_substr - this_record.
att_string.c_str() < 20 )
2781 else if( ( type_substr = strstr( this_record.
att_string.c_str(),
"lump" ) ) != NULL &&
2782 type_substr - this_record.
att_string.c_str() < 20 )
2786 else if( ( type_substr = strstr( this_record.
att_string.c_str(),
"shell" ) ) != NULL &&
2787 type_substr - this_record.
att_string.c_str() < 20 )
2792 else if( ( type_substr = strstr( this_record.
att_string.c_str(),
"surface" ) ) != NULL &&
2793 type_substr - this_record.
att_string.c_str() < 20 )
2798 else if( ( type_substr = strstr( this_record.
att_string.c_str(),
"face" ) ) != NULL &&
2799 type_substr - this_record.
att_string.c_str() < 20 )
2803 else if( ( type_substr = strstr( this_record.
att_string.c_str(),
"loop" ) ) != NULL &&
2804 type_substr - this_record.
att_string.c_str() < 20 )
2809 else if( ( type_substr = strstr( this_record.
att_string.c_str(),
"coedge" ) ) != NULL &&
2810 type_substr - this_record.
att_string.c_str() < 20 )
2815 else if( ( type_substr = strstr( this_record.
att_string.c_str(),
"edge" ) ) != NULL &&
2816 type_substr - this_record.
att_string.c_str() < 20 )
2820 else if( ( type_substr = strstr( this_record.
att_string.c_str(),
"vertex" ) ) != NULL &&
2821 type_substr - this_record.
att_string.c_str() < 20 )
2833 std::cout <<
"Warning: acis file has sequence numbers!" << std::endl;
2838 type_substr = strchr( type_substr,
' ' );
2839 if( NULL == type_substr )
return MB_FAILURE;
2842 int num_converted = sscanf( type_substr,
" $%d", &( this_record.
first_attrib ) );
2843 if( num_converted != 1 )
return MB_FAILURE;
2851 : fileEndian( 0 ), fileSchema( 0 ), numModels( 0 ), modelTableOffset( 0 ), modelMetaDataOffset( 0 ),
2858 std::cout <<
"FileTOC:End, Sch, #Mdl, TabOff, "
2859 <<
"MdlMDOff, actFEMdl = ";
2860 std::cout << fileEndian <<
", " << fileSchema <<
", " << numModels <<
", " << modelTableOffset <<
", "
2861 << modelMetaDataOffset <<
", " << activeFEModel << std::endl;
2868 std::cout <<
"ArrayInfo:numEntities, tableOffset, metaDataOffset = " << numEntities <<
", " << tableOffset <<
", "
2869 << metaDataOffset << std::endl;
2874 numEntities = uint_buf_in[0];
2875 tableOffset = uint_buf_in[1];
2876 metaDataOffset = uint_buf_in[2];
2881 std::cout <<
"FEModelHeader:feEndian, feSchema, feCompressFlag, feLength = " <<
feEndian <<
", " <<
feSchema <<
", "
2883 std::cout <<
"geomArray: ";
2885 std::cout <<
"nodeArray: ";
2887 std::cout <<
"elementArray: ";
2889 std::cout <<
"groupArray: ";
2891 std::cout <<
"blockArray: ";
2893 std::cout <<
"nodesetArray: ";
2895 std::cout <<
"sidesetArray: ";
2900 : geomID( 0 ), nodeCt( 0 ), nodeOffset( 0 ), elemCt( 0 ), elemOffset( 0 ), elemTypeCt( 0 ), elemLength( 0 ),
2901 maxDim( 0 ), setHandle( 0 )
2907 std::cout <<
"geomID = " << geomID << std::endl;
2908 std::cout <<
"nodeCt = " << nodeCt << std::endl;
2909 std::cout <<
"nodeOffset = " << nodeOffset << std::endl;
2910 std::cout <<
"elemCt = " << elemCt << std::endl;
2911 std::cout <<
"elemOffset = " << elemOffset << std::endl;
2912 std::cout <<
"elemTypeCt = " << elemTypeCt << std::endl;
2913 std::cout <<
"elemLength = " << elemLength << std::endl;
2914 std::cout <<
"setHandle = " << setHandle << std::endl;
2918 : grpID( 0 ), grpType( 0 ), memCt( 0 ), memOffset( 0 ), memTypeCt( 0 ), grpLength( 0 ), setHandle( 0 )
2924 std::cout <<
"grpID = " << grpID << std::endl;
2925 std::cout <<
"grpType = " << grpType << std::endl;
2926 std::cout <<
"memCt = " << memCt << std::endl;
2927 std::cout <<
"memOffset = " << memOffset << std::endl;
2928 std::cout <<
"memTypeCt = " << memTypeCt << std::endl;
2929 std::cout <<
"grpLength = " << grpLength << std::endl;
2930 std::cout <<
"setHandle = " << setHandle << std::endl;
2934 : blockID( 0 ), blockElemType( 0 ), memCt( 0 ), memOffset( 0 ), memTypeCt( 0 ), attribOrder( 0 ), blockCol( 0 ),
2935 blockMixElemType( 0 ), blockPyrType( 0 ), blockMat( 0 ), blockLength( 0 ), blockDim( 0 ), setHandle( 0 ),
2942 std::cout <<
"blockID = " << blockID << std::endl;
2943 std::cout <<
"blockElemType = " << blockElemType << std::endl;
2944 std::cout <<
"memCt = " << memCt << std::endl;
2945 std::cout <<
"memOffset = " << memOffset << std::endl;
2946 std::cout <<
"memTypeCt = " << memTypeCt << std::endl;
2947 std::cout <<
"attribOrder = " << attribOrder << std::endl;
2948 std::cout <<
"blockCol = " << blockCol << std::endl;
2949 std::cout <<
"blockMixElemType = " << blockMixElemType << std::endl;
2950 std::cout <<
"blockPyrType = " << blockPyrType << std::endl;
2951 std::cout <<
"blockMat = " << blockMat << std::endl;
2952 std::cout <<
"blockLength = " << blockLength << std::endl;
2953 std::cout <<
"blockDim = " << blockDim << std::endl;
2954 std::cout <<
"setHandle = " << setHandle << std::endl;
2955 std::cout <<
"blockEntityType = " << blockEntityType << std::endl;
2959 : nsID( 0 ), memCt( 0 ), memOffset( 0 ), memTypeCt( 0 ), pointSym( 0 ), nsCol( 0 ), nsLength( 0 ), setHandle( 0 )
2965 std::cout <<
"nsID = " << nsID << std::endl;
2966 std::cout <<
"memCt = " << memCt << std::endl;
2967 std::cout <<
"memOffset = " << memOffset << std::endl;
2968 std::cout <<
"memTypeCt = " << memTypeCt << std::endl;
2969 std::cout <<
"pointSym = " << pointSym << std::endl;
2970 std::cout <<
"nsCol = " << nsCol << std::endl;
2971 std::cout <<
"nsLength = " << nsLength << std::endl;
2972 std::cout <<
"setHandle = " << setHandle << std::endl;
2976 : ssID( 0 ), memCt( 0 ), memOffset( 0 ), memTypeCt( 0 ), numDF( 0 ), ssCol( 0 ), useShell( 0 ), ssLength( 0 ),
2983 std::cout <<
"ssID = " << ssID << std::endl;
2984 std::cout <<
"memCt = " << memCt << std::endl;
2985 std::cout <<
"memOffset = " << memOffset << std::endl;
2986 std::cout <<
"memTypeCt = " << memTypeCt << std::endl;
2987 std::cout <<
"numDF = " << numDF << std::endl;
2988 std::cout <<
"ssCol = " << ssCol << std::endl;
2989 std::cout <<
"useShell = " << useShell << std::endl;
2990 std::cout <<
"ssLength = " << ssLength << std::endl;
2991 std::cout <<
"setHandle = " << setHandle << std::endl;
2995 : mdOwner( 0 ), mdDataType( 0 ), mdIntValue( 0 ), mdName(
"(uninit)" ), mdStringValue(
"(uninit)" ), mdDblValue( 0 )
3001 std::cout <<
"MetaDataEntry:own, typ, name, I, D, S = " << mdOwner <<
", " << mdDataType <<
", " << mdName <<
", "
3002 << mdIntValue <<
", " << mdDblValue <<
", " << mdStringValue;
3004 if( mdIntArrayValue.size() )
3006 std::cout << std::endl <<
"IArray = " << mdIntArrayValue[0];
3007 for( i = 1; i < mdIntArrayValue.size(); i++ )
3008 std::cout <<
", " << mdIntArrayValue[i];
3010 if( mdDblArrayValue.size() )
3012 std::cout << std::endl <<
"DArray = " << mdDblArrayValue[0];
3013 for( i = 1; i < mdDblArrayValue.size(); i++ )
3014 std::cout <<
", " << mdDblArrayValue[i];
3016 std::cout << std::endl;
3021 std::cout <<
"MetaDataContainer:mdSchema, compressFlag, numDatums = " <<
mdSchema <<
", " <<
compressFlag <<
", "
3032 for(
unsigned int i = 0; i < metadataEntries.size(); i++ )
3034 if( owner == metadataEntries[i].mdOwner && name == metadataEntries[i].mdName )
return i;
3041 : modelHandle( 0 ), modelOffset( 0 ), modelLength( 0 ), modelType( 0 ), modelOwner( 0 ), modelPad( 0 ),
3042 feGeomH( NULL ), feGroupH( NULL ), feBlockH( NULL ), feNodeSetH( NULL ), feSideSetH( NULL )
3051 delete[] feNodeSetH;
3052 delete[] feSideSetH;
3057 std::cout <<
"ModelEntry: Han, Of, Len, Tp, Own, Pd = " << modelHandle <<
", " << modelOffset <<
", " << modelLength
3058 <<
", " << modelType <<
", " << modelOwner <<
", " << modelPad << std::endl;