summaryrefslogtreecommitdiffstats
path: root/hl
diff options
context:
space:
mode:
authorPedro Vicente Nunes <pvn@hdfgroup.org>2009-01-08 16:43:48 (GMT)
committerPedro Vicente Nunes <pvn@hdfgroup.org>2009-01-08 16:43:48 (GMT)
commit3c864efa3acef5f7219abccac70e89d20a5e47a1 (patch)
tree7d1cac398b0124f78952a60d8e8d954b39770db6 /hl
parentddc4d16e5a5c1beb65f7bee8f68a6c6554ede58e (diff)
downloadhdf5-3c864efa3acef5f7219abccac70e89d20a5e47a1.zip
hdf5-3c864efa3acef5f7219abccac70e89d20a5e47a1.tar.gz
hdf5-3c864efa3acef5f7219abccac70e89d20a5e47a1.tar.bz2
[svn-r16277] H5TBdelete_record was not handling correctly records at the end of the table.
added a ckeck that avoids to read these records if they are not needed (for pushing down the table) Marked the Table version as 3.0, and "NROWS" attribute writing (in H5TBdelete_record) was deprecated Added a test to shrink to dimensions 0 Merged the code from the Table API in trunk to the 1.6 version tested: windows, linux
Diffstat (limited to 'hl')
-rw-r--r--hl/src/H5TA.c5896
-rw-r--r--hl/src/H5TA.h33
-rw-r--r--hl/test/test_table.c2972
3 files changed, 4487 insertions, 4414 deletions
diff --git a/hl/src/H5TA.c b/hl/src/H5TA.c
index 065303d..49f49de 100644
--- a/hl/src/H5TA.c
+++ b/hl/src/H5TA.c
@@ -18,28 +18,29 @@
#include <string.h>
+
/*-------------------------------------------------------------------------
*
- * Private functions
+ * internal functions
*
*-------------------------------------------------------------------------
*/
-int H5TB_find_field(const char *field,
- const char *field_list);
+static 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 );
+static 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);
+static hid_t H5TB_create_type(hid_t loc_id,
+ const char *dset_name,
+ size_t type_size,
+ const size_t *field_offset,
+ const size_t *field_sizes,
+ hid_t ftype_id);
/*-------------------------------------------------------------------------
*
@@ -60,7 +61,7 @@ hid_t H5TB_create_type(hid_t loc_id,
*
* Date: January 17, 2001
*
- * Comments:
+ * Comments:
*
* Modifications:
*
@@ -80,187 +81,186 @@ herr_t H5TBmake_table( const char *table_title,
hsize_t chunk_size,
void *fill_data,
int compress,
- const void *data )
+ const void *buf )
{
-
- 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 */
+
+ 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.
+ */
+ 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 (buf)
+ {
+ /* Write data to the dataset. */
+ if (H5Dwrite( did, mem_type_id, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf ) < 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_CLASS ) < 0)
+ goto out;
+
+ /* attach the VERSION attribute */
+ if (H5LTset_attribute_string( loc_id, dset_name, "VERSION", TABLE_VERSION ) < 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);
+ }
+
+ /* terminate access to the data space. */
+ if (H5Sclose(sid) < 0)
+ goto out;
+
+ /* end access to the dataset */
+ if (H5Dclose(did) < 0)
+ goto out;
+ }
+
+ /* release the datatype. */
+ if (H5Tclose( mem_type_id ) < 0)
+ return -1;
+
+ return 0;
+
+ /* error zone */
out:
- H5E_BEGIN_TRY {
- H5Dclose(did);
- H5Sclose(sid);
- H5Pclose(plist_id);
- H5Tclose(mem_type_id);
- } H5E_END_TRY;
- return -1;
-
+ H5E_BEGIN_TRY {
+ H5Dclose(did);
+ H5Sclose(sid);
+ H5Pclose(plist_id);
+ H5Tclose(mem_type_id);
+ } H5E_END_TRY;
+ return -1;
+
}
/*-------------------------------------------------------------------------
@@ -286,7 +286,7 @@ out:
* Comments: Uses memory offsets
*
* Modifications: April 1, 2004
- * the DST_SIZES parameter is used to define the memory type ID
+ * the FIELD_SIZES parameter is used to define the memory type ID
* returned by H5TB_create_type
*
*-------------------------------------------------------------------------
@@ -295,99 +295,59 @@ out:
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 )
+ size_t type_size,
+ const size_t *field_offset,
+ const size_t *field_sizes,
+ const void *buf )
{
- hid_t did;
- hid_t tid=-1;
- hid_t mem_type_id=-1;
- hsize_t count[1];
- hsize_t offset[1];
- hid_t sid=-1;
- hid_t mem_space_id=-1;
- 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 ( 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 */
+ hid_t did;
+ hid_t tid=-1;
+ hid_t mem_type_id=-1;
+ hid_t sid=-1;
+ hid_t m_sid=-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,type_size,field_offset,field_sizes,tid)) < 0)
+ goto out;
+
+ /* append the records */
+ if ((H5TB_common_append_records(did, mem_type_id, (size_t)nrecords, nrecords_orig, buf)) < 0)
+ goto out;
+
+ /* close */
+ if (H5Tclose( tid ) < 0)
+ return -1;
+ if (H5Tclose( mem_type_id ) < 0)
+ goto out;
+ if (H5Dclose( did ) < 0)
+ goto out;
+
+ return 0;
+
+ /* error zone */
out:
- H5E_BEGIN_TRY {
- H5Dclose(did);
- H5Tclose(mem_type_id);
- H5Tclose(tid);
- H5Sclose(mem_space_id);
- H5Sclose(sid);
- } H5E_END_TRY;
- return -1;
+ H5E_BEGIN_TRY
+ {
+ H5Dclose(did);
+ H5Tclose(mem_type_id);
+ H5Tclose(tid);
+ H5Sclose(m_sid);
+ H5Sclose(sid);
+ } H5E_END_TRY;
+ return -1;
}
/*-------------------------------------------------------------------------
@@ -404,7 +364,7 @@ out:
* Comments: Uses memory offsets
*
* Modifications: April 1, 2004
- * the DST_SIZES parameter is used to define the memory type ID
+ * the FIELD_SIZES parameter is used to define the memory type ID
* returned by H5TB_create_type
*
*-------------------------------------------------------------------------
@@ -415,91 +375,83 @@ 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 )
+ size_t type_size,
+ const size_t *field_offset,
+ const size_t *field_sizes,
+ const void *buf )
{
-
- hid_t did;
- hid_t tid;
- hsize_t count[1];
- hsize_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 */
+
+ hid_t did;
+ hid_t tid;
+ hsize_t count[1];
+ hsize_t offset[1];
+ hid_t sid=-1;
+ hid_t m_sid=-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,type_size,field_offset,field_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 ((m_sid = H5Screate_simple( 1, mem_size, NULL )) < 0)
+ goto out;
+
+ if (H5Dwrite( did, mem_type_id, m_sid, sid, H5P_DEFAULT, buf ) < 0)
+ goto out;
+
+ /* close */
+ if (H5Sclose( m_sid ) < 0)
+ goto out;
+ if (H5Sclose( sid ) < 0)
+ goto out;
+ if (H5Tclose( tid ) < 0)
+ goto out;
+ if (H5Tclose( mem_type_id ) < 0)
+ return -1;
+ if (H5Dclose( did ) < 0)
+ return -1;
+
+ return 0;
+
+ /* error zone */
out:
- H5E_BEGIN_TRY {
- H5Dclose(did);
- H5Tclose(mem_type_id);
- H5Tclose(tid);
- H5Sclose(mem_space_id);
- H5Sclose(sid);
- } H5E_END_TRY;
- return -1;
+ H5E_BEGIN_TRY
+ {
+ H5Dclose(did);
+ H5Tclose(mem_type_id);
+ H5Tclose(tid);
+ H5Sclose(m_sid);
+ H5Sclose(sid);
+ } H5E_END_TRY;
+ return -1;
}
/*-------------------------------------------------------------------------
@@ -516,8 +468,7 @@ out:
* Comments:
*
* Modifications: April 1, 2004
- * the DST_SIZES parameter is used to define the memory type ID
- * returned by H5TB_create_type
+ * the FIELD_SIZES parameter is used to define a memory type ID
*
*-------------------------------------------------------------------------
*/
@@ -528,145 +479,145 @@ herr_t H5TBwrite_fields_name( hid_t loc_id,
hsize_t nrecords,
size_t type_size,
const size_t *field_offset,
- const size_t *dst_sizes,
- const void *data )
+ const size_t *field_sizes,
+ const void *buf )
{
-
- 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];
- hsize_t offset[1];
- hid_t mem_space_id=-1;
- hid_t file_space_id=-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 handles */
- if ( (file_space_id = H5Dget_space( did )) < 0 )
- goto out;
- if ( (mem_space_id = H5Screate_simple(1, &nrecords, NULL)) < 0 )
- goto out;
-
- /* Define a hyperslab in the dataset */
- offset[0] = start;
- count[0] = nrecords;
- if ( H5Sselect_hyperslab(file_space_id, H5S_SELECT_SET, offset, NULL, count, NULL) < 0 )
- goto out;
-
- /* Write */
- if ( H5Dwrite( did, write_type_id, mem_space_id, file_space_id, PRESERVE, data ) < 0 )
- goto out;
-
- /* close */
- if ( H5Tclose( write_type_id ) )
- goto out;
- if ( H5Tclose( tid ) < 0 )
- return -1;
- if ( H5Dclose( did ) < 0 )
- return -1;
- if ( H5Pclose( PRESERVE ) < 0 )
- return -1;
- if ( H5Sclose( file_space_id ) < 0 )
- return -1;
- if ( H5Sclose( mem_space_id ) < 0 )
- return -1;
-
-return 0;
-
- /* error zone, gracefully close */
+ 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];
+ hsize_t offset[1];
+ hid_t m_sid=-1;
+ hid_t file_space_id=-1;
+ char *member_name;
+ hssize_t nfields;
+ hssize_t i, j;
+ hid_t preserve_id;
+ size_t size_native;
+
+ /* create xfer properties to preserve initialized data */
+ if ((preserve_id = H5Pcreate (H5P_DATASET_XFER)) < 0)
+ return -1;
+ if (H5Pset_preserve (preserve_id, 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 (field_sizes[j]!=size_native)
+ {
+ if (H5Tset_size(nmtype_id, field_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, (size_t)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 ((file_space_id = H5Dget_space( did )) < 0)
+ goto out;
+ if ((m_sid = H5Screate_simple(1, &nrecords, NULL)) < 0)
+ goto out;
+
+ /* define a hyperslab in the dataset */
+ offset[0] = start;
+ count[0] = nrecords;
+ if (H5Sselect_hyperslab( file_space_id, H5S_SELECT_SET, offset, NULL, count, NULL) < 0)
+ goto out;
+
+ /* write */
+ if (H5Dwrite( did, write_type_id, m_sid, file_space_id, preserve_id, buf ) < 0)
+ goto out;
+
+ /* close */
+ if(H5Tclose( write_type_id ) )
+ goto out;
+ if(H5Tclose( tid ) < 0)
+ return -1;
+ if(H5Dclose( did ) < 0)
+ return -1;
+ if(H5Pclose( preserve_id ) < 0)
+ return -1;
+ if(H5Sclose( file_space_id ) < 0)
+ return -1;
+ if(H5Sclose( m_sid ) < 0)
+ return -1;
+
+ return 0;
+
+ /* error zone */
out:
- H5E_BEGIN_TRY {
- H5Pclose(PRESERVE);
- H5Dclose(did);
- H5Sclose(file_space_id);
- H5Sclose(mem_space_id);
- H5Tclose(write_type_id);
- H5Tclose(tid);
- } H5E_END_TRY;
- return -1;
-
+ H5E_BEGIN_TRY
+ {
+ H5Pclose(preserve_id);
+ H5Dclose(did);
+ H5Sclose(file_space_id);
+ H5Sclose(m_sid);
+ H5Tclose(write_type_id);
+ H5Tclose(tid);
+ } H5E_END_TRY;
+ return -1;
+
}
@@ -685,8 +636,7 @@ out:
* 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
+ * the FIELD_SIZES parameter is used to define a memory type ID
*
*-------------------------------------------------------------------------
*/
@@ -700,137 +650,132 @@ herr_t H5TBwrite_fields_index( hid_t loc_id,
hsize_t nrecords,
size_t type_size,
const size_t *field_offset,
- const size_t *dst_sizes,
- const void *data )
+ const size_t *field_sizes,
+ const void *buf )
{
-
- 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];
- hsize_t offset[1];
- hid_t mem_space_id=-1;
- hid_t file_space_id=-1;
- char *member_name;
- 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 ( 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 handles */
- if ( (file_space_id = H5Dget_space( did )) < 0 )
- goto out;
- if ( (mem_space_id = H5Screate_simple(1, &nrecords, NULL)) < 0 )
- goto out;
-
- /* Define a hyperslab in the dataset */
- offset[0] = start;
- count[0] = nrecords;
- if ( H5Sselect_hyperslab( file_space_id, H5S_SELECT_SET, offset, NULL, count, NULL) < 0 )
- goto out;
-
- /* Write */
- if ( H5Dwrite( did, write_type_id, mem_space_id, file_space_id, PRESERVE, data ) < 0 )
- goto out;
-
- /* close */
- if ( H5Tclose( write_type_id ) )
- goto out;
- if ( H5Tclose( tid ) < 0 )
- return -1;
- if ( H5Dclose( did ) < 0 )
- return -1;
- if ( H5Pclose( PRESERVE ) < 0 )
- return -1;
- if ( H5Sclose( file_space_id ) < 0 )
- return -1;
- if ( H5Sclose( mem_space_id ) < 0 )
- return -1;
-
-return 0;
-
- /* error zone, gracefully close */
+ 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];
+ hsize_t offset[1];
+ hid_t m_sid=-1;
+ hid_t file_space_id=-1;
+ char *member_name;
+ hsize_t i, j;
+ hid_t preserve_id;
+ size_t size_native;
+
+ /* create xfer properties to preserve initialized data */
+ if ((preserve_id = H5Pcreate (H5P_DATASET_XFER)) < 0)
+ return -1;
+ if (H5Pset_preserve (preserve_id, 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;
+
+ /* 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 (field_sizes[i]!=size_native)
+ {
+ if (H5Tset_size(nmtype_id, field_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, (size_t)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 handles */
+ if ((file_space_id = H5Dget_space( did )) < 0)
+ goto out;
+ if ((m_sid = H5Screate_simple(1, &nrecords, NULL)) < 0)
+ goto out;
+
+ /* define a hyperslab in the dataset */
+ offset[0] = start;
+ count[0] = nrecords;
+ if (H5Sselect_hyperslab( file_space_id, H5S_SELECT_SET, offset, NULL, count, NULL) < 0)
+ goto out;
+
+ /* write */
+ if (H5Dwrite( did, write_type_id, m_sid, file_space_id, preserve_id, buf ) < 0)
+ goto out;
+
+ /* close */
+ if (H5Tclose( write_type_id ) )
+ goto out;
+ if (H5Tclose( tid ) < 0)
+ return -1;
+ if (H5Dclose( did ) < 0)
+ return -1;
+ if (H5Pclose( preserve_id ) < 0)
+ return -1;
+ if (H5Sclose( file_space_id ) < 0)
+ return -1;
+ if (H5Sclose( m_sid ) < 0)
+ return -1;
+
+ return 0;
+
+ /* error zone */
out:
- H5E_BEGIN_TRY {
- H5Pclose(PRESERVE);
- H5Dclose(did);
- H5Sclose(file_space_id);
- H5Sclose(mem_space_id);
- H5Tclose(write_type_id);
- H5Tclose(tid);
- } H5E_END_TRY;
- return -1;
+ H5E_BEGIN_TRY
+ {
+ H5Pclose(preserve_id);
+ H5Dclose(did);
+ H5Sclose(file_space_id);
+ H5Sclose(m_sid);
+ H5Tclose(write_type_id);
+ H5Tclose(tid);
+ } H5E_END_TRY;
+ return -1;
}
@@ -863,61 +808,62 @@ out:
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,
+ size_t type_size,
+ const size_t *field_offset,
+ const size_t *field_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 */
+ 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,type_size,field_offset,field_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 */
out:
- H5E_BEGIN_TRY {
- H5Dclose(did);
- H5Tclose(mem_type_id);
- H5Tclose(ftype_id);
- H5Sclose(sid);
- } H5E_END_TRY;
- return -1;
+ H5E_BEGIN_TRY
+ {
+ H5Dclose(did);
+ H5Tclose(mem_type_id);
+ H5Tclose(ftype_id);
+ H5Sclose(sid);
+ } H5E_END_TRY;
+ return -1;
}
/*-------------------------------------------------------------------------
@@ -934,7 +880,7 @@ out:
* Comments:
*
* Modifications: April 1, 2004
- * the DST_SIZES parameter is used to define the memory type ID
+ * the FIELD_SIZES parameter is used to define the memory type ID
* returned by H5TB_create_type
*
*-------------------------------------------------------------------------
@@ -945,90 +891,60 @@ 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 )
+ size_t type_size,
+ const size_t *field_offset,
+ const size_t *field_sizes,
+ void *buf )
{
-
- hid_t did;
- hid_t ftype_id;
- hid_t mem_type_id=-1;
- hsize_t count[1];
- hsize_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 */
+
+ hid_t did;
+ hid_t ftype_id;
+ hid_t mem_type_id=-1;
+ hid_t sid=-1;
+ hid_t m_sid=-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,type_size,field_offset,field_sizes,ftype_id)) < 0)
+ goto out;
+
+ /* read the records */
+ if ((H5TB_common_read_records(did, mem_type_id, start, (size_t)nrecords, nrecords_orig, buf)) < 0)
+ goto out;
+
+ /* close */
+ 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 */
out:
- H5E_BEGIN_TRY {
- H5Dclose(did);
- H5Tclose(mem_type_id);
- H5Tclose(ftype_id);
- H5Sclose(mem_space_id);
- H5Sclose(sid);
- } H5E_END_TRY;
- return -1;
-
+ H5E_BEGIN_TRY {
+ H5Dclose(did);
+ H5Tclose(mem_type_id);
+ H5Tclose(ftype_id);
+ H5Sclose(m_sid);
+ H5Sclose(sid);
+ } H5E_END_TRY;
+ return -1;
+
}
@@ -1046,7 +962,7 @@ out:
* Comments:
*
* Modifications: April 1, 2004
- * the DST_SIZES parameter is used to define the memory type ID
+ * the FIELD_SIZES parameter is used to define the memory type ID
* returned by H5TB_create_type
*
*-------------------------------------------------------------------------
@@ -1060,130 +976,131 @@ herr_t H5TBread_fields_name( hid_t loc_id,
hsize_t nrecords,
size_t type_size,
const size_t *field_offset,
- const size_t *dst_sizes,
- void *data )
+ const size_t *field_sizes,
+ void *buf )
{
- 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];
- hsize_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 */
+ 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];
+ hsize_t offset[1];
+ hid_t sid=-1;
+ hid_t m_sid=-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 (field_sizes[j]!=size_native)
+ {
+ if (H5Tset_size(nmtype_id, field_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, (size_t)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 ((m_sid = H5Screate_simple( 1, mem_size, NULL )) < 0)
+ goto out;
+
+ /* read */
+ if (H5Dread( did, mem_type_id, m_sid, sid, H5P_DEFAULT, buf ) < 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( m_sid ) < 0)
+ goto out;
+ if (H5Dclose( did ) < 0)
+ return -1;
+
+ return 0;
+
+ /* error zone */
out:
- H5E_BEGIN_TRY {
- H5Dclose(did);
- H5Tclose(mem_type_id);
- H5Tclose(ftype_id);
- H5Sclose(mem_space_id);
- H5Sclose(sid);
- } H5E_END_TRY;
- return -1;
-
+ H5E_BEGIN_TRY
+ {
+ H5Dclose(did);
+ H5Tclose(mem_type_id);
+ H5Tclose(ftype_id);
+ H5Sclose(m_sid);
+ H5Sclose(sid);
+ } H5E_END_TRY;
+ return -1;
+
}
@@ -1201,7 +1118,7 @@ out:
* Comments:
*
* Modifications: April 1, 2004
- * the DST_SIZES parameter is used to define the memory type ID
+ * the FIELD_SIZES parameter is used to define the memory type ID
* returned by H5TB_create_type
*
*-------------------------------------------------------------------------
@@ -1216,137 +1133,130 @@ herr_t H5TBread_fields_index( hid_t loc_id,
hsize_t nrecords,
size_t type_size,
const size_t *field_offset,
- const size_t *dst_sizes,
- void *data )
+ const size_t *field_sizes,
+ void *buf )
{
-
- hid_t did;
- hid_t tid=-1;
- hid_t read_type_id=-1;
- hid_t member_type_id;
- hid_t nmtype_id;
- char *member_name;
- hsize_t count[1];
- hsize_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 ( 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 */
+
+ hid_t did;
+ hid_t tid=-1;
+ hid_t read_type_id=-1;
+ hid_t member_type_id;
+ hid_t nmtype_id;
+ char *member_name;
+ hsize_t count[1];
+ hsize_t offset[1];
+ hid_t sid=-1;
+ hid_t m_sid=-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 (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 (field_sizes[i]!=size_native)
+ {
+ if (H5Tset_size(nmtype_id, field_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, (size_t)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 ((m_sid = H5Screate_simple( 1, mem_size, NULL )) < 0)
+ goto out;
+
+ /* read */
+ if (H5Dread( did, read_type_id, m_sid, sid, H5P_DEFAULT, buf ) < 0)
+ goto out;
+
+ /* close */
+ if (H5Sclose( sid ) < 0)
+ goto out;
+ if (H5Sclose( m_sid ) < 0)
+ goto out;
+ if (H5Tclose( read_type_id ) )
+ goto out;
+ if (H5Tclose( tid ) < 0)
+ return -1;
+ if (H5Dclose( did ) < 0)
+ return -1;
+
+ return 0;
+
+ /* error zone */
out:
- H5E_BEGIN_TRY {
- H5Dclose(did);
- H5Tclose(read_type_id);
- H5Tclose(tid);
- H5Sclose(mem_space_id);
- H5Sclose(sid);
- } H5E_END_TRY;
- return -1;
-
+ H5E_BEGIN_TRY
+ {
+ H5Dclose(did);
+ H5Tclose(read_type_id);
+ H5Tclose(tid);
+ H5Sclose(m_sid);
+ H5Sclose(sid);
+ } H5E_END_TRY;
+ return -1;
+
}
@@ -1379,141 +1289,140 @@ herr_t H5TBdelete_record( hid_t loc_id,
hsize_t start,
hsize_t nrecords )
{
+
+ hsize_t nfields;
+ hsize_t ntotal_records;
+ hsize_t read_start;
+ hsize_t read_nrecords;
+ hid_t did=-1;
+ hid_t tid=-1;
+ hid_t sid=-1;
+ hid_t m_sid=-1;
+ hsize_t count[1];
+ hsize_t offset[1];
+ hsize_t mem_size[1];
+ unsigned char *tmp_buf=NULL;
+ size_t src_size;
+ size_t *src_offset;
+ size_t *src_sizes;
+ hsize_t dims[1];
+
+ /*-------------------------------------------------------------------------
+ * 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;
+ if (src_sizes == NULL )
+ return -1;
+
+ /* get field info */
+ if (H5TBget_field_info( loc_id, dset_name, NULL, src_sizes, src_offset, &src_size ) < 0)
+ return -1;
- 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];
- hsize_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;
- hsize_t dims[1];
-
-
-/*-------------------------------------------------------------------------
- * 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
- *-------------------------------------------------------------------------
- */
- dims[0] = ntotal_records - nrecords;
- if ( H5Dset_extent( did, dims ) < 0 )
- goto out;
-
- /* 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;
-
+ /* open the dataset. */
+ if ((did = H5Dopen(loc_id, dset_name)) < 0)
+ return -1;
+
+ /*-------------------------------------------------------------------------
+ * read the records after the deleted one(s)
+ *-------------------------------------------------------------------------
+ */
+
+ read_start = start + nrecords;
+ read_nrecords = ntotal_records - read_start;
- return 0;
+ if ( read_nrecords )
+ {
+ 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
+ *-------------------------------------------------------------------------
+ */
+
+ /* 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 ((m_sid = H5Screate_simple( 1, mem_size, NULL )) < 0)
+ goto out;
+
+ if (H5Dwrite( did, tid, m_sid, sid, H5P_DEFAULT, tmp_buf ) < 0)
+ goto out;
+
+ /* close */
+ if (H5Sclose( m_sid ) < 0)
+ goto out;
+ if (H5Sclose( sid ) < 0)
+ goto out;
+ if (H5Tclose( tid ) < 0)
+ goto out;
+
+ } /* read_nrecords */
+
+
+ /*-------------------------------------------------------------------------
+ * change the dataset dimension
+ *-------------------------------------------------------------------------
+ */
+ dims[0] = ntotal_records - nrecords;
+ if (H5Dset_extent( did, dims ) < 0)
+ goto out;
+
+ /* close dataset */
+ if (H5Dclose( did ) < 0)
+ return -1;
+
+ if (tmp_buf !=NULL)
+ free( tmp_buf );
+ free( src_offset );
+ free( src_sizes );
+
+
+ return 0;
+ /* error zone */
out:
- H5Dclose( did );
- return -1;
+
+ if (tmp_buf !=NULL )
+ free( tmp_buf );
+ H5E_BEGIN_TRY
+ {
+ H5Dclose(did);
+ H5Tclose(tid);
+ H5Sclose(sid);
+ } H5E_END_TRY;
+ return -1;
+
+
}
/*-------------------------------------------------------------------------
@@ -1530,7 +1439,7 @@ out:
* Comments: Uses memory offsets
*
* Modifications: April 1, 2004
- * the DST_SIZES parameter is used to define the memory type ID
+ * the FIELD_SIZES parameter is used to define the memory type ID
* returned by H5TB_create_type
*
*-------------------------------------------------------------------------
@@ -1541,146 +1450,139 @@ 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 )
+ size_t type_size,
+ const size_t *field_offset,
+ const size_t *field_sizes,
+ void *buf )
{
-
- 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];
- hsize_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 */
+
+ 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];
+ hsize_t offset[1];
+ hid_t sid=-1;
+ hid_t m_sid=-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,type_size,field_offset,field_sizes,tid)) < 0)
+ goto out;
+
+ read_nrecords = ntotal_records - start;
+ tmp_buf = (unsigned char *)calloc((size_t) read_nrecords, type_size);
+
+ /* read the records after the inserted one(s) */
+ if (H5TBread_records( loc_id, dset_name, start, read_nrecords, type_size, field_offset, field_sizes, tmp_buf ) < 0)
+ return -1;
+
+ /* extend the dataset */
+ dims[0] = ntotal_records + nrecords;
+
+ if (H5Dset_extent(did, dims) < 0)
+ goto out;
+
+ /*-------------------------------------------------------------------------
+ * write the inserted records
+ *-------------------------------------------------------------------------
+ */
+
+ /* create a simple memory data space */
+ mem_dims[0] = nrecords;
+ if ((m_sid = 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, m_sid, sid, H5P_DEFAULT, buf ) < 0)
+ goto out;
+
+ /* terminate access to the dataspace */
+ if (H5Sclose( m_sid ) < 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 ((m_sid = 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, m_sid, sid, H5P_DEFAULT, tmp_buf ) < 0)
+ goto out;
+
+ /* close */
+ if (H5Sclose( m_sid ) < 0)
+ goto out;
+ if (H5Sclose( sid ) < 0)
+ goto out;
+ if (H5Tclose( tid ) < 0)
+ return -1;
+ if (H5Tclose( mem_type_id ) < 0)
+ return -1;
+ if (H5Dclose( did ) < 0)
+ return -1;
+
+ free( tmp_buf );
+
+ return 0;
+
+ /* error zone */
out:
- H5E_BEGIN_TRY {
- H5Dclose(did);
- H5Sclose(sid);
- H5Sclose(mem_space_id);
- H5Tclose(mem_type_id);
- H5Tclose(tid);
- } H5E_END_TRY;
- return -1;
+ H5E_BEGIN_TRY
+ {
+ H5Dclose(did);
+ H5Sclose(sid);
+ H5Sclose(m_sid);
+ H5Tclose(mem_type_id);
+ H5Tclose(tid);
+ } H5E_END_TRY;
+ return -1;
}
/*-------------------------------------------------------------------------
@@ -1709,124 +1611,115 @@ herr_t H5TBadd_records_from( hid_t loc_id,
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;
- size_t type_size1;
-
- hsize_t count[1];
- hsize_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, 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 */
+ hid_t did_1;
+ hid_t tid_1;
+ hid_t sid_1=-1;
+ hid_t msid_1=-1;
+ size_t type_size1;
+ hsize_t count[1];
+ hsize_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 ((did_1 = H5Dopen(loc_id, dset_name1)) < 0)
+ return -1;
+
+ /* get the datatype */
+ if ((tid_1 = H5Dget_type( did_1 )) < 0)
+ goto out;
+
+ /* get the dataspace handle */
+ if ((sid_1 = H5Dget_space( did_1 )) < 0)
+ goto out;
+
+ /* get the size of the datatype */
+ if (( type_size1 = H5Tget_size( tid_1 )) == 0 )
+ goto out;
+
+ tmp_buf = (unsigned char *)calloc((size_t)nrecords, type_size1 );
+
+ /* define a hyperslab in the dataset of the size of the records */
+ offset[0] = start1;
+ count[0] = nrecords;
+ if (H5Sselect_hyperslab( sid_1, H5S_SELECT_SET, offset, NULL, count, NULL) < 0)
+ goto out;
+
+ /* create a memory dataspace handle */
+ mem_size[0] = count[0];
+ if ((msid_1 = H5Screate_simple( 1, mem_size, NULL )) < 0)
+ goto out;
+
+ if (H5Dread( did_1, tid_1, msid_1, sid_1, 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
+ *-------------------------------------------------------------------------
+ */
+
+ if (H5Sclose( msid_1 ) < 0)
+ goto out;
+ if (H5Sclose( sid_1 ) < 0)
+ goto out;
+ if (H5Tclose( tid_1 ) < 0)
+ return -1;
+ if (H5Dclose( did_1 ) < 0)
+ return -1;
+
+ free( tmp_buf );
+ free( src_offset );
+ free( src_sizes );
+
+ return 0;
+
+ /* error zone */
out:
- H5E_BEGIN_TRY {
- H5Dclose(dataset_id1);
- H5Sclose(space_id1);
- H5Sclose(mem_space_id1);
- H5Tclose(type_id1);
- } H5E_END_TRY;
- return -1;
-
+ H5E_BEGIN_TRY
+ {
+ H5Dclose(did_1);
+ H5Sclose(sid_1);
+ H5Sclose(msid_1);
+ H5Tclose(tid_1);
+ } H5E_END_TRY;
+ return -1;
+
}
/*-------------------------------------------------------------------------
@@ -1853,363 +1746,344 @@ herr_t H5TBcombine_tables( hid_t loc_id1,
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];
- hsize_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;
- size_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 */
- member_offset = H5Tget_member_offset( type_id3, (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_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;
-
+
+ /* identifiers for the 1st dataset. */
+ hid_t did_1=-1;
+ hid_t tid_1=-1;
+ hid_t sid_1=-1;
+ hid_t pid_1=-1;
+ /* identifiers for the 2nd dataset. */
+ hid_t did_2=-1;
+ hid_t tid_2=-1;
+ hid_t sid_2=-1;
+ hid_t pid_2=-1;
+ /* identifiers for the 3rd dataset. */
+ hid_t did_3=-1;
+ hid_t tid_3=-1;
+ hid_t sid_3=-1;
+ hid_t pid_3=-1;
+ hsize_t count[1];
+ hsize_t offset[1];
+ hid_t m_sid;
+ 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;
+ size_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 ((did_1 = H5Dopen(loc_id1, dset_name1)) < 0)
+ goto out;
+
+ /* get the datatype */
+ if ((tid_1 = H5Dget_type( did_1 )) < 0)
+ goto out;
+
+ /* get the dataspace handle */
+ if ((sid_1 = H5Dget_space( did_1 )) < 0)
+ goto out;
+
+ /* get creation properties list */
+ if ((pid_1 = H5Dget_create_plist( did_1 )) < 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 ((pid_3 = H5Pcopy(pid_1)) < 0)
+ goto out;
+
+ /* clone the type id */
+ if ((tid_3 = H5Tcopy(tid_1)) < 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 ((sid_3 = H5Screate_simple(1, dims, maxdims)) < 0)
+ return -1;
+
+ /* create the dataset */
+ if ((did_3 = H5Dcreate(loc_id1, dset_name3, tid_3, sid_3, pid_3)) < 0)
+ goto out;
+
+ /*-------------------------------------------------------------------------
+ * attach the conforming table attributes
+ *-------------------------------------------------------------------------
+ */
+ if (H5TB_attach_attributes("Merge table", loc_id1, dset_name3, nfields, tid_3) < 0)
+ goto out;
+
+ /*-------------------------------------------------------------------------
+ * get attributes
+ *-------------------------------------------------------------------------
+ */
+
+ type_size = H5Tget_size(tid_3);
+
+ /* alloc fill value attribute buffer */
+ tmp_fill_buf = (unsigned char *)malloc(type_size);
+
+ /* get the fill value attributes */
+ has_fill = H5TBAget_fill(loc_id1, dset_name1, did_1, 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( tid_3, (unsigned) i )) < 0)
+ goto out;
+
+ /* get the member offset */
+ member_offset = H5Tget_member_offset(tid_3, (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_3, 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( sid_1, H5S_SELECT_SET, offset, NULL, count, NULL) < 0)
+ goto out;
+
+ /* create a memory dataspace handle */
+ mem_size[0] = count[0];
+ if ((m_sid = H5Screate_simple( 1, mem_size, NULL )) < 0)
+ goto out;
+
+ if (H5Dread( did_1, tid_1, m_sid, sid_1, 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
+ *-------------------------------------------------------------------------
+ */
+
+ if (H5Sclose( m_sid ) < 0)
+ goto out;
+ if(H5Sclose( sid_1 ) < 0)
+ goto out;
+ if(H5Tclose( tid_1 ) < 0)
+ goto out;
+ if(H5Pclose( pid_1 ) < 0)
+ goto out;
+ if(H5Dclose( did_1 ) < 0)
+ goto out;
+
+ /* Release resources. */
+ free( tmp_buf );
+
+ /*-------------------------------------------------------------------------
+ * get information about the 2nd table
+ *-------------------------------------------------------------------------
+ */
+
+ /* open the dataset. */
+ if ((did_2 = H5Dopen(loc_id2, dset_name2)) < 0)
+ goto out;
+
+ /* get the datatype */
+ if ((tid_2 = H5Dget_type( did_2 )) < 0)
+ goto out;
+
+ /* get the dataspace handle */
+ if ((sid_2 = H5Dget_space( did_2 )) < 0)
+ goto out;
+
+ /* get the property list handle */
+ if ((pid_2 = H5Dget_create_plist( did_2 )) < 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( sid_2, H5S_SELECT_SET, offset, NULL, count, NULL) < 0)
+ goto out;
+
+ /* create a memory dataspace handle */
+ mem_size[0] = count[0];
+ if ((m_sid = H5Screate_simple( 1, mem_size, NULL )) < 0)
+ goto out;
+
+ if (H5Dread( did_2, tid_2, m_sid, sid_2, 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
+ *-------------------------------------------------------------------------
+ */
+
+ if (H5Sclose( m_sid ) < 0)
+ goto out;
+ if (H5Sclose( sid_2 ) < 0)
+ goto out;
+ if (H5Tclose( tid_2 ) < 0)
+ return -1;
+ if (H5Pclose( pid_2 ) < 0)
+ goto out;
+ if (H5Dclose( did_2 ) < 0)
+ return -1;
+
+ /*-------------------------------------------------------------------------
+ * release resources from 3rd table
+ *-------------------------------------------------------------------------
+ */
+
+ if (H5Sclose( sid_3 ) < 0)
+ return -1;
+ if (H5Tclose( tid_3 ) < 0)
+ return -1;
+ if (H5Pclose( pid_3 ) < 0)
+ return -1;
+ if (H5Dclose( did_3 ) < 0)
+ return -1;
+
+ /* Release resources. */
+ free( tmp_buf );
+ free( tmp_fill_buf );
+ free( src_offset );
+ free( src_sizes );
+
+ return 0;
+
+ /* error zone */
out:
- H5Dclose( dataset_id1 );
- return -1;
-
+ H5E_BEGIN_TRY
+ {
+ H5Dclose(did_1);
+ H5Sclose(sid_1);
+ H5Tclose(tid_1);
+ H5Pclose(pid_1);
+ H5Dclose(did_2);
+ H5Sclose(sid_2);
+ H5Tclose(tid_2);
+ H5Pclose(pid_2);
+ H5Dclose(did_3);
+ H5Sclose(sid_3);
+ H5Tclose(tid_3);
+ H5Pclose(pid_3);
+ } H5E_END_TRY;
+ return -1;
+
}
-
-
/*-------------------------------------------------------------------------
* Function: H5TBinsert_field
*
@@ -2234,310 +2108,282 @@ herr_t H5TBinsert_field( hid_t loc_id,
hid_t field_type,
hsize_t position,
const void *fill_data,
- const void *data )
+ const void *buf )
{
-
- /* 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;
- size_t total_size;
- hsize_t nfields;
- hsize_t nrecords;
- hsize_t dims_chunk[1];
- hsize_t dims[1];
- hsize_t maxdims[1] = { H5S_UNLIMITED };
- hsize_t count[1];
- hsize_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];
- size_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(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 ( 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;
-/*-------------------------------------------------------------------------
+ /* identifiers for the 1st, original dataset */
+ hid_t did_1;
+ hid_t tid_1;
+ hid_t sid_1;
+ hid_t pid_1;
+ hid_t msid_1;
+ /* identifiers for the 2nd, new dataset */
+ hid_t did_2;
+ hid_t tid_2;
+ hid_t sid_2;
+ hid_t pid_2;
+ hid_t msid_2;
+ hid_t member_type_id;
+ size_t member_size;
+ size_t new_member_size = 0;
+ char *member_name;
+ size_t total_size;
+ hsize_t nfields;
+ hsize_t nrecords;
+ hsize_t dims_chunk[1];
+ hsize_t dims[1];
+ hsize_t maxdims[1] = { H5S_UNLIMITED };
+ hsize_t count[1];
+ hsize_t offset[1];
+ hsize_t mem_size[1];
+ hid_t write_type_id;
+ hid_t preserve_id;
+ size_t curr_offset;
+ int inserted;
+ hsize_t idx;
+ char table_title[255];
+ size_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 ((did_1 = H5Dopen(loc_id, dset_name)) < 0)
+ return -1;
+
+ /* get creation properties list */
+ if ((pid_1 = H5Dget_create_plist( did_1 )) < 0)
+ goto out;
+
+ /* get the datatype */
+ if ((tid_1 = H5Dget_type( did_1 )) < 0)
+ goto out;
+
+ /* get the size of the datatype */
+ if (( total_size = H5Tget_size( tid_1 )) == 0 )
+ goto out;
+
+ /* get the dataspace handle */
+ if ((sid_1 = H5Dget_space( did_1 )) < 0)
+ goto out;
+
+ /* get dimension */
+ if (H5Sget_simple_extent_dims( sid_1, dims, NULL) < 0)
+ goto out;
+
+ /*-------------------------------------------------------------------------
+ * get attributes
+ *-------------------------------------------------------------------------
+ */
+
+ /* get the table title */
+ if ((H5TBAget_title( did_1, table_title )) < 0)
+ goto out;
+
+ /* alloc fill value attribute buffer */
+ tmp_fill_buf = (unsigned char *)malloc(total_size );
+
+ /* get the fill value attributes */
+ if ((H5TBAget_fill( loc_id, dset_name, did_1, 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 (( tid_2 = 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( tid_2, 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( tid_1, (unsigned)idx );
+
+ /* get the member type */
+ if (( member_type_id = H5Tget_member_type( tid_1,(unsigned)idx )) < 0)
+ goto out;
+
+ /* get the member size */
+ member_size = H5Tget_size( member_type_id );
+
+ /* insert it into the new type */
+ if (H5Tinsert( tid_2, 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 (H5Pget_chunk(pid_1, 1, dims_chunk) < 0)
+ goto out;
+
+ /* create a new simple data space with unlimited size, using the dimension */
+ if ((sid_2 = H5Screate_simple( 1, dims, maxdims)) < 0)
+ return -1;
+
+ /* modify dataset creation properties, i.e. enable chunking */
+ pid_2 = H5Pcreate(H5P_DATASET_CREATE);
+ if (H5Pset_chunk(pid_2, 1, dims_chunk) < 0)
+ return -1;
+
+ /* create the dataset. */
+ if ((did_2 = H5Dcreate(loc_id, "new", tid_2, sid_2, pid_2)) < 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(sid_1, H5S_SELECT_SET, offset, NULL, count, NULL) < 0)
+ goto out;
+
+ /* create a memory dataspace handle */
+ mem_size[0] = count[0];
+ if ((msid_1 = H5Screate_simple(1, mem_size, NULL)) < 0)
+ goto out;
+
+ if (H5Dread(did_1, tid_1, msid_1, 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( did_2, tid_1, msid_1, 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, (size_t)0, field_type ) < 0)
+ goto out;
+
+ /* create xfer properties to preserve initialized data */
+ if ((preserve_id = H5Pcreate (H5P_DATASET_XFER)) < 0)
+ goto out;
+ if (H5Pset_preserve (preserve_id, 1) < 0)
+ goto out;
+
+ /* only write if there is something to write */
+ if ( buf )
+ {
+ /* create a memory dataspace handle */
+ if ((msid_2 = H5Screate_simple( 1, mem_size, NULL )) < 0)
+ goto out;
+
+ /* write */
+ if (H5Dwrite( did_2, write_type_id, msid_2, sid_2, preserve_id, buf ) < 0)
+ goto out;
+
+ /* terminate access to the memory dataspace */
+ if (H5Sclose( msid_2 ) < 0)
+ goto out;
+ }
+
+ /* end access to the property list */
+ if (H5Pclose( preserve_id ) < 0)
+ goto out;
+
+ /*-------------------------------------------------------------------------
+ * release resources from 1st table
+ *-------------------------------------------------------------------------
+ */
+
+ if (H5Sclose( msid_1 ) < 0)
+ goto out;
+ if (H5Tclose( tid_1 ) < 0)
+ goto out;
+ if (H5Pclose( pid_1 ) < 0)
+ goto out;
+ if (H5Sclose( sid_1 ) < 0)
+ goto out;
+ if (H5Dclose( did_1 ) < 0)
+ goto out;
+
+
+ /*-------------------------------------------------------------------------
+ * release resources from 2nd table
+ *-------------------------------------------------------------------------
+ */
+
+ if (H5Sclose( sid_2 ) < 0)
+ goto out;
+ if (H5Tclose( tid_2 ) < 0)
+ goto out;
+ if (H5Pclose( pid_2 ) < 0)
+ goto out;
+ if (H5Dclose( did_2 ) < 0)
+ goto out;
+
+
+ /*-------------------------------------------------------------------------
* Delete 1st table
*-------------------------------------------------------------------------
*/
@@ -2551,119 +2397,126 @@ herr_t H5TBinsert_field( hid_t loc_id,
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 */
- 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;
- }
-
-/*-------------------------------------------------------------------------
- * 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;
-
+ /*-------------------------------------------------------------------------
+ * 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 ((did_1 = H5Dopen(loc_id, dset_name)) < 0)
+ return -1;
+
+ /* get the datatype */
+ if ((tid_1 = H5Dget_type( did_1 )) < 0)
+ goto out;
+
+ /* set the attributes */
+ if (H5TB_attach_attributes( table_title, loc_id, dset_name,(hsize_t) nfields, tid_1 ) < 0)
+ return -1;
+
+ /*-------------------------------------------------------------------------
+ * attach the fill attributes from previous table
+ *-------------------------------------------------------------------------
+ */
+
+ if (( sid_1 = H5Screate(H5S_SCALAR)) < 0)
+ goto out;
+
+ for ( i = 0; i < nfields-1; i++)
+ {
+ /* get the member type */
+ if(( member_type_id = H5Tget_member_type( tid_1, (unsigned) i )) < 0)
+ goto out;
+
+ /* get the member offset */
+ member_offset = H5Tget_member_offset(tid_1, (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_1, attr_name, member_type_id, sid_1, 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(tid_1, (unsigned)nfields - 1)) < 0)
+ goto out;
+
+ if ((attr_id = H5Acreate(did_1, attr_name, member_type_id, sid_1, 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 */
+ if (H5Sclose( sid_1 ) < 0)
+ goto out;
+ if (H5Tclose( tid_1 ) < 0)
+ goto out;
+ if (H5Dclose( did_1 ) < 0)
+ goto out;
+
+ /* release resources. */
+ free ( tmp_buf );
+ free ( tmp_fill_buf );
+
+ return 0;
+
+ /* error zone */
out:
- H5Dclose( dataset_id1 );
- return -1;
+ H5E_BEGIN_TRY
+ {
+ H5Dclose(did_1);
+ H5Sclose(sid_1);
+ H5Tclose(tid_1);
+ H5Pclose(pid_1);
+ H5Dclose(did_2);
+ H5Sclose(sid_2);
+ H5Tclose(tid_2);
+ H5Pclose(pid_2);
+
+ } H5E_END_TRY;
+ return -1;
+
}
-
/*-------------------------------------------------------------------------
* Function: H5TBdelete_field
*
@@ -2687,341 +2540,320 @@ 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;
- 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 ( 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;
-
-/*-------------------------------------------------------------------------
+ /* identifiers for the 1st original dataset */
+ hid_t did_1;
+ hid_t tid_1;
+ hid_t sid_1;
+ hid_t pid_1;
+ /* identifiers for the 2nd new dataset */
+ hid_t did_2;
+ hid_t tid_2;
+ hid_t sid_2;
+ hid_t pid_2;
+ 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;
+ hsize_t dims_chunk[1];
+ hsize_t dims[1];
+ hsize_t maxdims[1] = { H5S_UNLIMITED };
+ hid_t preserve_id;
+ 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 ((did_1 = H5Dopen(loc_id, dset_name)) < 0)
+ return -1;
+
+ /* get creation properties list */
+ if ((pid_1 = H5Dget_create_plist( did_1 )) < 0)
+ goto out;
+
+ /* get the datatype */
+ if ((tid_1 = H5Dget_type( did_1 )) < 0)
+ goto out;
+
+ /* get the size of the datatype */
+ type_size1 = H5Tget_size( tid_1 );
+
+ /* get the dataspace handle */
+ if ((sid_1 = H5Dget_space( did_1 )) < 0)
+ goto out;
+
+ /* get dimension */
+ if (H5Sget_simple_extent_dims( sid_1, 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( tid_1,(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( tid_1,(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 (( tid_2 = 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( did_1, 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( tid_1, (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( tid_1, (unsigned)i )) < 0)
+ goto out;
+
+ /* get the member size */
+ member_size = H5Tget_size( member_type_id );
+
+ /* insert it into the new type */
+ if (H5Tinsert( tid_2, 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( did_1, attr_name );
+
+ /* get it */
+ if (has_fill == 1 )
+ {
+ if(H5LT_get_attribute_disk( did_1, 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 (H5Pget_chunk(pid_1, 1, dims_chunk) < 0)
+ goto out;
+
+ /* create a new simple data space with unlimited size, using the dimension */
+ if ((sid_2 = H5Screate_simple(1, dims, maxdims)) < 0)
+ return -1;
+
+ /* modify dataset creation properties, i.e. enable chunking */
+ pid_2 = H5Pcreate(H5P_DATASET_CREATE);
+ if (H5Pset_chunk(pid_2, 1, dims_chunk) < 0)
+ return -1;
+
+ /* create the dataset. */
+ if ((did_2 = H5Dcreate(loc_id, "new", tid_2, sid_2, pid_2)) < 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(tid_1, (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(tid_1, (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, (size_t)0, member_type_id ) < 0)
+ goto out;
+
+ tmp_buf = (unsigned char *)calloc((size_t) nrecords, member_size );
+
+ /* read */
+ if (H5Dread( did_1, 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, (size_t)0, member_type_id ) < 0)
+ goto out;
+
+ /* create xfer properties to preserve initialized data */
+ if ((preserve_id = H5Pcreate (H5P_DATASET_XFER)) < 0)
+ goto out;
+ if (H5Pset_preserve (preserve_id, 1) < 0)
+ goto out;
+
+ /* write */
+ if(H5Dwrite( did_2, write_type_id, H5S_ALL, H5S_ALL, preserve_id, tmp_buf ) < 0)
+ goto out;
+
+ /* end access to the property list */
+ if (H5Pclose( preserve_id ) < 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
+ *-------------------------------------------------------------------------
+ */
+
+ if (H5Tclose( tid_1 ) < 0)
+ goto out;
+ if (H5Pclose( pid_1 ) < 0)
+ goto out;
+ if (H5Sclose( sid_1 ) < 0)
+ goto out;
+ if (H5Dclose( did_1 ) < 0)
+ goto out;
+
+
+ /*-------------------------------------------------------------------------
+ * release resources from 2nd table
+ *-------------------------------------------------------------------------
+ */
+
+ if (H5Sclose( sid_2 ) < 0)
+ goto out;
+ if (H5Tclose( tid_2 ) < 0)
+ goto out;
+ if (H5Pclose( pid_2 ) < 0)
+ goto out;
+ if (H5Dclose( did_2 ) < 0)
+ goto out;
+
+ /*-------------------------------------------------------------------------
* Delete 1st table
*-------------------------------------------------------------------------
*/
@@ -3036,94 +2868,104 @@ herr_t H5TBdelete_field( hid_t loc_id,
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;
-
+
+ /*-------------------------------------------------------------------------
+ * 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 ((did_1 = H5Dopen(loc_id, dset_name)) < 0)
+ return -1;
+
+ /* get the datatype */
+ if ((tid_1 = H5Dget_type( did_1 )) < 0)
+ goto out;
+
+ /* set the attributes */
+ if (H5TB_attach_attributes( table_title, loc_id, dset_name, nfields, tid_1 ) < 0)
+ return -1;
+
+ /*-------------------------------------------------------------------------
+ * attach the fill attributes from previous table
+ *-------------------------------------------------------------------------
+ */
+
+ if (has_fill == 1)
+ {
+ if((sid_1 = H5Screate(H5S_SCALAR)) < 0)
+ goto out;
+
+ for(i = 0; i < nfields; i++)
+ {
+
+ /* get the member type */
+ if (( member_type_id = H5Tget_member_type( tid_1, (unsigned)i )) < 0)
+ goto out;
+
+ /* get the member offset */
+ member_offset = H5Tget_member_offset(tid_1, (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_1, attr_name, member_type_id, sid_1, 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(sid_1) < 0)
+ goto out;
+
+ } /*has_fill*/
+
+ /* release the datatype. */
+ if (H5Tclose( tid_1 ) < 0)
+ goto out;
+
+ /* end access to the dataset */
+ if (H5Dclose( did_1 ) < 0)
+ goto out;
+
+ /* Release resources. */
+ free ( tmp_fill_buf );
+
+ return 0;
+
+/* error zone */
out:
- H5Dclose( dataset_id1 );
- return -1;
+ H5E_BEGIN_TRY
+ {
+ H5Dclose(did_1);
+ H5Sclose(sid_1);
+ H5Tclose(tid_1);
+ H5Pclose(pid_1);
+ H5Dclose(did_2);
+ H5Sclose(sid_2);
+ H5Tclose(tid_2);
+ H5Pclose(pid_2);
+
+ } H5E_END_TRY;
+ return -1;
+
}
-
/*-------------------------------------------------------------------------
*
* Table attribute functions
@@ -3152,14 +2994,14 @@ out:
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;
-
+
+ /* Get the TITLE attribute */
+ if(H5LT_get_attribute_disk( loc_id, "TITLE", table_title ) < 0)
+ return -1;
+
+
+ return 0;
+
}
/*-------------------------------------------------------------------------
@@ -3186,56 +3028,56 @@ herr_t H5TBAget_fill( hid_t loc_id,
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;
-
+
+ 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;
-
+ free( src_offset );
+ return -1;
+
}
@@ -3259,9 +3101,12 @@ out:
*
* Comments:
*
- * Modifications: May 08, 2003
+ * Modifications:
+ * May 08, 2003
* In version 2.0 of Table, the number of records is stored as an
* attribute "NROWS"
+ * November 24, 2008
+ * In version 3.0 of Table, "NROWS" was deprecated
*
*
*-------------------------------------------------------------------------
@@ -3272,84 +3117,75 @@ herr_t H5TBget_table_info ( hid_t loc_id,
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 */
+ hid_t tid=-1;
+ hid_t sid=-1;
+ hid_t did=-1;
+ int num_members;
+ hsize_t dims[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;
+
+ /*-------------------------------------------------------------------------
+ * get number of nfields
+ *-------------------------------------------------------------------------
+ */
+
+ if (nfields)
+ {
+ *nfields = num_members;
+ }
+
+
+ /*-------------------------------------------------------------------------
+ * get number of records
+ *-------------------------------------------------------------------------
+ */
+
+ if (nrecords)
+ {
+ /* get the dataspace handle */
+ if ((sid = H5Dget_space( did )) < 0)
+ goto out;
+
+ /* get dimension */
+ 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];
+ }
+
+ /* close */
+ if (H5Tclose( tid ) < 0)
+ goto out;
+ if (H5Dclose( did ) < 0)
+ return -1;
+
+ return 0;
+
+ /* error zone */
out:
- H5E_BEGIN_TRY {
- H5Dclose(did);
- H5Sclose(sid);
- H5Tclose(tid);
- } H5E_END_TRY;
- return -1;
-
+ H5E_BEGIN_TRY
+ {
+ H5Dclose(did);
+ H5Sclose(sid);
+ H5Tclose(tid);
+ } H5E_END_TRY;
+ return -1;
+
}
/*-------------------------------------------------------------------------
@@ -3377,97 +3213,109 @@ herr_t H5TBget_field_info( hid_t loc_id,
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;
-
+ hid_t did; /* dataset ID */
+ hid_t tid; /* file type ID */
+ hid_t n_tid; /* native type ID */
+ hid_t m_tid; /* member type ID */
+ hid_t nm_tid; /* native member ID */
+ hssize_t nfields;
+ char *member_name;
+ 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 (( tid = H5Dget_type( did )) < 0)
+ goto out;
+
+ if ((n_tid = H5Tget_native_type(tid,H5T_DIR_DEFAULT)) < 0)
+ goto out;
+
+ /* get the type size */
+ size = H5Tget_size( n_tid );
+
+ if ( type_size )
+ {
+ *type_size = size;
+ }
+
+ /* get the number of members */
+ if (( nfields = H5Tget_nmembers( tid )) < 0)
+ goto out;
+
+ /* iterate tru the members */
+ for ( i = 0; i < nfields; i++)
+ {
+ /* get the member name */
+ member_name = H5Tget_member_name( tid, (unsigned)i );
+
+ if (field_names )
+ {
+ strcpy( field_names[i], member_name );
+ }
+
+ /* get the member type */
+ if (( m_tid = H5Tget_member_type( tid,(unsigned) i )) < 0)
+ goto out;
+ if ((nm_tid = H5Tget_native_type(m_tid,H5T_DIR_DEFAULT)) < 0)
+ goto out;
+
+ /* get the member size */
+ member_size = H5Tget_size( nm_tid );
+
+ if(field_sizes )
+ {
+ field_sizes[i] = member_size;
+ }
+
+ /* get the member offset */
+ member_offset = H5Tget_member_offset( n_tid,(unsigned) i );
+
+ if(field_offsets )
+ {
+ field_offsets[i] = member_offset;
+ }
+
+ /* close the member types */
+ if (H5Tclose( m_tid ) < 0)
+ goto out;
+ if (H5Tclose( nm_tid ) < 0)
+ goto out;
+
+ free( member_name );
+
+ } /* i */
+
+ /* close */
+ if (H5Tclose( tid ) < 0)
+ goto out;
+ if (H5Tclose( n_tid ) < 0)
+ goto out;
+ if (H5Dclose( did ) < 0)
+ return -1;
+
+ return 0;
+
+ /* error zone */
out:
- H5Dclose( did );
- return -1;
-
+ H5E_BEGIN_TRY
+ {
+ H5Dclose(did);
+ H5Tclose(tid);
+ H5Tclose(n_tid);
+ } H5E_END_TRY;
+ return -1;
+
}
/*-------------------------------------------------------------------------
*
- * Private functions
+ * internal functions
*
*-------------------------------------------------------------------------
*/
@@ -3486,21 +3334,21 @@ out:
*-------------------------------------------------------------------------
*/
-
+static
int H5TB_find_field( const char *field, const char *field_list )
{
const char *start = field_list;
const char *end;
- while ( (end = strstr( start, "," )) != 0 )
+ while ( (end = strstr( start, "," )) != 0 )
{
size_t count = end - start;
- if ( strncmp(start, field, count) == 0 && count == strlen(field) )
+ if(strncmp(start, field, count) == 0 && count == strlen(field) )
return 1;
start = end + 1;
}
- if ( strcmp( start, field ) == 0 )
+ if(strcmp( start, field ) == 0 )
return 1;
return -1;
@@ -3528,57 +3376,57 @@ int H5TB_find_field( const char *field, const char *field_list )
*-------------------------------------------------------------------------
*/
-
+static
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;
-
+
+ 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_CLASS ) < 0)
+ goto out;
+
+ /* attach the VERSION attribute */
+ if (H5LTset_attribute_string( loc_id, dset_name, "VERSION", TABLE_VERSION ) < 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;
-
+ return -1;
+
}
/*-------------------------------------------------------------------------
@@ -3599,87 +3447,243 @@ out:
*-------------------------------------------------------------------------
*/
+static
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,
+ size_t type_size,
+ const size_t *field_offset,
+ const size_t *field_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;
+ 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,type_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 (field_sizes[i]!=size_native)
+ {
+ if (H5Tset_size(nmtype_id,field_sizes[i]) < 0)
+ goto out;
+ }
+ if (H5Tinsert(mem_type_id,fnames[i],field_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 */
+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;
+
+}
- 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 */
+/*-------------------------------------------------------------------------
+ *
+ * Functions shared between H5TB and H5PT
+ *
+ *-------------------------------------------------------------------------
+ */
+
+/*-------------------------------------------------------------------------
+ * Function: H5TB_common_append_records
+ *
+ * Purpose: Common code for reading records shared between H5PT and H5TB
+ *
+ * Return: Success: 0, Failure: -1
+ *
+ * Programmer: Nat Furrer, nfurrer@ncsa.uiuc.edu
+ * James Laird, jlaird@ncsa.uiuc.edu
+ *
+ * Date: March 8, 2004
+ *
+ * Comments: Called by H5TBappend_records and H5PTappend_records
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+herr_t H5TB_common_append_records( hid_t dataset_id,
+ hid_t mem_type_id,
+ size_t nrecords,
+ hsize_t orig_table_size,
+ const void * buf)
+{
+ hsize_t count[1];
+ hsize_t offset[1];
+ hid_t sid = H5I_BADID;
+ hid_t m_sid = H5I_BADID;
+ hsize_t dims[1];
+ hsize_t mem_dims[1];
+
+ /* extend the dataset */
+ dims[0] = nrecords + orig_table_size;
+ if (H5Dset_extent(dataset_id, dims) < 0)
+ goto out;
+
+ /* create a simple memory data space */
+ mem_dims[0] = nrecords;
+ if((m_sid = H5Screate_simple(1, mem_dims, NULL)) < 0)
+ goto out;
+
+ /* get a copy of the new file data space for writing */
+ if ((sid = H5Dget_space(dataset_id)) < 0)
+ goto out;
+
+ /* define a hyperslab in the dataset */
+ offset[0] = orig_table_size;
+ count[0] = nrecords;
+ if (H5Sselect_hyperslab( sid, H5S_SELECT_SET, offset, NULL, count, NULL) < 0)
+ goto out;
+
+ /* write the records */
+ if (H5Dwrite( dataset_id, mem_type_id, m_sid, sid, H5P_DEFAULT, buf ) < 0)
+ goto out;
+
+ /* close */
+ if (H5Sclose( m_sid ) < 0)
+ goto out;
+ if (H5Sclose( sid ) < 0)
+ goto out;
+
+ return 0;
+
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;
+ H5E_BEGIN_TRY
+ {
+ H5Sclose(m_sid);
+ H5Sclose(sid);
+ }
+ H5E_END_TRY;
+ return -1;
+}
+
+/*-------------------------------------------------------------------------
+ * Function: H5TB_common_read_records
+ *
+ * Purpose: Common code for reading records shared between H5PT and H5TB
+ *
+ * Return: Success: 0, Failure: -1
+ *
+ * Programmer: Nat Furrer, nfurrer@ncsa.uiuc.edu
+ * James Laird, jlaird@ncsa.uiuc.edu
+ *
+ * Date: March 8, 2004
+ *
+ * Comments: Called by H5TBread_records and H5PTread_records
+ *
+ * Modifications:
+ *
+ *
+ *-------------------------------------------------------------------------
+ */
+herr_t H5TB_common_read_records( hid_t dataset_id,
+ hid_t mem_type_id,
+ hsize_t start,
+ size_t nrecords,
+ hsize_t table_size,
+ void *buf)
+{
+ hsize_t count[1];
+ hsize_t offset[1];
+ hid_t sid = H5I_BADID;
+ hid_t m_sid = H5I_BADID;
+ hsize_t mem_size[1];
+
+ /* make sure the read request is in bounds */
+ if (start + nrecords > table_size )
+ goto out;
+
+ /* get the dataspace handle */
+ if ((sid = H5Dget_space( dataset_id )) < 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 ((m_sid = H5Screate_simple( 1, mem_size, NULL )) < 0)
+ goto out;
+ if ((H5Dread( dataset_id, mem_type_id, m_sid, sid, H5P_DEFAULT, buf)) < 0)
+ goto out;
+
+ /* close */
+ if (H5Sclose( m_sid ) < 0)
+ goto out;
+ if (H5Sclose( sid ) < 0)
+ goto out;
+
+ return 0;
+
+out:
+ H5E_BEGIN_TRY
+ {
+ H5Sclose(sid);
+ H5Sclose(m_sid);
+ }
+ H5E_END_TRY;
+ return -1;
}
diff --git a/hl/src/H5TA.h b/hl/src/H5TA.h
index 279ac5a..f6e635c 100644
--- a/hl/src/H5TA.h
+++ b/hl/src/H5TA.h
@@ -22,7 +22,9 @@
#include "H5LT.h"
-#define HLTB_MAX_FIELD_LEN 255
+#define TABLE_CLASS "TABLE"
+#define TABLE_VERSION "3.0"
+#define HLTB_MAX_FIELD_LEN 255
#if !defined(MAX)
#define MAX(X,Y) ((X)>(Y)?(X):(Y))
@@ -238,6 +240,35 @@ H5_HLDLL herr_t H5TBAget_fill( hid_t loc_id,
hid_t dset_id,
unsigned char *dst_buf );
+/*-------------------------------------------------------------------------
+ *
+ * Private write function used by H5TB and H5PT
+ *
+ *-------------------------------------------------------------------------
+ */
+
+herr_t H5TB_common_append_records( hid_t dataset_id,
+ hid_t mem_type_id,
+ size_t nrecords,
+ hsize_t orig_table_size,
+ const void * data);
+
+/*-------------------------------------------------------------------------
+ *
+ * Private read function used by H5TB and H5PT
+ *
+ *-------------------------------------------------------------------------
+ */
+
+
+herr_t H5TB_common_read_records( hid_t dataset_id,
+ hid_t mem_type_id,
+ hsize_t start,
+ size_t nrecords,
+ hsize_t table_size,
+ void *data);
+
+
#ifdef __cplusplus
}
#endif
diff --git a/hl/test/test_table.c b/hl/test/test_table.c
index fba7582..5e12ad8 100644
--- a/hl/test/test_table.c
+++ b/hl/test/test_table.c
@@ -16,6 +16,7 @@
#include "H5TA.h"
#include <stdlib.h>
+#include <string.h>
#include <assert.h>
#define TEST_FILE_BE "test_table_be.hdf5"
@@ -66,11 +67,11 @@
*/
typedef struct particle_t
{
- char name[16];
- long longi;
- float pressure;
- double temperature;
- int lati;
+ char name[16];
+ long longi;
+ float pressure;
+ double temperature;
+ int lati;
} particle_t;
/*-------------------------------------------------------------------------
@@ -87,47 +88,47 @@ static int compare_deleted(hsize_t rrecords, hsize_t dstart, hsize_t drecords,
* a subset of particle_t, with latitude and longitude fields
*-------------------------------------------------------------------------
*/
- typedef struct position_t
- {
- long longi;
- int lati;
- } position_t;
+typedef struct position_t
+{
+ long longi;
+ int lati;
+} position_t;
/*-------------------------------------------------------------------------
* a subset of particle_t, with name and pressure fields
*-------------------------------------------------------------------------
*/
- typedef struct namepressure_t
- {
- char name[16];
- float pressure;
- } namepressure_t;
+typedef struct namepressure_t
+{
+ char name[16];
+ float pressure;
+} namepressure_t;
/*-------------------------------------------------------------------------
* an extended particle, used in the insert field test
*-------------------------------------------------------------------------
*/
- typedef struct particle2_t
- {
- char name[16];
- long longi;
- float pressure;
- double temperature;
- int lati;
- int new_field;
- } particle2_t;
+typedef struct particle2_t
+{
+ char name[16];
+ long longi;
+ float pressure;
+ double temperature;
+ int lati;
+ int new_field;
+} particle2_t;
/*-------------------------------------------------------------------------
* a particle with one field less, used in the delete field test
*-------------------------------------------------------------------------
*/
- typedef struct particle3_t
- {
- char name[16];
- long longi;
- double temperature;
- int lati;
- } particle3_t;
+typedef struct particle3_t
+{
+ char name[16];
+ long longi;
+ double temperature;
+ int lati;
+} particle3_t;
/*-------------------------------------------------------------------------
@@ -137,1340 +138,1377 @@ static int compare_deleted(hsize_t rrecords, hsize_t dstart, hsize_t drecords,
int test_table(hid_t fid, int write)
{
- /* identifiers */
- hid_t fid1;
- hid_t fid2;
- hsize_t chunk_size=10;
- int compress=0;
- int *fill=NULL;
- particle_t fill1[1] = { {"no data",-1, -99.0f, -99.0, -1} };
- int fill1_new[1] = { -100 };
- hsize_t position;
- char tname[20];
-
- /* indices */
- int i, j;
-
- /* write, read, append, delete, insert some records and fields */
- hsize_t FIELDS = NFIELDS;
- hsize_t RECORDS = NRECORDS;
- hsize_t start;
- hsize_t wstart;
- hsize_t rstart;
- hsize_t istart;
- hsize_t dstart;
- hsize_t nrecords;
- hsize_t rrecords;
- hsize_t wrecords;
- hsize_t arecords;
- hsize_t irecords;
- hsize_t drecords;
- hsize_t nfields;
- hsize_t rfields;
- hsize_t start1; /* record to start reading from 1st table */
- hsize_t start2; /* record to start writing in 2nd table */
-
-/*-------------------------------------------------------------------------
- * read, write, insert, append buffers
- *-------------------------------------------------------------------------
- */
- particle_t rbuf[NRECORDS+4];
- particle2_t rbuf2[NRECORDS];
- particle3_t rbuf3[NRECORDS];
- particle_t rbufc[NRECORDS*2];
- particle_t abuf[2]={{"eight",80,8.0f,80.0,80},{"nine",90,9.0f,90.0,90}};
- particle_t ibuf[2]={{"zero", 0, 0.0f, 0.0, 0},{"zero", 0, 0.0f, 0.0, 0}};
- particle_t wbufd[NRECORDS];
- particle_t wbuf[NRECORDS] = {
- {"zero", 0, 0.0f, 0.0, 0,},
- {"one", 10, 1.0f, 10.0, 10},
- {"two", 20, 2.0f, 20.0, 20},
- {"three",30, 3.0f, 30.0, 30},
- {"four", 40, 4.0f, 40.0, 40},
- {"five", 50, 5.0f, 50.0, 50},
- {"six", 60, 6.0f, 60.0, 60},
- {"seven",70, 7.0f, 70.0, 70}
- };
- /* buffers for the field "Pressure" and "New_field" */
- float pressure_in [NRECORDS] = { 0.0f,1.0f,2.0f,3.0f,4.0f,5.0f,6.0f,7.0f };
- float pressure_out [NRECORDS];
- int buf_new[NRECORDS] = { 0,1,2,3,4,5,6,7 };
- /* buffers for the fields "Latitude,Longitude" */
- position_t position_out[NRECORDS_ADD];
- position_t position_in[NRECORDS_ADD] = { {0,0},
- {10,10},
- {20,20}};
- /* buffers for the fields "Name,Pressure" */
- namepressure_t namepre_out[NRECORDS];
- namepressure_t namepre_in[NRECORDS] =
- { {"zero",0.0f},
- {"one", 1.0f},
- {"two", 2.0f},
- {"three", 3.0f},
- {"four", 4.0f},
- {"five", 5.0f},
- {"six", 6.0f},
- {"seven", 7.0f},
- };
-
-
-/*-------------------------------------------------------------------------
- * initialize table parameters
- * field offsets and sizes used in the fields functions
- *-------------------------------------------------------------------------
- */
-
- size_t field_offset_pos[2]=
- {
- HOFFSET( position_t, longi ),
- HOFFSET( position_t, lati )
- };
- size_t field_offset_namepre[2]=
- {
- HOFFSET( namepressure_t, name ),
- HOFFSET( namepressure_t, pressure )
- };
- size_t field_sizes_pos[2]=
- {
- sizeof(position_in[0].longi),
- sizeof(position_in[0].lati)
- };
- size_t field_sizes_namepre[2]=
- {
- sizeof(namepre_in[0].name),
- sizeof(namepre_in[0].pressure)
- };
- size_t field_sizes_pre[1]=
- {
- sizeof(namepre_in[0].pressure)
- };
-
-/*-------------------------------------------------------------------------
- * query table test
- *-------------------------------------------------------------------------
- */
- char **names_out;
- size_t sizes_out[NFIELDS];
- size_t offset_out[NFIELDS];
- size_t size_out;
-
-/*-------------------------------------------------------------------------
- * initialize table parameters
- * field indexes (zero based) used in the fields functions
- * "Name 0","Longitude 1","Pressure 2","Temperature 3","Latitude 4"
- *-------------------------------------------------------------------------
- */
- int field_index_pre[1] = { 2 };
- int field_index_pos[2] = { 1,4 };
- int field_index_namepre[2] = { 0,2 };
- int field_index[NFIELDS] = { 0,1,2,3,4 };
-
-/*-------------------------------------------------------------------------
- * initialize table parameters
- * size and the offsets of struct members in memory
- * define the inserted field HDF5 type and buffers
- * these are used for the insert field test
- *-------------------------------------------------------------------------
- */
- hid_t field_type_new = H5T_NATIVE_INT;
- size_t dst_size2 = sizeof( particle2_t );
- size_t dst_offset2[NFIELDS+1] = { HOFFSET( particle2_t, name ),
- HOFFSET( particle2_t, longi ),
- HOFFSET( particle2_t, pressure ),
- HOFFSET( particle2_t, temperature ),
- HOFFSET( particle2_t, lati ),
- HOFFSET( particle2_t, new_field )};
- size_t dst_sizes2[NFIELDS+1] = { sizeof( rbuf2[0].name),
- sizeof( rbuf2[0].longi),
- sizeof( rbuf2[0].pressure),
- sizeof( rbuf2[0].temperature),
- sizeof( rbuf2[0].lati),
- sizeof( rbuf2[0].new_field)};
-/*-------------------------------------------------------------------------
- * initialize table parameters
- * size and the offsets of struct members in memory
- * these are used for the delete field test
- *-------------------------------------------------------------------------
- */
- size_t dst_size3 = sizeof( particle3_t );
- size_t dst_offset3[NFIELDS-1] = { HOFFSET( particle3_t, name ),
- HOFFSET( particle3_t, longi ),
- HOFFSET( particle3_t, temperature ),
- HOFFSET( particle3_t, lati )};
-
- size_t dst_sizes3[NFIELDS-1] = { sizeof( rbuf3[0].name),
- sizeof( rbuf3[0].longi),
- sizeof( rbuf3[0].temperature),
- sizeof( rbuf3[0].lati)};
-
-
-/*-------------------------------------------------------------------------
- * initialize table parameters
- * 1) size and the offsets of struct members in memory
- * 2) field names
- * 3) define a HDF5 type for the fields
- *-------------------------------------------------------------------------
- */
-
- size_t type_size_mem = sizeof( particle_t );
- size_t field_offset[NFIELDS]=
- {
- HOFFSET( particle_t, name ),
- HOFFSET( particle_t, longi ),
- HOFFSET( particle_t, pressure ),
- HOFFSET( particle_t, temperature ),
- HOFFSET( particle_t, lati )
- };
- size_t field_size[NFIELDS] =
- {
- sizeof( rbuf[0].name),
- sizeof( rbuf[0].longi),
- sizeof( rbuf[0].pressure),
- sizeof( rbuf[0].temperature),
- sizeof( rbuf[0].lati)
- };
- const char *field_names[NFIELDS] =
- { "Name","Longitude","Pressure","Temperature","Latitude" };
- hid_t field_type[NFIELDS];
- hid_t string_type = H5Tcopy( H5T_C_S1 );
- H5Tset_size( string_type, 16 );
- field_type[0] = string_type;
- field_type[1] = H5T_NATIVE_LONG;
- field_type[2] = H5T_NATIVE_FLOAT;
- field_type[3] = H5T_NATIVE_DOUBLE;
- field_type[4] = H5T_NATIVE_INT;
-
-/*-------------------------------------------------------------------------
- *
- * Functions tested:
- *
- * H5TBmake_table
- * H5TBread_table
- *
- *-------------------------------------------------------------------------
- */
- if (write)
- {
- TESTING2("making table");
-
- if (H5TBmake_table(TITLE,fid,"table1",FIELDS,RECORDS,type_size_mem,
- field_names,field_offset,field_type,
- chunk_size,fill,compress,wbuf)<0)
+ /* identifiers */
+ hid_t fid1;
+ hid_t fid2;
+ hsize_t chunk_size=10;
+ int compress=0;
+ int *fill=NULL;
+ particle_t fill1[1] = { {"no data",-1, -99.0f, -99.0, -1} };
+ int fill1_new[1] = { -100 };
+ hsize_t position;
+ char tname[20];
+
+ /* indices */
+ int i, j;
+
+ /* write, read, append, delete, insert some records and fields */
+ hsize_t FIELDS = NFIELDS;
+ hsize_t RECORDS = NRECORDS;
+ hsize_t start;
+ hsize_t wstart;
+ hsize_t rstart;
+ hsize_t istart;
+ hsize_t dstart;
+ hsize_t nrecords;
+ hsize_t rrecords;
+ hsize_t wrecords;
+ hsize_t arecords;
+ hsize_t irecords;
+ hsize_t drecords;
+ hsize_t nfields;
+ hsize_t rfields;
+ hsize_t start1; /* record to start reading from 1st table */
+ hsize_t start2; /* record to start writing in 2nd table */
+
+ /*-------------------------------------------------------------------------
+ * read, write, insert, append buffers
+ *-------------------------------------------------------------------------
+ */
+ particle_t rbuf[NRECORDS+4];
+ particle2_t rbuf2[NRECORDS];
+ particle3_t rbuf3[NRECORDS];
+ particle_t rbufc[NRECORDS*2];
+ particle_t abuf[2]={{"eight",80,8.0f,80.0,80},{"nine",90,9.0f,90.0,90}};
+ particle_t ibuf[2]={{"zero", 0, 0.0f, 0.0, 0},{"zero", 0, 0.0f, 0.0, 0}};
+ particle_t wbufd[NRECORDS];
+ particle_t wbuf[NRECORDS] = {
+ {"zero", 0, 0.0f, 0.0, 0,},
+ {"one", 10, 1.0f, 10.0, 10},
+ {"two", 20, 2.0f, 20.0, 20},
+ {"three",30, 3.0f, 30.0, 30},
+ {"four", 40, 4.0f, 40.0, 40},
+ {"five", 50, 5.0f, 50.0, 50},
+ {"six", 60, 6.0f, 60.0, 60},
+ {"seven",70, 7.0f, 70.0, 70}
+ };
+ /* buffers for the field "Pressure" and "New_field" */
+ float pressure_in [NRECORDS] = { 0.0f,1.0f,2.0f,3.0f,4.0f,5.0f,6.0f,7.0f };
+ float pressure_out [NRECORDS];
+ int buf_new[NRECORDS] = { 0,1,2,3,4,5,6,7 };
+ /* buffers for the fields "Latitude,Longitude" */
+ position_t position_out[NRECORDS_ADD];
+ position_t position_in[NRECORDS_ADD] = { {0,0},
+ {10,10},
+ {20,20}};
+ /* buffers for the fields "Name,Pressure" */
+ namepressure_t namepre_out[NRECORDS];
+ namepressure_t namepre_in[NRECORDS] =
+ { {"zero",0.0f},
+ {"one", 1.0f},
+ {"two", 2.0f},
+ {"three", 3.0f},
+ {"four", 4.0f},
+ {"five", 5.0f},
+ {"six", 6.0f},
+ {"seven", 7.0f},
+ };
+
+
+ /*-------------------------------------------------------------------------
+ * initialize table parameters
+ * field offsets and sizes used in the fields functions
+ *-------------------------------------------------------------------------
+ */
+
+ size_t field_offset_pos[2]=
+ {
+ HOFFSET( position_t, longi ),
+ HOFFSET( position_t, lati )
+ };
+ size_t field_offset_namepre[2]=
+ {
+ HOFFSET( namepressure_t, name ),
+ HOFFSET( namepressure_t, pressure )
+ };
+ size_t field_sizes_pos[2]=
+ {
+ sizeof(position_in[0].longi),
+ sizeof(position_in[0].lati)
+ };
+ size_t field_sizes_namepre[2]=
+ {
+ sizeof(namepre_in[0].name),
+ sizeof(namepre_in[0].pressure)
+ };
+ size_t field_sizes_pre[1]=
+ {
+ sizeof(namepre_in[0].pressure)
+ };
+
+ /*-------------------------------------------------------------------------
+ * query table test
+ *-------------------------------------------------------------------------
+ */
+ char **names_out;
+ size_t sizes_out[NFIELDS];
+ size_t offset_out[NFIELDS];
+ size_t size_out;
+
+ /*-------------------------------------------------------------------------
+ * initialize table parameters
+ * field indexes (zero based) used in the fields functions
+ * "Name 0","Longitude 1","Pressure 2","Temperature 3","Latitude 4"
+ *-------------------------------------------------------------------------
+ */
+ int field_index_pre[1] = { 2 };
+ int field_index_pos[2] = { 1,4 };
+ int field_index_namepre[2] = { 0,2 };
+ int field_index[NFIELDS] = { 0,1,2,3,4 };
+
+ /*-------------------------------------------------------------------------
+ * initialize table parameters
+ * size and the offsets of struct members in memory
+ * define the inserted field HDF5 type and buffers
+ * these are used for the insert field test
+ *-------------------------------------------------------------------------
+ */
+ hid_t field_type_new = H5T_NATIVE_INT;
+ size_t dst_size2 = sizeof( particle2_t );
+ size_t dst_offset2[NFIELDS+1] = { HOFFSET( particle2_t, name ),
+ HOFFSET( particle2_t, longi ),
+ HOFFSET( particle2_t, pressure ),
+ HOFFSET( particle2_t, temperature ),
+ HOFFSET( particle2_t, lati ),
+ HOFFSET( particle2_t, new_field )};
+ size_t dst_sizes2[NFIELDS+1] = { sizeof( rbuf2[0].name),
+ sizeof( rbuf2[0].longi),
+ sizeof( rbuf2[0].pressure),
+ sizeof( rbuf2[0].temperature),
+ sizeof( rbuf2[0].lati),
+ sizeof( rbuf2[0].new_field)};
+
+ /*-------------------------------------------------------------------------
+ * initialize table parameters
+ * size and the offsets of struct members in memory
+ * these are used for the delete field test
+ *-------------------------------------------------------------------------
+ */
+ size_t dst_size3 = sizeof( particle3_t );
+ size_t dst_offset3[NFIELDS-1] = { HOFFSET( particle3_t, name ),
+ HOFFSET( particle3_t, longi ),
+ HOFFSET( particle3_t, temperature ),
+ HOFFSET( particle3_t, lati )};
+
+ size_t dst_sizes3[NFIELDS-1] = { sizeof( rbuf3[0].name),
+ sizeof( rbuf3[0].longi),
+ sizeof( rbuf3[0].temperature),
+ sizeof( rbuf3[0].lati)};
+
+
+ /*-------------------------------------------------------------------------
+ * initialize table parameters
+ * 1) size and the offsets of struct members in memory
+ * 2) field names
+ * 3) define a HDF5 type for the fields
+ *-------------------------------------------------------------------------
+ */
+
+ size_t type_size_mem = sizeof( particle_t );
+ size_t field_offset[NFIELDS]=
+ {
+ HOFFSET( particle_t, name ),
+ HOFFSET( particle_t, longi ),
+ HOFFSET( particle_t, pressure ),
+ HOFFSET( particle_t, temperature ),
+ HOFFSET( particle_t, lati )
+ };
+ size_t field_size[NFIELDS] =
+ {
+ sizeof( rbuf[0].name),
+ sizeof( rbuf[0].longi),
+ sizeof( rbuf[0].pressure),
+ sizeof( rbuf[0].temperature),
+ sizeof( rbuf[0].lati)
+ };
+ const char *field_names[NFIELDS] =
+ { "Name","Longitude","Pressure","Temperature","Latitude" };
+ hid_t field_type[NFIELDS];
+ hid_t string_type = H5Tcopy( H5T_C_S1 );
+ H5Tset_size( string_type, 16 );
+ field_type[0] = string_type;
+ field_type[1] = H5T_NATIVE_LONG;
+ field_type[2] = H5T_NATIVE_FLOAT;
+ field_type[3] = H5T_NATIVE_DOUBLE;
+ field_type[4] = H5T_NATIVE_INT;
+
+ /*-------------------------------------------------------------------------
+ *
+ * Functions tested:
+ *
+ * H5TBmake_table
+ * H5TBread_table
+ *
+ *-------------------------------------------------------------------------
+ */
+ if (write)
+ {
+ TESTING2("making table");
+
+ if (H5TBmake_table(TITLE,fid,"table1",FIELDS,RECORDS,type_size_mem,
+ field_names,field_offset,field_type,
+ chunk_size,fill,compress,wbuf)<0)
+ goto out;
+ PASSED();
+ }
+
+
+ TESTING2("reading table");
+
+ /*-------------------------------------------------------------------------
+ * read the table
+ *-------------------------------------------------------------------------
+ */
+
+ if (H5TBread_table(fid,"table1",type_size_mem,field_offset,field_size,rbuf)<0)
+ goto out;
+
+ /* compare the extracted table with the original array */
+ for( i = 0; i < NRECORDS; i++ )
+ {
+ if (cmp_par(i,i,rbuf,wbuf)<0)
+ goto out;
+ }
+
+ PASSED();
+
+
+ /*-------------------------------------------------------------------------
+ *
+ * Functions tested:
+ *
+ * H5TBwrite_records
+ *
+ *-------------------------------------------------------------------------
+ */
+ if (write)
+ {
+ TESTING2("writing records");
+
+ /* create an empty table */
+ if (H5TBmake_table(TITLE,fid,"table2",FIELDS,RECORDS,type_size_mem,
+ field_names,field_offset,field_type,
+ chunk_size,fill,compress,0)<0)
+ goto out;
+
+ /*-------------------------------------------------------------------------
+ * write records, start at 0, write 8
+ * pos = 0 1 2 3 4 5 6 7
+ * data= 0 1 2 3 4 5 6 7
+ *-------------------------------------------------------------------------
+ */
+ wstart=0; wrecords=8;
+ if (H5TBwrite_records(fid,"table2",wstart,wrecords,type_size_mem,field_offset,
+ field_size,wbuf)<0)
+ goto out;
+
+ /* read it back */
+ if (H5TBread_table(fid,"table2",type_size_mem,field_offset,field_size,rbuf)<0)
+ goto out;
+
+ /* compare */
+ for( i = 0; i < NRECORDS; i++ )
+ {
+ if (cmp_par(i,i,rbuf,wbuf)<0)
+ goto out;
+ }
+
+ PASSED();
+ }
+
+ /*-------------------------------------------------------------------------
+ *
+ * Functions tested:
+ *
+ * H5TBread_records
+ *
+ *-------------------------------------------------------------------------
+ */
+
+ TESTING2("reading records");
+
+ /*-------------------------------------------------------------------------
+ * read records, start at 0, read 8
+ * pos = 0 1 2 3 4 5 6 7
+ * data= 0 1 2 3 4 5 6 7
+ *-------------------------------------------------------------------------
+ */
+
+ /*-------------------------------------------------------------------------
+ * for the read test we cannot use "table2" because it has been appended
+ * we use the original "table1" instead
+ *-------------------------------------------------------------------------
+ */
+ if(write)
+ strcpy(tname,"table2");
+ else
+ strcpy(tname,"table1");
+
+ rstart=0; rrecords=8;
+ if (H5TBread_records(fid,tname,rstart,rrecords,type_size_mem,field_offset,
+ field_size,rbuf)<0)
+ goto out;
+
+ /* compare */
+ for( i=(int)rstart; i<(int)rrecords; i++)
+ {
+ if (cmp_par(i,i,rbuf,wbuf)<0)
+ goto out;
+ }
+ PASSED();
+
+ /*-------------------------------------------------------------------------
+ *
+ * Functions tested:
+ *
+ * H5TBappend_records
+ * H5TBread_records
+ *
+ *-------------------------------------------------------------------------
+ */
+ if (write)
+ {
+ TESTING2("appending records");
+
+ /*-------------------------------------------------------------------------
+ * append 2 records
+ * pos = 0 1 2 3 4 5 6 7 8 9
+ * data= 0 1 2 3 4 5 6 7 8 9
+ *-------------------------------------------------------------------------
+ */
+ arecords=2;
+ if (H5TBappend_records(fid,"table2",arecords,type_size_mem,field_offset,field_size,abuf)<0)
+ return 1;
+
+ if (H5TBget_table_info(fid,"table2",&rfields,&rrecords)<0)
+ return 1;
+
+ rstart=0; rrecords=NRECORDS+arecords;
+ if (H5TBread_records(fid,"table2",rstart,rrecords,type_size_mem,field_offset,
+ field_size,rbuf)<0)
+ return 1;
+
+ /* compare */
+ wrecords=8;
+ for( i=(int)rstart; i<(int)wrecords; i++)
+ {
+ if (cmp_par(i,i,rbuf,wbuf)<0)
+ goto out;
+ }
+ for( i=(int)wrecords, j=0; i<(int)rrecords; i++,j++)
+ {
+ if (cmp_par(i,j,rbuf,abuf)<0)
+ goto out;
+ }
+ PASSED();
+ }
+
+ /*-------------------------------------------------------------------------
+ *
+ * Functions tested:
+ *
+ * H5TBinsert_record
+ * H5TBread_records
+ *
+ *-------------------------------------------------------------------------
+ */
+ if (write)
+ {
+ TESTING2("inserting records");
+
+ /*-------------------------------------------------------------------------
+ * insert 2 records
+ * pos = 0 1 2 3 4 5 6 7 8 9 10 11
+ * data= 0 0 0 1 2 3 4 5 6 7 8 9
+ *-------------------------------------------------------------------------
+ */
+ istart=1; irecords=2;
+ if (H5TBinsert_record(fid,"table2",istart,irecords,type_size_mem,field_offset,field_size,ibuf)<0)
+ return 1;
+
+ if (H5TBget_table_info(fid,"table2",&rfields,&rrecords)<0)
+ return 1;
+
+ if (H5TBread_records(fid,"table2",rstart,rrecords,type_size_mem,field_offset,
+ field_size,rbuf)<0)
+ return 1;
+
+ /* compare */
+ for( i=0; i<12; i++)
+ {
+ if (i<istart)
+ {
+ if (cmp_par(i,i,rbuf,wbuf)<0)
goto out;
- PASSED();
- }
-
-
- TESTING2("reading table");
-
-/*-------------------------------------------------------------------------
- * read the table
- *-------------------------------------------------------------------------
- */
-
- if (H5TBread_table(fid,"table1",type_size_mem,field_offset,field_size,rbuf)<0)
- goto out;
-
- /* compare the extracted table with the original array */
- for( i = 0; i < NRECORDS; i++ )
- {
- if (cmp_par(i,i,rbuf,wbuf)<0)
- goto out;
- }
-
- PASSED();
-
-
-/*-------------------------------------------------------------------------
- *
- * Functions tested:
- *
- * H5TBwrite_records
- *
- *-------------------------------------------------------------------------
- */
- if (write)
- {
- TESTING2("writing records");
-
- /* create an empty table */
- if (H5TBmake_table(TITLE,fid,"table2",FIELDS,RECORDS,type_size_mem,
- field_names,field_offset,field_type,
- chunk_size,fill,compress,0)<0)
+ }
+ else if (i>=(int)istart && i<(int)istart+(int)irecords)
+ {
+ j=i-(int)istart;
+ if (cmp_par(i,j,rbuf,ibuf)<0)
goto out;
-
-/*-------------------------------------------------------------------------
- * write records, start at 0, write 8
- * pos = 0 1 2 3 4 5 6 7
- * data= 0 1 2 3 4 5 6 7
- *-------------------------------------------------------------------------
- */
- wstart=0; wrecords=8;
- if (H5TBwrite_records(fid,"table2",wstart,wrecords,type_size_mem,field_offset,
- field_size,wbuf)<0)
- goto out;
-
- /* read it back */
- if (H5TBread_table(fid,"table2",type_size_mem,field_offset,field_size,rbuf)<0)
- goto out;
-
- /* compare */
- for( i = 0; i < NRECORDS; i++ )
- {
- if (cmp_par(i,i,rbuf,wbuf)<0)
- goto out;
- }
-
- PASSED();
- }
-
-/*-------------------------------------------------------------------------
- *
- * Functions tested:
- *
- * H5TBread_records
- *
- *-------------------------------------------------------------------------
- */
-
- TESTING2("reading records");
-
-/*-------------------------------------------------------------------------
- * read records, start at 0, read 8
- * pos = 0 1 2 3 4 5 6 7
- * data= 0 1 2 3 4 5 6 7
- *-------------------------------------------------------------------------
- */
-
-/*-------------------------------------------------------------------------
- * for the read test we cannot use "table2" because it has been appended
- * we use the original "table1" instead
- *-------------------------------------------------------------------------
- */
- if(write)
- strcpy(tname,"table2");
- else
- strcpy(tname,"table1");
-
- rstart=0; rrecords=8;
- if (H5TBread_records(fid,tname,rstart,rrecords,type_size_mem,field_offset,
- field_size,rbuf)<0)
- goto out;
-
- /* compare */
- for( i=(int)rstart; i<(int)rrecords; i++)
- {
- if (cmp_par(i,i,rbuf,wbuf)<0)
- goto out;
- }
- PASSED();
-
-/*-------------------------------------------------------------------------
- *
- * Functions tested:
- *
- * H5TBappend_records
- * H5TBread_records
- *
- *-------------------------------------------------------------------------
- */
- if (write)
- {
- TESTING2("appending records");
-
-/*-------------------------------------------------------------------------
- * append 2 records
- * pos = 0 1 2 3 4 5 6 7 8 9
- * data= 0 1 2 3 4 5 6 7 8 9
- *-------------------------------------------------------------------------
- */
- arecords=2;
- if (H5TBappend_records(fid,"table2",arecords,type_size_mem,field_offset,field_size,abuf)<0)
- return 1;
-
- if (H5TBget_table_info(fid,"table2",&rfields,&rrecords)<0)
- return 1;
-
- rstart=0; rrecords=NRECORDS+arecords;
- if (H5TBread_records(fid,"table2",rstart,rrecords,type_size_mem,field_offset,
- field_size,rbuf)<0)
- return 1;
-
- /* compare */
- wrecords=8;
- for( i=(int)rstart; i<(int)wrecords; i++)
- {
- if (cmp_par(i,i,rbuf,wbuf)<0)
- goto out;
- }
- for( i=(int)wrecords, j=0; i<(int)rrecords; i++,j++)
- {
- if (cmp_par(i,j,rbuf,abuf)<0)
- goto out;
- }
- PASSED();
- }
-
-/*-------------------------------------------------------------------------
- *
- * Functions tested:
- *
- * H5TBinsert_record
- * H5TBread_records
- *
- *-------------------------------------------------------------------------
- */
- if (write)
- {
- TESTING2("inserting records");
-
-/*-------------------------------------------------------------------------
- * insert 2 records
- * pos = 0 1 2 3 4 5 6 7 8 9 10 11
- * data= 0 0 0 1 2 3 4 5 6 7 8 9
- *-------------------------------------------------------------------------
- */
- istart=1; irecords=2;
- if (H5TBinsert_record(fid,"table2",istart,irecords,type_size_mem,field_offset,field_size,ibuf)<0)
- return 1;
-
- if (H5TBget_table_info(fid,"table2",&rfields,&rrecords)<0)
- return 1;
-
- if (H5TBread_records(fid,"table2",rstart,rrecords,type_size_mem,field_offset,
- field_size,rbuf)<0)
- return 1;
-
- /* compare */
- for( i=0; i<12; i++)
- {
- if (i<istart)
- {
- if (cmp_par(i,i,rbuf,wbuf)<0)
- goto out;
- }
- else if (i>=(int)istart && i<(int)istart+(int)irecords)
- {
- j=i-(int)istart;
- if (cmp_par(i,j,rbuf,ibuf)<0)
- goto out;
- }
- else if (i>=(int)istart+(int)irecords && i<10)
- {
- j=i-(int)irecords;
- if (cmp_par(i,j,rbuf,wbuf)<0)
- goto out;
- }
- else
- {
- j=i-10;
- if (cmp_par(i,j,rbuf,abuf)<0)
- goto out;
- }
- }
- PASSED();
- }
-
-/*-------------------------------------------------------------------------
- *
- * Functions tested:
- *
- * H5TBdelete_record
- * H5TBread_records
- *
- *-------------------------------------------------------------------------
- */
- if (write)
- {
- TESTING2("deleting records");
-
-/*-------------------------------------------------------------------------
- * Create a table
- * pos = 0 1 2 3 4 5 6 7
- * data= 0 1 2 3 4 5 6 7
- *-------------------------------------------------------------------------
- */
-
- for( i=0; i<NRECORDS; i++)
- {
- wbufd[i].lati = wbuf[i].lati;
- wbufd[i].longi = wbuf[i].longi;
- wbufd[i].pressure = wbuf[i].pressure;
- wbufd[i].temperature = wbuf[i].temperature;
- strcpy(wbufd[i].name, wbuf[i].name );
-
- }
-
-
- if (H5TBmake_table(TITLE,fid,"table3",FIELDS,RECORDS,type_size_mem,
- field_names,field_offset,field_type,
- chunk_size,fill,compress,wbufd)<0)
+ }
+ else if (i>=(int)istart+(int)irecords && i<10)
+ {
+ j=i-(int)irecords;
+ if (cmp_par(i,j,rbuf,wbuf)<0)
goto out;
-
-/*-------------------------------------------------------------------------
- * Delete records, start at 2, delete 3
- * pos = 0 1 2 3 4
- * data= 0 1 5 6 7
- *-------------------------------------------------------------------------
- */
- dstart=2; drecords=3;
- if (H5TBdelete_record(fid,"table3",dstart,drecords)<0)
- goto out;
-
- if (H5TBget_table_info(fid,"table3",&rfields,&rrecords)<0)
- goto out;
-
- rstart=0;
- if (H5TBread_records(fid,"table3",rstart,rrecords,type_size_mem,field_offset,
- field_size,rbuf)<0)
- goto out;
-
- /* Compare */
- nrecords=NRECORDS;
- assert(rrecords == nrecords-drecords);
- if (compare_deleted(rrecords,dstart,drecords,rbuf,wbufd)<0)
- goto out;
-
-/*-------------------------------------------------------------------------
- * reset compare buffer
- *-------------------------------------------------------------------------
- */
- nrecords=rrecords;
- for( i=0; i<nrecords; i++)
- wbufd[i] = rbuf[i];
-
-/*-------------------------------------------------------------------------
- * Delete records, start at 0, delete 2
- * pos = 0 1 2
- * data= 5 6 7
- *-------------------------------------------------------------------------
- */
- dstart=0; drecords=2;
- if (H5TBdelete_record(fid,"table3",dstart,drecords)<0)
- goto out;
-
- if (H5TBget_table_info(fid,"table3",&rfields,&rrecords)<0)
- goto out;
-
- rstart=0;
- if (H5TBread_records(fid,"table3",rstart,rrecords,type_size_mem,field_offset,
- field_size,rbuf)<0)
- goto out;
-
- /* Compare */
- assert(rrecords == nrecords-drecords);
- if (compare_deleted(rrecords,dstart,drecords,rbuf,wbufd)<0)
- goto out;
-
-/*-------------------------------------------------------------------------
- * reset compare buffer
- *-------------------------------------------------------------------------
- */
- nrecords=rrecords;
- for( i=0; i<nrecords; i++)
- wbufd[i] = rbuf[i];
-
-/*-------------------------------------------------------------------------
- * Delete records, start at 1, delete 1
- * pos = 0 1
- * data= 5 7
- *-------------------------------------------------------------------------
- */
- dstart=1; drecords=1;
- if (H5TBdelete_record(fid,"table3",dstart,drecords)<0)
- goto out;
-
- if (H5TBget_table_info(fid,"table3",&rfields,&rrecords)<0)
- goto out;
-
- rstart=0;
- if (H5TBread_records(fid,"table3",rstart,rrecords,type_size_mem,field_offset,
- field_size,rbuf)<0)
- goto out;
-
- /* Compare */
- assert(rrecords == nrecords-drecords);
- if (compare_deleted(rrecords,dstart,drecords,rbuf,wbufd)<0)
- goto out;
-
-/*-------------------------------------------------------------------------
- * reset compare buffer
- *-------------------------------------------------------------------------
- */
- nrecords=rrecords;
- for( i=0; i<nrecords; i++)
- wbufd[i] = rbuf[i];
-
-/*-------------------------------------------------------------------------
- * Delete records, start at 0, delete 1
- * pos = 0
- * data= 7
- *-------------------------------------------------------------------------
- */
- dstart=0; drecords=1;
- if (H5TBdelete_record(fid,"table3",dstart,drecords)<0)
- goto out;
-
- if (H5TBget_table_info(fid,"table3",&rfields,&rrecords)<0)
- goto out;
-
- rstart=0;
- if (H5TBread_records(fid,"table3",rstart,rrecords,type_size_mem,field_offset,
- field_size,rbuf)<0)
- goto out;
-
- /* Compare */
- assert(rrecords == nrecords-drecords);
- if (compare_deleted(rrecords,dstart,drecords,rbuf,wbufd)<0)
- goto out;
-
-/*-------------------------------------------------------------------------
- * reset compare buffer
- *-------------------------------------------------------------------------
- */
- nrecords=rrecords;
- for( i=0; i<nrecords; i++)
- wbufd[i] = rbuf[i];
-
- /* Read complete table */
- if (H5TBread_table(fid,"table3",type_size_mem,field_offset,field_size,rbuf)<0)
- goto out;
-
- /* Compare */
- for( i=0; i<rrecords; i++)
- {
- if (cmp_par(i,i,rbuf,wbufd)<0)
- goto out;
- }
-
- PASSED();
- }
-
-/*-------------------------------------------------------------------------
- *
- * Functions tested:
- *
- * H5TBadd_records_from
- * H5TBread_records
- *
- *-------------------------------------------------------------------------
- */
-
- if (write)
- {
- TESTING2("adding records");
-
- /* create 2 tables */
- if (H5TBmake_table(TITLE,fid,"table4",FIELDS,RECORDS,type_size_mem,
- field_names,field_offset,field_type,
- chunk_size,fill,compress,wbuf)<0)
+ }
+ else
+ {
+ j=i-10;
+ if (cmp_par(i,j,rbuf,abuf)<0)
goto out;
- if (H5TBmake_table(TITLE,fid,"table5",FIELDS,RECORDS,type_size_mem,
- field_names,field_offset,field_type,
- chunk_size,fill,compress,wbuf)<0)
+ }
+ }
+ PASSED();
+ }
+
+ /*-------------------------------------------------------------------------
+ *
+ * Functions tested:
+ *
+ * H5TBdelete_record
+ * H5TBread_records
+ *
+ *-------------------------------------------------------------------------
+ */
+ if (write)
+ {
+ TESTING2("deleting records");
+
+ /*-------------------------------------------------------------------------
+ * Create a table
+ * pos = 0 1 2 3 4 5 6 7
+ * data= 0 1 2 3 4 5 6 7
+ *-------------------------------------------------------------------------
+ */
+
+ for( i=0; i<NRECORDS; i++)
+ {
+ wbufd[i].lati = wbuf[i].lati;
+ wbufd[i].longi = wbuf[i].longi;
+ wbufd[i].pressure = wbuf[i].pressure;
+ wbufd[i].temperature = wbuf[i].temperature;
+ strcpy(wbufd[i].name, wbuf[i].name );
+
+ }
+
+
+ if (H5TBmake_table(TITLE,fid,"table3",FIELDS,RECORDS,type_size_mem,
+ field_names,field_offset,field_type,
+ chunk_size,fill,compress,wbufd)<0)
+ {
+ goto out;
+ }
+
+ /*-------------------------------------------------------------------------
+ * Delete records, start at 2, delete 3
+ * pos = 0 1 2 3 4
+ * data= 0 1 5 6 7
+ *-------------------------------------------------------------------------
+ */
+ dstart=2; drecords=3;
+ if (H5TBdelete_record(fid,"table3",dstart,drecords)<0)
+ goto out;
+
+ if (H5TBget_table_info(fid,"table3",&rfields,&rrecords)<0)
+ goto out;
+
+ rstart=0;
+ if (H5TBread_records(fid,"table3",rstart,rrecords,type_size_mem,field_offset,
+ field_size,rbuf)<0)
+ goto out;
+
+ /* Compare */
+ nrecords=NRECORDS;
+ assert(rrecords == nrecords-drecords);
+ if (compare_deleted(rrecords,dstart,drecords,rbuf,wbufd)<0)
+ {
+ goto out;
+ }
+
+ /*-------------------------------------------------------------------------
+ * reset compare buffer
+ *-------------------------------------------------------------------------
+ */
+ nrecords=rrecords;
+ for( i=0; i<nrecords; i++)
+ {
+ wbufd[i] = rbuf[i];
+ }
+
+ /*-------------------------------------------------------------------------
+ * Delete records, start at 0, delete 2
+ * pos = 0 1 2
+ * data= 5 6 7
+ *-------------------------------------------------------------------------
+ */
+ dstart=0; drecords=2;
+ if (H5TBdelete_record(fid,"table3",dstart,drecords)<0)
+ goto out;
+
+ if (H5TBget_table_info(fid,"table3",&rfields,&rrecords)<0)
+ goto out;
+
+ rstart=0;
+ if (H5TBread_records(fid,"table3",rstart,rrecords,type_size_mem,field_offset,
+ field_size,rbuf)<0)
+ goto out;
+
+ /* Compare */
+ assert(rrecords == nrecords-drecords);
+ if (compare_deleted(rrecords,dstart,drecords,rbuf,wbufd)<0)
+ {
+ goto out;
+ }
+
+ /*-------------------------------------------------------------------------
+ * reset compare buffer
+ *-------------------------------------------------------------------------
+ */
+ nrecords=rrecords;
+ for( i=0; i<nrecords; i++)
+ {
+ wbufd[i] = rbuf[i];
+ }
+
+ /*-------------------------------------------------------------------------
+ * Delete records, start at 1, delete 1
+ * pos = 0 1
+ * data= 5 7
+ *-------------------------------------------------------------------------
+ */
+ dstart=1; drecords=1;
+ if (H5TBdelete_record(fid,"table3",dstart,drecords)<0)
+ goto out;
+
+ if (H5TBget_table_info(fid,"table3",&rfields,&rrecords)<0)
+ goto out;
+
+ rstart=0;
+ if (H5TBread_records(fid,"table3",rstart,rrecords,type_size_mem,field_offset,
+ field_size,rbuf)<0)
+ goto out;
+
+ /* Compare */
+ assert(rrecords == nrecords-drecords);
+ if (compare_deleted(rrecords,dstart,drecords,rbuf,wbufd)<0)
+ {
+ goto out;
+ }
+
+ /*-------------------------------------------------------------------------
+ * reset compare buffer
+ *-------------------------------------------------------------------------
+ */
+ nrecords=rrecords;
+ for( i=0; i<nrecords; i++)
+ {
+ wbufd[i] = rbuf[i];
+ }
+
+ /*-------------------------------------------------------------------------
+ * Delete records, start at 0, delete 1
+ * pos = 0
+ * data= 7
+ *-------------------------------------------------------------------------
+ */
+ dstart=0; drecords=1;
+ if (H5TBdelete_record(fid,"table3",dstart,drecords)<0)
+ goto out;
+
+ if (H5TBget_table_info(fid,"table3",&rfields,&rrecords)<0)
+ goto out;
+
+ rstart=0;
+ if (H5TBread_records(fid,"table3",rstart,rrecords,type_size_mem,field_offset,
+ field_size,rbuf)<0)
+ goto out;
+
+ /* Compare */
+ assert(rrecords == nrecords-drecords);
+ if (compare_deleted(rrecords,dstart,drecords,rbuf,wbufd)<0)
+ {
+ goto out;
+ }
+
+ /*-------------------------------------------------------------------------
+ * reset compare buffer
+ *-------------------------------------------------------------------------
+ */
+ nrecords=rrecords;
+ for( i=0; i<nrecords; i++)
+ {
+ wbufd[i] = rbuf[i];
+ }
+
+ /* Read complete table */
+ if (H5TBread_table(fid,"table3",type_size_mem,field_offset,field_size,rbuf)<0)
+ goto out;
+
+ /* Compare */
+ for( i=0; i<rrecords; i++)
+ {
+ if (cmp_par(i,i,rbuf,wbufd)<0)
+ goto out;
+ }
+
+ /*-------------------------------------------------------------------------
+ * Delete records, start at 0, delete 1
+ * pos = 0
+ * data= empty
+ *-------------------------------------------------------------------------
+ */
+ dstart=0; drecords=1;
+ if (H5TBdelete_record(fid,"table3",dstart,drecords)<0)
+ goto out;
+
+ if (H5TBget_table_info(fid,"table3",&rfields,&rrecords)<0)
+ goto out;
+
+ if (rrecords)
+ goto out;
+
+ PASSED();
+ }
+
+ /*-------------------------------------------------------------------------
+ *
+ * Functions tested:
+ *
+ * H5TBadd_records_from
+ * H5TBread_records
+ *
+ *-------------------------------------------------------------------------
+ */
+
+ if (write)
+ {
+ TESTING2("adding records");
+
+ /* create 2 tables */
+ if (H5TBmake_table(TITLE,fid,"table4",FIELDS,RECORDS,type_size_mem,
+ field_names,field_offset,field_type,
+ chunk_size,fill,compress,wbuf)<0)
+ goto out;
+ if (H5TBmake_table(TITLE,fid,"table5",FIELDS,RECORDS,type_size_mem,
+ field_names,field_offset,field_type,
+ chunk_size,fill,compress,wbuf)<0)
+ goto out;
+
+ /* add the records from "table4" to "table5" */
+ start1 = 3;
+ nrecords = 2;
+ start2 = 6;
+ if ( H5TBadd_records_from(fid,"table4",start1,nrecords,"table5",start2)<0)
+ goto out;
+
+ /* read final table */
+ if (H5TBread_table(fid,"table5",type_size_mem,field_offset,field_size,rbuf)<0)
+ goto out;
+
+ /* compare */
+ for( i = 0; i < NRECORDS+2; i++ )
+ {
+ if ( i < start2 )
+ {
+ if (cmp_par(i,i,rbuf,wbuf)<0)
goto out;
-
- /* add the records from "table4" to "table5" */
- start1 = 3;
- nrecords = 2;
- start2 = 6;
- if ( H5TBadd_records_from(fid,"table4",start1,nrecords,"table5",start2)<0)
- goto out;
-
- /* read final table */
- if (H5TBread_table(fid,"table5",type_size_mem,field_offset,field_size,rbuf)<0)
- goto out;
-
- /* compare */
- for( i = 0; i < NRECORDS+2; i++ )
- {
- if ( i < start2 )
- {
- if (cmp_par(i,i,rbuf,wbuf)<0)
- goto out;
- }
- else if ( i < (int)start2+(int)nrecords )
- {
- j = i-(int)start1;
- if (cmp_par(i,j,rbuf,wbuf)<0)
- goto out;
- }
- else
- {
- j = i-(int)nrecords;
- if (cmp_par(i,j,rbuf,wbuf)<0)
- goto out;
- }
- }
-
- PASSED();
- }
-
-/*-------------------------------------------------------------------------
- *
- * Functions tested:
- *
- * H5TBcombine_tables
- * H5TBread_table
- *
- *-------------------------------------------------------------------------
- */
-
- if (write)
- {
- TESTING2("combining tables");
-
- /* create 2 tables */
- if (H5TBmake_table(TITLE,fid,"table6",FIELDS,RECORDS,type_size_mem,
- field_names,field_offset,field_type,
- chunk_size,fill,compress,wbuf)<0)
+ }
+ else if ( i < (int)start2+(int)nrecords )
+ {
+ j = i-(int)start1;
+ if (cmp_par(i,j,rbuf,wbuf)<0)
goto out;
- if (H5TBmake_table(TITLE,fid,"table7",FIELDS,RECORDS,type_size_mem,
- field_names,field_offset,field_type,
- chunk_size,fill,compress,wbuf)<0)
+ }
+ else
+ {
+ j = i-(int)nrecords;
+ if (cmp_par(i,j,rbuf,wbuf)<0)
goto out;
-
- /* combine the two tables into a third */
- if ( H5TBcombine_tables(fid,"table6",fid,"table7","table8")<0)
- goto out;
-
- /* read merged table */
- if (H5TBread_table(fid,"table8",type_size_mem,field_offset,field_size,rbufc)<0)
- goto out;
-
- /* compare */
- for( i = 0; i < NRECORDS*2; i++ )
- {
- if ( i < NRECORDS )
- {
- if (cmp_par(i,i,rbufc,wbuf)<0)
- goto out;
- }
- else
- {
- if (cmp_par(i,i-NRECORDS,rbufc,wbuf)<0)
- goto out;
- }
- }
-
-/*-------------------------------------------------------------------------
- * multi file test
- *-------------------------------------------------------------------------
- */
-
- /* create 2 files using default properties. */
- fid1 = H5Fcreate("combine_tables1.h5",H5F_ACC_TRUNC,H5P_DEFAULT,H5P_DEFAULT);
- fid2 = H5Fcreate("combine_tables2.h5",H5F_ACC_TRUNC,H5P_DEFAULT,H5P_DEFAULT);
-
- /* create 2 tables, one in each file */
- if (H5TBmake_table(TITLE,fid1,"table1",FIELDS,RECORDS,type_size_mem,
- field_names,field_offset,field_type,
- chunk_size,fill,compress,wbuf)<0)
+ }
+ }
+
+ PASSED();
+ }
+
+ /*-------------------------------------------------------------------------
+ *
+ * Functions tested:
+ *
+ * H5TBcombine_tables
+ * H5TBread_table
+ *
+ *-------------------------------------------------------------------------
+ */
+
+ if (write)
+ {
+ TESTING2("combining tables");
+
+ /* create 2 tables */
+ if (H5TBmake_table(TITLE,fid,"table6",FIELDS,RECORDS,type_size_mem,
+ field_names,field_offset,field_type,
+ chunk_size,fill,compress,wbuf)<0)
+ goto out;
+ if (H5TBmake_table(TITLE,fid,"table7",FIELDS,RECORDS,type_size_mem,
+ field_names,field_offset,field_type,
+ chunk_size,fill,compress,wbuf)<0)
+ goto out;
+
+ /* combine the two tables into a third */
+ if ( H5TBcombine_tables(fid,"table6",fid,"table7","table8")<0)
+ goto out;
+
+ /* read merged table */
+ if (H5TBread_table(fid,"table8",type_size_mem,field_offset,field_size,rbufc)<0)
+ goto out;
+
+ /* compare */
+ for( i = 0; i < NRECORDS*2; i++ )
+ {
+ if ( i < NRECORDS )
+ {
+ if (cmp_par(i,i,rbufc,wbuf)<0)
goto out;
- if (H5TBmake_table(TITLE,fid2,"table2",FIELDS,RECORDS,type_size_mem,
- field_names,field_offset,field_type,
- chunk_size,fill,compress,wbuf)<0)
+ }
+ else
+ {
+ if (cmp_par(i,i-NRECORDS,rbufc,wbuf)<0)
goto out;
-
- /* combine the two tables into a third */
- if ( H5TBcombine_tables(fid1,"table1",fid2,"table2","table3")<0)
- goto out;
-
- /* read merged table */
- if (H5TBread_table(fid1,"table3",type_size_mem,field_offset,field_size,rbufc)<0)
- goto out;
-
- /* compare */
- for( i = 0; i < NRECORDS*2; i++ )
- {
- if ( i < NRECORDS )
- {
- if (cmp_par(i,i,rbufc,wbuf)<0)
- goto out;
- }
- else
- {
- if (cmp_par(i,i-NRECORDS,rbufc,wbuf)<0)
- goto out;
- }
- }
-
- /* close files */
- H5Fclose(fid1);
- H5Fclose(fid2);
-
- PASSED();
- }
-
-
-/*-------------------------------------------------------------------------
- *
- * Functions tested:
- *
- * H5TBwrite_fields_name
- *
- *-------------------------------------------------------------------------
- */
- if (write)
- {
- TESTING2("writing fields by name");
-
- /* make an empty table with fill values */
- if (H5TBmake_table(TITLE,fid,"table9",FIELDS,RECORDS,type_size_mem,
- field_names,field_offset,field_type,
- chunk_size,fill1,compress,0)<0)
+ }
+ }
+
+ /*-------------------------------------------------------------------------
+ * multi file test
+ *-------------------------------------------------------------------------
+ */
+
+ /* create 2 files using default properties. */
+ fid1 = H5Fcreate("combine_tables1.h5",H5F_ACC_TRUNC,H5P_DEFAULT,H5P_DEFAULT);
+ fid2 = H5Fcreate("combine_tables2.h5",H5F_ACC_TRUNC,H5P_DEFAULT,H5P_DEFAULT);
+
+ /* create 2 tables, one in each file */
+ if (H5TBmake_table(TITLE,fid1,"table1",FIELDS,RECORDS,type_size_mem,
+ field_names,field_offset,field_type,
+ chunk_size,fill,compress,wbuf)<0)
+ goto out;
+ if (H5TBmake_table(TITLE,fid2,"table2",FIELDS,RECORDS,type_size_mem,
+ field_names,field_offset,field_type,
+ chunk_size,fill,compress,wbuf)<0)
+ goto out;
+
+ /* combine the two tables into a third */
+ if ( H5TBcombine_tables(fid1,"table1",fid2,"table2","table3")<0)
+ goto out;
+
+ /* read merged table */
+ if (H5TBread_table(fid1,"table3",type_size_mem,field_offset,field_size,rbufc)<0)
+ goto out;
+
+ /* compare */
+ for( i = 0; i < NRECORDS*2; i++ )
+ {
+ if ( i < NRECORDS )
+ {
+ if (cmp_par(i,i,rbufc,wbuf)<0)
goto out;
-
- /* write the pressure field starting at record 2 */
- start = 2;
- nrecords = NRECORDS_ADD;
- if (H5TBwrite_fields_name(fid,"table9","Pressure",start,nrecords,sizeof(float),
- 0,field_sizes_pre,pressure_in)<0)
- goto out;
-
- /* write the new longitude and latitude information starting at record 2 */
- start = 2;
- nrecords = 3;
- if (H5TBwrite_fields_name(fid,"table9","Latitude,Longitude",start,nrecords,sizeof(position_t),
- field_offset_pos,field_sizes_pos,position_in)<0)
- goto out;
-
- /* read back the all table */
- start = 0;
- nrecords = NRECORDS;
- if (H5TBread_table(fid,"table9",type_size_mem,field_offset,field_size,rbuf)<0)
- goto out;
-
- {
-
-
- /* compare the read values with the initial values */
- for( i = 0; i < NRECORDS; i++ )
- {
- if ( i >= 2 && i <= 4 )
+ }
+ else
+ {
+ if (cmp_par(i,i-NRECORDS,rbufc,wbuf)<0)
+ goto out;
+ }
+ }
+
+ /* close files */
+ H5Fclose(fid1);
+ H5Fclose(fid2);
+
+ PASSED();
+ }
+
+
+ /*-------------------------------------------------------------------------
+ *
+ * Functions tested:
+ *
+ * H5TBwrite_fields_name
+ *
+ *-------------------------------------------------------------------------
+ */
+ if (write)
{
- if ( rbuf[i].lati != position_in[i-NRECORDS_ADD+1].lati ||
- rbuf[i].longi != position_in[i-NRECORDS_ADD+1].longi ||
- rbuf[i].pressure != pressure_in[i-NRECORDS_ADD+1] )
- {
- fprintf(stderr,"%ld %f %d\n",
- rbuf[i].longi,rbuf[i].pressure,rbuf[i].lati);
- fprintf(stderr,"%ld %f %d\n",
- position_in[i].longi,pressure_in[i],position_in[i].lati);
- goto out;
- }
+ TESTING2("writing fields by name");
+
+ /* make an empty table with fill values */
+ if (H5TBmake_table(TITLE,fid,"table9",FIELDS,RECORDS,type_size_mem,
+ field_names,field_offset,field_type,
+ chunk_size,fill1,compress,0)<0)
+ goto out;
+
+ /* write the pressure field starting at record 2 */
+ start = 2;
+ nrecords = NRECORDS_ADD;
+ if (H5TBwrite_fields_name(fid,"table9","Pressure",start,nrecords,sizeof(float),
+ 0,field_sizes_pre,pressure_in)<0)
+ goto out;
+
+ /* write the new longitude and latitude information starting at record 2 */
+ start = 2;
+ nrecords = 3;
+ if (H5TBwrite_fields_name(fid,"table9","Latitude,Longitude",start,nrecords,sizeof(position_t),
+ field_offset_pos,field_sizes_pos,position_in)<0)
+ goto out;
+
+ /* read back the all table */
+ start = 0;
+ nrecords = NRECORDS;
+ if (H5TBread_table(fid,"table9",type_size_mem,field_offset,field_size,rbuf)<0)
+ goto out;
+
+ {
+
+
+ /* compare the read values with the initial values */
+ for( i = 0; i < NRECORDS; i++ )
+ {
+ if ( i >= 2 && i <= 4 )
+ {
+ if ( rbuf[i].lati != position_in[i-NRECORDS_ADD+1].lati ||
+ rbuf[i].longi != position_in[i-NRECORDS_ADD+1].longi ||
+ rbuf[i].pressure != pressure_in[i-NRECORDS_ADD+1] )
+ {
+ fprintf(stderr,"%ld %f %d\n",
+ rbuf[i].longi,rbuf[i].pressure,rbuf[i].lati);
+ fprintf(stderr,"%ld %f %d\n",
+ position_in[i].longi,pressure_in[i],position_in[i].lati);
+ goto out;
+ }
+ }
+ }
+ }
+
+
+
+ PASSED();
+ } /*write*/
+
+ /*-------------------------------------------------------------------------
+ *
+ * Functions tested:
+ *
+ * H5TBread_fields_name
+ *
+ *-------------------------------------------------------------------------
+ */
+ TESTING2("reading fields by name");
+
+ /*-------------------------------------------------------------------------
+ * write and read the "Pressure" field
+ *-------------------------------------------------------------------------
+ */
+ if (write)
+ {
+ if (H5TBmake_table(TITLE,fid,"table10",FIELDS,RECORDS,type_size_mem,
+ field_names,field_offset,field_type,
+ chunk_size,fill1,compress,0)<0)
+ goto out;
+
+ /* write the pressure field to all the records */
+ start = 0;
+ nrecords = NRECORDS;
+ if ( H5TBwrite_fields_name(fid,"table10","Pressure",start,nrecords,
+ sizeof( float ),0,field_sizes_pre,pressure_in)<0)
+ goto out;
}
- }
- }
-
-
-
- PASSED();
- } /*write*/
-
-/*-------------------------------------------------------------------------
- *
- * Functions tested:
- *
- * H5TBread_fields_name
- *
- *-------------------------------------------------------------------------
- */
- TESTING2("reading fields by name");
-
-/*-------------------------------------------------------------------------
- * write and read the "Pressure" field
- *-------------------------------------------------------------------------
- */
- if (write)
- {
- if (H5TBmake_table(TITLE,fid,"table10",FIELDS,RECORDS,type_size_mem,
- field_names,field_offset,field_type,
- chunk_size,fill1,compress,0)<0)
- goto out;
-
- /* write the pressure field to all the records */
- start = 0;
- nrecords = NRECORDS;
- if ( H5TBwrite_fields_name(fid,"table10","Pressure",start,nrecords,
- sizeof( float ),0,field_sizes_pre,pressure_in)<0)
- goto out;
- }
-
- /* read the "Pressure" field */
- start = 0;
- nrecords = NRECORDS;
- if ( H5TBread_fields_name(fid,"table10","Pressure",start,nrecords,
- sizeof(float),0,field_sizes_pre,pressure_out)<0)
- goto out;
-
-
- /* Compare the extracted table with the initial values */
- for( i = 0; i < NRECORDS; i++ )
- {
- if ( pressure_out[i] != pressure_in[i] ) {
- goto out;
- }
- }
-
-/*-------------------------------------------------------------------------
- * Write and read the "Latitude,Longitude" fields
- *-------------------------------------------------------------------------
- */
- if (write)
- {
- /* Write the new longitude and latitude information to all the records */
- start = 0;
- nrecords = NRECORDS_ADD;
- if ( H5TBwrite_fields_name(fid,"table10", "Latitude,Longitude", start, nrecords,
- sizeof( position_t ), field_offset_pos, field_sizes_pos, position_in ) < 0 )
- goto out;
- }/*write*/
-
- /* Read the "Latitude,Longitude" fields */
- start = 0;
- nrecords = NRECORDS_ADD;
- if ( H5TBread_fields_name( fid, "table10", "Latitude,Longitude",
- start, nrecords, sizeof(position_t), field_offset_pos, field_sizes_pos, position_out ) < 0 )
- goto out;
-
-
- /* Compare the extracted table with the initial values */
- for( i = 0; i < NRECORDS_ADD; i++ )
- {
- if ( position_out[i].lati != position_in[i].lati ||
- position_out[i].longi != position_in[i].longi )
- goto out;
- }
-
-
-/*-------------------------------------------------------------------------
- * Write and read the "Name,Pressure" fields
- *-------------------------------------------------------------------------
- */
- if (write)
- {
- /* Write the new name and pressure information to all the records */
- start = 0;
- nrecords = NRECORDS;
- if ( H5TBwrite_fields_name( fid, "table10", "Name,Pressure", start, nrecords,
- sizeof( namepressure_t ), field_offset_namepre, field_sizes_namepre, namepre_in ) < 0 )
- goto out;
- }/*write*/
-
- /* Read the "Name,Pressure" fields */
- start = 0;
- nrecords = NRECORDS;
- if ( H5TBread_fields_name( fid, "table10", "Name,Pressure",
- start, nrecords, sizeof(namepressure_t), field_offset_namepre, field_sizes_namepre,
- namepre_out ) < 0 )
- goto out;
-
-
- /* Compare the extracted table with the initial values */
- for( i = 0; i < NRECORDS; i++ )
- {
- if ( ( strcmp( namepre_out[i].name, namepre_in[i].name ) != 0 ) ||
- namepre_out[i].pressure != namepre_in[i].pressure ) {
- goto out;
- }
- }
-
- /* reset buffer */
- for( i = 0; i < NRECORDS; i++ )
- {
- strcpy( namepre_out[i].name, "\0" );
- namepre_out[i].pressure = -1;
- }
-
-/*-------------------------------------------------------------------------
- * read only 3 records of the "Name,Pressure" fields, starting at record 2
- *-------------------------------------------------------------------------
- */
- start = 2;
- nrecords = 3;
- if ( H5TBread_fields_name( fid, "table10", "Name,Pressure",
- start, nrecords, sizeof(namepressure_t), field_offset_namepre,
- field_sizes_namepre, namepre_out ) < 0 )
- goto out;
-
-
- /* Compare the extracted table with the initial values */
- for( i = 0; i < 3; i++ )
- {
- int iistart = (int) start;
- if ( ( strcmp( namepre_out[i].name, namepre_in[iistart+i].name ) != 0 ) ||
- namepre_out[i].pressure != namepre_in[iistart+i].pressure ) {
- goto out;
- }
- }
-
-
-
- PASSED();
-
-/*-------------------------------------------------------------------------
- *
- * Functions tested:
- *
- * H5TBwrite_fields_index
- *
- *-------------------------------------------------------------------------
- */
- if (write)
- {
- TESTING2("writing fields by index");
-
- /* make an empty table */
- if (H5TBmake_table(TITLE,fid,"table11",FIELDS,RECORDS,type_size_mem,
- field_names,field_offset,field_type,
- chunk_size,fill,compress,NULL)<0)
- goto out;
-
- /* write the pressure field starting at record 2 */
- nfields = 1;
- start = 2;
- nrecords = NRECORDS_ADD;
- if ( H5TBwrite_fields_index(fid, "table11", nfields, field_index_pre, start, nrecords,
- sizeof( float ), 0, field_sizes_pre, pressure_in ) < 0 )
- goto out;
-
-
- /* write the new longitude and latitude information starting at record 2 */
- nfields = 2;
- start = 2;
- nrecords = NRECORDS_ADD;
- if ( H5TBwrite_fields_index(fid, "table11", nfields, field_index_pos, start, nrecords,
- sizeof( position_t ), field_offset_pos, field_sizes_pos, position_in ) < 0 )
- goto out;
-
- /* read back the all table */
- nfields = 5;
- start = 0;
- nrecords = NRECORDS;
- if ( H5TBread_fields_index(fid, "table11", nfields, field_index,
- start, nrecords, type_size_mem, field_offset, field_size, rbuf ) < 0 )
- goto out;
-
- /* Compare the extracted table with the initial values */
- for( i = 0; i < NRECORDS; i++ )
- {
- if ( i >= 2 && i <= 4 )
- {
- if ( rbuf[i].lati != position_in[i-NRECORDS_ADD+1].lati ||
- rbuf[i].longi != position_in[i-NRECORDS_ADD+1].longi ||
- rbuf[i].pressure != pressure_in[i-NRECORDS_ADD+1] )
- goto out;
- }
- }
-
- PASSED();
- }
-
-
-/*-------------------------------------------------------------------------
- *
- * Functions tested:
- *
- * H5TBread_fields_index
- *
- *-------------------------------------------------------------------------
- */
-
- TESTING2("reading fields by index");
-
- if (write)
- {
- /* make an empty table */
- if (H5TBmake_table(TITLE,fid,"table12",FIELDS,RECORDS,type_size_mem,
- field_names,field_offset,field_type,
- chunk_size,fill,compress,NULL)<0)
- goto out;
-
-/*-------------------------------------------------------------------------
- * write and read the "Pressure" field
- *-------------------------------------------------------------------------
- */
-
- /* write the pressure field to all the records */
- nfields = 1;
- start = 0;
- nrecords = NRECORDS;
- if ( H5TBwrite_fields_index(fid, "table12", nfields, field_index_pre, start, nrecords,
- sizeof( float ), 0, field_sizes_pre, pressure_in ) < 0 )
- goto out;
- }
-
- /* read the "Pressure" field */
- nfields = 1;
- start = 0;
- nrecords = NRECORDS;
- if ( H5TBread_fields_index(fid, "table12", nfields, field_index_pre,
- start, nrecords, sizeof(float), 0, field_sizes_pre, pressure_out ) < 0 )
- goto out;
-
- /* compare the extracted table with the initial values */
- for( i = 0; i < NRECORDS; i++ )
- {
- if ( pressure_out[i] != pressure_in[i] ) {
- goto out;
- }
- }
-
-/*-------------------------------------------------------------------------
- * write and read the "Latitude,Longitude" fields
- *-------------------------------------------------------------------------
- */
- if (write)
- {
- /* write the new longitude and latitude information to all the records */
- nfields = 2;
- start = 0;
- nrecords = NRECORDS;
- if ( H5TBwrite_fields_index(fid, "table12", nfields, field_index_pos, start, nrecords,
- sizeof( position_t ), field_offset_pos, field_sizes_pos, position_in ) < 0 )
- goto out;
- } /*write*/
-
- /* read the "Latitude,Longitude" fields */
- nfields = 2;
- start = 0;
- nrecords = NRECORDS_ADD;
- if ( H5TBread_fields_index(fid, "table12", nfields, field_index_pos,
- start, nrecords, sizeof(position_t), field_offset_pos, field_sizes_pos, position_out ) < 0 )
- goto out;
-
- /* compare the extracted table with the initial values */
- for( i = 0; i < NRECORDS_ADD; i++ )
- {
- if ( position_out[i].lati != position_in[i].lati ||
- position_out[i].longi != position_in[i].longi ) {
- goto out;
- }
- }
-
-/*-------------------------------------------------------------------------
- * write and read the "Name,Pressure" fields
- *-------------------------------------------------------------------------
- */
-
- if (write)
- {
- /* write the new name and pressure information to all the records */
- nfields = 2;
- start = 0;
- nrecords = NRECORDS;
- if ( H5TBwrite_fields_index(fid, "table12", nfields, field_index_namepre, start, nrecords,
- sizeof( namepressure_t ), field_offset_namepre, field_sizes_namepre, namepre_in ) < 0 )
- goto out;
- }
-
- /* read the "Name,Pressure" fields */
- nfields = 2;
- start = 0;
- nrecords = NRECORDS;
- if ( H5TBread_fields_index(fid, "table12", nfields, field_index_namepre,
- start, nrecords, sizeof(namepressure_t), field_offset_namepre,
- field_sizes_namepre, namepre_out ) < 0 )
- goto out;
-
- /* compare the extracted table with the initial values */
- for( i = 0; i < NRECORDS; i++ )
- {
- if ( ( strcmp( namepre_out[i].name, namepre_in[i].name ) != 0 ) ||
- namepre_out[i].pressure != namepre_in[i].pressure ) {
- goto out;
- }
- }
-
- /* reset buffer */
- for( i = 0; i < NRECORDS; i++ )
- {
- strcpy( namepre_out[i].name, "\0" );
- namepre_out[i].pressure = -1;
- }
-
-/*-------------------------------------------------------------------------
- * read only 3 records of the "Name,Pressure" fields, starting at record 2
- *-------------------------------------------------------------------------
- */
-
- /* write the new name and pressure information to all the records */
- nfields = 2;
- start = 2;
- nrecords = 3;
- if ( H5TBread_fields_index(fid, "table12", nfields, field_index_namepre,
- start, nrecords, sizeof(namepressure_t), field_offset_namepre,
- field_sizes_namepre, namepre_out ) < 0 )
- goto out;
-
- /* compare the extracted table with the initial values */
- for( i = 0; i < 3; i++ )
- {
- int iistart = (int) start;
- if ( ( strcmp( namepre_out[i].name, wbuf[iistart+i].name ) != 0 ) ||
- namepre_out[i].pressure != wbuf[iistart+i].pressure ) {
- goto out;
- }
- }
-
- PASSED();
-
-
-/*-------------------------------------------------------------------------
- *
- * Functions tested:
- *
- * H5TBinsert_field
- *
- *-------------------------------------------------------------------------
- */
-
- if (write)
- {
- TESTING2("inserting fields");
-
- /* make a table */
- if (H5TBmake_table(TITLE,fid,"table13",FIELDS,RECORDS,type_size_mem,
- field_names,field_offset,field_type,
- chunk_size,fill1,compress,wbuf)<0)
- goto out;
-
- /* insert the new field at the end of the field list */
- position = NFIELDS;
- if ( H5TBinsert_field( fid, "table13", "New Field", field_type_new, position,
- fill1_new, buf_new ) < 0 )
- goto out;
-
- /* read the table */
- if ( H5TBread_table( fid, "table13", dst_size2, dst_offset2, dst_sizes2, rbuf2 ) < 0 )
- goto out;
-
- /* compare the extracted table with the original array */
- for( i = 0; i < NRECORDS; i++ )
- {
- if ( ( strcmp( rbuf2[i].name, wbuf[i].name ) != 0 ) ||
- rbuf2[i].lati != wbuf[i].lati ||
- rbuf2[i].longi != wbuf[i].longi ||
- rbuf2[i].pressure != wbuf[i].pressure ||
- rbuf2[i].temperature != wbuf[i].temperature ||
- rbuf2[i].new_field != buf_new[i] ) {
- goto out;
- }
- }
- PASSED();
- }
-
-
-/*-------------------------------------------------------------------------
- *
- * Functions tested:
- *
- * H5TBdelete_field
- *
- *-------------------------------------------------------------------------
- */
- if (write)
- {
- TESTING2("deleting fields");
-
- /* make a table */
- if (H5TBmake_table(TITLE,fid,"table14",FIELDS,RECORDS,type_size_mem,
- field_names,field_offset,field_type,
- chunk_size,fill,compress,wbuf)<0)
+
+ /* read the "Pressure" field */
+ start = 0;
+ nrecords = NRECORDS;
+ if ( H5TBread_fields_name(fid,"table10","Pressure",start,nrecords,
+ sizeof(float),0,field_sizes_pre,pressure_out)<0)
+ goto out;
+
+
+ /* Compare the extracted table with the initial values */
+ for( i = 0; i < NRECORDS; i++ )
+ {
+ if ( pressure_out[i] != pressure_in[i] ) {
+ goto out;
+ }
+ }
+
+ /*-------------------------------------------------------------------------
+ * Write and read the "Latitude,Longitude" fields
+ *-------------------------------------------------------------------------
+ */
+ if (write)
+ {
+ /* Write the new longitude and latitude information to all the records */
+ start = 0;
+ nrecords = NRECORDS_ADD;
+ if ( H5TBwrite_fields_name(fid,"table10", "Latitude,Longitude", start, nrecords,
+ sizeof( position_t ), field_offset_pos, field_sizes_pos, position_in ) < 0 )
+ goto out;
+ }/*write*/
+
+ /* Read the "Latitude,Longitude" fields */
+ start = 0;
+ nrecords = NRECORDS_ADD;
+ if ( H5TBread_fields_name( fid, "table10", "Latitude,Longitude",
+ start, nrecords, sizeof(position_t), field_offset_pos, field_sizes_pos, position_out ) < 0 )
+ goto out;
+
+
+ /* Compare the extracted table with the initial values */
+ for( i = 0; i < NRECORDS_ADD; i++ )
+ {
+ if ( position_out[i].lati != position_in[i].lati ||
+ position_out[i].longi != position_in[i].longi )
+ goto out;
+ }
+
+
+ /*-------------------------------------------------------------------------
+ * Write and read the "Name,Pressure" fields
+ *-------------------------------------------------------------------------
+ */
+ if (write)
+ {
+ /* Write the new name and pressure information to all the records */
+ start = 0;
+ nrecords = NRECORDS;
+ if ( H5TBwrite_fields_name( fid, "table10", "Name,Pressure", start, nrecords,
+ sizeof( namepressure_t ), field_offset_namepre, field_sizes_namepre, namepre_in ) < 0 )
+ goto out;
+ }/*write*/
+
+ /* Read the "Name,Pressure" fields */
+ start = 0;
+ nrecords = NRECORDS;
+ if ( H5TBread_fields_name( fid, "table10", "Name,Pressure",
+ start, nrecords, sizeof(namepressure_t), field_offset_namepre, field_sizes_namepre,
+ namepre_out ) < 0 )
+ goto out;
+
+
+ /* Compare the extracted table with the initial values */
+ for( i = 0; i < NRECORDS; i++ )
+ {
+ if ( ( strcmp( namepre_out[i].name, namepre_in[i].name ) != 0 ) ||
+ namepre_out[i].pressure != namepre_in[i].pressure ) {
+ goto out;
+ }
+ }
+
+ /* reset buffer */
+ for( i = 0; i < NRECORDS; i++ )
+ {
+ strcpy( namepre_out[i].name, "\0" );
+ namepre_out[i].pressure = -1;
+ }
+
+ /*-------------------------------------------------------------------------
+ * read only 3 records of the "Name,Pressure" fields, starting at record 2
+ *-------------------------------------------------------------------------
+ */
+ start = 2;
+ nrecords = 3;
+ if ( H5TBread_fields_name( fid, "table10", "Name,Pressure",
+ start, nrecords, sizeof(namepressure_t), field_offset_namepre,
+ field_sizes_namepre, namepre_out ) < 0 )
+ goto out;
+
+
+ /* Compare the extracted table with the initial values */
+ for( i = 0; i < 3; i++ )
+ {
+ int iistart = (int) start;
+ if ( ( strcmp( namepre_out[i].name, namepre_in[iistart+i].name ) != 0 ) ||
+ namepre_out[i].pressure != namepre_in[iistart+i].pressure ) {
+ goto out;
+ }
+ }
+
+
+
+ PASSED();
+
+ /*-------------------------------------------------------------------------
+ *
+ * Functions tested:
+ *
+ * H5TBwrite_fields_index
+ *
+ *-------------------------------------------------------------------------
+ */
+ if (write)
+ {
+ TESTING2("writing fields by index");
+
+ /* make an empty table */
+ if (H5TBmake_table(TITLE,fid,"table11",FIELDS,RECORDS,type_size_mem,
+ field_names,field_offset,field_type,
+ chunk_size,fill,compress,NULL)<0)
+ goto out;
+
+ /* write the pressure field starting at record 2 */
+ nfields = 1;
+ start = 2;
+ nrecords = NRECORDS_ADD;
+ if ( H5TBwrite_fields_index(fid, "table11", nfields, field_index_pre, start, nrecords,
+ sizeof( float ), 0, field_sizes_pre, pressure_in ) < 0 )
+ goto out;
+
+
+ /* write the new longitude and latitude information starting at record 2 */
+ nfields = 2;
+ start = 2;
+ nrecords = NRECORDS_ADD;
+ if ( H5TBwrite_fields_index(fid, "table11", nfields, field_index_pos, start, nrecords,
+ sizeof( position_t ), field_offset_pos, field_sizes_pos, position_in ) < 0 )
+ goto out;
+
+ /* read back the all table */
+ nfields = 5;
+ start = 0;
+ nrecords = NRECORDS;
+ if ( H5TBread_fields_index(fid, "table11", nfields, field_index,
+ start, nrecords, type_size_mem, field_offset, field_size, rbuf ) < 0 )
+ goto out;
+
+ /* Compare the extracted table with the initial values */
+ for( i = 0; i < NRECORDS; i++ )
+ {
+ if ( i >= 2 && i <= 4 )
+ {
+ if ( rbuf[i].lati != position_in[i-NRECORDS_ADD+1].lati ||
+ rbuf[i].longi != position_in[i-NRECORDS_ADD+1].longi ||
+ rbuf[i].pressure != pressure_in[i-NRECORDS_ADD+1] )
goto out;
-
-
- /* delete the field */
- if ( H5TBdelete_field(fid, "table14", "Pressure" ) < 0 )
- goto out;
-
- /* read the table */
- if ( H5TBread_table(fid, "table14", dst_size3, dst_offset3, dst_sizes3, rbuf3 ) < 0 )
- goto out;
-
- /* compare the extracted table with the original array */
- for( i = 0; i < NRECORDS; i++ )
- {
- if ( ( strcmp( rbuf3[i].name, wbuf[i].name ) != 0 ) ||
- rbuf3[i].lati != wbuf[i].lati ||
- rbuf3[i].longi != wbuf[i].longi ||
- rbuf3[i].temperature != wbuf[i].temperature ) {
- goto out;
- }
- }
-
- PASSED();
- }
-
-/*-------------------------------------------------------------------------
- *
- * Functions tested:
- *
- * H5TBget_table_info
- * H5TBget_field_info
- *
- *-------------------------------------------------------------------------
- */
-
- TESTING2("getting table info");
-
- /* get table info */
- if ( H5TBget_table_info (fid, "table1", &rfields, &rrecords ) < 0 )
- goto out;
-
- if ( NFIELDS != rfields || rrecords != NRECORDS ) {
- goto out;
- }
-
- PASSED();
-
-/*-------------------------------------------------------------------------
- *
- * Functions tested:
- *
- * H5TBget_field_info
- *
- *-------------------------------------------------------------------------
- */
-
- TESTING2("getting field info");
-
- /* alocate */
- names_out = malloc( sizeof(char*) * (size_t)NFIELDS );
- for ( i = 0; i < NFIELDS; i++)
- {
- names_out[i] = malloc( sizeof(char) * 255 );
- }
-
- /* Get field info */
- if ( H5TBget_field_info(fid, "table1", names_out, sizes_out, offset_out, &size_out ) < 0 )
- goto out;
-
- for ( i = 0; i < NFIELDS; i++)
- {
- if ( (strcmp( field_names[i], names_out[i] ) != 0)) {
- goto out;
- }
- }
-
- /* release */
- for ( i = 0; i < NFIELDS; i++)
- {
- free ( names_out[i] );
- }
- free ( names_out );
-
- PASSED();
-
-/*-------------------------------------------------------------------------
- * end
- *-------------------------------------------------------------------------
- */
- return 0;
+ }
+ }
+
+ PASSED();
+ }
+
+
+ /*-------------------------------------------------------------------------
+ *
+ * Functions tested:
+ *
+ * H5TBread_fields_index
+ *
+ *-------------------------------------------------------------------------
+ */
+
+ TESTING2("reading fields by index");
+
+ if (write)
+ {
+ /* make an empty table */
+ if (H5TBmake_table(TITLE,fid,"table12",FIELDS,RECORDS,type_size_mem,
+ field_names,field_offset,field_type,
+ chunk_size,fill,compress,NULL)<0)
+ {
+ goto out;
+ }
+
+ /*-------------------------------------------------------------------------
+ * write and read the "Pressure" field
+ *-------------------------------------------------------------------------
+ */
+
+ /* write the pressure field to all the records */
+ nfields = 1;
+ start = 0;
+ nrecords = NRECORDS;
+ if ( H5TBwrite_fields_index(fid, "table12", nfields, field_index_pre, start, nrecords,
+ sizeof( float ), 0, field_sizes_pre, pressure_in ) < 0 )
+ goto out;
+ }
+
+ /* read the "Pressure" field */
+ nfields = 1;
+ start = 0;
+ nrecords = NRECORDS;
+ if ( H5TBread_fields_index(fid, "table12", nfields, field_index_pre,
+ start, nrecords, sizeof(float), 0, field_sizes_pre, pressure_out ) < 0 )
+ goto out;
+
+ /* compare the extracted table with the initial values */
+ for( i = 0; i < NRECORDS; i++ )
+ {
+ if ( pressure_out[i] != pressure_in[i] ) {
+ goto out;
+ }
+ }
+
+ /*-------------------------------------------------------------------------
+ * write and read the "Latitude,Longitude" fields
+ *-------------------------------------------------------------------------
+ */
+ if (write)
+ {
+ /* write the new longitude and latitude information to all the records */
+ nfields = 2;
+ start = 0;
+ nrecords = NRECORDS;
+ if ( H5TBwrite_fields_index(fid, "table12", nfields, field_index_pos, start, nrecords,
+ sizeof( position_t ), field_offset_pos, field_sizes_pos, position_in ) < 0 )
+ goto out;
+ } /*write*/
+
+ /* read the "Latitude,Longitude" fields */
+ nfields = 2;
+ start = 0;
+ nrecords = NRECORDS_ADD;
+ if ( H5TBread_fields_index(fid, "table12", nfields, field_index_pos,
+ start, nrecords, sizeof(position_t), field_offset_pos, field_sizes_pos, position_out ) < 0 )
+ goto out;
+
+ /* compare the extracted table with the initial values */
+ for( i = 0; i < NRECORDS_ADD; i++ )
+ {
+ if ( position_out[i].lati != position_in[i].lati ||
+ position_out[i].longi != position_in[i].longi ) {
+ goto out;
+ }
+ }
+
+ /*-------------------------------------------------------------------------
+ * write and read the "Name,Pressure" fields
+ *-------------------------------------------------------------------------
+ */
+
+ if (write)
+ {
+ /* write the new name and pressure information to all the records */
+ nfields = 2;
+ start = 0;
+ nrecords = NRECORDS;
+ if ( H5TBwrite_fields_index(fid, "table12", nfields, field_index_namepre, start, nrecords,
+ sizeof( namepressure_t ), field_offset_namepre, field_sizes_namepre, namepre_in ) < 0 )
+ goto out;
+ }
+
+ /* read the "Name,Pressure" fields */
+ nfields = 2;
+ start = 0;
+ nrecords = NRECORDS;
+ if ( H5TBread_fields_index(fid, "table12", nfields, field_index_namepre,
+ start, nrecords, sizeof(namepressure_t), field_offset_namepre,
+ field_sizes_namepre, namepre_out ) < 0 )
+ goto out;
+
+ /* compare the extracted table with the initial values */
+ for( i = 0; i < NRECORDS; i++ )
+ {
+ if ( ( strcmp( namepre_out[i].name, namepre_in[i].name ) != 0 ) ||
+ namepre_out[i].pressure != namepre_in[i].pressure ) {
+ goto out;
+ }
+ }
+
+ /* reset buffer */
+ for( i = 0; i < NRECORDS; i++ )
+ {
+ strcpy( namepre_out[i].name, "\0" );
+ namepre_out[i].pressure = -1;
+ }
+
+ /*-------------------------------------------------------------------------
+ * read only 3 records of the "Name,Pressure" fields, starting at record 2
+ *-------------------------------------------------------------------------
+ */
+
+ /* write the new name and pressure information to all the records */
+ nfields = 2;
+ start = 2;
+ nrecords = 3;
+ if ( H5TBread_fields_index(fid, "table12", nfields, field_index_namepre,
+ start, nrecords, sizeof(namepressure_t), field_offset_namepre,
+ field_sizes_namepre, namepre_out ) < 0 )
+ goto out;
+
+ /* compare the extracted table with the initial values */
+ for( i = 0; i < 3; i++ )
+ {
+ int iistart = (int) start;
+ if ( ( strcmp( namepre_out[i].name, wbuf[iistart+i].name ) != 0 ) ||
+ namepre_out[i].pressure != wbuf[iistart+i].pressure ) {
+ goto out;
+ }
+ }
+
+ PASSED();
+
+
+ /*-------------------------------------------------------------------------
+ *
+ * Functions tested:
+ *
+ * H5TBinsert_field
+ *
+ *-------------------------------------------------------------------------
+ */
+
+ if (write)
+ {
+ TESTING2("inserting fields");
+
+ /* make a table */
+ if (H5TBmake_table(TITLE,fid,"table13",FIELDS,RECORDS,type_size_mem,
+ field_names,field_offset,field_type,
+ chunk_size,fill1,compress,wbuf)<0)
+ goto out;
+
+ /* insert the new field at the end of the field list */
+ position = NFIELDS;
+ if ( H5TBinsert_field( fid, "table13", "New Field", field_type_new, position,
+ fill1_new, buf_new ) < 0 )
+ goto out;
+
+ /* read the table */
+ if ( H5TBread_table( fid, "table13", dst_size2, dst_offset2, dst_sizes2, rbuf2 ) < 0 )
+ goto out;
+
+ /* compare the extracted table with the original array */
+ for( i = 0; i < NRECORDS; i++ )
+ {
+ if ( ( strcmp( rbuf2[i].name, wbuf[i].name ) != 0 ) ||
+ rbuf2[i].lati != wbuf[i].lati ||
+ rbuf2[i].longi != wbuf[i].longi ||
+ rbuf2[i].pressure != wbuf[i].pressure ||
+ rbuf2[i].temperature != wbuf[i].temperature ||
+ rbuf2[i].new_field != buf_new[i] ) {
+ goto out;
+ }
+ }
+ PASSED();
+ }
+
+
+ /*-------------------------------------------------------------------------
+ *
+ * Functions tested:
+ *
+ * H5TBdelete_field
+ *
+ *-------------------------------------------------------------------------
+ */
+ if (write)
+ {
+ TESTING2("deleting fields");
+
+ /* make a table */
+ if (H5TBmake_table(TITLE,fid,"table14",FIELDS,RECORDS,type_size_mem,
+ field_names,field_offset,field_type,
+ chunk_size,fill,compress,wbuf)<0)
+ goto out;
+
+
+ /* delete the field */
+ if ( H5TBdelete_field(fid, "table14", "Pressure" ) < 0 )
+ goto out;
+
+ /* read the table */
+ if ( H5TBread_table(fid, "table14", dst_size3, dst_offset3, dst_sizes3, rbuf3 ) < 0 )
+ goto out;
+
+ /* compare the extracted table with the original array */
+ for( i = 0; i < NRECORDS; i++ )
+ {
+ if ( ( strcmp( rbuf3[i].name, wbuf[i].name ) != 0 ) ||
+ rbuf3[i].lati != wbuf[i].lati ||
+ rbuf3[i].longi != wbuf[i].longi ||
+ rbuf3[i].temperature != wbuf[i].temperature ) {
+ goto out;
+ }
+ }
+
+ PASSED();
+ }
+
+ /*-------------------------------------------------------------------------
+ *
+ * Functions tested:
+ *
+ * H5TBget_table_info
+ * H5TBget_field_info
+ *
+ *-------------------------------------------------------------------------
+ */
+
+ TESTING2("getting table info");
+
+ /* get table info */
+ if ( H5TBget_table_info (fid, "table1", &rfields, &rrecords ) < 0 )
+ goto out;
+
+ if ( NFIELDS != rfields || rrecords != NRECORDS ) {
+ goto out;
+ }
+
+ PASSED();
+
+ /*-------------------------------------------------------------------------
+ *
+ * Functions tested:
+ *
+ * H5TBget_field_info
+ *
+ *-------------------------------------------------------------------------
+ */
+
+ TESTING2("getting field info");
+
+ /* alocate */
+ names_out = malloc( sizeof(char*) * (size_t)NFIELDS );
+ for ( i = 0; i < NFIELDS; i++)
+ {
+ names_out[i] = malloc( sizeof(char) * 255 );
+ }
+
+ /* Get field info */
+ if ( H5TBget_field_info(fid, "table1", names_out, sizes_out, offset_out, &size_out ) < 0 )
+ goto out;
+
+ for ( i = 0; i < NFIELDS; i++)
+ {
+ if ( (strcmp( field_names[i], names_out[i] ) != 0)) {
+ goto out;
+ }
+ }
+
+ /* release */
+ for ( i = 0; i < NFIELDS; i++)
+ {
+ free ( names_out[i] );
+ }
+ free ( names_out );
+
+ PASSED();
+
+ /*-------------------------------------------------------------------------
+ * end
+ *-------------------------------------------------------------------------
+ */
+ return 0;
out:
- H5_FAILED();
- return -1;
+ H5_FAILED();
+ return -1;
}
@@ -1481,75 +1519,75 @@ out:
int main(void)
{
- hid_t fid; /* identifier for the file */
- unsigned flags=H5F_ACC_RDONLY;
-
-/*-------------------------------------------------------------------------
- * test1: create a file for the write/read test
- *-------------------------------------------------------------------------
- */
-
- /* create a file using default properties */
- fid=H5Fcreate("test_table.h5",H5F_ACC_TRUNC,H5P_DEFAULT,H5P_DEFAULT);
-
- puts("Testing table with file creation mode (read/write in native architecture):");
-
- /* test, do write */
- if (test_table(fid,1)<0)
- goto out;
-
- /* close */
- H5Fclose(fid);
-
-/*-------------------------------------------------------------------------
- * test2: open a file written in test1 on a big-endian machine
- *-------------------------------------------------------------------------
- */
- puts("Testing table with file open mode (read big-endian data):");
-
- fid=h5file_open(TEST_FILE_BE,flags);
-
- /* test, do not write */
- if (test_table(fid,0)<0)
- goto out;
-
- /* close */
- H5Fclose(fid);
-
-/*-------------------------------------------------------------------------
- * test3: open a file written in test1 on a little-endian machine
- *-------------------------------------------------------------------------
- */
- puts("Testing table with file open mode (read little-endian data):");
-
- fid=h5file_open(TEST_FILE_LE,flags);
-
- /* test, do not write */
- if (test_table(fid,0)<0)
- goto out;
-
- /* close */
- H5Fclose(fid);
-
-/*-------------------------------------------------------------------------
- * test4: open a file written in test1 on the Cray T3 machine
- *-------------------------------------------------------------------------
- */
- puts("Testing table with file open mode (read Cray data):");
-
- fid=h5file_open(TEST_FILE_CRAY,flags);
-
- /* test, do not write */
- if (test_table(fid,0)<0)
- goto out;
-
- /* close */
- H5Fclose(fid);
-
- return 0;
+ hid_t fid; /* identifier for the file */
+ unsigned flags=H5F_ACC_RDONLY;
+
+ /*-------------------------------------------------------------------------
+ * test1: create a file for the write/read test
+ *-------------------------------------------------------------------------
+ */
+
+ /* create a file using default properties */
+ fid=H5Fcreate("test_table.h5",H5F_ACC_TRUNC,H5P_DEFAULT,H5P_DEFAULT);
+
+ puts("Testing table with file creation mode (read/write in native architecture):");
+
+ /* test, do write */
+ if (test_table(fid,1)<0)
+ goto out;
+
+ /* close */
+ H5Fclose(fid);
+
+ /*-------------------------------------------------------------------------
+ * test2: open a file written in test1 on a big-endian machine
+ *-------------------------------------------------------------------------
+ */
+ puts("Testing table with file open mode (read big-endian data):");
+
+ fid=h5file_open(TEST_FILE_BE,flags);
+
+ /* test, do not write */
+ if (test_table(fid,0)<0)
+ goto out;
+
+ /* close */
+ H5Fclose(fid);
+
+ /*-------------------------------------------------------------------------
+ * test3: open a file written in test1 on a little-endian machine
+ *-------------------------------------------------------------------------
+ */
+ puts("Testing table with file open mode (read little-endian data):");
+
+ fid=h5file_open(TEST_FILE_LE,flags);
+
+ /* test, do not write */
+ if (test_table(fid,0)<0)
+ goto out;
+
+ /* close */
+ H5Fclose(fid);
+
+ /*-------------------------------------------------------------------------
+ * test4: open a file written in test1 on the Cray T3 machine
+ *-------------------------------------------------------------------------
+ */
+ puts("Testing table with file open mode (read Cray data):");
+
+ fid=h5file_open(TEST_FILE_CRAY,flags);
+
+ /* test, do not write */
+ if (test_table(fid,0)<0)
+ goto out;
+
+ /* close */
+ H5Fclose(fid);
+
+ return 0;
out:
- H5Fclose(fid);
- return 1;
+ H5Fclose(fid);
+ return 1;
}
@@ -1559,25 +1597,25 @@ out:
*/
static hid_t h5file_open(const char *fname, unsigned flags)
{
-
- hid_t fid; /* identifier for the file */
- char *srcdir = getenv("srcdir"); /* the source directory */
- char data_file[512]=""; /* buffer to hold name of existing file */
-
- /* compose the name of the file to open, using the srcdir, if appropriate */
- if (srcdir){
- strcpy(data_file,srcdir);
- strcat(data_file,"/");
- }
- strcat(data_file,fname);
-
- /* open */
- if((fid=H5Fopen(data_file,flags,H5P_DEFAULT))<0) {
- fprintf(stderr,"Error: Cannot open file <%s>\n",data_file );
- exit(1);
- }
-
- return fid;
+
+ hid_t fid; /* identifier for the file */
+ char *srcdir = getenv("srcdir"); /* the source directory */
+ char data_file[512]=""; /* buffer to hold name of existing file */
+
+ /* compose the name of the file to open, using the srcdir, if appropriate */
+ if (srcdir){
+ strcpy(data_file,srcdir);
+ strcat(data_file,"/");
+ }
+ strcat(data_file,fname);
+
+ /* open */
+ if((fid=H5Fopen(data_file,flags,H5P_DEFAULT))<0) {
+ fprintf(stderr,"Error: Cannot open file <%s>\n",data_file );
+ exit(1);
+ }
+
+ return fid;
}
/*-------------------------------------------------------------------------
@@ -1586,19 +1624,19 @@ static hid_t h5file_open(const char *fname, unsigned flags)
*/
static int cmp_par(hsize_t i, hsize_t j, particle_t *rbuf, particle_t *wbuf )
{
- if ( ( strcmp( rbuf[i].name, wbuf[j].name ) != 0 ) ||
- rbuf[i].lati != wbuf[j].lati ||
- rbuf[i].longi != wbuf[j].longi ||
- rbuf[i].pressure != wbuf[j].pressure ||
- rbuf[i].temperature != wbuf[j].temperature ) {
- fprintf(stderr,"read and write buffers have differences\n");
- fprintf(stderr,"%s %ld %f %f %d\n",
- rbuf[i].name,rbuf[i].longi,rbuf[i].pressure,rbuf[i].temperature,rbuf[i].lati);
- fprintf(stderr,"%s %ld %f %f %d\n",
- wbuf[j].name,wbuf[j].longi,wbuf[j].pressure,wbuf[j].temperature,wbuf[j].lati);
- return -1;
- }
- return 0;
+ if ( ( strcmp( rbuf[i].name, wbuf[j].name ) != 0 ) ||
+ rbuf[i].lati != wbuf[j].lati ||
+ rbuf[i].longi != wbuf[j].longi ||
+ rbuf[i].pressure != wbuf[j].pressure ||
+ rbuf[i].temperature != wbuf[j].temperature ) {
+ fprintf(stderr,"read and write buffers have differences\n");
+ fprintf(stderr,"%s %ld %f %f %d\n",
+ rbuf[i].name,rbuf[i].longi,rbuf[i].pressure,rbuf[i].temperature,rbuf[i].lati);
+ fprintf(stderr,"%s %ld %f %f %d\n",
+ wbuf[j].name,wbuf[j].longi,wbuf[j].pressure,wbuf[j].temperature,wbuf[j].lati);
+ return -1;
+ }
+ return 0;
}
/*-------------------------------------------------------------------------
@@ -1608,21 +1646,21 @@ static int cmp_par(hsize_t i, hsize_t j, particle_t *rbuf, particle_t *wbuf )
static int compare_deleted(hsize_t rrecords, hsize_t dstart, hsize_t drecords,
particle_t *rbuf, particle_t *wbuf)
{
- hsize_t i,j;
- for( i=0; i<rrecords; i++)
- {
- if (i<dstart)
- {
- if (cmp_par(i,i,rbuf,wbuf)<0)
- return -1;
- }
- else
- {
- j=i+drecords;
- if (cmp_par(i,j,rbuf,wbuf)<0)
- return -1;
- }
- }
- return 0;
+ hsize_t i,j;
+ for( i=0; i<rrecords; i++)
+ {
+ if (i<dstart)
+ {
+ if (cmp_par(i,i,rbuf,wbuf)<0)
+ return -1;
+ }
+ else
+ {
+ j=i+drecords;
+ if (cmp_par(i,j,rbuf,wbuf)<0)
+ return -1;
+ }
+ }
+ return 0;
}