[MOAB-dev] r3018 - in MOAB/trunk: . test/h5file

kraftche at mcs.anl.gov kraftche at mcs.anl.gov
Thu Jul 16 15:45:50 CDT 2009


Author: kraftche
Date: 2009-07-16 15:45:50 -0500 (Thu, 16 Jul 2009)
New Revision: 3018

Modified:
   MOAB/trunk/MBCore.cpp
   MOAB/trunk/MBReaderIface.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
   MOAB/trunk/exodus_test.cc
   MOAB/trunk/test/h5file/h5partial.cpp
Log:
o Allow multiple tags to be used to designate the subset of the file
  to read.

o Add a new function to MBReaderIface that reads only the values of 
  a tag from the file.
  
o Update all readers for above changes (most return MB_NOT_IMPLEMENTED
  for this functionality.)

o Implement read of only tag data for HDF5 and Exodus file formats,
  and add simple tests.



Modified: MOAB/trunk/MBCore.cpp
===================================================================
--- MOAB/trunk/MBCore.cpp	2009-07-16 17:56:10 UTC (rev 3017)
+++ MOAB/trunk/MBCore.cpp	2009-07-16 20:45:50 UTC (rev 3018)
@@ -424,12 +424,23 @@
   MBErrorCode rval;
   const MBReaderWriterSet* set = reader_writer_set();
 
+  MBReaderIface::IDTag subset = { set_tag_name, set_tag_values, num_set_tag_values };
+  MBReaderIface::IDTag* subsets;
+  int num_sets;    
+  if (set_tag_name && num_set_tag_values) {
+    num_sets = 1;
+    subsets = ⊂
+  }
+  else {
+    num_sets = 0;
+    subsets = 0;
+  }
+
     // otherwise try using the file extension to select a reader
   MBReaderIface* reader = set->get_file_extension_reader( file_name );
   if (reader)
-  { 
-    rval = reader->load_file( file_name, file_set, opts, set_tag_name, 
-                              set_tag_values, num_set_tag_values );
+  {
+    rval = reader->load_file( file_name, file_set, opts, subsets, num_sets );
     delete reader;
   }
   else
@@ -441,8 +452,7 @@
       MBReaderIface* reader = iter->make_reader( this );
       if (NULL != reader)
       {
-        rval = reader->load_file( file_name, file_set, opts, set_tag_name,
-                                  set_tag_values, num_set_tag_values );
+        rval = reader->load_file( file_name, file_set, opts, subsets, num_sets );
         delete reader;
         if (MB_SUCCESS == rval)
           break;

Modified: MOAB/trunk/MBReaderIface.hpp
===================================================================
--- MOAB/trunk/MBReaderIface.hpp	2009-07-16 17:56:10 UTC (rev 3017)
+++ MOAB/trunk/MBReaderIface.hpp	2009-07-16 20:45:50 UTC (rev 3018)
@@ -34,6 +34,13 @@
   
     virtual ~MBReaderIface() {}
     
+      /** Struct used to specify subset of file to read */
+    struct IDTag {
+      const char* tag_name;  //!< Name of tag containing integer IDs
+      const int* tag_values; //!< Array of integer ID values
+      int num_tag_values;    //!< Length of tag_values array
+    };
+    
     /**
      *\brief Load mesh from a file.
      *
@@ -41,13 +48,11 @@
      *
      *\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 subset_list    An array of tag name and value sets specifying
+     *                      the subset of the file to read.  If multiple
+     *                      tags are specified, the sets that match all
+     *                      tags (intersection) should be read.
+     *\param subset_list_length The length of the 'subset_list' 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
@@ -55,11 +60,32 @@
     virtual MBErrorCode load_file( const char* file_name,
                                    MBEntityHandle& file_set,
                                    const FileOptions& opts,
-                                   const char* set_tag_name = 0,
-                                   const int* set_tag_values = 0,
-                                   int num_set_tag_values = 0,
+                                   const IDTag* subset_list = 0,
+                                   int subset_list_length = 0,
                                    const MBTag* file_id_tag = 0 ) = 0;
 
+
+    /**
+     *\brief Read tag values from a file.
+     *
+     * Read the list if all integer tag values from the file for
+     * a tag that is a single integer value per entity.
+     *
+     *\param file_name      The file to read.
+     *\param tag_name       The tag for which to read values
+     *\param tag_values_out Output: The list of tag values.
+     *\param subset_list    An array of tag name and value sets specifying
+     *                      the subset of the file to read.  If multiple
+     *                      tags are specified, the sets that match all
+     *                      tags (intersection) should be read.
+     *\param subset_list_length The length of the 'subset_list' array.
+     */
+    virtual MBErrorCode read_tag_values( const char* file_name,
+                                         const char* tag_name,
+                                         const FileOptions& opts,
+                                         std::vector<int>& tag_values_out,
+                                         const IDTag* subset_list = 0,
+                                         int subset_list_length = 0 ) = 0;
 };
 
 #endif

Modified: MOAB/trunk/ReadCGM.cpp
===================================================================
--- MOAB/trunk/ReadCGM.cpp	2009-07-16 17:56:10 UTC (rev 3017)
+++ MOAB/trunk/ReadCGM.cpp	2009-07-16 20:45:50 UTC (rev 3018)
@@ -94,19 +94,32 @@
   delete myGeomTool;
 }
 
+
+MBErrorCode ReadCGM::read_tag_values( const char* /* file_name */,
+                                      const char* /* tag_name */,
+                                      const FileOptions& /* opts */,
+                                      std::vector<int>& /* tag_values_out */,
+                                      const IDTag* /* subset_list */,
+                                      int /* subset_list_length */ )
+{
+  return MB_NOT_IMPLEMENTED;
+}
+
+
+
 // copy geometry into mesh database
 MBErrorCode ReadCGM::load_file(const char *cgm_file_name,
                       MBEntityHandle& file_set,
                       const FileOptions& opts,
-                      const char* name_subset,
-                      const int*, const int,
+                      const MBReaderIface::IDTag* subset_list,
+                      int subset_list_length,
                       const MBTag* file_id_tag)
 {
   // blocks_to_load and num_blocks are ignored.
   MBErrorCode rval;
   file_set = 0;
 
-  if (name_subset) {
+  if (subset_list && subset_list_length) {
     readUtilIface->report_error( "Reading subset of files not supported for CGM data." );
     return MB_UNSUPPORTED_OPERATION;
   }

Modified: MOAB/trunk/ReadCGM.hpp
===================================================================
--- MOAB/trunk/ReadCGM.hpp	2009-07-16 17:56:10 UTC (rev 3017)
+++ MOAB/trunk/ReadCGM.hpp	2009-07-16 20:45:50 UTC (rev 3018)
@@ -55,14 +55,20 @@
     //  * FACET_DISTANCE_TOLERANCE=<real> (default: 0.001)
     //  * MAX_FACET_EDGE_LENGTH=<real> (default: 0.0)
     //  * CGM_ATTRIBS=<yes|no>         (default: no)
-  MBErrorCode load_file(const char *cgm_file_name,
+  MBErrorCode load_file( const char *cgm_file_name,
                          MBEntityHandle& file_set,
                          const FileOptions& opts,
-                         const char* set_tag_name,
-                         const int* set_tag_values,
-                         int num_set_tag_values,
-                         const MBTag* file_id_tag );
+                         const MBReaderIface::IDTag* subset_list = 0,
+                         int subset_list_length = 0,
+                         const MBTag* file_id_tag = 0 );
 
+  MBErrorCode read_tag_values( const char* file_name,
+                               const char* tag_name,
+                               const FileOptions& opts,
+                               std::vector<int>& tag_values_out,
+                               const IDTag* subset_list = 0,
+                               int subset_list_length = 0 );
+
    //! Constructor
    ReadCGM(MBInterface* impl = NULL);
 

Modified: MOAB/trunk/ReadGmsh.cpp
===================================================================
--- MOAB/trunk/ReadGmsh.cpp	2009-07-16 17:56:10 UTC (rev 3017)
+++ MOAB/trunk/ReadGmsh.cpp	2009-07-16 20:45:50 UTC (rev 3018)
@@ -80,17 +80,33 @@
 const int max_type_int = sizeof(typemap) / sizeof(typemap[0]) - 1;
 
 
+MBErrorCode ReadGmsh::read_tag_values( const char* /* file_name */,
+                                       const char* /* tag_name */,
+                                       const FileOptions& /* opts */,
+                                       std::vector<int>& /* tag_values_out */,
+                                       const IDTag* /* subset_list */,
+                                       int /* subset_list_length */ )
+{
+  return MB_NOT_IMPLEMENTED;
+}
+
+
 MBErrorCode ReadGmsh::load_file( const char* filename, 
                                  MBEntityHandle& file_set,
                                  const FileOptions& ,
-                                 const char* set_tag_name,
-                                 const int* blocks, 
-                                 const int num_blocks,
+                                 const MBReaderIface::IDTag* subset_list,
+                                 int subset_list_length,
                                  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." );
-    return MB_UNSUPPORTED_OPERATION;
+  int num_blocks = 0;
+  const int* blocks = 0;
+  if (subset_list && subset_list_length) {
+    if (subset_list_length > 1 && !strcmp( subset_list[0].tag_name, MATERIAL_SET_TAG_NAME) ) {
+      readMeshIface->report_error( "GMsh supports subset read only by material ID." );
+      return MB_UNSUPPORTED_OPERATION;
+    }
+    blocks = subset_list[0].tag_values;
+    num_blocks = subset_list[0].num_tag_values;
   }
 
   mCurrentMeshHandle = 0;

Modified: MOAB/trunk/ReadGmsh.hpp
===================================================================
--- MOAB/trunk/ReadGmsh.hpp	2009-07-16 17:56:10 UTC (rev 3017)
+++ MOAB/trunk/ReadGmsh.hpp	2009-07-16 20:45:50 UTC (rev 3018)
@@ -38,13 +38,19 @@
     //! factory method 
   static MBReaderIface* factory( MBInterface* );
 
-  MBErrorCode load_file(const char *file_name,
-                        MBEntityHandle& file_set,
-                        const FileOptions& opts,
-                        const char* set_tag_name,
-                        const int* set_tag_values,
-                        int num_set_tag_values,
-                        const MBTag* file_id_tag );
+  MBErrorCode load_file( const char *file_name,
+                         MBEntityHandle& file_set,
+                         const FileOptions& opts,
+                         const MBReaderIface::IDTag* subset_list = 0,
+                         int subset_list_length = 0,
+                         const MBTag* file_id_tag = 0 );
+
+  MBErrorCode read_tag_values( const char* file_name,
+                               const char* tag_name,
+                               const FileOptions& opts,
+                               std::vector<int>& tag_values_out,
+                               const IDTag* subset_list = 0,
+                               int subset_list_length = 0 );
   
     //! Constructor
   ReadGmsh(MBInterface* impl = NULL);

Modified: MOAB/trunk/ReadHDF5.cpp
===================================================================
--- MOAB/trunk/ReadHDF5.cpp	2009-07-16 17:56:10 UTC (rev 3017)
+++ MOAB/trunk/ReadHDF5.cpp	2009-07-16 20:45:50 UTC (rev 3018)
@@ -142,13 +142,8 @@
   H5Tclose( handleType );
 }
 
-MBErrorCode ReadHDF5::load_file( const char* filename, 
-                                 MBEntityHandle& file_set, 
-                                 const FileOptions& opts,
-                                 const char* name,
-                                 const int* id_list, 
-                                 const int num_ids,
-                                 const MBTag* file_id_tag )
+MBErrorCode ReadHDF5::set_up_read( const char* filename,
+                                   const FileOptions& opts )
 {
   MBErrorCode rval;
   mhdf_Status status;
@@ -183,12 +178,6 @@
   dataBuffer = (char*)malloc( bufferSize );
   if (!dataBuffer)
     return error(MB_MEMORY_ALLOCATION_FAILED);
-
-  rval = iFace->create_meshset( MESHSET_SET, file_set );
-  if (MB_SUCCESS != rval) {
-    free(dataBuffer);
-    return error(rval);
-  }
   
   hid_t file_prop = H5P_DEFAULT;
   if (use_mpio || native_parallel) {
@@ -214,10 +203,9 @@
     readUtil->report_error( mhdf_message( &status ));
     free( dataBuffer );
     if (indepIO != H5P_DEFAULT)
-      H5Pclose( indepIO );
+      H5Pclose( indepIO ); 
     if (collIO != indepIO)
       H5Pclose( collIO );
-    iFace->delete_entities( &file_set, 1 );
     return error(MB_FAILURE);
   }
 
@@ -230,30 +218,62 @@
     if (collIO != indepIO)
       H5Pclose( collIO );
     mhdf_closeFile( filePtr, &status );
-    iFace->delete_entities( &file_set, 1 );
     return error(MB_FAILURE);
   }
- 
-  if (name) 
-    rval = load_file_partial( file_set, name, id_list, num_ids, opts );
-  else
-    rval = load_file_impl( file_set, opts );
-  mhdf_closeFile( filePtr, &status );
-  filePtr = 0;
+  
+  return MB_SUCCESS;
+}
+
+MBErrorCode ReadHDF5::clean_up_read( const FileOptions& )
+{
+  free( dataBuffer );
+  free( fileInfo );
+
   if (indepIO != H5P_DEFAULT)
     H5Pclose( indepIO );
   if (collIO != indepIO)
     H5Pclose( collIO );
-  if (MB_SUCCESS == rval && is_error(status))
-    rval = MB_FAILURE;
 
-  if (file_set && MB_SUCCESS == rval) {
+  mhdf_Status status;
+  mhdf_closeFile( filePtr, &status );
+  filePtr = 0;
+  return is_error(status) ? MB_FAILURE : MB_SUCCESS;
+    return MB_FAILURE;
+}
+
+MBErrorCode ReadHDF5::load_file( const char* filename, 
+                                 MBEntityHandle& file_set, 
+                                 const FileOptions& opts,
+                                 const MBReaderIface::IDTag* subset_list,
+                                 int subset_list_length,
+                                 const MBTag* file_id_tag )
+{
+  MBErrorCode rval;
+ 
+  rval = set_up_read( filename, opts );
+  if (MB_SUCCESS != rval)
+    return rval;
+ 
+  if (subset_list && subset_list_length) 
+    rval = load_file_partial( file_set, subset_list, subset_list_length, opts );
+  else
+    rval = load_file_impl( file_set, opts );
+    
+  MBErrorCode rval2 = clean_up_read( opts );
+  if (rval == MB_SUCCESS && rval2 != MB_SUCCESS)
+    rval = rval2;
+  
+  if (MB_SUCCESS == rval) {
     DEBUGOUT("Creating entity set for file contents\n")
-    MBRange range;
-    MBRange::iterator hint = range.begin();
-    for (IDMap::iterator j = idMap.begin(); j != idMap.end(); ++j)
-      hint = range.insert( hint, j->value, j->value + j->count - 1);
-    rval = iFace->add_entities( file_set, range );
+
+    rval = iFace->create_meshset( MESHSET_SET, file_set );
+    if (MB_SUCCESS == rval) {
+      MBRange range;
+      MBRange::iterator hint = range.begin();
+      for (IDMap::iterator j = idMap.begin(); j != idMap.end(); ++j)
+        hint = range.insert( hint, j->value, j->value + j->count - 1);
+      rval = iFace->add_entities( file_set, range );
+    }
   }
         
       // delete everything that was read in if read failed part-way through
@@ -268,14 +288,13 @@
     rval = store_file_ids( *file_id_tag );
   }
   
-  free( dataBuffer );
-  free( fileInfo );
   return rval;
 }
   
 
 
-MBErrorCode ReadHDF5::load_file_impl( MBEntityHandle file_set, const FileOptions& opts )
+MBErrorCode ReadHDF5::load_file_impl( MBEntityHandle file_set, 
+                                      const FileOptions& opts )
 {
   MBErrorCode rval;
   mhdf_Status status;
@@ -360,39 +379,69 @@
   return rval;
 }
 
-MBErrorCode ReadHDF5::load_file_partial( MBEntityHandle file_set, 
-                                         const char* name,
-                                         const int* id_list,
-                                         int num_ids,
-                                         const FileOptions& opts )
+MBErrorCode ReadHDF5::find_int_tag( const char* name, int& index )
 {
-  mhdf_Status status;
-  
-DEBUGOUT( "RETREIVING TAGGED ENTITIES" );
-    
-  int tag_index;
-  for (tag_index = 0; tag_index < fileInfo->num_tag_desc; ++tag_index) 
-    if (!strcmp( name, fileInfo->tags[tag_index].name))
+  for (index = 0; index < fileInfo->num_tag_desc; ++index) 
+    if (!strcmp( name, fileInfo->tags[index].name))
       break;
-  if (tag_index == fileInfo->num_tag_desc) {
+
+  if (index == fileInfo->num_tag_desc) {
     readUtil->report_error( "File does not contain subset tag '%s'", name );
     return error(MB_TAG_NOT_FOUND);
   }
-  if (fileInfo->tags[tag_index].type != mhdf_INTEGER ||
-      fileInfo->tags[tag_index].size != 1) {
+
+  if (fileInfo->tags[index].type != mhdf_INTEGER ||
+      fileInfo->tags[index].size != 1) {
     readUtil->report_error( "Tag '%s' does not containa single integer value", name );
     return error(MB_TYPE_OUT_OF_RANGE);
   }
   
+  return MB_SUCCESS;
+}
+
+MBErrorCode ReadHDF5::get_subset_ids( const MBReaderIface::IDTag* subset_list,
+                                      int subset_list_length,
+                                      MBRange& file_ids )
+{
+  MBErrorCode rval;
+  
+  for (int i = 0; i < subset_list_length; ++i) {  
     
-  MBErrorCode rval;
+    int tag_index;
+    rval = find_int_tag( subset_list[i].tag_name, tag_index );
+    if (MB_SUCCESS != rval)
+      return error(rval);
+  
+    MBRange tmp_file_ids;
+    std::vector<int> ids( subset_list[i].tag_values, 
+                          subset_list[i].tag_values + subset_list[i].num_tag_values );
+    std::sort( ids.begin(), ids.end() );
+    rval = search_tag_values( tag_index, ids, tmp_file_ids );
+    if (MB_SUCCESS != rval)
+      return error(rval);
+    
+    if (i == 0) 
+      file_ids.swap( tmp_file_ids );
+    else 
+      file_ids = intersect( tmp_file_ids, file_ids );
+  }
+  
+  return MB_SUCCESS;
+}
+
+MBErrorCode ReadHDF5::load_file_partial( MBEntityHandle file_set, 
+                                         const MBReaderIface::IDTag* subset_list,
+                                         int subset_list_length,
+                                         const FileOptions& opts )
+{
+  mhdf_Status status;
+  
+DEBUGOUT( "RETREIVING TAGGED ENTITIES" );
+    
   MBRange file_ids;
-  std::vector<int> ids( id_list, id_list+num_ids );
-  std::sort( ids.begin(), ids.end() );
-  rval = search_tag_values( tag_index, ids, file_ids );
-  if (MB_SUCCESS != rval) {
+  MBErrorCode rval = get_subset_ids( subset_list, subset_list_length, file_ids );
+  if (MB_SUCCESS != rval)
     return error(rval);
-  }
   
 DEBUGOUT( "GATHERING ADDITIONAL ENTITIES" );
   
@@ -3196,4 +3245,285 @@
   return MB_SUCCESS;
 }
 
+MBErrorCode ReadHDF5::read_tag_values( const char* file_name,
+                                       const char* tag_name,
+                                       const FileOptions& opts,
+                                       std::vector<int>& tag_values_out,
+                                       const IDTag* subset_list,
+                                       int subset_list_length )
+{
+  MBErrorCode rval;
+  
+  rval = set_up_read( file_name, opts );
+  if (MB_SUCCESS != rval)
+    return error(rval);
+  
+  int tag_index;
+  rval = find_int_tag( tag_name, tag_index );
+  if (MB_SUCCESS != rval) {
+    clean_up_read( opts );
+    return error(rval);
+  }
+  
+  if (subset_list && subset_list_length) {
+    MBRange file_ids;
+    rval = get_subset_ids( subset_list, subset_list_length, file_ids );
+    if (MB_SUCCESS != rval) {
+      clean_up_read( opts );
+      return error(rval);
+    }
     
+    rval = read_tag_values_partial( tag_index, file_ids, tag_values_out );
+    if (MB_SUCCESS != rval) {
+      clean_up_read( opts );
+      return error(rval);
+    }
+  }
+  else {
+    rval = read_tag_values_all( tag_index, tag_values_out );
+    if (MB_SUCCESS != rval) {
+      clean_up_read( opts );
+      return error(rval);
+    }
+  }
+    
+  return clean_up_read( opts );
+}
+
+MBErrorCode ReadHDF5::read_tag_values_partial( int tag_index,
+                                               const MBRange& file_ids,
+                                               std::vector<int>& tag_values )
+{
+  mhdf_Status status;
+  const mhdf_TagDesc& tag = fileInfo->tags[tag_index];
+  long num_ent, num_val;
+  
+    // read sparse values
+  if (tag.have_sparse) {
+    hid_t handles[3];
+    mhdf_openSparseTagData( filePtr, tag.name, &num_ent, &num_val, handles, &status );
+    if (mhdf_isError( &status )) {
+      readUtil->report_error( "%s", mhdf_message( &status ) );
+      return error(MB_FAILURE);
+    }
+    
+      // read all entity handles and fill 'offsets' with ranges of
+      // offsets into the data table for entities that we want.
+    MBRange offsets;
+    long* buffer = reinterpret_cast<long*>(dataBuffer);
+    const long buffer_size = bufferSize/sizeof(long);
+    long remaining = num_ent, offset = 0;
+    while (remaining) {
+      long count = std::min( remaining, buffer_size );
+      mhdf_readSparseTagEntitiesWithOpt( handles[0], offset, count, 
+                                         H5T_NATIVE_LONG, buffer, collIO, 
+                                         &status );
+      if (mhdf_isError( &status )) {
+        readUtil->report_error( "%s", mhdf_message( &status ) );
+        mhdf_closeData( filePtr, handles[1], &status );
+        mhdf_closeData( filePtr, handles[0], &status );
+        return error(MB_FAILURE);
+      }
+      
+      std::sort( buffer, buffer+count );
+      MBRange::iterator ins = offsets.begin();
+      MBRange::const_iterator i = file_ids.begin();
+      for (long j = 0; j < count; ++j) {
+        if (i == file_ids.end())
+          break;
+        while ((long)*i < buffer[j])
+          ++i;
+        if ((long)*i == buffer[j]) {
+          ins = offsets.insert( ins, j+offset, j+offset );
+        }
+      }
+      
+      remaining -= count;
+      offset += count;
+    }
+    
+    mhdf_closeData( filePtr, handles[0], &status );
+    if (mhdf_isError( &status )) {
+      readUtil->report_error( "%s", mhdf_message( &status ) );
+      mhdf_closeData( filePtr, handles[1], &status );
+      return error(MB_FAILURE);
+    }
+
+    tag_values.clear();
+    MBRange::const_pair_iterator p;
+    for (p = offsets.const_pair_begin(); p != offsets.const_pair_end(); ++p) {
+      long offset = p->first;
+      long count = p->second - p->first + 1;
+      size_t prev_size = tag_values.size();
+      tag_values.resize( prev_size + count );
+      mhdf_readSparseTagValuesWithOpt( handles[1], offset, count, H5T_NATIVE_INT,
+                                       &tag_values[prev_size], indepIO, &status );
+      if (mhdf_isError( &status )) {
+        readUtil->report_error( "%s", mhdf_message( &status ) );
+        mhdf_closeData( filePtr, handles[1], &status );
+        return error(MB_FAILURE);
+      }
+    }   
+    
+    mhdf_closeData( filePtr, handles[1], &status );
+    if (mhdf_isError( &status )) {
+      readUtil->report_error( "%s", mhdf_message( &status ) );
+      return error(MB_FAILURE);
+    }
+  }
+  
+  std::sort( tag_values.begin(), tag_values.end() );
+  tag_values.erase( std::unique(tag_values.begin(), tag_values.end()), tag_values.end() );
+  
+    // read dense values
+  std::vector<int> prev_data, curr_data;
+  for (int i = 0; i < tag.num_dense_indices; ++i) {
+    int grp = tag.dense_elem_indices[i];
+    const char* gname = 0;
+    mhdf_EntDesc* desc = 0;
+    if (grp == -1) {
+      gname = mhdf_node_type_handle();
+      desc = &fileInfo->nodes;
+    }
+    else if (grp == -2) {
+      gname = mhdf_set_type_handle();
+      desc = &fileInfo->sets;
+    }
+    else {
+      assert(grp >= 0 && grp < fileInfo->num_elem_desc);
+      gname = fileInfo->elems[grp].handle;
+      desc = &fileInfo->elems[grp].desc;
+    }
+    
+    MBRange::iterator s = file_ids.lower_bound( (MBEntityHandle)(desc->start_id) );
+    MBRange::iterator e = MBRange::lower_bound( s, file_ids.end(),  
+                                   (MBEntityHandle)(desc->start_id) + desc->count );
+    MBRange subset;
+    subset.merge( s, e );
+    
+    hid_t handle = mhdf_openDenseTagData( filePtr, tag.name, gname, &num_val, &status );
+    if (mhdf_isError( &status )) {
+      readUtil->report_error( "%s", mhdf_message( &status ) );
+      return error(MB_FAILURE);
+    }
+    
+    curr_data.clear();
+    MBRange::const_pair_iterator p;
+    for (p = subset.const_pair_begin(); p != subset.const_pair_end(); ++p) {
+      long offset = p->first - desc->start_id;
+      long count = p->second - p->first + 1;
+      size_t prev_size = curr_data.size();
+      curr_data.resize( prev_size + count );
+      mhdf_readDenseTagWithOpt( handle, offset, count, H5T_NATIVE_INT,
+                                &curr_data[prev_size], indepIO, &status );
+      if (mhdf_isError( &status )) {
+        readUtil->report_error( "%s", mhdf_message( &status ) );
+        mhdf_closeData( filePtr, handle, &status );
+        return error(MB_FAILURE);
+      }
+    }   
+    
+    mhdf_closeData( filePtr, handle, &status );
+    if (mhdf_isError( &status )) {
+      readUtil->report_error( "%s", mhdf_message( &status ) );
+      return error(MB_FAILURE);
+    }
+ 
+    std::sort( curr_data.begin(), curr_data.end() );
+    curr_data.erase( std::unique(curr_data.begin(), curr_data.end()), curr_data.end() );
+    
+    prev_data.clear();
+    tag_values.swap( prev_data );
+    std::set_union( prev_data.begin(), prev_data.end(),
+                    curr_data.begin(), curr_data.end(),
+                    std::back_inserter( tag_values ) );
+  }
+  
+  return MB_SUCCESS;
+}
+
+MBErrorCode ReadHDF5::read_tag_values_all( int tag_index,
+                                           std::vector<int>& tag_values )
+{
+  mhdf_Status status;
+  const mhdf_TagDesc& tag = fileInfo->tags[tag_index];
+  long junk, num_val;
+  
+    // read sparse values
+  if (tag.have_sparse) {
+    hid_t handles[3];
+    mhdf_openSparseTagData( filePtr, tag.name, &junk, &num_val, handles, &status );
+    if (mhdf_isError( &status )) {
+      readUtil->report_error( "%s", mhdf_message( &status ) );
+      return error(MB_FAILURE);
+    }
+    
+    mhdf_closeData( filePtr, handles[0], &status );
+    if (mhdf_isError( &status )) {
+      readUtil->report_error( "%s", mhdf_message( &status ) );
+      mhdf_closeData( filePtr, handles[1], &status );
+      return error(MB_FAILURE);
+    }
+    
+    tag_values.resize( num_val );
+    mhdf_readSparseTagValuesWithOpt( handles[1], 0, num_val, H5T_NATIVE_INT,
+                                     &tag_values[0], collIO, &status );
+    if (mhdf_isError( &status )) {
+      readUtil->report_error( "%s", mhdf_message( &status ) );
+      mhdf_closeData( filePtr, handles[1], &status );
+      return error(MB_FAILURE);
+    }
+    
+    mhdf_closeData( filePtr, handles[1], &status );
+    if (mhdf_isError( &status )) {
+      readUtil->report_error( "%s", mhdf_message( &status ) );
+      return error(MB_FAILURE);
+    }
+  }
+  
+  std::sort( tag_values.begin(), tag_values.end() );
+  tag_values.erase( std::unique(tag_values.begin(), tag_values.end()), tag_values.end() );
+  
+    // read dense values
+  std::vector<int> prev_data, curr_data;
+  for (int i = 0; i < tag.num_dense_indices; ++i) {
+    int grp = tag.dense_elem_indices[i];
+    const char* gname = 0;
+    if (grp == -1)
+      gname = mhdf_node_type_handle();
+    else if (grp == -2)
+      gname = mhdf_set_type_handle();
+    else
+      gname = fileInfo->elems[grp].handle;
+    hid_t handle = mhdf_openDenseTagData( filePtr, tag.name, gname, &num_val, &status );
+    if (mhdf_isError( &status )) {
+      readUtil->report_error( "%s", mhdf_message( &status ) );
+      return error(MB_FAILURE);
+    }
+    
+    curr_data.resize( num_val );
+    mhdf_readDenseTagWithOpt( handle, 0, num_val, H5T_NATIVE_INT, &curr_data[0], collIO, &status );
+    if (mhdf_isError( &status )) {
+      readUtil->report_error( "%s", mhdf_message( &status ) );
+      mhdf_closeData( filePtr, handle, &status );
+      return error(MB_FAILURE);
+    }
+    
+    mhdf_closeData( filePtr, handle, &status );
+    if (mhdf_isError( &status )) {
+      readUtil->report_error( "%s", mhdf_message( &status ) );
+      return error(MB_FAILURE);
+    }
+ 
+    std::sort( curr_data.begin(), curr_data.end() );
+    curr_data.erase( std::unique(curr_data.begin(), curr_data.end()), curr_data.end() );
+    
+    prev_data.clear();
+    tag_values.swap( prev_data );
+    std::set_union( prev_data.begin(), prev_data.end(),
+                    curr_data.begin(), curr_data.end(),
+                    std::back_inserter( tag_values ) );
+  }
+  
+  return MB_SUCCESS;
+}

Modified: MOAB/trunk/ReadHDF5.hpp
===================================================================
--- MOAB/trunk/ReadHDF5.hpp	2009-07-16 17:56:10 UTC (rev 3017)
+++ MOAB/trunk/ReadHDF5.hpp	2009-07-16 20:45:50 UTC (rev 3018)
@@ -50,21 +50,31 @@
   MBErrorCode load_file( const char* filename,
                          MBEntityHandle& file_set,
                          const FileOptions& opts,
-                         const char* set_tag_name,
-                         const int* set_tag_values,
-                         int num_set_tag_values,
-                         const MBTag* file_id_tag );
+                         const MBReaderIface::IDTag* subset_list = 0,
+                         int subset_list_length = 0,
+                         const MBTag* file_id_tag = 0 );
+
+  MBErrorCode read_tag_values( const char* file_name,
+                               const char* tag_name,
+                               const FileOptions& opts,
+                               std::vector<int>& tag_values_out,
+                               const IDTag* subset_list = 0,
+                               int subset_list_length = 0 );
+
 protected:
 
   MBErrorCode load_file_impl( MBEntityHandle file_set,
                               const FileOptions& opts );
 
   MBErrorCode load_file_partial( MBEntityHandle file_set, 
-                                 const char* set_tag_name,
-                                 const int* set_tag_values,
-                                 int num_set_tag_values,
+                                 const MBReaderIface::IDTag* subset_list,
+                                 int subset_list_length,
                                  const FileOptions& opts );
 
+  MBErrorCode read_tag_values_all( int tag_index, std::vector<int>& results );
+  MBErrorCode read_tag_values_partial( int tag_index, const MBRange& file_ids,
+                                       std::vector<int>& results );
+
 private:
   MBErrorCode init();
   
@@ -106,6 +116,16 @@
   //! when reading the entire file on all processors.
   hid_t indepIO, collIO;
   
+  MBErrorCode set_up_read( const char* file_name, const FileOptions& opts );
+  MBErrorCode clean_up_read( const FileOptions& opts );
+  
+  
+  //! Given a list of tags and values, get the file ids for the
+  //! corresponding entities in the file.
+  MBErrorCode get_subset_ids( const MBReaderIface::IDTag* subset_list,
+                              int subset_list_length,
+                              MBRange& file_ids_out );
+  
   MBErrorCode read_nodes( const MBRange& node_file_ids );
   
     // Read elements in fileInfo->elems[index]
@@ -389,6 +409,13 @@
      * into a tag value on the entity.
      */
   MBErrorCode store_file_ids( MBTag tag );
+  
+    /**\brief Find index in mhdf_FileDesc* fileInfo for specified tag name
+     *
+     * Given a tag name, find its index in fileInfo and verify that
+     * each tag value is a single integer.
+     */
+  MBErrorCode find_int_tag( const char* name, int& index_out );
 };
 
 #endif

Modified: MOAB/trunk/ReadIDEAS.cpp
===================================================================
--- MOAB/trunk/ReadIDEAS.cpp	2009-07-16 17:56:10 UTC (rev 3017)
+++ MOAB/trunk/ReadIDEAS.cpp	2009-07-16 20:45:50 UTC (rev 3018)
@@ -20,14 +20,26 @@
   impl->query_interface("MBReadUtilIface", reinterpret_cast<void**>(&readMeshIface));
 }
 
+
+MBErrorCode ReadIDEAS::read_tag_values( const char* /* file_name */,
+                                        const char* /* tag_name */,
+                                        const FileOptions& /* opts */,
+                                        std::vector<int>& /* tag_values_out */,
+                                        const IDTag* /* subset_list */,
+                                        int /* subset_list_length */ )
+{
+  return MB_NOT_IMPLEMENTED;
+}
+
+
 MBErrorCode ReadIDEAS::load_file(const char* fname, 
                                  MBEntityHandle& meshset, 
                                  const FileOptions& options,
-                                 const char* name,
-                                 const int*, const int,
+                                 const MBReaderIface::IDTag* subset_list,
+                                 int subset_list_length,
                                  const MBTag* file_id_tag ) {
 
-  if (name) {
+  if (subset_list && subset_list_length) {
     readMeshIface->report_error( "Reading subset of files not supported for IDEAS." );
     return MB_UNSUPPORTED_OPERATION;
   }

Modified: MOAB/trunk/ReadIDEAS.hpp
===================================================================
--- MOAB/trunk/ReadIDEAS.hpp	2009-07-16 17:56:10 UTC (rev 3017)
+++ MOAB/trunk/ReadIDEAS.hpp	2009-07-16 20:45:50 UTC (rev 3018)
@@ -20,13 +20,19 @@
 
   static MBReaderIface* factory( MBInterface* );
 
-  MBErrorCode load_file(const char* fname, 
-			MBEntityHandle& meshset, 
-			const FileOptions&,
-			const char* set_tag_name,
-                        const int* set_tag_values,
-                        int num_set_tag_values,
-                        const MBTag* file_id_tag );
+  MBErrorCode load_file( const char* fname, 
+			 MBEntityHandle& meshset, 
+			 const FileOptions&,
+                         const MBReaderIface::IDTag* subset_list = 0,
+                         int subset_list_length = 0,
+                         const MBTag* file_id_tag = 0 );
+
+  MBErrorCode read_tag_values( const char* file_name,
+                               const char* tag_name,
+                               const FileOptions& opts,
+                               std::vector<int>& tag_values_out,
+                               const IDTag* subset_list = 0,
+                               int subset_list_length = 0 );
   
   //! Constructor
   ReadIDEAS(MBInterface* impl = NULL);

Modified: MOAB/trunk/ReadMCNP5.cpp
===================================================================
--- MOAB/trunk/ReadMCNP5.cpp	2009-07-16 17:56:10 UTC (rev 3017)
+++ MOAB/trunk/ReadMCNP5.cpp	2009-07-16 20:45:50 UTC (rev 3018)
@@ -45,16 +45,27 @@
   }
 }
 
+
+MBErrorCode ReadMCNP5::read_tag_values( const char* /* file_name */,
+                                        const char* /* tag_name */,
+                                        const FileOptions& /* opts */,
+                                        std::vector<int>& /* tag_values_out */,
+                                        const IDTag* /* subset_list */,
+                                        int /* subset_list_length */ )
+{
+  return MB_NOT_IMPLEMENTED;
+}
+
+
 // load the file as called by the MBInterface function
 MBErrorCode ReadMCNP5::load_file(const char        *filename, 
                                  MBEntityHandle    &input_meshset, 
                                  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 MBReaderIface::IDTag* subset_list,
+                                 int               subset_list_length,
                                  const MBTag*      file_id_tag) {
   // at this time there is no support for reading a subset of the file
-  if (set_tag_name) {
+  if (subset_list && subset_list_length) {
     readMeshIface->report_error( "Reading subset of files not supported for meshtal." );
     return MB_UNSUPPORTED_OPERATION;
   }

Modified: MOAB/trunk/ReadMCNP5.hpp
===================================================================
--- MOAB/trunk/ReadMCNP5.hpp	2009-07-16 17:56:10 UTC (rev 3017)
+++ MOAB/trunk/ReadMCNP5.hpp	2009-07-16 20:45:50 UTC (rev 3018)
@@ -14,14 +14,20 @@
   // factory method
   static MBReaderIface* factory( MBInterface* );
   
-  MBErrorCode load_file(const char*       fname,
-                        MBEntityHandle    &input_meshset,
-                        const FileOptions &options,
-                        const char*       set_tag_name, /* not used */
-                        const int*        material_set_list,
-                        const int         num_material_sets,
-                        const MBTag*      file_id_tag );
+  MBErrorCode load_file( const char*                 fname,
+                         MBEntityHandle              &input_meshset,
+                         const FileOptions           &options,
+                         const MBReaderIface::IDTag* subset_list = 0,
+                         int                         subset_list_length = 0,
+                         const MBTag*                file_id_tag = 0 );
 
+  MBErrorCode read_tag_values( const char*        file_name,
+                               const char*        tag_name,
+                               const FileOptions& opts,
+                               std::vector<int>&  tag_values_out,
+                               const IDTag*       subset_list = 0,
+                               int                subset_list_length = 0 );
+
   // constructor
   ReadMCNP5(MBInterface* impl = NULL);
 

Modified: MOAB/trunk/ReadNCDF.cpp
===================================================================
--- MOAB/trunk/ReadNCDF.cpp	2009-07-16 17:56:10 UTC (rev 3017)
+++ MOAB/trunk/ReadNCDF.cpp	2009-07-16 20:45:50 UTC (rev 3018)
@@ -428,22 +428,89 @@
 }
   
 
+MBErrorCode ReadNCDF::read_tag_values(const char* file_name,
+                                      const char* tag_name,
+                                      const FileOptions& opts,
+                                      std::vector<int>& id_array,
+                                      const IDTag* subset_list,
+                                      int subset_list_length )
+{
+  if (subset_list && subset_list_length) {
+    readMeshIface->report_error( "ExodusII reader supports subset read only by material ID." );
+    return MB_UNSUPPORTED_OPERATION;
+  }
 
+    // 1. Read the header
+  MBErrorCode rval = read_exodus_header( file_name );
+  if (MB_FAILURE == rval) 
+    return rval;
+  
+  int count = 0;
+  const char* prop;
+  const char* blocks   = "eb_prop1";
+  const char* nodesets = "ns_prop1";
+  const char* sidesets = "ss_prop1";
+  
+  if (!strcmp(tag_name, MATERIAL_SET_TAG_NAME)) {
+    count = numberElementBlocks_loading;
+    prop = blocks;
+  }
+  else if (!strcmp(tag_name, DIRICHLET_SET_TAG_NAME)) {
+    count = numberNodeSets_loading;
+    prop = nodesets;
+  }
+  else if (!strcmp(tag_name, NEUMANN_SET_TAG_NAME)) {
+    count = numberSideSets_loading;
+    prop = sidesets;
+  }
+  else {  
+    delete ncFile;
+    ncFile = 0;
+    return MB_TAG_NOT_FOUND;
+  }
+  
+  if (count) {
+    NcVar *nc_var = ncFile->get_var( prop );
+    if (NULL == nc_var || !nc_var->is_valid()) {
+      readMeshIface->report_error("Problem getting prop variable.");
+      rval = MB_FAILURE;
+    }
+    else {
+      id_array.resize( count );
+      NcBool status = nc_var->get(&id_array[0], count);
+      if (0 == status) {
+        readMeshIface->report_error("Problem getting element id vector.");
+        rval = MB_FAILURE;
+      }
+    }
+  }
+  
+  delete ncFile;
+  ncFile = 0;
+  return rval;
+}
+
+
+
 MBErrorCode ReadNCDF::load_file(const char *exodus_file_name,
                                 MBEntityHandle& file_set,
                                 const FileOptions& opts,
-                                const char* set_tag_name,
-                                const int *blocks_to_load,
-                                const int num_blocks,
+                                const MBReaderIface::IDTag* subset_list,
+                                int subset_list_length,
                                 const MBTag* file_id_tag)
 {
   MBErrorCode status;
 
-  if (blocks_to_load && !strcmp( set_tag_name, MATERIAL_SET_TAG_NAME )) {
-    readMeshIface->report_error( "Exodus reader supports subset read only by block ID." );
-    return MB_UNSUPPORTED_OPERATION;
+  int num_blocks = 0;
+  const int* blocks_to_load = 0;
+  if (subset_list && subset_list_length) {
+    if (subset_list_length > 1 && !strcmp( subset_list[0].tag_name, MATERIAL_SET_TAG_NAME) ) {
+      readMeshIface->report_error( "ExodusII reader supports subset read only by material ID." );
+      return MB_UNSUPPORTED_OPERATION;
+    }
+    blocks_to_load = subset_list[0].tag_values;
+    num_blocks = subset_list[0].num_tag_values;
   }
-
   
   file_set = 0;
     // this function directs the reading of an exoii file, but doesn't do any of
@@ -517,6 +584,8 @@
     // what about properties???
 
   file_set = mCurrentMeshHandle;
+  delete ncFile;
+  ncFile = 0;
   return MB_SUCCESS;
 }
 

Modified: MOAB/trunk/ReadNCDF.hpp
===================================================================
--- MOAB/trunk/ReadNCDF.hpp	2009-07-16 17:56:10 UTC (rev 3017)
+++ MOAB/trunk/ReadNCDF.hpp	2009-07-16 20:45:50 UTC (rev 3018)
@@ -69,13 +69,19 @@
                  const char* delimiters );
 
     //! load an ExoII file
-  MBErrorCode load_file(const char *exodus_file_name,
+  MBErrorCode load_file( const char *exodus_file_name,
                          MBEntityHandle& file_set,
                          const FileOptions& opts,
-                         const char* set_tag_name,
-                         const int* blocks_to_load,
-                         const int num_blocks,
-                         const MBTag* file_id_tag = 0);
+                         const MBReaderIface::IDTag* subset_list = 0,
+                         int subset_list_length = 0,
+                         const MBTag* file_id_tag = 0 );
+
+  MBErrorCode read_tag_values( const char* file_name,
+                               const char* tag_name,
+                               const FileOptions& opts,
+                               std::vector<int>& tag_values_out,
+                               const IDTag* subset_list = 0,
+                               int subset_list_length = 0 );
   
    //! Constructor
    ReadNCDF(MBInterface* impl = NULL);

Modified: MOAB/trunk/ReadSTL.cpp
===================================================================
--- MOAB/trunk/ReadSTL.cpp	2009-07-16 17:56:10 UTC (rev 3017)
+++ MOAB/trunk/ReadSTL.cpp	2009-07-16 20:45:50 UTC (rev 3018)
@@ -74,17 +74,29 @@
 }
 
 
+
+MBErrorCode ReadSTL::read_tag_values( const char* /* file_name */,
+                                      const char* /* tag_name */,
+                                      const FileOptions& /* opts */,
+                                      std::vector<int>& /* tag_values_out */,
+                                      const IDTag* /* subset_list */,
+                                      int /* subset_list_length */ )
+{
+  return MB_NOT_IMPLEMENTED;
+}
+
+
 MBErrorCode ReadSTL::load_file( const char* filename,
                                 MBEntityHandle& file_set, 
                                 const FileOptions& opts,
-                                const char* name,
-                                const int*, const int,
+                                const MBReaderIface::IDTag* subset_list,
+                                int subset_list_length,
                                 const MBTag* file_id_tag )
 {
   mCurrentMeshHandle = 0;
   const MBErrorCode result = load_file_impl( filename, opts, file_id_tag );
   
-  if (name) {
+  if (subset_list && subset_list_length) {
     readMeshIface->report_error( "Reading subset of files not supported for STL." );
     return MB_UNSUPPORTED_OPERATION;
   }

Modified: MOAB/trunk/ReadSTL.hpp
===================================================================
--- MOAB/trunk/ReadSTL.hpp	2009-07-16 17:56:10 UTC (rev 3017)
+++ MOAB/trunk/ReadSTL.hpp	2009-07-16 20:45:50 UTC (rev 3018)
@@ -71,13 +71,19 @@
 
     //! Generic file loading code for both binary and ASCII readers.
     //! Calls reader-specific read_triangles function to do actual I/O.
-  MBErrorCode load_file(const char *file_name,
-                        MBEntityHandle& file_set,
-                        const FileOptions& opts,
-                        const char* set_tag_name,
-                        const int* set_tag_values,
-                        int num_set_tag_values,
-                        const MBTag* file_id_tag );
+  MBErrorCode load_file( const char *file_name,
+                         MBEntityHandle& file_set,
+                         const FileOptions& opts,
+                         const MBReaderIface::IDTag* subset_list = 0,
+                         int subset_list_length = 0,
+                         const MBTag* file_id_tag = 0 );
+
+  MBErrorCode read_tag_values( const char* file_name,
+                               const char* tag_name,
+                               const FileOptions& opts,
+                               std::vector<int>& tag_values_out,
+                               const IDTag* subset_list = 0,
+                               int subset_list_length = 0 );
   
     //! Constructor
   ReadSTL(MBInterface* impl = NULL);

Modified: MOAB/trunk/ReadSms.cpp
===================================================================
--- MOAB/trunk/ReadSms.cpp	2009-07-16 17:56:10 UTC (rev 3017)
+++ MOAB/trunk/ReadSms.cpp	2009-07-16 20:45:50 UTC (rev 3018)
@@ -61,14 +61,25 @@
   }
 }
 
+MBErrorCode ReadSms::read_tag_values(const char* /* file_name */,
+                                     const char* /* tag_name */,
+                                     const FileOptions& /* opts */,
+                                     std::vector<int>& /* tag_values_out */,
+                                     const IDTag* /* subset_list */,
+                                     int /* subset_list_length */ )
+{
+  return MB_NOT_IMPLEMENTED;
+}
+
+
 MBErrorCode ReadSms::load_file( const char* filename, 
                                 MBEntityHandle& file_set,
                                 const FileOptions& ,
-                                const char* name,
-                                const int*, const int,
+                                const MBReaderIface::IDTag* subset_list,
+                                int subset_list_length,
                                 const MBTag* file_id_tag )
 {
-  if (name) {
+  if (subset_list && subset_list_length) {
     readMeshIface->report_error( "Reading subset of files not supported for Sms." );
     return MB_UNSUPPORTED_OPERATION;
   }

Modified: MOAB/trunk/ReadSms.hpp
===================================================================
--- MOAB/trunk/ReadSms.hpp	2009-07-16 17:56:10 UTC (rev 3017)
+++ MOAB/trunk/ReadSms.hpp	2009-07-16 20:45:50 UTC (rev 3018)
@@ -17,13 +17,19 @@
     //! factory method 
   static MBReaderIface* factory( MBInterface* );
 
-  MBErrorCode load_file(const char *file_name,
-                        MBEntityHandle& file_set,
-                        const FileOptions& opts,
-                        const char* set_tag_name,
-                        const int* set_tag_values,
-                        int num_set_tag_values,
-                        const MBTag* file_id_tag = 0 );
+  MBErrorCode load_file( const char *file_name,
+                         MBEntityHandle& file_set,
+                         const FileOptions& opts,
+                         const MBReaderIface::IDTag* subset_list = 0,
+                         int subset_list_length = 0,
+                         const MBTag* file_id_tag = 0 );
+
+  MBErrorCode read_tag_values( const char* file_name,
+                               const char* tag_name,
+                               const FileOptions& opts,
+                               std::vector<int>& tag_values_out,
+                               const IDTag* subset_list = 0,
+                               int subset_list_length = 0 );
   
     //! Constructor
   ReadSms(MBInterface* impl = NULL);

Modified: MOAB/trunk/ReadTetGen.cpp
===================================================================
--- MOAB/trunk/ReadTetGen.cpp	2009-07-16 17:56:10 UTC (rev 3017)
+++ MOAB/trunk/ReadTetGen.cpp	2009-07-16 20:45:50 UTC (rev 3018)
@@ -61,17 +61,29 @@
   return MB_SUCCESS;
 }
 
+
+MBErrorCode ReadTetGen::read_tag_values( const char* /* file_name */,
+                                         const char* /* tag_name */,
+                                         const FileOptions& /* opts */,
+                                         std::vector<int>& /* tag_values_out */,
+                                         const IDTag* /* subset_list */,
+                                         int /* subset_list_length */ )
+{
+  return MB_NOT_IMPLEMENTED;
+}
+
+
 MBErrorCode ReadTetGen::load_file( const char* file_name_c,
                                    MBEntityHandle& file_set,
                                    const FileOptions& opts,
-                                   const char* name,
-                                   const int*, const int,
+                                   const MBReaderIface::IDTag* subset_list,
+                                   int subset_list_length,
                                    const MBTag* file_id_tag )
 {
   std::ifstream node_file, ele_file, face_file, edge_file;
   MBErrorCode rval;
   
-  if (name) {
+  if (subset_list && subset_list_length) {
     readTool->report_error( "Reading subset of files not supported for TetGen." );
     return MB_UNSUPPORTED_OPERATION;
   }

Modified: MOAB/trunk/ReadTetGen.hpp
===================================================================
--- MOAB/trunk/ReadTetGen.hpp	2009-07-16 17:56:10 UTC (rev 3017)
+++ MOAB/trunk/ReadTetGen.hpp	2009-07-16 20:45:50 UTC (rev 3018)
@@ -36,13 +36,19 @@
   static MBReaderIface* factory( MBInterface* );
 
     //! load a file
-  MBErrorCode load_file(const char *file_name,
-                        MBEntityHandle& file_set,
-                        const FileOptions&,
-                        const char* set_tag_name,
-                        const int* set_tag_values,
-                        int num_set_tag_values,
-                        const MBTag* file_id_tag );
+  MBErrorCode load_file( const char *file_name,
+                         MBEntityHandle& file_set,
+                         const FileOptions&,
+                         const MBReaderIface::IDTag* subset_list = 0,
+                         int subset_list_length = 0,
+                         const MBTag* file_id_tag = 0 );
+
+  MBErrorCode read_tag_values( const char* file_name,
+                               const char* tag_name,
+                               const FileOptions& opts,
+                               std::vector<int>& tag_values_out,
+                               const IDTag* subset_list = 0,
+                               int subset_list_length = 0 );
   
     //! Constructor
   ReadTetGen(MBInterface* impl = NULL);

Modified: MOAB/trunk/ReadVtk.cpp
===================================================================
--- MOAB/trunk/ReadVtk.cpp	2009-07-16 17:56:10 UTC (rev 3017)
+++ MOAB/trunk/ReadVtk.cpp	2009-07-16 20:45:50 UTC (rev 3018)
@@ -170,13 +170,24 @@
                                        0 };
 
 
-MBErrorCode ReadVtk::load_file(const char *filename,
-                               MBEntityHandle& file_set,
-                               const FileOptions& opts,
-                               const char* name,
-                               const int*, const int,
-                               const MBTag* file_id_tag) 
+MBErrorCode ReadVtk::read_tag_values( const char* /* file_name */,
+                                      const char* /* tag_name */,
+                                      const FileOptions& /* opts */,
+                                      std::vector<int>& /* tag_values_out */,
+                                      const IDTag* /* subset_list */,
+                                      int /* subset_list_length */ )
 {
+  return MB_NOT_IMPLEMENTED;
+}
+
+
+MBErrorCode ReadVtk::load_file( const char *filename,
+                                MBEntityHandle& file_set,
+                                const FileOptions& opts,
+                                const MBReaderIface::IDTag* subset_list,
+                                int subset_list_length,
+                                const MBTag* file_id_tag) 
+{
   MBErrorCode result;
   file_set = 0;
 
@@ -185,7 +196,7 @@
   std::vector<MBRange> element_list;
   MBRange vertices;
   
-  if (name) {
+  if (subset_list && subset_list_length) {
     readMeshIface->report_error( "Reading subset of files not supported for VTK." );
     return MB_UNSUPPORTED_OPERATION;
   }

Modified: MOAB/trunk/ReadVtk.hpp
===================================================================
--- MOAB/trunk/ReadVtk.hpp	2009-07-16 17:56:10 UTC (rev 3017)
+++ MOAB/trunk/ReadVtk.hpp	2009-07-16 20:45:50 UTC (rev 3018)
@@ -32,13 +32,19 @@
   static MBReaderIface* factory( MBInterface* );
 
     //! load a file
-  MBErrorCode load_file(const char *file_name,
-                        MBEntityHandle& file_set,
-                        const FileOptions&,
-                        const char* set_tag_name,
-                        const int* set_tag_values,
-                        int num_set_tag_values,
-                        const MBTag* file_id_tag );
+  MBErrorCode load_file( const char *file_name,
+                         MBEntityHandle& file_set,
+                         const FileOptions&,
+                         const MBReaderIface::IDTag* subset_list = 0,
+                         int subset_list_length = 0,
+                         const MBTag* file_id_tag = 0 );
+
+  MBErrorCode read_tag_values( const char* file_name,
+                               const char* tag_name,
+                               const FileOptions& opts,
+                               std::vector<int>& tag_values_out,
+                               const IDTag* subset_list = 0,
+                               int subset_list_length = 0 );
   
     //! Constructor
   ReadVtk(MBInterface* impl = NULL);

Modified: MOAB/trunk/Tqdcfr.cpp
===================================================================
--- MOAB/trunk/Tqdcfr.cpp	2009-07-16 17:56:10 UTC (rev 3017)
+++ MOAB/trunk/Tqdcfr.cpp	2009-07-16 20:45:50 UTC (rev 3018)
@@ -190,18 +190,28 @@
   
 }
 
-  
+
+MBErrorCode Tqdcfr::read_tag_values( const char* /* file_name */,
+                                     const char* /* tag_name */,
+                                     const FileOptions& /* opts */,
+                                     std::vector<int>& /* tag_values_out */,
+                                     const IDTag* /* subset_list */,
+                                     int /* subset_list_length */ )
+{
+  return MB_NOT_IMPLEMENTED;
+}
+
 MBErrorCode Tqdcfr::load_file(const char *file_name,
                               MBEntityHandle& file_set,
                               const FileOptions& opts,
-                              const char* block_tag_name,
-                              const int*, const int,
+                              const MBReaderIface::IDTag* subset_list,
+                              int subset_list_length,
                               const MBTag* file_id_tag) 
 {
   MBErrorCode result;
   file_set = mFileSet = 0;
 
-  if (block_tag_name) {
+  if (subset_list && subset_list_length) {
     readUtilIface->report_error( "Reading subset of files not supported for CUB files." );
     return MB_UNSUPPORTED_OPERATION;
   }

Modified: MOAB/trunk/Tqdcfr.hpp
===================================================================
--- MOAB/trunk/Tqdcfr.hpp	2009-07-16 17:56:10 UTC (rev 3017)
+++ MOAB/trunk/Tqdcfr.hpp	2009-07-16 20:45:50 UTC (rev 3018)
@@ -295,10 +295,17 @@
   MBErrorCode load_file(const char *file_name,
                         MBEntityHandle& file_set,
                         const FileOptions& opts,
-                        const char* block_tag_name,
-                        const int* block_list,
-                        int num_blocks,
+                        const MBReaderIface::IDTag* subset_list = 0,
+                        int subset_list_length = 0,
                         const MBTag* file_id_tag = 0 );
+
+  MBErrorCode read_tag_values( const char* file_name,
+                               const char* tag_name,
+                               const FileOptions& opts,
+                               std::vector<int>& tag_values_out,
+                               const IDTag* subset_list = 0,
+                               int subset_list_length = 0 );
+                               
   MBErrorCode read_nodeset(ModelEntry *model,
                     NodesetHeader *nodeseth);
   MBErrorCode read_sideset(const double data_version,

Modified: MOAB/trunk/exodus_test.cc
===================================================================
--- MOAB/trunk/exodus_test.cc	2009-07-16 17:56:10 UTC (rev 3017)
+++ MOAB/trunk/exodus_test.cc	2009-07-16 20:45:50 UTC (rev 3018)
@@ -65,6 +65,10 @@
 void test_read_shell_edge()   { test_read_side( 4, MBEDGE, 3 ); } // sideset 4
 void test_read_hex20_side()   { test_read_side( 2, MBQUAD, 8 ); }  // sideset 2
 
+void test_read_block_ids();
+void test_read_sideset_ids();
+void test_read_nodeset_ids();
+
 int main()
 {
   int result = 0;
@@ -88,6 +92,10 @@
   result += RUN_TEST(test_read_shell_edge);
   result += RUN_TEST(test_read_hex20_side);
   
+  result += RUN_TEST(test_read_block_ids );
+  result += RUN_TEST(test_read_sideset_ids);
+  result += RUN_TEST(test_read_nodeset_ids);
+  
   return result;
 }
 
@@ -391,3 +399,36 @@
     
 }
 
+void test_read_ids_common( const char* file_name,
+                           const char* tag_name,
+                           const int* expected_vals,
+                           int num_expected )
+{
+  MBCore mb;
+  ReadNCDF reader(&mb);
+  
+  FileOptions opts("");
+  std::vector<int> values;
+  MBErrorCode rval = reader.read_tag_values( file_name, tag_name, opts, values );
+  CHECK_ERR(rval);
+  
+  std::vector<int> expected( expected_vals, expected_vals+num_expected );
+  std::sort( values.begin(), values.end() );
+  std::sort( expected.begin(), expected.end() );
+  CHECK_EQUAL( expected, values );
+}
+
+void test_read_block_ids() {
+  const int expected[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13 };
+  test_read_ids_common( ho_file, MATERIAL_SET_TAG_NAME, expected, sizeof(expected)/sizeof(expected[0]) );
+}
+
+void test_read_sideset_ids() {
+  const int expected[] = { 1, 2, 3, 4 };
+  test_read_ids_common( ho_file, NEUMANN_SET_TAG_NAME, expected, sizeof(expected)/sizeof(expected[0]) );
+}
+
+void test_read_nodeset_ids() {
+  test_read_ids_common( ho_file, DIRICHLET_SET_TAG_NAME, 0, 0 );
+}
+

Modified: MOAB/trunk/test/h5file/h5partial.cpp
===================================================================
--- MOAB/trunk/test/h5file/h5partial.cpp	2009-07-16 17:56:10 UTC (rev 3017)
+++ MOAB/trunk/test/h5file/h5partial.cpp	2009-07-16 20:45:50 UTC (rev 3018)
@@ -1,6 +1,9 @@
 #include "MBCore.hpp"
 #include "MBRange.hpp"
 #include "TestUtil.hpp"
+#include "ReadHDF5.hpp"
+#include "MBTagConventions.hpp"
+#include "FileOptions.hpp"
 #include <vector>
 #include <stdlib.h>
 #include <iostream>
@@ -134,7 +137,10 @@
 
 void test_read_sides();
 
+void test_read_ids();
 
+void test_read_partial_ids();
+
 int main( int argc, char* argv[] )
 {
   if (argc > 1) {
@@ -169,6 +175,8 @@
   result += RUN_TEST(test_read_tagged_elems);
   result += RUN_TEST(test_read_tagged_nodes);
   result += RUN_TEST(test_read_sides);
+  result += RUN_TEST(test_read_ids);
+  result += RUN_TEST(test_read_partial_ids);
 
   if (argc == 1)
     remove( TEST_FILE );
@@ -1480,3 +1488,90 @@
     CHECK_EQUAL( 4, (int)edges.size() );
   }
 }
+
+const int expected_ids[] = { 2, 4, 6, 8, 10, 12, 14, 16, 18 };
+const int expected_vols[] = { 3, 7, 10 };
+
+void write_id_test_file()
+{
+  MBCore moab;
+  MBInterface& mb = moab;
+  MBErrorCode rval;
+  
+    // create 12 entity sets
+  MBEntityHandle sets[12];
+  for (int i = 0; i < 12; ++i) {
+    rval = mb.create_meshset( MESHSET_SET, sets[i] );
+    CHECK_ERR(rval);
+  }
+  
+    // create tag handles
+  MBTag id = 0, gid = 0, dim = 0;
+  mb.tag_create( ID_TAG_NAME, sizeof(int), MB_TAG_SPARSE, MB_TYPE_INTEGER, id, 0 );
+  mb.tag_create( GEOM_DIMENSION_TAG_NAME, sizeof(int), MB_TAG_SPARSE, MB_TYPE_INTEGER, dim, 0 );
+  mb.tag_create( GLOBAL_ID_TAG_NAME, sizeof(int), MB_TAG_DENSE, MB_TYPE_INTEGER, gid, 0 );
+  
+    // set ID tag on first 10 sets
+  rval = mb.tag_set_data( id, sets, sizeof(expected_ids)/sizeof(int), expected_ids );
+  CHECK_ERR(rval);
+    // set geom dim on all sets, only three of them have dim == 3
+  int num_vol = sizeof(expected_vols)/sizeof(int);
+  int dims[12], ids[12];
+  int v = 0;
+  for (int i = 0; i < 12; ++i) {
+    dims[i] = i % 3 + 1;
+    if (dims[i] == 3) {
+      if (v < num_vol) 
+        ids[i] = expected_vols[v++];
+      else
+        ids[i] = expected_vols[0];
+    }
+    else
+      ids[i] = 100;
+  }
+  rval = mb.tag_set_data( gid, sets, 12, ids );
+  CHECK_ERR(rval);
+  rval = mb.tag_set_data( dim, sets, 12, dims );
+  CHECK_ERR(rval);
+  
+  rval = mb.write_file( TEST_FILE, "MOAB" );
+  CHECK_ERR(rval);
+}
+
+void test_read_ids()
+{
+  write_id_test_file();
+  
+  MBCore moab;
+  ReadHDF5 reader(&moab);
+  FileOptions opts("");
+  MBErrorCode rval;
+  std::vector<int> values;
+  rval = reader.read_tag_values( TEST_FILE, ID_TAG_NAME, opts, values );
+  remove( TEST_FILE );
+  CHECK_ERR(rval);
+  
+  std::sort( values.begin(), values.end() );
+  std::vector<int> expected( expected_ids, expected_ids+sizeof(expected_ids)/sizeof(int) );
+  CHECK_EQUAL( expected, values );
+}
+
+void test_read_partial_ids()
+{
+  write_id_test_file();
+  
+  const int three = 3;
+  MBReaderIface::IDTag vols = { GEOM_DIMENSION_TAG_NAME, &three, 1 };
+  
+  MBCore moab;
+  ReadHDF5 reader(&moab);
+  FileOptions opts("");
+  MBErrorCode rval;
+  std::vector<int> values;
+  rval = reader.read_tag_values( TEST_FILE, GLOBAL_ID_TAG_NAME, opts, values, &vols, 1 );
+  remove( TEST_FILE );
+  CHECK_ERR(rval);
+  
+  std::sort( values.begin(), values.end() );
+  std::vector<int> expected( expected_ids, expected_ids+sizeof(expected_ids)/sizeof(int) );
+}



More information about the moab-dev mailing list