[MOAB-dev] r1681 - in MOAB/trunk: . mhdf/include mhdf/src
kraftche at mcs.anl.gov
kraftche at mcs.anl.gov
Fri Mar 21 20:31:49 CDT 2008
Author: kraftche
Date: 2008-03-21 20:31:49 -0500 (Fri, 21 Mar 2008)
New Revision: 1681
Modified:
MOAB/trunk/WriteHDF5.cpp
MOAB/trunk/mhdf/include/mhdf.h
MOAB/trunk/mhdf/src/tags.c
Log:
fix mhdf bug: don't assume default and mesh values for handle-type tags are passed in as arrays of 32-bit integers
Modified: MOAB/trunk/WriteHDF5.cpp
===================================================================
--- MOAB/trunk/WriteHDF5.cpp 2008-03-22 01:29:42 UTC (rev 1680)
+++ MOAB/trunk/WriteHDF5.cpp 2008-03-22 01:31:49 UTC (rev 1681)
@@ -1497,6 +1497,7 @@
MBTagType mb_type;
MBDataType mb_data_type;
long table_size;
+ hid_t value_type = 0;
//get tag properties from moab
if (MB_SUCCESS != iFace->tag_get_name( tag_data.tag_id, name ) ||
@@ -1530,6 +1531,23 @@
size_t chunk_size = bufferSize / mb_size;
assert( chunk_size > 0 );
char* tag_buffer = (char*)dataBuffer;
+
+ if (mb_data_type == MB_TYPE_HANDLE) {
+ hsize_t len = mb_size / sizeof(MBEntityHandle);
+ if (len == 1)
+ value_type = id_type;
+ else {
+#if defined(H5Tarray_create_vers) && H5Tarray_create_vers > 1
+ value_type = H5Tarray_create( id_type, 1, &len );
+#else
+ value_type = H5Tarray_create( id_type, 1, &len, 0 );
+#endif
+ if (value_type < 0) {
+ mhdf_closeData( filePtr, tables[1], &status );
+ return MB_FAILURE;
+ }
+ }
+ }
// Write the tag values
size_t remaining = tag_data.range.size();
@@ -1562,7 +1580,12 @@
{
rval = iFace->tag_get_data( tag_data.tag_id, range, tag_buffer );
}
- CHK_MB_ERR_1(rval, tables[1], status);
+ if (MB_SUCCESS != rval) {
+ mhdf_closeData( filePtr, tables[1], &status );
+ if (value_type && value_type != id_type)
+ H5Tclose( value_type );
+ return rval;
+ }
// Convert MBEntityHandles to file ids
if (mb_data_type == MB_TYPE_HANDLE)
@@ -1570,12 +1593,16 @@
// write the data
mhdf_writeSparseTagValues( tables[1], offset, count,
- 0, tag_buffer, &status );
+ value_type, tag_buffer, &status );
+ if (mhdf_isError(&status) && value_type && value_type != id_type)
+ H5Tclose( value_type );
CHK_MHDF_ERR_1(status, tables[1]);
offset += count;
} // while (remaining)
+ if (value_type && value_type != id_type)
+ H5Tclose( value_type );
mhdf_closeData( filePtr, tables[1], &status );
CHK_MHDF_ERR_0(status);
@@ -2368,6 +2395,7 @@
def_value,
mesh_value,
hdf_type,
+ mb_type == MB_TYPE_HANDLE ? id_type : 0,
&status );
CHK_MHDF_ERR_0(status);
@@ -2392,7 +2420,7 @@
storage,
def_value, def_val_len / elem_size,
mesh_value, mesh_val_len / elem_size,
- hdf_type,
+ hdf_type, mb_type == MB_TYPE_HANDLE ? id_type : 0,
&status );
CHK_MHDF_ERR_0(status);
Modified: MOAB/trunk/mhdf/include/mhdf.h
===================================================================
--- MOAB/trunk/mhdf/include/mhdf.h 2008-03-22 01:29:42 UTC (rev 1680)
+++ MOAB/trunk/mhdf/include/mhdf.h 2008-03-22 01:31:49 UTC (rev 1681)
@@ -1546,6 +1546,12 @@
*\param hdf_type If non-zero, assumed to be a user-specified type
* for opaque data. Ignored if tag_type is not
* mhdf_OPAQUE.
+ *\param hdf_base_type Ignored if hdf_type is non-zero. If hdf_type is
+ * zero and this type is non-zero, it is used either
+ * as the type or as the base type for an array type for
+ * default_value and global_value, respectively. Typically
+ * used to specify the input data type for mhdf_ENTITY_ID
+ * tags.
*/
void
mhdf_createTag( mhdf_FileHandle file_handle,
@@ -1556,6 +1562,7 @@
const void* default_value,
const void* global_value,
hid_t hdf_type,
+ hid_t mhdf_base_type,
mhdf_Status* status );
/** \brief Add variable-length tag to file
@@ -1576,6 +1583,12 @@
*\param hdf_type If non-zero, assumed to be a user-specified type
* for opaque data. Ignored if tag_type is not
* mhdf_OPAQUE.
+ *\param hdf_base_type Ignored if hdf_type is non-zero. If hdf_type is
+ * zero and this type is non-zero, it is used either
+ * as the type or as the base type for an array type for
+ * default_value and global_value, respectively. Typically
+ * used to specify the input data type for mhdf_ENTITY_ID
+ * tags.
*/
void
mhdf_createVarLenTag( mhdf_FileHandle file_handle,
@@ -1587,6 +1600,7 @@
const void* global_value,
int global_value_length,
hid_t hdf_type,
+ hid_t hdf_base_type,
mhdf_Status* status );
Modified: MOAB/trunk/mhdf/src/tags.c
===================================================================
--- MOAB/trunk/mhdf/src/tags.c 2008-03-22 01:29:42 UTC (rev 1680)
+++ MOAB/trunk/mhdf/src/tags.c 2008-03-22 01:31:49 UTC (rev 1681)
@@ -245,6 +245,7 @@
const void* global_value,
int global_value_size_in,
hid_t hdf_type,
+ hid_t hdf_base_type,
mhdf_Status* status )
{
hid_t temp_id, group_id, tag_id;
@@ -255,6 +256,7 @@
int one = 1, var_len=0;
hsize_t default_value_size = default_value_size_in;
hsize_t global_value_size = global_value_size_in;
+ int close_base_type = 0;
/* Validate input */
@@ -377,7 +379,7 @@
case mhdf_ENTITY_ID:
arr_len = abs(size);
- hdf_type = H5Tcopy( H5T_NATIVE_INT );
+ hdf_type = H5Tcopy( H5T_NATIVE_ULONG );
break;
case mhdf_BOOLEAN:
@@ -404,6 +406,12 @@
return -1;
}
+ if (hdf_base_type && H5Tget_class(hdf_type) != H5Tget_class(hdf_base_type)) {
+ mhdf_setFail( status, "Invalid base type for tag default/global data" );
+ H5Gclose( tag_id );
+ return -1;
+ }
+
if (size < -1 || !arr_len)
{
mhdf_setFail( status, "Invalid 'size' parameter passed to mhdf_createTag (%d)", (int)size);
@@ -434,11 +442,34 @@
return -1;
}
hdf_type = temp_id;
+
+ if (hdf_base_type) {
+ if (H5Tequal( hdf_base_type, hdf_type ) > 0) {
+ hdf_base_type = hdf_type;
+ }
+ else {
+#if defined(H5Tarray_create_vers) && H5Tarray_create_vers > 1
+ temp_id = H5Tarray_create2( hdf_base_type, 1, &arr_len);
+#else
+ temp_id = H5Tarray_create( hdf_base_type, 1, &arr_len, NULL );
+#endif
+ if (temp_id < 0)
+ {
+ mhdf_setFail( status, "Failed to create tag type object." );
+ H5Gclose( tag_id );
+ H5Tclose( hdf_type );
+ return -1;
+ }
+ hdf_base_type = temp_id;
+ close_base_type = 1;
+ }
+ }
}
+ if (!hdf_base_type)
+ hdf_base_type = hdf_type;
-
/* Create tag type object, or write attribute if opaque */
#if defined(H5Tcommit_vers) && H5Tcommit_vers > 1
@@ -449,6 +480,8 @@
if (rval < 0)
{
mhdf_setFail( status, "H5Tcommit failed for tag \"%s\"", tag_name );
+ if (close_base_type)
+ H5Tclose( hdf_base_type );
H5Tclose( hdf_type );
H5Gclose( tag_id );
return -1;
@@ -464,6 +497,8 @@
status );
if (!rval)
{
+ if (close_base_type)
+ H5Tclose( hdf_base_type );
H5Gclose( tag_id );
H5Tclose( hdf_type );
return -1;
@@ -476,9 +511,12 @@
if (default_value)
{
- rval = store_tag_val_in_attrib( tag_id, TAG_DEFAULT_ATTRIB, hdf_type, default_value,
+ rval = store_tag_val_in_attrib( tag_id, TAG_DEFAULT_ATTRIB, hdf_base_type,
+ default_value,
var_len ? default_value_size : 1, status );
if (!rval) {
+ if (close_base_type)
+ H5Tclose( hdf_base_type );
H5Gclose( tag_id );
H5Tclose( hdf_type );
return -1;
@@ -489,15 +527,20 @@
if (global_value)
{
- rval = store_tag_val_in_attrib( tag_id, TAG_GLOBAL_ATTRIB, hdf_type, global_value,
+ rval = store_tag_val_in_attrib( tag_id, TAG_GLOBAL_ATTRIB, hdf_base_type,
+ global_value,
var_len ? global_value_size : 1, status );
if (!rval) {
+ if (close_base_type)
+ H5Tclose( hdf_base_type );
H5Gclose( tag_id );
H5Tclose( hdf_type );
return -1;
}
}
+ if (close_base_type)
+ H5Tclose( hdf_base_type );
H5Tclose( hdf_type );
mhdf_setOkay( status );
return tag_id;
@@ -513,12 +556,14 @@
const void* default_value,
const void* global_value,
hid_t hdf_type,
+ hid_t hdf_base_type,
mhdf_Status* status )
{
hid_t tag_id;
API_BEGIN;
tag_id = create_tag_common( file_handle, tag_name, tag_type, size, storage,
- default_value, 1, global_value, 1, hdf_type, status );
+ default_value, 1, global_value, 1, hdf_type,
+ hdf_base_type, status );
if (tag_id >= 0)
H5Gclose( tag_id );
API_END;
@@ -534,6 +579,7 @@
const void* global_value,
int global_value_length,
hid_t hdf_type,
+ hid_t hdf_base_type,
mhdf_Status* status )
{
herr_t rval;
@@ -544,7 +590,7 @@
tag_id = create_tag_common( file_handle, tag_name, tag_type, -1, storage,
default_value, default_value_length,
global_value, global_value_length,
- hdf_type, status );
+ hdf_type, hdf_base_type, status );
if (tag_id >= 0) {
rval = mhdf_create_scalar_attrib( tag_id,
TAG_VARLEN_ATTRIB,
More information about the moab-dev
mailing list