summaryrefslogtreecommitdiffstats
path: root/hl/src
diff options
context:
space:
mode:
Diffstat (limited to 'hl/src')
-rw-r--r--hl/src/Dependencies14
-rw-r--r--hl/src/H5HL.h25
-rw-r--r--hl/src/H5IM.c1264
-rw-r--r--hl/src/H5IM.h91
-rw-r--r--hl/src/H5LT.c2716
-rw-r--r--hl/src/H5LT.h374
-rw-r--r--hl/src/H5TA.c3689
-rw-r--r--hl/src/H5TA.h246
-rw-r--r--hl/src/Makefile.in34
9 files changed, 8453 insertions, 0 deletions
diff --git a/hl/src/Dependencies b/hl/src/Dependencies
new file mode 100644
index 0000000..2218168
--- /dev/null
+++ b/hl/src/Dependencies
@@ -0,0 +1,14 @@
+## This file is machine generated on GNU systems.
+## Only temporary changes may be made here.
+
+H5IM.lo: \
+ $(srcdir)/H5IM.c \
+ $(srcdir)/H5IM.h \
+ $(srcdir)/H5LT.h
+H5LT.lo: \
+ $(srcdir)/H5LT.c \
+ $(srcdir)/H5LT.h
+H5TB.lo: \
+ $(srcdir)/H5TB.c \
+ $(srcdir)/H5TB.h \
+ $(srcdir)/H5LT.h
diff --git a/hl/src/H5HL.h b/hl/src/H5HL.h
new file mode 100644
index 0000000..3b3d67b
--- /dev/null
+++ b/hl/src/H5HL.h
@@ -0,0 +1,25 @@
+
+/****************************************************************************
+ * NCSA HDF *
+ * Scientific Data Technologies *
+ * National Center for Supercomputing Applications *
+ * University of Illinois at Urbana-Champaign *
+ * 605 E. Springfield, Champaign IL 61820 *
+ * *
+ * For conditions of distribution and use, see the accompanying *
+ * hdf/COPYING file. *
+ * *
+ ****************************************************************************/
+
+
+#ifndef _H5HL_H
+#define _H5HL_H
+
+#include "H5LT.h"
+#include "H5IM.h"
+#include "H5TA.h"
+
+
+
+#endif
+
diff --git a/hl/src/H5IM.c b/hl/src/H5IM.c
new file mode 100644
index 0000000..a2b8172
--- /dev/null
+++ b/hl/src/H5IM.c
@@ -0,0 +1,1264 @@
+/****************************************************************************
+ * NCSA HDF *
+ * Scientific Data Technologies *
+ * National Center for Supercomputing Applications *
+ * University of Illinois at Urbana-Champaign *
+ * 605 E. Springfield, Champaign IL 61820 *
+ * *
+ * For conditions of distribution and use, see the accompanying *
+ * hdf/COPYING file. *
+ * *
+ ****************************************************************************/
+
+#include "H5IM.h"
+
+#include <string.h>
+#include <stdlib.h>
+
+
+/*-------------------------------------------------------------------------
+ * Function: H5IMmake_image_8bit
+ *
+ * Purpose: Creates and writes an image an 8 bit image
+ *
+ * Return: Success: 0, Failure: -1
+ *
+ * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
+ *
+ * Date: June 13, 2001
+ *
+ * Comments:
+ * based on HDF5 Image and Palette Specification
+ * http://hdf.ncsa.uiuc.edu/HDF5/H5Image/ImageSpec.html
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+
+herr_t H5IMmake_image_8bit( hid_t loc_id,
+ const char *dset_name,
+ hsize_t width,
+ hsize_t height,
+ const unsigned char *buffer )
+{
+ int rank = 3;
+ hsize_t dims[3];
+
+ /* Initialize the image dimensions */
+ dims[0] = height;
+ dims[1] = width;
+ dims[2] = 1;
+
+ /* Make the dataset */
+ if ( H5LTmake_dataset( loc_id, dset_name, rank, dims, H5T_NATIVE_UCHAR, buffer ) < 0 )
+ return -1;
+
+ /* Attach the CLASS attribute */
+ if ( H5LTset_attribute_string( loc_id, dset_name, "CLASS", "IMAGE" ) < 0 )
+ return -1;
+
+ /* Attach the VERSION attribute */
+ if ( H5LTset_attribute_string( loc_id, dset_name, "IMAGE_VERSION", "1.2" ) < 0 )
+ return -1;
+
+ /* Attach the IMAGE_SUBCLASS attribute */
+ if ( H5LTset_attribute_string( loc_id, dset_name, "IMAGE_SUBCLASS", "IMAGE_INDEXED" ) < 0 )
+ return -1;
+
+ return 0;
+}
+
+
+
+/*-------------------------------------------------------------------------
+ * Function: H5IMmake_image_24bit
+ *
+ * Purpose:
+ *
+ * Return: Success: 0, Failure: -1
+ *
+ * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
+ *
+ * Date: June 13, 2001
+ *
+ * Comments:
+ * based on HDF5 Image and Palette Specification
+ * http://hdf.ncsa.uiuc.edu/HDF5/H5Image/ImageSpec.html
+ *
+ * Interlace Mode Dimensions in the Dataspace
+ * INTERLACE_PIXEL [height][width][pixel components]
+ * INTERLACE_PLANE [pixel components][height][width]
+ *
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+
+herr_t H5IMmake_image_24bit( hid_t loc_id,
+ const char *dset_name,
+ hsize_t width,
+ hsize_t height,
+ const char *interlace,
+ const unsigned char *buffer )
+{
+ int rank = 3;
+ hsize_t dims[3];
+
+ /* Initialize the image dimensions */
+
+ if ( strcmp( interlace, "INTERLACE_PIXEL" ) == 0 )
+ {
+ /* Number of color planes is defined as the third dimension */
+ dims[0] = height;
+ dims[1] = width;
+ dims[2] = 3;
+ }
+ else
+ if ( strcmp( interlace, "INTERLACE_PLANE" ) == 0 )
+ {
+ /* Number of color planes is defined as the first dimension */
+ dims[0] = 3;
+ dims[1] = height;
+ dims[2] = width;
+ }
+ else return -1;
+
+ /* Make the dataset */
+ if ( H5LTmake_dataset( loc_id, dset_name, rank, dims, H5T_NATIVE_UCHAR, buffer ) < 0 )
+ return -1;
+
+ /* Attach the CLASS attribute */
+ if ( H5LTset_attribute_string( loc_id, dset_name, "CLASS", "IMAGE" ) < 0 )
+ return -1;
+
+ /* Attach the VERSION attribute */
+ if ( H5LTset_attribute_string( loc_id, dset_name, "IMAGE_VERSION", "1.2" ) < 0 )
+ return -1;
+
+ /* Attach the IMAGE_SUBCLASS attribute */
+ if ( H5LTset_attribute_string( loc_id, dset_name, "IMAGE_SUBCLASS", "IMAGE_TRUECOLOR" ) < 0 )
+ return -1;
+
+ /* Attach the INTERLACE_MODE attribute. This attributes is only for true color images */
+ if ( H5LTset_attribute_string( loc_id, dset_name, "INTERLACE_MODE", interlace ) < 0 )
+ return -1;
+
+ return 0;
+
+}
+
+
+
+/*-------------------------------------------------------------------------
+ * Function: find_palette
+ *
+ * Purpose: operator function used by H5LT_find_palette
+ *
+ * Return:
+ *
+ * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
+ *
+ * Date: May 28, 2001
+ *
+ * Comments:
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+
+static herr_t find_palette( hid_t loc_id, const char *name, void *op_data )
+{
+
+ /* Define a default zero value for return. This will cause the iterator to continue if
+ * the palette attribute is not found yet.
+ */
+
+ int ret = 0;
+
+ /* Shut compiler */
+ loc_id=loc_id;
+ op_data=op_data;
+
+ /* Define a positive value for return value if the attribute was found. This will
+ * cause the iterator to immediately return that positive value,
+ * indicating short-circuit success
+ */
+
+ if( strcmp( name, "PALETTE" ) == 0 )
+ ret = 1;
+
+
+ return ret;
+}
+
+
+/*-------------------------------------------------------------------------
+ * Function: H5IM_find_palette
+ *
+ * Purpose: Private function. Find the attribute "PALETTE" in the image dataset
+ *
+ * Return: Success: 1, Failure: 0
+ *
+ * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
+ *
+ * Date: May 11, 2001
+ *
+ * Comments:
+ * The function uses H5Aiterate with the operator function find_palette
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+
+static herr_t H5IM_find_palette( hid_t loc_id )
+{
+
+ unsigned int attr_num; /* Starting attribute to look up */
+ herr_t ret;
+
+ attr_num = 0;
+ ret = H5Aiterate( loc_id, &attr_num, find_palette, 0 );
+
+ return ret;
+}
+
+
+/*-------------------------------------------------------------------------
+ * Function: H5IMget_image_info
+ *
+ * Purpose: Gets information about an image dataset (dimensions, interlace mode
+ * and number of associated palettes).
+ *
+ * Return: Success: 0, Failure: -1
+ *
+ * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
+ *
+ * Date: July 25, 2001
+ *
+ * Comments:
+ * based on HDF5 Image and Palette Specification
+ * http://hdf.ncsa.uiuc.edu/HDF5/H5Image/ImageSpec.html
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+
+herr_t H5IMget_image_info( hid_t loc_id,
+ const char *dset_name,
+ hsize_t *width,
+ hsize_t *height,
+ hsize_t *planes,
+ char *interlace,
+ hssize_t *npals )
+{
+ hid_t did, sid;
+ hsize_t dims[3];
+ hid_t attr_id;
+ hid_t attr_type;
+ int has_attr;
+ hid_t attr_space_id;
+ hid_t attr_class;
+ int has_pal;
+
+ /*assume initially we have no palettes attached*/
+ *npals = 0;
+
+ /* Open the dataset. */
+ if ( (did = H5Dopen( loc_id, dset_name )) < 0 )
+ return -1;
+
+ /* Try to find the attribute "INTERLACE_MODE" on the >>image<< dataset */
+ has_attr = H5LT_find_attribute( did, "INTERLACE_MODE" );
+
+ /* It exists, get it */
+ if ( has_attr == 1 )
+ {
+
+ if ( (attr_id = H5Aopen_name( did, "INTERLACE_MODE" )) < 0 )
+ goto out;
+
+ if ( (attr_type = H5Aget_type( attr_id )) < 0 )
+ goto out;
+
+ if ( H5Aread( attr_id, attr_type, interlace ) < 0 )
+ goto out;
+
+ if ( H5Tclose( attr_type ) < 0 )
+ goto out;
+
+ if ( H5Aclose( attr_id ) < 0 )
+ goto out;
+ }
+
+ /* Get the dataspace handle */
+ if ( (sid = H5Dget_space( did )) < 0 )
+ goto out;
+
+ /* Get dimensions */
+ if ( H5Sget_simple_extent_dims( sid, dims, NULL) < 0 )
+ goto out;
+
+ /* Initialize the image dimensions */
+
+ if ( has_attr == 1 )
+ /* This is a 24 bit image */
+ {
+
+ if ( strcmp( interlace, "INTERLACE_PIXEL" ) == 0 )
+ {
+ /* Number of color planes is defined as the third dimension */
+ *height = dims[0];
+ *width = dims[1];
+ *planes = dims[2];
+ }
+ else
+ if ( strcmp( interlace, "INTERLACE_PLANE" ) == 0 )
+ {
+ /* Number of color planes is defined as the first dimension */
+ *planes = dims[0];
+ *height = dims[1];
+ *width = dims[2];
+ }
+ else return -1;
+ }
+ else
+ /* This is a 8 bit image */
+ {
+ *height = dims[0];
+ *width = dims[1];
+ *planes = dims[2];
+ }
+
+ /* Close */
+ if ( H5Sclose( sid ) < 0 )
+ goto out;
+
+
+ /* Get number of palettes */
+
+
+ /* Try to find the attribute "PALETTE" on the >>image<< dataset */
+ has_pal = H5IM_find_palette( did );
+
+ if ( has_pal == 1 )
+ {
+
+ if ( (attr_id = H5Aopen_name( did, "PALETTE" )) < 0 )
+ goto out;
+
+ if ( (attr_type = H5Aget_type( attr_id )) < 0 )
+ goto out;
+
+ if ( (attr_class = H5Tget_class( attr_type )) < 0 )
+ goto out;
+
+ /* Check if it is really a reference */
+
+ if ( attr_class == H5T_REFERENCE )
+ {
+
+ /* Get the reference(s) */
+
+ if ( (attr_space_id = H5Aget_space( attr_id )) < 0 )
+ goto out;
+
+ *npals = H5Sget_simple_extent_npoints( attr_space_id );
+
+ if ( H5Sclose( attr_space_id ) < 0 )
+ goto out;
+
+ } /* H5T_REFERENCE */
+
+ if ( H5Tclose( attr_type ) < 0 )
+ goto out;
+
+ /* Close the attribute. */
+ if ( H5Aclose( attr_id ) < 0 )
+ goto out;
+
+ }
+
+ /* End access to the dataset and release resources used by it. */
+ if ( H5Dclose( did ) < 0 )
+ goto out;
+
+ return 0;
+
+out:
+ H5Dclose( did );
+ return -1;
+
+}
+
+
+/*-------------------------------------------------------------------------
+ * Function: H5IMread_image
+ *
+ * Purpose: Reads image data from disk.
+ *
+ * Return: Success: 0, Failure: -1
+ *
+ * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
+ *
+ * Date: June 13, 2001
+ *
+ * Comments:
+ * based on HDF5 Image and Palette Specification
+ * http://hdf.ncsa.uiuc.edu/HDF5/H5Image/ImageSpec.html
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+
+herr_t H5IMread_image( hid_t loc_id,
+ const char *dset_name,
+ unsigned char *buffer )
+{
+ hid_t did;
+
+ /* Open the dataset. */
+ if ( (did = H5Dopen( loc_id, dset_name )) < 0 )
+ return -1;
+
+ /* Read */
+ if ( H5Dread( did, H5T_NATIVE_UCHAR, H5S_ALL, H5S_ALL, H5P_DEFAULT, buffer ) < 0 )
+ goto out;
+
+ /* End access to the dataset and release resources used by it. */
+ if ( H5Dclose( did ) )
+ return -1;
+
+ return 0;
+
+out:
+ H5Dclose( did );
+ return -1;
+
+}
+
+
+/*-------------------------------------------------------------------------
+ * Function: H5IMmake_palette
+ *
+ * Purpose: Creates and writes a palette.
+ *
+ * Return: Success: 0, Failure: -1
+ *
+ * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
+ *
+ * Date: May 01, 2001
+ *
+ * Comments:
+ * based on HDF5 Image and Palette Specification
+ * http://hdf.ncsa.uiuc.edu/HDF5/H5Image/ImageSpec.html
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+
+herr_t H5IMmake_palette( hid_t loc_id,
+ const char *pal_name,
+ const hsize_t *pal_dims,
+ const unsigned char *pal_data )
+
+{
+
+ int has_pal;
+
+ /* Check if the dataset already exists */
+ has_pal = H5LTfind_dataset( loc_id, pal_name );
+
+ /* It exists. Return */
+ if ( has_pal == 1 )
+ return 0;
+
+ /* Make the palette dataset. */
+ if ( H5LTmake_dataset( loc_id, pal_name, 2, pal_dims, H5T_NATIVE_UCHAR, pal_data ) < 0 )
+ return -1;
+
+ /* Attach the attribute "CLASS" to the >>palette<< dataset*/
+ if ( H5LTset_attribute_string( loc_id, pal_name, "CLASS", "PALETTE" ) < 0 )
+ return -1;
+
+ /* Attach the attribute "PAL_VERSION" to the >>palette<< dataset*/
+ if ( H5LTset_attribute_string( loc_id, pal_name, "PAL_VERSION", "1.2" ) < 0 )
+ return -1;
+
+ return 0;
+
+}
+
+
+/*-------------------------------------------------------------------------
+ * Function: H5IMlink_palette
+ *
+ * Purpose: This function attaches a palette to an existing image dataset
+ *
+ * Return: Success: 0, Failure: -1
+ *
+ * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
+ *
+ * Date: May 01, 2001
+ *
+ * Comments:
+ * based on HDF5 Image and Palette Specification
+ * http://hdf.ncsa.uiuc.edu/HDF5/H5Image/ImageSpec.html
+ *
+ * An image (dataset) within an HDF5 file may optionally specify an array of
+ * palettes to be viewed with. The dataset will have an attribute
+ * which contains an array of object reference pointers which refer to palettes in the file.
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+
+herr_t H5IMlink_palette( hid_t loc_id,
+ const char *image_name,
+ const char *pal_name )
+
+{
+
+ hid_t image_id;
+ hid_t attr_type;
+ hid_t attr_id;
+ hid_t attr_space_id;
+ hid_t attr_class;
+ hobj_ref_t ref; /* write a new reference */
+ hobj_ref_t *refbuf; /* buffer to read references */
+ hssize_t n_refs;
+ hsize_t dim_ref;
+ int ok_pal, has_pal;
+
+ /* Try to find the palette dataset */
+ has_pal = H5LTfind_dataset( loc_id, pal_name );
+
+ /* The image dataset may or not have the attribute "PALETTE"
+ * First we try to open to see if it is already there; if not, it is created.
+ * If it exists, the array of references is extended to hold the reference
+ * to the new palette
+ */
+
+ /* First we get the image id */
+ if ( (image_id = H5Dopen( loc_id, image_name )) < 0 )
+ return -1;
+
+ /* Try to find the attribute "PALETTE" on the >>image<< dataset */
+ ok_pal = H5LT_find_attribute( image_id, "PALETTE" );
+
+ /* It does not exist. We create the attribute and one reference */
+ if ( ok_pal == 0 )
+ {
+
+ if ( (attr_space_id = H5Screate( H5S_SCALAR )) < 0 )
+ goto out;
+
+ /* Create the attribute type for the reference */
+ if ( (attr_type = H5Tcopy( H5T_STD_REF_OBJ )) < 0 )
+ goto out;
+
+ /* Create the attribute "PALETTE" to be attached to the image*/
+ if ( (attr_id = H5Acreate( image_id, "PALETTE", attr_type, attr_space_id, H5P_DEFAULT )) < 0 )
+ goto out;
+
+ /* Create a reference. The reference is created on the local id. */
+ if ( H5Rcreate( &ref, loc_id, pal_name, H5R_OBJECT, -1 ) < 0 )
+ goto out;
+
+ /* Write the attribute with the reference */
+ if ( H5Awrite( attr_id, attr_type, &ref ) < 0 )
+ goto out;
+
+ if ( H5Sclose( attr_space_id ) < 0 )
+ goto out;
+
+ }
+
+ /* The attribute already exists, open it */
+
+ else if ( ok_pal == 1 )
+
+ {
+
+ if ( (attr_id = H5Aopen_name( image_id, "PALETTE" )) < 0 )
+ goto out;
+
+ if ( (attr_type = H5Aget_type( attr_id )) < 0 )
+ goto out;
+
+ if ( (attr_class = H5Tget_class( attr_type )) < 0 )
+ goto out;
+
+ /* Check if it is really a reference */
+
+ if ( attr_class == H5T_REFERENCE )
+ {
+
+ /* Get and save the old reference(s) */
+
+ if ( (attr_space_id = H5Aget_space( attr_id )) < 0 )
+ goto out;
+
+ n_refs = H5Sget_simple_extent_npoints( attr_space_id );
+
+ dim_ref = n_refs + 1;
+
+ refbuf = malloc( sizeof(hobj_ref_t) * (int)dim_ref );
+
+ if ( H5Aread( attr_id, attr_type, refbuf ) < 0 )
+ goto out;
+
+ if ( H5Sclose( attr_space_id ) < 0 )
+ goto out;
+
+ /* The attribute must be deleted, in order to the new one can reflect the changes*/
+ if ( H5Adelete( image_id, "PALETTE" ) < 0 )
+ goto out;
+
+ /* Create a new reference for this palette. */
+ if ( H5Rcreate( &ref, loc_id, pal_name, H5R_OBJECT, -1 ) < 0 )
+ goto out;
+
+ refbuf[n_refs] = ref;
+
+ /* Create the data space for the new references */
+ if ( (attr_space_id = H5Screate_simple( 1, &dim_ref, NULL )) < 0 )
+ goto out;
+
+ /* Create the attribute again with the changes of space */
+ if ( (attr_id = H5Acreate( image_id, "PALETTE", attr_type, attr_space_id, H5P_DEFAULT )) < 0 )
+ goto out;
+
+ /* Write the attribute with the new references */
+ if ( H5Awrite( attr_id, attr_type, refbuf ) < 0 )
+ goto out;
+
+ if ( H5Sclose( attr_space_id ) < 0 )
+ goto out;
+
+ free( refbuf );
+
+ } /* H5T_REFERENCE */
+
+ if ( H5Tclose( attr_type ) < 0 )
+ goto out;
+
+ /* Close the attribute. */
+ if ( H5Aclose( attr_id ) < 0 )
+ goto out;
+
+ }
+
+ /* Close the image dataset. */
+ if ( H5Dclose( image_id ) < 0 )
+ return -1;
+
+ return 0;
+
+out:
+ H5Dclose( image_id );
+ return -1;
+}
+
+
+
+/*-------------------------------------------------------------------------
+ * Function: H5IMunlink_palette
+ *
+ * Purpose: This function dettaches a palette from an existing image dataset
+ *
+ * Return: Success: 0, Failure: -1
+ *
+ * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
+ *
+ * Date: September 10, 2001
+ *
+ * Comments:
+ * based on HDF5 Image and Palette Specification
+ * http://hdf.ncsa.uiuc.edu/HDF5/H5Image/ImageSpec.html
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+
+herr_t H5IMunlink_palette( hid_t loc_id,
+ const char *image_name,
+ const char *pal_name )
+{
+ hid_t image_id;
+ hid_t attr_type;
+ hid_t attr_id;
+ hid_t attr_class;
+ int ok_pal, has_pal;
+
+ /* Try to find the palette dataset */
+ has_pal = H5LTfind_dataset( loc_id, pal_name );
+
+ /* It does not exist. Return */
+ if ( has_pal == 0 )
+ return -1;
+
+ /* The image dataset may or not have the attribute "PALETTE"
+ * First we try to open to see if it is already there; if not, it is created.
+ * If it exists, the array of references is extended to hold the reference
+ * to the new palette
+ */
+
+ /* First we get the image id */
+ if ( (image_id = H5Dopen( loc_id, image_name )) < 0 )
+ return -1;
+
+ /* Try to find the attribute "PALETTE" on the >>image<< dataset */
+ ok_pal = H5LT_find_attribute( image_id, "PALETTE" );
+
+ /* It does not exist. Nothing to do */
+ if ( ok_pal == 0 )
+ return -1;
+
+ /* The attribute exists, open it */
+ else if ( ok_pal == 1 )
+ {
+ if ( (attr_id = H5Aopen_name( image_id, "PALETTE" )) < 0 )
+ goto out;
+
+ if ( (attr_type = H5Aget_type( attr_id )) < 0 )
+ goto out;
+
+ if ( (attr_class = H5Tget_class( attr_type )) < 0 )
+ goto out;
+
+ /* Check if it is really a reference */
+ if ( attr_class == H5T_REFERENCE )
+ {
+
+ /* Deelete the attribute */
+ if ( H5Adelete( image_id, "PALETTE" ) < 0 )
+ goto out;
+
+ } /* H5T_REFERENCE */
+
+ if ( H5Tclose( attr_type ) < 0 )
+ goto out;
+
+ /* Close the attribute. */
+ if ( H5Aclose( attr_id ) < 0 )
+ goto out;
+
+ } /* ok_pal */
+
+ /* Close the image dataset. */
+ if ( H5Dclose( image_id ) < 0 )
+ return -1;
+
+ return 0;
+
+out:
+ H5Dclose( image_id );
+ return -1;
+}
+
+
+/*-------------------------------------------------------------------------
+ * Function: H5IMget_npalettes
+ *
+ * Purpose: Gets the number of palettes associated to an image
+ *
+ * Return: Success: 0, Failure: -1
+ *
+ * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
+ *
+ * Date: July 22, 2001
+ *
+ * Comments:
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+
+herr_t H5IMget_npalettes( hid_t loc_id,
+ const char *image_name,
+ hssize_t *npals )
+{
+ hid_t image_id;
+ hid_t attr_type;
+ hid_t attr_id;
+ hid_t attr_space_id;
+ hid_t attr_class;
+ int has_pal;
+
+ /*assume initially we have no palettes attached*/
+ *npals = 0;
+
+ /* Open the dataset. */
+ if ( (image_id = H5Dopen( loc_id, image_name )) < 0 )
+ return -1;
+
+ /* Try to find the attribute "PALETTE" on the >>image<< dataset */
+ has_pal = H5IM_find_palette( image_id );
+
+ if ( has_pal == 1 )
+ {
+
+ if ( (attr_id = H5Aopen_name( image_id, "PALETTE" )) < 0 )
+ goto out;
+
+ if ( (attr_type = H5Aget_type( attr_id )) < 0 )
+ goto out;
+
+ if ( (attr_class = H5Tget_class( attr_type )) < 0 )
+ goto out;
+
+ /* Check if it is really a reference */
+
+ if ( attr_class == H5T_REFERENCE )
+ {
+ if ( (attr_space_id = H5Aget_space( attr_id )) < 0 )
+ goto out;
+
+ *npals = H5Sget_simple_extent_npoints( attr_space_id );
+
+ if ( H5Sclose( attr_space_id ) < 0 )
+ goto out;
+
+ } /* H5T_REFERENCE */
+
+ if ( H5Tclose( attr_type ) < 0 )
+ goto out;
+
+ /* Close the attribute. */
+ if ( H5Aclose( attr_id ) < 0 )
+ goto out;
+
+ }
+
+ /* Close the image dataset. */
+ if ( H5Dclose( image_id ) < 0 )
+ return -1;
+
+ return 0;
+
+out:
+ H5Dclose( image_id );
+ return -1;
+
+}
+
+
+/*-------------------------------------------------------------------------
+ * Function: H5IMget_palette_info
+ *
+ * Purpose: Get palette information
+ *
+ * Return: Success: 0, Failure: -1
+ *
+ * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
+ *
+ * Date: July 22, 2001
+ *
+ * Comments:
+ * based on HDF5 Image and Palette Specification
+ * http://hdf.ncsa.uiuc.edu/HDF5/H5Image/ImageSpec.html
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+
+herr_t H5IMget_palette_info( hid_t loc_id,
+ const char *image_name,
+ int pal_number,
+ hsize_t *pal_dims )
+{
+ hid_t image_id;
+ int has_pal;
+ hid_t attr_type;
+ hid_t attr_id;
+ hid_t attr_space_id;
+ hid_t attr_class;
+ hssize_t n_refs;
+ hsize_t dim_ref;
+ hobj_ref_t *refbuf; /* buffer to read references */
+ hid_t pal_id;
+ int rank;
+ hid_t pal_space_id;
+ hsize_t pal_maxdims[2];
+
+ /* Open the dataset. */
+ if ( (image_id = H5Dopen( loc_id, image_name )) < 0 )
+ return -1;
+
+ /* Try to find the attribute "PALETTE" on the >>image<< dataset */
+ has_pal = H5IM_find_palette( image_id );
+
+ if ( has_pal == 1 )
+ {
+
+ if ( (attr_id = H5Aopen_name( image_id, "PALETTE" )) < 0 )
+ goto out;
+
+ if ( (attr_type = H5Aget_type( attr_id )) < 0 )
+ goto out;
+
+ if ( (attr_class = H5Tget_class( attr_type )) < 0 )
+ goto out;
+
+ /* Check if it is really a reference */
+
+ if ( attr_class == H5T_REFERENCE )
+ {
+
+ /* Get the reference(s) */
+
+ if ( (attr_space_id = H5Aget_space( attr_id )) < 0 )
+ goto out;
+
+ n_refs = H5Sget_simple_extent_npoints( attr_space_id );
+
+ dim_ref = n_refs;
+
+ refbuf = malloc( sizeof(hobj_ref_t) * (int)dim_ref );
+
+ if ( H5Aread( attr_id, attr_type, refbuf ) < 0 )
+ goto out;
+
+ /* Get the actual palette */
+
+ if ( (pal_id = H5Rdereference( image_id, H5R_OBJECT, &refbuf[pal_number] )) < 0 )
+ goto out;
+
+ if ( (pal_space_id = H5Dget_space( pal_id )) < 0 )
+ goto out;
+
+ if ( (rank = H5Sget_simple_extent_ndims( pal_space_id )) < 0 )
+ goto out;
+
+ if ( H5Sget_simple_extent_dims( pal_space_id, pal_dims, pal_maxdims ) < 0 )
+ goto out;
+
+ if ( H5Sclose( pal_space_id ) < 0 )
+ goto out;
+
+ if ( H5Sclose( attr_space_id ) < 0 )
+ goto out;
+
+ free( refbuf );
+
+ } /* H5T_REFERENCE */
+
+ if ( H5Tclose( attr_type ) < 0 )
+ goto out;
+
+ /* Close the attribute. */
+ if ( H5Aclose( attr_id ) < 0 )
+ goto out;
+
+ }
+
+ /* Close the image dataset. */
+ if ( H5Dclose( image_id ) < 0 )
+ return -1;
+
+ return 0;
+
+out:
+ H5Dclose( image_id );
+ return -1;
+
+}
+
+
+/*-------------------------------------------------------------------------
+ * Function: H5IMget_palette
+ *
+ * Purpose: Read palette
+ *
+ * Return: Success: 0, Failure: -1
+ *
+ * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
+ *
+ * Date: August 30, 2001
+ *
+ * Comments:
+ * based on HDF5 Image and Palette Specification
+ * http://hdf.ncsa.uiuc.edu/HDF5/H5Image/ImageSpec.html
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+
+herr_t H5IMget_palette( hid_t loc_id,
+ const char *image_name,
+ int pal_number,
+ unsigned char *pal_data )
+{
+ hid_t image_id;
+ int has_pal;
+ hid_t attr_type;
+ hid_t attr_id;
+ hid_t attr_space_id;
+ hid_t attr_class;
+ hssize_t n_refs;
+ hsize_t dim_ref;
+ hobj_ref_t *refbuf; /* buffer to read references */
+ hid_t pal_id;
+
+ /* Open the dataset. */
+ if ( (image_id = H5Dopen( loc_id, image_name )) < 0 )
+ return -1;
+
+ /* Try to find the attribute "PALETTE" on the >>image<< dataset */
+ has_pal = H5IM_find_palette( image_id );
+
+ if ( has_pal == 1 )
+ {
+
+ if ( (attr_id = H5Aopen_name( image_id, "PALETTE" )) < 0 )
+ goto out;
+
+ if ( (attr_type = H5Aget_type( attr_id )) < 0 )
+ goto out;
+
+ if ( (attr_class = H5Tget_class( attr_type )) < 0 )
+ goto out;
+
+ /* Check if it is really a reference */
+
+ if ( attr_class == H5T_REFERENCE )
+ {
+
+ /* Get the reference(s) */
+
+ if ( (attr_space_id = H5Aget_space( attr_id )) < 0 )
+ goto out;
+
+ n_refs = H5Sget_simple_extent_npoints( attr_space_id );
+
+ dim_ref = n_refs;
+
+ refbuf = malloc( sizeof(hobj_ref_t) * (int)dim_ref );
+
+ if ( H5Aread( attr_id, attr_type, refbuf ) < 0 )
+ goto out;
+
+ /* Get the palette id */
+ if ( (pal_id = H5Rdereference( image_id, H5R_OBJECT, &refbuf[pal_number] )) < 0 )
+ goto out;
+
+ /* Read the palette dataset */
+ if ( H5Dread( pal_id, H5Dget_type(pal_id), H5S_ALL, H5S_ALL, H5P_DEFAULT, pal_data ) < 0 )
+ goto out;
+
+ if ( H5Sclose( attr_space_id ) < 0 )
+ goto out;
+
+ free( refbuf );
+
+ } /* H5T_REFERENCE */
+
+ if ( H5Tclose( attr_type ) < 0 )
+ goto out;
+
+ /* Close the attribute. */
+ if ( H5Aclose( attr_id ) < 0 )
+ goto out;
+
+ }
+
+
+ /* Close the image dataset. */
+ if ( H5Dclose( image_id ) < 0 )
+ return -1;
+
+ return 0;
+
+out:
+ H5Dclose( image_id );
+ return -1;
+
+}
+
+/*-------------------------------------------------------------------------
+ * Function: H5IMis_image
+ *
+ * Purpose:
+ *
+ * Return: true, false, fail
+ *
+ * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
+ *
+ * Date: August 30, 2001
+ *
+ * Comments:
+ * based on HDF5 Image and Palette Specification
+ * http://hdf.ncsa.uiuc.edu/HDF5/H5Image/ImageSpec.html
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+
+herr_t H5IMis_image( hid_t loc_id,
+ const char *dset_name )
+{
+ hid_t did;
+ int has_class;
+ hid_t attr_type;
+ hid_t attr_id;
+ hid_t attr_class;
+ char attr_data[20];
+ herr_t ret;
+
+ /* Assume initially fail condition */
+ ret = -1;
+
+ /* Open the dataset. */
+ if ( (did = H5Dopen( loc_id, dset_name )) < 0 )
+ return -1;
+
+ /* Try to find the attribute "CLASS" on the dataset */
+ has_class = H5LT_find_attribute( did, "CLASS" );
+
+ if ( has_class == 0 )
+ {
+ H5Dclose( did );
+ return 0;
+ }
+
+ else if ( has_class == 1 )
+ {
+
+ if ( (attr_id = H5Aopen_name( did, "CLASS" )) < 0 )
+ goto out;
+
+ if ( (attr_type = H5Aget_type( attr_id )) < 0 )
+ goto out;
+
+ if ( (attr_class = H5Tget_class( attr_type )) < 0 )
+ goto out;
+
+ if ( H5Aread( attr_id, attr_type, attr_data ) < 0 )
+ goto out;
+
+ if( strcmp( attr_data, "IMAGE" ) == 0 )
+ ret = 1;
+ else
+ ret = 0;
+
+ if ( H5Tclose( attr_type ) < 0 )
+ goto out;
+
+ if ( H5Aclose( attr_id ) < 0 )
+ goto out;
+
+ }
+
+ /* Close the dataset. */
+ if ( H5Dclose( did ) < 0 )
+ return -1;
+
+ return ret;
+
+out:
+ H5Dclose( did );
+ return -1;
+
+}
+
+
+
+/*-------------------------------------------------------------------------
+ * Function: H5IMis_palette
+ *
+ * Purpose:
+ *
+ * Return: true, false, fail
+ *
+ * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
+ *
+ * Date: August 30, 2001
+ *
+ * Comments:
+ * based on HDF5 Image and Palette Specification
+ * http://hdf.ncsa.uiuc.edu/HDF5/H5Image/ImageSpec.html
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+
+herr_t H5IMis_palette( hid_t loc_id,
+ const char *dset_name )
+{
+ hid_t did;
+ int has_class;
+ hid_t attr_type;
+ hid_t attr_id;
+ hid_t attr_class;
+ char attr_data[20];
+ herr_t ret;
+
+ /* Assume initially fail condition */
+ ret = -1;
+
+ /* Open the dataset. */
+ if ( (did = H5Dopen( loc_id, dset_name )) < 0 )
+ return -1;
+
+ /* Try to find the attribute "CLASS" on the dataset */
+ has_class = H5LT_find_attribute( did, "CLASS" );
+
+ if ( has_class == 0 )
+ {
+ H5Dclose( did );
+ return 0;
+ }
+
+ else if ( has_class == 1 )
+ {
+
+ if ( (attr_id = H5Aopen_name( did, "CLASS" )) < 0 )
+ goto out;
+
+ if ( (attr_type = H5Aget_type( attr_id )) < 0 )
+ goto out;
+
+ if ( (attr_class = H5Tget_class( attr_type )) < 0 )
+ goto out;
+
+ if ( H5Aread( attr_id, attr_type, attr_data ) < 0 )
+ goto out;
+
+ if( strcmp( attr_data, "PALETTE" ) == 0 )
+ ret = 1;
+ else
+ ret = 0;
+
+ if ( H5Tclose( attr_type ) < 0 )
+ goto out;
+
+ if ( H5Aclose( attr_id ) < 0 )
+ goto out;
+
+ }
+
+ /* Close the dataset. */
+ if ( H5Dclose( did ) < 0 )
+ return -1;
+
+ return ret;
+
+out:
+ H5Dclose( did );
+ return -1;
+
+}
diff --git a/hl/src/H5IM.h b/hl/src/H5IM.h
new file mode 100644
index 0000000..db79222
--- /dev/null
+++ b/hl/src/H5IM.h
@@ -0,0 +1,91 @@
+
+/****************************************************************************
+ * NCSA HDF *
+ * Scientific Data Technologies *
+ * National Center for Supercomputing Applications *
+ * University of Illinois at Urbana-Champaign *
+ * 605 E. Springfield, Champaign IL 61820 *
+ * *
+ * For conditions of distribution and use, see the accompanying *
+ * hdf/COPYING file. *
+ * *
+ ****************************************************************************/
+
+
+#ifndef _H5IM_H
+#define _H5IM_H
+
+#include "H5LT.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+
+herr_t H5IMmake_image_8bit( hid_t loc_id,
+ const char *dset_name,
+ hsize_t width,
+ hsize_t height,
+ const unsigned char *buffer );
+
+herr_t H5IMmake_image_24bit( hid_t loc_id,
+ const char *dset_name,
+ hsize_t width,
+ hsize_t height,
+ const char *interlace,
+ const unsigned char *buffer );
+
+herr_t H5IMget_image_info( hid_t loc_id,
+ const char *dset_name,
+ hsize_t *width,
+ hsize_t *height,
+ hsize_t *planes,
+ char *interlace,
+ hssize_t *npals );
+
+herr_t H5IMread_image( hid_t loc_id,
+ const char *dset_name,
+ unsigned char *buffer );
+
+
+
+herr_t H5IMmake_palette( hid_t loc_id,
+ const char *pal_name,
+ const hsize_t *pal_dims,
+ const unsigned char *pal_data );
+
+herr_t H5IMlink_palette( hid_t loc_id,
+ const char *image_name,
+ const char *pal_name );
+
+herr_t H5IMunlink_palette( hid_t loc_id,
+ const char *image_name,
+ const char *pal_name );
+
+herr_t H5IMget_npalettes( hid_t loc_id,
+ const char *image_name,
+ hssize_t *npals );
+
+herr_t H5IMget_palette_info( hid_t loc_id,
+ const char *image_name,
+ int pal_number,
+ hsize_t *pal_dims );
+
+
+herr_t H5IMget_palette( hid_t loc_id,
+ const char *image_name,
+ int pal_number,
+ unsigned char *pal_data );
+
+herr_t H5IMis_image( hid_t loc_id,
+ const char *dset_name );
+
+herr_t H5IMis_palette( hid_t loc_id,
+ const char *dset_name );
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/hl/src/H5LT.c b/hl/src/H5LT.c
new file mode 100644
index 0000000..c8ac099
--- /dev/null
+++ b/hl/src/H5LT.c
@@ -0,0 +1,2716 @@
+/****************************************************************************
+ * NCSA HDF *
+ * Scientific Data Technologies *
+ * National Center for Supercomputing Applications *
+ * University of Illinois at Urbana-Champaign *
+ * 605 E. Springfield, Champaign IL 61820 *
+ * *
+ * For conditions of distribution and use, see the accompanying *
+ * hdf/COPYING file. *
+ * *
+ ****************************************************************************/
+
+#include "H5LT.h"
+#include <string.h>
+#include <stdlib.h>
+
+/*-------------------------------------------------------------------------
+ *
+ * Private functions
+ *
+ *-------------------------------------------------------------------------
+ */
+
+herr_t H5LT_open_id( hid_t loc_id,
+ const char *obj_name,
+ int obj_type );
+
+herr_t H5LT_close_id( hid_t obj_id,
+ int obj_type );
+
+/*-------------------------------------------------------------------------
+ *
+ * Public functions
+ *
+ *-------------------------------------------------------------------------
+ */
+
+/*-------------------------------------------------------------------------
+ * Function: H5LTmake_dataset
+ *
+ * Purpose: Creates and writes a dataset of a type tid
+ *
+ * Return: Success: 0, Failure: -1
+ *
+ * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
+ *
+ * Date: March 19, 2001
+ *
+ * Comments:
+ *
+ * Modifications:
+ *
+ *
+ *-------------------------------------------------------------------------
+ */
+
+herr_t H5LTmake_dataset( hid_t loc_id,
+ const char *dset_name,
+ int rank,
+ const hsize_t *dims,
+ hid_t tid,
+ const void *data )
+{
+
+ hid_t did, sid;
+
+ /* Create the data space for the dataset. */
+ if ( (sid = H5Screate_simple( rank, dims, NULL )) < 0 )
+ return -1;
+
+ /* Create the dataset. */
+ if ( (did = H5Dcreate( loc_id, dset_name, tid, sid, H5P_DEFAULT )) < 0 )
+ goto out;
+
+ /* Write the dataset only if there is data to write */
+
+ if ( data )
+ {
+ if ( H5Dwrite( did, tid, H5S_ALL, H5S_ALL, H5P_DEFAULT, data ) < 0 )
+ goto out;
+ }
+
+ /* End access to the dataset and release resources used by it. */
+ if ( H5Dclose( did ) < 0 )
+ return -1;
+
+ /* Terminate access to the data space. */
+ if ( H5Sclose( sid ) < 0 )
+ return -1;
+
+ return 0;
+
+out:
+ H5Dclose( did );
+ H5Sclose( sid );
+ return -1;
+}
+
+/*-------------------------------------------------------------------------
+ * Function: H5LTmake_dataset_char
+ *
+ * Purpose: Creates and writes a dataset of H5T_NATIVE_CHAR type
+ *
+ * Return: Success: 0, Failure: -1
+ *
+ * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
+ *
+ * Date: September 14, 2001
+ *
+ * Comments:
+ *
+ * Modifications:
+ *
+ *
+ *-------------------------------------------------------------------------
+ */
+
+herr_t H5LTmake_dataset_char( hid_t loc_id,
+ const char *dset_name,
+ int rank,
+ const hsize_t *dims,
+ const char *data )
+{
+
+ hid_t did, sid;
+
+ /* Create the data space for the dataset. */
+ if ( (sid = H5Screate_simple( rank, dims, NULL )) < 0 )
+ return -1;
+
+ /* Create the dataset. */
+ if ( (did = H5Dcreate( loc_id, dset_name, H5T_NATIVE_CHAR, sid, H5P_DEFAULT )) < 0 )
+ goto out;
+
+ /* Write the dataset only if there is data to write */
+
+ if ( data )
+ {
+ if ( H5Dwrite( did, H5T_NATIVE_CHAR, H5S_ALL, H5S_ALL, H5P_DEFAULT, data ) < 0 )
+ goto out;
+ }
+
+ /* End access to the dataset and release resources used by it. */
+ if ( H5Dclose( did ) < 0 )
+ return -1;
+
+ /* Terminate access to the data space. */
+ if ( H5Sclose( sid ) < 0 )
+ return -1;
+
+ return 0;
+
+out:
+ H5Dclose( did );
+ H5Sclose( sid );
+ return -1;
+}
+
+
+/*-------------------------------------------------------------------------
+ * Function: H5LTmake_dataset_short
+ *
+ * Purpose: Creates and writes a dataset of H5T_NATIVE_SHORT type
+ *
+ * Return: Success: 0, Failure: -1
+ *
+ * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
+ *
+ * Date: September 14, 2001
+ *
+ * Comments:
+ *
+ * Modifications:
+ *
+ *
+ *-------------------------------------------------------------------------
+ */
+
+
+herr_t H5LTmake_dataset_short( hid_t loc_id,
+ const char *dset_name,
+ int rank,
+ const hsize_t *dims,
+ const short *data )
+{
+
+ hid_t did, sid;
+
+ /* Create the data space for the dataset. */
+ if ( (sid = H5Screate_simple( rank, dims, NULL )) < 0 )
+ return -1;
+
+ /* Create the dataset. */
+ if ( (did = H5Dcreate( loc_id, dset_name, H5T_NATIVE_SHORT, sid, H5P_DEFAULT )) < 0 )
+ goto out;
+
+ /* Write the dataset only if there is data to write */
+
+ if ( data )
+ {
+ if ( H5Dwrite( did, H5T_NATIVE_SHORT, H5S_ALL, H5S_ALL, H5P_DEFAULT, data ) < 0 )
+ goto out;
+ }
+
+ /* End access to the dataset and release resources used by it. */
+ if ( H5Dclose( did ) < 0 )
+ return -1;
+
+ /* Terminate access to the data space. */
+ if ( H5Sclose( sid ) < 0 )
+ return -1;
+
+ return 0;
+
+out:
+ H5Dclose( did );
+ H5Sclose( sid );
+ return -1;
+}
+
+/*-------------------------------------------------------------------------
+ * Function: H5LTmake_dataset_int
+ *
+ * Purpose: Creates and writes a dataset of H5T_NATIVE_INT type
+ *
+ * Return: Success: 0, Failure: -1
+ *
+ * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
+ *
+ * Date: September 14, 2001
+ *
+ * Comments:
+ *
+ * Modifications:
+ *
+ *
+ *-------------------------------------------------------------------------
+ */
+
+
+herr_t H5LTmake_dataset_int( hid_t loc_id,
+ const char *dset_name,
+ int rank,
+ const hsize_t *dims,
+ const int *data )
+{
+
+ hid_t did, sid;
+
+ /* Create the data space for the dataset. */
+ if ( (sid = H5Screate_simple( rank, dims, NULL )) < 0 )
+ return -1;
+
+ /* Create the dataset. */
+ if ( (did = H5Dcreate( loc_id, dset_name, H5T_NATIVE_INT, sid, H5P_DEFAULT )) < 0 )
+ goto out;
+
+ /* Write the dataset only if there is data to write */
+
+ if ( data )
+ {
+ if ( H5Dwrite( did, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, data ) < 0 )
+ goto out;
+ }
+
+ /* End access to the dataset and release resources used by it. */
+ if ( H5Dclose( did ) < 0 )
+ return -1;
+
+ /* Terminate access to the data space. */
+ if ( H5Sclose( sid ) < 0 )
+ return -1;
+
+ return 0;
+
+out:
+ H5Dclose( did );
+ H5Sclose( sid );
+ return -1;
+}
+
+
+
+/*-------------------------------------------------------------------------
+ * Function: H5LTmake_dataset_long
+ *
+ * Purpose: Creates and writes a dataset of H5T_NATIVE_LONG type
+ *
+ * Return: Success: 0, Failure: -1
+ *
+ * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
+ *
+ * Date: September 14, 2001
+ *
+ * Comments:
+ *
+ * Modifications:
+ *
+ *
+ *-------------------------------------------------------------------------
+ */
+
+
+herr_t H5LTmake_dataset_long( hid_t loc_id,
+ const char *dset_name,
+ int rank,
+ const hsize_t *dims,
+ const long *data )
+{
+
+ hid_t did, sid;
+
+ /* Create the data space for the dataset. */
+ if ( (sid = H5Screate_simple( rank, dims, NULL )) < 0 )
+ return -1;
+
+ /* Create the dataset. */
+ if ( (did = H5Dcreate( loc_id, dset_name, H5T_NATIVE_LONG, sid, H5P_DEFAULT )) < 0 )
+ goto out;
+
+ /* Write the dataset only if there is data to write */
+
+ if ( data )
+ {
+ if ( H5Dwrite( did, H5T_NATIVE_LONG, H5S_ALL, H5S_ALL, H5P_DEFAULT, data ) < 0 )
+ goto out;
+ }
+
+ /* End access to the dataset and release resources used by it. */
+ if ( H5Dclose( did ) < 0 )
+ return -1;
+
+ /* Terminate access to the data space. */
+ if ( H5Sclose( sid ) < 0 )
+ return -1;
+
+ return 0;
+
+out:
+ H5Dclose( did );
+ H5Sclose( sid );
+ return -1;
+}
+
+/*-------------------------------------------------------------------------
+ * Function: H5LTmake_dataset_float
+ *
+ * Purpose: Creates and writes a dataset of H5T_NATIVE_FLOAT type
+ *
+ * Return: Success: 0, Failure: -1
+ *
+ * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
+ *
+ * Date: September 14, 2001
+ *
+ * Comments:
+ *
+ * Modifications:
+ *
+ *
+ *-------------------------------------------------------------------------
+ */
+
+
+herr_t H5LTmake_dataset_float( hid_t loc_id,
+ const char *dset_name,
+ int rank,
+ const hsize_t *dims,
+ const float *data )
+{
+
+ hid_t did, sid;
+
+ /* Create the data space for the dataset. */
+ if ( (sid = H5Screate_simple( rank, dims, NULL )) < 0 )
+ return -1;
+
+ /* Create the dataset. */
+ if ( (did = H5Dcreate( loc_id, dset_name, H5T_NATIVE_FLOAT, sid, H5P_DEFAULT )) < 0 )
+ goto out;
+
+ /* Write the dataset only if there is data to write */
+
+ if ( data )
+ {
+ if ( H5Dwrite( did, H5T_NATIVE_FLOAT, H5S_ALL, H5S_ALL, H5P_DEFAULT, data ) < 0 )
+ goto out;
+ }
+
+ /* End access to the dataset and release resources used by it. */
+ if ( H5Dclose( did ) < 0 )
+ return -1;
+
+ /* Terminate access to the data space. */
+ if ( H5Sclose( sid ) < 0 )
+ return -1;
+
+ return 0;
+
+out:
+ H5Dclose( did );
+ H5Sclose( sid );
+ return -1;
+}
+
+
+
+/*-------------------------------------------------------------------------
+ * Function: H5LTmake_dataset_double
+ *
+ * Purpose: Creates and writes a dataset of H5T_NATIVE_DOUBLE type
+ *
+ * Return: Success: 0, Failure: -1
+ *
+ * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
+ *
+ * Date: September 14, 2001
+ *
+ * Comments:
+ *
+ * Modifications:
+ *
+ *
+ *-------------------------------------------------------------------------
+ */
+
+
+herr_t H5LTmake_dataset_double( hid_t loc_id,
+ const char *dset_name,
+ int rank,
+ const hsize_t *dims,
+ const double *data )
+{
+
+ hid_t did, sid;
+
+ /* Create the data space for the dataset. */
+ if ( (sid = H5Screate_simple( rank, dims, NULL )) < 0 )
+ return -1;
+
+ /* Create the dataset. */
+ if ( (did = H5Dcreate( loc_id, dset_name, H5T_NATIVE_DOUBLE, sid, H5P_DEFAULT )) < 0 )
+ goto out;
+
+ /* Write the dataset only if there is data to write */
+
+ if ( data )
+ {
+ if ( H5Dwrite( did, H5T_NATIVE_DOUBLE, H5S_ALL, H5S_ALL, H5P_DEFAULT, data ) < 0 )
+ goto out;
+ }
+
+ /* End access to the dataset and release resources used by it. */
+ if ( H5Dclose( did ) < 0 )
+ return -1;
+
+ /* Terminate access to the data space. */
+ if ( H5Sclose( sid ) < 0 )
+ return -1;
+
+ return 0;
+
+out:
+ H5Dclose( did );
+ H5Sclose( sid );
+ return -1;
+}
+
+
+/*-------------------------------------------------------------------------
+ * Function: H5LTmake_dataset_string
+ *
+ * Purpose: Creates and writes a dataset of H5T_C_S1 type
+ *
+ * Return: Success: 0, Failure: -1
+ *
+ * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
+ *
+ * Date: October 05, 2004
+ *
+ * Comments:
+ *
+ * Modifications:
+ *
+ *
+ *-------------------------------------------------------------------------
+ */
+
+
+herr_t H5LTmake_dataset_string(hid_t loc_id,
+ const char *dset_name,
+ const char *buf )
+{
+
+ hid_t did=-1;
+ hid_t sid=-1;
+ hid_t tid;
+ size_t size;
+
+ /* create a string data type */
+ if ( (tid = H5Tcopy( H5T_C_S1 )) < 0 )
+ goto out;
+
+ size = strlen(buf) + 1; /* extra null term */
+
+ if ( H5Tset_size(tid,size) < 0 )
+ goto out;
+
+ if ( H5Tset_strpad(tid,H5T_STR_NULLTERM ) < 0 )
+ goto out;
+
+ /* Create the data space for the dataset. */
+ if ( (sid = H5Screate( H5S_SCALAR )) < 0 )
+ goto out;
+
+ /* Create the dataset. */
+ if ( (did = H5Dcreate(loc_id,dset_name,tid,sid,H5P_DEFAULT)) < 0 )
+ goto out;
+
+ /* Write the dataset only if there is data to write */
+
+ if (buf)
+ {
+ if ( H5Dwrite(did,tid,H5S_ALL,H5S_ALL,H5P_DEFAULT,buf) < 0 )
+ goto out;
+ }
+
+ /* close*/
+ if ( H5Dclose(did) < 0 )
+ return -1;
+ if ( H5Sclose(sid) < 0 )
+ return -1;
+ if ( H5Tclose(tid) < 0 )
+ goto out;
+
+ return 0;
+
+out:
+ H5Dclose(did);
+ H5Tclose(tid);
+ H5Sclose(sid);
+ return -1;
+}
+
+
+/*-------------------------------------------------------------------------
+ * Function: H5LTread_dataset
+ *
+ * Purpose: Reads a dataset from disk.
+ *
+ * Return: Success: 0, Failure: -1
+ *
+ * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
+ *
+ * Date: June 13, 2001
+ *
+ *-------------------------------------------------------------------------
+ */
+
+herr_t H5LTread_dataset( hid_t loc_id,
+ const char *dset_name,
+ hid_t tid,
+ void *data )
+{
+ hid_t did;
+
+ /* Open the dataset. */
+ if ( (did = H5Dopen( loc_id, dset_name )) < 0 )
+ return -1;
+
+ /* Read */
+ if ( H5Dread( did, tid, H5S_ALL, H5S_ALL, H5P_DEFAULT, data ) < 0 )
+ goto out;
+
+ /* End access to the dataset and release resources used by it. */
+ if ( H5Dclose( did ) )
+ return -1;
+
+ return 0;
+
+out:
+ H5Dclose( did );
+ return -1;
+
+}
+
+
+/*-------------------------------------------------------------------------
+ * Function: H5LTread_dataset_char
+ *
+ * Purpose: Reads a dataset from disk.
+ *
+ * Return: Success: 0, Failure: -1
+ *
+ * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
+ *
+ * Date: November 5, 2001
+ *
+ *-------------------------------------------------------------------------
+ */
+
+herr_t H5LTread_dataset_char( hid_t loc_id,
+ const char *dset_name,
+ char *data )
+{
+ hid_t did;
+
+ /* Open the dataset. */
+ if ( (did = H5Dopen( loc_id, dset_name )) < 0 )
+ return -1;
+
+ /* Read */
+ if ( H5Dread( did, H5T_NATIVE_CHAR, H5S_ALL, H5S_ALL, H5P_DEFAULT, data ) < 0 )
+ goto out;
+
+ /* End access to the dataset and release resources used by it. */
+ if ( H5Dclose( did ) )
+ return -1;
+
+ return 0;
+
+out:
+ H5Dclose( did );
+ return -1;
+
+}
+
+/*-------------------------------------------------------------------------
+ * Function: H5LTread_dataset_short
+ *
+ * Purpose: Reads a dataset from disk.
+ *
+ * Return: Success: 0, Failure: -1
+ *
+ * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
+ *
+ * Date: November 5, 2001
+ *
+ *-------------------------------------------------------------------------
+ */
+
+herr_t H5LTread_dataset_short( hid_t loc_id,
+ const char *dset_name,
+ short *data )
+{
+ hid_t did;
+
+ /* Open the dataset. */
+ if ( (did = H5Dopen( loc_id, dset_name )) < 0 )
+ return -1;
+
+ /* Read */
+ if ( H5Dread( did, H5T_NATIVE_SHORT, H5S_ALL, H5S_ALL, H5P_DEFAULT, data ) < 0 )
+ goto out;
+
+ /* End access to the dataset and release resources used by it. */
+ if ( H5Dclose( did ) )
+ return -1;
+
+ return 0;
+
+out:
+ H5Dclose( did );
+ return -1;
+
+}
+
+/*-------------------------------------------------------------------------
+ * Function: H5LTread_dataset_int
+ *
+ * Purpose: Reads a dataset from disk.
+ *
+ * Return: Success: 0, Failure: -1
+ *
+ * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
+ *
+ * Date: November 5, 2001
+ *
+ *-------------------------------------------------------------------------
+ */
+
+herr_t H5LTread_dataset_int( hid_t loc_id,
+ const char *dset_name,
+ int *data )
+{
+ hid_t did;
+
+ /* Open the dataset. */
+ if ( (did = H5Dopen( loc_id, dset_name )) < 0 )
+ return -1;
+
+ /* Read */
+ if ( H5Dread( did, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, data ) < 0 )
+ goto out;
+
+ /* End access to the dataset and release resources used by it. */
+ if ( H5Dclose( did ) )
+ return -1;
+
+ return 0;
+
+out:
+ H5Dclose( did );
+ return -1;
+
+}
+
+/*-------------------------------------------------------------------------
+ * Function: H5LTread_dataset_long
+ *
+ * Purpose: Reads a dataset from disk.
+ *
+ * Return: Success: 0, Failure: -1
+ *
+ * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
+ *
+ * Date: November 5, 2001
+ *
+ *-------------------------------------------------------------------------
+ */
+
+herr_t H5LTread_dataset_long( hid_t loc_id,
+ const char *dset_name,
+ long *data )
+{
+ hid_t did;
+
+ /* Open the dataset. */
+ if ( (did = H5Dopen( loc_id, dset_name )) < 0 )
+ return -1;
+
+ /* Read */
+ if ( H5Dread( did, H5T_NATIVE_LONG, H5S_ALL, H5S_ALL, H5P_DEFAULT, data ) < 0 )
+ goto out;
+
+ /* End access to the dataset and release resources used by it. */
+ if ( H5Dclose( did ) )
+ return -1;
+
+ return 0;
+
+out:
+ H5Dclose( did );
+ return -1;
+
+}
+
+/*-------------------------------------------------------------------------
+ * Function: H5LTread_dataset_float
+ *
+ * Purpose: Reads a dataset from disk.
+ *
+ * Return: Success: 0, Failure: -1
+ *
+ * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
+ *
+ * Date: November 5, 2001
+ *
+ *-------------------------------------------------------------------------
+ */
+
+herr_t H5LTread_dataset_float( hid_t loc_id,
+ const char *dset_name,
+ float *data )
+{
+ hid_t did;
+
+ /* Open the dataset. */
+ if ( (did = H5Dopen( loc_id, dset_name )) < 0 )
+ return -1;
+
+ /* Read */
+ if ( H5Dread( did, H5T_NATIVE_FLOAT, H5S_ALL, H5S_ALL, H5P_DEFAULT, data ) < 0 )
+ goto out;
+
+ /* End access to the dataset and release resources used by it. */
+ if ( H5Dclose( did ) )
+ return -1;
+
+ return 0;
+
+out:
+ H5Dclose( did );
+ return -1;
+
+}
+
+
+/*-------------------------------------------------------------------------
+ * Function: H5LTread_dataset_double
+ *
+ * Purpose: Reads a dataset from disk.
+ *
+ * Return: Success: 0, Failure: -1
+ *
+ * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
+ *
+ * Date: November 5, 2001
+ *
+ *-------------------------------------------------------------------------
+ */
+
+herr_t H5LTread_dataset_double( hid_t loc_id,
+ const char *dset_name,
+ double *data )
+{
+ hid_t did;
+
+ /* Open the dataset. */
+ if ( (did = H5Dopen( loc_id, dset_name )) < 0 )
+ return -1;
+
+ /* Read */
+ if ( H5Dread( did, H5T_NATIVE_DOUBLE, H5S_ALL, H5S_ALL, H5P_DEFAULT, data ) < 0 )
+ goto out;
+
+ /* End access to the dataset and release resources used by it. */
+ if ( H5Dclose( did ) )
+ return -1;
+
+ return 0;
+
+out:
+ H5Dclose( did );
+ return -1;
+
+}
+
+
+/*-------------------------------------------------------------------------
+ * Function: H5LTread_dataset_string
+ *
+ * Purpose: Reads a dataset
+ *
+ * Return: Success: 0, Failure: -1
+ *
+ * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
+ *
+ * Date: October 05, 2004
+ *
+ *-------------------------------------------------------------------------
+ */
+
+herr_t H5LTread_dataset_string( hid_t loc_id,
+ const char *dset_name,
+ char *buf )
+{
+ hid_t did;
+ hid_t tid;
+
+ /* Open the dataset. */
+ if ( (did = H5Dopen( loc_id, dset_name )) < 0 )
+ return -1;
+
+ if ( (tid = H5Dget_type(did)) < 0 )
+ goto out;
+
+ /* Read */
+ if ( H5Dread(did,tid,H5S_ALL,H5S_ALL,H5P_DEFAULT,buf) < 0 )
+ goto out;
+
+ /* close */
+ if ( H5Dclose(did) )
+ goto out;
+ if ( H5Tclose(tid) )
+ return -1;
+
+ return 0;
+
+out:
+ H5Dclose( did );
+ H5Tclose( tid );
+ return -1;
+
+}
+
+
+/*-------------------------------------------------------------------------
+ * Function: H5LTget_dataset_ndims
+ *
+ * Purpose: Gets the dimensionality of a dataset.
+ *
+ * Return: Success: 0, Failure: -1
+ *
+ * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
+ *
+ * Date: September 4, 2001
+ *
+ *-------------------------------------------------------------------------
+ */
+
+herr_t H5LTget_dataset_ndims( hid_t loc_id,
+ const char *dset_name,
+ int *rank )
+{
+ hid_t did;
+ hid_t sid;
+
+ /* Open the dataset. */
+ if ( (did = H5Dopen( loc_id, dset_name )) < 0 )
+ return -1;
+
+ /* Get the dataspace handle */
+ if ( (sid = H5Dget_space( did )) < 0 )
+ goto out;
+
+ /* Get rank */
+ if ( (*rank = H5Sget_simple_extent_ndims( sid )) < 0 )
+ goto out;
+
+ /* Terminate access to the dataspace */
+ if ( H5Sclose( sid ) < 0 )
+ goto out;
+
+ /* End access to the dataset */
+ if ( H5Dclose( did ) )
+ return -1;
+
+ return 0;
+
+out:
+ H5Dclose( did );
+ H5Sclose( sid );
+ return -1;
+
+}
+
+
+/*-------------------------------------------------------------------------
+ * Function: H5LTget_dataset_info
+ *
+ * Purpose: Gets information about a dataset.
+ *
+ * Return: Success: 0, Failure: -1
+ *
+ * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
+ *
+ * Date: September 4, 2001
+ *
+ *-------------------------------------------------------------------------
+ */
+
+herr_t H5LTget_dataset_info( hid_t loc_id,
+ const char *dset_name,
+ hsize_t *dims,
+ H5T_class_t *type_class,
+ size_t *type_size )
+{
+ hid_t did;
+ hid_t tid;
+ hid_t sid;
+
+ /* Open the dataset. */
+ if ( (did = H5Dopen( loc_id, dset_name )) < 0 )
+ return -1;
+
+ /* Get an identifier for the datatype. */
+ tid = H5Dget_type( did );
+
+ /* Get the class. */
+ *type_class = H5Tget_class( tid );
+
+ /* Get the size. */
+ *type_size = H5Tget_size( tid );
+
+ /* Get the dataspace handle */
+ if ( (sid = H5Dget_space( did )) < 0 )
+ goto out;
+
+ /* Get dimensions */
+ if ( H5Sget_simple_extent_dims( sid, dims, NULL) < 0 )
+ goto out;
+
+ /* Terminate access to the dataspace */
+ if ( H5Sclose( sid ) < 0 )
+ goto out;
+
+ /* Release the datatype. */
+ if ( H5Tclose( tid ) )
+ return -1;
+
+ /* End access to the dataset */
+ if ( H5Dclose( did ) )
+ return -1;
+
+ return 0;
+
+out:
+ H5Tclose( tid );
+ H5Dclose( did );
+ return -1;
+
+}
+
+/*-------------------------------------------------------------------------
+ * Function: find_dataset
+ *
+ * Purpose: operator function used by H5LTfind_dataset
+ *
+ * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
+ *
+ * Date: June 21, 2001
+ *
+ * Comments:
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+
+static herr_t find_dataset( hid_t loc_id, const char *name, void *op_data)
+{
+
+ /* Define a default zero value for return. This will cause the iterator to continue if
+ * the dataset is not found yet.
+ */
+
+ int ret = 0;
+
+ char *dset_name = (char*)op_data;
+
+ /* Shut the compiler up */
+ loc_id=loc_id;
+
+ /* Define a positive value for return value if the dataset was found. This will
+ * cause the iterator to immediately return that positive value,
+ * indicating short-circuit success
+ */
+
+ if( strcmp( name, dset_name ) == 0 )
+ ret = 1;
+
+
+ return ret;
+}
+
+
+
+/*-------------------------------------------------------------------------
+ * Function: H5LTfind_dataset
+ *
+ * Purpose: Inquires if a dataset named dset_name exists attached
+ * to the object loc_id.
+ *
+ * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
+ *
+ * Date: July 15, 2001
+ *
+ * Return:
+ * Success: The return value of the first operator that
+ * returns non-zero, or zero if all members were
+ * processed with no operator returning non-zero.
+ *
+ * Failure: Negative if something goes wrong within the
+ * library, or the negative value returned by one
+ * of the operators.
+ *
+ *-------------------------------------------------------------------------
+ */
+
+herr_t H5LTfind_dataset( hid_t loc_id, const char *dset_name )
+{
+
+ herr_t ret;
+
+ ret = H5Giterate( loc_id, ".", 0, find_dataset, (void *)dset_name );
+
+ return ret;
+}
+
+
+/*-------------------------------------------------------------------------
+ *
+ * Set attribute functions
+ *
+ *-------------------------------------------------------------------------
+ */
+
+
+/*-------------------------------------------------------------------------
+ * Function: H5LTset_attribute_string
+ *
+ * Purpose: Creates and writes a string attribute named attr_name and attaches
+ * it to the object specified by the name obj_name.
+ *
+ * Return: Success: 0, Failure: -1
+ *
+ * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
+ *
+ * Date: July 23, 2001
+ *
+ * Comments: If the attribute already exists, it is overwritten
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+
+herr_t H5LTset_attribute_string( hid_t loc_id,
+ const char *obj_name,
+ const char *attr_name,
+ const char *attr_data )
+{
+ hid_t attr_type;
+ hid_t attr_space_id;
+ hid_t attr_id;
+ hid_t obj_id;
+ int has_attr;
+ H5G_stat_t statbuf;
+ size_t attr_size;
+
+
+ /* Get the type of object */
+ if (H5Gget_objinfo( loc_id, obj_name, 1, &statbuf )<0)
+ return -1;
+
+ /* Open the object */
+ if ((obj_id = H5LT_open_id( loc_id, obj_name, statbuf.type )) < 0)
+ return -1;
+
+ /* Create the attribute */
+ if ( (attr_type = H5Tcopy( H5T_C_S1 )) < 0 )
+ goto out;
+
+ attr_size = strlen( attr_data ) + 1; /* extra null term */
+
+ if ( H5Tset_size( attr_type, (size_t)attr_size) < 0 )
+ goto out;
+
+ if ( H5Tset_strpad( attr_type, H5T_STR_NULLTERM ) < 0 )
+ goto out;
+
+ if ( (attr_space_id = H5Screate( H5S_SCALAR )) < 0 )
+ goto out;
+
+ /* Verify if the attribute already exists */
+ has_attr = H5LT_find_attribute( obj_id, attr_name );
+
+ /* The attribute already exists, delete it */
+ if ( has_attr == 1 )
+ {
+ if ( H5Adelete( obj_id, attr_name ) < 0 )
+ goto out;
+ }
+
+ /* Create and write the attribute */
+
+ if ( (attr_id = H5Acreate( obj_id, attr_name, attr_type, attr_space_id, H5P_DEFAULT )) < 0 )
+ goto out;
+
+ if ( H5Awrite( attr_id, attr_type, attr_data ) < 0 )
+ goto out;
+
+ if ( H5Aclose( attr_id ) < 0 )
+ goto out;
+
+ if ( H5Sclose( attr_space_id ) < 0 )
+ goto out;
+
+ if ( H5Tclose(attr_type) < 0 )
+ goto out;
+
+ /* Close the object */
+ if ( H5LT_close_id( obj_id, statbuf.type ) < 0 )
+ return -1;
+
+ return 0;
+
+out:
+
+ H5LT_close_id( obj_id, statbuf.type );
+ return -1;
+}
+
+
+
+
+
+/*-------------------------------------------------------------------------
+ * Function: H5LT_set_attribute_numerical
+ *
+ * Purpose: Private function used by H5LTset_attribute_int and H5LTset_attribute_float
+ *
+ * Return: Success: 0, Failure: -1
+ *
+ * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
+ *
+ * Date: July 25, 2001
+ *
+ * Comments:
+ *
+ *-------------------------------------------------------------------------
+ */
+
+
+herr_t H5LT_set_attribute_numerical( hid_t loc_id,
+ const char *obj_name,
+ const char *attr_name,
+ size_t size,
+ hid_t tid,
+ const void *data )
+{
+
+ hid_t obj_id, sid, attr_id;
+ hsize_t dim_size=size;
+ int has_attr;
+ H5G_stat_t statbuf;
+
+ /* Get the type of object */
+ if (H5Gget_objinfo(loc_id, obj_name, 1, &statbuf)<0)
+ return -1;
+
+ /* Open the object */
+ if ((obj_id = H5LT_open_id( loc_id, obj_name, statbuf.type )) < 0)
+ return -1;
+
+ /* Create the data space for the attribute. */
+ if ( (sid = H5Screate_simple( 1, &dim_size, NULL )) < 0 )
+ goto out;
+
+ /* Verify if the attribute already exists */
+ has_attr = H5LT_find_attribute( obj_id, attr_name );
+
+ /* The attribute already exists, delete it */
+ if ( has_attr == 1 )
+ {
+ if ( H5Adelete( obj_id, attr_name ) < 0 )
+ goto out;
+ }
+
+ /* Create the attribute. */
+ if ( (attr_id = H5Acreate( obj_id, attr_name, tid, sid, H5P_DEFAULT )) < 0 )
+ goto out;
+
+ /* Write the attribute data. */
+ if ( H5Awrite( attr_id, tid, data ) < 0 )
+ goto out;
+
+ /* Close the attribute. */
+ if ( H5Aclose( attr_id ) < 0 )
+ goto out;
+
+ /* Close the dataspace. */
+ if ( H5Sclose( sid ) < 0 )
+ goto out;
+
+ /* Close the object */
+ if ( H5LT_close_id( obj_id, statbuf.type ) < 0 )
+ return -1;
+
+ return 0;
+
+out:
+ H5LT_close_id( obj_id, statbuf.type );
+ return -1;
+}
+
+/*-------------------------------------------------------------------------
+ * Function: H5LT_open_id
+ *
+ * Purpose: Private function used by H5LT_set_attribute_*
+ *
+ * Return: Success: 0, Failure: -1
+ *
+ * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
+ *
+ * Date: September 19, 2002
+ *
+ * Comments:
+ *
+ *-------------------------------------------------------------------------
+ */
+
+herr_t H5LT_open_id( hid_t loc_id,
+ const char *obj_name,
+ int obj_type /*basic object type*/ )
+{
+
+ hid_t obj_id = -1;
+
+ switch ( obj_type )
+ {
+ case H5G_DATASET:
+
+ /* Open the dataset. */
+ if ( (obj_id = H5Dopen( loc_id, obj_name )) < 0 )
+ return -1;
+ break;
+
+ case H5G_GROUP:
+
+ /* Open the group. */
+ if ( (obj_id = H5Gopen( loc_id, obj_name )) < 0 )
+ return -1;
+ break;
+
+ default:
+ return -1;
+ }
+
+ return obj_id;
+
+}
+
+
+/*-------------------------------------------------------------------------
+ * Function: H5LT_close_id
+ *
+ * Purpose: Private function used by H5LT_set_attribute_*
+ *
+ * Return: Success: 0, Failure: -1
+ *
+ * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
+ *
+ * Date: September 19, 2002
+ *
+ * Comments:
+ *
+ *-------------------------------------------------------------------------
+ */
+
+herr_t H5LT_close_id( hid_t obj_id,
+ int obj_type /*basic object type*/ )
+{
+ switch ( obj_type )
+ {
+ case H5G_DATASET:
+ /* Close the dataset. */
+ if ( H5Dclose( obj_id ) < 0 )
+ return -1;
+ break;
+
+ case H5G_GROUP:
+ /* Close the group. */
+ if ( H5Gclose( obj_id ) < 0 )
+ return -1;
+ break;
+
+ default:
+ return -1;
+ }
+
+ return 0;
+}
+
+
+/*-------------------------------------------------------------------------
+ * Function: H5LTset_attribute_char
+ *
+ * Purpose: Create and write an attribute.
+ *
+ * Return: Success: 0, Failure: -1
+ *
+ * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
+ *
+ * Date: November 7, 2001
+ *
+ * Comments:
+ *
+ *-------------------------------------------------------------------------
+ */
+
+herr_t H5LTset_attribute_char( hid_t loc_id,
+ const char *obj_name,
+ const char *attr_name,
+ const char *data,
+ size_t size )
+{
+
+ if ( H5LT_set_attribute_numerical( loc_id, obj_name, attr_name, size,
+ H5T_NATIVE_CHAR, data ) < 0 )
+ return -1;
+
+ return 0;
+}
+
+/*-------------------------------------------------------------------------
+ * Function: H5LTset_attribute_uchar
+ *
+ * Purpose: Create and write an attribute.
+ *
+ * Return: Success: 0, Failure: -1
+ *
+ * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
+ *
+ * Date: March 8, 2004
+ *
+ * Comments:
+ *
+ *-------------------------------------------------------------------------
+ */
+
+herr_t H5LTset_attribute_uchar( hid_t loc_id,
+ const char *obj_name,
+ const char *attr_name,
+ const unsigned char *data,
+ size_t size )
+{
+
+ if ( H5LT_set_attribute_numerical( loc_id, obj_name, attr_name, size,
+ H5T_NATIVE_UCHAR, data ) < 0 )
+ return -1;
+
+ return 0;
+
+}
+
+/*-------------------------------------------------------------------------
+ * Function: H5LTset_attribute_short
+ *
+ * Purpose: Create and write an attribute.
+ *
+ * Return: Success: 0, Failure: -1
+ *
+ * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
+ *
+ * Date: November 7, 2001
+ *
+ * Comments:
+ *
+ *-------------------------------------------------------------------------
+ */
+
+herr_t H5LTset_attribute_short( hid_t loc_id,
+ const char *obj_name,
+ const char *attr_name,
+ const short *data,
+ size_t size )
+{
+
+ if ( H5LT_set_attribute_numerical( loc_id, obj_name, attr_name, size,
+ H5T_NATIVE_SHORT, data ) < 0 )
+ return -1;
+
+ return 0;
+
+}
+
+/*-------------------------------------------------------------------------
+ * Function: H5LTset_attribute_ushort
+ *
+ * Purpose: Create and write an attribute.
+ *
+ * Return: Success: 0, Failure: -1
+ *
+ * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
+ *
+ * Date: March 8, 2004
+ *
+ * Comments:
+ *
+ *-------------------------------------------------------------------------
+ */
+
+herr_t H5LTset_attribute_ushort( hid_t loc_id,
+ const char *obj_name,
+ const char *attr_name,
+ const unsigned short *data,
+ size_t size )
+{
+
+ if ( H5LT_set_attribute_numerical( loc_id, obj_name, attr_name, size,
+ H5T_NATIVE_USHORT, data ) < 0 )
+ return -1;
+
+ return 0;
+
+}
+
+/*-------------------------------------------------------------------------
+ * Function: H5LTset_attribute_int
+ *
+ * Purpose: Create and write an attribute.
+ *
+ * Return: Success: 0, Failure: -1
+ *
+ * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
+ *
+ * Date: November 7, 2001
+ *
+ * Comments:
+ *
+ *-------------------------------------------------------------------------
+ */
+
+herr_t H5LTset_attribute_int( hid_t loc_id,
+ const char *obj_name,
+ const char *attr_name,
+ const int *data,
+ size_t size )
+{
+
+ if ( H5LT_set_attribute_numerical( loc_id, obj_name, attr_name, size,
+ H5T_NATIVE_INT, data ) < 0 )
+ return -1;
+
+ return 0;
+
+}
+
+/*-------------------------------------------------------------------------
+ * Function: H5LTset_attribute_uint
+ *
+ * Purpose: Create and write an attribute.
+ *
+ * Return: Success: 0, Failure: -1
+ *
+ * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
+ *
+ * Date: March 8, 2004
+ *
+ * Comments:
+ *
+ *-------------------------------------------------------------------------
+ */
+
+herr_t H5LTset_attribute_uint( hid_t loc_id,
+ const char *obj_name,
+ const char *attr_name,
+ const unsigned int *data,
+ size_t size )
+{
+
+ if ( H5LT_set_attribute_numerical( loc_id, obj_name, attr_name, size,
+ H5T_NATIVE_UINT, data ) < 0 )
+ return -1;
+
+ return 0;
+
+}
+
+
+/*-------------------------------------------------------------------------
+ * Function: H5LTset_attribute_long
+ *
+ * Purpose: Create and write an attribute.
+ *
+ * Return: Success: 0, Failure: -1
+ *
+ * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
+ *
+ * Date: November 7, 2001
+ *
+ * Comments:
+ *
+ *-------------------------------------------------------------------------
+ */
+
+herr_t H5LTset_attribute_long( hid_t loc_id,
+ const char *obj_name,
+ const char *attr_name,
+ const long *data,
+ size_t size )
+{
+
+ if ( H5LT_set_attribute_numerical( loc_id, obj_name, attr_name, size,
+ H5T_NATIVE_LONG, data ) < 0 )
+ return -1;
+
+ return 0;
+
+}
+
+/*-------------------------------------------------------------------------
+ * Function: H5LTset_attribute_ulong
+ *
+ * Purpose: Create and write an attribute.
+ *
+ * Return: Success: 0, Failure: -1
+ *
+ * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
+ *
+ * Date: March 8, 2004
+ *
+ * Comments:
+ *
+ *-------------------------------------------------------------------------
+ */
+
+herr_t H5LTset_attribute_ulong( hid_t loc_id,
+ const char *obj_name,
+ const char *attr_name,
+ const unsigned long *data,
+ size_t size )
+{
+
+ if ( H5LT_set_attribute_numerical( loc_id, obj_name, attr_name, size,
+ H5T_NATIVE_ULONG, data ) < 0 )
+ return -1;
+
+ return 0;
+
+}
+
+
+/*-------------------------------------------------------------------------
+ * Function: H5LTset_attribute_float
+ *
+ * Purpose: Create and write an attribute.
+ *
+ * Return: Success: 0, Failure: -1
+ *
+ * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
+ *
+ * Date: July 25, 2001
+ *
+ * Comments:
+ *
+ *-------------------------------------------------------------------------
+ */
+
+
+herr_t H5LTset_attribute_float( hid_t loc_id,
+ const char *obj_name,
+ const char *attr_name,
+ const float *data,
+ size_t size )
+{
+
+ if ( H5LT_set_attribute_numerical( loc_id, obj_name, attr_name, size,
+ H5T_NATIVE_FLOAT, data ) < 0 )
+ return -1;
+
+ return 0;
+
+}
+
+
+/*-------------------------------------------------------------------------
+ * Function: H5LTset_attribute_double
+ *
+ * Purpose: Create and write an attribute.
+ *
+ * Return: Success: 0, Failure: -1
+ *
+ * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
+ *
+ * Date: November 7, 2001
+ *
+ * Comments:
+ *
+ *-------------------------------------------------------------------------
+ */
+
+herr_t H5LTset_attribute_double( hid_t loc_id,
+ const char *obj_name,
+ const char *attr_name,
+ const double *data,
+ size_t size )
+{
+
+ if ( H5LT_set_attribute_numerical( loc_id, obj_name, attr_name, size,
+ H5T_NATIVE_DOUBLE, data ) < 0 )
+ return -1;
+
+ return 0;
+
+}
+
+
+
+/*-------------------------------------------------------------------------
+ * Function: find_attr
+ *
+ * Purpose: operator function used by H5LT_find_attribute
+ *
+ * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
+ *
+ * Date: June 21, 2001
+ *
+ * Comments:
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+
+static herr_t find_attr( hid_t loc_id, const char *name, void *op_data)
+{
+
+ /* Define a default zero value for return. This will cause the iterator to continue if
+ * the palette attribute is not found yet.
+ */
+
+ int ret = 0;
+
+ char *attr_name = (char*)op_data;
+
+ /* Shut the compiler up */
+ loc_id=loc_id;
+
+ /* Define a positive value for return value if the attribute was found. This will
+ * cause the iterator to immediately return that positive value,
+ * indicating short-circuit success
+ */
+
+ if( strcmp( name, attr_name ) == 0 )
+ ret = 1;
+
+
+ return ret;
+}
+
+
+/*-------------------------------------------------------------------------
+ * Function: H5LT_find_attribute
+ *
+ * Purpose: Inquires if an attribute named attr_name exists attached to the object loc_id.
+ *
+ * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
+ *
+ * Date: June 21, 2001
+ *
+ * Comments:
+ * The function uses H5Aiterate with the operator function find_attr
+ *
+ * Return:
+ * Success: The return value of the first operator that
+ * returns non-zero, or zero if all members were
+ * processed with no operator returning non-zero.
+ *
+ * Failure: Negative if something goes wrong within the
+ * library, or the negative value returned by one
+ * of the operators.
+ *
+ *-------------------------------------------------------------------------
+ */
+
+herr_t H5LT_find_attribute( hid_t loc_id, const char* attr_name )
+{
+
+ unsigned int attr_num;
+ herr_t ret;
+
+ attr_num = 0;
+ ret = H5Aiterate( loc_id, &attr_num, find_attr, (void *)attr_name );
+
+ return ret;
+}
+
+
+
+/*-------------------------------------------------------------------------
+ * Function: H5LTget_attribute_ndims
+ *
+ * Purpose: Gets the dimensionality of an attribute.
+ *
+ * Return: Success: 0, Failure: -1
+ *
+ * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
+ *
+ * Date: September 4, 2001
+ *
+ *-------------------------------------------------------------------------
+ */
+
+herr_t H5LTget_attribute_ndims( hid_t loc_id,
+ const char *obj_name,
+ const char *attr_name,
+ int *rank )
+{
+ hid_t attr_id;
+ hid_t sid;
+ H5G_stat_t statbuf;
+ hid_t obj_id;
+
+ /* Get the type of object */
+ if (H5Gget_objinfo( loc_id, obj_name, 1, &statbuf )<0)
+ return -1;
+
+ /* Open the object */
+ if ((obj_id = H5LT_open_id( loc_id, obj_name, statbuf.type )) < 0)
+ return -1;
+
+ /* Open the attribute. */
+ if ( ( attr_id = H5Aopen_name( obj_id, attr_name ) ) < 0 )
+ {
+ H5LT_close_id( obj_id, statbuf.type );
+ return -1;
+ }
+
+ /* Get the dataspace handle */
+ if ( (sid = H5Aget_space( attr_id )) < 0 )
+ goto out;
+
+ /* Get rank */
+ if ( (*rank = H5Sget_simple_extent_ndims( sid )) < 0 )
+ goto out;
+
+ /* Terminate access to the attribute */
+ if ( H5Sclose( sid ) < 0 )
+ goto out;
+
+ /* End access to the attribute */
+ if ( H5Aclose( attr_id ) )
+ goto out;;
+
+ /* Close the object */
+ if ( H5LT_close_id( obj_id, statbuf.type ) < 0 )
+ return -1;
+
+ return 0;
+
+out:
+ H5Aclose( attr_id );
+ H5LT_close_id( obj_id, statbuf.type );
+ return -1;
+
+}
+
+
+/*-------------------------------------------------------------------------
+ * Function: H5LTget_attribute_info
+ *
+ * Purpose: Gets information about an attribute.
+ *
+ * Return: Success: 0, Failure: -1
+ *
+ * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
+ *
+ * Date: September 4, 2001
+ *
+ *-------------------------------------------------------------------------
+ */
+
+herr_t H5LTget_attribute_info( hid_t loc_id,
+ const char *obj_name,
+ const char *attr_name,
+ hsize_t *dims,
+ H5T_class_t *type_class,
+ size_t *type_size )
+{
+ hid_t attr_id;
+ hid_t tid;
+ hid_t sid;
+ H5G_stat_t statbuf;
+ hid_t obj_id;
+
+ /* Get the type of object */
+ if (H5Gget_objinfo( loc_id, obj_name, 1, &statbuf )<0)
+ return -1;
+
+ /* Open the object */
+ if ((obj_id = H5LT_open_id( loc_id, obj_name, statbuf.type )) < 0)
+ return -1;
+
+ /* Open the attribute. */
+ if ( ( attr_id = H5Aopen_name( obj_id, attr_name ) ) < 0 )
+ {
+ H5LT_close_id( obj_id, statbuf.type );
+ return -1;
+ }
+
+ /* Get an identifier for the datatype. */
+ tid = H5Aget_type( attr_id );
+
+ /* Get the class. */
+ *type_class = H5Tget_class( tid );
+
+ /* Get the size. */
+ *type_size = H5Tget_size( tid );
+
+ /* Get the dataspace handle */
+ if ( (sid = H5Aget_space( attr_id )) < 0 )
+ goto out;
+
+ /* Get dimensions */
+ if ( H5Sget_simple_extent_dims( sid, dims, NULL) < 0 )
+ goto out;
+
+ /* Terminate access to the dataspace */
+ if ( H5Sclose( sid ) < 0 )
+ goto out;
+
+ /* Release the datatype. */
+ if ( H5Tclose( tid ) )
+ goto out;
+
+ /* End access to the attribute */
+ if ( H5Aclose( attr_id ) )
+ goto out;
+
+ /* Close the object */
+ if ( H5LT_close_id( obj_id, statbuf.type ) < 0 )
+ return -1;
+
+ return 0;
+
+out:
+ H5Tclose( tid );
+ H5Aclose( attr_id );
+ H5LT_close_id( obj_id, statbuf.type );
+ return -1;
+
+}
+
+
+/*-------------------------------------------------------------------------
+ *
+ * General functions
+ *
+ *-------------------------------------------------------------------------
+ */
+
+/*-------------------------------------------------------------------------
+ * Function: H5LTcreate_compound_type
+ *
+ * Purpose:
+ *
+ * Return: Success: 0, Failure: -1
+ *
+ * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
+ *
+ * Date: September 18, 2001
+ *
+ * Comments:
+ *
+ * Modifications:
+ *
+ *
+ *-------------------------------------------------------------------------
+ */
+
+hid_t H5LTcreate_compound_type( hsize_t nfields, size_t size, const char *field_names[],
+ const size_t *field_offset, const hid_t *field_types )
+{
+
+ hid_t tid;
+ hsize_t i;
+
+ /* Create the memory data type. */
+ if ((tid = H5Tcreate (H5T_COMPOUND, size )) < 0 )
+ goto out;
+
+ /* Insert fields. */
+ for ( i = 0; i < nfields; i++)
+ {
+ if ( H5Tinsert(tid, field_names[i], field_offset[i], field_types[i] ) < 0 )
+ goto out;
+ }
+
+ return tid;
+
+out:
+ return -1;
+}
+
+
+
+
+
+/*-------------------------------------------------------------------------
+ * Function: H5LTrepack
+ *
+ * Purpose: Packs/Unpacks data from buffers. This function transfers data from a packed
+ * data, src_buf, to a "natural byte aligned" (an n-byte item at an n-byte boundary)
+ * data, dst_buf, and vice-versa.
+ *
+ * Return: Success: 0, Failure: -1
+ *
+ * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
+ *
+ * Date: January 17, 2002
+ *
+ * Comments:
+ *
+ * Modifications:
+ *
+ *
+ *-------------------------------------------------------------------------
+ */
+
+herr_t H5LTrepack( hsize_t nfields,
+ hsize_t nrecords,
+ size_t src_size,
+ const size_t *src_offset,
+ const size_t *src_sizes,
+ size_t dst_size,
+ const size_t *dst_offset,
+ const size_t *dst_sizes,
+ unsigned char *src_buf,
+ unsigned char *dst_buf )
+{
+ hsize_t i, j;
+ /* size of each field of destination data counting with padding */
+ size_t *size_pad = (size_t *)malloc((size_t)nfields * sizeof(size_t));
+
+ /* Shut compiler */
+ src_size=src_size;
+ src_offset=src_offset;
+
+ if ( size_pad == NULL )
+ goto out;
+
+ for ( i= 0; i < nfields; i++)
+ {
+
+ size_pad[i] = ( i == nfields-1 ? dst_size-dst_offset[i] : dst_offset[i+1]-dst_offset[i] );
+
+ }
+
+ /* Iterate tru the records */
+ for ( i = 0; i < nrecords; i++)
+ {
+ /* Iterate tru the members */
+ for ( j = 0; j < nfields; j++)
+ {
+
+ memcpy( dst_buf, src_buf, dst_sizes[j] );
+ dst_buf += size_pad[j];
+ src_buf += src_sizes[j];
+
+ }
+
+ }
+
+ if ( size_pad != NULL )
+ free( size_pad );
+
+return 0;
+
+out:
+ return -1;
+
+}
+
+
+/*-------------------------------------------------------------------------
+ *
+ * Get attribute functions
+ *
+ *-------------------------------------------------------------------------
+ */
+
+
+/*-------------------------------------------------------------------------
+ * Function: H5LTget_attribute_string
+ *
+ * Purpose: Reads an attribute named attr_name
+ *
+ * Return: Success: 0, Failure: -1
+ *
+ * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
+ *
+ * Date: September 19, 2002
+ *
+ * Comments:
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+
+
+herr_t H5LTget_attribute_string( hid_t loc_id,
+ const char *obj_name,
+ const char *attr_name,
+ char *data )
+{
+
+ /* identifiers */
+ hid_t obj_id;
+ H5G_stat_t statbuf;
+
+ /* Get the type of object */
+ if (H5Gget_objinfo(loc_id, obj_name, 1, &statbuf)<0)
+ return -1;
+
+ /* Open the object */
+ if ((obj_id = H5LT_open_id( loc_id, obj_name, statbuf.type )) < 0)
+ return -1;
+
+ /* Get the attribute */
+ if ( H5LT_get_attribute_disk( obj_id, attr_name, data ) < 0 )
+ return -1;
+
+ /* Close the object */
+ if ( H5LT_close_id( obj_id, statbuf.type ) < 0 )
+ return -1;
+
+ return 0;
+
+}
+
+/*-------------------------------------------------------------------------
+ * Function: H5LTget_attribute_char
+ *
+ * Purpose: Reads an attribute named attr_name
+ *
+ * Return: Success: 0, Failure: -1
+ *
+ * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
+ *
+ * Date: September 19, 2002
+ *
+ * Comments:
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+herr_t H5LTget_attribute_char( hid_t loc_id,
+ const char *obj_name,
+ const char *attr_name,
+ char *data )
+{
+
+ /* identifiers */
+ hid_t obj_id;
+ H5G_stat_t statbuf;
+
+ /* Get the type of object */
+ if (H5Gget_objinfo(loc_id, obj_name, 1, &statbuf)<0)
+ return -1;
+
+ /* Open the object */
+ if ((obj_id = H5LT_open_id( loc_id, obj_name, statbuf.type )) < 0)
+ return -1;
+
+ /* Get the attribute */
+ if ( H5LT_get_attribute_mem( obj_id, attr_name, H5T_NATIVE_CHAR, data ) < 0 )
+ return -1;
+
+ /* Close the object */
+ if ( H5LT_close_id( obj_id, statbuf.type ) < 0 )
+ return -1;
+
+ return 0;
+
+}
+
+/*-------------------------------------------------------------------------
+ * Function: H5LTget_attribute_uchar
+ *
+ * Purpose: Reads an attribute named attr_name
+ *
+ * Return: Success: 0, Failure: -1
+ *
+ * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
+ *
+ * Date: March 8, 2004
+ *
+ * Comments:
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+herr_t H5LTget_attribute_uchar( hid_t loc_id,
+ const char *obj_name,
+ const char *attr_name,
+ unsigned char *data )
+{
+
+ /* identifiers */
+ hid_t obj_id;
+ H5G_stat_t statbuf;
+
+ /* Get the type of object */
+ if (H5Gget_objinfo(loc_id, obj_name, 1, &statbuf)<0)
+ return -1;
+
+ /* Open the object */
+ if ((obj_id = H5LT_open_id( loc_id, obj_name, statbuf.type )) < 0)
+ return -1;
+
+ /* Get the attribute */
+ if ( H5LT_get_attribute_mem( obj_id, attr_name, H5T_NATIVE_UCHAR, data ) < 0 )
+ return -1;
+
+ /* Close the object */
+ if ( H5LT_close_id( obj_id, statbuf.type ) < 0 )
+ return -1;
+
+ return 0;
+
+}
+
+
+
+/*-------------------------------------------------------------------------
+ * Function: H5LTget_attribute_short
+ *
+ * Purpose: Reads an attribute named attr_name
+ *
+ * Return: Success: 0, Failure: -1
+ *
+ * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
+ *
+ * Date: September 19, 2002
+ *
+ * Comments:
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+herr_t H5LTget_attribute_short( hid_t loc_id,
+ const char *obj_name,
+ const char *attr_name,
+ short *data )
+{
+
+ /* identifiers */
+ hid_t obj_id;
+ H5G_stat_t statbuf;
+
+ /* Get the type of object */
+ if (H5Gget_objinfo(loc_id, obj_name, 1, &statbuf)<0)
+ return -1;
+
+ /* Open the object */
+ if ((obj_id = H5LT_open_id( loc_id, obj_name, statbuf.type )) < 0)
+ return -1;
+
+ /* Get the attribute */
+ if ( H5LT_get_attribute_mem( obj_id, attr_name, H5T_NATIVE_SHORT, data ) < 0 )
+ return -1;
+
+ /* Close the object */
+ if ( H5LT_close_id( obj_id, statbuf.type ) < 0 )
+ return -1;
+
+ return 0;
+
+}
+
+/*-------------------------------------------------------------------------
+ * Function: H5LTget_attribute_ushort
+ *
+ * Purpose: Reads an attribute named attr_name
+ *
+ * Return: Success: 0, Failure: -1
+ *
+ * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
+ *
+ * Date: March 8, 2004
+ *
+ * Comments:
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+herr_t H5LTget_attribute_ushort( hid_t loc_id,
+ const char *obj_name,
+ const char *attr_name,
+ unsigned short *data )
+{
+
+ /* identifiers */
+ hid_t obj_id;
+ H5G_stat_t statbuf;
+
+ /* Get the type of object */
+ if (H5Gget_objinfo(loc_id, obj_name, 1, &statbuf)<0)
+ return -1;
+
+ /* Open the object */
+ if ((obj_id = H5LT_open_id( loc_id, obj_name, statbuf.type )) < 0)
+ return -1;
+
+ /* Get the attribute */
+ if ( H5LT_get_attribute_mem( obj_id, attr_name, H5T_NATIVE_USHORT, data ) < 0 )
+ return -1;
+
+ /* Close the object */
+ if ( H5LT_close_id( obj_id, statbuf.type ) < 0 )
+ return -1;
+
+ return 0;
+
+}
+
+
+
+/*-------------------------------------------------------------------------
+ * Function: H5LTget_attribute_int
+ *
+ * Purpose: Reads an attribute named attr_name
+ *
+ * Return: Success: 0, Failure: -1
+ *
+ * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
+ *
+ * Date: September 19, 2002
+ *
+ * Comments:
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+herr_t H5LTget_attribute_int( hid_t loc_id,
+ const char *obj_name,
+ const char *attr_name,
+ int *data )
+{
+
+ /* identifiers */
+ hid_t obj_id;
+ H5G_stat_t statbuf;
+
+ /* Get the type of object */
+ if (H5Gget_objinfo(loc_id, obj_name, 1, &statbuf)<0)
+ return -1;
+
+ /* Open the object */
+ if ((obj_id = H5LT_open_id( loc_id, obj_name, statbuf.type )) < 0)
+ return -1;
+
+ /* Get the attribute */
+ if ( H5LT_get_attribute_mem( obj_id, attr_name, H5T_NATIVE_INT, data ) < 0 )
+ return -1;
+
+ /* Close the object */
+ if ( H5LT_close_id( obj_id, statbuf.type ) < 0 )
+ return -1;
+
+ return 0;
+
+}
+
+/*-------------------------------------------------------------------------
+ * Function: H5LTget_attribute_uint
+ *
+ * Purpose: Reads an attribute named attr_name
+ *
+ * Return: Success: 0, Failure: -1
+ *
+ * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
+ *
+ * Date: March 8, 2004
+ *
+ * Comments:
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+herr_t H5LTget_attribute_uint( hid_t loc_id,
+ const char *obj_name,
+ const char *attr_name,
+ unsigned int *data )
+{
+
+ /* identifiers */
+ hid_t obj_id;
+ H5G_stat_t statbuf;
+
+ /* Get the type of object */
+ if (H5Gget_objinfo(loc_id, obj_name, 1, &statbuf)<0)
+ return -1;
+
+ /* Open the object */
+ if ((obj_id = H5LT_open_id( loc_id, obj_name, statbuf.type )) < 0)
+ return -1;
+
+ /* Get the attribute */
+ if ( H5LT_get_attribute_mem( obj_id, attr_name, H5T_NATIVE_UINT, data ) < 0 )
+ return -1;
+
+ /* Close the object */
+ if ( H5LT_close_id( obj_id, statbuf.type ) < 0 )
+ return -1;
+
+ return 0;
+
+}
+
+
+
+/*-------------------------------------------------------------------------
+ * Function: H5LTget_attribute_long
+ *
+ * Purpose: Reads an attribute named attr_name
+ *
+ * Return: Success: 0, Failure: -1
+ *
+ * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
+ *
+ * Date: September 19, 2002
+ *
+ * Comments:
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+herr_t H5LTget_attribute_long( hid_t loc_id,
+ const char *obj_name,
+ const char *attr_name,
+ long *data )
+{
+
+ /* identifiers */
+ hid_t obj_id;
+ H5G_stat_t statbuf;
+
+ /* Get the type of object */
+ if (H5Gget_objinfo(loc_id, obj_name, 1, &statbuf)<0)
+ return -1;
+
+ /* Open the object */
+ if ((obj_id = H5LT_open_id( loc_id, obj_name, statbuf.type )) < 0)
+ return -1;
+
+ /* Get the attribute */
+ if ( H5LT_get_attribute_mem( obj_id, attr_name, H5T_NATIVE_LONG, data ) < 0 )
+ return -1;
+
+ /* Close the object */
+ if ( H5LT_close_id( obj_id, statbuf.type ) < 0 )
+ return -1;
+
+ return 0;
+
+}
+
+/*-------------------------------------------------------------------------
+ * Function: H5LTget_attribute_ulong
+ *
+ * Purpose: Reads an attribute named attr_name
+ *
+ * Return: Success: 0, Failure: -1
+ *
+ * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
+ *
+ * Date: March 8, 2004
+ *
+ * Comments:
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+herr_t H5LTget_attribute_ulong( hid_t loc_id,
+ const char *obj_name,
+ const char *attr_name,
+ unsigned long *data )
+{
+
+ /* identifiers */
+ hid_t obj_id;
+ H5G_stat_t statbuf;
+
+ /* Get the type of object */
+ if (H5Gget_objinfo(loc_id, obj_name, 1, &statbuf)<0)
+ return -1;
+
+ /* Open the object */
+ if ((obj_id = H5LT_open_id( loc_id, obj_name, statbuf.type )) < 0)
+ return -1;
+
+ /* Get the attribute */
+ if ( H5LT_get_attribute_mem( obj_id, attr_name, H5T_NATIVE_ULONG, data ) < 0 )
+ return -1;
+
+ /* Close the object */
+ if ( H5LT_close_id( obj_id, statbuf.type ) < 0 )
+ return -1;
+
+ return 0;
+
+}
+
+
+/*-------------------------------------------------------------------------
+ * Function: H5LTget_attribute_float
+ *
+ * Purpose: Reads an attribute named attr_name
+ *
+ * Return: Success: 0, Failure: -1
+ *
+ * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
+ *
+ * Date: September 19, 2002
+ *
+ * Comments:
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+
+
+herr_t H5LTget_attribute_float( hid_t loc_id,
+ const char *obj_name,
+ const char *attr_name,
+ float *data )
+{
+
+ /* identifiers */
+ hid_t obj_id;
+ H5G_stat_t statbuf;
+
+ /* Get the type of object */
+ if (H5Gget_objinfo(loc_id, obj_name, 1, &statbuf)<0)
+ return -1;
+
+ /* Open the object */
+ if ((obj_id = H5LT_open_id( loc_id, obj_name, statbuf.type )) < 0)
+ return -1;
+
+ /* Get the attribute */
+ if ( H5LT_get_attribute_mem( obj_id, attr_name, H5T_NATIVE_FLOAT, data ) < 0 )
+ return -1;
+
+ /* Close the object */
+ if ( H5LT_close_id( obj_id, statbuf.type ) < 0 )
+ return -1;
+
+ return 0;
+
+}
+
+
+/*-------------------------------------------------------------------------
+ * Function: H5LTget_attribute_double
+ *
+ * Purpose: Reads an attribute named attr_name
+ *
+ * Return: Success: 0, Failure: -1
+ *
+ * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
+ *
+ * Date: September 19, 2002
+ *
+ * Comments:
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+
+
+herr_t H5LTget_attribute_double( hid_t loc_id,
+ const char *obj_name,
+ const char *attr_name,
+ double *data )
+{
+
+ /* identifiers */
+ hid_t obj_id;
+ H5G_stat_t statbuf;
+
+ /* Get the type of object */
+ if (H5Gget_objinfo(loc_id, obj_name, 1, &statbuf)<0)
+ return -1;
+
+ /* Open the object */
+ if ((obj_id = H5LT_open_id( loc_id, obj_name, statbuf.type )) < 0)
+ return -1;
+
+ /* Get the attribute */
+ if ( H5LT_get_attribute_mem( obj_id, attr_name, H5T_NATIVE_DOUBLE, data ) < 0 )
+ return -1;
+
+ /* Close the object */
+ if ( H5LT_close_id( obj_id, statbuf.type ) < 0 )
+ return -1;
+
+ return 0;
+
+}
+
+
+/*-------------------------------------------------------------------------
+ * Function: H5LTget_attribute
+ *
+ * Purpose: Reads an attribute named attr_name with the memory type mem_type_id
+ *
+ * Return: Success: 0, Failure: -1
+ *
+ * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
+ *
+ * Date: September 19, 2002
+ *
+ * Comments: Private function
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+
+
+herr_t H5LTget_attribute( hid_t loc_id,
+ const char *obj_name,
+ const char *attr_name,
+ hid_t mem_type_id,
+ void *data )
+{
+
+ /* identifiers */
+ hid_t obj_id;
+ H5G_stat_t statbuf;
+
+ /* Get the type of object */
+ if (H5Gget_objinfo(loc_id, obj_name, 1, &statbuf)<0)
+ return -1;
+
+ /* Open the object */
+ if ((obj_id = H5LT_open_id( loc_id, obj_name, statbuf.type )) < 0)
+ return -1;
+
+ /* Get the attribute */
+ if ( H5LT_get_attribute_mem( obj_id, attr_name, mem_type_id, data ) < 0 )
+ {
+ H5LT_close_id( obj_id, statbuf.type );
+ return -1;
+ }
+
+ /* Close the object */
+ if ( H5LT_close_id( obj_id, statbuf.type ) < 0 )
+ return -1;
+
+ return 0;
+}
+
+
+/*-------------------------------------------------------------------------
+ * Function: H5LT_get_attribute_mem
+ *
+ * Purpose: Reads an attribute named attr_name with the memory type mem_type_id
+ *
+ * Return: Success: 0, Failure: -1
+ *
+ * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
+ *
+ * Date: September 19, 2002
+ *
+ * Comments: Private function
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+
+
+herr_t H5LT_get_attribute_mem( hid_t obj_id,
+ const char *attr_name,
+ hid_t mem_type_id,
+ void *data )
+{
+
+ /* identifiers */
+ hid_t attr_id;
+
+ if ( ( attr_id = H5Aopen_name( obj_id, attr_name ) ) < 0 )
+ return -1;
+
+ if ( H5Aread( attr_id, mem_type_id, data ) < 0 )
+ goto out;
+
+ if ( H5Aclose( attr_id ) < 0 )
+ return -1;
+
+ return 0;
+
+out:
+ H5Aclose( attr_id );
+ return -1;
+}
+
+/*-------------------------------------------------------------------------
+ * Function: H5LT_get_attribute_disk
+ *
+ * Purpose: Reads an attribute named attr_name with the datatype stored on disk
+ *
+ * Return: Success: 0, Failure: -1
+ *
+ * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
+ *
+ * Date: September 19, 2002
+ *
+ * Comments:
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+
+herr_t H5LT_get_attribute_disk( hid_t loc_id,
+ const char *attr_name,
+ void *attr_out )
+{
+ /* identifiers */
+ hid_t attr_id;
+ hid_t attr_type;
+
+ if ( ( attr_id = H5Aopen_name( loc_id, attr_name ) ) < 0 )
+ return -1;
+
+ if ( (attr_type = H5Aget_type( attr_id )) < 0 )
+ goto out;
+
+ if ( H5Aread( attr_id, attr_type, attr_out ) < 0 )
+ goto out;
+
+ if ( H5Tclose( attr_type ) < 0 )
+ goto out;
+
+ if ( H5Aclose( attr_id ) < 0 )
+ return -1;;
+
+ return 0;
+
+out:
+ H5Tclose( attr_type );
+ H5Aclose( attr_id );
+ return -1;
+}
+
+
+
+
diff --git a/hl/src/H5LT.h b/hl/src/H5LT.h
new file mode 100644
index 0000000..aa4b1b1
--- /dev/null
+++ b/hl/src/H5LT.h
@@ -0,0 +1,374 @@
+
+/****************************************************************************
+ * NCSA HDF *
+ * Scientific Data Technologies *
+ * National Center for Supercomputing Applications *
+ * University of Illinois at Urbana-Champaign *
+ * 605 E. Springfield, Champaign IL 61820 *
+ * *
+ * For conditions of distribution and use, see the accompanying *
+ * hdf/COPYING file. *
+ * *
+ ****************************************************************************/
+
+
+#ifndef _H5LT_H
+#define _H5LT_H
+
+#include <hdf5.h>
+
+#define TESTING(WHAT) {printf("%-70s", "Testing " WHAT); fflush(stdout);}
+#define PASSED() {puts(" PASSED");fflush(stdout);}
+#define H5_FAILED() {puts("*FAILED*");fflush(stdout);}
+#define SKIPPED() {puts(" -SKIP-");fflush(stdout);}
+#define EXAMPLE(WHAT) {printf("%-70s", "Example " WHAT); fflush(stdout);}
+
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+/*-------------------------------------------------------------------------
+ *
+ * Make dataset functions
+ *
+ *-------------------------------------------------------------------------
+ */
+
+herr_t H5LTmake_dataset( hid_t loc_id,
+ const char *dset_name,
+ int rank,
+ const hsize_t *dims,
+ hid_t type_id,
+ const void *buffer );
+
+herr_t H5LTmake_dataset_char( hid_t loc_id,
+ const char *dset_name,
+ int rank,
+ const hsize_t *dims,
+ const char *buffer );
+
+herr_t H5LTmake_dataset_short( hid_t loc_id,
+ const char *dset_name,
+ int rank,
+ const hsize_t *dims,
+ const short *buffer );
+
+herr_t H5LTmake_dataset_int( hid_t loc_id,
+ const char *dset_name,
+ int rank,
+ const hsize_t *dims,
+ const int *buffer );
+
+herr_t H5LTmake_dataset_long( hid_t loc_id,
+ const char *dset_name,
+ int rank,
+ const hsize_t *dims,
+ const long *buffer );
+
+herr_t H5LTmake_dataset_float( hid_t loc_id,
+ const char *dset_name,
+ int rank,
+ const hsize_t *dims,
+ const float *buffer );
+
+herr_t H5LTmake_dataset_double( hid_t loc_id,
+ const char *dset_name,
+ int rank,
+ const hsize_t *dims,
+ const double *buffer );
+
+herr_t H5LTmake_dataset_string(hid_t loc_id,
+ const char *dset_name,
+ const char *buf );
+
+
+/*-------------------------------------------------------------------------
+ *
+ * Read dataset functions
+ *
+ *-------------------------------------------------------------------------
+ */
+
+herr_t H5LTread_dataset( hid_t loc_id,
+ const char *dset_name,
+ hid_t type_id,
+ void *buffer );
+
+herr_t H5LTread_dataset_char( hid_t loc_id,
+ const char *dset_name,
+ char *buffer );
+
+herr_t H5LTread_dataset_short( hid_t loc_id,
+ const char *dset_name,
+ short *buffer );
+
+herr_t H5LTread_dataset_int( hid_t loc_id,
+ const char *dset_name,
+ int *buffer );
+
+herr_t H5LTread_dataset_long( hid_t loc_id,
+ const char *dset_name,
+ long *buffer );
+
+herr_t H5LTread_dataset_float( hid_t loc_id,
+ const char *dset_name,
+ float *buffer );
+
+herr_t H5LTread_dataset_double( hid_t loc_id,
+ const char *dset_name,
+ double *buffer );
+
+herr_t H5LTread_dataset_string( hid_t loc_id,
+ const char *dset_name,
+ char *buf );
+
+/*-------------------------------------------------------------------------
+ *
+ * Query dataset functions
+ *
+ *-------------------------------------------------------------------------
+ */
+
+
+herr_t H5LTget_dataset_ndims( hid_t loc_id,
+ const char *dset_name,
+ int *rank );
+
+herr_t H5LTget_dataset_info( hid_t loc_id,
+ const char *dset_name,
+ hsize_t *dims,
+ H5T_class_t *type_class,
+ size_t *type_size );
+
+herr_t H5LTfind_dataset( hid_t loc_id, const char *name );
+
+
+
+/*-------------------------------------------------------------------------
+ *
+ * Set attribute functions
+ *
+ *-------------------------------------------------------------------------
+ */
+
+
+herr_t H5LTset_attribute_string( hid_t loc_id,
+ const char *obj_name,
+ const char *attr_name,
+ const char *attr_data );
+
+herr_t H5LTset_attribute_char( hid_t loc_id,
+ const char *obj_name,
+ const char *attr_name,
+ const char *buffer,
+ size_t size );
+
+herr_t H5LTset_attribute_uchar( hid_t loc_id,
+ const char *obj_name,
+ const char *attr_name,
+ const unsigned char *buffer,
+ size_t size );
+
+herr_t H5LTset_attribute_short( hid_t loc_id,
+ const char *obj_name,
+ const char *attr_name,
+ const short *buffer,
+ size_t size );
+
+herr_t H5LTset_attribute_ushort( hid_t loc_id,
+ const char *obj_name,
+ const char *attr_name,
+ const unsigned short *buffer,
+ size_t size );
+
+herr_t H5LTset_attribute_int( hid_t loc_id,
+ const char *obj_name,
+ const char *attr_name,
+ const int *buffer,
+ size_t size );
+
+herr_t H5LTset_attribute_uint( hid_t loc_id,
+ const char *obj_name,
+ const char *attr_name,
+ const unsigned int *buffer,
+ size_t size );
+
+herr_t H5LTset_attribute_long( hid_t loc_id,
+ const char *obj_name,
+ const char *attr_name,
+ const long *buffer,
+ size_t size );
+
+herr_t H5LTset_attribute_ulong( hid_t loc_id,
+ const char *obj_name,
+ const char *attr_name,
+ const unsigned long *buffer,
+ size_t size );
+
+herr_t H5LTset_attribute_float( hid_t loc_id,
+ const char *obj_name,
+ const char *attr_name,
+ const float *buffer,
+ size_t size );
+
+herr_t H5LTset_attribute_double( hid_t loc_id,
+ const char *obj_name,
+ const char *attr_name,
+ const double *buffer,
+ size_t size );
+
+/*-------------------------------------------------------------------------
+ *
+ * Get attribute functions
+ *
+ *-------------------------------------------------------------------------
+ */
+
+herr_t H5LTget_attribute( hid_t loc_id,
+ const char *obj_name,
+ const char *attr_name,
+ hid_t mem_type_id,
+ void *data );
+
+herr_t H5LTget_attribute_string( hid_t loc_id,
+ const char *obj_name,
+ const char *attr_name,
+ char *data );
+
+herr_t H5LTget_attribute_char( hid_t loc_id,
+ const char *obj_name,
+ const char *attr_name,
+ char *data );
+
+herr_t H5LTget_attribute_uchar( hid_t loc_id,
+ const char *obj_name,
+ const char *attr_name,
+ unsigned char *data );
+
+herr_t H5LTget_attribute_short( hid_t loc_id,
+ const char *obj_name,
+ const char *attr_name,
+ short *data );
+
+herr_t H5LTget_attribute_ushort( hid_t loc_id,
+ const char *obj_name,
+ const char *attr_name,
+ unsigned short *data );
+
+herr_t H5LTget_attribute_int( hid_t loc_id,
+ const char *obj_name,
+ const char *attr_name,
+ int *data );
+
+herr_t H5LTget_attribute_uint( hid_t loc_id,
+ const char *obj_name,
+ const char *attr_name,
+ unsigned int *data );
+
+herr_t H5LTget_attribute_long( hid_t loc_id,
+ const char *obj_name,
+ const char *attr_name,
+ long *data );
+
+herr_t H5LTget_attribute_ulong( hid_t loc_id,
+ const char *obj_name,
+ const char *attr_name,
+ unsigned long *data );
+
+herr_t H5LTget_attribute_float( hid_t loc_id,
+ const char *obj_name,
+ const char *attr_name,
+ float *data );
+
+herr_t H5LTget_attribute_double( hid_t loc_id,
+ const char *obj_name,
+ const char *attr_name,
+ double *data );
+
+
+/*-------------------------------------------------------------------------
+ *
+ * Query attribute functions
+ *
+ *-------------------------------------------------------------------------
+ */
+
+
+herr_t H5LTget_attribute_ndims( hid_t loc_id,
+ const char *obj_name,
+ const char *attr_name,
+ int *rank );
+
+herr_t H5LTget_attribute_info( hid_t loc_id,
+ const char *obj_name,
+ const char *attr_name,
+ hsize_t *dims,
+ H5T_class_t *type_class,
+ size_t *type_size );
+
+
+
+
+
+/*-------------------------------------------------------------------------
+ *
+ * General functions
+ *
+ *-------------------------------------------------------------------------
+ */
+
+
+hid_t H5LTcreate_compound_type( hsize_t nfields, size_t size, const char *field_names[],
+ const size_t *field_offset, const hid_t *field_types );
+
+
+herr_t H5LTrepack( hsize_t nfields,
+ hsize_t nrecords,
+ size_t src_size,
+ const size_t *src_offset,
+ const size_t *src_sizes,
+ size_t dst_size,
+ const size_t *dst_offset,
+ const size_t *dst_sizes,
+ unsigned char *src_buf,
+ unsigned char *dst_buf );
+
+
+
+/*-------------------------------------------------------------------------
+ *
+ * Private functions
+ *
+ *-------------------------------------------------------------------------
+ */
+
+
+herr_t H5LT_get_attribute_mem( hid_t obj_id,
+ const char *attr_name,
+ hid_t mem_type_id,
+ void *data );
+
+herr_t H5LT_get_attribute_disk( hid_t obj_id,
+ const char *attr_name,
+ void *data );
+
+herr_t H5LT_find_attribute( hid_t loc_id, const char *name );
+
+
+herr_t H5LT_set_attribute_numerical( hid_t loc_id,
+ const char *obj_name,
+ const char *attr_name,
+ size_t size,
+ hid_t type_id,
+ const void *data );
+
+
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/hl/src/H5TA.c b/hl/src/H5TA.c
new file mode 100644
index 0000000..79a845b
--- /dev/null
+++ b/hl/src/H5TA.c
@@ -0,0 +1,3689 @@
+/****************************************************************************
+ * NCSA HDF *
+ * Scientific Data Technologies *
+ * National Center for Supercomputing Applications *
+ * University of Illinois at Urbana-Champaign *
+ * 605 E. Springfield, Champaign IL 61820 *
+ * *
+ * For conditions of distribution and use, see the accompanying *
+ * hdf/COPYING file. *
+ * *
+ ****************************************************************************/
+
+#include "H5TA.h"
+#include <stdlib.h>
+#include <string.h>
+
+#if 0
+#define SHRINK
+#endif
+
+
+/*-------------------------------------------------------------------------
+ *
+ * Private functions
+ *
+ *-------------------------------------------------------------------------
+ */
+
+int H5TB_find_field(const char *field,
+ const char *field_list);
+
+herr_t H5TB_attach_attributes(const char *table_title,
+ hid_t loc_id,
+ const char *dset_name,
+ hsize_t nfields,
+ hid_t tid );
+
+hid_t H5TB_create_type(hid_t loc_id,
+ const char *dset_name,
+ size_t dst_size,
+ const size_t *dst_offset,
+ const size_t *dst_sizes,
+ hid_t ftype_id);
+
+/*-------------------------------------------------------------------------
+ *
+ * Create functions
+ *
+ *-------------------------------------------------------------------------
+ */
+
+/*-------------------------------------------------------------------------
+ * Function: H5TBmake_table
+ *
+ * Purpose: Make a table
+ *
+ * Return: Success: 0, Failure: -1
+ *
+ * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
+ * Quincey Koziol
+ *
+ * Date: January 17, 2001
+ *
+ * Comments: The data is packed
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+
+
+herr_t H5TBmake_table( const char *table_title,
+ hid_t loc_id,
+ const char *dset_name,
+ hsize_t nfields,
+ hsize_t nrecords,
+ size_t type_size,
+ const char *field_names[],
+ const size_t *field_offset,
+ const hid_t *field_types,
+ hsize_t chunk_size,
+ void *fill_data,
+ int compress,
+ const void *data )
+{
+
+ hid_t did;
+ hid_t sid;
+ hid_t mem_type_id;
+ hid_t plist_id;
+ hsize_t dims[1];
+ hsize_t dims_chunk[1];
+ hsize_t maxdims[1] = { H5S_UNLIMITED };
+ char attr_name[255];
+ char *member_name;
+ hid_t attr_id;
+ char aux[255];
+ hsize_t i;
+ unsigned char *tmp_buf;
+
+ dims[0] = nrecords;
+ dims_chunk[0] = chunk_size;
+
+ /* Create the memory data type. */
+ if ((mem_type_id = H5Tcreate (H5T_COMPOUND, type_size )) < 0 )
+ return -1;
+
+ /* Insert fields. */
+ for ( i = 0; i < nfields; i++)
+ {
+ if ( H5Tinsert(mem_type_id, field_names[i], field_offset[i], field_types[i] ) < 0 )
+ return -1;
+ }
+
+ /* Create a simple data space with unlimited size */
+ if ( (sid = H5Screate_simple( 1, dims, maxdims )) < 0 )
+ return -1;
+
+ /* Modify dataset creation properties, i.e. enable chunking */
+ plist_id = H5Pcreate (H5P_DATASET_CREATE);
+ if ( H5Pset_chunk ( plist_id, 1, dims_chunk ) < 0 )
+ return -1;
+
+ /* Set the fill value using a struct as the data type. */
+ if ( fill_data )
+ {
+ if ( H5Pset_fill_value( plist_id, mem_type_id, fill_data ) < 0 )
+ return -1;
+ }
+
+ /*
+ Dataset creation property list is modified to use
+ GZIP compression with the compression effort set to 6.
+ Note that compression can be used only when dataset is chunked.
+ */
+ if ( compress )
+ {
+ if ( H5Pset_deflate( plist_id, 6) < 0 )
+ return -1;
+ }
+
+ /* Create the dataset. */
+ if ( (did = H5Dcreate( loc_id, dset_name, mem_type_id, sid, plist_id )) < 0 )
+ goto out;
+
+ /* Only write if there is something to write */
+ if ( data )
+ {
+ /* Write data to the dataset. */
+ if ( H5Dwrite( did, mem_type_id, H5S_ALL, H5S_ALL, H5P_DEFAULT, data ) < 0 )
+ goto out;
+ }
+
+ /* Terminate access to the data space. */
+ if ( H5Sclose( sid ) < 0 )
+ goto out;
+
+ /* End access to the dataset */
+ if ( H5Dclose( did ) < 0 )
+ goto out;
+
+ /* End access to the property list */
+ if ( H5Pclose( plist_id ) < 0 )
+ goto out;
+
+/*-------------------------------------------------------------------------
+ * Set the conforming table attributes
+ *-------------------------------------------------------------------------
+ */
+
+ /* Attach the CLASS attribute */
+ if ( H5LTset_attribute_string( loc_id, dset_name, "CLASS", "TABLE" ) < 0 )
+ goto out;
+
+ /* Attach the VERSION attribute */
+ if ( H5LTset_attribute_string( loc_id, dset_name, "VERSION", "2.0" ) < 0 )
+ goto out;
+
+ /* Attach the TITLE attribute */
+ if ( H5LTset_attribute_string( loc_id, dset_name, "TITLE", table_title ) < 0 )
+ goto out;
+
+ /* Attach the FIELD_ name attribute */
+ for ( i = 0; i < nfields; i++)
+ {
+
+ /* Get the member name */
+ member_name = H5Tget_member_name( mem_type_id,(unsigned) i );
+
+ strcpy( attr_name, "FIELD_" );
+ sprintf( aux, "%d", (int)i );
+ strcat( attr_name, aux );
+ sprintf( aux, "%s", "_NAME" );
+ strcat( attr_name, aux );
+
+ /* Attach the attribute */
+ if ( H5LTset_attribute_string( loc_id, dset_name, attr_name, member_name ) < 0 )
+ goto out;
+
+ free( member_name );
+
+ }
+
+ /* Attach the FIELD_ fill value attribute */
+ if ( fill_data )
+ {
+
+ tmp_buf = fill_data;
+
+ /* Open the dataset. */
+ if ( (did = H5Dopen( loc_id, dset_name )) < 0 )
+ return -1;
+
+ if (( sid = H5Screate(H5S_SCALAR)) < 0 )
+ goto out;
+
+ for ( i = 0; i < nfields; i++)
+ {
+
+ /* Get the member name */
+ member_name = H5Tget_member_name( mem_type_id, (unsigned) i );
+
+ strcpy( attr_name, "FIELD_" );
+ sprintf( aux, "%d", (int)i );
+ strcat( attr_name, aux );
+ sprintf( aux, "%s", "_FILL" );
+ strcat( attr_name, aux );
+
+ if ( (attr_id = H5Acreate( did, attr_name, field_types[i], sid, H5P_DEFAULT )) < 0 )
+ goto out;
+
+ if ( H5Awrite( attr_id, field_types[i], tmp_buf+field_offset[i] ) < 0 )
+ goto out;
+
+ if ( H5Aclose( attr_id ) < 0 )
+ goto out;
+
+ free( member_name );
+ }
+
+ /* Close the dataset. */
+ H5Dclose( did );
+
+ /* Close data space. */
+ H5Sclose( sid );
+ }
+
+ /* Release the datatype. */
+ if ( H5Tclose( mem_type_id ) < 0 )
+ return -1;
+
+
+return 0;
+
+/* error zone, gracefully close */
+out:
+ H5E_BEGIN_TRY {
+ H5Dclose(did);
+ H5Sclose(sid);
+ H5Pclose(plist_id);
+ H5Tclose(mem_type_id);
+ } H5E_END_TRY;
+ return -1;
+
+}
+
+/*-------------------------------------------------------------------------
+ *
+ * Write functions
+ *
+ *-------------------------------------------------------------------------
+ */
+
+/*-------------------------------------------------------------------------
+ * Function: H5TBappend_records
+ *
+ * Purpose: Appends records to a table
+ *
+ * Return: Success: 0, Failure: -1
+ *
+ * Programmers:
+ * Pedro Vicente, pvn@ncsa.uiuc.edu
+ * Quincey Koziol
+ *
+ * Date: November 19, 2001
+ *
+ * Comments: Uses memory offsets
+ *
+ * Modifications: April 1, 2004
+ * the DST_SIZES parameter is used to define the memory type ID
+ * returned by H5TB_create_type
+ *
+ *-------------------------------------------------------------------------
+ */
+
+herr_t H5TBappend_records( hid_t loc_id,
+ const char *dset_name,
+ hsize_t nrecords,
+ size_t dst_size,
+ const size_t *dst_offset,
+ const size_t *dst_sizes,
+ const void *data )
+{
+ hid_t did;
+ hid_t tid=-1;
+ hid_t mem_type_id=-1;
+ hsize_t count[1];
+ hssize_t offset[1];
+ hid_t sid=-1;
+ hid_t mem_space_id=-1;
+ int rank;
+ hsize_t dims[1];
+ hsize_t mem_dims[1];
+ hsize_t nrecords_orig;
+ hsize_t nfields;
+
+ /* Get the original number of records and fields */
+ if ( H5TBget_table_info ( loc_id, dset_name, &nfields, &nrecords_orig ) < 0 )
+ return -1;
+
+ /* Open the dataset. */
+ if ( (did = H5Dopen( loc_id, dset_name )) < 0 )
+ goto out;
+
+ /* Get the datatypes */
+ if ( (tid = H5Dget_type( did )) < 0 )
+ goto out;
+
+ if ((mem_type_id=H5TB_create_type(loc_id,dset_name,dst_size,dst_offset,dst_sizes,tid))<0)
+ goto out;
+
+ /* Extend the dataset */
+ dims[0] = nrecords_orig;
+ dims[0] += nrecords;
+
+ if ( H5Dextend ( did, dims ) < 0 )
+ goto out;
+
+ /* Create a simple memory data space */
+ mem_dims[0]=nrecords;
+ if ( (mem_space_id = H5Screate_simple( 1, mem_dims, NULL )) < 0 )
+ return -1;
+
+ /* Get the file data space */
+ if ( (sid = H5Dget_space( did )) < 0 )
+ return -1;
+
+ /* Get the dimensions */
+ if ( (rank = H5Sget_simple_extent_dims( sid, dims, NULL )) != 1 )
+ goto out;
+
+ /* Define a hyperslab in the dataset */
+ offset[0] = nrecords_orig;
+ count[0] = nrecords;
+ if ( H5Sselect_hyperslab( sid, H5S_SELECT_SET, offset, NULL, count, NULL) < 0 )
+ goto out;
+
+ if ( H5Dwrite( did, mem_type_id, mem_space_id, sid, H5P_DEFAULT, data ) < 0 )
+ goto out;
+
+ /* Terminate access to the dataspace */
+ if ( H5Sclose( mem_space_id ) < 0 )
+ goto out;
+
+ if ( H5Sclose( sid ) < 0 )
+ goto out;
+
+ /* Release the datatype. */
+ if ( H5Tclose( tid ) < 0 )
+ return -1;
+
+ /* Release the datatype. */
+ if ( H5Tclose( mem_type_id ) < 0 )
+ goto out;
+
+ /* End access to the dataset */
+ if ( H5Dclose( did ) < 0 )
+ goto out;
+
+
+return 0;
+
+/* error zone, gracefully close */
+out:
+ H5E_BEGIN_TRY {
+ H5Dclose(did);
+ H5Tclose(mem_type_id);
+ H5Tclose(tid);
+ H5Sclose(mem_space_id);
+ H5Sclose(sid);
+ } H5E_END_TRY;
+ return -1;
+}
+
+/*-------------------------------------------------------------------------
+ * Function: H5TBwrite_records
+ *
+ * Purpose: Writes records
+ *
+ * Return: Success: 0, Failure: -1
+ *
+ * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
+ *
+ * Date: November 19, 2001
+ *
+ * Comments: Uses memory offsets
+ *
+ * Modifications: April 1, 2004
+ * the DST_SIZES parameter is used to define the memory type ID
+ * returned by H5TB_create_type
+ *
+ *-------------------------------------------------------------------------
+ */
+
+
+herr_t H5TBwrite_records( hid_t loc_id,
+ const char *dset_name,
+ hsize_t start,
+ hsize_t nrecords,
+ size_t dst_size,
+ const size_t *dst_offset,
+ const size_t *dst_sizes,
+ const void *data )
+{
+
+ hid_t did;
+ hid_t tid;
+ hsize_t count[1];
+ hssize_t offset[1];
+ hid_t sid=-1;
+ hid_t mem_space_id=-1;
+ hsize_t mem_size[1];
+ hsize_t dims[1];
+ hid_t mem_type_id=-1;
+
+ /* Open the dataset. */
+ if ( (did = H5Dopen( loc_id, dset_name )) < 0 )
+ return -1;
+
+ /* Get the datatype */
+ if ( (tid = H5Dget_type( did )) < 0 )
+ goto out;
+
+ if ((mem_type_id=H5TB_create_type(loc_id,dset_name,dst_size,dst_offset,dst_sizes,tid))<0)
+ goto out;
+
+ /* Get the dataspace handle */
+ if ( (sid = H5Dget_space( did )) < 0 )
+ goto out;
+
+ /* Get records */
+ if ( H5Sget_simple_extent_dims( sid, dims, NULL) < 0 )
+ goto out;
+
+ if ( start + nrecords > dims[0] )
+ goto out;
+
+ /* Define a hyperslab in the dataset of the size of the records */
+ offset[0] = start;
+ count[0] = nrecords;
+ if ( H5Sselect_hyperslab( sid, H5S_SELECT_SET, offset, NULL, count, NULL) < 0 )
+ goto out;
+
+ /* Create a memory dataspace handle */
+ mem_size[0] = count[0];
+ if ( (mem_space_id = H5Screate_simple( 1, mem_size, NULL )) < 0 )
+ goto out;
+
+ if ( H5Dwrite( did, mem_type_id, mem_space_id, sid, H5P_DEFAULT, data ) < 0 )
+ goto out;
+
+ /* Terminate access to the memory dataspace */
+ if ( H5Sclose( mem_space_id ) < 0 )
+ goto out;
+
+ /* Terminate access to the dataspace */
+ if ( H5Sclose( sid ) < 0 )
+ goto out;
+
+ /* Release the datatype. */
+ if ( H5Tclose( tid ) < 0 )
+ goto out;
+
+ /* Release the datatype. */
+ if ( H5Tclose( mem_type_id ) < 0 )
+ return -1;
+
+ /* End access to the dataset */
+ if ( H5Dclose( did ) < 0 )
+ return -1;
+
+
+return 0;
+
+/* error zone, gracefully close */
+out:
+ H5E_BEGIN_TRY {
+ H5Dclose(did);
+ H5Tclose(mem_type_id);
+ H5Tclose(tid);
+ H5Sclose(mem_space_id);
+ H5Sclose(sid);
+ } H5E_END_TRY;
+ return -1;
+}
+
+/*-------------------------------------------------------------------------
+ * Function: H5TBwrite_fields_name
+ *
+ * Purpose: Writes fields
+ *
+ * Return: Success: 0, Failure: -1
+ *
+ * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
+ *
+ * Date: November 21, 2001
+ *
+ * Comments:
+ *
+ * Modifications: April 1, 2004
+ * the DST_SIZES parameter is used to define the memory type ID
+ * returned by H5TB_create_type
+ *
+ *-------------------------------------------------------------------------
+ */
+herr_t H5TBwrite_fields_name( hid_t loc_id,
+ const char *dset_name,
+ const char *field_names,
+ hsize_t start,
+ hsize_t nrecords,
+ size_t type_size,
+ const size_t *field_offset,
+ const size_t *dst_sizes,
+ const void *data )
+{
+
+ hid_t did;
+ hid_t tid=-1;
+ hid_t write_type_id=-1;
+ hid_t member_type_id;
+ hid_t nmtype_id;
+ hsize_t count[1];
+ hssize_t offset[1];
+ hid_t sid=-1;
+ char *member_name;
+ hssize_t nfields;
+ hssize_t i, j;
+ hid_t PRESERVE;
+ size_t size_native;
+
+ /* Create xfer properties to preserve initialized data */
+ if ((PRESERVE = H5Pcreate (H5P_DATASET_XFER))<0)
+ return -1;
+ if (H5Pset_preserve (PRESERVE, 1)<0)
+ return -1;
+
+ /* Open the dataset. */
+ if ( (did = H5Dopen( loc_id, dset_name )) < 0 )
+ goto out;
+
+ /* Get the datatype */
+ if ( (tid = H5Dget_type( did )) < 0 )
+ goto out;
+
+ /* Get the number of fields */
+ if ( ( nfields = H5Tget_nmembers( tid )) < 0 )
+ goto out;
+
+ /* Create a write id */
+ if ( ( write_type_id = H5Tcreate( H5T_COMPOUND, type_size )) < 0 )
+ goto out;
+
+ j = 0;
+
+ /* Iterate tru the members */
+ for ( i = 0; i < nfields; i++)
+ {
+ /* Get the member name */
+ member_name = H5Tget_member_name( tid, (unsigned)i );
+
+ if ( H5TB_find_field( member_name, field_names ) > 0 )
+ {
+
+ /* Get the member type */
+ if ( ( member_type_id = H5Tget_member_type( tid,(unsigned) i )) < 0 )
+ goto out;
+
+ /* Convert to native type */
+ if ((nmtype_id=H5Tget_native_type(member_type_id,H5T_DIR_DEFAULT))<0)
+ goto out;
+
+ size_native=H5Tget_size(nmtype_id);
+
+ /* Adjust, if necessary */
+ if (dst_sizes[j]!=size_native)
+ {
+ if (H5Tset_size(nmtype_id, dst_sizes[j])<0)
+ goto out;
+ }
+
+ /* The field in the file is found by its name */
+ if ( field_offset )
+ {
+ if ( H5Tinsert( write_type_id, member_name, field_offset[j], nmtype_id ) < 0 )
+ goto out;
+ }
+ /* Only one field */
+ else
+ {
+ if ( H5Tinsert( write_type_id, member_name, 0, nmtype_id ) < 0 )
+ goto out;
+ }
+
+ j++;
+
+ /* Close */
+ if ( H5Tclose( member_type_id ) < 0 )
+ goto out;
+ if ( H5Tclose( nmtype_id ) < 0 )
+ goto out;
+ }
+
+ free( member_name );
+
+ }
+
+ /* Get the dataspace handle */
+ if ( (sid = H5Dget_space( did )) < 0 )
+ goto out;
+
+ /* Define a hyperslab in the dataset */
+ offset[0] = start;
+ count[0] = nrecords;
+ if ( H5Sselect_hyperslab( sid, H5S_SELECT_SET, offset, NULL, count, NULL) < 0 )
+ goto out;
+
+ /* Write */
+ if ( H5Dwrite( did, write_type_id, H5S_ALL, sid, PRESERVE, data ) < 0 )
+ goto out;
+
+ /* End access to the write id */
+ if ( H5Tclose( write_type_id ) )
+ goto out;
+
+ /* Release the datatype. */
+ if ( H5Tclose( tid ) < 0 )
+ return -1;
+
+ /* End access to the dataset */
+ if ( H5Dclose( did ) < 0 )
+ return -1;
+
+ /* End access to the property list */
+ if ( H5Pclose( PRESERVE ) < 0 )
+ return -1;
+
+return 0;
+
+ /* error zone, gracefully close */
+out:
+ H5E_BEGIN_TRY {
+ H5Pclose(PRESERVE);
+ H5Dclose(did);
+ H5Sclose(sid);
+ H5Tclose(write_type_id);
+ H5Tclose(tid);
+ } H5E_END_TRY;
+ return -1;
+
+}
+
+
+
+/*-------------------------------------------------------------------------
+ * Function: H5TBwrite_fields_index
+ *
+ * Purpose: Writes fields
+ *
+ * Return: Success: 0, Failure: -1
+ *
+ * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
+ *
+ * Date: November 21, 2001
+ *
+ * Comments: Uses memory offsets
+ *
+ * Modifications: April 1, 2004
+ * the DST_SIZES parameter is used to define the memory type ID
+ * returned by H5TB_create_type
+ *
+ *-------------------------------------------------------------------------
+ */
+
+
+herr_t H5TBwrite_fields_index( hid_t loc_id,
+ const char *dset_name,
+ hsize_t nfields,
+ const int *field_index,
+ hsize_t start,
+ hsize_t nrecords,
+ size_t type_size,
+ const size_t *field_offset,
+ const size_t *dst_sizes,
+ const void *data )
+{
+
+ hid_t did;
+ hid_t tid=-1;
+ hid_t write_type_id=-1;
+ hid_t member_type_id;
+ hid_t nmtype_id;
+ hsize_t count[1];
+ hssize_t offset[1];
+ hid_t sid=-1;
+ char *member_name;
+ int nmenbers;
+ hsize_t i, j;
+ hid_t PRESERVE;
+ size_t size_native;
+
+ /* Create xfer properties to preserve initialized data */
+ if ((PRESERVE = H5Pcreate (H5P_DATASET_XFER))<0)
+ return -1;
+ if (H5Pset_preserve (PRESERVE, 1)<0)
+ return -1;
+
+ /* Open the dataset. */
+ if ( (did = H5Dopen( loc_id, dset_name )) < 0 )
+ goto out;
+
+ /* Get the datatype */
+ if ( (tid = H5Dget_type( did )) < 0 )
+ goto out;
+
+ /* Get the number of fields */
+ if ( ( nmenbers = H5Tget_nmembers( tid )) < 0 )
+ goto out;
+
+ /* Create a write id */
+ if ( ( write_type_id = H5Tcreate( H5T_COMPOUND, type_size )) < 0 )
+ goto out;
+
+
+ /* Iterate tru the members */
+ for ( i = 0; i < nfields; i++)
+ {
+
+ j = field_index[i];
+
+ /* Get the member name */
+ member_name = H5Tget_member_name( tid, (unsigned) j );
+
+ /* Get the member type */
+ if ( ( member_type_id = H5Tget_member_type( tid, (unsigned) j )) < 0 )
+ goto out;
+
+ /* Convert to native type */
+ if ((nmtype_id=H5Tget_native_type(member_type_id,H5T_DIR_DEFAULT))<0)
+ goto out;
+
+ size_native=H5Tget_size(nmtype_id);
+
+ if (dst_sizes[i]!=size_native)
+ {
+ if (H5Tset_size(nmtype_id, dst_sizes[i])<0)
+ goto out;
+ }
+
+ /* The field in the file is found by its name */
+ if ( field_offset )
+ {
+ if ( H5Tinsert( write_type_id, member_name, field_offset[ i ], nmtype_id ) < 0 )
+ goto out;
+ }
+ /* Only one field */
+ else
+ {
+ if ( H5Tinsert( write_type_id, member_name, 0, nmtype_id ) < 0 )
+ goto out;
+ }
+ /* Close */
+ if ( H5Tclose( member_type_id ) < 0 )
+ goto out;
+ if ( H5Tclose( nmtype_id ) < 0 )
+ goto out;
+
+ free( member_name );
+
+ }
+
+ /* Get the dataspace handle */
+ if ( (sid = H5Dget_space( did )) < 0 )
+ goto out;
+
+ /* Define a hyperslab in the dataset */
+ offset[0] = start;
+ count[0] = nrecords;
+ if ( H5Sselect_hyperslab( sid, H5S_SELECT_SET, offset, NULL, count, NULL) < 0 )
+ goto out;
+
+ /* Write */
+ if ( H5Dwrite( did, write_type_id, H5S_ALL, sid, PRESERVE, data ) < 0 )
+ goto out;
+
+ /* End access to the write id */
+ if ( H5Tclose( write_type_id ) )
+ goto out;
+
+ /* Release the datatype. */
+ if ( H5Tclose( tid ) < 0 )
+ return -1;
+
+ /* End access to the dataset */
+ if ( H5Dclose( did ) < 0 )
+ return -1;
+
+ /* End access to the property list */
+ if ( H5Pclose( PRESERVE ) < 0 )
+ return -1;
+
+return 0;
+
+ /* error zone, gracefully close */
+out:
+ H5E_BEGIN_TRY {
+ H5Pclose(PRESERVE);
+ H5Dclose(did);
+ H5Sclose(sid);
+ H5Tclose(write_type_id);
+ H5Tclose(tid);
+ } H5E_END_TRY;
+ return -1;
+}
+
+
+/*-------------------------------------------------------------------------
+ *
+ * Read functions
+ *
+ *-------------------------------------------------------------------------
+ */
+
+
+/*-------------------------------------------------------------------------
+ * Function: H5TBread_table
+ *
+ * Purpose: Reads a table
+ *
+ * Return: Success: 0, Failure: -1
+ *
+ * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
+ *
+ * Date: November 20, 2001
+ *
+ * Comments:
+ *
+ * Modifications: April 1, 2004
+ * used a memory type ID returned by H5TB_create_type
+ *
+ *-------------------------------------------------------------------------
+ */
+
+herr_t H5TBread_table( hid_t loc_id,
+ const char *dset_name,
+ size_t dst_size,
+ const size_t *dst_offset,
+ const size_t *dst_sizes,
+ void *dst_buf )
+{
+ hid_t did;
+ hid_t ftype_id=-1;
+ hid_t mem_type_id=-1;
+ hid_t sid;
+ hsize_t dims[1];
+
+ /* open the dataset. */
+ if ((did=H5Dopen(loc_id,dset_name))<0)
+ return -1;
+
+ /* get the dataspace handle */
+ if ( (sid = H5Dget_space( did )) < 0 )
+ goto out;
+
+ /* get dimensions */
+ if ( H5Sget_simple_extent_dims( sid, dims, NULL) < 0 )
+ goto out;
+
+ /* get the datatypes */
+ if ((ftype_id=H5Dget_type (did))<0)
+ goto out;
+
+ if ((mem_type_id=H5TB_create_type(loc_id,dset_name,dst_size,dst_offset,dst_sizes,ftype_id))<0)
+ goto out;
+
+ /* read */
+ if ( H5Dread( did, mem_type_id, H5S_ALL, H5S_ALL, H5P_DEFAULT, dst_buf) < 0 )
+ goto out;
+
+ /* close */
+ if ( H5Tclose( ftype_id ) < 0 )
+ goto out;
+ if ( H5Tclose( mem_type_id ) < 0 )
+ goto out;
+ if ( H5Sclose( sid ) < 0 )
+ goto out;
+ if ( H5Dclose( did ) < 0 )
+ return -1;
+
+ return 0;
+
+ /* error zone, gracefully close */
+out:
+ H5E_BEGIN_TRY {
+ H5Dclose(did);
+ H5Tclose(mem_type_id);
+ H5Tclose(ftype_id);
+ H5Sclose(sid);
+ } H5E_END_TRY;
+ return -1;
+}
+
+/*-------------------------------------------------------------------------
+ * Function: H5TBread_records
+ *
+ * Purpose: Reads records
+ *
+ * Return: Success: 0, Failure: -1
+ *
+ * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
+ *
+ * Date: November 19, 2001
+ *
+ * Comments:
+ *
+ * Modifications: April 1, 2004
+ * the DST_SIZES parameter is used to define the memory type ID
+ * returned by H5TB_create_type
+ *
+ *-------------------------------------------------------------------------
+ */
+
+
+herr_t H5TBread_records( hid_t loc_id,
+ const char *dset_name,
+ hsize_t start,
+ hsize_t nrecords,
+ size_t dst_size,
+ const size_t *dst_offset,
+ const size_t *dst_sizes,
+ void *data )
+{
+
+ hid_t did;
+ hid_t ftype_id;
+ hid_t mem_type_id=-1;
+ hsize_t count[1];
+ hssize_t offset[1];
+ hid_t sid=-1;
+ hsize_t dims[1];
+ hid_t mem_space_id=-1;
+ hsize_t mem_size[1];
+ hsize_t nrecords_orig;
+ hsize_t nfields;
+
+ /* get the number of records and fields */
+ if ( H5TBget_table_info ( loc_id, dset_name, &nfields, &nrecords_orig ) < 0 )
+ return -1;
+
+ /* open the dataset */
+ if ( (did = H5Dopen( loc_id, dset_name )) < 0 )
+ return -1;
+
+ /* get the datatypes */
+ if ( (ftype_id = H5Dget_type( did )) < 0 )
+ goto out;
+
+ if ((mem_type_id=H5TB_create_type(loc_id,dset_name,dst_size,dst_offset,dst_sizes,ftype_id))<0)
+ goto out;
+
+ /* get the dataspace handle */
+ if ( (sid = H5Dget_space( did )) < 0 )
+ goto out;
+
+ /* get records */
+ if ( H5Sget_simple_extent_dims( sid, dims, NULL) < 0 )
+ goto out;
+
+ if ( start + nrecords > dims[0] )
+ goto out;
+
+ /* define a hyperslab in the dataset of the size of the records */
+ offset[0] = start;
+ count[0] = nrecords;
+ if ( H5Sselect_hyperslab( sid, H5S_SELECT_SET, offset, NULL, count, NULL) < 0 )
+ goto out;
+
+ /* create a memory dataspace handle */
+ mem_size[0] = count[0];
+ if ( (mem_space_id = H5Screate_simple( 1, mem_size, NULL )) < 0 )
+ goto out;
+
+ /* read */
+ if ( H5Dread( did, mem_type_id, mem_space_id, sid, H5P_DEFAULT, data ) < 0 )
+ goto out;
+
+ /* close */
+ if ( H5Sclose( mem_space_id ) < 0 )
+ goto out;
+ if ( H5Sclose( sid ) < 0 )
+ goto out;
+ if ( H5Tclose( ftype_id ) < 0 )
+ return -1;
+ if ( H5Tclose( mem_type_id ) < 0 )
+ return -1;
+ if ( H5Dclose( did ) < 0 )
+ return -1;
+
+ return 0;
+
+ /* error zone, gracefully close */
+out:
+ H5E_BEGIN_TRY {
+ H5Dclose(did);
+ H5Tclose(mem_type_id);
+ H5Tclose(ftype_id);
+ H5Sclose(mem_space_id);
+ H5Sclose(sid);
+ } H5E_END_TRY;
+ return -1;
+
+}
+
+
+/*-------------------------------------------------------------------------
+ * Function: H5TBread_fields_name
+ *
+ * Purpose: Reads fields
+ *
+ * Return: Success: 0, Failure: -1
+ *
+ * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
+ *
+ * Date: November 19, 2001
+ *
+ * Comments:
+ *
+ * Modifications: April 1, 2004
+ * the DST_SIZES parameter is used to define the memory type ID
+ * returned by H5TB_create_type
+ *
+ *-------------------------------------------------------------------------
+ */
+
+
+herr_t H5TBread_fields_name( hid_t loc_id,
+ const char *dset_name,
+ const char *field_names,
+ hsize_t start,
+ hsize_t nrecords,
+ size_t type_size,
+ const size_t *field_offset,
+ const size_t *dst_sizes,
+ void *data )
+{
+
+ hid_t did;
+ hid_t ftype_id=-1;
+ hid_t mem_type_id=-1;
+ hid_t mtype_id;
+ hid_t nmtype_id;
+ char *member_name;
+ hssize_t nfields;
+ hsize_t count[1];
+ hssize_t offset[1];
+ hid_t sid=-1;
+ hid_t mem_space_id=-1;
+ hsize_t mem_size[1];
+ size_t size_native;
+ hssize_t i, j;
+
+ /* open the dataset */
+ if ( (did = H5Dopen( loc_id, dset_name )) < 0 )
+ goto out;
+
+ /* get the datatype */
+ if ( (ftype_id = H5Dget_type( did )) < 0 )
+ goto out;
+
+ /* get the number of fields */
+ if ( ( nfields = H5Tget_nmembers( ftype_id )) < 0 )
+ goto out;
+
+ /* create a memory read id */
+ if ( ( mem_type_id = H5Tcreate( H5T_COMPOUND, type_size )) < 0 )
+ goto out;
+
+ /* iterate tru the members */
+ for ( i=0,j=0; i<nfields; i++)
+ {
+ /* get the member name */
+ member_name = H5Tget_member_name( ftype_id, (unsigned)i );
+
+ if ( H5TB_find_field( member_name, field_names ) > 0 )
+ {
+ /* get the member type */
+ if ( ( mtype_id = H5Tget_member_type( ftype_id, (unsigned) i )) < 0 )
+ goto out;
+
+ /* convert to native type */
+ if ((nmtype_id=H5Tget_native_type(mtype_id,H5T_DIR_DEFAULT))<0)
+ goto out;
+
+ size_native=H5Tget_size(nmtype_id);
+
+ if (dst_sizes[j]!=size_native)
+ {
+ if (H5Tset_size(nmtype_id, dst_sizes[j])<0)
+ goto out;
+ }
+ /* the field in the file is found by its name */
+ if ( field_offset )
+ {
+ if ( H5Tinsert( mem_type_id, member_name, field_offset[j], nmtype_id ) < 0 )
+ goto out;
+ }
+ else
+ {
+ if ( H5Tinsert( mem_type_id, member_name, 0, nmtype_id ) < 0 )
+ goto out;
+ }
+
+ /* close */
+ if ( H5Tclose( mtype_id ) < 0 )
+ goto out;
+ if ( H5Tclose( nmtype_id ) < 0 )
+ goto out;
+ j++;
+ }
+ free( member_name );
+ }
+
+ /* get the dataspace handle */
+ if ( (sid = H5Dget_space( did )) < 0 )
+ goto out;
+
+ /* define a hyperslab in the dataset */
+ offset[0] = start;
+ count[0] = nrecords;
+ if ( H5Sselect_hyperslab( sid, H5S_SELECT_SET, offset, NULL, count, NULL) < 0 )
+ goto out;
+
+ /* create a memory dataspace handle */
+ mem_size[0] = count[0];
+ if ( (mem_space_id = H5Screate_simple( 1, mem_size, NULL )) < 0 )
+ goto out;
+
+ /* read */
+ if ( H5Dread( did, mem_type_id, mem_space_id, sid, H5P_DEFAULT, data ) < 0 )
+ goto out;
+
+ /* close */
+ if ( H5Tclose( mem_type_id ) )
+ goto out;
+ if ( H5Tclose( ftype_id ) < 0 )
+ return -1;
+ if ( H5Sclose( sid ) < 0 )
+ goto out;
+ if ( H5Sclose( mem_space_id ) < 0 )
+ goto out;
+ if ( H5Dclose( did ) < 0 )
+ return -1;
+
+ return 0;
+
+/* error zone, gracefully close */
+out:
+ H5E_BEGIN_TRY {
+ H5Dclose(did);
+ H5Tclose(mem_type_id);
+ H5Tclose(ftype_id);
+ H5Sclose(mem_space_id);
+ H5Sclose(sid);
+ } H5E_END_TRY;
+ return -1;
+
+}
+
+
+/*-------------------------------------------------------------------------
+ * Function: H5TBread_fields_index
+ *
+ * Purpose: Reads fields
+ *
+ * Return: Success: 0, Failure: -1
+ *
+ * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
+ *
+ * Date: November 19, 2001
+ *
+ * Comments:
+ *
+ * Modifications: April 1, 2004
+ * the DST_SIZES parameter is used to define the memory type ID
+ * returned by H5TB_create_type
+ *
+ *-------------------------------------------------------------------------
+ */
+
+
+herr_t H5TBread_fields_index( hid_t loc_id,
+ const char *dset_name,
+ hsize_t nfields,
+ const int *field_index,
+ hsize_t start,
+ hsize_t nrecords,
+ size_t type_size,
+ const size_t *field_offset,
+ const size_t *dst_sizes,
+ void *data )
+{
+
+ hid_t did;
+ hid_t tid=-1;
+ hid_t read_type_id=-1;
+ hid_t member_type_id;
+ hid_t nmtype_id;
+ hssize_t member_size;
+ char *member_name;
+ hsize_t count[1];
+ hssize_t offset[1];
+ hid_t sid=-1;
+ hid_t mem_space_id=-1;
+ hsize_t mem_size[1];
+ size_t size_native;
+ hsize_t i, j;
+
+ /* Open the dataset. */
+ if ( (did = H5Dopen( loc_id, dset_name )) < 0 )
+ goto out;
+
+ /* Get the datatype */
+ if ( (tid = H5Dget_type( did )) < 0 )
+ goto out;
+
+ /* Create a read id */
+ if ( ( read_type_id = H5Tcreate( H5T_COMPOUND, type_size )) < 0 )
+ goto out;
+
+ /* Iterate tru the members */
+ for ( i = 0; i < nfields; i++)
+ {
+ j = field_index[i];
+
+ /* Get the member name */
+ member_name = H5Tget_member_name( tid, (unsigned) j );
+
+ /* Get the member type */
+ if ( ( member_type_id = H5Tget_member_type( tid, (unsigned) j )) < 0 )
+ goto out;
+
+ /* Get the member size */
+ if ( ( member_size = H5Tget_size( member_type_id )) < 0 )
+ goto out;
+
+ /* Convert to native type */
+ if ((nmtype_id=H5Tget_native_type(member_type_id,H5T_DIR_DEFAULT))<0)
+ goto out;
+
+ size_native=H5Tget_size(nmtype_id);
+
+ if (dst_sizes[i]!=size_native)
+ {
+ if (H5Tset_size(nmtype_id, dst_sizes[i])<0)
+ goto out;
+ }
+
+ /* The field in the file is found by its name */
+ if ( field_offset )
+ {
+ if ( H5Tinsert( read_type_id, member_name, field_offset[i], nmtype_id ) < 0 )
+ goto out;
+ }
+ else
+ {
+ if ( H5Tinsert( read_type_id, member_name, 0, nmtype_id ) < 0 )
+ goto out;
+ }
+
+ /* Close the member type */
+ if ( H5Tclose( member_type_id ) < 0 )
+ goto out;
+ if ( H5Tclose( nmtype_id ) < 0 )
+ goto out;
+
+ free( member_name );
+ }
+
+ /* Get the dataspace handle */
+ if ( (sid = H5Dget_space( did )) < 0 )
+ goto out;
+
+ /* Define a hyperslab in the dataset */
+ offset[0] = start;
+ count[0] = nrecords;
+ if ( H5Sselect_hyperslab( sid, H5S_SELECT_SET, offset, NULL, count, NULL) < 0 )
+ goto out;
+
+ /* Create a memory dataspace handle */
+ mem_size[0] = count[0];
+ if ( (mem_space_id = H5Screate_simple( 1, mem_size, NULL )) < 0 )
+ goto out;
+
+ /* Read */
+ if ( H5Dread( did, read_type_id, mem_space_id, sid, H5P_DEFAULT, data ) < 0 )
+ goto out;
+
+ /* Terminate access to the dataspace */
+ if ( H5Sclose( sid ) < 0 )
+ goto out;
+
+ /* Terminate access to the memory dataspace */
+ if ( H5Sclose( mem_space_id ) < 0 )
+ goto out;
+
+ /* End access to the read id */
+ if ( H5Tclose( read_type_id ) )
+ goto out;
+
+ /* Release the datatype. */
+ if ( H5Tclose( tid ) < 0 )
+ return -1;
+
+ /* End access to the dataset */
+ if ( H5Dclose( did ) < 0 )
+ return -1;
+
+return 0;
+
+/* error zone, gracefully close */
+out:
+ H5E_BEGIN_TRY {
+ H5Dclose(did);
+ H5Tclose(read_type_id);
+ H5Tclose(tid);
+ H5Sclose(mem_space_id);
+ H5Sclose(sid);
+ } H5E_END_TRY;
+ return -1;
+
+}
+
+
+/*-------------------------------------------------------------------------
+ *
+ * Manipulation functions
+ *
+ *-------------------------------------------------------------------------
+ */
+
+/*-------------------------------------------------------------------------
+ * Function: H5TBdelete_record
+ *
+ * Purpose: Delete records from middle of table ("pulling up" all the records after it)
+ *
+ * Return: Success: 0, Failure: -1
+ *
+ * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
+ *
+ * Date: November 26, 2001
+ *
+ * Modifications: April 29, 2003
+ *
+ *
+ *-------------------------------------------------------------------------
+ */
+
+herr_t H5TBdelete_record( hid_t loc_id,
+ const char *dset_name,
+ hsize_t start,
+ hsize_t nrecords )
+{
+
+ hsize_t nfields;
+ hsize_t ntotal_records;
+ hsize_t read_start;
+ hsize_t read_nrecords;
+ hid_t did;
+ hid_t tid;
+ hsize_t count[1];
+ hssize_t offset[1];
+ hid_t sid;
+ hid_t mem_space_id;
+ hsize_t mem_size[1];
+ unsigned char *tmp_buf;
+ size_t src_size;
+ size_t *src_offset;
+ size_t *src_sizes;
+ hsize_t nrows;
+#if defined (SHRINK)
+ hsize_t dims[1];
+#endif
+
+
+/*-------------------------------------------------------------------------
+ * First we get information about type size and offsets on disk
+ *-------------------------------------------------------------------------
+ */
+
+ /* Get the number of records and fields */
+ if ( H5TBget_table_info ( loc_id, dset_name, &nfields, &ntotal_records ) < 0 )
+ return -1;
+
+ src_offset = (size_t *)malloc((size_t)nfields * sizeof(size_t));
+ src_sizes = (size_t *)malloc((size_t)nfields * sizeof(size_t));
+
+ if ( src_offset == NULL )
+ return -1;
+
+ /* Get field info */
+ if ( H5TBget_field_info( loc_id, dset_name, NULL, src_sizes, src_offset, &src_size ) < 0 )
+ return -1;
+
+/*-------------------------------------------------------------------------
+ * Read the records after the deleted one(s)
+ *-------------------------------------------------------------------------
+ */
+
+ read_start = start + nrecords;
+ read_nrecords = ntotal_records - read_start;
+ tmp_buf = (unsigned char *)calloc((size_t) read_nrecords, src_size );
+
+ if ( tmp_buf == NULL )
+ return -1;
+
+ /* Read the records after the deleted one(s) */
+ if ( H5TBread_records( loc_id, dset_name, read_start, read_nrecords, src_size,
+ src_offset, src_sizes, tmp_buf ) < 0 )
+ return -1;
+
+
+/*-------------------------------------------------------------------------
+ * Write the records in another position
+ *-------------------------------------------------------------------------
+ */
+
+ /* Open the dataset. */
+ if ( (did = H5Dopen( loc_id, dset_name )) < 0 )
+ return -1;
+
+ /* Get the datatype */
+ if ( (tid = H5Dget_type( did )) < 0 )
+ goto out;
+
+ /* Get the dataspace handle */
+ if ( (sid = H5Dget_space( did )) < 0 )
+ goto out;
+
+ /* Define a hyperslab in the dataset of the size of the records */
+ offset[0] = start;
+ count[0] = read_nrecords;
+ if ( H5Sselect_hyperslab( sid, H5S_SELECT_SET, offset, NULL, count, NULL) < 0 )
+ goto out;
+
+ /* Create a memory dataspace handle */
+ mem_size[0] = count[0];
+ if ( (mem_space_id = H5Screate_simple( 1, mem_size, NULL )) < 0 )
+ goto out;
+
+ if ( H5Dwrite( did, tid, mem_space_id, sid, H5P_DEFAULT, tmp_buf ) < 0 )
+ goto out;
+
+ /* Terminate access to the memory dataspace */
+ if ( H5Sclose( mem_space_id ) < 0 )
+ goto out;
+
+ /* Terminate access to the dataspace */
+ if ( H5Sclose( sid ) < 0 )
+ goto out;
+
+ /* Release the datatype. */
+ if ( H5Tclose( tid ) < 0 )
+ goto out;
+
+
+/*-------------------------------------------------------------------------
+ * Change the table dimension
+ *-------------------------------------------------------------------------
+ */
+#if defined (SHRINK)
+ dims[0] = ntotal_records - nrecords;
+ if ( H5Dset_extent( did, dims ) < 0 )
+ goto out;
+#endif
+
+ /* End access to the dataset */
+ if ( H5Dclose( did ) < 0 )
+ return -1;
+
+ free( tmp_buf );
+ free( src_offset );
+ free( src_sizes );
+
+
+/*-------------------------------------------------------------------------
+ * Store the new dimension as an attribute
+ *-------------------------------------------------------------------------
+ */
+
+ nrows = ntotal_records - nrecords;
+ /* Set the attribute */
+ if (H5LT_set_attribute_numerical(loc_id,dset_name,"NROWS",1,
+ H5T_NATIVE_LLONG,&nrows)<0)
+ return -1;
+
+
+ return 0;
+
+out:
+ H5Dclose( did );
+ return -1;
+}
+
+/*-------------------------------------------------------------------------
+ * Function: H5TBinsert_record
+ *
+ * Purpose: Inserts records into middle of table ("pushing down" all the records after it)
+ *
+ * Return: Success: 0, Failure: -1
+ *
+ * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
+ *
+ * Date: November 26, 2001
+ *
+ * Comments: Uses memory offsets
+ *
+ * Modifications: April 1, 2004
+ * the DST_SIZES parameter is used to define the memory type ID
+ * returned by H5TB_create_type
+ *
+ *-------------------------------------------------------------------------
+ */
+
+
+herr_t H5TBinsert_record( hid_t loc_id,
+ const char *dset_name,
+ hsize_t start,
+ hsize_t nrecords,
+ size_t dst_size,
+ const size_t *dst_offset,
+ const size_t *dst_sizes,
+ void *data )
+{
+
+ hsize_t nfields;
+ hsize_t ntotal_records;
+ hsize_t read_nrecords;
+ hid_t did;
+ hid_t tid=-1;
+ hid_t mem_type_id=-1;
+ hsize_t count[1];
+ hssize_t offset[1];
+ hid_t sid=-1;
+ hid_t mem_space_id=-1;
+ hsize_t dims[1];
+ hsize_t mem_dims[1];
+ unsigned char *tmp_buf;
+
+/*-------------------------------------------------------------------------
+ * Read the records after the inserted one(s)
+ *-------------------------------------------------------------------------
+ */
+
+ /* Get the dimensions */
+ if ( H5TBget_table_info ( loc_id, dset_name, &nfields, &ntotal_records ) < 0 )
+ return -1;
+
+ /* Open the dataset. */
+ if ( (did = H5Dopen( loc_id, dset_name )) < 0 )
+ goto out;
+
+ /* Get the datatype */
+ if ( (tid = H5Dget_type( did )) < 0 )
+ goto out;
+
+ /* Create the memory data type. */
+ if ((mem_type_id=H5TB_create_type(loc_id,dset_name,dst_size,dst_offset,dst_sizes,tid))<0)
+ goto out;
+
+ read_nrecords = ntotal_records - start;
+ tmp_buf = (unsigned char *)calloc((size_t) read_nrecords, dst_size );
+
+ /* Read the records after the inserted one(s) */
+ if ( H5TBread_records( loc_id, dset_name, start, read_nrecords, dst_size, dst_offset,
+ dst_sizes, tmp_buf ) < 0 )
+ return -1;
+
+ /* Extend the dataset */
+ dims[0] = ntotal_records + nrecords;
+
+ if ( H5Dextend ( did, dims ) < 0 )
+ goto out;
+
+/*-------------------------------------------------------------------------
+ * Write the inserted records
+ *-------------------------------------------------------------------------
+ */
+
+ /* Create a simple memory data space */
+ mem_dims[0]=nrecords;
+ if ( (mem_space_id = H5Screate_simple( 1, mem_dims, NULL )) < 0 )
+ return -1;
+
+ /* Get the file data space */
+ if ( (sid = H5Dget_space( did )) < 0 )
+ return -1;
+
+ /* Define a hyperslab in the dataset to write the new data */
+ offset[0] = start;
+ count[0] = nrecords;
+ if ( H5Sselect_hyperslab( sid, H5S_SELECT_SET, offset, NULL, count, NULL) < 0 )
+ goto out;
+
+ if ( H5Dwrite( did, mem_type_id, mem_space_id, sid, H5P_DEFAULT, data ) < 0 )
+ goto out;
+
+ /* Terminate access to the dataspace */
+ if ( H5Sclose( mem_space_id ) < 0 )
+ goto out;
+ if ( H5Sclose( sid ) < 0 )
+ goto out;
+
+/*-------------------------------------------------------------------------
+ * Write the "pushed down" records
+ *-------------------------------------------------------------------------
+ */
+
+ /* Create a simple memory data space */
+ mem_dims[0]=read_nrecords;
+ if ( (mem_space_id = H5Screate_simple( 1, mem_dims, NULL )) < 0 )
+ return -1;
+
+ /* Get the file data space */
+ if ( (sid = H5Dget_space( did )) < 0 )
+ return -1;
+
+ /* Define a hyperslab in the dataset to write the new data */
+ offset[0] = start + nrecords;
+ count[0] = read_nrecords;
+ if ( H5Sselect_hyperslab( sid, H5S_SELECT_SET, offset, NULL, count, NULL) < 0 )
+ goto out;
+
+ if ( H5Dwrite( did, mem_type_id, mem_space_id, sid, H5P_DEFAULT, tmp_buf ) < 0 )
+ goto out;
+
+ /* Terminate access to the dataspace */
+ if ( H5Sclose( mem_space_id ) < 0 )
+ goto out;
+
+ if ( H5Sclose( sid ) < 0 )
+ goto out;
+
+ /* Release the datatype. */
+ if ( H5Tclose( tid ) < 0 )
+ return -1;
+
+ /* Release the datatype. */
+ if ( H5Tclose( mem_type_id ) < 0 )
+ return -1;
+
+ /* End access to the dataset */
+ if ( H5Dclose( did ) < 0 )
+ return -1;
+
+ free( tmp_buf );
+
+ return 0;
+
+ /* error zone, gracefully close */
+out:
+ H5E_BEGIN_TRY {
+ H5Dclose(did);
+ H5Sclose(sid);
+ H5Sclose(mem_space_id);
+ H5Tclose(mem_type_id);
+ H5Tclose(tid);
+ } H5E_END_TRY;
+ return -1;
+}
+
+/*-------------------------------------------------------------------------
+ * Function: H5TBadd_records_from
+ *
+ * Purpose: Add records from first table to second table
+ *
+ * Return: Success: 0, Failure: -1
+ *
+ * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
+ *
+ * Date: December 5, 2001
+ *
+ * Comments:
+ *
+ * Modifications:
+ *
+ *
+ *-------------------------------------------------------------------------
+ */
+
+herr_t H5TBadd_records_from( hid_t loc_id,
+ const char *dset_name1,
+ hsize_t start1,
+ hsize_t nrecords,
+ const char *dset_name2,
+ hsize_t start2 )
+{
+
+ /* Identifiers for the 1st dataset. */
+ hid_t dataset_id1;
+ hid_t type_id1;
+ hid_t space_id1=-1;
+ hid_t mem_space_id1=-1;
+ hssize_t type_size1;
+
+ hsize_t count[1];
+ hssize_t offset[1];
+ hsize_t mem_size[1];
+ hsize_t nfields;
+ hsize_t ntotal_records;
+ unsigned char *tmp_buf;
+ size_t src_size;
+ size_t *src_offset;
+ size_t *src_sizes;
+
+/*-------------------------------------------------------------------------
+ * First we get information about type size and offsets on disk
+ *-------------------------------------------------------------------------
+ */
+
+ /* Get the number of records and fields */
+ if ( H5TBget_table_info ( loc_id, dset_name1, &nfields, &ntotal_records ) < 0 )
+ return -1;
+
+ src_offset = (size_t *)malloc((size_t)nfields * sizeof(size_t));
+ src_sizes = (size_t *)malloc((size_t)nfields * sizeof(size_t));
+
+ if ( src_offset == NULL )
+ return -1;
+
+ /* Get field info */
+ if ( H5TBget_field_info( loc_id, dset_name1, NULL, src_sizes, src_offset, &src_size ) < 0 )
+ return -1;
+
+/*-------------------------------------------------------------------------
+ * Get information about the first table and read it
+ *-------------------------------------------------------------------------
+ */
+
+ /* Open the 1st dataset. */
+ if ( (dataset_id1 = H5Dopen( loc_id, dset_name1 )) < 0 )
+ return -1;
+
+ /* Get the datatype */
+ if ( (type_id1 = H5Dget_type( dataset_id1 )) < 0 )
+ goto out;
+
+ /* Get the dataspace handle */
+ if ( (space_id1 = H5Dget_space( dataset_id1 )) < 0 )
+ goto out;
+
+ /* Get the size of the datatype */
+ if ( ( type_size1 = H5Tget_size( type_id1 )) < 0 )
+ goto out;
+
+ tmp_buf = (unsigned char *)calloc((size_t)nrecords, (size_t)type_size1 );
+
+ /* Define a hyperslab in the dataset of the size of the records */
+ offset[0] = start1;
+ count[0] = nrecords;
+ if ( H5Sselect_hyperslab( space_id1, H5S_SELECT_SET, offset, NULL, count, NULL) < 0 )
+ goto out;
+
+ /* Create a memory dataspace handle */
+ mem_size[0] = count[0];
+ if ( (mem_space_id1 = H5Screate_simple( 1, mem_size, NULL )) < 0 )
+ goto out;
+
+ if ( H5Dread( dataset_id1, type_id1, mem_space_id1, space_id1, H5P_DEFAULT, tmp_buf ) < 0 )
+ goto out;
+
+/*-------------------------------------------------------------------------
+ * Add to the second table
+ *-------------------------------------------------------------------------
+ */
+ if ( H5TBinsert_record(loc_id,dset_name2,start2,nrecords,src_size,src_offset,src_sizes,tmp_buf ) < 0 )
+ goto out;
+
+/*-------------------------------------------------------------------------
+ * Close resources for table 1
+ *-------------------------------------------------------------------------
+ */
+
+ /* Terminate access to the memory dataspace */
+ if ( H5Sclose( mem_space_id1 ) < 0 )
+ goto out;
+
+ /* Terminate access to the dataspace */
+ if ( H5Sclose( space_id1 ) < 0 )
+ goto out;
+
+ /* Release the datatype. */
+ if ( H5Tclose( type_id1 ) < 0 )
+ return -1;
+
+ /* End access to the dataset */
+ if ( H5Dclose( dataset_id1 ) < 0 )
+ return -1;
+
+ free( tmp_buf );
+ free( src_offset );
+ free( src_sizes );
+
+return 0;
+
+ /* error zone, gracefully close */
+out:
+ H5E_BEGIN_TRY {
+ H5Dclose(dataset_id1);
+ H5Sclose(space_id1);
+ H5Sclose(mem_space_id1);
+ H5Tclose(type_id1);
+ } H5E_END_TRY;
+ return -1;
+
+}
+
+/*-------------------------------------------------------------------------
+ * Function: H5TBcombine_tables
+ *
+ * Purpose: Combine records from two tables into a third
+ *
+ * Return: Success: 0, Failure: -1
+ *
+ * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
+ *
+ * Date: December 10, 2001
+ *
+ * Comments:
+ *
+ * Modifications:
+ *
+ *
+ *-------------------------------------------------------------------------
+ */
+herr_t H5TBcombine_tables( hid_t loc_id1,
+ const char *dset_name1,
+ hid_t loc_id2,
+ const char *dset_name2,
+ const char *dset_name3 )
+{
+
+ /* Identifiers for the 1st dataset. */
+ hid_t dataset_id1;
+ hid_t type_id1;
+ hid_t space_id1;
+ hid_t plist_id1;
+
+ /* Identifiers for the 2nd dataset. */
+ hid_t dataset_id2;
+ hid_t type_id2;
+ hid_t space_id2;
+ hid_t plist_id2;
+
+ /* Identifiers for the 3rd dataset. */
+ hid_t dataset_id3;
+ hid_t type_id3;
+ hid_t space_id3;
+ hid_t plist_id3;
+
+ hsize_t count[1];
+ hssize_t offset[1];
+ hid_t mem_space_id;
+ hsize_t mem_size[1];
+ hsize_t nfields;
+ hsize_t nrecords;
+ hsize_t dims[1];
+ hsize_t maxdims[1] = { H5S_UNLIMITED };
+
+
+ size_t type_size;
+ hid_t sid;
+ hid_t member_type_id;
+ hssize_t member_offset;
+ char attr_name[255];
+ hid_t attr_id;
+ char aux[255];
+ unsigned char *tmp_buf;
+ unsigned char *tmp_fill_buf;
+ hsize_t i;
+ size_t src_size;
+ size_t *src_offset;
+ size_t *src_sizes;
+ int has_fill=0;
+
+/*-------------------------------------------------------------------------
+ * First we get information about type size and offsets on disk
+ *-------------------------------------------------------------------------
+ */
+
+ /* Get the number of records and fields */
+ if ( H5TBget_table_info ( loc_id1, dset_name1, &nfields, &nrecords ) < 0 )
+ return -1;
+
+ src_offset = (size_t *)malloc((size_t)nfields * sizeof(size_t));
+ src_sizes = (size_t *)malloc((size_t)nfields * sizeof(size_t));
+
+
+ if ( src_offset == NULL )
+ return -1;
+
+ /* Get field info */
+ if ( H5TBget_field_info( loc_id1, dset_name1, NULL, src_sizes, src_offset, &src_size ) < 0 )
+ return -1;
+
+/*-------------------------------------------------------------------------
+ * Get information about the first table
+ *-------------------------------------------------------------------------
+ */
+
+ /* Open the 1st dataset. */
+ if ( (dataset_id1 = H5Dopen( loc_id1, dset_name1 )) < 0 )
+ goto out;
+
+ /* Get the datatype */
+ if ( (type_id1 = H5Dget_type( dataset_id1 )) < 0 )
+ goto out;
+
+ /* Get the dataspace handle */
+ if ( (space_id1 = H5Dget_space( dataset_id1 )) < 0 )
+ goto out;
+
+ /* Get creation properties list */
+ if ( (plist_id1 = H5Dget_create_plist( dataset_id1 )) < 0 )
+ goto out;
+
+ /* Get the dimensions */
+ if ( H5TBget_table_info ( loc_id1, dset_name1, &nfields, &nrecords ) < 0 )
+ return -1;
+
+/*-------------------------------------------------------------------------
+ * Make the merged table with no data originally
+ *-------------------------------------------------------------------------
+ */
+
+ /* Clone the property list */
+ if ( ( plist_id3 = H5Pcopy( plist_id1 )) < 0 )
+ goto out;
+
+ /* Clone the type id */
+ if ( ( type_id3 = H5Tcopy( type_id1 )) < 0 )
+ goto out;
+
+/*-------------------------------------------------------------------------
+ * Here we do not clone the file space from the 1st dataset, because we want to create
+ * an empty table. Instead we create a new dataspace with zero records and expandable.
+ *-------------------------------------------------------------------------
+ */
+ dims[0] = 0;
+
+/* Create a simple data space with unlimited size */
+ if ( (space_id3 = H5Screate_simple( 1, dims, maxdims )) < 0 )
+ return -1;
+
+ /* Create the dataset */
+ if ( (dataset_id3 = H5Dcreate( loc_id1, dset_name3, type_id3, space_id3, plist_id3 )) < 0 )
+ goto out;
+
+/*-------------------------------------------------------------------------
+ * Attach the conforming table attributes
+ *-------------------------------------------------------------------------
+ */
+ if ( H5TB_attach_attributes( "Merge table", loc_id1, dset_name3, nfields, type_id3 ) < 0 )
+ goto out;
+
+/*-------------------------------------------------------------------------
+ * Get attributes
+ *-------------------------------------------------------------------------
+ */
+
+ type_size = H5Tget_size( type_id3 );
+
+ /* alloc fill value attribute buffer */
+ tmp_fill_buf = (unsigned char *)malloc((size_t) type_size );
+
+ /* Get the fill value attributes */
+ has_fill=H5TBAget_fill( loc_id1, dset_name1, dataset_id1, tmp_fill_buf );
+
+/*-------------------------------------------------------------------------
+ * Attach the fill attributes from previous table
+ *-------------------------------------------------------------------------
+ */
+ if ( has_fill == 1 )
+ {
+
+ if (( sid = H5Screate(H5S_SCALAR)) < 0 )
+ goto out;
+
+ for ( i = 0; i < nfields; i++)
+ {
+
+ /* Get the member type */
+ if ( ( member_type_id = H5Tget_member_type( type_id3, (unsigned) i )) < 0 )
+ goto out;
+
+ /* Get the member offset */
+ if ( ( member_offset = H5Tget_member_offset( type_id3, (unsigned) i )) < 0 )
+ goto out;
+
+ strcpy( attr_name, "FIELD_" );
+ sprintf( aux, "%d", (int) i );
+ strcat( attr_name, aux );
+ sprintf( aux, "%s", "_FILL" );
+ strcat( attr_name, aux );
+
+ if ( (attr_id = H5Acreate( dataset_id3, attr_name, member_type_id, sid, H5P_DEFAULT )) < 0 )
+ goto out;
+
+ if ( H5Awrite( attr_id, member_type_id, tmp_fill_buf+member_offset ) < 0 )
+ goto out;
+
+ if ( H5Aclose( attr_id ) < 0 )
+ goto out;
+
+ if ( H5Tclose( member_type_id ) < 0 )
+ goto out;
+ }
+
+ /* Close data space. */
+ if ( H5Sclose( sid ) < 0 )
+ goto out;
+ }
+
+/*-------------------------------------------------------------------------
+ * Read data from 1st table
+ *-------------------------------------------------------------------------
+ */
+
+ tmp_buf = (unsigned char *)calloc((size_t) nrecords, type_size );
+
+ /* Define a hyperslab in the dataset of the size of the records */
+ offset[0] = 0;
+ count[0] = nrecords;
+ if ( H5Sselect_hyperslab( space_id1, H5S_SELECT_SET, offset, NULL, count, NULL) < 0 )
+ goto out;
+
+ /* Create a memory dataspace handle */
+ mem_size[0] = count[0];
+ if ( (mem_space_id = H5Screate_simple( 1, mem_size, NULL )) < 0 )
+ goto out;
+
+ if ( H5Dread( dataset_id1, type_id1, mem_space_id, space_id1, H5P_DEFAULT, tmp_buf ) < 0 )
+ goto out;
+
+/*-------------------------------------------------------------------------
+ * Save data from 1st table into new table
+ *-------------------------------------------------------------------------
+ */
+
+ /* Append the records to the new table */
+ if ( H5TBappend_records( loc_id1, dset_name3, nrecords, src_size, src_offset, src_sizes, tmp_buf ) < 0 )
+ goto out;
+
+/*-------------------------------------------------------------------------
+ * Release resources from 1st table
+ *-------------------------------------------------------------------------
+ */
+
+ /* Terminate access to the memory dataspace */
+ if ( H5Sclose( mem_space_id ) < 0 )
+ goto out;
+
+ /* Terminate access to the dataspace */
+ if ( H5Sclose( space_id1 ) < 0 )
+ goto out;
+
+ /* Release the datatype. */
+ if ( H5Tclose( type_id1 ) < 0 )
+ goto out;
+
+ /* Terminate access to a property list */
+ if ( H5Pclose( plist_id1 ) < 0 )
+ goto out;
+
+ /* End access to the dataset */
+ if ( H5Dclose( dataset_id1 ) < 0 )
+ goto out;
+
+ /* Release resources. */
+ free( tmp_buf );
+
+/*-------------------------------------------------------------------------
+ * Get information about the 2nd table
+ *-------------------------------------------------------------------------
+ */
+
+ /* Open the dataset. */
+ if ( (dataset_id2 = H5Dopen( loc_id2, dset_name2 )) < 0 )
+ goto out;
+
+ /* Get the datatype */
+ if ( (type_id2 = H5Dget_type( dataset_id2 )) < 0 )
+ goto out;
+
+ /* Get the dataspace handle */
+ if ( (space_id2 = H5Dget_space( dataset_id2 )) < 0 )
+ goto out;
+
+ /* Get the property list handle */
+ if ( (plist_id2 = H5Dget_create_plist( dataset_id2 )) < 0 )
+ goto out;
+
+ /* Get the dimensions */
+ if ( H5TBget_table_info ( loc_id2, dset_name2, &nfields, &nrecords ) < 0 )
+ return -1;
+
+/*-------------------------------------------------------------------------
+ * Read data from 2nd table
+ *-------------------------------------------------------------------------
+ */
+
+ tmp_buf = (unsigned char *)calloc((size_t) nrecords, type_size );
+
+ /* Define a hyperslab in the dataset of the size of the records */
+ offset[0] = 0;
+ count[0] = nrecords;
+ if ( H5Sselect_hyperslab( space_id2, H5S_SELECT_SET, offset, NULL, count, NULL) < 0 )
+ goto out;
+
+ /* Create a memory dataspace handle */
+ mem_size[0] = count[0];
+ if ( (mem_space_id = H5Screate_simple( 1, mem_size, NULL )) < 0 )
+ goto out;
+
+ if ( H5Dread( dataset_id2, type_id2, mem_space_id, space_id2, H5P_DEFAULT, tmp_buf ) < 0 )
+ goto out;
+
+
+/*-------------------------------------------------------------------------
+ * Save data from 2nd table into new table
+ *-------------------------------------------------------------------------
+ */
+
+ /* append the records to the new table */
+ if ( H5TBappend_records( loc_id1, dset_name3, nrecords, src_size, src_offset, src_sizes, tmp_buf ) < 0 )
+ goto out;
+
+/*-------------------------------------------------------------------------
+ * Release resources from 2nd table
+ *-------------------------------------------------------------------------
+ */
+
+ /* Terminate access to the memory dataspace */
+ if ( H5Sclose( mem_space_id ) < 0 )
+ goto out;
+
+ /* Terminate access to the dataspace */
+ if ( H5Sclose( space_id2 ) < 0 )
+ goto out;
+
+ /* Release the datatype. */
+ if ( H5Tclose( type_id2 ) < 0 )
+ return -1;
+
+ /* Terminate access to a property list */
+ if ( H5Pclose( plist_id2 ) < 0 )
+ goto out;
+
+ /* End access to the dataset */
+ if ( H5Dclose( dataset_id2 ) < 0 )
+ return -1;
+
+/*-------------------------------------------------------------------------
+ * Release resources from 3rd table
+ *-------------------------------------------------------------------------
+ */
+
+ /* Terminate access to the dataspace */
+ if ( H5Sclose( space_id3 ) < 0 )
+ return -1;
+
+ /* Release the datatype. */
+ if ( H5Tclose( type_id3 ) < 0 )
+ return -1;
+
+ /* Terminate access to a property list */
+ if ( H5Pclose( plist_id3 ) < 0 )
+ return -1;
+
+ /* End access to the dataset */
+ if ( H5Dclose( dataset_id3 ) < 0 )
+ return -1;
+
+ /* Release resources. */
+ free( tmp_buf );
+ free( tmp_fill_buf );
+ free( src_offset );
+ free( src_sizes );
+
+return 0;
+
+out:
+ H5Dclose( dataset_id1 );
+ return -1;
+
+}
+
+
+
+/*-------------------------------------------------------------------------
+ * Function: H5TBinsert_field
+ *
+ * Purpose: Inserts a field
+ *
+ * Return: Success: 0, Failure: -1
+ *
+ * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
+ *
+ * Date: January 30, 2002
+ *
+ * Comments:
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+
+herr_t H5TBinsert_field( hid_t loc_id,
+ const char *dset_name,
+ const char *field_name,
+ hid_t field_type,
+ hsize_t position,
+ const void *fill_data,
+ const void *data )
+{
+
+ /* Identifiers for the 1st, original dataset */
+ hid_t dataset_id1;
+ hid_t type_id1;
+ hid_t space_id1;
+ hid_t plist_id1;
+ hid_t mem_space_id1;
+
+ /* Identifiers for the 2nd, new dataset */
+ hid_t dataset_id2;
+ hid_t type_id2;
+ hid_t space_id2;
+ hid_t plist_id2;
+ hid_t mem_space_id2;
+
+ hid_t member_type_id;
+ size_t member_size;
+ size_t new_member_size = 0;
+ char *member_name;
+ hssize_t total_size;
+ hsize_t nfields;
+ hsize_t nrecords;
+ int rank_chunk;
+ hsize_t dims_chunk[1];
+ hsize_t dims[1];
+ hsize_t maxdims[1] = { H5S_UNLIMITED };
+ hsize_t count[1];
+ hssize_t offset[1];
+ hsize_t mem_size[1];
+ hid_t write_type_id;
+ hid_t PRESERVE;
+ size_t curr_offset;
+ int inserted;
+ hsize_t idx;
+ char table_title[255];
+ hssize_t member_offset;
+ char attr_name[255];
+ hid_t attr_id;
+ char aux[255];
+ unsigned char *tmp_buf;
+ unsigned char *tmp_fill_buf;
+ hsize_t i;
+
+ /* Get the number of records and fields */
+ if ( H5TBget_table_info ( loc_id, dset_name, &nfields, &nrecords ) < 0 )
+ return -1;
+
+/*-------------------------------------------------------------------------
+ * Get information about the old data type
+ *-------------------------------------------------------------------------
+ */
+
+ /* Open the dataset. */
+ if ( (dataset_id1 = H5Dopen( loc_id, dset_name )) < 0 )
+ return -1;
+
+ /* Get creation properties list */
+ if ( (plist_id1 = H5Dget_create_plist( dataset_id1 )) < 0 )
+ goto out;
+
+ /* Get the datatype */
+ if ( (type_id1 = H5Dget_type( dataset_id1 )) < 0 )
+ goto out;
+
+ /* Get the size of the datatype */
+ if ( ( total_size = H5Tget_size( type_id1 )) < 0 )
+ goto out;
+
+ /* Get the dataspace handle */
+ if ( (space_id1 = H5Dget_space( dataset_id1 )) < 0 )
+ goto out;
+
+ /* Get dimension */
+ if ( H5Sget_simple_extent_dims( space_id1, dims, NULL) < 0 )
+ goto out;
+
+/*-------------------------------------------------------------------------
+ * Get attributes
+ *-------------------------------------------------------------------------
+ */
+
+ /* Get the table title */
+ if ( (H5TBAget_title( dataset_id1, table_title )) < 0 )
+ goto out;
+
+ /* alloc fill value attribute buffer */
+ tmp_fill_buf = (unsigned char *)malloc((size_t) total_size );
+
+ /* Get the fill value attributes */
+ if ( (H5TBAget_fill( loc_id, dset_name, dataset_id1, tmp_fill_buf )) < 0 )
+ goto out;
+
+/*-------------------------------------------------------------------------
+ * Create a new data type
+ *-------------------------------------------------------------------------
+ */
+
+ /* Get the new member size */
+ member_size = H5Tget_size( field_type );
+
+ /* Create the data type. */
+ if (( type_id2 = H5Tcreate (H5T_COMPOUND,(size_t)(total_size + member_size) )) < 0 )
+ goto out;
+
+ curr_offset = 0;
+ inserted = 0;
+
+ /* Insert the old fields, counting with the new one */
+ for ( i = 0; i < nfields + 1; i++)
+ {
+
+ idx = i;
+ if ( inserted )
+ idx = i - 1;
+
+ if ( i == position )
+ {
+
+ /* Get the new member size */
+ new_member_size = H5Tget_size( field_type );
+
+ /* Insert the new field type */
+ if ( H5Tinsert( type_id2, field_name, curr_offset, field_type ) < 0 )
+ goto out;
+
+ curr_offset += new_member_size;
+
+ inserted = 1;
+
+ continue;
+
+ }
+
+ /* Get the member name */
+ member_name = H5Tget_member_name( type_id1, (unsigned)idx );
+
+ /* Get the member type */
+ if ( ( member_type_id = H5Tget_member_type( type_id1,(unsigned)idx )) < 0 )
+ goto out;
+
+ /* Get the member size */
+ member_size = H5Tget_size( member_type_id );
+
+ /* Insert it into the new type */
+ if ( H5Tinsert( type_id2, member_name, curr_offset, member_type_id ) < 0 )
+ goto out;
+
+ curr_offset += member_size;
+
+ free( member_name );
+
+ /* Close the member type */
+ if ( H5Tclose( member_type_id ) < 0 )
+ goto out;
+
+
+ } /* i */
+
+/*-------------------------------------------------------------------------
+ * Create a new temporary dataset
+ *-------------------------------------------------------------------------
+ */
+
+ /* Retrieve the size of chunk */
+ if ( ( rank_chunk = H5Pget_chunk( plist_id1, 1, dims_chunk )) < 0 )
+ goto out;
+
+ /* Create a new simple data space with unlimited size, using the dimension */
+ if ( ( space_id2 = H5Screate_simple( 1, dims, maxdims )) < 0 )
+ return -1;
+
+ /* Modify dataset creation properties, i.e. enable chunking */
+ plist_id2 = H5Pcreate (H5P_DATASET_CREATE);
+ if ( H5Pset_chunk ( plist_id2, 1, dims_chunk ) < 0 )
+ return -1;
+
+ /* Create the dataset. */
+ if ( ( dataset_id2 = H5Dcreate( loc_id, "new", type_id2, space_id2, plist_id2 )) < 0 )
+ goto out;
+
+
+/*-------------------------------------------------------------------------
+ * Read data from 1st table
+ *-------------------------------------------------------------------------
+ */
+
+ tmp_buf = (unsigned char *)calloc((size_t) nrecords, (size_t)total_size );
+
+ /* Define a hyperslab in the dataset of the size of the records */
+ offset[0] = 0;
+ count[0] = nrecords;
+ if ( H5Sselect_hyperslab( space_id1, H5S_SELECT_SET, offset, NULL, count, NULL) < 0 )
+ goto out;
+
+ /* Create a memory dataspace handle */
+ mem_size[0] = count[0];
+ if ( (mem_space_id1 = H5Screate_simple( 1, mem_size, NULL )) < 0 )
+ goto out;
+
+ if ( H5Dread( dataset_id1, type_id1, mem_space_id1, H5S_ALL, H5P_DEFAULT, tmp_buf ) < 0 )
+ goto out;
+
+
+/*-------------------------------------------------------------------------
+ * Save data from 1st table into new table, using the 1st type id
+ *-------------------------------------------------------------------------
+ */
+
+ /* Write */
+ if ( H5Dwrite( dataset_id2, type_id1, mem_space_id1, H5S_ALL, H5P_DEFAULT, tmp_buf ) < 0 )
+ goto out;
+
+
+/*-------------------------------------------------------------------------
+ * Save the function supplied data of the new field
+ *-------------------------------------------------------------------------
+ */
+
+
+ /* Create a write id */
+ if ( ( write_type_id = H5Tcreate( H5T_COMPOUND, (size_t)new_member_size )) < 0 )
+ goto out;
+
+ /* The field in the file is found by its name */
+ if ( H5Tinsert( write_type_id, field_name, 0, field_type ) < 0 )
+ goto out;
+
+ /* Create xfer properties to preserve initialized data */
+ if ((PRESERVE = H5Pcreate (H5P_DATASET_XFER))<0)
+ goto out;
+ if (H5Pset_preserve (PRESERVE, 1)<0)
+ goto out;
+
+ /* Only write if there is something to write */
+ if ( data )
+ {
+
+ /* Create a memory dataspace handle */
+ if ( (mem_space_id2 = H5Screate_simple( 1, mem_size, NULL )) < 0 )
+ goto out;
+
+ /* Write */
+ if ( H5Dwrite( dataset_id2, write_type_id, mem_space_id2, space_id2, PRESERVE, data ) < 0 )
+ goto out;
+
+ /* Terminate access to the memory dataspace */
+ if ( H5Sclose( mem_space_id2 ) < 0 )
+ goto out;
+ }
+
+ /* End access to the property list */
+ if ( H5Pclose( PRESERVE ) < 0 )
+ goto out;
+
+
+
+/*-------------------------------------------------------------------------
+ * Release resources from 1st table
+ *-------------------------------------------------------------------------
+ */
+
+ /* Terminate access to the memory dataspace */
+ if ( H5Sclose( mem_space_id1 ) < 0 )
+ goto out;
+
+ /* Release the datatype. */
+ if ( H5Tclose( type_id1 ) < 0 )
+ goto out;
+
+ /* Terminate access to a property list */
+ if ( H5Pclose( plist_id1 ) < 0 )
+ goto out;
+
+ /* Terminate access to the data space */
+ if ( H5Sclose( space_id1 ) < 0 )
+ goto out;
+
+ /* End access to the dataset */
+ if ( H5Dclose( dataset_id1 ) < 0 )
+ goto out;
+
+
+/*-------------------------------------------------------------------------
+ * Release resources from 2nd table
+ *-------------------------------------------------------------------------
+ */
+
+ /* Terminate access to the dataspace */
+ if ( H5Sclose( space_id2 ) < 0 )
+ goto out;
+
+ /* Release the datatype. */
+ if ( H5Tclose( type_id2 ) < 0 )
+ return -1;
+
+ /* Terminate access to a property list */
+ if ( H5Pclose( plist_id2 ) < 0 )
+ goto out;
+
+ /* End access to the dataset */
+ if ( H5Dclose( dataset_id2 ) < 0 )
+ return -1;
+/*-------------------------------------------------------------------------
+ * Delete 1st table
+ *-------------------------------------------------------------------------
+ */
+ if ( H5Gunlink( loc_id, dset_name ) < 0 )
+ return -1;
+
+/*-------------------------------------------------------------------------
+ * Rename 2nd table
+ *-------------------------------------------------------------------------
+ */
+
+ if ( H5Gmove( loc_id, "new", dset_name ) < 0 )
+ return -1;
+
+/*-------------------------------------------------------------------------
+ * Attach the conforming table attributes
+ *-------------------------------------------------------------------------
+ */
+
+ /* Get the number of records and fields */
+ if ( H5TBget_table_info ( loc_id, dset_name, &nfields, &nrecords ) < 0 )
+ return -1;
+
+ /* Open the dataset. */
+ if ( (dataset_id1 = H5Dopen( loc_id, dset_name )) < 0 )
+ return -1;
+
+ /* Get the datatype */
+ if ( (type_id1 = H5Dget_type( dataset_id1 )) < 0 )
+ goto out;
+
+ /* Set the attributes */
+ if ( H5TB_attach_attributes( table_title, loc_id, dset_name,(hsize_t) nfields, type_id1 ) < 0 )
+ return -1;
+/*-------------------------------------------------------------------------
+ * Attach the fill attributes from previous table
+ *-------------------------------------------------------------------------
+ */
+
+ if (( space_id1 = H5Screate(H5S_SCALAR)) < 0 )
+ goto out;
+
+ for ( i = 0; i < nfields-1; i++)
+ {
+ /* Get the member type */
+ if ( ( member_type_id = H5Tget_member_type( type_id1, (unsigned) i )) < 0 )
+ goto out;
+
+ /* Get the member offset */
+ if ( ( member_offset = H5Tget_member_offset( type_id1, (unsigned) i )) < 0 )
+ goto out;
+
+ strcpy( attr_name, "FIELD_" );
+ sprintf( aux, "%d", (int)i );
+ strcat( attr_name, aux );
+ sprintf( aux, "%s", "_FILL" );
+ strcat( attr_name, aux );
+
+ if ( (attr_id = H5Acreate( dataset_id1, attr_name, member_type_id, space_id1, H5P_DEFAULT )) < 0 )
+ goto out;
+
+ if ( H5Awrite( attr_id, member_type_id, tmp_fill_buf+member_offset ) < 0 )
+ goto out;
+
+ if ( H5Aclose( attr_id ) < 0 )
+ goto out;
+
+ /* Close the member type */
+ if ( H5Tclose( member_type_id ) < 0 )
+ goto out;
+ }
+
+/*-------------------------------------------------------------------------
+ * Attach the fill attribute from the new field, if present
+ *-------------------------------------------------------------------------
+ */
+ if ( fill_data )
+ {
+
+ strcpy( attr_name, "FIELD_" );
+ sprintf( aux, "%d",(int)( nfields-1) );
+ strcat( attr_name, aux );
+ sprintf( aux, "%s", "_FILL" );
+ strcat( attr_name, aux );
+
+ /* Get the member type */
+ if ( ( member_type_id = H5Tget_member_type( type_id1, (unsigned)nfields-1 )) < 0 )
+ goto out;
+
+ if ( (attr_id = H5Acreate( dataset_id1, attr_name, member_type_id, space_id1, H5P_DEFAULT )) < 0 )
+ goto out;
+
+ if ( H5Awrite( attr_id, member_type_id, fill_data ) < 0 )
+ goto out;
+
+ if ( H5Aclose( attr_id ) < 0 )
+ goto out;
+
+ if ( H5Tclose( member_type_id ) < 0 )
+ goto out;
+
+ }
+
+ /* Close data space. */
+ if ( H5Sclose( space_id1 ) < 0 )
+ goto out;
+
+ /* Release the datatype. */
+ if ( H5Tclose( type_id1 ) < 0 )
+ goto out;
+
+ /* End access to the dataset */
+ if ( H5Dclose( dataset_id1 ) < 0 )
+ goto out;
+
+ /* Release resources. */
+ free ( tmp_buf );
+ free ( tmp_fill_buf );
+
+
+return 0;
+
+out:
+ H5Dclose( dataset_id1 );
+ return -1;
+}
+
+/*-------------------------------------------------------------------------
+ * Function: H5TBdelete_field
+ *
+ * Purpose: Deletes a field
+ *
+ * Return: Success: 0, Failure: -1
+ *
+ * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
+ *
+ * Date: January 30, 2002
+ *
+ * Comments:
+ *
+ * Modifications:
+ *
+ *
+ *-------------------------------------------------------------------------
+ */
+
+herr_t H5TBdelete_field( hid_t loc_id,
+ const char *dset_name,
+ const char *field_name )
+{
+
+ /* Identifiers for the 1st original dataset */
+ hid_t dataset_id1;
+ hid_t type_id1;
+ hid_t space_id1;
+ hid_t plist_id1;
+
+ /* Identifiers for the 2nd new dataset */
+ hid_t dataset_id2;
+ hid_t type_id2;
+ hid_t space_id2;
+ hid_t plist_id2;
+
+ hid_t member_type_id;
+ size_t member_size;
+ char *member_name;
+ size_t type_size1;
+ size_t type_size2;
+ hsize_t nfields;
+ hsize_t nrecords;
+ int rank_chunk;
+ hsize_t dims_chunk[1];
+ hsize_t dims[1];
+ hsize_t maxdims[1] = { H5S_UNLIMITED };
+ hid_t PRESERVE;
+ size_t curr_offset;
+ size_t delete_member_size = 0;
+ hid_t read_type_id;
+ hid_t write_type_id;
+ unsigned char *tmp_buf;
+ unsigned char *tmp_fill_buf;
+ char attr_name[255];
+ char aux[255];
+ char table_title[255];
+ size_t member_offset;
+ hid_t attr_id;
+ hsize_t i;
+ int has_fill=0;
+
+ /* Get the number of records and fields */
+ if ( H5TBget_table_info ( loc_id, dset_name, &nfields, &nrecords ) < 0 )
+ return -1;
+
+/*-------------------------------------------------------------------------
+ * Get information about the old data type
+ *-------------------------------------------------------------------------
+ */
+
+ /* Open the dataset. */
+ if ( (dataset_id1 = H5Dopen( loc_id, dset_name )) < 0 )
+ return -1;
+
+ /* Get creation properties list */
+ if ( (plist_id1 = H5Dget_create_plist( dataset_id1 )) < 0 )
+ goto out;
+
+ /* Get the datatype */
+ if ( (type_id1 = H5Dget_type( dataset_id1 )) < 0 )
+ goto out;
+
+ /* Get the size of the datatype */
+ type_size1 = H5Tget_size( type_id1 );
+
+ /* Get the dataspace handle */
+ if ( (space_id1 = H5Dget_space( dataset_id1 )) < 0 )
+ goto out;
+
+ /* Get dimension */
+ if ( H5Sget_simple_extent_dims( space_id1, dims, NULL) < 0 )
+ goto out;
+
+/*-------------------------------------------------------------------------
+ * Create a new data type; first we find the size of the datatype to delete
+ *-------------------------------------------------------------------------
+ */
+
+ /* Check out the field */
+ for ( i = 0; i < nfields; i++)
+ {
+
+ /* Get the member name */
+ member_name = H5Tget_member_name( type_id1,(unsigned) i );
+
+ /* We want to find the field to delete */
+ if ( H5TB_find_field( member_name, field_name ) > 0 )
+ {
+ /* Get the member type */
+ if ( ( member_type_id = H5Tget_member_type( type_id1,(unsigned) i )) < 0 )
+ goto out;
+
+ /* Get the member size */
+ delete_member_size = H5Tget_size( member_type_id );
+
+ /* Close the member type */
+ if ( H5Tclose( member_type_id ) < 0 )
+ goto out;
+
+ free( member_name );
+
+ break;
+
+ }
+
+ free( member_name );
+
+ } /* i */
+
+ /* No field to delete was found */
+ if ( delete_member_size == 0 )
+ goto out;
+
+/*-------------------------------------------------------------------------
+ * Create a new data type; we now insert all the fields into the new type
+ *-------------------------------------------------------------------------
+ */
+
+ type_size2 = type_size1 - delete_member_size;
+
+ /* Create the data type. */
+ if (( type_id2 = H5Tcreate (H5T_COMPOUND, type_size2 )) < 0 )
+ goto out;
+
+ curr_offset = 0;
+
+ /* alloc fill value attribute buffer */
+ tmp_fill_buf = (unsigned char *)malloc((size_t) type_size2 );
+
+/*-------------------------------------------------------------------------
+ * Get attributes from previous table in the process
+ *-------------------------------------------------------------------------
+ */
+
+ /* Get the table title */
+ if ( (H5TBAget_title( dataset_id1, table_title )) < 0 )
+ goto out;
+
+ /* Insert the old fields except the one to delete */
+ for ( i = 0; i < nfields; i++)
+ {
+
+ /* Get the member name */
+ member_name = H5Tget_member_name( type_id1, (unsigned) i );
+
+ /* We want to skip the field to delete */
+ if ( H5TB_find_field( member_name, field_name ) > 0 )
+ {
+ free( member_name );
+ continue;
+ }
+
+ /* Get the member type */
+ if ( ( member_type_id = H5Tget_member_type( type_id1, (unsigned)i )) < 0 )
+ goto out;
+
+ /* Get the member size */
+ member_size = H5Tget_size( member_type_id );
+
+ /* Insert it into the new type */
+ if ( H5Tinsert( type_id2, member_name, curr_offset, member_type_id ) < 0 )
+ goto out;
+
+ /*-------------------------------------------------------------------------
+ * Get the fill value information
+ *-------------------------------------------------------------------------
+ */
+
+ strcpy( attr_name, "FIELD_" );
+ sprintf( aux, "%d", (int)i );
+ strcat( attr_name, aux );
+ sprintf( aux, "%s", "_FILL" );
+ strcat( attr_name, aux );
+
+ /* Check if we have the _FILL attribute */
+ has_fill = H5LT_find_attribute( dataset_id1, attr_name );
+
+ /* Get it */
+ if ( has_fill == 1 )
+ {
+ if ( H5LT_get_attribute_disk( dataset_id1, attr_name, tmp_fill_buf+curr_offset ) < 0 )
+ goto out;
+ }
+
+ curr_offset += member_size;
+
+ free( member_name );
+
+ /* Close the member type */
+ if ( H5Tclose( member_type_id ) < 0 )
+ goto out;
+
+ } /* i */
+
+/*-------------------------------------------------------------------------
+ * Create a new temporary dataset
+ *-------------------------------------------------------------------------
+ */
+
+ /* Retrieve the size of chunk */
+ if ( ( rank_chunk = H5Pget_chunk( plist_id1, 1, dims_chunk )) < 0 )
+ goto out;
+
+ /* Create a new simple data space with unlimited size, using the dimension */
+ if ( ( space_id2 = H5Screate_simple( 1, dims, maxdims )) < 0 )
+ return -1;
+
+ /* Modify dataset creation properties, i.e. enable chunking */
+ plist_id2 = H5Pcreate (H5P_DATASET_CREATE);
+ if ( H5Pset_chunk ( plist_id2, 1, dims_chunk ) < 0 )
+ return -1;
+
+ /* Create the dataset. */
+ if ( ( dataset_id2 = H5Dcreate( loc_id, "new", type_id2, space_id2, plist_id2 )) < 0 )
+ goto out;
+
+/*-------------------------------------------------------------------------
+ * We have to read field by field of the old dataset and save it into the new one
+ *-------------------------------------------------------------------------
+ */
+ for ( i = 0; i < nfields; i++)
+ {
+
+ /* Get the member name */
+ member_name = H5Tget_member_name( type_id1,(unsigned) i );
+
+ /* Skip the field to delete */
+ if ( H5TB_find_field( member_name, field_name ) > 0 )
+ {
+ free( member_name );
+ continue;
+ }
+
+ /* Get the member type */
+ if ( ( member_type_id = H5Tget_member_type( type_id1, (unsigned)i )) < 0 )
+ goto out;
+
+ /* Get the member size */
+ member_size = H5Tget_size( member_type_id );
+
+ /* Create a read id */
+ if ( ( read_type_id = H5Tcreate( H5T_COMPOUND, member_size )) < 0 )
+ goto out;
+
+ /* Insert it into the new type */
+ if ( H5Tinsert( read_type_id, member_name, 0, member_type_id ) < 0 )
+ goto out;
+
+ tmp_buf = (unsigned char *)calloc((size_t) nrecords, member_size );
+
+ /* Read */
+ if ( H5Dread( dataset_id1, read_type_id, H5S_ALL, H5S_ALL, H5P_DEFAULT, tmp_buf ) < 0 )
+ goto out;
+
+ /* Create a write id */
+ if ( ( write_type_id = H5Tcreate( H5T_COMPOUND, member_size )) < 0 )
+ goto out;
+
+ /* The field in the file is found by its name */
+ if ( H5Tinsert( write_type_id, member_name, 0, member_type_id ) < 0 )
+ goto out;
+
+ /* Create xfer properties to preserve initialized data */
+ if ((PRESERVE = H5Pcreate (H5P_DATASET_XFER))<0)
+ goto out;
+ if (H5Pset_preserve (PRESERVE, 1)<0)
+ goto out;
+
+ /* Write */
+ if ( H5Dwrite( dataset_id2, write_type_id, H5S_ALL, H5S_ALL, PRESERVE, tmp_buf ) < 0 )
+ goto out;
+
+ /* End access to the property list */
+ if ( H5Pclose( PRESERVE ) < 0 )
+ goto out;
+
+ /* Close the member type */
+ if ( H5Tclose( member_type_id ) < 0 )
+ goto out;
+
+ /* Close the read type */
+ if ( H5Tclose( read_type_id ) < 0 )
+ goto out;
+
+ /* Close the write type */
+ if ( H5Tclose( write_type_id ) < 0 )
+ goto out;
+
+ /* Release resources. */
+ free( member_name );
+ free ( tmp_buf );
+
+ } /* i */
+
+/*-------------------------------------------------------------------------
+ * Release resources from 1st table
+ *-------------------------------------------------------------------------
+ */
+
+ /* Release the datatype. */
+ if ( H5Tclose( type_id1 ) < 0 )
+ goto out;
+
+ /* Terminate access to a property list */
+ if ( H5Pclose( plist_id1 ) < 0 )
+ goto out;
+
+ /* Terminate access to the data space */
+ if ( H5Sclose( space_id1 ) < 0 )
+ goto out;
+
+ /* End access to the dataset */
+ if ( H5Dclose( dataset_id1 ) < 0 )
+ goto out;
+
+
+/*-------------------------------------------------------------------------
+ * Release resources from 2nd table
+ *-------------------------------------------------------------------------
+ */
+
+ /* Terminate access to the dataspace */
+ if ( H5Sclose( space_id2 ) < 0 )
+ goto out;
+
+ /* Release the datatype. */
+ if ( H5Tclose( type_id2 ) < 0 )
+ return -1;
+
+ /* Terminate access to a property list */
+ if ( H5Pclose( plist_id2 ) < 0 )
+ goto out;
+
+ /* End access to the dataset */
+ if ( H5Dclose( dataset_id2 ) < 0 )
+ return -1;
+
+/*-------------------------------------------------------------------------
+ * Delete 1st table
+ *-------------------------------------------------------------------------
+ */
+
+ if ( H5Gunlink( loc_id, dset_name ) < 0 )
+ return -1;
+
+/*-------------------------------------------------------------------------
+ * Rename 2nd table
+ *-------------------------------------------------------------------------
+ */
+
+ if ( H5Gmove( loc_id, "new", dset_name ) < 0 )
+ return -1;
+
+/*-------------------------------------------------------------------------
+ * Attach the conforming table attributes
+ *-------------------------------------------------------------------------
+ */
+
+ /* Get the number of records and fields */
+ if ( H5TBget_table_info ( loc_id, dset_name, &nfields, &nrecords ) < 0 )
+ return -1;
+
+ /* Open the dataset. */
+ if ( (dataset_id1 = H5Dopen( loc_id, dset_name )) < 0 )
+ return -1;
+
+ /* Get the datatype */
+ if ( (type_id1 = H5Dget_type( dataset_id1 )) < 0 )
+ goto out;
+
+ /* Set the attributes */
+ if ( H5TB_attach_attributes( table_title, loc_id, dset_name, nfields, type_id1 ) < 0 )
+ return -1;
+
+/*-------------------------------------------------------------------------
+ * Attach the fill attributes from previous table
+ *-------------------------------------------------------------------------
+ */
+
+ if ( has_fill == 1 )
+ {
+
+ if (( space_id1 = H5Screate(H5S_SCALAR)) < 0 )
+ goto out;
+
+ for ( i = 0; i < nfields; i++)
+ {
+
+ /* Get the member type */
+ if ( ( member_type_id = H5Tget_member_type( type_id1, (unsigned)i )) < 0 )
+ goto out;
+
+ /* Get the member offset */
+ member_offset = H5Tget_member_offset( type_id1, (unsigned)i );
+
+ strcpy( attr_name, "FIELD_" );
+ sprintf( aux, "%d", (int)i );
+ strcat( attr_name, aux );
+ sprintf( aux, "%s", "_FILL" );
+ strcat( attr_name, aux );
+
+ if ( (attr_id = H5Acreate( dataset_id1, attr_name, member_type_id, space_id1, H5P_DEFAULT )) < 0 )
+ goto out;
+
+ if ( H5Awrite( attr_id, member_type_id, tmp_fill_buf+member_offset ) < 0 )
+ goto out;
+
+ if ( H5Aclose( attr_id ) < 0 )
+ goto out;
+
+ /* Close the member type */
+ if ( H5Tclose( member_type_id ) < 0 )
+ goto out;
+
+ }
+
+ /* Close data space. */
+ if ( H5Sclose( space_id1 ) < 0 )
+ goto out;
+
+ } /*has_fill*/
+
+ /* Release the datatype. */
+ if ( H5Tclose( type_id1 ) < 0 )
+ goto out;
+
+ /* End access to the dataset */
+ if ( H5Dclose( dataset_id1 ) < 0 )
+ goto out;
+
+ /* Release resources. */
+ free ( tmp_fill_buf );
+
+return 0;
+
+out:
+ H5Dclose( dataset_id1 );
+ return -1;
+}
+
+/*-------------------------------------------------------------------------
+ *
+ * Table attribute functions
+ *
+ *-------------------------------------------------------------------------
+ */
+
+/*-------------------------------------------------------------------------
+ * Function: H5TBAget_title
+ *
+ * Purpose: Read the table title
+ *
+ * Return: Success: 0, Failure: -1
+ *
+ * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
+ *
+ * Date: January 30, 2001
+ *
+ * Comments:
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+
+herr_t H5TBAget_title( hid_t loc_id,
+ char *table_title )
+{
+
+ /* Get the TITLE attribute */
+ if ( H5LT_get_attribute_disk( loc_id, "TITLE", table_title ) < 0 )
+ return -1;
+
+
+ return 0;
+
+}
+
+/*-------------------------------------------------------------------------
+ * Function: H5TBAget_fill
+ *
+ * Purpose: Read the table attribute fill values
+ *
+ * Return: Success: 0, Failure: -1
+ *
+ * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
+ *
+ * Date: January 30, 2002
+ *
+ * Comments:
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+
+
+herr_t H5TBAget_fill( hid_t loc_id,
+ const char *dset_name,
+ hid_t dset_id,
+ unsigned char *dst_buf )
+{
+
+ hsize_t nfields;
+ hsize_t nrecords;
+ char attr_name[255];
+ char aux[255];
+ hsize_t i;
+ size_t *src_offset;
+ int has_fill=0;
+
+ /* Get the number of records and fields */
+ if ( H5TBget_table_info ( loc_id, dset_name, &nfields, &nrecords ) < 0 )
+ return -1;
+
+ src_offset = (size_t *)malloc((size_t)nfields * sizeof(size_t));
+
+ if (src_offset == NULL )
+ return -1;
+
+ /* Get field info */
+ if ( H5TBget_field_info( loc_id, dset_name, NULL, NULL, src_offset, NULL ) < 0 )
+ goto out;
+
+ for ( i = 0; i < nfields; i++)
+ {
+ strcpy( attr_name, "FIELD_" );
+ sprintf( aux, "%d", (int)i );
+ strcat( attr_name, aux );
+ sprintf( aux, "%s", "_FILL" );
+ strcat( attr_name, aux );
+
+ /* Check if we have the _FILL attribute */
+ has_fill = H5LT_find_attribute( dset_id, attr_name );
+
+ /* Get it */
+ if ( has_fill == 1 )
+ {
+ if ( H5LT_get_attribute_disk( dset_id, attr_name, dst_buf+src_offset[i] ) < 0 )
+ goto out;
+ }
+
+ }
+
+ free( src_offset );
+
+ return has_fill;
+
+out:
+ free( src_offset );
+ return -1;
+
+}
+
+
+/*-------------------------------------------------------------------------
+ *
+ * Inquiry functions
+ *
+ *-------------------------------------------------------------------------
+ */
+
+/*-------------------------------------------------------------------------
+ * Function: H5TBget_table_info
+ *
+ * Purpose: Gets the number of records and fields of a table
+ *
+ * Return: Success: 0, Failure: -1
+ *
+ * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
+ *
+ * Date: November 19, 2001
+ *
+ * Comments:
+ *
+ * Modifications: May 08, 2003
+ * In version 2.0 of Table, the number of records is stored as an
+ * attribute "NROWS"
+ *
+ *
+ *-------------------------------------------------------------------------
+ */
+
+herr_t H5TBget_table_info ( hid_t loc_id,
+ const char *dset_name,
+ hsize_t *nfields,
+ hsize_t *nrecords )
+{
+ hid_t tid;
+ hid_t sid=-1;
+ hid_t did;
+ int num_members;
+ hsize_t dims[1];
+ int has_attr;
+ hsize_t n[1];
+
+ /* Open the dataset. */
+ if ( (did = H5Dopen( loc_id, dset_name )) < 0 )
+ return -1;
+
+ /* Get the datatype */
+ if ( (tid = H5Dget_type( did )) < 0 )
+ goto out;
+
+ /* Get the number of members */
+ if ( (num_members = H5Tget_nmembers( tid )) < 0 )
+ goto out;
+
+ if (nfields)
+ *nfields = num_members;
+
+
+/*-------------------------------------------------------------------------
+ * Get number of records
+ *-------------------------------------------------------------------------
+ */
+
+ if (nrecords)
+ {
+ /* Try to find the attribute "NROWS" */
+ has_attr = H5LT_find_attribute( did, "NROWS" );
+
+ /* It exists, get it */
+ if ( has_attr == 1 )
+ {
+ /* Get the attribute */
+ if ( H5LTget_attribute(loc_id,dset_name,"NROWS",H5T_NATIVE_LLONG,n)<0)
+ return -1;
+
+ *nrecords = *n;
+ }
+ else
+ {
+ /* Get the dataspace handle */
+ if ( (sid = H5Dget_space( did )) < 0 )
+ goto out;
+
+ /* Get records */
+ if ( H5Sget_simple_extent_dims( sid, dims, NULL) < 0 )
+ goto out;
+
+ /* Terminate access to the dataspace */
+ if ( H5Sclose( sid ) < 0 )
+ goto out;
+
+ *nrecords = dims[0];
+ }
+ }/*nrecords*/
+
+ /* close */
+ if ( H5Tclose( tid ) < 0 )
+ goto out;
+ if ( H5Dclose( did ) < 0 )
+ return -1;
+
+return 0;
+
+/* error zone, gracefully close */
+out:
+ H5E_BEGIN_TRY {
+ H5Dclose(did);
+ H5Sclose(sid);
+ H5Tclose(tid);
+ } H5E_END_TRY;
+ return -1;
+
+}
+
+/*-------------------------------------------------------------------------
+ * Function: H5TBget_field_info
+ *
+ * Purpose: Get information about fields
+ *
+ * Return: Success: 0, Failure: -1
+ *
+ * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
+ *
+ * Date: November 19, 2001
+ *
+ * Comments:
+ *
+ * Modifications:
+ *
+ *
+ *-------------------------------------------------------------------------
+ */
+herr_t H5TBget_field_info( hid_t loc_id,
+ const char *dset_name,
+ char *field_names[],
+ size_t *field_sizes,
+ size_t *field_offsets,
+ size_t *type_size )
+{
+ hid_t did;
+ hid_t ftype_id;
+ hid_t native_type_id;
+ hssize_t nfields;
+ char *member_name;
+ hid_t member_type_id;
+ hid_t nativem_type_id;
+ size_t member_size;
+ size_t member_offset;
+ size_t size;
+ hssize_t i;
+
+ /* Open the dataset. */
+ if ( ( did = H5Dopen( loc_id, dset_name )) < 0 )
+ goto out;
+
+ /* Get the datatype */
+ if ( ( ftype_id = H5Dget_type( did )) < 0 )
+ goto out;
+
+ if ((native_type_id = H5Tget_native_type(ftype_id,H5T_DIR_DEFAULT))<0)
+ goto out;
+
+ /* Get the type size */
+ size = H5Tget_size( native_type_id );
+
+ if ( type_size )
+ *type_size = size;
+
+ /* Get the number of members */
+ if ( ( nfields = H5Tget_nmembers( ftype_id )) < 0 )
+ goto out;
+
+ /* Iterate tru the members */
+ for ( i = 0; i < nfields; i++)
+ {
+ /* Get the member name */
+ member_name = H5Tget_member_name( ftype_id, (unsigned)i );
+
+ if ( field_names )
+ strcpy( field_names[i], member_name );
+
+ /* Get the member type */
+ if ( ( member_type_id = H5Tget_member_type( ftype_id,(unsigned) i )) < 0 )
+ goto out;
+ if ((nativem_type_id = H5Tget_native_type(member_type_id,H5T_DIR_DEFAULT))<0)
+ goto out;
+
+ /* Get the member size */
+ member_size = H5Tget_size( nativem_type_id );
+
+ if ( field_sizes )
+ field_sizes[i] = member_size;
+
+ /* Get the member offset */
+ member_offset = H5Tget_member_offset( native_type_id,(unsigned) i );
+
+ if ( field_offsets )
+ field_offsets[i] = member_offset;
+
+ /* Close the member type */
+ if ( H5Tclose( member_type_id ) < 0 )
+ goto out;
+ if ( H5Tclose( nativem_type_id ) < 0 )
+ goto out;
+
+ free( member_name );
+
+ } /* i */
+
+ /* Release the datatype. */
+ if ( H5Tclose( ftype_id ) < 0 )
+ return -1;
+ if ( H5Tclose( native_type_id ) < 0 )
+ return -1;
+
+ /* End access to the dataset */
+ if ( H5Dclose( did ) < 0 )
+ return -1;
+
+return 0;
+
+out:
+ H5Dclose( did );
+ return -1;
+
+}
+
+/*-------------------------------------------------------------------------
+ *
+ * Private functions
+ *
+ *-------------------------------------------------------------------------
+ */
+
+/*-------------------------------------------------------------------------
+ * Function: H5TB_find_field
+ *
+ * Purpose: Find a string field
+ *
+ * Return: Success: 0, Failure: -1
+ *
+ * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
+ *
+ * Date: November 19, 2001
+ *
+ *-------------------------------------------------------------------------
+ */
+
+
+int H5TB_find_field( const char *field, const char *field_list )
+{
+ const char *start = field_list;
+ const char *end;
+
+ while ( (end = strstr( start, "," )) != 0 ) {
+ if ( strncmp(start,field,(size_t)(end-start)) == 0 ) return 1;
+ start = end + 1;
+ }
+
+ if ( strcmp( start, field ) == 0 ) return 1;
+
+ return -1;
+
+}
+
+
+/*-------------------------------------------------------------------------
+ * Function: H5TB_attach_attributes
+ *
+ * Purpose: Private function that creates the conforming table attributes;
+ * Used by H5TBcombine_tables; not used by H5TBmake_table, which does not read
+ * the fill value attributes from an existing table
+ *
+ * Return: Success: 0, Failure: -1
+ *
+ * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
+ *
+ * Date: December 6, 2001
+ *
+ * Comments:
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+
+
+herr_t H5TB_attach_attributes( const char *table_title,
+ hid_t loc_id,
+ const char *dset_name,
+ hsize_t nfields,
+ hid_t tid )
+{
+
+ char attr_name[255];
+ char *member_name;
+ char aux[255];
+ hsize_t i;
+
+ /* Attach the CLASS attribute */
+ if ( H5LTset_attribute_string( loc_id, dset_name, "CLASS", "TABLE" ) < 0 )
+ goto out;
+
+ /* Attach the VERSION attribute */
+ if ( H5LTset_attribute_string( loc_id, dset_name, "VERSION", "2.0" ) < 0 )
+ goto out;
+
+ /* Attach the TITLE attribute */
+ if ( H5LTset_attribute_string( loc_id, dset_name, "TITLE", table_title ) < 0 )
+ goto out;
+
+ /* Attach the FIELD_ name attribute */
+ for ( i = 0; i < nfields; i++)
+ {
+
+ /* Get the member name */
+ member_name = H5Tget_member_name( tid, (unsigned)i );
+
+ strcpy( attr_name, "FIELD_" );
+ sprintf( aux, "%d", (int)i );
+ strcat( attr_name, aux );
+ sprintf( aux, "%s", "_NAME" );
+ strcat( attr_name, aux );
+
+ /* Attach the attribute */
+ if ( H5LTset_attribute_string( loc_id, dset_name, attr_name, member_name ) < 0 )
+ goto out;
+
+ free( member_name );
+
+ }
+
+ return 0;
+
+out:
+ return -1;
+
+}
+
+/*-------------------------------------------------------------------------
+ * Function: H5TB_create_type
+ *
+ * Purpose: Private function that creates a memory type ID
+ *
+ * Return: Success: the memory type ID, Failure: -1
+ *
+ * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
+ *
+ * Date: March 31, 2004
+ *
+ * Comments:
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+
+hid_t H5TB_create_type(hid_t loc_id,
+ const char *dset_name,
+ size_t dst_size,
+ const size_t *dst_offset,
+ const size_t *dst_sizes,
+ hid_t ftype_id)
+{
+ hid_t mem_type_id;
+ hid_t mtype_id=-1;
+ hid_t nmtype_id=-1;
+ size_t size_native;
+ hsize_t nfields;
+ char **fnames;
+ unsigned i;
+
+ /* get the number of fields */
+ if (H5TBget_table_info(loc_id,dset_name,&nfields,NULL)<0)
+ return -1;
+
+ if ((fnames=malloc(sizeof(char*)*(size_t)nfields))==NULL)
+ return -1;
+
+ for ( i=0; i<nfields; i++)
+ {
+ if ((fnames[i]=malloc(sizeof(char)*HLTB_MAX_FIELD_LEN))==NULL) {
+ free(fnames);
+ return -1;
+ }
+ }
+
+ /* get field info */
+ if ( H5TBget_field_info(loc_id,dset_name,fnames,NULL,NULL,NULL)<0)
+ goto out;
+
+ /* create the memory data type */
+ if ((mem_type_id=H5Tcreate(H5T_COMPOUND,dst_size))<0)
+ goto out;
+
+ /* get each field ID and adjust its size, if necessary */
+ for ( i=0; i<nfields; i++)
+ {
+ if ((mtype_id=H5Tget_member_type(ftype_id,i))<0)
+ goto out;
+ if ((nmtype_id=H5Tget_native_type(mtype_id,H5T_DIR_DEFAULT))<0)
+ goto out;
+ size_native=H5Tget_size(nmtype_id);
+ if (dst_sizes[i]!=size_native)
+ {
+ if (H5Tset_size(nmtype_id,dst_sizes[i])<0)
+ goto out;
+ }
+ if (H5Tinsert(mem_type_id,fnames[i],dst_offset[i],nmtype_id) < 0 )
+ goto out;
+ if (H5Tclose(mtype_id)<0)
+ goto out;
+ if (H5Tclose(nmtype_id)<0)
+ goto out;
+ }
+
+ for ( i=0; i<nfields; i++)
+ {
+ free (fnames[i]);
+ }
+ free (fnames);
+
+ return mem_type_id;
+
+ /* error zone, gracefully close and free */
+out:
+ H5E_BEGIN_TRY {
+ H5Tclose(mtype_id);
+ H5Tclose(nmtype_id);
+ } H5E_END_TRY;
+ for ( i=0; i<nfields; i++)
+ {
+ if (fnames[i])
+ free (fnames[i]);
+ }
+ if (fnames)
+ free (fnames);
+ return -1;
+
+}
+
diff --git a/hl/src/H5TA.h b/hl/src/H5TA.h
new file mode 100644
index 0000000..0b75228
--- /dev/null
+++ b/hl/src/H5TA.h
@@ -0,0 +1,246 @@
+
+/****************************************************************************
+ * NCSA HDF *
+ * Scientific Data Technologies *
+ * National Center for Supercomputing Applications *
+ * University of Illinois at Urbana-Champaign *
+ * 605 E. Springfield, Champaign IL 61820 *
+ * *
+ * For conditions of distribution and use, see the accompanying *
+ * hdf/COPYING file. *
+ * *
+ ****************************************************************************/
+
+
+#ifndef _H5TB_H
+#define _H5TB_H
+
+#if 0
+#define H5_TB_DEBUG
+#endif
+
+#include "H5LT.h"
+
+#define HLTB_MAX_FIELD_LEN 255
+
+#if !defined(MAX)
+#define MAX(X,Y) ((X)>(Y)?(X):(Y))
+#endif
+
+
+
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+/*-------------------------------------------------------------------------
+ *
+ * Create functions
+ *
+ *-------------------------------------------------------------------------
+ */
+
+herr_t H5TBmake_table( const char *table_title,
+ hid_t loc_id,
+ const char *dset_name,
+ hsize_t nfields,
+ hsize_t nrecords,
+ size_t type_size,
+ const char *field_names[],
+ const size_t *field_offset,
+ const hid_t *field_types,
+ hsize_t chunk_size,
+ void *fill_data,
+ int compress,
+ const void *data );
+
+
+/*-------------------------------------------------------------------------
+ *
+ * Write functions
+ *
+ *-------------------------------------------------------------------------
+ */
+
+herr_t H5TBappend_records( hid_t loc_id,
+ const char *dset_name,
+ hsize_t nrecords,
+ size_t type_size,
+ const size_t *field_offset,
+ const size_t *dst_sizes,
+ const void *data );
+
+herr_t H5TBwrite_records( hid_t loc_id,
+ const char *dset_name,
+ hsize_t start,
+ hsize_t nrecords,
+ size_t type_size,
+ const size_t *field_offset,
+ const size_t *dst_sizes,
+ const void *data );
+
+
+herr_t H5TBwrite_fields_name( hid_t loc_id,
+ const char *dset_name,
+ const char *field_names,
+ hsize_t start,
+ hsize_t nrecords,
+ size_t type_size,
+ const size_t *field_offset,
+ const size_t *dst_sizes,
+ const void *data );
+
+herr_t H5TBwrite_fields_index( hid_t loc_id,
+ const char *dset_name,
+ hsize_t nfields,
+ const int *field_index,
+ hsize_t start,
+ hsize_t nrecords,
+ size_t type_size,
+ const size_t *field_offset,
+ const size_t *dst_sizes,
+ const void *data );
+
+
+/*-------------------------------------------------------------------------
+ *
+ * Read functions
+ *
+ *-------------------------------------------------------------------------
+ */
+
+
+
+herr_t H5TBread_table( hid_t loc_id,
+ const char *dset_name,
+ size_t dst_size,
+ const size_t *dst_offset,
+ const size_t *dst_sizes,
+ void *dst_buf );
+
+
+herr_t H5TBread_fields_name( hid_t loc_id,
+ const char *dset_name,
+ const char *field_names,
+ hsize_t start,
+ hsize_t nrecords,
+ size_t type_size,
+ const size_t *field_offset,
+ const size_t *dst_sizes,
+ void *data );
+
+herr_t H5TBread_fields_index( hid_t loc_id,
+ const char *dset_name,
+ hsize_t nfields,
+ const int *field_index,
+ hsize_t start,
+ hsize_t nrecords,
+ size_t type_size,
+ const size_t *field_offset,
+ const size_t *dst_sizes,
+ void *data );
+
+
+herr_t H5TBread_records( hid_t loc_id,
+ const char *dset_name,
+ hsize_t start,
+ hsize_t nrecords,
+ size_t type_size,
+ const size_t *dst_offset,
+ const size_t *dst_sizes,
+ void *data );
+
+/*-------------------------------------------------------------------------
+ *
+ * Inquiry functions
+ *
+ *-------------------------------------------------------------------------
+ */
+
+
+herr_t H5TBget_table_info ( hid_t loc_id,
+ const char *dset_name,
+ hsize_t *nfields,
+ hsize_t *nrecords );
+
+herr_t H5TBget_field_info( hid_t loc_id,
+ const char *dset_name,
+ char *field_names[],
+ size_t *field_sizes,
+ size_t *field_offsets,
+ size_t *type_size );
+
+
+/*-------------------------------------------------------------------------
+ *
+ * Manipulation functions
+ *
+ *-------------------------------------------------------------------------
+ */
+
+
+herr_t H5TBdelete_record( hid_t loc_id,
+ const char *dset_name,
+ hsize_t start,
+ hsize_t nrecords );
+
+
+herr_t H5TBinsert_record( hid_t loc_id,
+ const char *dset_name,
+ hsize_t start,
+ hsize_t nrecords,
+ size_t dst_size,
+ const size_t *dst_offset,
+ const size_t *dst_sizes,
+ void *data );
+
+herr_t H5TBadd_records_from( hid_t loc_id,
+ const char *dset_name1,
+ hsize_t start1,
+ hsize_t nrecords,
+ const char *dset_name2,
+ hsize_t start2 );
+
+herr_t H5TBcombine_tables( hid_t loc_id1,
+ const char *dset_name1,
+ hid_t loc_id2,
+ const char *dset_name2,
+ const char *dset_name3 );
+
+herr_t H5TBinsert_field( hid_t loc_id,
+ const char *dset_name,
+ const char *field_name,
+ hid_t field_type,
+ hsize_t position,
+ const void *fill_data,
+ const void *data );
+
+herr_t H5TBdelete_field( hid_t loc_id,
+ const char *dset_name,
+ const char *field_name );
+
+
+/*-------------------------------------------------------------------------
+ *
+ * Table attribute functions
+ *
+ *-------------------------------------------------------------------------
+ */
+
+herr_t H5TBAget_title( hid_t loc_id,
+ char *table_title );
+
+herr_t H5TBAget_fill( hid_t loc_id,
+ const char *dset_name,
+ hid_t dset_id,
+ unsigned char *dst_buf );
+
+#ifdef __cplusplus
+}
+#endif
+
+
+#endif
+
diff --git a/hl/src/Makefile.in b/hl/src/Makefile.in
new file mode 100644
index 0000000..76ab0e1
--- /dev/null
+++ b/hl/src/Makefile.in
@@ -0,0 +1,34 @@
+## HDF5 Library Makefile(.in)
+##
+## Copyright (C) 2001 National Center for Supercomputing Applications.
+## All rights reserved.
+##
+##
+top_srcdir=@top_srcdir@
+top_builddir=../..
+srcdir=@srcdir@
+@COMMENCE@
+
+## Add `-I.' to the C preprocessor flags.
+CPPFLAGS=-I. -I$(srcdir) -I$(top_builddir)/src -I$(top_srcdir)/src -I$(top_srcdir)/tools/lib @CPPFLAGS@
+
+## This is our main target, but also remove the settings file when cleaning.
+LIB=libhdf5_hl.la
+LIBHDF5=$(top_builddir)/src/libhdf5.la
+CLEAN=
+
+## Source and object files for the library (lexicographically)...
+LIB_SRC=H5LT.c H5TA.c H5IM.c
+
+LIB_OBJ=$(LIB_SRC:.c=.lo)
+
+## Temporary files
+MOSTLYCLEAN=
+
+## Public header files (to be installed)...
+PUB_HDR=H5IM.h H5LT.h H5TA.h H5HL.h
+
+## Other header files (not to be installed)...
+PRIVATE_HDR=
+
+@CONCLUDE@