[MOAB-dev] r3015 - MOAB/trunk

kraftche at mcs.anl.gov kraftche at mcs.anl.gov
Wed Jul 15 18:00:22 CDT 2009


Author: kraftche
Date: 2009-07-15 18:00:20 -0500 (Wed, 15 Jul 2009)
New Revision: 3015

Modified:
   MOAB/trunk/MBRange.hpp
   MOAB/trunk/MBReadUtil.cpp
   MOAB/trunk/MBReadUtil.hpp
   MOAB/trunk/MBReadUtilIface.hpp
   MOAB/trunk/MBReaderIface.hpp
   MOAB/trunk/RangeMap.hpp
   MOAB/trunk/ReadCGM.cpp
   MOAB/trunk/ReadCGM.hpp
   MOAB/trunk/ReadGmsh.cpp
   MOAB/trunk/ReadGmsh.hpp
   MOAB/trunk/ReadHDF5.cpp
   MOAB/trunk/ReadHDF5.hpp
   MOAB/trunk/ReadIDEAS.cpp
   MOAB/trunk/ReadIDEAS.hpp
   MOAB/trunk/ReadMCNP5.cpp
   MOAB/trunk/ReadMCNP5.hpp
   MOAB/trunk/ReadNCDF.cpp
   MOAB/trunk/ReadNCDF.hpp
   MOAB/trunk/ReadSTL.cpp
   MOAB/trunk/ReadSTL.hpp
   MOAB/trunk/ReadSms.cpp
   MOAB/trunk/ReadSms.hpp
   MOAB/trunk/ReadTetGen.cpp
   MOAB/trunk/ReadTetGen.hpp
   MOAB/trunk/ReadVtk.cpp
   MOAB/trunk/ReadVtk.hpp
   MOAB/trunk/Tqdcfr.cpp
   MOAB/trunk/Tqdcfr.hpp
Log:
o Add new optional argument for all readers:  const MBTag* file_id_tag = 0
  If non-null, file readers store file IDs in designated tag.
o Clean up any created entities if read of SMS file fails
o Check geometry dimension value read from SMS file before using it
  as an array index.
o Add error handling to ReadIDEAS
o Fix bug in ReadIDEAS: wrong vertices uses in element connectivity
  if database is not empty when reading file.



Modified: MOAB/trunk/MBRange.hpp
===================================================================
--- MOAB/trunk/MBRange.hpp	2009-07-15 22:42:45 UTC (rev 3014)
+++ MOAB/trunk/MBRange.hpp	2009-07-15 23:00:20 UTC (rev 3015)
@@ -650,6 +650,8 @@
 
   const_pair_iterator const_pair_begin() const { return const_pair_iterator( mHead.mNext ); }
   const_pair_iterator const_pair_end() const { return const_pair_iterator( &mHead ); }
+  const_pair_iterator pair_begin() const { return const_pair_iterator( mHead.mNext ); }
+  const_pair_iterator pair_end() const { return const_pair_iterator( &mHead ); }
 };
 
  

Modified: MOAB/trunk/MBReadUtil.cpp
===================================================================
--- MOAB/trunk/MBReadUtil.cpp	2009-07-15 22:42:45 UTC (rev 3014)
+++ MOAB/trunk/MBReadUtil.cpp	2009-07-15 23:00:20 UTC (rev 3015)
@@ -318,3 +318,75 @@
   etype = MBMAXTYPE;
   return MB_FAILURE;
 }
+
+static MBErrorCode check_int_tag( MBInterface* mb, MBTag tag )
+{
+  int size;
+  MBDataType type;
+  MBErrorCode rval = mb->tag_get_size( tag, size );
+  if (MB_SUCCESS != rval)
+    return rval;
+  if (size != sizeof(int))
+    return MB_TYPE_OUT_OF_RANGE;
+  rval = mb->tag_get_data_type( tag, type );
+  if (type != MB_TYPE_OPAQUE && type != MB_TYPE_INTEGER)
+    return MB_TYPE_OUT_OF_RANGE;
+  return MB_SUCCESS;
+}
+
+MBErrorCode MBReadUtil::assign_ids( MBTag id_tag, const MBRange& ents, int start )
+{
+  MBErrorCode rval = check_int_tag( mMB, id_tag );
+  if (MB_SUCCESS != rval)
+    return rval;
+
+  MBRange tmp_range;
+  std::vector<int> data;
+  for (MBRange::const_pair_iterator i = ents.pair_begin(); 
+       i != ents.pair_end(); ++i) {
+    data.resize( i->second + 1 - i->first );
+    for (std::vector<int>::iterator j = data.begin(); j != data.end(); ++j)
+      *j = start++;
+    tmp_range.clear();
+    tmp_range.insert( i->first, i->second );
+    rval = mMB->tag_set_data( id_tag, tmp_range, &data[0] );
+    if (MB_SUCCESS != rval)
+      return rval;
+  }
+  
+  return MB_SUCCESS;
+}
+
+MBErrorCode MBReadUtil::assign_ids( MBTag id_tag, 
+                                    const MBEntityHandle* ents, 
+                                    size_t num_ents, 
+                                    int start )
+{
+  MBErrorCode rval = check_int_tag( mMB, id_tag );
+  if (MB_SUCCESS != rval)
+    return rval;
+
+  std::vector<int> data;
+  const MBEntityHandle* const end = ents + num_ents;
+  const MBEntityHandle* i = ents;
+  while (i != end) {
+    const MBEntityHandle* next = std::find( i, end, 0 );
+    size_t size = next - i;
+    if (!size) {
+      ++i;
+      continue;
+    }
+    
+    int id = start + (i - ents);
+    data.resize(size);
+    for (std::vector<int>::iterator j = data.begin(); j != data.end(); ++j)
+      *j = id++;
+    
+    rval = mMB->tag_set_data( id_tag, i, size, &data[0] );
+    if (MB_SUCCESS != rval)
+      return rval;
+  }
+  
+  return MB_SUCCESS;
+}
+

Modified: MOAB/trunk/MBReadUtil.hpp
===================================================================
--- MOAB/trunk/MBReadUtil.hpp	2009-07-15 22:42:45 UTC (rev 3014)
+++ MOAB/trunk/MBReadUtil.hpp	2009-07-15 23:00:20 UTC (rev 3015)
@@ -104,6 +104,11 @@
                                    int dim,
                                    MBEntityHandle *bound_verts, 
                                    MBEntityType &etype);
+
+
+  MBErrorCode assign_ids( MBTag id_tag, const MBRange& ents, int start = 0 );
+  MBErrorCode assign_ids( MBTag id_tag, const MBEntityHandle* ents, 
+                          size_t num_ents, int start = 0 );
 };
 
 #endif

Modified: MOAB/trunk/MBReadUtilIface.hpp
===================================================================
--- MOAB/trunk/MBReadUtilIface.hpp	2009-07-15 22:42:45 UTC (rev 3014)
+++ MOAB/trunk/MBReadUtilIface.hpp	2009-07-15 23:00:20 UTC (rev 3015)
@@ -146,6 +146,16 @@
                                            int dim,
                                            MBEntityHandle *bound_verts, 
                                            MBEntityType &etype) = 0;
+
+    //! Assign sequential IDS to entities in range and store IDs in tag
+  virtual MBErrorCode assign_ids( MBTag id_tag, const MBRange& ents, 
+                                  int start = 0 ) = 0;
+  
+    //! Assign to each entity in an array the ID that is its position
+    //! in the array plus the value of 'start'.  For any non-zero handles
+    //! in the array, store the ID value in the passed tag.
+  virtual MBErrorCode assign_ids( MBTag id_tag, const MBEntityHandle* ents, 
+                                  size_t num_ents, int start = 0 ) = 0;
 };
 
 inline 

Modified: MOAB/trunk/MBReaderIface.hpp
===================================================================
--- MOAB/trunk/MBReaderIface.hpp	2009-07-15 22:42:45 UTC (rev 3014)
+++ MOAB/trunk/MBReaderIface.hpp	2009-07-15 23:00:20 UTC (rev 3015)
@@ -39,11 +39,17 @@
      *
      * Method all readers must provide to import a mesh.
      *
-     *\param file_name           The file to read.
-     *\param file_set            Output: a new entity set containing all data read from file.
-     *\param material_set_list   A list of material sets to read, or NULL
-     *                           if the entire file is to be read.
-     *\param material_set_list_len The length of <code>material_set_list</code>
+     *\param file_name      The file to read.
+     *\param file_set       Output: a new entity set containing all data read from file.
+     *\param set_tag_name   If only reading part of the file, the entities
+     *                      to be read will be identified by their values
+     *                      for this integer tag.
+     *\param set_tag_values For the integer tag with the name indicated by
+     *                      set_tag_name, the list of tag values for entities/sets
+     *                      to read.
+     *\param num_set_tag_values The length of the 'set_tag_values' array.
+     *\param file_id_tag    If specified, reader should store for each entity
+     *                      it reads, a unique integer ID for this tag.
      *\author Jason Kraftcheck
      */
     virtual MBErrorCode load_file( const char* file_name,
@@ -51,7 +57,8 @@
                                    const FileOptions& opts,
                                    const char* set_tag_name = 0,
                                    const int* set_tag_values = 0,
-                                   int num_set_tag_values = 0 ) = 0;
+                                   int num_set_tag_values = 0,
+                                   const MBTag* file_id_tag = 0 ) = 0;
 
 };
 

Modified: MOAB/trunk/RangeMap.hpp
===================================================================
--- MOAB/trunk/RangeMap.hpp	2009-07-15 22:42:45 UTC (rev 3014)
+++ MOAB/trunk/RangeMap.hpp	2009-07-15 23:00:20 UTC (rev 3015)
@@ -35,6 +35,9 @@
 class RangeMap 
 {
 public:
+  typedef KeyType key_type;
+  typedef ValType value_type;
+
   struct Range {
     KeyType begin, count;
     ValType value;

Modified: MOAB/trunk/ReadCGM.cpp
===================================================================
--- MOAB/trunk/ReadCGM.cpp	2009-07-15 22:42:45 UTC (rev 3014)
+++ MOAB/trunk/ReadCGM.cpp	2009-07-15 23:00:20 UTC (rev 3015)
@@ -99,7 +99,8 @@
                       MBEntityHandle& file_set,
                       const FileOptions& opts,
                       const char* name_subset,
-                      const int*, const int)
+                      const int*, const int,
+                      const MBTag* file_id_tag)
 {
   // blocks_to_load and num_blocks are ignored.
   MBErrorCode rval;
@@ -557,6 +558,9 @@
   loaded_range = subtract( loaded_range, init_range);
   rval = mdbImpl->add_entities(mCurrentMeshHandle, loaded_range);
   if (MB_FAILURE == rval) return rval;
+  
+  if (file_id_tag)
+    readUtilIface->assign_ids( *file_id_tag, loaded_range );
 
   file_set = mCurrentMeshHandle;
   return MB_SUCCESS;

Modified: MOAB/trunk/ReadCGM.hpp
===================================================================
--- MOAB/trunk/ReadCGM.hpp	2009-07-15 22:42:45 UTC (rev 3014)
+++ MOAB/trunk/ReadCGM.hpp	2009-07-15 23:00:20 UTC (rev 3015)
@@ -60,7 +60,8 @@
                          const FileOptions& opts,
                          const char* set_tag_name,
                          const int* set_tag_values,
-                         int num_set_tag_values );
+                         int num_set_tag_values,
+                         const MBTag* file_id_tag );
 
    //! Constructor
    ReadCGM(MBInterface* impl = NULL);

Modified: MOAB/trunk/ReadGmsh.cpp
===================================================================
--- MOAB/trunk/ReadGmsh.cpp	2009-07-15 22:42:45 UTC (rev 3014)
+++ MOAB/trunk/ReadGmsh.cpp	2009-07-15 23:00:20 UTC (rev 3015)
@@ -84,7 +84,9 @@
                                  MBEntityHandle& file_set,
                                  const FileOptions& ,
                                  const char* set_tag_name,
-                                 const int* blocks, const int num_blocks )
+                                 const int* blocks, 
+                                 const int num_blocks,
+                                 const MBTag* file_id_tag )
 {
   if (!strcmp( set_tag_name, MATERIAL_SET_TAG_NAME )) {
     readMeshIface->report_error( "GMsh supports subset read only by material ID." );
@@ -92,7 +94,7 @@
   }
 
   mCurrentMeshHandle = 0;
-  const MBErrorCode result = load_file_impl( filename, blocks, num_blocks );
+  const MBErrorCode result = load_file_impl( filename, blocks, num_blocks, file_id_tag );
   
     // If file read has failed, destroy anything that was
     // created during the read.
@@ -112,7 +114,8 @@
 
 MBErrorCode ReadGmsh::load_file_impl( const char* filename, 
                                       const int* material_set_list,
-                                      const int num_material_sets )
+                                      const int num_material_sets,
+                                      const MBTag* file_id_tag )
 {
   geomSets.clear();
   MBErrorCode result = mdbImpl->tag_get_handle( GLOBAL_ID_TAG_NAME, globalId );
@@ -195,7 +198,7 @@
   double *x = coord_arrays[0], 
          *y = coord_arrays[1],
          *z = coord_arrays[2];
-  for( long i = 0; i < num_nodes; ++i )
+  for( long i = 0; i < num_nodes; ++i, ++handle )
   {
     long id;
     if (!tokens.get_long_ints( 1, &id ) ||
@@ -204,7 +207,7 @@
         !tokens.get_doubles( 1, z++ ))
       return MB_FILE_WRITE_ERROR;
     
-    if (!node_id_map.insert( std::pair<long,MBEntityHandle>( id, handle++ ) ).second)
+    if (!node_id_map.insert( std::pair<long,MBEntityHandle>( id, handle ) ).second)
     {
       readMeshIface->report_error( "Dulicate node ID at line %d\n",
                                    tokens.line_number() );
@@ -227,6 +230,11 @@
   result = mdbImpl->tag_set_data( globalId, &handles[0], num_nodes, &ids[0] );
   if (MB_SUCCESS != result)
     return result;
+  if (file_id_tag) {
+    result = mdbImpl->tag_set_data( *file_id_tag, &handles[0], num_nodes, &ids[0] );
+    if (MB_SUCCESS != result) 
+      return result;
+  }
   ids.clear();
   handles.clear();
   
@@ -296,7 +304,8 @@
                                   mat_set_list,
                                   geom_set_list,
                                   part_set_list,
-                                  connectivity ) ;
+                                  connectivity,
+                                  file_id_tag ) ;
         if (MB_SUCCESS != result)
           return result;
       }
@@ -348,7 +357,8 @@
                               mat_set_list,
                               geom_set_list,
                               part_set_list,
-                              connectivity ) ;
+                              connectivity,
+                              file_id_tag ) ;
     if (MB_SUCCESS != result)
       return result;
   }
@@ -367,7 +377,8 @@
                                const std::vector<int>& matl_ids,
                                const std::vector<int>& geom_ids,
                                const std::vector<int>& prtn_ids,
-                               const std::vector<MBEntityHandle>& connectivity )
+                               const std::vector<MBEntityHandle>& connectivity,
+                               const MBTag* file_id_tag )
 {
   MBErrorCode result;
   
@@ -415,6 +426,11 @@
   result = mdbImpl->tag_set_data( globalId, elements, &elem_ids[0] );
   if (MB_SUCCESS != result)
     return result;
+  if (file_id_tag) {
+    result = mdbImpl->tag_set_data( *file_id_tag, elements, &elem_ids[0] );
+    if (MB_SUCCESS != result) 
+      return result;
+  }
   
     // Add elements to material sets
   result = create_sets( type.mbtype, elements, matl_ids, 0 );

Modified: MOAB/trunk/ReadGmsh.hpp
===================================================================
--- MOAB/trunk/ReadGmsh.hpp	2009-07-15 22:42:45 UTC (rev 3014)
+++ MOAB/trunk/ReadGmsh.hpp	2009-07-15 23:00:20 UTC (rev 3015)
@@ -43,7 +43,8 @@
                         const FileOptions& opts,
                         const char* set_tag_name,
                         const int* set_tag_values,
-                        int num_set_tag_values );
+                        int num_set_tag_values,
+                        const MBTag* file_id_tag );
   
     //! Constructor
   ReadGmsh(MBInterface* impl = NULL);
@@ -61,14 +62,16 @@
 
   MBErrorCode load_file_impl( const char *file_name,
                               const int* material_set_list,
-                              const int num_material_sets );
+                              const int num_material_sets,
+                              const MBTag* file_id_tag );
   
   MBErrorCode create_elements( const ElementType& type,
                                const std::vector<int>& elem_ids,
                                const std::vector<int>& matl_ids,
                                const std::vector<int>& geom_ids,
                                const std::vector<int>& prtn_ids,
-                               const std::vector<MBEntityHandle>& connectivity );
+                               const std::vector<MBEntityHandle>& connectivity,
+                               const MBTag* file_id_tag );
 
   MBErrorCode create_sets( MBEntityType element_type,
                            const MBRange& elements,

Modified: MOAB/trunk/ReadHDF5.cpp
===================================================================
--- MOAB/trunk/ReadHDF5.cpp	2009-07-15 22:42:45 UTC (rev 3014)
+++ MOAB/trunk/ReadHDF5.cpp	2009-07-15 23:00:20 UTC (rev 3015)
@@ -147,7 +147,8 @@
                                  const FileOptions& opts,
                                  const char* name,
                                  const int* id_list, 
-                                 const int num_ids )
+                                 const int num_ids,
+                                 const MBTag* file_id_tag )
 {
   MBErrorCode rval;
   mhdf_Status status;
@@ -263,6 +264,9 @@
       range.insert( i->value, i->value + i->count - 1 );
     iFace->delete_entities( range );
   }
+  else if (file_id_tag) {
+    rval = store_file_ids( *file_id_tag );
+  }
   
   free( dataBuffer );
   free( fileInfo );
@@ -3158,5 +3162,38 @@
   return MB_SUCCESS;
 }
 
-  
+MBErrorCode ReadHDF5::store_file_ids( MBTag tag )
+{
+  typedef int tag_type;
+  tag_type* buffer = reinterpret_cast<tag_type*>(dataBuffer);
+  const long buffer_size = bufferSize / sizeof(tag_type);
+  for (IDMap::iterator i = idMap.begin(); i != idMap.end(); ++i) {
+    IDMap::Range range = *i;
     
+      // make sure the values will fit in the tag type
+    IDMap::key_type rv = range.begin + (range.count - 1);
+    tag_type tv = (tag_type)rv;
+    if ((IDMap::key_type)tv != rv) {
+      assert(false);
+      return MB_INDEX_OUT_OF_RANGE;
+    }
+    
+    while (range.count) {
+      long count = buffer_size < range.count ? buffer_size : range.count;
+
+      MBRange handles;
+      handles.insert( range.value, range.value + count - 1 );
+      range.value += count;
+      range.count -= count;
+      for (long i = 0; i < count; ++i) 
+        buffer[i] = (tag_type)range.begin++;
+
+      MBErrorCode rval = iFace->tag_set_data( tag, handles, buffer );
+      if (MB_SUCCESS != rval)
+        return rval;
+    }
+  }
+  return MB_SUCCESS;
+}
+
+    

Modified: MOAB/trunk/ReadHDF5.hpp
===================================================================
--- MOAB/trunk/ReadHDF5.hpp	2009-07-15 22:42:45 UTC (rev 3014)
+++ MOAB/trunk/ReadHDF5.hpp	2009-07-15 23:00:20 UTC (rev 3015)
@@ -52,7 +52,8 @@
                          const FileOptions& opts,
                          const char* set_tag_name,
                          const int* set_tag_values,
-                         int num_set_tag_values );
+                         int num_set_tag_values,
+                         const MBTag* file_id_tag );
 protected:
 
   MBErrorCode load_file_impl( MBEntityHandle file_set,
@@ -381,6 +382,13 @@
                              const long num_sets,
                              const long set_content_len,
                              const MBRange& ranged_file_ids );
+  
+    /**\brief Store file IDS in tag values
+     *
+     * Copy fild ID from IDMap for each entity read from file
+     * into a tag value on the entity.
+     */
+  MBErrorCode store_file_ids( MBTag tag );
 };
 
 #endif

Modified: MOAB/trunk/ReadIDEAS.cpp
===================================================================
--- MOAB/trunk/ReadIDEAS.cpp	2009-07-15 22:42:45 UTC (rev 3014)
+++ MOAB/trunk/ReadIDEAS.cpp	2009-07-15 23:00:20 UTC (rev 3015)
@@ -24,7 +24,8 @@
                                  MBEntityHandle& meshset, 
                                  const FileOptions& options,
                                  const char* name,
-                                 const int*, const int ) {
+                                 const int*, const int,
+                                 const MBTag* file_id_tag ) {
 
   if (name) {
     readMeshIface->report_error( "Reading subset of files not supported for IDEAS." );
@@ -43,23 +44,38 @@
   std::string s = line;
   if (s.find("-1") > s.length()) return MB_FAILURE;
 
+  MBEntityHandle first_vertex = 0;
+
   while (! file.eof() ) {
     file.getline(line, 10000);
     s = line;
 
+    MBErrorCode rval;
     unsigned int header_id = (unsigned int) strtol(line, NULL, 10);
     switch (header_id) {
       case VERTEX_LIST :
-        create_vertices(); 
+        if (first_vertex) // multiple vertex blocks?
+          return MB_FAILURE;
+        rval = create_vertices( first_vertex, file_id_tag ); 
       break;
       case MAKE_TETRAHEDRA :
-        create_tetrahedral_elements();
+        if (!first_vertex) // need to read vertices first
+          return MB_FAILURE;
+        rval = create_tetrahedral_elements( first_vertex, file_id_tag );
       break;
       default:
-        skip_header(); 
+        rval = skip_header(); 
       break;
     }
 
+    if (MB_SUCCESS != rval) {
+      file.close();
+      MBRange ents;
+      MBI->get_entities_by_handle( mesh_handle, ents );
+      ents.insert( mesh_handle );
+      MBI->delete_entities( ents );
+      return rval;
+    }
   }
 
   meshset = mesh_handle;
@@ -68,7 +84,7 @@
 
 }
 
-void ReadIDEAS::skip_header() {
+MBErrorCode ReadIDEAS::skip_header() {
 
   // Go until finding a pair of -1 lines
   char *ctmp;
@@ -79,9 +95,8 @@
 
   long int il;
 
-  while (! file.eof() ) {
-    file.getline(line, 10000);
-
+  while (file.getline(line, 10000)) {
+ 
     il = std::strtol(line, &ctmp, 10);
     if (il == -1) {
       s = ctmp;
@@ -89,18 +104,20 @@
     }
     else end_of_block = 0;
 
-    if (end_of_block >= 2) break;
+    if (end_of_block >= 2)
+      return MB_SUCCESS;
 
   }
 
+  return MB_FAILURE;
 }
 
 
 
-void ReadIDEAS::create_vertices() {
+MBErrorCode ReadIDEAS::create_vertices(MBEntityHandle& first_vertex,
+                                       const MBTag* file_id_tag) {
 
   // Read two lines: first has some data, second has coordinates
-  double *coords;
   char line1[10000], line2[10000];
   int il1, il2;
   char *ctmp1, *ctmp2;
@@ -111,10 +128,12 @@
   int top_of_block = file.tellg();
   unsigned int num_verts = 0;
 
-  while (! file.eof() ) {
+  for (;;) {
 
-    file.getline(line1, 10000);
-    file.getline(line2, 10000);
+    if (!file.getline(line1, 10000))
+      return MB_FAILURE;
+    if (!file.getline(line2, 10000))
+      return MB_FAILURE;
 
     // Check if we are at the end of the block
     il1 = std::strtol(line1, &ctmp1, 10);
@@ -128,56 +147,74 @@
   }
 
   file.seekg( top_of_block );
-  coords = new double [ 3*num_verts ];
+  
+  std::vector<double*> arrays;
+  rval = readMeshIface->get_node_arrays( 3, num_verts, 0, first_vertex, arrays );
+  if (MB_SUCCESS != rval)
+    return rval;
 
+  MBRange verts;
+  verts.insert( first_vertex, first_vertex + num_verts - 1 );
+  rval = MBI->add_entities( mesh_handle, verts );
+  assert( MB_SUCCESS == rval );
+  if (MB_SUCCESS != rval)
+    return rval;
+  
+  double *x = arrays[0];
+  double *y = arrays[1];
+  double *z = arrays[2];
   for (unsigned int i = 0; i < num_verts; i++) {
 
-    file.getline(line1, 10000);
-    file.getline(line2, 10000);
+    if (!file.getline(line1, 10000))
+      return MB_FAILURE;
+    if (!file.getline(line2, 10000))
+      return MB_FAILURE;
 
     // Get the doubles out of the 2nd line
-    coords[3*i  ] = std::strtod(line2, &ctmp2);
-    coords[3*i+1] = std::strtod(ctmp2+1, &ctmp2);
-    coords[3*i+2] = std::strtod(ctmp2+1, NULL);
+    x[i] = std::strtod(line2, &ctmp2);
+    y[i] = std::strtod(ctmp2+1, &ctmp2);
+    z[i] = std::strtod(ctmp2+1, NULL);
 
   }
 
-  MBRange verts;
-  rval = MBI->create_vertices(coords, num_verts, verts);
-  assert( MB_SUCCESS == rval );
+  if (!file.getline(line1, 10000))
+    return MB_FAILURE;
+  if (!file.getline(line2, 10000))
+    return MB_FAILURE;
 
-  rval = MBI->add_entities( mesh_handle, verts );
-  assert( MB_SUCCESS == rval );
-
-  file.getline(line1, 10000);
-  file.getline(line2, 10000);
-
+  if (file_id_tag) {
+    rval = readMeshIface->assign_ids( *file_id_tag, verts, 1 );
+    if (MB_SUCCESS != rval)
+      return rval;
+  }
+  
+  return MB_SUCCESS;
 }
 
 
-void ReadIDEAS::create_tetrahedral_elements() {
+MBErrorCode ReadIDEAS::create_tetrahedral_elements(MBEntityHandle vstart,
+                                                   const MBTag* file_id_tag) {
 
   MBEntityHandle connect[4];
   char line1[10000], line2[10000];
-  int il1, il2;
+  int il1, il2, id = 0;
   char *ctmp1, *ctmp2;
   std::string s1, s2;
+  long verts[4];
 
   MBErrorCode rval;
   MBEntityHandle handle;
 
-  MBRange verts;
-  rval = MBI->get_entities_by_type( mesh_handle, MBVERTEX, verts, true);
-  MBEntityHandle vstart = *(verts.begin());
-
   MBTag mat_prop_tag, phys_prop_tag;
   rval = MBI->tag_create( MAT_PROP_TABLE_TAG  , sizeof(int), MB_TAG_DENSE, mat_prop_tag, 0); 
+  if (MB_SUCCESS != rval && MB_ALREADY_ALLOCATED != rval) return rval;
   rval = MBI->tag_create( PHYS_PROP_TABLE_TAG , sizeof(int), MB_TAG_DENSE, phys_prop_tag, 0); 
+  if (MB_SUCCESS != rval && MB_ALREADY_ALLOCATED != rval) return rval;
  
-  while (! file.eof() ) {
+  for (;;) {
 
-    file.getline(line1, 10000);
-    file.getline(line2, 10000);
+    if (!file.getline(line1, 10000) || !file.getline(line2, 10000))
+      return MB_FAILURE;
 
     // Check if we are at the end of the block
     il1 = std::strtol(line1, &ctmp1, 10);
@@ -185,7 +222,8 @@
     if ((il1 == -1) && (il2 == -1)) {
       s1 = ctmp1;
       s2 = ctmp2;
-      if ((s1.empty()) && (s2.empty())) break;     
+      if ((s1.empty()) && (s2.empty())) 
+        return MB_SUCCESS;     
     }
 
     // Get property tables out of 1st line
@@ -193,10 +231,12 @@
     int mat_table  = strtol(line1+31, &ctmp1, 10);
 
     // Get the connectivity out of the 2nd line
-    connect[0] = vstart + strtol( line2, &ctmp2, 10) - 1;
-    connect[1] = vstart + strtol( ctmp2+1, &ctmp2, 10) - 1;
-    connect[2] = vstart + strtol( ctmp2+1, &ctmp2, 10) - 1;
-    connect[3] = vstart + strtol( ctmp2+1, &ctmp2, 10) - 1;
+    if (4 != sscanf( line2, "%ld %ld %ld %ld", verts,verts+1,verts+2,verts+3))
+      return MB_FAILURE;
+    connect[0] = vstart + verts[0] - 1;
+    connect[1] = vstart + verts[1] - 1;
+    connect[2] = vstart + verts[2] - 1;
+    connect[3] = vstart + verts[3] - 1;
 
     // Make the element
     rval = MBI->create_element(MBTET, connect, 4, handle);
@@ -211,6 +251,11 @@
     rval = MBI->add_entities( mesh_handle, &handle, 1);
     assert( MB_SUCCESS == rval );
     
+    if (file_id_tag) {
+      rval = MBI->tag_set_data( *file_id_tag, &handle, 1, &id );
+      ++id;
+    }
   }
-
+  
+  return MB_FAILURE;
 }

Modified: MOAB/trunk/ReadIDEAS.hpp
===================================================================
--- MOAB/trunk/ReadIDEAS.hpp	2009-07-15 22:42:45 UTC (rev 3014)
+++ MOAB/trunk/ReadIDEAS.hpp	2009-07-15 23:00:20 UTC (rev 3015)
@@ -25,7 +25,8 @@
 			const FileOptions&,
 			const char* set_tag_name,
                         const int* set_tag_values,
-                        int num_set_tag_values );
+                        int num_set_tag_values,
+                        const MBTag* file_id_tag );
   
   //! Constructor
   ReadIDEAS(MBInterface* impl = NULL);
@@ -35,9 +36,9 @@
 
 protected:
   
-  void skip_header();
-  void create_vertices();
-  void create_tetrahedral_elements();
+  MBErrorCode skip_header();
+  MBErrorCode create_vertices(MBEntityHandle& first_vertex, const MBTag* file_id_tag);
+  MBErrorCode create_tetrahedral_elements(MBEntityHandle first_vertex, const MBTag* file_id_tag);
   
 private:
   

Modified: MOAB/trunk/ReadMCNP5.cpp
===================================================================
--- MOAB/trunk/ReadMCNP5.cpp	2009-07-15 22:42:45 UTC (rev 3014)
+++ MOAB/trunk/ReadMCNP5.cpp	2009-07-15 23:00:20 UTC (rev 3015)
@@ -29,7 +29,7 @@
 
 // constructor
 ReadMCNP5::ReadMCNP5(MBInterface* impl)
-  : MBI(impl) {
+  : MBI(impl), fileIDTag(0) {
     assert( NULL!=impl);
     void *ptr = 0;
     MBI->query_interface("MBReadUtilIface", &ptr);
@@ -51,13 +51,16 @@
                                  const FileOptions &options,
                                  const char        *set_tag_name,        // not used
                                  const int         *material_set_list,   // not used
-                                 const int         num_material_sets ) { // not used
-  
+                                 const int         num_material_sets,    // not used
+                                 const MBTag*      file_id_tag) {
   // at this time there is no support for reading a subset of the file
   if (set_tag_name) {
     readMeshIface->report_error( "Reading subset of files not supported for meshtal." );
     return MB_UNSUPPORTED_OPERATION;
   }
+  
+  nodeId = elemId = 0;
+  fileIDTag = file_id_tag;
 
   // Average several meshtal files if the AVERAGE_TALLY option is givin.
   // In this case, the integer value is the number of files to average.
@@ -735,7 +738,7 @@
                                         bool                debug,
                                         MBEntityHandle      &start_vert,
                                         coordinate_system   coord_sys,
-                                        MBEntityHandle      tally_meshset) {
+                                        MBEntityHandle      tally_meshset ) {
                                          
   // The only info needed to build elements is the mesh plane boundaries.
   MBErrorCode result;
@@ -769,6 +772,14 @@
   MBRange vert_range(start_vert, start_vert+n_verts-1);
   result = MBI->add_entities( tally_meshset, vert_range );
   if(MB_SUCCESS != result) return result;
+  
+  if (fileIDTag) {
+    result = readMeshIface->assign_ids( *fileIDTag, vert_range, nodeId );
+    if (MB_SUCCESS != result)
+      return result;
+    nodeId += vert_range.size();
+  }
+  
   return MB_SUCCESS;
 }
 
@@ -844,6 +855,14 @@
   result = MBI->add_entities( tally_meshset, element_range );
   if(MB_SUCCESS != result) return result;
   if (debug) std::cout << "Read " << n_elements << " elements from tally." << std::endl;
+  
+  if (fileIDTag) {
+    result = readMeshIface->assign_ids( *fileIDTag, element_range, elemId );
+    if (MB_SUCCESS != result)
+      return result;
+    elemId += element_range.size();
+  }
+
   return MB_SUCCESS;
 }
 

Modified: MOAB/trunk/ReadMCNP5.hpp
===================================================================
--- MOAB/trunk/ReadMCNP5.hpp	2009-07-15 22:42:45 UTC (rev 3014)
+++ MOAB/trunk/ReadMCNP5.hpp	2009-07-15 23:00:20 UTC (rev 3015)
@@ -19,7 +19,8 @@
                         const FileOptions &options,
                         const char*       set_tag_name, /* not used */
                         const int*        material_set_list,
-                        const int         num_material_sets );
+                        const int         num_material_sets,
+                        const MBTag*      file_id_tag );
 
   // constructor
   ReadMCNP5(MBInterface* impl = NULL);
@@ -48,6 +49,9 @@
   
   // MOAB Interface
   MBInterface* MBI;
+  
+  const MBTag* fileIDTag;
+  int nodeId, elemId;
 
   // reads the meshtal file
   MBErrorCode load_one_file( const char        *fname,

Modified: MOAB/trunk/ReadNCDF.cpp
===================================================================
--- MOAB/trunk/ReadNCDF.cpp	2009-07-15 22:42:45 UTC (rev 3014)
+++ MOAB/trunk/ReadNCDF.cpp	2009-07-15 23:00:20 UTC (rev 3015)
@@ -434,7 +434,8 @@
                                 const FileOptions& opts,
                                 const char* set_tag_name,
                                 const int *blocks_to_load,
-                                const int num_blocks)
+                                const int num_blocks,
+                                const MBTag* file_id_tag)
 {
   MBErrorCode status;
 
@@ -474,7 +475,7 @@
     // 2. Read the nodes unless they've already been read before
   if (!previously_loaded)
   {
-    status = read_nodes();
+    status = read_nodes(file_id_tag);
     if (MB_FAILURE == status) return status;
   }
  
@@ -483,7 +484,7 @@
   if (MB_FAILURE == status) return status;
 
     // 4. Read elements (might not read them, depending on active blocks)
-  status = read_elements();
+  status = read_elements(file_id_tag);
   if (MB_FAILURE == status) return status;
   
     // 5. Read global ids
@@ -586,7 +587,7 @@
   return MB_SUCCESS;
 }
  
-MBErrorCode ReadNCDF::read_nodes()
+MBErrorCode ReadNCDF::read_nodes(const MBTag* file_id_tag)
 {
 
     // read the nodes into memory
@@ -651,7 +652,13 @@
       return MB_FAILURE;
     }
   }
-
+  
+  if (file_id_tag) {
+    MBRange nodes;
+    nodes.insert( node_handle, node_handle + numberNodes_loading - 1 );
+    readMeshIface->assign_ids( *file_id_tag, nodes, vertexOffset );
+  }
+  
   return MB_SUCCESS;
 }
 
@@ -826,7 +833,7 @@
 }
 
 
-MBErrorCode ReadNCDF::read_elements()
+MBErrorCode ReadNCDF::read_elements(const MBTag* file_id_tag)
 {
     // read in elements
   
@@ -980,7 +987,13 @@
       return MB_FAILURE;
     if( mdbImpl->tag_set_data( mGlobalIdTag, &ms_handle, 1, &block_id ) != MB_SUCCESS )
       return MB_FAILURE;
-
+      
+      
+    if (file_id_tag) {
+      MBRange range;
+      range.insert( this_it->startMBId, this_it->startMBId + this_it->numElements - 1 );
+      readMeshIface->assign_ids( *file_id_tag, range, this_it->startExoId );
+    }
   }
 
   return MB_SUCCESS;

Modified: MOAB/trunk/ReadNCDF.hpp
===================================================================
--- MOAB/trunk/ReadNCDF.hpp	2009-07-15 22:42:45 UTC (rev 3014)
+++ MOAB/trunk/ReadNCDF.hpp	2009-07-15 23:00:20 UTC (rev 3015)
@@ -74,7 +74,8 @@
                          const FileOptions& opts,
                          const char* set_tag_name,
                          const int* blocks_to_load,
-                         const int num_blocks);
+                         const int num_blocks,
+                         const MBTag* file_id_tag = 0);
   
    //! Constructor
    ReadNCDF(MBInterface* impl = NULL);
@@ -97,14 +98,14 @@
   MBErrorCode read_exodus_header(const char *exodus_file_name);
   
     //! read the nodes
-  MBErrorCode read_nodes();
+  MBErrorCode read_nodes(const MBTag* file_id_tag);
   
     //! read block headers, containing info about element type, number, etc.
   MBErrorCode read_block_headers(const int *blocks_to_load,
                                   const int num_blocks);
   
     //! read the element blocks
-  MBErrorCode read_elements();
+  MBErrorCode read_elements(const MBTag* file_id_tag);
   
     //! read in the global element ids
   MBErrorCode read_global_ids();

Modified: MOAB/trunk/ReadSTL.cpp
===================================================================
--- MOAB/trunk/ReadSTL.cpp	2009-07-15 22:42:45 UTC (rev 3014)
+++ MOAB/trunk/ReadSTL.cpp	2009-07-15 23:00:20 UTC (rev 3015)
@@ -78,10 +78,11 @@
                                 MBEntityHandle& file_set, 
                                 const FileOptions& opts,
                                 const char* name,
-                                const int*, const int )
+                                const int*, const int,
+                                const MBTag* file_id_tag )
 {
   mCurrentMeshHandle = 0;
-  const MBErrorCode result = load_file_impl( filename, opts );
+  const MBErrorCode result = load_file_impl( filename, opts, file_id_tag );
   
   if (name) {
     readMeshIface->report_error( "Reading subset of files not supported for STL." );
@@ -107,7 +108,8 @@
 // pure-virtual function implemented in subclasses to read
 // the data from the file.
 MBErrorCode ReadSTL::load_file_impl(const char *filename,
-                                    const FileOptions& opts ) 
+                                    const FileOptions& opts,
+                                    const MBTag* file_id_tag ) 
 {
   MBErrorCode result;
 
@@ -178,6 +180,12 @@
   if (MB_SUCCESS != result)
     return result;
   
+  if (file_id_tag) {
+    result = readMeshIface->assign_ids( *file_id_tag, range );
+    if (MB_SUCCESS != result)
+      return result;
+  }
+    
     // Copy vertex coordinates into entity sequence coordinate arrays
     // and copy handle into vertex_map.
   double *x = coord_arrays[0], *y = coord_arrays[1], *z = coord_arrays[2];
@@ -208,6 +216,12 @@
   if (MB_SUCCESS != result)
     return result;
   
+  if (file_id_tag) {
+    result = readMeshIface->assign_ids( *file_id_tag, range2 );
+    if (MB_SUCCESS != result)
+      return result;
+  }
+  
     // Use vertex_map to reconver triangle connectivity from
     // vertex coordinates.
   MBEntityHandle *conn_sav = connectivity;

Modified: MOAB/trunk/ReadSTL.hpp
===================================================================
--- MOAB/trunk/ReadSTL.hpp	2009-07-15 22:42:45 UTC (rev 3014)
+++ MOAB/trunk/ReadSTL.hpp	2009-07-15 23:00:20 UTC (rev 3015)
@@ -76,7 +76,8 @@
                         const FileOptions& opts,
                         const char* set_tag_name,
                         const int* set_tag_values,
-                        int num_set_tag_values );
+                        int num_set_tag_values,
+                        const MBTag* file_id_tag );
   
     //! Constructor
   ReadSTL(MBInterface* impl = NULL);
@@ -117,7 +118,9 @@
 
     //! Generic file loading code for both binary and ASCII readers.
     //! Calls reader-specific *_read_triangles function to do actual I/O.
-  MBErrorCode load_file_impl(const char *file_name, const FileOptions& opts );
+  MBErrorCode load_file_impl( const char *file_name, 
+                              const FileOptions& opts,
+                              const MBTag* file_id_tag );
 
     //! Meshset Handle for the mesh that is currently being read
   MBEntityHandle mCurrentMeshHandle;

Modified: MOAB/trunk/ReadSms.cpp
===================================================================
--- MOAB/trunk/ReadSms.cpp	2009-07-15 22:42:45 UTC (rev 3014)
+++ MOAB/trunk/ReadSms.cpp	2009-07-15 23:00:20 UTC (rev 3015)
@@ -65,13 +65,15 @@
                                 MBEntityHandle& file_set,
                                 const FileOptions& ,
                                 const char* name,
-                                const int*, const int )
+                                const int*, const int,
+                                const MBTag* file_id_tag )
 {
   if (name) {
     readMeshIface->report_error( "Reading subset of files not supported for Sms." );
     return MB_UNSUPPORTED_OPERATION;
   }
 
+  setId = 1;
     
     // Open file
   FILE* file_ptr = fopen( filename, "r" );
@@ -82,7 +84,7 @@
   }
 
   mCurrentMeshHandle = 0;
-  const MBErrorCode result = load_file_impl( file_ptr );
+  const MBErrorCode result = load_file_impl( file_ptr, file_id_tag );
   fclose( file_ptr );
   
     // If file read has failed, destroy anything that was
@@ -100,7 +102,7 @@
   return result;
 }
 
-MBErrorCode ReadSms::load_file_impl( FILE* file_ptr )
+MBErrorCode ReadSms::load_file_impl( FILE* file_ptr, const MBTag* file_id_tag )
 {
   bool warned = false;
   
@@ -159,6 +161,10 @@
   CHECK("Failed to get node arrays.");
   if (MB_SUCCESS != result)
     return result;
+    
+  result = add_entities( vstart, nvertices, file_id_tag );
+  if (MB_SUCCESS != result)
+    return result;
   
   MBEntityHandle this_gent, new_handle;
   std::vector<MBEntityHandle> gentities[4];
@@ -175,7 +181,7 @@
            coord_arrays[0]+i, coord_arrays[1]+i, coord_arrays[2]+i);
     CHECKN(5);
     
-    result = get_set(gentities, gent_type, gent_id, geomDimension, this_gent);
+    result = get_set(gentities, gent_type, gent_id, geomDimension, this_gent, file_id_tag );
     if (MB_SUCCESS != result)
       return result;
 
@@ -216,6 +222,10 @@
   result = readMeshIface->get_element_array(nedges, 2, MBEDGE, 1, estart, connect);
   CHECK("Failed to create array of edges.");
   if (MB_SUCCESS != result) return result;
+    
+  result = add_entities( estart, nedges, file_id_tag );
+  if (MB_SUCCESS != result)
+    return result;
 
   for(int i = 0; i < nedges; i++)
   {
@@ -238,7 +248,7 @@
       warned = true;
     }
 
-    result = get_set(gentities, gent_type, gent_id, geomDimension, this_gent);
+    result = get_set(gentities, gent_type, gent_id, geomDimension, this_gent, file_id_tag);
     CHECK("Problem getting geom set for edge.");
     if (MB_SUCCESS != result)
       return result;
@@ -292,7 +302,7 @@
     n = fscanf(file_ptr,"%d %d", &gent_type, &num_bounding);
     CHECKN(2);
 
-    result = get_set(gentities, gent_type, gent_id, geomDimension, this_gent);
+    result = get_set(gentities, gent_type, gent_id, geomDimension, this_gent, file_id_tag);
     CHECK("Problem getting geom set for face.");
     if (MB_SUCCESS != result)
       return result;
@@ -326,6 +336,9 @@
     CHECK("Failed to create edge.");
     if (MB_SUCCESS != result) return result;
 
+    result = mdbImpl->add_entities(mCurrentMeshHandle, &new_faces[i], 1);
+    if (MB_SUCCESS != result) return result;
+
     result = mdbImpl->add_entities(this_gent, &new_faces[i], 1);
     CHECK("Failed to add edge to geom set.");
     if (MB_SUCCESS != result) return result;
@@ -355,6 +368,12 @@
     }
 
   } // end of reading faces
+  
+  if (file_id_tag) {
+    result = readMeshIface->assign_ids( *file_id_tag, &new_faces[0], new_faces.size(), 1 );
+    if (MB_SUCCESS != result)
+      return result;
+  }
 
 
 // *******************************
@@ -363,11 +382,14 @@
   int sense[MB_MAX_SUB_ENTITIES];
   bound_verts.resize(MB_MAX_SUB_ENTITIES);
 
+  std::vector<MBEntityHandle> regions;
+  if (file_id_tag)
+    regions.resize( nregions );
   for(int i = 0; i < nregions; i++)
   {
     n = fscanf(file_ptr, "%d", &gent_id); CHECKN(1);
     if (!gent_id) continue;
-    result = get_set(gentities, 3, gent_id, geomDimension, this_gent);
+    result = get_set(gentities, 3, gent_id, geomDimension, this_gent, file_id_tag);
     CHECK("Couldn't get geom set for region.");
     if (MB_SUCCESS != result)
       return result;
@@ -398,9 +420,18 @@
     CHECK("Failed to add region to geom set.");
     if (MB_SUCCESS != result) return result;
 
+    if (file_id_tag)
+      regions[i] = new_handle;
+  
     n = fscanf(file_ptr, "%d ", &dum_int); CHECKN(1);
 
   } // end of reading regions
+  
+  if (file_id_tag) {
+    result = readMeshIface->assign_ids( *file_id_tag, &regions[0], regions.size(), 1 );
+    if (MB_SUCCESS != result)
+      return result;
+  }
 
   return MB_SUCCESS;
 }
@@ -408,10 +439,14 @@
 MBErrorCode ReadSms::get_set(std::vector<MBEntityHandle> *sets,
                              int set_dim, int set_id,
                              MBTag dim_tag,
-                             MBEntityHandle &this_set) 
+                             MBEntityHandle &this_set,
+                             const MBTag* file_id_tag) 
 {
   MBErrorCode result = MB_SUCCESS;
   
+  if (set_dim < 0 || set_dim > 3)
+    return MB_FILE_WRITE_ERROR;
+  
   if ((int)sets[set_dim].size() <= set_id || 
       !sets[set_dim][set_id]) {
     if ((int)sets[set_dim].size() <= set_id) 
@@ -429,6 +464,18 @@
                                      &sets[set_dim][set_id], 1,
                                      &set_dim);
       if (MB_SUCCESS != result) return result;
+      
+      result = mdbImpl->add_entities( mCurrentMeshHandle,
+                                      &sets[set_dim][set_id],
+                                      1 );
+      if (MB_SUCCESS != result) return result;
+      
+      if (file_id_tag) {
+        result = mdbImpl->tag_set_data(*file_id_tag,
+                                     &sets[set_dim][set_id], 1,
+                                     &setId);
+        ++setId;
+      }
     }
   }
 
@@ -472,3 +519,24 @@
     */
 }
 
+MBErrorCode ReadSms::add_entities( MBEntityHandle start,
+                                   MBEntityHandle count,
+                                   const MBTag* file_id_tag )
+{
+  if (!count)
+    return MB_FAILURE;
+  MBRange range;
+  range.insert( start, start + count - 1 );
+  
+  MBErrorCode rval = mdbImpl->add_entities( mCurrentMeshHandle, range );
+  if (MB_SUCCESS != rval)
+    return rval;
+  
+  if (file_id_tag) {
+    rval = readMeshIface->assign_ids( *file_id_tag, range, 1 );
+    if (MB_SUCCESS != rval)
+      return rval;
+  }
+  
+  return MB_SUCCESS;
+}

Modified: MOAB/trunk/ReadSms.hpp
===================================================================
--- MOAB/trunk/ReadSms.hpp	2009-07-15 22:42:45 UTC (rev 3014)
+++ MOAB/trunk/ReadSms.hpp	2009-07-15 23:00:20 UTC (rev 3015)
@@ -22,7 +22,8 @@
                         const FileOptions& opts,
                         const char* set_tag_name,
                         const int* set_tag_values,
-                        int num_set_tag_values );
+                        int num_set_tag_values,
+                        const MBTag* file_id_tag = 0 );
   
     //! Constructor
   ReadSms(MBInterface* impl = NULL);
@@ -32,12 +33,17 @@
 
 private:
 
-  MBErrorCode load_file_impl( FILE* file );
+  MBErrorCode add_entities( MBEntityHandle start, 
+                            MBEntityHandle count,
+                            const MBTag* file_id_tag );
+
+  MBErrorCode load_file_impl( FILE* file, const MBTag* file_id_tag );
   
   MBErrorCode get_set(std::vector<MBEntityHandle> *sets,
                       int set_type, int set_id,
                       MBTag set_tag,
-                      MBEntityHandle &this_set);
+                      MBEntityHandle &this_set,
+                      const MBTag* file_id_tag );
 
   MBErrorCode read_parallel_info(FILE *file_ptr);
 
@@ -50,6 +56,8 @@
   MBEntityHandle mCurrentMeshHandle;
   
   MBTag globalId, paramCoords, geomDimension;
+  
+  int setId;
 };
 
 

Modified: MOAB/trunk/ReadTetGen.cpp
===================================================================
--- MOAB/trunk/ReadTetGen.cpp	2009-07-15 22:42:45 UTC (rev 3014)
+++ MOAB/trunk/ReadTetGen.cpp	2009-07-15 23:00:20 UTC (rev 3015)
@@ -65,7 +65,8 @@
                                    MBEntityHandle& file_set,
                                    const FileOptions& opts,
                                    const char* name,
-                                   const int*, const int )
+                                   const int*, const int,
+                                   const MBTag* file_id_tag )
 {
   std::ifstream node_file, ele_file, face_file, edge_file;
   MBErrorCode rval;
@@ -143,6 +144,14 @@
     rval = mbIface->add_entities( file_set, tris );
   if (MB_SUCCESS == rval)
     rval = mbIface->add_entities( file_set, edges );
+  if (file_id_tag && MB_SUCCESS == rval)
+    rval = readTool->assign_ids( *file_id_tag, &nodes[0], nodes.size() );
+  if (file_id_tag && MB_SUCCESS == rval)
+    rval = readTool->assign_ids( *file_id_tag, edges );
+  if (file_id_tag && MB_SUCCESS == rval)
+    rval = readTool->assign_ids( *file_id_tag, tris );
+  if (file_id_tag && MB_SUCCESS == rval)
+    rval = readTool->assign_ids( *file_id_tag, tets );
   
   if (MB_SUCCESS != rval) {
     if (file_set) 

Modified: MOAB/trunk/ReadTetGen.hpp
===================================================================
--- MOAB/trunk/ReadTetGen.hpp	2009-07-15 22:42:45 UTC (rev 3014)
+++ MOAB/trunk/ReadTetGen.hpp	2009-07-15 23:00:20 UTC (rev 3015)
@@ -41,7 +41,8 @@
                         const FileOptions&,
                         const char* set_tag_name,
                         const int* set_tag_values,
-                        int num_set_tag_values );
+                        int num_set_tag_values,
+                        const MBTag* file_id_tag );
   
     //! Constructor
   ReadTetGen(MBInterface* impl = NULL);

Modified: MOAB/trunk/ReadVtk.cpp
===================================================================
--- MOAB/trunk/ReadVtk.cpp	2009-07-15 22:42:45 UTC (rev 3014)
+++ MOAB/trunk/ReadVtk.cpp	2009-07-15 23:00:20 UTC (rev 3015)
@@ -174,7 +174,8 @@
                                MBEntityHandle& file_set,
                                const FileOptions& opts,
                                const char* name,
-                               const int*, const int) 
+                               const int*, const int,
+                               const MBTag* file_id_tag) 
 {
   MBErrorCode result;
   file_set = 0;
@@ -257,6 +258,12 @@
   if (MB_SUCCESS != result) 
     return result;
   
+  if (file_id_tag) {
+    result = store_file_ids( *file_id_tag, vertices, element_list );
+    if (MB_SUCCESS != result)
+      return result;
+  }
+  
     // Count the number of elements read
   long elem_count = 0;
   for (std::vector<MBRange>::iterator it = element_list.begin(); it != element_list.end(); ++it )
@@ -1281,4 +1288,23 @@
   return MB_SUCCESS;
 }
 
+MBErrorCode ReadVtk::store_file_ids( MBTag tag, const MBRange& verts,
+                                     const std::vector<MBRange>& elems )
+{
+  MBErrorCode rval;
+  
+  rval = readMeshIface->assign_ids( tag, verts );
+  if (MB_SUCCESS != rval)
+    return rval;
 
+  int id = 0;
+  for (size_t i = 0; i < elems.size(); ++i) {
+    rval = readMeshIface->assign_ids( tag, elems[i], id );
+    id += elems[i].size();
+  }
+  
+  return MB_SUCCESS;
+}
+
+    
+    

Modified: MOAB/trunk/ReadVtk.hpp
===================================================================
--- MOAB/trunk/ReadVtk.hpp	2009-07-15 22:42:45 UTC (rev 3014)
+++ MOAB/trunk/ReadVtk.hpp	2009-07-15 23:00:20 UTC (rev 3015)
@@ -37,7 +37,8 @@
                         const FileOptions&,
                         const char* set_tag_name,
                         const int* set_tag_values,
-                        int num_set_tag_values );
+                        int num_set_tag_values,
+                        const MBTag* file_id_tag );
   
     //! Constructor
   ReadVtk(MBInterface* impl = NULL);
@@ -131,6 +132,10 @@
                                      std::vector<MBRange>& entities,
                                      const char* name);
 
+  MBErrorCode store_file_ids( MBTag tag,
+                              const MBRange& vertices,
+                              const std::vector<MBRange>& elements );
+
 private:
 
   MBReadUtilIface* readMeshIface;

Modified: MOAB/trunk/Tqdcfr.cpp
===================================================================
--- MOAB/trunk/Tqdcfr.cpp	2009-07-15 22:42:45 UTC (rev 3014)
+++ MOAB/trunk/Tqdcfr.cpp	2009-07-15 23:00:20 UTC (rev 3015)
@@ -195,7 +195,8 @@
                               MBEntityHandle& file_set,
                               const FileOptions& opts,
                               const char* block_tag_name,
-                              const int*, const int) 
+                              const int*, const int,
+                              const MBTag* file_id_tag) 
 {
   MBErrorCode result;
   file_set = mFileSet = 0;
@@ -386,6 +387,9 @@
 
   after_ents = subtract( after_ents, beforeEnts);
   result = mdbImpl->add_entities(mFileSet, after_ents);
+  
+  if (file_id_tag)
+    readUtilIface->assign_ids( *file_id_tag, after_ents );
 
   return result;
 }

Modified: MOAB/trunk/Tqdcfr.hpp
===================================================================
--- MOAB/trunk/Tqdcfr.hpp	2009-07-15 22:42:45 UTC (rev 3014)
+++ MOAB/trunk/Tqdcfr.hpp	2009-07-15 23:00:20 UTC (rev 3015)
@@ -297,7 +297,8 @@
                         const FileOptions& opts,
                         const char* block_tag_name,
                         const int* block_list,
-                        int num_blocks );
+                        int num_blocks,
+                        const MBTag* file_id_tag = 0 );
   MBErrorCode read_nodeset(ModelEntry *model,
                     NodesetHeader *nodeseth);
   MBErrorCode read_sideset(const double data_version,



More information about the moab-dev mailing list