[MOAB-dev] r1999 - in MOAB/trunk: . mhdf/include

kraftche at mcs.anl.gov kraftche at mcs.anl.gov
Tue Jul 8 14:04:14 CDT 2008


Author: kraftche
Date: 2008-07-08 14:04:14 -0500 (Tue, 08 Jul 2008)
New Revision: 1999

Modified:
   MOAB/trunk/ReadHDF5.cpp
   MOAB/trunk/WriteHDF5.cpp
   MOAB/trunk/mhdf/include/mhdf.h
Log:
Fix "bug" in HDF5 file format as written by MOAB:  
 - mhdf.h defines constants for tag storage type 
   (bit, dense, sparse, or mesh).  
 - ReadHDF5 and WriteHDF5 cast the MBTagType to an 
   int rather than using the constants provided in
   mhdf.h.  
 - The values for the mhdf.h constants are not the
   same as the MBTagType enum values.
Solution:
 - Change the values of the mhdf constants to mach
   the MOAB ones so as to avoid breaking reading
   of existing files.
 - Change ReadHFD5 and WriteHDF5 such that they 
   convert between the mhdf and MOAB constants to
   avoid future breakage.
 



Modified: MOAB/trunk/ReadHDF5.cpp
===================================================================
--- MOAB/trunk/ReadHDF5.cpp	2008-07-08 17:05:54 UTC (rev 1998)
+++ MOAB/trunk/ReadHDF5.cpp	2008-07-08 19:04:14 UTC (rev 1999)
@@ -1138,7 +1138,7 @@
   
   mhdf_TagDataType mhdf_type;  // Enum for tag data type
   int tag_size;                // Size of tag
-  int storage;                 // TSTT storage type (dense vs. sparse)
+  int mhdf_storage;            // TSTT storage type (dense vs. sparse)
   int have_default;            // File contains default value for tag
   int have_global;             // File contains global value for tag
   int have_sparse;             // File contains sparse data table for tag
@@ -1147,15 +1147,25 @@
   int array_size;              // If tag is not opaque, the number of data per entity
   MBTag handle;                // The handle for the tag
   MBDataType mb_type;          // The MOAB data type for the data
+  MBTagType storage;
   
     // Get description of tag
-  mhdf_getTagInfo( filePtr, name, &mhdf_type, &tag_size, &storage,
+  mhdf_getTagInfo( filePtr, name, &mhdf_type, &tag_size, &mhdf_storage,
                    &have_default, &have_global, &have_sparse, &status );
   if (mhdf_isError( &status ))
   {
     readUtil->report_error( mhdf_message( &status ) );
     return MB_FAILURE;
   }
+  switch (mhdf_storage) {
+    case mhdf_DENSE_TYPE : storage = MB_TAG_DENSE ; break;
+    case mhdf_SPARSE_TYPE: storage = MB_TAG_SPARSE; break;
+    case mhdf_BIT_TYPE   : storage = MB_TAG_BIT;    break;
+    case mhdf_MESH_TYPE  : storage = MB_TAG_MESH;   break;
+    default:
+      readUtil->report_error( "Invalid storage type for tag '%s': %d\n", name, mhdf_storage );
+      return MB_FAILURE;
+  }
 
     // Type-specific stuff
   switch (mhdf_type)
@@ -1338,10 +1348,10 @@
   else if (MB_TAG_NOT_FOUND == rval)
   {
     if (tag_size == MB_VARIABLE_LENGTH)
-      rval = iFace->tag_create_variable_length( name, (MBTagType)storage, mb_type,
+      rval = iFace->tag_create_variable_length( name, storage, mb_type,
                                                 handle, default_ptr, default_size );
     else
-      rval = iFace->tag_create( name, tag_size, (MBTagType)storage, mb_type,
+      rval = iFace->tag_create( name, tag_size, storage, mb_type,
                                 handle, default_ptr );
     if (MB_SUCCESS != rval)
       return rval;

Modified: MOAB/trunk/WriteHDF5.cpp
===================================================================
--- MOAB/trunk/WriteHDF5.cpp	2008-07-08 17:05:54 UTC (rev 1998)
+++ MOAB/trunk/WriteHDF5.cpp	2008-07-08 19:04:14 UTC (rev 1999)
@@ -2440,10 +2440,10 @@
                                    unsigned long num_sparse_entities,
                                    unsigned long data_table_size )
 {
-  MBTagType storage;
+  MBTagType mb_storage;
   MBDataType mb_type;
   mhdf_TagDataType mhdf_type;
-  int tag_size, elem_size, mhdf_size;
+  int tag_size, elem_size, mhdf_size, storage;
   hid_t hdf_type = (hid_t)0;
   hid_t handles[2];
   std::string tag_name;
@@ -2452,7 +2452,14 @@
   
 
     // get tag properties
-  rval = iFace->tag_get_type( tag_id, storage  ); CHK_MB_ERR_0(rval);
+  rval = iFace->tag_get_type( tag_id, mb_storage  ); CHK_MB_ERR_0(rval);
+  switch (mb_storage) {
+    case MB_TAG_DENSE :  storage = mhdf_DENSE_TYPE ; break;
+    case MB_TAG_SPARSE:  storage = mhdf_SPARSE_TYPE; break;
+    case MB_TAG_BIT:     storage = mhdf_BIT_TYPE;    break;
+    case MB_TAG_MESH:    storage = mhdf_MESH_TYPE;   break;
+    default: return MB_FAILURE;
+  }
   rval = iFace->tag_get_name( tag_id, tag_name ); CHK_MB_ERR_0(rval);
   rval = get_tag_size( tag_id, mb_type, tag_size, elem_size, mhdf_size, mhdf_type, hdf_type );
   CHK_MB_ERR_0(rval);

Modified: MOAB/trunk/mhdf/include/mhdf.h
===================================================================
--- MOAB/trunk/mhdf/include/mhdf.h	2008-07-08 17:05:54 UTC (rev 1998)
+++ MOAB/trunk/mhdf/include/mhdf.h	2008-07-08 19:04:14 UTC (rev 1999)
@@ -1492,11 +1492,11 @@
 /*@{*/
 
 /** \brief Was dense tag data in mesh database */
-#define mhdf_DENSE_TYPE   0 
+#define mhdf_DENSE_TYPE   2 
 /** \brief Was sparse tag data in mesh database */
 #define mhdf_SPARSE_TYPE  1 
 /** \brief Was bit-field tag data in mesh database */
-#define mhdf_BIT_TYPE     2 
+#define mhdf_BIT_TYPE     0 
 /** \brief Unused */
 #define mhdf_MESH_TYPE    3 
 




More information about the moab-dev mailing list