[MOAB-dev] r2795 - in MOAB/trunk/mhdf: . example include src
kraftche at cae.wisc.edu
kraftche at cae.wisc.edu
Thu Apr 2 13:45:32 CDT 2009
Author: kraftche
Date: 2009-04-02 13:45:32 -0500 (Thu, 02 Apr 2009)
New Revision: 2795
Added:
MOAB/trunk/mhdf/example/info.c
MOAB/trunk/mhdf/src/file-desc.c
MOAB/trunk/mhdf/src/file-desc.h
Modified:
MOAB/trunk/mhdf/Makefile.am
MOAB/trunk/mhdf/include/mhdf.h
MOAB/trunk/mhdf/src/connectivity.c
MOAB/trunk/mhdf/src/nodes.c
MOAB/trunk/mhdf/src/sets.c
MOAB/trunk/mhdf/src/util.c
MOAB/trunk/mhdf/src/util.h
Log:
o Add new function: mhdf_getFileSummary
- reads summary of file contents
- returns summary in a single block of memory for easy copy/send/bcast, etc.
o Add new function: mhdf_fixFileDesc
- fix copy of struct returned by mhdf_getFileSummary, updating
internal pointers using offset from original struct start.
o Add new functions that open tables w/out reading attributes.
o Add utility (h5minfo) that calls mhdf_getFileSummary for a file
and prints the results.
Modified: MOAB/trunk/mhdf/Makefile.am
===================================================================
--- MOAB/trunk/mhdf/Makefile.am 2009-04-01 20:44:55 UTC (rev 2794)
+++ MOAB/trunk/mhdf/Makefile.am 2009-04-02 18:45:32 UTC (rev 2795)
@@ -1,10 +1,12 @@
noinst_LTLIBRARIES = libmhdf.la
libmhdf_la_LIBADD = $(HDF5_LIBS)
+bin_PROGRAMS = h5minfo
libmhdf_la_SOURCES = include/mhdf.h \
src/adjacency.c \
src/connectivity.c \
+ src/file-desc.c \
src/file-handle.c \
src/file-handle.h \
src/file.c \
@@ -17,6 +19,10 @@
src/util.c \
src/util.h
+h5minfo_SOURCES = include/mhdf.h example/info.c
+h5minfo_LDADD = libmhdf.la
+
DEFS = -I$(srcdir)/include
EXTRA_DIST = doc/Doxyfile example/hexes_to_gmsh.c
+
Added: MOAB/trunk/mhdf/example/info.c
===================================================================
--- MOAB/trunk/mhdf/example/info.c (rev 0)
+++ MOAB/trunk/mhdf/example/info.c 2009-04-02 18:45:32 UTC (rev 2795)
@@ -0,0 +1,245 @@
+#include "mhdf.h"
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <ctype.h>
+#include <H5Tpublic.h>
+
+static int print_file_summary( struct mhdf_FileDesc* data );
+
+int main( int argc, char* argv[] )
+{
+ int result;
+ mhdf_FileHandle file;
+ mhdf_Status status;
+ unsigned long max_id;
+ struct mhdf_FileDesc* data;
+
+ if (argc != 2) {
+ fprintf( stderr,"Usage: %s <filename>\n", argv[0] );
+ return 1;
+ }
+
+ file = mhdf_openFile( argv[1], 0, &max_id, &status );
+ if (mhdf_isError( &status )) {
+ fprintf( stderr,"%s: %s\n", argv[1], mhdf_message( &status ) );
+ return 1;
+ }
+
+ data = mhdf_getFileSummary( file, H5T_NATIVE_ULONG, &status );
+ if (mhdf_isError( &status )) {
+ fprintf( stderr,"%s: %s\n", argv[1], mhdf_message( &status ) );
+ return 1;
+ }
+
+ mhdf_closeFile( file, &status );
+
+ printf( "%s:\n", argv[1] );
+ result = print_file_summary( data );
+ free( data );
+ return result;
+}
+
+static void print_ent_desc( const char* name,
+ const char* subname,
+ struct mhdf_EntDesc* data,
+ const char* vals_label,
+ struct mhdf_FileDesc* all )
+{
+ int i, len = 10;
+
+ if (vals_label && strlen(vals_label) > len)
+ len = strlen(vals_label);
+
+ if (subname)
+ printf( " %s (%s):\n", name, subname );
+ else
+ printf( " %s:\n", name );
+
+ if (vals_label)
+ printf( " %-*s: %d\n", len, vals_label, data->vals_per_ent );
+
+ printf( " %-*s: %ld [%ld - %ld]\n", len, "entities", data->count, data->start_id, data->start_id + data->count - 1 );
+ if (!data->num_dense_tags)
+ return;
+
+ printf( " %-*s: \"%s\"", len, "dense tags", all->tags[data->dense_tag_indices[0]].name );
+ for (i = 1; i < data->num_dense_tags; ++i)
+ printf( ", \"%s\"", all->tags[data->dense_tag_indices[i]].name );
+ printf ("\n");
+}
+
+static void print_elem_desc( struct mhdf_ElemDesc* data, struct mhdf_FileDesc* all )
+{
+ print_ent_desc( data->handle, data->type, &data->desc, "nodes per element", all );
+}
+
+static const char* tag_type_name( enum mhdf_TagDataType type )
+{
+ static const char opaque[] = "opaque";
+ static const char integer[] = "integer";
+ static const char real[] = "real";
+ static const char bits[] = "bit field";
+ static const char boolean[] = "boolean";
+ static const char id[] = "entity id";
+ static const char unknown[] = "(UNKNOWN TYPE ID)";
+ switch (type) {
+ case mhdf_OPAQUE: return opaque;
+ case mhdf_INTEGER: return integer;
+ case mhdf_FLOAT: return real;
+ case mhdf_BITFIELD: return bits;
+ case mhdf_BOOLEAN: return boolean;
+ case mhdf_ENTITY_ID: return id;
+ default: return unknown;
+ }
+ return unknown;
+}
+
+static const char* string_tag_value( const void* value,
+ enum mhdf_TagDataType type,
+ int size )
+{
+ static char buffer[1024];
+ const char* data = value;
+ char* offset = buffer;
+ int print, i;
+ const int* intptr = value;
+ const double* dblptr = value;
+ const unsigned long* idptr = value;
+
+
+ if (size <= 0) {
+ *buffer = '\0';
+ return buffer;
+ }
+
+ switch (type) {
+ case mhdf_OPAQUE:
+ print = 1;
+ for (i = 0; i < size; ++i)
+ if (!isprint(data[i]))
+ print = 0;
+ if (print) {
+ offset[0] = '"';
+ memcpy( offset+1, data, size );
+ offset[size+1] = '"';
+ offset[size+2] = '\0';
+ offset += size+2;
+ }
+ else {
+ strcpy( offset, "0x" );
+ offset += 2;
+ for (i = 0; i < size; ++i)
+ offset += sprintf( offset, "%02x", (unsigned int)data[i] );
+ }
+ break;
+ case mhdf_INTEGER:
+ if (size == 1) {
+ offset += sprintf( offset, "%d", intptr[0] );
+ }
+ else {
+ offset += sprintf( offset, "{%d", intptr[0] );
+ for (i = 1; i < size; ++i)
+ offset += sprintf( offset, ",%d", intptr[i] );
+ offset += sprintf( offset, "}" );
+ }
+ break;
+ case mhdf_FLOAT:
+ if (size == 1) {
+ offset += sprintf( offset, "%g", dblptr[0] );
+ }
+ else {
+ offset += sprintf( offset, "{%g", dblptr[0] );
+ for (i = 1; i < size; ++i)
+ offset += sprintf( offset, ",%g", dblptr[i] );
+ offset += sprintf( offset, "}" );
+ }
+ break;
+ case mhdf_BITFIELD:
+ if (size > 8)
+ offset += sprintf( offset, "(more than 8 bits)" );
+ else {
+ for (i = size - 1; i >= 0; --i)
+ *(offset++) = *data & (1<<i) ? '1' : '0';
+ *offset = '\0';
+ }
+ break;
+ case mhdf_BOOLEAN:
+ if (size == 1) {
+ offset += sprintf( offset, "%s", data[0] ? "true" : "false" );
+ }
+ else {
+ offset += sprintf( offset, "{%s", data[0] ? "true" : "false" );
+ for (i = 1; i < size; ++i)
+ offset += sprintf( offset, ",%s", data[i] ? "true" : "false" );
+ offset += sprintf( offset, "}" );
+ }
+ break;
+ case mhdf_ENTITY_ID:
+ if (size == 1) {
+ offset += sprintf( offset, "%ld", idptr[0] );
+ }
+ else {
+ offset += sprintf( offset, "{%ld", idptr[0] );
+ for (i = 1; i < size; ++i)
+ offset += sprintf( offset, ",%ld", idptr[i] );
+ offset += sprintf( offset, "}" );
+ }
+ break;
+ default:
+ strcpy( buffer, "(unknown data type)" );
+ break;
+ }
+
+ return buffer;
+}
+
+static void print_tag_desc( struct mhdf_TagDesc* data, struct mhdf_FileDesc* all )
+{
+ int i, width = 8;
+
+ printf( " \"%s\":\n", data->name );
+ printf( " %-*s: %s\n", width, "type", tag_type_name( data->type ) );
+ if (data->size < 0)
+ printf( " %-*s: (variable)\n", width, "size" );
+ else
+ printf( " %-*s: %d (%d bytes)\n", width, "size", data->size, data->bytes );
+ printf( " %-*s: %x\n", width, "flags", data->storage );
+ if (data->default_value)
+ printf( " %-*s: %s\n", width, "default",
+ string_tag_value( data->default_value, data->type, data->default_value_size ) );
+ if (data->global_value)
+ printf( " %-*s: %s\n", width, "mesh val",
+ string_tag_value( data->global_value, data->type, data->global_value_size ) );
+ if (data->have_sparse) {
+ printf( " %-*s: (sparse)", width, "tables" );
+ for (i = 0; i < data->num_dense_indices; ++i)
+ printf( ", %s", all->elems[data->dense_elem_indices[i]].handle );
+ }
+ else if (data->num_dense_indices) {
+ printf( " %-*s: %s", width, "tables", all->elems[data->dense_elem_indices[0]].handle );
+ for (i = 1; i < data->num_dense_indices; ++i)
+ printf( ", %s", all->elems[data->dense_elem_indices[i]].handle );
+ }
+ else {
+ printf( " %-*s: (none)", width, "tables" );
+ }
+ printf( "\n" );
+}
+
+static int print_file_summary( struct mhdf_FileDesc* data )
+{
+ int i;
+
+ printf( " Entities:\n" );
+ print_ent_desc( "Nodes", NULL, &data->nodes, "dimension", data );
+ for (i = 0; i < data->num_elem_desc; ++i)
+ print_elem_desc( data->elems + i, data );
+ print_ent_desc( "Sets", NULL, &data->sets, NULL, data );
+
+ printf( " Tags:\n" );
+ for (i = 0; i < data->num_tag_desc; ++i)
+ print_tag_desc( data->tags + i, data );
+
+ return 0;
+}
Modified: MOAB/trunk/mhdf/include/mhdf.h
===================================================================
--- MOAB/trunk/mhdf/include/mhdf.h 2009-04-01 20:44:55 UTC (rev 2794)
+++ MOAB/trunk/mhdf/include/mhdf.h 2009-04-02 18:45:32 UTC (rev 2795)
@@ -209,6 +209,76 @@
hid_t options,
mhdf_Status* status );
+/** Data common to sets, nodes, and each element type */
+struct mhdf_EntDesc {
+ long start_id; /**< First file ID for table of data */
+ long count; /**< Number of entities in table */
+ int vals_per_ent; /**< Connectivity length for elems, dimension for verts, unused for sets */
+ int* dense_tag_indices; /**< Indices into mhdf_FileDesc::tags for each tag for which dense data is present for these entities */
+ int num_dense_tags; /**< Length of dense_tag_indices */
+};
+/** Struct describing a tag */
+struct mhdf_TagDesc {
+ const char* name; /**< Tag name */
+ enum mhdf_TagDataType type; /**< Data type */
+ int size; /**< Tag size (num of data type) */
+ int bytes; /**< Tag size (number of bytes) */
+ int storage; /**< MOAB tag type (dense or sparse) */
+ int have_sparse; /**< Have sparse id/data pairs in file */
+ void* default_value; /**< Default value, NULL if none. */
+ int default_value_size;
+ void* global_value; /**< Global value, NULL if none. */
+ int global_value_size;
+ int* dense_elem_indices; /**< Array of indices indicating element types for which dense
+ data is stored. -2 for sets, -1 for nodes. */
+ int num_dense_indices;
+};
+struct mhdf_ElemDesc {
+ const char* handle; /**< String table identifier */
+ const char* type; /**< String type designator */
+ struct mhdf_EntDesc desc;
+};
+struct mhdf_FileDesc {
+ struct mhdf_EntDesc nodes;
+ struct mhdf_EntDesc sets;
+ struct mhdf_ElemDesc* elems; /**< Array of element table descriptions */
+ int num_elem_desc;
+ struct mhdf_TagDesc* tags; /**< Array of tag descriptions */
+ int num_tag_desc;
+ size_t total_size; /**< Size of memory block containing all struct data */
+ unsigned char* offset; /**< Unused, may be used by application */
+};
+
+/** \brief Get summary of data tables contained within file.
+ *
+ * Returned struct, including all pointed-to data, is allocated in a
+ * single contiguous block of memory with a size equal to 'total_size'.
+ * Caller is responsible for freeing the returned struct FileDesc pointer
+ * (and *only* that pointer, not pointers nexted within the struct!).
+ * Caller may copy (e.g. MPI_BCast) entire struct as one contiguous block,
+ * assuming all nested pointers in the copy are updated to the correct
+ * relative offset from the beginning of the struct.
+ */
+struct mhdf_FileDesc*
+mhdf_getFileSummary( mhdf_FileHandle file_handle,
+ hid_t file_id_type,
+ mhdf_Status* status );
+
+/**\brief Fix nested pointers for copied/moved FileDesc struct
+ *
+ * This is a utility method to facility copying/moving/communicating
+ * struct FileDesc instances. The structure and all data it references
+ * are allocated in a single contiguous block of memory of size
+ * FileDesc::total_size. As such, the struct can be copied with a single
+ * memcpy, packed into a single network packet, communicated with a single
+ * MPI call, etc. However, the pointers contained within the struct will
+ * not be valid in the copied instance (they will still point into the
+ * original instance.) Given a pointer to the copied struct and the address
+ * of the original struct, this function will updated all contained pointers.
+ */
+void
+mhdf_fixFileDesc( struct mhdf_FileDesc* copy_ptr, const struct mhdf_FileDesc* orig_addr );
+
/** \brief Given an element type Id, get the name.
* Fails if buffer is not of sufficient size.
* \param file_handle The file.
@@ -326,6 +396,9 @@
long* first_node_id_out,
mhdf_Status* status );
+hid_t
+mhdf_openNodeCoordsSimple( mhdf_FileHandle file_handle, mhdf_Status* status );
+
/** \brief Write node coordinate data
*
* Write interleaved coordinate data for a block of nodes
@@ -595,6 +668,12 @@
long* first_elem_id_out,
mhdf_Status* status );
+hid_t
+mhdf_openConnectivitySimple( mhdf_FileHandle file_handle,
+ const char* elem_handle,
+ mhdf_Status* status );
+
+
/** \brief Write element coordinate data
*
* Write interleaved fixed-connectivity element data for a block of elements.
@@ -1202,6 +1281,9 @@
long* first_set_id_out,
mhdf_Status* status );
+hid_t
+mhdf_openSetMetaSimple( mhdf_FileHandle file_handle, mhdf_Status* status );
+
/** \brief Read list of sets and meta-information about sets.
*
* Read set descriptions. See \ref mhdf_createSetMeta or \ref mhdf_set
Modified: MOAB/trunk/mhdf/src/connectivity.c
===================================================================
--- MOAB/trunk/mhdf/src/connectivity.c 2009-04-01 20:44:55 UTC (rev 2794)
+++ MOAB/trunk/mhdf/src/connectivity.c 2009-04-02 18:45:32 UTC (rev 2795)
@@ -130,6 +130,34 @@
return table_id;
}
+hid_t
+mhdf_openConnectivitySimple( mhdf_FileHandle file_handle,
+ const char* elem_handle,
+ mhdf_Status* status )
+{
+ FileHandle* file_ptr;
+ hid_t elem_id, table_id;
+ API_BEGIN;
+
+ file_ptr = (FileHandle*)(file_handle);
+ if (!mhdf_check_valid_file( file_ptr, status ))
+ return -1;
+
+ elem_id = mhdf_elem_group_from_handle( file_ptr, elem_handle, status );
+ if (elem_id < 0) return -1;
+
+ table_id = mhdf_open_table_simple( elem_id, CONNECTIVITY_NAME, status );
+
+ H5Gclose( elem_id );
+ if (table_id < 0)
+ return -1;
+
+ file_ptr->open_handle_count++;
+ mhdf_setOkay( status );
+ API_END_H(1);
+ return table_id;
+}
+
void
mhdf_writeConnectivity( hid_t table_id,
long offset,
Added: MOAB/trunk/mhdf/src/file-desc.c
===================================================================
--- MOAB/trunk/mhdf/src/file-desc.c (rev 0)
+++ MOAB/trunk/mhdf/src/file-desc.c 2009-04-02 18:45:32 UTC (rev 2795)
@@ -0,0 +1,518 @@
+#include "mhdf.h"
+#include "util.h"
+#include "status.h"
+#include <assert.h>
+#include <stdlib.h>
+#include <string.h>
+#include <H5Tpublic.h>
+
+static struct mhdf_FileDesc* alloc_file_desc( mhdf_Status* status );
+static void* realloc_data( struct mhdf_FileDesc** data, size_t append_bytes, mhdf_Status* status );
+static char buffer[512];
+
+static struct mhdf_FileDesc* alloc_file_desc( mhdf_Status* status )
+{
+ struct mhdf_FileDesc* result;
+ /* allocate a little short of a page */
+ result = (struct mhdf_FileDesc*)mhdf_malloc(4000, status);
+ if (mhdf_isError( status ))
+ return 0;
+
+ memset( result, 0, sizeof(struct mhdf_FileDesc) );
+ result->total_size = 4000;
+ result->offset = ((char*)result) + sizeof(struct mhdf_FileDesc);
+ return result;
+}
+
+static void* realloc_data( struct mhdf_FileDesc** data, size_t append_bytes, mhdf_Status* status )
+{
+ void* result_ptr;
+ struct mhdf_FileDesc* const input_ptr = *data;
+ unsigned char* const mem_ptr = (unsigned char*)input_ptr;
+ size_t new_size;
+
+ if (mem_ptr + input_ptr->total_size < input_ptr->offset + append_bytes) {
+ if (append_bytes < input_ptr->total_size)
+ new_size = 2 * input_ptr->total_size;
+ else
+ new_size = input_ptr->total_size + append_bytes;
+ *data = (struct mhdf_FileDesc*)mhdf_realloc( *data, new_size, status );
+ if (mhdf_isError( status ))
+ return 0;
+
+ if (*data != input_ptr)
+ mhdf_fixFileDesc( *data, input_ptr );
+ }
+
+ result_ptr = input_ptr->offset;
+ input_ptr->offset += append_bytes;
+ return result_ptr;
+}
+
+#define FIX_OFFSET( TYPE, FIELD ) \
+ copy_ptr->FIELD = (TYPE)( ((char*)(copy_ptr->FIELD) - (char*)orig_addr) + (char*)copy_ptr )
+
+
+void
+mhdf_fixFileDesc( struct mhdf_FileDesc* copy_ptr, const struct mhdf_FileDesc* orig_addr )
+{
+ int i;
+
+ API_BEGIN;
+ FIX_OFFSET( int*, nodes.dense_tag_indices );
+ FIX_OFFSET( int*, sets.dense_tag_indices );
+ FIX_OFFSET( struct mhdf_ElemDesc*, elems );
+ FIX_OFFSET( struct mhdf_TagDesc*, tags );
+
+ for (i = 0; i < copy_ptr->num_elem_desc; ++i) {
+ FIX_OFFSET( const char*, elems[i].handle );
+ FIX_OFFSET( const char*, elems[i].type );
+ FIX_OFFSET( int*, elems[i].desc.dense_tag_indices );
+ }
+
+ for (i = 0; i < copy_ptr->num_tag_desc; ++i) {
+ FIX_OFFSET( const char*, tags[i].name );
+ FIX_OFFSET( void*, tags[i].default_value );
+ FIX_OFFSET( void*, tags[i].global_value );
+ FIX_OFFSET( int*, tags[i].dense_elem_indices );
+ }
+ API_END;
+}
+
+static
+struct mhdf_FileDesc*
+get_elem_desc( mhdf_FileHandle file_handle,
+ struct mhdf_FileDesc* result,
+ const char* elem_handle,
+ int index,
+ mhdf_Status* status )
+{
+ hid_t id_pair[2];
+ int poly;
+ void* ptr;
+ long junk;
+
+ ptr = realloc_data( &result, strlen(elem_handle)+1, status );
+ if (!ptr) return NULL;
+ strcpy( ptr, elem_handle );
+ result->elems[index].handle = ptr;
+
+ mhdf_getElemTypeName( file_handle, elem_handle,
+ buffer, sizeof(buffer), status );
+ if (mhdf_isError(status)) {
+ free( result );
+ return NULL;
+ }
+
+ ptr = realloc_data( &result, strlen(buffer)+1, status );
+ if (!ptr) return NULL;
+ strcpy( ptr, buffer );
+ result->elems[index].type = ptr;
+
+ poly = mhdf_isPolyElement( file_handle, elem_handle, status );
+ if (mhdf_isError(status)) {
+ free( result );
+ return NULL;
+ }
+
+ if (!poly) {
+ id_pair[0] = mhdf_openConnectivity( file_handle,
+ elem_handle,
+ &result->elems[index].desc.vals_per_ent,
+ &result->elems[index].desc.count,
+ &result->elems[index].desc.start_id,
+ status );
+ if (id_pair[0] < 0) {
+ free( result );
+ return NULL;
+ }
+ mhdf_closeData( file_handle, id_pair[0], status );
+ }
+ else {
+ result->elems[index].desc.vals_per_ent = -1;
+ mhdf_openPolyConnectivity( file_handle,
+ elem_handle,
+ &result->elems[index].desc.count,
+ &junk,
+ &result->elems[index].desc.start_id,
+ id_pair,
+ status );
+ if (id_pair[0] < 0) {
+ free( result );
+ return NULL;
+ }
+ mhdf_closeData( file_handle, id_pair[0], status );
+ mhdf_closeData( file_handle, id_pair[1], status );
+ }
+
+ result->elems[index].desc.dense_tag_indices = NULL;
+ result->elems[index].desc.num_dense_tags = 0;
+ return result;
+}
+
+static
+unsigned get_file_id_size( hid_t file_id_type, mhdf_Status* status )
+{
+ if (H5Tget_class( file_id_type ) != H5T_INTEGER) {
+ mhdf_setFail( status, "Invalid handle or type class for file ID type." );
+ return 0;
+ }
+
+ return H5Tget_size( file_id_type );
+}
+
+static
+struct mhdf_FileDesc*
+get_tag_desc( mhdf_FileHandle file_handle,
+ struct mhdf_FileDesc* result,
+ const char* name,
+ int index,
+ hid_t type,
+ mhdf_Status* status )
+{
+ void* ptr;
+ int have_default, have_global;
+ int valsize, size;
+
+ ptr = realloc_data( &result, strlen(name)+1, status );
+ if (NULL == ptr) return NULL;
+ strcpy( ptr, name );
+ result->tags[index].name = ptr;
+
+ mhdf_getTagInfo( file_handle,
+ name,
+ &result->tags[index].type,
+ &result->tags[index].size,
+ &result->tags[index].storage,
+ &have_default,
+ &have_global,
+ &result->tags[index].have_sparse,
+ status );
+ if (mhdf_isError(status)) {
+ free( result );
+ return NULL;
+ }
+
+ /* For variable lengt tags, have_default and have_global will
+ contain the size of the respective values. For fixed-length
+ tags, they are either zero or one. Simplify later code by
+ making them contain the size for both cases. */
+ valsize = result->tags[index].size;
+ if (result->tags[index].size >= 0) {
+ if (have_default)
+ have_default = valsize;
+ if (have_global)
+ have_global = valsize;
+ }
+
+ result->tags[index].default_value = NULL;
+ result->tags[index].default_value_size = have_default;
+ result->tags[index].global_value = NULL;
+ result->tags[index].global_value_size = have_global;
+
+ switch (result->tags[index].type) {
+ case mhdf_OPAQUE:
+ type = 0;
+ break;
+ case mhdf_BOOLEAN:
+ type = H5T_NATIVE_UCHAR;
+ break;
+ case mhdf_INTEGER:
+ type = H5T_INTEGER;
+ have_default *= sizeof(int);
+ have_global *= sizeof(int);
+ valsize *= sizeof(int);
+ break;
+ case mhdf_FLOAT:
+ type = H5T_NATIVE_DOUBLE;
+ have_default *= sizeof(double);
+ have_global *= sizeof(double);
+ valsize *= sizeof(double);
+ break;
+ case mhdf_BITFIELD:
+ have_default = (have_default+7)/8;
+ have_global = (have_global+7)/8;
+ valsize = (valsize+7)/8;
+ switch (valsize) {
+ case 1:
+ type = H5Tcopy( H5T_NATIVE_B8 );
+ break;
+ case 2:
+ type = H5Tcopy( H5T_NATIVE_B16 );
+ break;
+ case 3:
+ ++valsize;
+ case 4:
+ type = H5Tcopy( H5T_NATIVE_B32 );
+ break;
+ case 5:
+ ++valsize;
+ case 6:
+ ++valsize;
+ case 7:
+ ++valsize;
+ case 8:
+ type = H5Tcopy( H5T_NATIVE_B64 );
+ break;
+ default:
+ free( result );
+ mhdf_setFail( status, "Cannot create a bit tag larger than 64-bits. %d bits requested.\n", (int)valsize);
+ return NULL;
+ }
+ break;
+ case mhdf_ENTITY_ID:
+ if (0 == type)
+ type = H5T_NATIVE_ULONG;
+ size = get_file_id_size( type, status );
+ if (!size) {
+ free( result );
+ return NULL;
+ }
+ have_default *= size;
+ have_global *= size;
+ valsize *= size;
+ break;
+ default:
+ mhdf_setFail( status, "Unknown mhdf_TagDataType value (%d) for tag (\"%s\")",
+ (int)result->tags[index].type, name );
+ free( result );
+ return NULL;
+ }
+ result->tags[index].bytes = valsize;
+
+ if (have_default || have_global) {
+ if (have_default) {
+ ptr = realloc_data( &result, have_default, status );
+ if (NULL == ptr) {
+ if (result->tags[index].type == mhdf_BITFIELD)
+ H5Tclose( type );
+ return NULL;
+ }
+ result->tags[index].default_value = ptr;
+ }
+ if (have_global) {
+ ptr = realloc_data( &result, have_global, status );
+ if (NULL == ptr) {
+ if (result->tags[index].type == mhdf_BITFIELD)
+ H5Tclose( type );
+ return NULL;
+ }
+ result->tags[index].global_value = ptr;
+ }
+ mhdf_getTagValues( file_handle,
+ name,
+ type,
+ result->tags[index].default_value,
+ result->tags[index].global_value,
+ status );
+ if (result->tags[index].type == mhdf_BITFIELD)
+ H5Tclose( type );
+ if (mhdf_isError(status)) {
+ free( result );
+ return NULL;
+ }
+ }
+
+ return result;
+}
+
+struct mhdf_FileDesc*
+mhdf_getFileSummary( mhdf_FileHandle file_handle,
+ hid_t file_id_type,
+ mhdf_Status* status )
+{
+ struct mhdf_FileDesc* result;
+ hid_t table_id;
+ int i, j, k, size, *indices;
+ void* ptr;
+ char **elem_handles = 0, **tag_names = 0;
+ unsigned char *array, *matrix;
+
+ API_BEGIN;
+
+ mhdf_setOkay( status );
+ result = alloc_file_desc( status );
+ if (NULL == result) return NULL;
+
+ /* get node info */
+ table_id = mhdf_openNodeCoords( file_handle,
+ &result->nodes.count,
+ &result->nodes.vals_per_ent,
+ &result->nodes.start_id,
+ status );
+ if (table_id < 0) {
+ free( result );
+ return NULL;
+ }
+ mhdf_closeData( file_handle, table_id, status );
+
+
+ /* get set info */
+ result->sets.vals_per_ent = -1;
+ table_id = mhdf_openSetMeta( file_handle,
+ &result->sets.count,
+ &result->sets.start_id,
+ status );
+ if (table_id < 0) {
+ free( result );
+ return NULL;
+ }
+ mhdf_closeData( file_handle, table_id, status );
+
+
+ /* get element list */
+ elem_handles = mhdf_getElemHandles( file_handle,
+ &result->num_elem_desc,
+ status );
+ if (elem_handles == NULL) {
+ free( result );
+ return NULL;
+ }
+
+ /* allocate array of element descriptors */
+ size = result->num_elem_desc * sizeof(struct mhdf_ElemDesc);
+ ptr = realloc_data( &result, size, status );
+ if (NULL == ptr) {
+ free( elem_handles );
+ return NULL;
+ }
+ memset( ptr, 0, size );
+ result->elems = ptr;
+
+ /* Initialize each element descriptor */
+ for (i = 0; i < result->num_elem_desc; ++i) {
+ result = get_elem_desc( file_handle, result, elem_handles[i], i, status );
+ if (NULL == result) {
+ free( elem_handles );
+ return NULL;
+ }
+ }
+
+ /* get tag list */
+ tag_names = mhdf_getTagNames( file_handle, &result->num_tag_desc, status );
+ if (tag_names == NULL) {
+ free( elem_handles );
+ free( result );
+ return NULL;
+ }
+
+ /* allocate array of tag descriptors */
+ size = result->num_tag_desc * sizeof(struct mhdf_TagDesc);
+ ptr = realloc_data( &result, size, status );
+ if (NULL == ptr) {
+ free( elem_handles );
+ free( tag_names );
+ return NULL;
+ }
+ memset( ptr, 0, size );
+ result->tags = ptr;
+
+ /* Initialize each tag descriptor */
+ for (i = 0; i < result->num_tag_desc; ++i) {
+ result = get_tag_desc( file_handle, result, tag_names[i], i, file_id_type, status );
+ if (NULL == result) {
+ free( elem_handles );
+ free( tag_names );
+ return NULL;
+ }
+ }
+
+ /* Determine which dense tags are present */
+
+ size = (2 + result->num_elem_desc) * result->num_tag_desc;
+ array = mhdf_malloc( size, status );
+ if (NULL == array) {
+ free( elem_handles );
+ free( tag_names );
+ free( result );
+ return NULL;
+ }
+ memset( array, 0, size );
+ matrix = array + (2 * result->num_tag_desc);
+
+ for (j = 0; j < result->num_tag_desc; ++j) {
+ if (mhdf_haveDenseTag( file_handle, tag_names[j], mhdf_node_type_handle(), status ))
+ matrix[-1*result->num_tag_desc+j] = 1;
+ if (mhdf_haveDenseTag( file_handle, tag_names[j], mhdf_set_type_handle(), status ))
+ matrix[-2*result->num_tag_desc+j] = 1;
+ for (i = 0; i < result->num_elem_desc; ++i)
+ if (mhdf_haveDenseTag( file_handle, tag_names[j], elem_handles[i], status ))
+ matrix[i*result->num_tag_desc+j] = 1;
+ }
+ free( elem_handles );
+ free( tag_names );
+
+ /* Populate dense tag lists for element types */
+ for (i = -2; i < result->num_elem_desc; ++i) {
+ size = 0;
+ for (j = 0; j < result->num_tag_desc; ++j)
+ size += matrix[i*result->num_tag_desc+j];
+ if (!size) {
+ indices = NULL;
+ }
+ else {
+ indices = realloc_data( &result, size*sizeof(int), status );
+ if (NULL == indices) {
+ free( array );
+ return NULL;
+ }
+
+ k = 0;
+ for (j = 0; j < result->num_tag_desc; ++j)
+ if (matrix[i*result->num_tag_desc+j])
+ indices[k++] = j;
+ assert( k == size );
+ }
+
+ if (i == -2) {
+ result->sets.dense_tag_indices = indices;
+ result->sets.num_dense_tags = size;
+ }
+ else if (i == -1) {
+ result->nodes.dense_tag_indices = indices;
+ result->nodes.num_dense_tags = size;
+ }
+ else {
+ result->elems[i].desc.dense_tag_indices = indices;
+ result->elems[i].desc.num_dense_tags = size;
+ }
+ }
+
+ /* Populate dense tag lists for each tag */
+ for (j = 0; j < result->num_tag_desc; ++j) {
+ size = 0;
+ for (i = -2; i < result->num_elem_desc; ++i)
+ size += matrix[i*result->num_tag_desc+j];
+ if (!size) {
+ indices = 0;
+ }
+ else {
+ indices = realloc_data( &result, size*sizeof(int), status );
+ if (NULL == ptr) {
+ free( array );
+ return NULL;
+ }
+
+ k = 0;
+ for (i = -2; i < result->num_elem_desc; ++i)
+ if (matrix[i*result->num_tag_desc+j])
+ indices[k++] = i;
+ assert( k == size );
+ }
+
+ result->tags[i].num_dense_indices = size;
+ result->tags[i].dense_elem_indices = indices;
+ }
+
+ /* Compact memory and return */
+ free( array );
+ result->total_size = result->offset - (unsigned char*)result;
+
+ API_END;
+ return result;
+}
+
+
+
+
+
Added: MOAB/trunk/mhdf/src/file-desc.h
===================================================================
--- MOAB/trunk/mhdf/src/file-desc.h (rev 0)
+++ MOAB/trunk/mhdf/src/file-desc.h 2009-04-02 18:45:32 UTC (rev 2795)
@@ -0,0 +1,479 @@
+#include "mhdf.h"
+#include "util.h"
+#include "status.h"
+#include <assert.h>
+#include <stdlib.h>
+#include <string.h>
+
+static struct mhdf_FileDesc* alloc_file_desc( mhdf_Status* status );
+static void* realloc_data( struct mhdf_FileDesc** data, size_t append_bytes, mhdf_Status* status );
+static char buffer[512];
+
+static struct mhdf_FileDesc* alloc_file_desc( mhdf_Status* status )
+{
+ struct mhdf_FileDesc* result;
+ /* allocate a little short of a page */
+ result = (struct mhdf_FileDesc*)mhdf_malloc(4000, status);
+ if (mhdf_isError( status ))
+ return 0;
+
+ memset( result, 0, sizeof(struct mhdf_FileDesc) );
+ result->total_size = 4000;
+ offset = ((char*)result) + sizeof(struct mhdf_FileDesc);
+ return result;
+}
+
+static void* realloc_data( struct mhdf_FileDesc** data, size_t append_bytes, mhdf_Status* status )
+{
+ void* result_ptr;
+ struct mhdf_FileDesc* const input_ptr = *data;
+ unsigned char* const mem_ptr = (unsigned char*)input_ptr;
+ unsigned char* new_mem_ptr;
+ size_t new_size;
+
+ if (mem_ptr + total_size < input_ptr->offset + append_bytes) {
+ if (append_bytes < inputptr->total_size)
+ new_size = 2 * input_ptr->total_size;
+ else
+ new_size = input_ptr->total_size + append_bytes;
+ *data = (struct mhdf_FileDesc*)mhdf_realloc( *data, new_size, status );
+ if (mhdf_isError( status ))
+ return 0;
+
+ if (*data != input_ptr)
+ mhdf_fixFileDesc( *data, input_ptr );
+ }
+
+ result_ptr = input_ptr->offset;
+ input_ptr->offset += append_bytes;
+ return result_ptr;
+}
+
+#define FIX_OFFSET( TYPE, FIELD ) \
+ copy_ptr->(FIELD) = (TYPE)( ((char*)(copy_ptr->(FIELD)) - (char*)orig_addr) + (char*)copy_ptr )
+
+
+void
+mhdf_fixFileDesc( struct FileDesc* copy_ptr, const struct FileDesc* orig_addr )
+{
+ int i;
+
+ API_BEGIN;
+ FIX_OFFSET( const struct mhdf_ElemDesc*, elems );
+ FIX_OFFSET( const struct mhdf_TagDesc*, tags );
+
+ for (i = 0; i < copy_ptr->num_elem_desc; ++i) {
+ FIX_OFFSET( const char*, elems[i].handle );
+ FIX_OFFSET( const char*, elems[i].type );
+ FIX_OFFSET( const int*, elems[i].dense_tag_indices );
+ }
+
+ for (i = 0; i < copy_ptr->num_tag_desc; ++i) {
+ FIX_OFFSET( const char*, tags[i].name );
+ FIX_OFFSET( void*, tags[i].default_value );
+ FIX_OFFSET( void*, tags[i].global_value );
+ FIX_OFFSET( const int*, tags[i].dense_elem_indices );
+ }
+ API_END;
+}
+
+static
+struct mhdf_FileDesc*
+get_elem_desc( mhdf_FileHandle file_handle,
+ struct mhdf_FileDesc* result,
+ const char* elem_handle,
+ int index,
+ mhdf_Status* status )
+{
+ hid_t id_pair[2];
+ int poly;
+ void* ptr;
+ long junk;
+
+ ptr = realloc_data( &result, strlen(elem_handle)+1, status );
+ if (!ptr) return NULL;
+ strcpy( ptr, elem_handle );
+ result->elems[index]->handle = ptr;
+
+ mhdf_getElemTypeName( file_handle, elem_handle,
+ buffer, sizeof(buffer), status );
+ if (mhdf_isError(status)) {
+ free( result );
+ return NULL;
+ }
+
+ ptr = realloc_data( &result, strlen(buffer)+1, status );
+ if (!ptr) return NULL;
+ strcpy( ptr, buffer );
+ result->elems[index]->type = ptr;
+
+ poly = mhdf_isPolyElement( file_handle, elem_handle, status );
+ if (mhdf_isError(status)) {
+ free( result );
+ return NULL;
+ }
+
+ if (!poly) {
+ id_pair[0] = mhdf_OpenConnectivity( file_handle,
+ elem_handle,
+ &result->elems[index].conn_len,
+ &result->elems[index].count,
+ &result->elems[index].start_id,
+ status );
+ if (id_pair[0] < 0) {
+ free( result );
+ return NULL;
+ }
+ mhdf_closeData( file_handle, id_pair[0], status );
+ }
+ else {
+ result->elems[index].conn_len = -1;
+ mhdf_openPolyConnectivity( file_handle,
+ elem_handle,
+ &result->elems[index].count,
+ &junk,
+ &result->elems[index].start_id,
+ id_pair[2],
+ status );
+ if (id_pair[0] < 0) {
+ free( result );
+ return NULL;
+ }
+ mhdf_closeData( file_handle, id_pair[0], status );
+ mhdf_closeData( file_handle, id_pair[1], status );
+ }
+
+ result->elems[index].dense_tag_indices = NULL;
+ result->elems[index].num_dense_indices = 0;
+ return result;
+}
+
+static
+unsigned get_file_id_size( hid_t file_id_type, mhdf_Status* status )
+{
+ if (H5Tget_class( file_id_type ) != H5T_INTEGER) {
+ mhdf_setFail( status, "Invalid handle or type class for file ID type." );
+ return 0;
+ }
+
+ return H5Tget_size( file_id_type );
+}
+
+static
+struct mhdf_FileDesc*
+get_tag_desc( mhdf_FileHandle file_handle,
+ struct mhdf_FileDesc* result,
+ const char* name,
+ int index,
+ hid_t type,
+ mhdf_Status* status )
+{
+ void* ptr;
+ int have_default, have_global, have_sparse;
+ int valsize;
+
+ ptr = realloc_data( &result, strlen(name)+1, status );
+ if (NULL == ptr) return NULL;
+ strcpy( ptr, name );
+ result->tags[index]->name = ptr;
+
+ mhdf_getTagInfo( file_handle,
+ name,
+ &result->tags[index].type,
+ &result->tags[index].size,
+ &result->tags[index].storage,
+ &have_default,
+ &have_global,
+ &result->tags[index].have_sparse,
+ status );
+ if (mhdf_isError(status)) {
+ free( result );
+ return NULL;
+ }
+
+ /* For variable lengt tags, have_default and have_global will
+ contain the size of the respective values. For fixed-length
+ tags, they are either zero or one. Simplify later code by
+ making them contain the size for both cases. */
+ valsize = tags[index].size;
+ if (result->tags[index].size >= 0) {
+ if (have_default)
+ have_default = valsize;
+ if (have_global)
+ have_global = valsize;
+ }
+
+ result->tags[index].default_value = NULL;
+ result->tags[index].default_value_size = have_default;
+ result->tags[index].global_value = NULL;
+ result->tags[index].global_value_size = have_global;
+
+ switch (result->tags[index].type) {
+ case mhdf_OPAQUE:
+ type = 0;
+ break;
+ case mhdf_BOOLEAN:
+ type = H5T_UNSIGNED_CHAR;
+ break;
+ case mhdf_INTEGER:
+ type = H5T_INTEGER;
+ have_default *= sizeof(int);
+ have_global *= sizeof(int);
+ valsize *= sizeof(int);
+ break;
+ case mhdf_FLOAT:
+ type = H5T_DOUBLE;
+ have_default *= sizeof(double);
+ have_global *= sizeof(double);
+ valsize *= sizeof(double);
+ break;
+ case mhdf_BITFIELD:
+ have_default = (have_default+7)/8;
+ have_global = (have_global+7)/8;
+ valsize = (valsize+7)/8;
+ if (size <= 8)
+ hdf_type = H5Tcopy( H5T_NATIVE_B8 );
+ else if (size <= 16)
+ hdf_type = H5Tcopy( H5T_NATIVE_B16 );
+ else if (size <= 32)
+ hdf_type = H5Tcopy( H5T_NATIVE_B32 );
+ else if (size <= 64)
+ hdf_type = H5Tcopy( H5T_NATIVE_B64 );
+ else
+ {
+ free( result );
+ mhdf_setFail( status, "Cannot create a bit tag larger than 64-bits. %d bits requested.\n", (int)size);
+ return NULL;
+ }
+ break;
+ case mhdf_ENTITY_ID:
+ if (0 == type)
+ type = H5T_NATIVE_ULONG;
+ size = get_file_id_size( type, status );
+ if (!size) {
+ free( result );
+ return NULL;
+ }
+ have_default *= size;
+ have_global *= size;
+ valsize *= size;
+ break;
+ default:
+ mhdf_setFail( status, "Unknown mhdf_TagDataType value (%d) for tag (\"%s\")",
+ (int)result->tags[index].type, name );
+ free( result );
+ return NULL;
+ }
+ result->tags[index].bytes = valsize;
+
+ if (have_default || have_global) {
+ if (have_default) {
+ ptr = realloc_data( &result, have_default, status );
+ if (NULL == ptr) {
+ if (result->tags[index].type == mhdf_BITFIELD)
+ H5Tclose( type );
+ return NULL;
+ }
+ result->tags[index].default_value = ptr;
+ }
+ if (have_global) {
+ ptr = realloc_data( &result, have_global, status );
+ if (NULL == ptr) {
+ if (result->tags[index].type == mhdf_BITFIELD)
+ H5Tclose( type );
+ return NULL;
+ }
+ result->tags[index].global_value = ptr;
+ }
+ mhdf_getTagValues( file_handle,
+ name,
+ type,
+ result->tags[index].default_value,
+ result->tags[index].global_value,
+ status );
+ if (result->tags[index].type == mhdf_BITFIELD)
+ H5Tclose( type );
+ if (mhdf_isError(status)) {
+ free( result );
+ return NULL;
+ }
+ }
+
+ return result;
+}
+
+struct mhdf_FileDesc*
+mhdf_getFileSummary( mhdf_FileHandle file_handle,
+ hid_t file_id_type,
+ mhdf_Status* status )
+{
+ struct mhdf_FileDesc* result;
+ hid_t table_id;
+ int i, j, k, size;
+ void* ptr;
+ char **elem_handles = 0, **tag_names = 0;
+ unsigned char* array;
+
+ API_BEGIN;
+
+ mhdf_setOkay( status );
+ result = alloc_file_desc( status );
+ if (NULL == result) return NULL;
+
+ /* get node info */
+ table_id = mhdf_openNodeCoords( file_handle,
+ &result->node_count,
+ &result->node_dim,
+ &result->node_start_id,
+ status );
+ if (table_id < 0) {
+ free( result );
+ return NULL;
+ }
+ mhdf_closeData( file_handle, table_id, status );
+
+
+ /* get set info */
+ table_id = mhdf_openSetMeta( file_handle,
+ &result->set_count,
+ &result->node_count,
+ &status );
+ if (table_id < 0) {
+ free( result );
+ return NULL;
+ }
+ mhdf_closeData( file_handle, table_id, status );
+
+
+ /* get element list */
+ elem_handles = mhdf_getElemHandles( file_handle,
+ &result->num_elem_desc,
+ status );
+ if (elem_handles == NULL) {
+ free( result );
+ return NULL;
+ }
+
+ /* allocate array of element descriptors */
+ size = result->num_elem_desc * sizeof(struct mhdf_ElemDesc);
+ ptr = realloc_data( &result, size, status );
+ if (NULL == ptr) {
+ free( elem_handles );
+ return NULL;
+ }
+ memset( ptr, 0, size );
+ result->elems = ptr;
+
+ /* Initialize each element descriptor */
+ for (i = 0; i < result->num_elem_desc; ++i) {
+ result = get_elem_desc( file_handle, result, elem_handles[i], i, status );
+ if (NULL == result) {
+ free( elem_handles );
+ return NULL;
+ }
+ }
+
+ /* get tag list */
+ tag_names = mhdf_getTagNames( file_handle, &result->num_tag_desc, status );
+ if (tag_names == NULL) {
+ free( elem_handles );
+ free( result );
+ return NULL;
+ }
+
+ /* allocate array of tag descriptors */
+ size = result->num_tag_desc * sizeof(struct mhdf_TagDesc);
+ ptr = realloc_data( &result, size, status );
+ if (NULL == ptr) {
+ free( elem_handles );
+ free( tag_names );
+ return NULL;
+ }
+ memset( ptr, 0, size );
+ result->tags = ptr;
+
+ /* Initialize each tag descriptor */
+ for (i = 0; i < result->num_tag_desc; ++i) {
+ result = get_tag_desc( file_handle, result, tag_names[i], i, file_id_type, status );
+ if (NULL == result) {
+ free( elem_handles );
+ free( tag_names );
+ return NULL;
+ }
+ }
+
+ /* Determine which dense tags are present */
+
+ size = result->num_elem_desc * result->num_tag_desc;
+ array = mhdf_malloc( size, status );
+ if (NULL == array) {
+ free( elem_handles );
+ free( tag_names );
+ free( result );
+ return NULL;
+ }
+ memset( array, 0, size );
+
+ for (i = 0; i < result->num_elem_desc; ++i)
+ for (j = 0; j < result->num_tag_desc; ++j)
+ if (mhdf_haveDenseTag( file_hanlde, tag_names[j], elem_handles[i], status ))
+ array[i*result->num_tag_desc+j] = 1;
+ free( elem_handles );
+ free( tag_names );
+
+ /* Populate dense tag lists for element types */
+ for (i = 0; i < result->num_elem_desc; ++i) {
+ size = 0;
+ for (j = 0; j < result->num_tag_desc; ++j)
+ size += array[i*result->num_tag_desc+j];
+ if (!size)
+ continue;
+
+ ptr = realloc_data( &result, size*sizeof(int), status );
+ if (NULL == ptr) {
+ free( array );
+ return NULL;
+ }
+ result->elems[i].num_dense_indices = size;
+ result->elems[i].dense_tag_indices = ptr;
+ k = 0;
+ for (j = 0; j < result->num_tag_desc; ++j)
+ if (array[i*result->num_tag_desc+j])
+ result->elems[i].dense_tag_indices[k++] = j;
+ assert( k == size );
+ }
+
+ /* Populate dense tag lists for each tag */
+ for (j = 0; j < result->num_tag_desc; ++j) {
+ size = 0;
+ for (i = 0; i < result->num_elem_desc; ++i)
+ size += array[i*result->num_tag_desc+j];
+ if (!size)
+ continue;
+
+ ptr = realloc_data( &result, size*sizeof(int), status );
+ if (NULL == ptr) {
+ free( array );
+ return NULL;
+ }
+ result->tags[i].num_dense_indices = size;
+ result->tags[i].dense_elem_indices = ptr;
+ k = 0;
+ for (i = 0; i < result->num_elem_desc; ++i)
+ if (array[i*result->num_tag_desc+j])
+ result->tags[i].dense_elem_indices[k++] = i;
+ assert( k == size );
+ }
+
+ /* Compact memory and return */
+ free( array );
+ result->total_size = offset - (unsigned char*)result;
+
+ API_END;
+ return result;
+}
+
+
+
+
+
Modified: MOAB/trunk/mhdf/src/nodes.c
===================================================================
--- MOAB/trunk/mhdf/src/nodes.c 2009-04-01 20:44:55 UTC (rev 2794)
+++ MOAB/trunk/mhdf/src/nodes.c 2009-04-02 18:45:32 UTC (rev 2795)
@@ -109,6 +109,26 @@
return table_id;
}
+hid_t
+mhdf_openNodeCoordsSimple( mhdf_FileHandle file_handle, mhdf_Status* status )
+{
+ FileHandle* file_ptr = (FileHandle*)file_handle;
+ hid_t table_id;
+ API_BEGIN;
+
+ if (!mhdf_check_valid_file( file_ptr, status ))
+ return -1;
+
+ table_id = mhdf_open_table_simple( file_ptr->hdf_handle,
+ NODE_COORD_PATH, status );
+ if (table_id < 0)
+ return -1;
+
+ file_ptr->open_handle_count++;
+ mhdf_setOkay( status );
+ API_END_H(1);
+ return table_id;
+}
void
mhdf_writeNodeCoords( hid_t table_id,
Modified: MOAB/trunk/mhdf/src/sets.c
===================================================================
--- MOAB/trunk/mhdf/src/sets.c 2009-04-01 20:44:55 UTC (rev 2794)
+++ MOAB/trunk/mhdf/src/sets.c 2009-04-02 18:45:32 UTC (rev 2795)
@@ -202,6 +202,26 @@
return table_id;
}
+hid_t
+mhdf_openSetMetaSimple( mhdf_FileHandle file, mhdf_Status* status )
+{
+ FileHandle* file_ptr = (FileHandle*)file;
+ hid_t table_id;
+ API_BEGIN;
+
+ if (!mhdf_check_valid_file( file_ptr, status ))
+ return -1;
+
+ table_id = mhdf_open_table_simple( file_ptr->hdf_handle,
+ SET_META_PATH, status );
+ if (table_id < 0)
+ return -1;
+
+ file_ptr->open_handle_count++;
+ mhdf_setOkay( status );
+ API_END_H(1);
+ return table_id;
+}
static int
mhdf_readwriteSetMeta( hid_t table_id, int read,
Modified: MOAB/trunk/mhdf/src/util.c
===================================================================
--- MOAB/trunk/mhdf/src/util.c 2009-04-01 20:44:55 UTC (rev 2794)
+++ MOAB/trunk/mhdf/src/util.c 2009-04-02 18:45:32 UTC (rev 2795)
@@ -38,6 +38,15 @@
return result;
}
+void* mhdf_realloc( void* ptr, size_t size, mhdf_Status* status )
+{
+ void* result;
+ result = realloc(ptr, size);
+ if (!result)
+ mhdf_setFail( status, "Allocation of %d bytes failed.\n", (int)size );
+ return result;
+}
+
size_t mhdf_name_to_path( const char* name, char* path, size_t path_len )
{
size_t length = 1;
@@ -681,6 +690,28 @@
return table_id;
}
+hid_t
+mhdf_open_table_simple( hid_t group_id, const char* path, mhdf_Status* status )
+{
+ hid_t table_id;
+
+#if defined(H5Dopen_vers) && H5Dopen_vers > 1
+ table_id = H5Dopen2( group_id, path, H5P_DEFAULT );
+#else
+ table_id = H5Dopen( group_id, path );
+#endif
+ if (table_id < 0)
+ {
+ mhdf_setFail( status, "HDF5 DataSet creation failed.");
+ }
+ else
+ {
+ mhdf_setOkay( status );
+ }
+
+ return table_id;
+}
+
static int qs_comp_int ( const void* ptr1, const void* ptr2 )
{
const int* left = (const int*)ptr1;
Modified: MOAB/trunk/mhdf/src/util.h
===================================================================
--- MOAB/trunk/mhdf/src/util.h 2009-04-01 20:44:55 UTC (rev 2794)
+++ MOAB/trunk/mhdf/src/util.h 2009-04-02 18:45:32 UTC (rev 2795)
@@ -27,6 +27,7 @@
void* mhdf_malloc( size_t size, mhdf_Status* status );
+void* mhdf_realloc( void* ptr, size_t size, mhdf_Status* status );
size_t mhdf_name_to_path( const char* name, char* path, size_t path_len );
@@ -130,6 +131,9 @@
long* start_id_out,
mhdf_Status* status );
+hid_t
+mhdf_open_table_simple( hid_t group, const char* path, mhdf_Status* status );
+
int
mhdf_compact_to_ranges( int* length_in_out, int* ids_in, int ordered );
More information about the moab-dev
mailing list