46 assert( NULL != impl );
75 const Tag* file_id_tag )
87 if(
debug ) std::cout <<
"begin ReadNASTRAN::load_file" << std::endl;
98 std::ifstream file( filename );
111 std::vector< std::string > tokens;
112 tokens.reserve( 10 );
120 entity_count[type]++;
121 getline( file, line );
128 std::cout <<
"entity_count[" << i <<
"]=" << entity_count[i] << std::endl;
133 std::vector< Range > materials;
137 std::vector< double* > coord_arrays( 3 );
140 if( 0 == start_vert )
return MB_FAILURE;
141 int id, vert_index = 0;
142 if(
debug ) std::cout <<
"allocated coord arrays" << std::endl;
149 getline( file, line );
154 std::vector< std::string > tokens;
155 tokens.reserve( 10 );
167 double* coords[3] = { coord_arrays[0] + vert_index, coord_arrays[1] + vert_index,
168 coord_arrays[2] + vert_index };
171 if( !
nodeIdMap.
insert(
id, start_vert + vert_index, 1 ).second )
return MB_FAILURE;
200 std::string::size_type found_asterisk = line.find(
"*" );
201 if( std::string::npos != found_asterisk )
208 std::string::size_type found_comma = line.find(
"," );
209 if( std::string::npos != found_comma )
225 std::vector< std::string >& tokens )
227 size_t line_size = line.size();
233 const int field_length = 8;
234 unsigned int n_tokens = line_size / field_length;
235 for(
unsigned int i = 0; i < n_tokens; i++ )
237 tokens.push_back( line.substr( i * field_length, field_length ) );
254 if( 0 == first_token.compare(
"GRID " ) )
256 else if( 0 == first_token.compare(
"CTETRA " ) )
258 else if( 0 == first_token.compare(
"CPENTA " ) )
260 else if( 0 == first_token.compare(
"CHEXA " ) )
285 std::string significand = token;
286 std::string exponent =
"0";
290 std::string back_token = token.substr( 1 );
293 std::string::size_type found_minus = back_token.find(
"-" );
294 if( std::string::npos != found_minus )
297 exponent = token.substr( found_minus + 1 );
298 significand = token.substr( 0, found_minus + 1 );
301 if( std::string::npos != significand.find(
"E" ) )
303 significand = significand.substr( 1, significand.size() - 2 );
310 std::string::size_type found_E = token.find(
"E" );
311 if( std::string::npos != found_E )
313 significand = token.substr( 0, found_E - 1 );
314 exponent = token.substr( found_E + 1 );
316 std::size_t found_plus = exponent.find(
"+" );
317 if( std::string::npos != found_plus )
319 exponent = exponent.substr( found_plus + 1 );
325 std::size_t found_plus = token.find(
"+" );
326 if( std::string::npos != found_plus )
328 significand = token.substr( 0, found_plus - 1 );
329 exponent = token.substr( found_plus + 1 );
335 double signi = atof( significand.c_str() );
336 double expon = atof( exponent.c_str() );
338 if( HUGE_VAL == signi || HUGE_VAL == expon )
return MB_FAILURE;
340 real = signi * pow( 10, expon );
354 id = atoi( tokens[1].c_str() );
358 int coord_system = atoi( tokens[2].c_str() );
359 if( 0 != coord_system )
361 std::cerr <<
"ReadNASTRAN: alternative coordinate systems not implemented" << std::endl;
366 for(
unsigned int i = 0; i < 3; i++ )
368 result =
get_real( tokens[i + 3], *coords[i] );
370 if(
debug ) std::cout <<
"read_node: coords[" << i <<
"]=" << coords[i] << std::endl;
380 std::vector< Range >& materials,
381 const EntityType element_type,
386 int id = atoi( tokens[1].c_str() );
387 int material = atoi( tokens[2].c_str() );
391 if( material >= (
int)materials.size() )
393 if( (
int)materials.capacity() < material )
394 materials.resize( material + 1 );
397 std::vector< Range > new_mat( material + 1 );
398 for(
size_t i = 0; i < materials.size(); ++i )
399 new_mat[i].swap( materials[i] );
400 materials.swap( new_mat );
407 assert( n_conn <= (
int)(
sizeof( conn_verts ) /
sizeof(
EntityHandle ) ) );
410 for(
int i = 0; i < n_conn; i++ )
412 int n = atoi( tokens[3 + i].c_str() );
424 materials[material].insert( element );
437 for(
size_t i = 0; i < materials.size(); ++i )
439 if( materials[i].empty() )
continue;
467 for(
int t = 0; t < 2; ++t )
470 for( i = fileIdMap.
begin(); i != fileIdMap.
end(); ++i )
472 Range range( i->value, i->value + i->count - 1 );
477 if( file_id_tag && *file_id_tag != id_tag )