39 if( MB_SUCCESS != result ) \
41 std::cerr << ( a ) << std::endl; \
46 if( n != ( a ) ) return MB_FILE_WRITE_ERROR
83 const Tag* file_id_tag )
93 FILE* file_ptr = fopen( filename,
"r" );
108 double dum_params[] = { 0.0, 0.0, 0.0 };
114 CHECK(
"Failed to create param coords tag." );
119 CHECK(
"Failed to create geom dim tag." );
122 char line[256], all_line[1024];
125 if( fgets( all_line,
sizeof( all_line ), file_ptr ) == NULL )
129 if( sscanf( all_line,
"%s %d", line, &file_type ) != 2 )
137 CHECK(
"Failed to read parallel info." );
140 int nregions, nfaces, nedges, nvertices, npoints;
141 n = fscanf( file_ptr,
"%d %d %d %d %d", &nregions, &nfaces, &nedges, &nvertices, &npoints );
143 if( nregions < 0 || nfaces < 0 || nedges < 0 || nvertices < 0 || npoints < 0 )
return MB_FILE_WRITE_ERROR;
146 std::vector< double* > coord_arrays;
149 CHECK(
"Failed to get node arrays." );
157 std::vector< EntityHandle > gentities[4];
158 int gent_id, dum_int;
159 int gent_type, num_connections;
161 for(
int i = 0; i < nvertices; i++ )
163 n = fscanf( file_ptr,
"%d", &gent_id );
165 if( !gent_id )
continue;
167 n = fscanf( file_ptr,
"%d %d %lf %lf %lf", &gent_type, &num_connections, coord_arrays[0] + i,
168 coord_arrays[1] + i, coord_arrays[2] + i );
173 new_handle = vstart + i;
175 CHECK(
"Adding vertex to geom set failed." );
180 n = fscanf( file_ptr,
"%le", dum_params );
183 CHECK(
"Failed to set param coords tag for vertex." );
186 n = fscanf( file_ptr,
"%le %le %d", dum_params, dum_params + 1, &dum_int );
188 dum_params[2] = dum_int;
190 CHECK(
"Failed to set param coords tag for vertex." );
201 int vert1, vert2, num_pts;
202 std::vector< EntityHandle > everts( 2 );
205 CHECK(
"Failed to create array of edges." );
213 for(
int i = 0; i < nedges; i++ )
215 n = fscanf( file_ptr,
"%d", &gent_id );
217 if( !gent_id )
continue;
219 n = fscanf( file_ptr,
"%d %d %d %d %d", &gent_type, &vert1, &vert2, &num_connections, &num_pts );
224 connect[0] = vstart + vert1 - 1;
225 connect[1] = vstart + vert2 - 1;
226 if( num_pts > 1 && !warned )
228 std::cout <<
"Warning: num_points > 1 not supported; choosing last one." << std::endl;
233 CHECK(
"Problem getting geom set for edge." );
235 new_handle = estart + i;
237 CHECK(
"Failed to add edge to geom set." );
241 for(
int j = 0; j < num_pts; j++ )
246 n = fscanf( file_ptr,
"%le", dum_params );
249 CHECK(
"Failed to set param coords tag for edge." );
252 n = fscanf( file_ptr,
"%le %le %d", dum_params, dum_params + 1, &dum_int );
254 dum_params[2] = dum_int;
256 CHECK(
"Failed to set param coords tag for edge." );
267 std::vector< EntityHandle > bound_ents, bound_verts, new_faces;
270 new_faces.resize( nfaces );
273 for(
int i = 0; i < nfaces; i++ )
275 n = fscanf( file_ptr,
"%d", &gent_id );
277 if( !gent_id )
continue;
279 n = fscanf( file_ptr,
"%d %d", &gent_type, &num_bounding );
283 CHECK(
"Problem getting geom set for face." );
285 bound_ents.resize( num_bounding + 1 );
286 bound_verts.resize( num_bounding );
287 for(
int j = 0; j < num_bounding; j++ )
289 n = fscanf( file_ptr,
"%d ", &bound_id );
291 if( 0 > bound_id ) bound_id = abs( bound_id );
292 assert( 0 < bound_id && bound_id <= nedges );
294 bound_ents[j] = estart + abs( bound_id ) - 1;
298 for(
int j = 0; j < num_bounding; j++ )
300 if( j == num_bounding - 1 ) bound_ents[j + 1] = bound_ents[0];
302 CHECK(
"Failed to get vertices bounding edge." );
303 assert( shverts.
size() == 1 );
304 bound_verts[j] = *shverts.
begin();
310 CHECK(
"Failed to create edge." );
313 CHECK(
"Failed to add edge to geom set." );
315 int num_read = fscanf( file_ptr,
"%d", &num_pts );
316 if( !num_pts || !num_read )
continue;
318 for(
int j = 0; j < num_pts; j++ )
323 n = fscanf( file_ptr,
"%le", dum_params );
326 CHECK(
"Failed to set param coords tag for face." );
329 n = fscanf( file_ptr,
"%le %le %d", dum_params, dum_params + 1, &dum_int );
331 dum_params[2] = dum_int;
333 CHECK(
"Failed to set param coords tag for face." );
353 std::vector< EntityHandle > regions;
354 if( file_id_tag ) regions.resize( nregions );
355 for(
int i = 0; i < nregions; i++ )
357 n = fscanf( file_ptr,
"%d", &gent_id );
359 if( !gent_id )
continue;
361 CHECK(
"Couldn't get geom set for region." );
362 n = fscanf( file_ptr,
"%d", &num_bounding );
364 bound_ents.resize( num_bounding );
365 for(
int j = 0; j < num_bounding; j++ )
367 n = fscanf( file_ptr,
"%d ", &bound_id );
369 assert( abs( bound_id ) < (
int)new_faces.size() + 1 && bound_id );
371 sense[j] = ( bound_id < 0 ) ? -1 : 1;
372 bound_ents[j] = new_faces[abs( bound_id ) - 1];
377 CHECK(
"Failed in get_ordered_vertices." );
381 CHECK(
"Failed to create region." );
384 CHECK(
"Failed to add region to geom set." );
386 if( file_id_tag ) regions[i] = new_handle;
388 n = fscanf( file_ptr,
"%d ", &dum_int );
406 const Tag* file_id_tag )
412 if( (
int)sets[set_dim].
size() <= set_id || !sets[set_dim][set_id] )
414 if( (
int)sets[set_dim].
size() <= set_id ) sets[set_dim].resize( set_id + 1, 0 );
416 if( !sets[set_dim][set_id] )
433 this_set = sets[set_dim][set_id];
443 int nparts, part_id, num_ifaces, num_corner_ents;
444 int num_read = fscanf( file_ptr,
"%d %d %d %d", &
nparts, &part_id, &num_ifaces, &num_corner_ents );
445 if( !num_read )
return MB_FAILURE;
448 int iface_id, iface_dim, iface_own, num_iface_corners;
450 std::vector< int >* iface_corners = NULL;
451 for(
int i = 0; i < num_ifaces; i++ )
453 num_read = fscanf( file_ptr,
"%d %d %d %d", &iface_id, &iface_dim, &iface_own, &num_iface_corners );
454 if( !num_read )
return MB_FAILURE;
460 iface_corners =
new std::vector< int >( num_iface_corners );
461 for(
int j = 0; j < num_iface_corners; j++ )
463 num_read = fscanf( file_ptr,
"%d", &( *iface_corners )[j] );
466 delete iface_corners;
475 delete iface_corners;
476 iface_corners = NULL;
485 if( !count || !file_id_tag )
return MB_FAILURE;
488 range.
insert( start, start + count - 1 );