summaryrefslogtreecommitdiffstats
path: root/hl/src
diff options
context:
space:
mode:
Diffstat (limited to 'hl/src')
-rwxr-xr-xhl/src/COPYING2
-rw-r--r--hl/src/H5DS.c3980
-rw-r--r--hl/src/H5IM.c1932
-rw-r--r--hl/src/H5LT.c3362
-rw-r--r--hl/src/H5LTanalyze.c20
-rw-r--r--hl/src/H5LTparse.c32
-rw-r--r--hl/src/H5LTparse.y27
-rw-r--r--hl/src/H5LTpublic.h4
-rw-r--r--hl/src/H5PT.c23
-rw-r--r--hl/src/H5TB.c6557
-rw-r--r--hl/src/H5TBprivate.h1
-rw-r--r--hl/src/H5TBpublic.h20
-rw-r--r--hl/src/Makefile.am6
-rw-r--r--hl/src/Makefile.in221
14 files changed, 8223 insertions, 7964 deletions
diff --git a/hl/src/COPYING b/hl/src/COPYING
index ef0cbaf..6903daf 100755
--- a/hl/src/COPYING
+++ b/hl/src/COPYING
@@ -1,5 +1,5 @@
- Copyright by The HDF Group (THG) and
+ Copyright by The HDF Group and
The Board of Trustees of the University of Illinois.
All rights reserved.
diff --git a/hl/src/H5DS.c b/hl/src/H5DS.c
index 08345c6..e15c132 100644
--- a/hl/src/H5DS.c
+++ b/hl/src/H5DS.c
@@ -1,17 +1,17 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- * Copyright by The HDF Group. *
- * Copyright by the Board of Trustees of the University of Illinois. *
- * All rights reserved. *
- * *
- * This file is part of HDF5. The full HDF5 copyright notice, including *
- * terms governing use, modification, and redistribution, is contained in *
- * the files COPYING and Copyright.html. COPYING can be found at the root *
- * of the source code distribution tree; Copyright.html can be found at the *
- * root level of an installed copy of the electronic HDF5 document set and *
- * is linked from the top-level documents page. It can also be found at *
- * http://hdfgroup.org/HDF5/doc/Copyright.html. If you do not have *
- * access to either file, you may request a copy from help@hdfgroup.org. *
- * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
+* Copyright by The HDF Group. *
+* Copyright by the Board of Trustees of the University of Illinois. *
+* All rights reserved. *
+* *
+* This file is part of HDF5. The full HDF5 copyright notice, including *
+* terms governing use, modification, and redistribution, is contained in *
+* the files COPYING and Copyright.html. COPYING can be found at the root *
+* of the source code distribution tree; Copyright.html can be found at the *
+* root level of an installed copy of the electronic HDF5 document set and *
+* is linked from the top-level documents page. It can also be found at *
+* http://hdfgroup.org/HDF5/doc/Copyright.html. If you do not have *
+* access to either file, you may request a copy from help@hdfgroup.org. *
+* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#include <assert.h>
#include <stdlib.h>
@@ -24,2043 +24,2249 @@
/*-------------------------------------------------------------------------
- * Function: H5DSset_scale
- *
- * Purpose: The dataset DSID is converted to a Dimension Scale dataset.
- * Creates the CLASS attribute, set to the value "DIMENSION_SCALE"
- * and an empty REFERENCE_LIST attribute.
- * If DIMNAME is specified, then an attribute called NAME is created,
- * with the value DIMNAME.
- *
- * Return: Success: SUCCEED, Failure: FAIL
- *
- * Programmer: pvn@ncsa.uiuc.edu
- *
- * Date: January 04, 2005
- *
- * Comments:
- *
- * Modifications:
- *
- *-------------------------------------------------------------------------
- */
+* Function: H5DSset_scale
+*
+* Purpose: The dataset DSID is converted to a Dimension Scale dataset.
+* Creates the CLASS attribute, set to the value "DIMENSION_SCALE"
+* and an empty REFERENCE_LIST attribute.
+* If DIMNAME is specified, then an attribute called NAME is created,
+* with the value DIMNAME.
+*
+* Return: Success: SUCCEED, Failure: FAIL
+*
+* Programmer: pvn@ncsa.uiuc.edu
+*
+* Date: January 04, 2005
+*
+* Comments:
+*
+* Modifications:
+*
+*-------------------------------------------------------------------------
+*/
herr_t H5DSset_scale(hid_t dsid,
const char *dimname)
{
- int has_dimlist;
- H5I_type_t it;
+ int has_dimlist;
+ H5I_type_t it;
-/*-------------------------------------------------------------------------
- * parameter checking
- *-------------------------------------------------------------------------
- */
- /* get ID type */
- if ((it = H5Iget_type(dsid)) < 0)
- return FAIL;
+ /*-------------------------------------------------------------------------
+ * parameter checking
+ *-------------------------------------------------------------------------
+ */
+ /* get ID type */
+ if ((it = H5Iget_type(dsid)) < 0)
+ return FAIL;
- if (H5I_DATASET!=it)
- return FAIL;
+ if (H5I_DATASET!=it)
+ return FAIL;
-/*-------------------------------------------------------------------------
- * check if the dataset is a dataset wich has references to dimension scales
- *-------------------------------------------------------------------------
- */
+ /*-------------------------------------------------------------------------
+ * check if the dataset is a dataset wich has references to dimension scales
+ *-------------------------------------------------------------------------
+ */
- /* try to find the attribute "DIMENSION_LIST" */
- if ((has_dimlist = H5LT_find_attribute(dsid,DIMENSION_LIST)) < 0)
- return FAIL;
+ /* try to find the attribute "DIMENSION_LIST" */
+ if ((has_dimlist = H5LT_find_attribute(dsid,DIMENSION_LIST)) < 0)
+ return FAIL;
- if (has_dimlist == 1)
- return FAIL;
+ if (has_dimlist == 1)
+ return FAIL;
-/*-------------------------------------------------------------------------
- * write the standard attributes for a Dimension Scale dataset
- *-------------------------------------------------------------------------
- */
+ /*-------------------------------------------------------------------------
+ * write the standard attributes for a Dimension Scale dataset
+ *-------------------------------------------------------------------------
+ */
- if (H5LT_set_attribute_string(dsid,"CLASS",DIMENSION_SCALE_CLASS) < 0)
- return FAIL;
+ if (H5LT_set_attribute_string(dsid,"CLASS",DIMENSION_SCALE_CLASS) < 0)
+ return FAIL;
- if (dimname!=NULL)
- {
- if (H5LT_set_attribute_string(dsid,"NAME",dimname) < 0)
- return FAIL;
- }
+ if (dimname!=NULL)
+ {
+ if (H5LT_set_attribute_string(dsid,"NAME",dimname) < 0)
+ return FAIL;
+ }
- return SUCCEED;
+ return SUCCEED;
}
/*-------------------------------------------------------------------------
- * Function: H5DSattach_scale
- *
- * Purpose: Define Dimension Scale DSID to be associated with dimension IDX
- * of Dataset DID. Entries are created in the DIMENSION_LIST and
- * REFERENCE_LIST attributes.
- *
- * Return:
- * Success: SUCCEED
- * Failure: FAIL
- *
- * Fails if: Bad arguments
- * If DSID is not a Dimension Scale
- * If DID is a Dimension Scale (A Dimension Scale cannot have scales)
- *
- * Programmer: pvn@ncsa.uiuc.edu
- *
- * Date: December 20, 2004
- *
- * Comments:
- *
- * Modifications:
- *
- *-------------------------------------------------------------------------
- */
+* Function: H5DSattach_scale
+*
+* Purpose: Define Dimension Scale DSID to be associated with dimension IDX
+* of Dataset DID. Entries are created in the DIMENSION_LIST and
+* REFERENCE_LIST attributes.
+*
+* Return:
+* Success: SUCCEED
+* Failure: FAIL
+*
+* Fails if: Bad arguments
+* If DSID is not a Dimension Scale
+* If DID is a Dimension Scale (A Dimension Scale cannot have scales)
+*
+* Programmer: pvn@ncsa.uiuc.edu
+*
+* Date: December 20, 2004
+*
+* Comments:
+*
+* Modifications:
+*
+*-------------------------------------------------------------------------
+*/
herr_t H5DSattach_scale(hid_t did,
hid_t dsid,
unsigned int idx)
{
- int has_dimlist;
- int has_reflist;
- int is_ds;
- hssize_t nelmts;
- hid_t sid; /* space ID */
- hid_t tid = -1; /* attribute type ID */
- hid_t aid = -1; /* attribute ID */
- int rank; /* rank of dataset */
- hsize_t *dims; /* dimension of the "REFERENCE_LIST" array */
- ds_list_t dsl; /* attribute data in the DS pointing to the dataset */
- ds_list_t *dsbuf; /* array of attribute data in the DS pointing to the dataset */
- hobj_ref_t ref_to_ds; /* reference to the DS */
- hobj_ref_t ref_j; /* iterator reference */
- hvl_t *buf; /* VL buffer to store in the attribute */
- hid_t dsid_j; /* DS dataset ID in DIMENSION_LIST */
- H5O_info_t oi1, oi2;
- H5I_type_t it1, it2;
- int i, len;
- int found_ds=0;
-
-/*-------------------------------------------------------------------------
- * parameter checking
- *-------------------------------------------------------------------------
- */
- /* the dataset cannot be a DS dataset */
- if ((H5DSis_scale(did))==1)
- return FAIL;
-
- /* get info for the dataset in the parameter list */
- if(H5Oget_info(did, &oi1) < 0)
- return FAIL;
-
- /* get info for the scale in the parameter list */
- if(H5Oget_info(dsid, &oi2) < 0)
- return FAIL;
-
- /* same object, not valid */
- if(oi1.fileno == oi2.fileno && oi1.addr == oi2.addr)
- return FAIL;
-
- /* get ID type */
- if ((it1 = H5Iget_type(did)) < 0)
- return FAIL;
- if ((it2 = H5Iget_type(dsid)) < 0)
- return FAIL;
-
- if (H5I_DATASET!=it1 || H5I_DATASET!=it2)
- return FAIL;
-
- /* the DS dataset cannot have dimension scales */
- if (H5LT_find_attribute(dsid,DIMENSION_LIST)==1)
- return FAIL;
-
- /* check if the dataset is a "reserved" dataset (image, table) */
- if (H5DS_is_reserved(did)==1)
- return FAIL;
-
-
-/*-------------------------------------------------------------------------
- * The dataset may or may not have the associated DS attribute
- * First we try to open to see if it is already there; if not, it is created.
- * If it exists, the array of references is extended to hold the reference
- * to the new DS
- *-------------------------------------------------------------------------
- */
-
- /* get dataset space */
- if ((sid = H5Dget_space(did)) < 0)
- return FAIL;
-
- /* get rank */
- if ((rank=H5Sget_simple_extent_ndims(sid)) < 0)
- goto out;
-
- /* scalar rank */
- if (rank==0)
- rank=1;
-
- /* close dataset space */
- if (H5Sclose(sid) < 0)
- return FAIL;
-
- /* parameter range checking */
- if (idx>(unsigned)rank-1)
- return FAIL;
-
-/*-------------------------------------------------------------------------
- * two references are created: one to the DS, saved in "DIMENSION_LIST"
- * and one to the dataset, saved in "REFERENCE_LIST"
- *-------------------------------------------------------------------------
- */
- /* create a reference for the >>DS<< dataset */
- if (H5Rcreate(&ref_to_ds,dsid,".",H5R_OBJECT,-1) < 0)
- return FAIL;
-
- /* create a reference for the >>data<< dataset */
- if (H5Rcreate(&dsl.ref,did,".",H5R_OBJECT,-1) < 0)
- return FAIL;
-
- /* try to find the attribute "DIMENSION_LIST" on the >>data<< dataset */
- if ((has_dimlist = H5LT_find_attribute(did,DIMENSION_LIST)) < 0)
- return FAIL;
-
-/*-------------------------------------------------------------------------
- * it does not exist. we create the attribute and its reference data
- *-------------------------------------------------------------------------
- */
- if (has_dimlist == 0)
- {
- /* create one entry array */
- dims = (hsize_t*) malloc (1 * sizeof (hsize_t));
-
- if(dims == NULL)
- return FAIL;
-
- dims[0] = rank;
-
- /* space for the attribute */
- if((sid = H5Screate_simple(1, dims, NULL)) < 0)
- return FAIL;
-
- /* create the type for the attribute "DIMENSION_LIST" */
- if((tid = H5Tvlen_create(H5T_STD_REF_OBJ)) < 0)
- goto out;
-
- /* create the attribute */
- if((aid = H5Acreate2(did, DIMENSION_LIST, tid, sid, H5P_DEFAULT, H5P_DEFAULT)) < 0)
- goto out;
-
- /* allocate and initialize the VL */
- buf = (hvl_t*)malloc((size_t)rank * sizeof(hvl_t));
-
- if(buf == NULL)
- goto out;
-
- for(i = 0; i < rank; i++) {
- buf[i].len = 0;
- buf[i].p = NULL;
- }
-
- /* store the REF information in the index of the dataset that has the DS */
- buf[idx].len = 1;
- buf[idx].p = malloc( 1 * sizeof(hobj_ref_t));
- ((hobj_ref_t *)buf[idx].p)[0] = ref_to_ds;
-
- /* write the attribute with the reference */
- if (H5Awrite(aid,tid,buf) < 0)
- goto out;
-
- /* close */
- if (H5Dvlen_reclaim(tid,sid,H5P_DEFAULT,buf) < 0)
- goto out;
- if (H5Sclose(sid) < 0)
- goto out;
- if (H5Tclose(tid) < 0)
- goto out;
- if (H5Aclose(aid) < 0)
- goto out;
-
- if (dims)
- free(dims);
- if (buf)
- free(buf);
-
- }
-
-/*-------------------------------------------------------------------------
- * the attribute already exists, open it, extend the buffer,
- * and insert the new reference
- *-------------------------------------------------------------------------
- */
-
- else if ( has_dimlist == 1 )
- {
- if((aid = H5Aopen(did, DIMENSION_LIST, H5P_DEFAULT)) < 0)
- goto out;
-
- if((tid = H5Aget_type(aid)) < 0)
- goto out;
-
- if((sid = H5Aget_space(aid)) < 0)
- goto out;
-
- /* allocate and initialize the VL */
- buf = (hvl_t*)malloc((size_t)rank * sizeof(hvl_t));
-
- if(buf == NULL)
- goto out;
-
- /* read */
- if(H5Aread(aid, tid, buf) < 0)
- goto out;
-
- /* check to avoid inserting duplicates. it is not FAIL, just do nothing */
- /* iterate all the REFs in this dimension IDX */
- for (i=0; i<(int)buf[idx].len; i++)
- {
- /* get the reference */
- ref_j = ((hobj_ref_t *)buf[idx].p)[i];
-
- /* get the scale id for this REF */
- if ((dsid_j = H5Rdereference(did,H5R_OBJECT,&ref_j)) < 0)
- goto out;
-
- /* get info for DS in the parameter list */
- if(H5Oget_info(dsid, &oi1) < 0)
- goto out;
-
- /* get info for this DS */
- if(H5Oget_info(dsid_j, &oi2) < 0)
- goto out;
-
- /* same object, so this DS scale is already in this DIM IDX */
- if(oi1.fileno == oi2.fileno && oi1.addr == oi2.addr)
- found_ds = 1;
-
- /* close the dereferenced dataset */
- if (H5Dclose(dsid_j) < 0)
- goto out;
- }
-
- if (found_ds==0)
- {
- /* we are adding one more DS to this dimension */
- if ( buf[idx].len > 0 )
- {
- buf[idx].len++;
- len = buf[idx].len;
- buf[idx].p = realloc( buf[idx].p, len * sizeof(hobj_ref_t));
- ((hobj_ref_t *)buf[idx].p)[ len-1 ] = ref_to_ds;
- }
- else
- {
- /* store the REF information in the index of the dataset that has the DS */
- buf[idx].len = 1;
- buf[idx].p = malloc( 1 * sizeof(hobj_ref_t));
- ((hobj_ref_t *)buf[idx].p)[0] = ref_to_ds;
- }
- }
-
- /* write the attribute with the new references */
- if (H5Awrite(aid,tid,buf) < 0)
- goto out;
-
- /* close */
- if (H5Dvlen_reclaim(tid,sid,H5P_DEFAULT,buf) < 0)
- goto out;
- if (H5Sclose(sid) < 0)
- goto out;
- if (H5Tclose(tid) < 0)
- goto out;
- if (H5Aclose(aid) < 0)
- goto out;
- if (buf)
- free(buf);
-
- } /* has_dimlist */
-
-/*-------------------------------------------------------------------------
- * save DS info on the >>DS<< dataset
- *-------------------------------------------------------------------------
- */
-
- /* try to find the attribute "REFERENCE_LIST" on the >>DS<< dataset */
- if ((has_reflist = H5LT_find_attribute(dsid,REFERENCE_LIST)) < 0)
- goto out;
-
-/*-------------------------------------------------------------------------
- * it does not exist. we create the attribute and its reference data
- *-------------------------------------------------------------------------
- */
- if (has_reflist == 0)
- {
- /* create one entry array */
- dims = (hsize_t*) malloc (1 * sizeof (hsize_t));
-
- if (dims == NULL)
- goto out;
-
- dims[0] = 1;
-
- /* space for the attribute */
- if ((sid = H5Screate_simple(1,dims,NULL)) < 0)
- goto out;
-
- /* create the compound datatype for the attribute "REFERENCE_LIST" */
- if((tid = H5Tcreate(H5T_COMPOUND, sizeof(ds_list_t))) < 0)
- goto out;
-
- /* insert reference field */
- if(H5Tinsert(tid, "dataset", HOFFSET(ds_list_t,ref), H5T_STD_REF_OBJ) < 0)
- goto out;
-
- /* insert dimension idx of the dataset field */
- if(H5Tinsert(tid, "dimension", HOFFSET(ds_list_t, dim_idx), H5T_NATIVE_INT) < 0)
- goto out;
-
- /* create the attribute */
- if((aid = H5Acreate2(dsid, REFERENCE_LIST, tid, sid, H5P_DEFAULT, H5P_DEFAULT)) < 0)
- goto out;
-
- /* store the IDX information */
- dsl.dim_idx = idx;
-
- /* write the attribute with the reference */
- if(H5Awrite(aid, tid, &dsl) < 0)
- goto out;
-
- /* close */
- if(H5Sclose(sid) < 0)
- goto out;
- if(H5Tclose(tid) < 0)
- goto out;
- if(H5Aclose(aid) < 0)
- goto out;
-
- if(dims)
- free(dims);
- }
-
-/*-------------------------------------------------------------------------
- * the "REFERENCE_LIST" array already exists, open it and extend it
- *-------------------------------------------------------------------------
- */
-
- else if(has_reflist == 1)
- {
- if((aid = H5Aopen(dsid, REFERENCE_LIST, H5P_DEFAULT)) < 0)
- goto out;
-
- if((tid = H5Aget_type(aid)) < 0)
- goto out;
-
- /* get and save the old reference(s) */
- if((sid = H5Aget_space(aid)) < 0)
- goto out;
-
- if((nelmts = H5Sget_simple_extent_npoints(sid)) < 0)
- goto out;
-
- nelmts++;
-
- dsbuf = malloc((size_t)nelmts * sizeof(ds_list_t));
-
- if (dsbuf == NULL)
- goto out;
-
- if (H5Aread(aid,tid,dsbuf) < 0)
- goto out;
-
- /* close */
- if (H5Sclose(sid) < 0)
- goto out;
- if (H5Aclose(aid) < 0)
- goto out;
-
-/*-------------------------------------------------------------------------
- * create a new attribute
- *-------------------------------------------------------------------------
- */
-
- /* the attribute must be deleted, in order to the new one can reflect the changes*/
- if(H5Adelete(dsid, REFERENCE_LIST) < 0)
- goto out;
-
- /* store the IDX information (index of the dataset that has the DS) */
- dsl.dim_idx = idx;
- dsbuf[nelmts-1] = dsl;
-
- /* create a new data space for the new references array */
- dims = (hsize_t *)malloc((size_t)nelmts * sizeof(hsize_t));
- if(dims == NULL)
- goto out;
- dims[0] = nelmts;
-
- if((sid = H5Screate_simple(1, dims, NULL)) < 0)
- goto out;
-
- if(dims)
- free(dims);
-
- /* create the attribute again with the changes of space */
- if((aid = H5Acreate2(dsid, REFERENCE_LIST, tid, sid, H5P_DEFAULT, H5P_DEFAULT)) < 0)
- goto out;
+ int has_dimlist;
+ int has_reflist;
+ int is_ds;
+ hssize_t nelmts;
+ hid_t sid; /* space ID */
+ hid_t tid = -1; /* attribute type ID */
+ hid_t ntid = -1; /* attribute native type ID */
+ hid_t aid = -1; /* attribute ID */
+ int rank; /* rank of dataset */
+ hsize_t *dims=NULL; /* dimension of the "REFERENCE_LIST" array */
+ ds_list_t dsl; /* attribute data in the DS pointing to the dataset */
+ ds_list_t *dsbuf=NULL; /* array of attribute data in the DS pointing to the dataset */
+ hobj_ref_t ref_to_ds; /* reference to the DS */
+ hobj_ref_t ref_j; /* iterator reference */
+ hvl_t *buf=NULL; /* VL buffer to store in the attribute */
+ hid_t dsid_j; /* DS dataset ID in DIMENSION_LIST */
+ H5O_info_t oi1, oi2;
+ H5I_type_t it1, it2;
+ int i, len;
+ int found_ds=0;
+ htri_t is_scale;
+
+ /*-------------------------------------------------------------------------
+ * parameter checking
+ *-------------------------------------------------------------------------
+ */
+
+ if ((is_scale = H5DSis_scale(did)) < 0)
+ return FAIL;
+
+ /* the dataset cannot be a DS dataset */
+ if ( is_scale == 1)
+ return FAIL;
+
+ /* get info for the dataset in the parameter list */
+ if(H5Oget_info(did, &oi1) < 0)
+ return FAIL;
+
+ /* get info for the scale in the parameter list */
+ if(H5Oget_info(dsid, &oi2) < 0)
+ return FAIL;
+
+ /* same object, not valid */
+ if(oi1.fileno == oi2.fileno && oi1.addr == oi2.addr)
+ return FAIL;
+
+ /* get ID type */
+ if ((it1 = H5Iget_type(did)) < 0)
+ return FAIL;
+ if ((it2 = H5Iget_type(dsid)) < 0)
+ return FAIL;
+
+ if (H5I_DATASET!=it1 || H5I_DATASET!=it2)
+ return FAIL;
+
+ /* the DS dataset cannot have dimension scales */
+ if (H5LT_find_attribute(dsid,DIMENSION_LIST)==1)
+ return FAIL;
+
+ /* check if the dataset is a "reserved" dataset (image, table) */
+ if (H5DS_is_reserved(did)==1)
+ return FAIL;
+
+
+ /*-------------------------------------------------------------------------
+ * The dataset may or may not have the associated DS attribute
+ * First we try to open to see if it is already there; if not, it is created.
+ * If it exists, the array of references is extended to hold the reference
+ * to the new DS
+ *-------------------------------------------------------------------------
+ */
+
+ /* get dataset space */
+ if ((sid = H5Dget_space(did)) < 0)
+ return FAIL;
+
+ /* get rank */
+ if ((rank=H5Sget_simple_extent_ndims(sid)) < 0)
+ goto out;
+
+ /* scalar rank */
+ if (rank==0)
+ rank=1;
+
+ /* close dataset space */
+ if (H5Sclose(sid) < 0)
+ return FAIL;
+
+ /* parameter range checking */
+ if (idx>(unsigned)rank-1)
+ return FAIL;
+
+ /*-------------------------------------------------------------------------
+ * two references are created: one to the DS, saved in "DIMENSION_LIST"
+ * and one to the dataset, saved in "REFERENCE_LIST"
+ *-------------------------------------------------------------------------
+ */
+ /* create a reference for the >>DS<< dataset */
+ if (H5Rcreate(&ref_to_ds,dsid,".",H5R_OBJECT,-1) < 0)
+ return FAIL;
+
+ /* create a reference for the >>data<< dataset */
+ if (H5Rcreate(&dsl.ref,did,".",H5R_OBJECT,-1) < 0)
+ return FAIL;
+
+ /* try to find the attribute "DIMENSION_LIST" on the >>data<< dataset */
+ if ((has_dimlist = H5LT_find_attribute(did,DIMENSION_LIST)) < 0)
+ return FAIL;
+
+ /*-------------------------------------------------------------------------
+ * it does not exist. we create the attribute and its reference data
+ *-------------------------------------------------------------------------
+ */
+ if (has_dimlist == 0)
+ {
+ /* create one entry array */
+ dims = (hsize_t*) malloc (1 * sizeof (hsize_t));
+
+ if(dims == NULL)
+ return FAIL;
+
+ dims[0] = rank;
+
+ /* space for the attribute */
+ if((sid = H5Screate_simple(1, dims, NULL)) < 0)
+ return FAIL;
+
+ /* create the type for the attribute "DIMENSION_LIST" */
+ if((tid = H5Tvlen_create(H5T_STD_REF_OBJ)) < 0)
+ goto out;
+
+ /* create the attribute */
+ if((aid = H5Acreate2(did, DIMENSION_LIST, tid, sid, H5P_DEFAULT, H5P_DEFAULT)) < 0)
+ goto out;
+
+ /* allocate and initialize the VL */
+ buf = (hvl_t*)malloc((size_t)rank * sizeof(hvl_t));
+
+ if(buf == NULL)
+ goto out;
+
+ for(i = 0; i < rank; i++) {
+ buf[i].len = 0;
+ buf[i].p = NULL;
+ }
+
+ /* store the REF information in the index of the dataset that has the DS */
+ buf[idx].len = 1;
+ buf[idx].p = malloc( 1 * sizeof(hobj_ref_t));
+ ((hobj_ref_t *)buf[idx].p)[0] = ref_to_ds;
+
+ /* write the attribute with the reference */
+ if (H5Awrite(aid,tid,buf) < 0)
+ goto out;
+
+ /* close */
+ if (H5Dvlen_reclaim(tid,sid,H5P_DEFAULT,buf) < 0)
+ goto out;
+ if (H5Sclose(sid) < 0)
+ goto out;
+ if (H5Tclose(tid) < 0)
+ goto out;
+ if (H5Aclose(aid) < 0)
+ goto out;
+
+ if (dims)
+ {
+ free(dims);
+ dims = NULL;
+ }
+ if (buf)
+ {
+ free(buf);
+ buf = NULL;
+ }
- /* write the attribute with the new references */
- if(H5Awrite(aid, tid, dsbuf) < 0)
- goto out;
+ }
- /* close */
- if(H5Sclose(sid) < 0)
- goto out;
- if(H5Tclose(tid) < 0)
- goto out;
- if(H5Aclose(aid) < 0)
- goto out;
+ /*-------------------------------------------------------------------------
+ * the attribute already exists, open it, extend the buffer,
+ * and insert the new reference
+ *-------------------------------------------------------------------------
+ */
- if (dsbuf)
- free(dsbuf);
+ else if ( has_dimlist == 1 )
+ {
+ if((aid = H5Aopen(did, DIMENSION_LIST, H5P_DEFAULT)) < 0)
+ goto out;
+
+ if((tid = H5Aget_type(aid)) < 0)
+ goto out;
+
+ if((sid = H5Aget_space(aid)) < 0)
+ goto out;
+
+ /* allocate and initialize the VL */
+ buf = (hvl_t*)malloc((size_t)rank * sizeof(hvl_t));
+
+ if(buf == NULL)
+ goto out;
+
+ /* read */
+ if(H5Aread(aid, tid, buf) < 0)
+ goto out;
+
+ /* check to avoid inserting duplicates. it is not FAIL, just do nothing */
+ /* iterate all the REFs in this dimension IDX */
+ for (i=0; i<(int)buf[idx].len; i++)
+ {
+ /* get the reference */
+ ref_j = ((hobj_ref_t *)buf[idx].p)[i];
+
+ /* get the scale id for this REF */
+ if ((dsid_j = H5Rdereference(did,H5R_OBJECT,&ref_j)) < 0)
+ goto out;
+
+ /* get info for DS in the parameter list */
+ if(H5Oget_info(dsid, &oi1) < 0)
+ goto out;
+
+ /* get info for this DS */
+ if(H5Oget_info(dsid_j, &oi2) < 0)
+ goto out;
+
+ /* same object, so this DS scale is already in this DIM IDX */
+ if(oi1.fileno == oi2.fileno && oi1.addr == oi2.addr)
+ found_ds = 1;
+
+ /* close the dereferenced dataset */
+ if (H5Dclose(dsid_j) < 0)
+ goto out;
+ }
+
+ if (found_ds==0)
+ {
+ /* we are adding one more DS to this dimension */
+ if ( buf[idx].len > 0 )
+ {
+ buf[idx].len++;
+ len = buf[idx].len;
+ buf[idx].p = realloc( buf[idx].p, len * sizeof(hobj_ref_t));
+ ((hobj_ref_t *)buf[idx].p)[ len-1 ] = ref_to_ds;
+ }
+ else
+ {
+ /* store the REF information in the index of the dataset that has the DS */
+ buf[idx].len = 1;
+ buf[idx].p = malloc( 1 * sizeof(hobj_ref_t));
+ ((hobj_ref_t *)buf[idx].p)[0] = ref_to_ds;
+ }
+ }
+
+ /* write the attribute with the new references */
+ if (H5Awrite(aid,tid,buf) < 0)
+ goto out;
+
+ /* close */
+ if (H5Dvlen_reclaim(tid,sid,H5P_DEFAULT,buf) < 0)
+ goto out;
+ if (H5Sclose(sid) < 0)
+ goto out;
+ if (H5Tclose(tid) < 0)
+ goto out;
+ if (H5Aclose(aid) < 0)
+ goto out;
+ if (buf)
+ {
+ free(buf);
+ buf = NULL;
+ }
+
+ } /* has_dimlist */
+
+ /*-------------------------------------------------------------------------
+ * save DS info on the >>DS<< dataset
+ *-------------------------------------------------------------------------
+ */
+
+ /* try to find the attribute "REFERENCE_LIST" on the >>DS<< dataset */
+ if ((has_reflist = H5LT_find_attribute(dsid,REFERENCE_LIST)) < 0)
+ goto out;
+
+ /*-------------------------------------------------------------------------
+ * it does not exist. we create the attribute and its reference data
+ *-------------------------------------------------------------------------
+ */
+ if (has_reflist == 0)
+ {
+ /* create one entry array */
+ dims = (hsize_t*) malloc (1 * sizeof (hsize_t));
+
+ if (dims == NULL)
+ goto out;
+
+ dims[0] = 1;
+
+ /* space for the attribute */
+ if ((sid = H5Screate_simple(1,dims,NULL)) < 0)
+ goto out;
+
+ /* create the compound datatype for the attribute "REFERENCE_LIST" */
+ if((tid = H5Tcreate(H5T_COMPOUND, sizeof(ds_list_t))) < 0)
+ goto out;
+
+ /* insert reference field */
+ if(H5Tinsert(tid, "dataset", HOFFSET(ds_list_t,ref), H5T_STD_REF_OBJ) < 0)
+ goto out;
+
+ /* insert dimension idx of the dataset field */
+ if(H5Tinsert(tid, "dimension", HOFFSET(ds_list_t, dim_idx), H5T_NATIVE_INT) < 0)
+ goto out;
+
+ /* create the attribute */
+ if((aid = H5Acreate2(dsid, REFERENCE_LIST, tid, sid, H5P_DEFAULT, H5P_DEFAULT)) < 0)
+ goto out;
+
+ /* store the IDX information */
+ dsl.dim_idx = idx;
+
+ /* write the attribute with the reference */
+ if(H5Awrite(aid, tid, &dsl) < 0)
+ goto out;
+
+ /* close */
+ if(H5Sclose(sid) < 0)
+ goto out;
+ if(H5Tclose(tid) < 0)
+ goto out;
+ if(H5Aclose(aid) < 0)
+ goto out;
+
+ if(dims)
+ {
+ free(dims);
+ dims = NULL;
+ }
+ }
- } /* has_reflist */
+ /*-------------------------------------------------------------------------
+ * the "REFERENCE_LIST" array already exists, open it and extend it
+ *-------------------------------------------------------------------------
+ */
-/*-------------------------------------------------------------------------
- * write the standard attributes for a Dimension Scale dataset
- *-------------------------------------------------------------------------
- */
+ else if(has_reflist == 1)
+ {
+ if((aid = H5Aopen(dsid, REFERENCE_LIST, H5P_DEFAULT)) < 0)
+ goto out;
+
+ if((tid = H5Aget_type(aid)) < 0)
+ goto out;
+
+ if((ntid = H5Tget_native_type(tid, H5T_DIR_DEFAULT)) < 0)
+ goto out;
+
+ /* get and save the old reference(s) */
+ if((sid = H5Aget_space(aid)) < 0)
+ goto out;
+
+ if((nelmts = H5Sget_simple_extent_npoints(sid)) < 0)
+ goto out;
+
+ nelmts++;
+
+ dsbuf = (ds_list_t*) malloc((size_t)nelmts * sizeof(ds_list_t));
+
+ if (dsbuf == NULL)
+ goto out;
+
+ if (H5Aread(aid,ntid,dsbuf) < 0)
+ goto out;
+
+ /* close */
+ if (H5Sclose(sid) < 0)
+ goto out;
+ if (H5Aclose(aid) < 0)
+ goto out;
+ if (H5Tclose(ntid) < 0)
+ goto out;
+
+ /*-------------------------------------------------------------------------
+ * create a new attribute
+ *-------------------------------------------------------------------------
+ */
+
+ /* the attribute must be deleted, in order to the new one can reflect the changes*/
+ if(H5Adelete(dsid, REFERENCE_LIST) < 0)
+ goto out;
+
+ /* store the IDX information (index of the dataset that has the DS) */
+ dsl.dim_idx = idx;
+ dsbuf[nelmts-1] = dsl;
+
+ /* create a new data space for the new references array */
+ dims = (hsize_t *)malloc((size_t)nelmts * sizeof(hsize_t));
+ if(dims == NULL)
+ goto out;
+ dims[0] = nelmts;
+
+ if((sid = H5Screate_simple(1, dims, NULL)) < 0)
+ goto out;
+
+ if (dims)
+ {
+ free(dims);
+ dims = NULL;
+ }
+
+ /* create the attribute again with the changes of space */
+ if((aid = H5Acreate2(dsid, REFERENCE_LIST, tid, sid, H5P_DEFAULT, H5P_DEFAULT)) < 0)
+ goto out;
+
+ /* write the attribute with the new references */
+ if(H5Awrite(aid, tid, dsbuf) < 0)
+ goto out;
+
+ /* close */
+ if(H5Sclose(sid) < 0)
+ goto out;
+ if(H5Tclose(tid) < 0)
+ goto out;
+ if(H5Aclose(aid) < 0)
+ goto out;
+
+ if (dsbuf)
+ {
+ free(dsbuf);
+ dsbuf = NULL;
+ }
+
+ } /* has_reflist */
+
+ /*-------------------------------------------------------------------------
+ * write the standard attributes for a Dimension Scale dataset
+ *-------------------------------------------------------------------------
+ */
+
+ if ((is_ds=H5DSis_scale(dsid)) < 0)
+ return FAIL;
+
+ if (is_ds == 0 )
+ {
+ if (H5LT_set_attribute_string(dsid,"CLASS",DIMENSION_SCALE_CLASS) < 0)
+ return FAIL;
+ }
- if ((is_ds=H5DSis_scale(dsid)) < 0)
- return FAIL;
+ return SUCCEED;
- if (is_ds == 0 )
- {
- if (H5LT_set_attribute_string(dsid,"CLASS",DIMENSION_SCALE_CLASS) < 0)
- return FAIL;
- }
+ /* error zone */
+out:
- return SUCCEED;
+ if (dims)
+ {
+ free(dims);
+ dims = NULL;
+ }
+ if (buf)
+ {
+ free(buf);
+ buf = NULL;
+ }
+ if (dsbuf)
+ {
+ free(dsbuf);
+ dsbuf = NULL;
+ }
-/* error zone, gracefully close */
-out:
- H5E_BEGIN_TRY {
- H5Sclose(sid);
- H5Aclose(aid);
- H5Tclose(tid);
- } H5E_END_TRY;
- return FAIL;
+ H5E_BEGIN_TRY {
+ H5Sclose(sid);
+ H5Aclose(aid);
+ H5Tclose(ntid);
+ H5Tclose(tid);
+ } H5E_END_TRY;
+ return FAIL;
}
/*-------------------------------------------------------------------------
- * Function: H5DSdetach_scale
- *
- * Purpose: If possible, deletes association of Dimension Scale DSID with
- * dimension IDX of Dataset DID. This deletes the entries in the
- * DIMENSION_LIST and REFERENCE_LIST attributes.
- *
- * Return:
- * Success: SUCCEED
- * Failure: FAIL
- *
- * Fails if: Bad arguments
- * The dataset DID or DSID do not exist.
- * The DSID is not a Dimension Scale
- * DSID is not attached to DID.
- * Note that a scale may be associated with more than dimension of the same dataset.
- * If so, the detach operation only deletes one of the associations, for DID.
- *
- * Programmer: pvn@ncsa.uiuc.edu
- *
- * Date: December 20, 2004
- *
- * Comments:
- *
- * Modifications:
- *
- *-------------------------------------------------------------------------
- */
+* Function: H5DSdetach_scale
+*
+* Purpose: If possible, deletes association of Dimension Scale DSID with
+* dimension IDX of Dataset DID. This deletes the entries in the
+* DIMENSION_LIST and REFERENCE_LIST attributes.
+*
+* Return:
+* Success: SUCCEED
+* Failure: FAIL
+*
+* Fails if: Bad arguments
+* The dataset DID or DSID do not exist.
+* The DSID is not a Dimension Scale
+* DSID is not attached to DID.
+* Note that a scale may be associated with more than dimension of the same dataset.
+* If so, the detach operation only deletes one of the associations, for DID.
+*
+* Programmer: pvn@ncsa.uiuc.edu
+*
+* Date: December 20, 2004
+*
+* Comments:
+*
+* Modifications:
+*
+*-------------------------------------------------------------------------
+*/
herr_t H5DSdetach_scale(hid_t did,
hid_t dsid,
unsigned int idx)
{
- int has_dimlist;
- int has_reflist;
- hssize_t nelmts;
- hid_t dsid_j; /* DS dataset ID in DIMENSION_LIST */
+ int has_dimlist;
+ int has_reflist;
+ hssize_t nelmts;
+ hid_t dsid_j; /* DS dataset ID in DIMENSION_LIST */
hid_t did_i; /* dataset ID in REFERENCE_LIST */
- hid_t sid; /* space ID */
- hid_t tid = -1; /* attribute type ID */
- hid_t aid = -1; /* attribute ID */
- int rank; /* rank of dataset */
- ds_list_t *dsbuf = NULL; /* array of attribute data in the DS pointing to the dataset */
- ds_list_t *dsbufn = NULL; /* array of attribute data in the DS pointing to the dataset */
- hsize_t *dims = NULL; /* dimension of the "REFERENCE_LIST" array */
- hobj_ref_t ref; /* reference to the DS */
- hvl_t *buf = NULL; /* VL buffer to store in the attribute */
- unsigned i, j, jj;
- H5O_info_t oi1, oi2, oi3, oi4;
- int found_dset = 0, found_ds = 0;
- H5I_type_t it1, it2;
-
-/*-------------------------------------------------------------------------
- * parameter checking
- *-------------------------------------------------------------------------
- */
- /* the dataset cannot be a DS dataset */
- if ((H5DSis_scale(did))==1)
- return FAIL;
-
- /* get info for the dataset in the parameter list */
- if(H5Oget_info(did, &oi1) < 0)
- return FAIL;
-
- /* get info for the scale in the parameter list */
- if(H5Oget_info(dsid, &oi2) < 0)
- return FAIL;
-
- /* same object, not valid */
- if(oi1.fileno == oi2.fileno && oi1.addr == oi2.addr)
- return FAIL;
-
- /* get ID type */
- if ((it1 = H5Iget_type(did)) < 0)
- return FAIL;
- if ((it2 = H5Iget_type(dsid)) < 0)
- return FAIL;
-
- if (H5I_DATASET!=it1 || H5I_DATASET!=it2)
- return FAIL;
-
-
-/*-------------------------------------------------------------------------
- * Find "DIMENSION_LIST"
- *-------------------------------------------------------------------------
- */
- /* try to find the attribute "DIMENSION_LIST" on the >>data<< dataset */
- if ((has_dimlist = H5LT_find_attribute(did,DIMENSION_LIST)) < 0)
- return FAIL;
-
- if (has_dimlist == 0)
- return FAIL;
-
- /* get dataset space */
- if ((sid = H5Dget_space(did)) < 0)
- return FAIL;
-
- /* get rank */
- if ((rank=H5Sget_simple_extent_ndims(sid)) < 0)
- goto out;
-
- /* close dataset space */
- if (H5Sclose(sid) < 0)
- return FAIL;
-
-
-/*-------------------------------------------------------------------------
- * find "REFERENCE_LIST"
- *-------------------------------------------------------------------------
- */
-
- /* try to find the attribute "REFERENCE_LIST" on the >>DS<< dataset */
- if((has_reflist = H5LT_find_attribute(dsid, REFERENCE_LIST)) < 0)
- return FAIL;
-
- if(has_reflist == 0)
- return FAIL;
-
-/*-------------------------------------------------------------------------
- * open "DIMENSION_LIST", and delete the reference
- *-------------------------------------------------------------------------
- */
-
- if((aid = H5Aopen(did, DIMENSION_LIST, H5P_DEFAULT)) < 0)
- return FAIL;
-
- if((tid = H5Aget_type(aid)) < 0)
- goto out;
-
- if((sid = H5Aget_space(aid)) < 0)
- goto out;
-
- /* allocate and initialize the VL */
- buf = (hvl_t*)malloc((size_t)rank * sizeof(hvl_t));
-
- if(buf == NULL)
- goto out;
-
- /* read */
- if (H5Aread(aid,tid,buf) < 0)
- goto out;
-
- /* reset */
- if ( buf[idx].len > 0 )
- {
- for (j=0; j<buf[idx].len; j++)
- {
- /* get the reference */
- ref = ((hobj_ref_t *)buf[idx].p)[j];
-
- /* get the DS id */
- if ((dsid_j = H5Rdereference(did,H5R_OBJECT,&ref)) < 0)
- goto out;
-
- /* get info for DS in the parameter list */
- if(H5Oget_info(dsid, &oi1) < 0)
- goto out;
-
- /* get info for this DS */
- if(H5Oget_info(dsid_j, &oi2) < 0)
- goto out;
-
- /* same object, reset */
- if(oi1.fileno == oi2.fileno && oi1.addr == oi2.addr) {
- for(jj=j; jj<buf[idx].len-1; jj++)
- ((hobj_ref_t *)buf[idx].p)[jj] = ((hobj_ref_t *)buf[idx].p)[jj+1];
- buf[idx].len--;
-
- found_ds = 1;
-
- /* close the dereferenced dataset and break */
- if (H5Dclose(dsid_j) < 0)
- goto out;
- break;
- }
-
- /* close the dereferenced dataset */
- if (H5Dclose(dsid_j) < 0)
- goto out;
- } /* j */
- } /* if */
-
- /* write the attribute */
- if (H5Awrite(aid,tid,buf) < 0)
- goto out;
-
- /* close */
- if (H5Dvlen_reclaim(tid,sid,H5P_DEFAULT,buf) < 0)
- goto out;
- if (H5Sclose(sid) < 0)
- goto out;
- if (H5Tclose(tid) < 0)
- goto out;
- if(H5Aclose(aid) < 0)
- goto out;
- if(buf)
- free(buf);
-
- /* the scale must be present */
- if(found_ds == 0)
- goto out;
-
-/*-------------------------------------------------------------------------
- * the "REFERENCE_LIST" array exists, update
- *-------------------------------------------------------------------------
- */
-
- if((aid = H5Aopen(dsid, REFERENCE_LIST, H5P_DEFAULT)) < 0)
- goto out;
-
- if((tid = H5Aget_type(aid)) < 0)
- goto out;
-
- /* get and save the old reference(s) */
- if((sid = H5Aget_space(aid)) < 0)
- goto out;
-
- if((nelmts = H5Sget_simple_extent_npoints(sid)) < 0)
- goto out;
-
- dsbuf = malloc((size_t)nelmts * sizeof(ds_list_t));
- if(dsbuf == NULL)
- goto out;
-
- if (H5Aread(aid,tid,dsbuf) < 0)
- goto out;
+ hid_t sid; /* space ID */
+ hid_t tid = -1; /* attribute type ID */
+ hid_t ntid = -1; /* attribute native type ID */
+ hid_t aid = -1; /* attribute ID */
+ int rank; /* rank of dataset */
+ ds_list_t *dsbuf = NULL; /* array of attribute data in the DS pointing to the dataset */
+ ds_list_t *dsbufn = NULL; /* array of attribute data in the DS pointing to the dataset */
+ hsize_t *dims = NULL; /* dimension of the "REFERENCE_LIST" array */
+ hobj_ref_t ref; /* reference to the DS */
+ hvl_t *buf = NULL; /* VL buffer to store in the attribute */
+ unsigned i, j, jj;
+ H5O_info_t oi1, oi2, oi3, oi4;
+ int found_dset = 0, found_ds = 0;
+ H5I_type_t it1, it2;
+ htri_t is_scale;
+
+ /*-------------------------------------------------------------------------
+ * parameter checking
+ *-------------------------------------------------------------------------
+ */
+
+ if ((is_scale = H5DSis_scale(did)) < 0)
+ return FAIL;
+
+ /* the dataset cannot be a DS dataset */
+ if ( is_scale == 1)
+ return FAIL;
+
+ /* get info for the dataset in the parameter list */
+ if(H5Oget_info(did, &oi1) < 0)
+ return FAIL;
+
+ /* get info for the scale in the parameter list */
+ if(H5Oget_info(dsid, &oi2) < 0)
+ return FAIL;
+
+ /* same object, not valid */
+ if(oi1.fileno == oi2.fileno && oi1.addr == oi2.addr)
+ return FAIL;
+
+ /* get ID type */
+ if ((it1 = H5Iget_type(did)) < 0)
+ return FAIL;
+ if ((it2 = H5Iget_type(dsid)) < 0)
+ return FAIL;
+
+ if (H5I_DATASET!=it1 || H5I_DATASET!=it2)
+ return FAIL;
+
+
+ /*-------------------------------------------------------------------------
+ * Find "DIMENSION_LIST"
+ *-------------------------------------------------------------------------
+ */
+ /* try to find the attribute "DIMENSION_LIST" on the >>data<< dataset */
+ if ((has_dimlist = H5LT_find_attribute(did,DIMENSION_LIST)) < 0)
+ return FAIL;
+
+ if (has_dimlist == 0)
+ return FAIL;
+
+ /* get dataset space */
+ if ((sid = H5Dget_space(did)) < 0)
+ return FAIL;
+
+ /* get rank */
+ if ((rank=H5Sget_simple_extent_ndims(sid)) < 0)
+ goto out;
+
+ /* close dataset space */
+ if (H5Sclose(sid) < 0)
+ return FAIL;
+
+ /* parameter range checking */
+ if (idx>(unsigned)rank-1)
+ return FAIL;
+
+ /*-------------------------------------------------------------------------
+ * find "REFERENCE_LIST"
+ *-------------------------------------------------------------------------
+ */
+
+ /* try to find the attribute "REFERENCE_LIST" on the >>DS<< dataset */
+ if((has_reflist = H5LT_find_attribute(dsid, REFERENCE_LIST)) < 0)
+ return FAIL;
+
+ if(has_reflist == 0)
+ return FAIL;
+
+ /*-------------------------------------------------------------------------
+ * open "DIMENSION_LIST", and delete the reference
+ *-------------------------------------------------------------------------
+ */
+
+ if((aid = H5Aopen(did, DIMENSION_LIST, H5P_DEFAULT)) < 0)
+ return FAIL;
+
+ if((tid = H5Aget_type(aid)) < 0)
+ goto out;
+
+ if((sid = H5Aget_space(aid)) < 0)
+ goto out;
+
+ /* allocate and initialize the VL */
+ buf = (hvl_t*)malloc((size_t)rank * sizeof(hvl_t));
+
+ if(buf == NULL)
+ goto out;
+
+ /* read */
+ if (H5Aread(aid,tid,buf) < 0)
+ goto out;
+
+ /* reset */
+ if ( buf[idx].len > 0 )
+ {
+ for (j=0; j<buf[idx].len; j++)
+ {
+ /* get the reference */
+ ref = ((hobj_ref_t *)buf[idx].p)[j];
+
+ /* get the DS id */
+ if ((dsid_j = H5Rdereference(did,H5R_OBJECT,&ref)) < 0)
+ goto out;
+
+ /* get info for DS in the parameter list */
+ if(H5Oget_info(dsid, &oi1) < 0)
+ goto out;
+
+ /* get info for this DS */
+ if(H5Oget_info(dsid_j, &oi2) < 0)
+ goto out;
+
+ /* same object, reset */
+ if(oi1.fileno == oi2.fileno && oi1.addr == oi2.addr)
+ {
+ size_t len;
+
+ for(jj=j; jj<buf[idx].len-1; jj++)
+ {
+ ((hobj_ref_t *)buf[idx].p)[jj] = ((hobj_ref_t *)buf[idx].p)[jj+1];
+ }
+
+ buf[idx].len--;
+ len = buf[idx].len;
+ buf[idx].p = realloc( buf[idx].p, len * sizeof(hobj_ref_t));
+
+ found_ds = 1;
+
+ /* close the dereferenced dataset and break */
+ if (H5Dclose(dsid_j) < 0)
+ goto out;
+ break;
+ }
+
+ /* close the dereferenced dataset */
+ if (H5Dclose(dsid_j) < 0)
+ goto out;
+ } /* j */
+ } /* if */
+
+ /* write the attribute */
+ if (H5Awrite(aid,tid,buf) < 0)
+ goto out;
+
+ /* close */
+ if (H5Dvlen_reclaim(tid,sid,H5P_DEFAULT,buf) < 0)
+ goto out;
+ if (H5Sclose(sid) < 0)
+ goto out;
+ if (H5Tclose(tid) < 0)
+ goto out;
+ if (H5Aclose(aid) < 0)
+ goto out;
+
+ if (buf)
+ {
+ free(buf);
+ buf = NULL;
+ }
- for(i=0; i<nelmts; i++)
- {
- /* get the reference to the dataset */
- ref = dsbuf[i].ref;
+ /* the scale must be present */
+ if(found_ds == 0)
+ goto out;
- /* get the dataset id */
- if ((did_i = H5Rdereference(did,H5R_OBJECT,&ref)) < 0)
- goto out;
+ /*-------------------------------------------------------------------------
+ * the "REFERENCE_LIST" array exists, update
+ *-------------------------------------------------------------------------
+ */
- /* get info for dataset in the parameter list */
- if(H5Oget_info(did, &oi3) < 0)
- goto out;
+ if((aid = H5Aopen(dsid, REFERENCE_LIST, H5P_DEFAULT)) < 0)
+ goto out;
- /* get info for this dataset */
- if(H5Oget_info(did_i, &oi4) < 0)
- goto out;
+ if((tid = H5Aget_type(aid)) < 0)
+ goto out;
+
+ if((ntid = H5Tget_native_type(tid, H5T_DIR_DEFAULT)) < 0)
+ goto out;
- /* same object, reset. we want to detach only for this DIM */
- if(oi3.fileno == oi4.fileno && oi3.addr == oi4.addr && (int)idx == dsbuf[i].dim_idx) {
- for(jj=i; jj<nelmts-1; jj++)
- dsbuf[jj] = dsbuf[jj+1];
- nelmts--;
- found_dset=1;
+ /* get and save the old reference(s) */
+ if((sid = H5Aget_space(aid)) < 0)
+ goto out;
- /* close the dereferenced dataset and break */
- if (H5Dclose(did_i) < 0)
- goto out;
- break;
- } /* if */
+ if((nelmts = H5Sget_simple_extent_npoints(sid)) < 0)
+ goto out;
- /* close the dereferenced dataset */
- if (H5Dclose(did_i) < 0)
- goto out;
+ dsbuf = (ds_list_t*) malloc((size_t)nelmts * sizeof(ds_list_t));
+ if(dsbuf == NULL)
+ goto out;
- } /* i */
+ if (H5Aread(aid,ntid,dsbuf) < 0)
+ goto out;
- /* close space and attribute */
- if (H5Sclose(sid) < 0)
- goto out;
- if (H5Aclose(aid) < 0)
- goto out;
+ for(i=0; i<nelmts; i++)
+ {
+ /* get the reference to the dataset */
+ ref = dsbuf[i].ref;
+
+ /* get the dataset id */
+ if ((did_i = H5Rdereference(did,H5R_OBJECT,&ref)) < 0)
+ goto out;
+
+ /* get info for dataset in the parameter list */
+ if(H5Oget_info(did, &oi3) < 0)
+ goto out;
+
+ /* get info for this dataset */
+ if(H5Oget_info(did_i, &oi4) < 0)
+ goto out;
+
+ /* same object, reset. we want to detach only for this DIM */
+ if(oi3.fileno == oi4.fileno && oi3.addr == oi4.addr && (int)idx == dsbuf[i].dim_idx) {
+ for(jj=i; jj<nelmts-1; jj++)
+ dsbuf[jj] = dsbuf[jj+1];
+ nelmts--;
+ found_dset=1;
+
+ /* close the dereferenced dataset and break */
+ if (H5Dclose(did_i) < 0)
+ goto out;
+ break;
+ } /* if */
+
+ /* close the dereferenced dataset */
+ if (H5Dclose(did_i) < 0)
+ goto out;
+
+ } /* i */
+
+ /* close space and attribute */
+ if (H5Sclose(sid) < 0)
+ goto out;
+ if (H5Aclose(aid) < 0)
+ goto out;
+ if (H5Tclose(ntid) < 0)
+ goto out;
+
+ /*-------------------------------------------------------------------------
+ * check if we found the pointed dataset
+ *-------------------------------------------------------------------------
+ */
+
+ /* the pointed dataset must exist */
+ if (found_dset == 0)
+ goto out;
+
+ /*-------------------------------------------------------------------------
+ * create a new attribute
+ *-------------------------------------------------------------------------
+ */
+
+ /* the attribute must be deleted, in order to the new one can reflect the changes*/
+ if (H5Adelete(dsid, REFERENCE_LIST) < 0)
+ goto out;
+
+ /* don't do anything for an empty array */
+ if(nelmts)
+ {
+ /* create a new data space for the new references array */
+ dims = (hsize_t*)malloc((size_t)nelmts * sizeof (hsize_t));
+ if(dims == NULL)
+ goto out;
+ dims[0] = nelmts;
+
+ dsbufn = (ds_list_t*) malloc((size_t)nelmts * sizeof(ds_list_t));
+ if(dsbufn == NULL)
+ goto out;
+
+ /* store the new information */
+ for(i = 0; i < nelmts; i++)
+ dsbufn[i] = dsbuf[i];
+
+ if((sid = H5Screate_simple(1, dims, NULL)) < 0)
+ goto out;
+
+ /* create the attribute again with the changes of space */
+ if((aid = H5Acreate2(dsid, REFERENCE_LIST, tid, sid, H5P_DEFAULT, H5P_DEFAULT)) < 0)
+ goto out;
+
+ /* write the new attribute with the new references */
+ if(H5Awrite(aid, tid, dsbufn) < 0)
+ goto out;
+
+ /* close space and attribute */
+ if(H5Sclose(sid) < 0)
+ goto out;
+ if(H5Aclose(aid) < 0)
+ goto out;
+ } /* nelmts */
+
+ /* close type */
+ if (H5Tclose(tid) < 0)
+ goto out;
+
+ if (dsbuf)
+ {
+ free(dsbuf);
+ dsbuf=NULL;
+ }
+ if (dsbufn)
+ {
+ free(dsbufn);
+ dsbufn=NULL;
+ }
+ if (dims)
+ {
+ free(dims);
+ dims=NULL;
+ }
-/*-------------------------------------------------------------------------
- * check if we found the pointed dataset
- *-------------------------------------------------------------------------
- */
- /* the pointed dataset must exist */
- if (found_dset == 0)
- goto out;
+ return SUCCEED;
-/*-------------------------------------------------------------------------
- * create a new attribute
- *-------------------------------------------------------------------------
- */
-
- /* the attribute must be deleted, in order to the new one can reflect the changes*/
- if(H5Adelete(dsid, REFERENCE_LIST) < 0)
- goto out;
-
- /* don't do anything for an empty array */
- if(nelmts)
- {
- /* create a new data space for the new references array */
- dims = (hsize_t*)malloc((size_t)nelmts * sizeof (hsize_t));
- if(dims == NULL)
- goto out;
- dims[0] = nelmts;
-
- dsbufn = malloc((size_t)nelmts * sizeof(ds_list_t));
- if(dsbufn == NULL)
- goto out;
-
- /* store the new information */
- for(i = 0; i < nelmts; i++)
- dsbufn[i] = dsbuf[i];
-
- if((sid = H5Screate_simple(1, dims, NULL)) < 0)
- goto out;
-
- /* create the attribute again with the changes of space */
- if((aid = H5Acreate2(dsid, REFERENCE_LIST, tid, sid, H5P_DEFAULT, H5P_DEFAULT)) < 0)
- goto out;
-
- /* write the new attribute with the new references */
- if(H5Awrite(aid, tid, dsbufn) < 0)
- goto out;
-
- /* close space and attribute */
- if(H5Sclose(sid) < 0)
- goto out;
- if(H5Aclose(aid) < 0)
- goto out;
- } /* nelmts */
-
- /* close type */
- if (H5Tclose(tid) < 0)
- goto out;
-
- if (dsbuf) {
- free(dsbuf);
- dsbuf=NULL;
- }
- if (dsbufn) {
- free(dsbufn);
- dsbufn=NULL;
- }
- if (dims) {
- free(dims);
- dims=NULL;
- }
-
-
- return SUCCEED;
-
-/* error zone, gracefully close */
+ /* error zone */
out:
- H5E_BEGIN_TRY {
- H5Sclose(sid);
- H5Aclose(aid);
- H5Tclose(tid);
- if (dsbuf)
- free(dsbuf);
- if (dsbufn)
- free(dsbufn);
- if (dims)
- free(dims);
- } H5E_END_TRY;
- return FAIL;
+ H5E_BEGIN_TRY {
+ H5Sclose(sid);
+ H5Aclose(aid);
+ H5Tclose(ntid);
+ H5Tclose(tid);
+
+ if (dsbuf)
+ {
+ free(dsbuf);
+ dsbuf=NULL;
+ }
+ if (dsbufn)
+ {
+ free(dsbufn);
+ dsbufn=NULL;
+ }
+ if (dims)
+ {
+ free(dims);
+ dims=NULL;
+ }
+ if (buf)
+ {
+ free(buf);
+ buf=NULL;
+ }
+ } H5E_END_TRY;
+ return FAIL;
}
/*-------------------------------------------------------------------------
- * Function: H5DSis_attached
- *
- * Purpose: Report if dimension scale DSID is currently attached to
- * dimension IDX of dataset DID by checking if DID has a pointer in the REFERENCE_LIST
- * attribute and DSID (scale ) has a pointer in the DIMENSION_LIST attribute
- *
- * Return:
- * 1: both the DS and the dataset pointers match
- * 0: one of them or both do not match
- * FAIL (-1): error
- *
- * Fails if: Bad arguments
- * If DSID is not a Dimension Scale
- * If DID is a Dimension Scale (A Dimension Scale cannot have scales)
- *
- * Programmer: pvn@ncsa.uiuc.edu
- *
- * Date: February 18, 2005
- *
- * Comments:
- *
- * Modifications:
- *
- *-------------------------------------------------------------------------
- */
+* Function: H5DSis_attached
+*
+* Purpose: Report if dimension scale DSID is currently attached to
+* dimension IDX of dataset DID by checking if DID has a pointer in the REFERENCE_LIST
+* attribute and DSID (scale ) has a pointer in the DIMENSION_LIST attribute
+*
+* Return:
+* 1: both the DS and the dataset pointers match
+* 0: one of them or both do not match
+* FAIL (-1): error
+*
+* Fails if: Bad arguments
+* If DSID is not a Dimension Scale
+* If DID is a Dimension Scale (A Dimension Scale cannot have scales)
+*
+* Programmer: pvn@ncsa.uiuc.edu
+*
+* Date: February 18, 2005
+*
+* Comments:
+*
+* Modifications:
+*
+*-------------------------------------------------------------------------
+*/
htri_t H5DSis_attached(hid_t did,
hid_t dsid,
unsigned int idx)
{
- int has_dimlist;
- int has_reflist;
- hssize_t nelmts;
- hid_t sid; /* space ID */
- hid_t tid = -1; /* attribute type ID */
- hid_t aid = -1; /* attribute ID */
- int rank; /* rank of dataset */
- ds_list_t *dsbuf; /* array of attribute data in the DS pointing to the dataset */
- hobj_ref_t ref; /* reference to the DS */
- hvl_t *buf; /* VL buffer to store in the attribute */
- hid_t dsid_j; /* DS dataset ID in DIMENSION_LIST */
+ int has_dimlist;
+ int has_reflist;
+ hssize_t nelmts;
+ hid_t sid; /* space ID */
+ hid_t tid = -1; /* attribute type ID */
+ hid_t ntid = -1; /* attribute native type ID */
+ hid_t aid = -1; /* attribute ID */
+ int rank; /* rank of dataset */
+ ds_list_t *dsbuf; /* array of attribute data in the DS pointing to the dataset */
+ hobj_ref_t ref; /* reference to the DS */
+ hvl_t *buf; /* VL buffer to store in the attribute */
+ hid_t dsid_j; /* DS dataset ID in DIMENSION_LIST */
hid_t did_i; /* dataset ID in REFERENCE_LIST */
- H5O_info_t oi1, oi2, oi3, oi4;
- H5I_type_t it1, it2;
- int i;
- int found_dset=0, found_ds=0;
-
-/*-------------------------------------------------------------------------
- * parameter checking
- *-------------------------------------------------------------------------
- */
- /* the dataset cannot be a DS dataset */
- if ((H5DSis_scale(did))==1)
- return FAIL;
-
- /* get info for the dataset in the parameter list */
- if(H5Oget_info(did, &oi1) < 0)
- return FAIL;
-
- /* get info for the scale in the parameter list */
- if(H5Oget_info(dsid, &oi2) < 0)
- return FAIL;
-
- /* same object, not valid */
- if(oi1.fileno == oi2.fileno && oi1.addr == oi2.addr)
- return FAIL;
-
- /* get ID type */
- if ((it1 = H5Iget_type(did)) < 0)
- return FAIL;
- if ((it2 = H5Iget_type(dsid)) < 0)
- return FAIL;
-
- if (H5I_DATASET!=it1 || H5I_DATASET!=it2)
- return FAIL;
-
-/*-------------------------------------------------------------------------
- * get space
- *-------------------------------------------------------------------------
- */
-
- /* get dataset space */
- if ((sid = H5Dget_space(did)) < 0)
- return FAIL;
-
- /* get rank */
- if ((rank=H5Sget_simple_extent_ndims(sid)) < 0)
- goto out;
-
- /* close dataset space */
- if (H5Sclose(sid) < 0)
- goto out;
-
- /* parameter range checking */
- if(idx > ((unsigned)rank - 1))
- goto out;
-
- /* try to find the attribute "DIMENSION_LIST" on the >>data<< dataset */
- if((has_dimlist = H5LT_find_attribute(did, DIMENSION_LIST)) < 0)
- return FAIL;
-
-/*-------------------------------------------------------------------------
- * open "DIMENSION_LIST"
- *-------------------------------------------------------------------------
- */
-
- if(has_dimlist == 1)
- {
- if((aid = H5Aopen(did, DIMENSION_LIST, H5P_DEFAULT)) < 0)
- goto out;
-
- if((tid = H5Aget_type(aid)) < 0)
- goto out;
-
- if((sid = H5Aget_space(aid)) < 0)
- goto out;
-
- /* allocate and initialize the VL */
- buf = (hvl_t*)malloc((size_t)rank * sizeof(hvl_t));
-
- if(buf == NULL)
- goto out;
-
- /* read */
- if (H5Aread(aid,tid,buf) < 0)
- goto out;
-
- /* iterate all the REFs in this dimension IDX */
- for (i=0; i<(int)buf[idx].len; i++)
- {
- /* get the reference */
- ref = ((hobj_ref_t *)buf[idx].p)[i];
-
- /* get the scale id for this REF */
- if ((dsid_j = H5Rdereference(did,H5R_OBJECT,&ref)) < 0)
- goto out;
-
- /* get info for DS in the parameter list */
- if(H5Oget_info(dsid, &oi1) < 0)
- goto out;
-
- /* get info for this DS */
- if(H5Oget_info(dsid_j, &oi2) < 0)
- goto out;
-
- /* same object */
- if(oi1.fileno == oi2.fileno && oi1.addr == oi2.addr)
- found_ds = 1;
-
- /* close the dereferenced dataset */
- if (H5Dclose(dsid_j) < 0)
- goto out;
-
- }
-
-
- /* close */
- if (H5Dvlen_reclaim(tid,sid,H5P_DEFAULT,buf) < 0)
- goto out;
- if (H5Sclose(sid) < 0)
- goto out;
- if (H5Tclose(tid) < 0)
- goto out;
- if (H5Aclose(aid) < 0)
- goto out;
- if (buf)
- free(buf);
- } /* has_dimlist */
-
-/*-------------------------------------------------------------------------
- * info on the >>DS<< dataset
- *-------------------------------------------------------------------------
- */
-
- /* try to find the attribute "REFERENCE_LIST" on the >>DS<< dataset */
- if((has_reflist = H5LT_find_attribute(dsid, REFERENCE_LIST)) < 0)
- goto out;
-
-/*-------------------------------------------------------------------------
- * open "REFERENCE_LIST"
- *-------------------------------------------------------------------------
- */
-
- if(has_reflist == 1)
- {
- if((aid = H5Aopen(dsid, REFERENCE_LIST, H5P_DEFAULT)) < 0)
- goto out;
-
- if((tid = H5Aget_type(aid)) < 0)
- goto out;
-
- /* get and save the old reference(s) */
- if((sid = H5Aget_space(aid)) < 0)
- goto out;
-
- if((nelmts = H5Sget_simple_extent_npoints(sid)) < 0)
- goto out;
-
- dsbuf = malloc((size_t)nelmts * sizeof(ds_list_t));
-
- if (dsbuf == NULL)
- goto out;
-
- if (H5Aread(aid,tid,dsbuf) < 0)
- goto out;
-
-/*-------------------------------------------------------------------------
- * iterate
- *-------------------------------------------------------------------------
- */
-
- for(i=0; i<nelmts; i++)
- {
- /* get the reference */
- ref = dsbuf[i].ref;
-
- /* the reference was not deleted */
- if (ref)
- {
- /* get the dataset id */
- if ((did_i = H5Rdereference(did,H5R_OBJECT,&ref)) < 0)
- goto out;
-
- /* get info for dataset in the parameter list */
- if(H5Oget_info(did, &oi3) < 0)
- goto out;
-
- /* get info for this dataset */
- if(H5Oget_info(did_i, &oi4) < 0)
- goto out;
-
- /* same object */
- if(oi3.fileno == oi4.fileno && oi3.addr == oi4.addr && (int)idx==dsbuf[i].dim_idx)
- found_dset=1;
-
- /* close the dereferenced dataset */
- if (H5Dclose(did_i) < 0)
- goto out;
- } /* if */
- } /* i */
-
-
- /* close */
- if (H5Sclose(sid) < 0)
- goto out;
- if (H5Tclose(tid) < 0)
- goto out;
- if (H5Aclose(aid) < 0)
- goto out;
- if (dsbuf)
- free(dsbuf);
- } /* has_reflist */
-
- if (found_ds && found_dset)
- return 1;
- else
- return 0;
-
-/* error zone, gracefully close */
+ H5O_info_t oi1, oi2, oi3, oi4;
+ H5I_type_t it1, it2;
+ int i;
+ int found_dset=0, found_ds=0;
+ htri_t is_scale;
+
+ /*-------------------------------------------------------------------------
+ * parameter checking
+ *-------------------------------------------------------------------------
+ */
+
+ if ((is_scale = H5DSis_scale(did)) < 0)
+ return FAIL;
+
+ /* the dataset cannot be a DS dataset */
+ if ( is_scale == 1)
+ return FAIL;
+
+ /* get info for the dataset in the parameter list */
+ if(H5Oget_info(did, &oi1) < 0)
+ return FAIL;
+
+ /* get info for the scale in the parameter list */
+ if(H5Oget_info(dsid, &oi2) < 0)
+ return FAIL;
+
+ /* same object, not valid */
+ if(oi1.fileno == oi2.fileno && oi1.addr == oi2.addr)
+ return FAIL;
+
+ /* get ID type */
+ if ((it1 = H5Iget_type(did)) < 0)
+ return FAIL;
+ if ((it2 = H5Iget_type(dsid)) < 0)
+ return FAIL;
+
+ if (H5I_DATASET!=it1 || H5I_DATASET!=it2)
+ return FAIL;
+
+ /*-------------------------------------------------------------------------
+ * get space
+ *-------------------------------------------------------------------------
+ */
+
+ /* get dataset space */
+ if ((sid = H5Dget_space(did)) < 0)
+ return FAIL;
+
+ /* get rank */
+ if ((rank=H5Sget_simple_extent_ndims(sid)) < 0)
+ goto out;
+
+ /* close dataset space */
+ if (H5Sclose(sid) < 0)
+ goto out;
+
+ /* parameter range checking */
+ if(idx > ((unsigned)rank - 1))
+ return FAIL;
+
+ /* try to find the attribute "DIMENSION_LIST" on the >>data<< dataset */
+ if((has_dimlist = H5LT_find_attribute(did, DIMENSION_LIST)) < 0)
+ return FAIL;
+
+ /*-------------------------------------------------------------------------
+ * open "DIMENSION_LIST"
+ *-------------------------------------------------------------------------
+ */
+
+ if(has_dimlist == 1)
+ {
+ if((aid = H5Aopen(did, DIMENSION_LIST, H5P_DEFAULT)) < 0)
+ goto out;
+
+ if((tid = H5Aget_type(aid)) < 0)
+ goto out;
+
+ if((sid = H5Aget_space(aid)) < 0)
+ goto out;
+
+ /* allocate and initialize the VL */
+ buf = (hvl_t*)malloc((size_t)rank * sizeof(hvl_t));
+
+ if(buf == NULL)
+ goto out;
+
+ /* read */
+ if (H5Aread(aid,tid,buf) < 0)
+ goto out;
+
+ /* iterate all the REFs in this dimension IDX */
+ for (i=0; i<(int)buf[idx].len; i++)
+ {
+ /* get the reference */
+ ref = ((hobj_ref_t *)buf[idx].p)[i];
+
+ /* get the scale id for this REF */
+ if ((dsid_j = H5Rdereference(did,H5R_OBJECT,&ref)) < 0)
+ goto out;
+
+ /* get info for DS in the parameter list */
+ if(H5Oget_info(dsid, &oi1) < 0)
+ goto out;
+
+ /* get info for this DS */
+ if(H5Oget_info(dsid_j, &oi2) < 0)
+ goto out;
+
+ /* same object */
+ if(oi1.fileno == oi2.fileno && oi1.addr == oi2.addr)
+ found_ds = 1;
+
+ /* close the dereferenced dataset */
+ if (H5Dclose(dsid_j) < 0)
+ goto out;
+
+ }
+
+
+ /* close */
+ if (H5Dvlen_reclaim(tid,sid,H5P_DEFAULT,buf) < 0)
+ goto out;
+ if (H5Sclose(sid) < 0)
+ goto out;
+ if (H5Tclose(tid) < 0)
+ goto out;
+ if (H5Aclose(aid) < 0)
+ goto out;
+ if (buf)
+ {
+ free(buf);
+ buf = NULL;
+ }
+ } /* has_dimlist */
+
+ /*-------------------------------------------------------------------------
+ * info on the >>DS<< dataset
+ *-------------------------------------------------------------------------
+ */
+
+ /* try to find the attribute "REFERENCE_LIST" on the >>DS<< dataset */
+ if((has_reflist = H5LT_find_attribute(dsid, REFERENCE_LIST)) < 0)
+ goto out;
+
+ /*-------------------------------------------------------------------------
+ * open "REFERENCE_LIST"
+ *-------------------------------------------------------------------------
+ */
+
+ if(has_reflist == 1)
+ {
+ if((aid = H5Aopen(dsid, REFERENCE_LIST, H5P_DEFAULT)) < 0)
+ goto out;
+
+ if((tid = H5Aget_type(aid)) < 0)
+ goto out;
+
+ if((ntid = H5Tget_native_type(tid, H5T_DIR_DEFAULT)) < 0)
+ goto out;
+
+ /* get and save the old reference(s) */
+ if((sid = H5Aget_space(aid)) < 0)
+ goto out;
+
+ if((nelmts = H5Sget_simple_extent_npoints(sid)) < 0)
+ goto out;
+
+ dsbuf = (ds_list_t*) malloc((size_t)nelmts * sizeof(ds_list_t));
+
+ if (dsbuf == NULL)
+ goto out;
+
+ if (H5Aread(aid,ntid,dsbuf) < 0)
+ goto out;
+
+ /*-------------------------------------------------------------------------
+ * iterate
+ *-------------------------------------------------------------------------
+ */
+
+ for(i=0; i<nelmts; i++)
+ {
+ /* get the reference */
+ ref = dsbuf[i].ref;
+
+ /* the reference was not deleted */
+ if (ref)
+ {
+ /* get the dataset id */
+ if ((did_i = H5Rdereference(did,H5R_OBJECT,&ref)) < 0)
+ goto out;
+
+ /* get info for dataset in the parameter list */
+ if(H5Oget_info(did, &oi3) < 0)
+ goto out;
+
+ /* get info for this dataset */
+ if(H5Oget_info(did_i, &oi4) < 0)
+ goto out;
+
+ /* same object */
+ if(oi3.fileno == oi4.fileno && oi3.addr == oi4.addr && (int)idx==dsbuf[i].dim_idx)
+ found_dset=1;
+
+ /* close the dereferenced dataset */
+ if (H5Dclose(did_i) < 0)
+ goto out;
+ } /* if */
+ } /* i */
+
+
+ /* close */
+ if (H5Sclose(sid) < 0)
+ goto out;
+ if (H5Tclose(ntid) < 0)
+ goto out;
+ if (H5Tclose(tid) < 0)
+ goto out;
+ if (H5Aclose(aid) < 0)
+ goto out;
+ if (dsbuf)
+ {
+ free(dsbuf);
+ dsbuf = NULL;
+ }
+ } /* has_reflist */
+
+ if (found_ds && found_dset)
+ return 1;
+ else
+ return 0;
+
+ /* error zone */
out:
- H5E_BEGIN_TRY {
- H5Sclose(sid);
- H5Aclose(aid);
- H5Tclose(tid);
- } H5E_END_TRY;
- return FAIL;
+ H5E_BEGIN_TRY {
+ H5Sclose(sid);
+ H5Aclose(aid);
+ H5Tclose(tid);
+ } H5E_END_TRY;
+
+ if (buf)
+ {
+ free(buf);
+ buf = NULL;
+ }
+ if (dsbuf)
+ {
+ free(dsbuf);
+ dsbuf = NULL;
+ }
+ return FAIL;
}
/*-------------------------------------------------------------------------
- * Function: H5DSiterate_scales
- *
- * Purpose: H5DSiterate_scales iterates over the scales attached to dimension DIM
- * of dataset DID. For each scale in the list, the visitor_data and some
- * additional information, specified below, are passed to the visitor function.
- * The iteration begins with the IDX object in the group and the next element
- * to be processed by the operator is returned in IDX. If IDX is NULL, then the
- * iterator starts at zero.
- *
- * Parameters:
- *
- * hid_t DID; IN: the dataset
- * unsigned int dim; IN: the dimension of the dataset
- * int *idx; IN/OUT: input the index to start iterating, output the
- * next index to visit. If NULL, start at the first position.
- * H5DS_iterate_t visitor; IN: the visitor function
- * void *visitor_data; IN: arbitrary data to pass to the visitor function.
- *
- * Iterate over all scales of DIM, calling an application callback
- * with the item, key and any operator data.
- *
- * The operator callback receives a pointer to the item ,
- * and the pointer to the operator data passed
- * in to H5SL_iterate ('op_data'). The return values from an operator are:
- * A. Zero causes the iterator to continue, returning zero when all
- * nodes of that type have been processed.
- * B. Positive causes the iterator to immediately return that positive
- * value, indicating short-circuit success.
- * C. Negative causes the iterator to immediately return that value,
- * indicating failure.
- *
- * Programmer: pvn@ncsa.uiuc.edu
- *
- * Date: January 31, 2005
- *
- * Comments:
- *
- * Modifications:
- *
- *-------------------------------------------------------------------------
- */
+* Function: H5DSiterate_scales
+*
+* Purpose: H5DSiterate_scales iterates over the scales attached to dimension DIM
+* of dataset DID. For each scale in the list, the visitor_data and some
+* additional information, specified below, are passed to the visitor function.
+* The iteration begins with the IDX object in the group and the next element
+* to be processed by the operator is returned in IDX. If IDX is NULL, then the
+* iterator starts at zero.
+*
+* Parameters:
+*
+* hid_t DID; IN: the dataset
+* unsigned int DIM; IN: the dimension of the dataset
+* int *DS_IDX; IN/OUT: on input the dimension scale index to start iterating,
+* on output the next index to visit. If NULL, start at
+* the first position.
+* H5DS_iterate_t VISITOR; IN: the visitor function
+* void *VISITOR_DATA; IN: arbitrary data to pass to the visitor function.
+*
+* Iterate over all scales of DIM, calling an application callback
+* with the item, key and any operator data.
+*
+* The operator callback receives a pointer to the item ,
+* and the pointer to the operator data passed
+* in to H5SL_iterate ('op_data'). The return values from an operator are:
+* A. Zero causes the iterator to continue, returning zero when all
+* nodes of that type have been processed.
+* B. Positive causes the iterator to immediately return that positive
+* value, indicating short-circuit success.
+* C. Negative causes the iterator to immediately return that value,
+* indicating failure.
+*
+* Programmer: pvn@ncsa.uiuc.edu
+*
+* Date: January 31, 2005
+*
+* Comments:
+*
+* Modifications:
+*
+*-------------------------------------------------------------------------
+*/
herr_t H5DSiterate_scales(hid_t did,
unsigned int dim,
- int *idx,
+ int *ds_idx,
H5DS_iterate_t visitor,
void *visitor_data )
{
- hid_t scale_id;
- int rank;
- hobj_ref_t ref; /* reference to the DS */
- hid_t sid; /* space ID */
- hid_t tid = -1; /* attribute type ID */
- hid_t aid = -1; /* attribute ID */
- hvl_t *buf=NULL; /* VL buffer to store in the attribute */
- H5I_type_t it; /* ID type */
- herr_t ret_value=0;
- int j_idx;
- int nscales;
- int has_dimlist;
- int i;
-
-/*-------------------------------------------------------------------------
- * parameter checking
- *-------------------------------------------------------------------------
- */
- /* get ID type */
- if ((it = H5Iget_type(did)) < 0)
- return FAIL;
-
- if (H5I_DATASET!=it)
- return FAIL;
-
- /* get the number of scales assotiated with this DIM */
- if ((nscales = H5DSget_num_scales(did,dim)) < 0)
- return FAIL;
-
- /* get dataset space */
- if ((sid = H5Dget_space(did)) < 0)
- return FAIL;
-
- /* get rank */
- if ((rank=H5Sget_simple_extent_ndims(sid)) < 0)
- goto out;
-
- /* close dataset space */
- if(H5Sclose(sid) < 0)
- goto out;
-
- /* try to find the attribute "DIMENSION_LIST" on the >>data<< dataset */
- if((has_dimlist = H5LT_find_attribute(did, DIMENSION_LIST)) < 0)
- return FAIL;
-
- if(has_dimlist == 0)
- return SUCCEED;
-
- else if(has_dimlist == 1)
- {
- if((aid = H5Aopen(did, DIMENSION_LIST, H5P_DEFAULT)) < 0)
- goto out;
- if((tid = H5Aget_type(aid)) < 0)
- goto out;
- if((sid = H5Aget_space(aid)) < 0)
- goto out;
-
- /* allocate and initialize the VL */
- buf = (hvl_t*)malloc((size_t)rank * sizeof(hvl_t));
-
- if(buf == NULL)
- goto out;
-
- /* read */
- if(H5Aread(aid, tid, buf) < 0)
- goto out;
-
- if ( buf[dim].len > 0 )
- {
- if (idx!=NULL)
- j_idx = *idx;
- else
- j_idx=0;
-
- /* iterate */
- for(i=j_idx; i<nscales; i++)
- {
- /* get the reference */
- ref = ((hobj_ref_t *)buf[dim].p)[ i ];
-
- /* disable error reporting, the ID might refer to a deleted dataset */
- H5E_BEGIN_TRY {
- /* get the DS id */
- if ((scale_id = H5Rdereference(did,H5R_OBJECT,&ref)) < 0)
- goto out;
- } H5E_END_TRY;
-
- if((ret_value=(visitor)(did,dim,scale_id,visitor_data))!=0)
+ hid_t scale_id;
+ int rank;
+ hobj_ref_t ref; /* reference to the DS */
+ hid_t sid; /* space ID */
+ hid_t tid = -1; /* attribute type ID */
+ hid_t aid = -1; /* attribute ID */
+ hvl_t *buf=NULL; /* VL buffer to store in the attribute */
+ H5I_type_t it; /* ID type */
+ herr_t ret_value=0;
+ int j_idx;
+ int nscales;
+ int has_dimlist;
+ int i;
+
+ /*-------------------------------------------------------------------------
+ * parameter checking
+ *-------------------------------------------------------------------------
+ */
+ /* get ID type */
+ if ((it = H5Iget_type(did)) < 0)
+ return FAIL;
+
+ if (H5I_DATASET!=it)
+ return FAIL;
+
+ /* get the number of scales assotiated with this DIM */
+ if ((nscales = H5DSget_num_scales(did,dim)) < 0)
+ return FAIL;
+
+ /* parameter range checking */
+ if (ds_idx!=NULL)
{
- /* set the return IDX OUT value at current scale index and break */
- if (idx!=NULL)
- {
- *idx = i;
- }
+ if (*ds_idx>=nscales)
+ return FAIL;
+ }
- /* close the DS id */
- if (H5Dclose(scale_id) < 0)
- goto out;
+ /* get dataset space */
+ if ((sid = H5Dget_space(did)) < 0)
+ return FAIL;
- break;
- }
+ /* get rank */
+ if ((rank=H5Sget_simple_extent_ndims(sid)) < 0)
+ goto out;
- /* close the DS id */
- if (H5Dclose(scale_id) < 0)
- goto out;
+ /* close dataset space */
+ if(H5Sclose(sid) < 0)
+ goto out;
- } /* i */
- } /* if */
+ if ( dim >= (unsigned)rank )
+ return FAIL;
- /* close */
- if (H5Dvlen_reclaim(tid,sid,H5P_DEFAULT,buf) < 0)
- goto out;
- if (H5Sclose(sid) < 0)
- goto out;
- if (H5Tclose(tid) < 0)
- goto out;
- if (H5Aclose(aid) < 0)
- goto out;
- if (buf)
- free(buf);
+ /* try to find the attribute "DIMENSION_LIST" on the >>data<< dataset */
+ if((has_dimlist = H5LT_find_attribute(did, DIMENSION_LIST)) < 0)
+ return FAIL;
- } /* if has_dimlist */
+ if(has_dimlist == 0)
+ return SUCCEED;
- return ret_value;
+ else if(has_dimlist == 1)
+ {
+ if((aid = H5Aopen(did, DIMENSION_LIST, H5P_DEFAULT)) < 0)
+ goto out;
+ if((tid = H5Aget_type(aid)) < 0)
+ goto out;
+ if((sid = H5Aget_space(aid)) < 0)
+ goto out;
+
+ /* allocate and initialize the VL */
+ buf = (hvl_t*)malloc((size_t)rank * sizeof(hvl_t));
+
+ if(buf == NULL)
+ goto out;
+
+ /* read */
+ if(H5Aread(aid, tid, buf) < 0)
+ goto out;
+
+ if ( buf[dim].len > 0 )
+ {
+ if (ds_idx!=NULL)
+ j_idx = *ds_idx;
+ else
+ j_idx=0;
+
+ /* iterate */
+ for(i=j_idx; i<nscales; i++)
+ {
+ /* get the reference */
+ ref = ((hobj_ref_t *)buf[dim].p)[ i ];
+
+ /* disable error reporting, the ID might refer to a deleted dataset */
+ H5E_BEGIN_TRY {
+ /* get the DS id */
+ if ((scale_id = H5Rdereference(did,H5R_OBJECT,&ref)) < 0)
+ goto out;
+ } H5E_END_TRY;
+
+ /* set the return IDX OUT value at current scale index */
+ if (ds_idx!=NULL)
+ {
+ *ds_idx = i;
+ }
+
+ if((ret_value=(visitor)(did,dim,scale_id,visitor_data))!=0)
+ {
+ /* break */
+
+ /* close the DS id */
+ if (H5Dclose(scale_id) < 0)
+ goto out;
+
+ break;
+ }
+
+ /* close the DS id */
+ if (H5Dclose(scale_id) < 0)
+ goto out;
+
+ } /* i */
+ } /* if */
+
+ /* close */
+ if (H5Dvlen_reclaim(tid,sid,H5P_DEFAULT,buf) < 0)
+ goto out;
+ if (H5Sclose(sid) < 0)
+ goto out;
+ if (H5Tclose(tid) < 0)
+ goto out;
+ if (H5Aclose(aid) < 0)
+ goto out;
+ if (buf)
+ {
+ free(buf);
+ buf = NULL;
+ }
+
+ } /* if has_dimlist */
+
+ return ret_value;
out:
- H5E_BEGIN_TRY {
- if (buf)
- {
- H5Dvlen_reclaim(tid,sid,H5P_DEFAULT,buf);
- free(buf);
- }
- H5Sclose(sid);
- H5Aclose(aid);
- H5Tclose(tid);
- } H5E_END_TRY;
- return FAIL;
+ H5E_BEGIN_TRY {
+ if (buf)
+ {
+ H5Dvlen_reclaim(tid,sid,H5P_DEFAULT,buf);
+ free(buf);
+ }
+ H5Sclose(sid);
+ H5Aclose(aid);
+ H5Tclose(tid);
+ } H5E_END_TRY;
+ return FAIL;
}
/*-------------------------------------------------------------------------
- * Function: H5DSset_label
- *
- * Purpose: Set label for the dimension IDX of dataset DID to the value LABEL
- *
- * Return: Success: SUCCEED, Failure: FAIL
- *
- * Programmer: pvn@ncsa.uiuc.edu
- *
- * Date: January 11, 2005
- *
- * Comments:
- *
- * Modifications:
- *
- *-------------------------------------------------------------------------
- */
-
-herr_t H5DSset_label(hid_t did,
- unsigned int idx,
- const char *label)
+* Function: H5DSset_label
+*
+* Purpose: Set label for the dimension IDX of dataset DID to the value LABEL
+*
+* Return: Success: SUCCEED, Failure: FAIL
+*
+* Programmer: pvn@ncsa.uiuc.edu
+*
+* Date: January 11, 2005
+*
+* Comments:
+*
+* Modifications:
+*
+*-------------------------------------------------------------------------
+*/
+
+herr_t H5DSset_label(hid_t did, unsigned int idx, const char *label)
{
- int has_labels;
- hid_t sid; /* space ID */
- hid_t tid = -1; /* attribute type ID */
- hid_t aid = -1; /* attribute ID */
- int rank; /* rank of dataset */
- hsize_t dims[1]; /* dimensions of dataset */
- const char **buf=NULL; /* buffer to store in the attribute */
- H5I_type_t it; /* ID type */
- unsigned int i;
-
-/*-------------------------------------------------------------------------
- * parameter checking
- *-------------------------------------------------------------------------
- */
- /* get ID type */
- if ((it = H5Iget_type(did)) < 0)
- return FAIL;
-
- if (H5I_DATASET!=it)
- return FAIL;
-
-/*-------------------------------------------------------------------------
- * attribute "DIMENSION_LABELS"
- *-------------------------------------------------------------------------
- */
-
- /* try to find the attribute "DIMENSION_LABELS" on the >>data<< dataset */
- if ((has_labels = H5LT_find_attribute(did,DIMENSION_LABELS)) < 0)
- return FAIL;
-
- /* get dataset space */
- if ((sid = H5Dget_space(did)) < 0)
- return FAIL;
-
- /* get rank */
- if ((rank=H5Sget_simple_extent_ndims(sid)) < 0)
- goto out;
-
- /* close dataset space */
- if (H5Sclose(sid) < 0)
- goto out;
-
-/*-------------------------------------------------------------------------
- * make the attribute and insert label
- *-------------------------------------------------------------------------
- */
-
- if (has_labels == 0)
- {
- dims[0] = rank;
-
- /* space for the attribute */
- if((sid = H5Screate_simple(1, dims, NULL)) < 0)
- goto out;
-
- /* create the datatype */
- if((tid = H5Tcopy(H5T_C_S1)) < 0)
- goto out;
- if(H5Tset_size(tid, H5T_VARIABLE) < 0)
- goto out;
-
- /* create the attribute */
- if((aid = H5Acreate2(did, DIMENSION_LABELS, tid, sid, H5P_DEFAULT, H5P_DEFAULT)) < 0)
- goto out;
-
- /* allocate and initialize */
- buf = (const char **)malloc((size_t)rank * sizeof(char *));
-
- if(buf == NULL)
- goto out;
-
- for(i = 0; i < (unsigned int)rank; i++)
- buf[i] = NULL;
-
- /* store the label information in the required index */
- buf[idx] = label;
-
- /* write the attribute with the label */
- if (H5Awrite(aid,tid,buf) < 0)
- goto out;
-
- /* close */
- if (H5Sclose(sid) < 0)
- goto out;
- if(H5Tclose(tid) < 0)
- goto out;
- if(H5Aclose(aid) < 0)
- goto out;
- if(buf)
- free(buf);
- }
-
-/*-------------------------------------------------------------------------
- * just insert label
- *-------------------------------------------------------------------------
- */
-
- else
- {
- if((aid = H5Aopen(did, DIMENSION_LABELS, H5P_DEFAULT)) < 0)
- goto out;
-
- if((tid = H5Aget_type(aid)) < 0)
- goto out;
-
- /* allocate and initialize */
- buf = (const char **)malloc((size_t)rank * sizeof(char *));
-
- if(buf == NULL)
- goto out;
-
- /* read */
- if(H5Aread(aid, tid, buf) < 0)
- goto out;
-
- /* store the label information in the required index */
- buf[idx] = label;
+ int has_labels;
+ hid_t sid = -1; /* space ID */
+ hid_t tid = -1; /* attribute type ID */
+ hid_t aid = -1; /* attribute ID */
+ int rank; /* rank of dataset */
+ hsize_t dims[1]; /* dimensions of dataset */
+ const char **buf = NULL; /* buffer to store in the attribute */
+ H5I_type_t it; /* ID type */
+ unsigned int i;
+
+ /*-------------------------------------------------------------------------
+ * parameter checking
+ *-------------------------------------------------------------------------
+ */
+ /* get ID type */
+ if ((it = H5Iget_type(did)) < 0)
+ return FAIL;
+
+ if (H5I_DATASET != it)
+ return FAIL;
+
+ /* get dataset space */
+ if ((sid = H5Dget_space(did)) < 0)
+ return FAIL;
+
+ /* get rank */
+ if ((rank = H5Sget_simple_extent_ndims(sid)) < 0)
+ goto out;
+
+ /* close dataset space */
+ if (H5Sclose(sid) < 0)
+ goto out;
+
+ if ( idx >= (unsigned)rank )
+ return FAIL;
+
+ /*-------------------------------------------------------------------------
+ * attribute "DIMENSION_LABELS"
+ *-------------------------------------------------------------------------
+ */
+
+ /* try to find the attribute "DIMENSION_LABELS" on the >>data<< dataset */
+ if ((has_labels = H5LT_find_attribute(did, DIMENSION_LABELS)) < 0)
+ return FAIL;
+
+ /*-------------------------------------------------------------------------
+ * make the attribute and insert label
+ *-------------------------------------------------------------------------
+ */
+
+ if (has_labels == 0)
+ {
+ dims[0] = rank;
+
+ /* space for the attribute */
+ if ((sid = H5Screate_simple(1, dims, NULL)) < 0)
+ goto out;
+
+ /* create the datatype */
+ if ((tid = H5Tcopy(H5T_C_S1)) < 0)
+ goto out;
+ if (H5Tset_size(tid, H5T_VARIABLE) < 0)
+ goto out;
+
+ /* create the attribute */
+ if ((aid = H5Acreate2(did, DIMENSION_LABELS, tid, sid, H5P_DEFAULT, H5P_DEFAULT)) < 0)
+ goto out;
+
+ /* allocate and initialize */
+ buf = (const char **) malloc((size_t) rank * sizeof(char *));
+
+ if (buf == NULL)
+ goto out;
+
+ for (i = 0; i < (unsigned int) rank; i++)
+ buf[i] = NULL;
+
+ /* store the label information in the required index */
+ buf[idx] = label;
+
+ /* write the attribute with the label */
+ if (H5Awrite(aid, tid, buf) < 0)
+ goto out;
+
+ /* close */
+ if (H5Sclose(sid) < 0)
+ goto out;
+ if (H5Tclose(tid) < 0)
+ goto out;
+ if (H5Aclose(aid) < 0)
+ goto out;
+ if (buf)
+ {
+ free(buf);
+ buf = NULL;
+ }
+ }
- /* write the attribute with the new references */
- if (H5Awrite(aid,tid,buf) < 0)
- goto out;
+ /*-------------------------------------------------------------------------
+ * just insert label
+ *-------------------------------------------------------------------------
+ */
- /* close */
- if (H5Tclose(tid) < 0)
- goto out;
- if (H5Aclose(aid) < 0)
- goto out;
- if (buf)
- free(buf);
- }
+ else
+ {
+ if ((aid = H5Aopen(did, DIMENSION_LABELS, H5P_DEFAULT)) < 0)
+ goto out;
+
+ if ((tid = H5Aget_type(aid)) < 0)
+ goto out;
+
+ /* allocate and initialize */
+ buf = (const char **) malloc((size_t) rank * sizeof(char *));
+
+ if (buf == NULL)
+ goto out;
+
+ /* read */
+ if (H5Aread(aid, tid, (void *) buf) < 0)
+ goto out;
+
+ /* free the ptr that will be replaced by label */
+ if (buf[idx])
+ free((void *)buf[idx]);
+
+ /* store the label information in the required index */
+ buf[idx] = label;
+
+ /* write the attribute with the new references */
+ if (H5Awrite(aid, tid, buf) < 0)
+ goto out;
+
+ /* label was brought in, so don't free */
+ buf[idx] = NULL;
+
+ /* free all the ptr's from the H5Aread() */
+ for (i = 0; i < (unsigned int) rank; i++)
+ {
+ if (buf[i])
+ free((void *)buf[i]);
+ }
+
+ /* close */
+ if (H5Tclose(tid) < 0)
+ goto out;
+ if (H5Aclose(aid) < 0)
+ goto out;
+ if (buf)
+ {
+ free(buf);
+ buf = NULL;
+ }
+ }
- return SUCCEED;
+ return SUCCEED;
- /* error zone, gracefully close */
-out:
- H5E_BEGIN_TRY {
- H5Sclose(sid);
- H5Aclose(aid);
- H5Tclose(tid);
- } H5E_END_TRY;
- return FAIL;
+ /* error zone */
+out:
+ if (buf)
+ {
+ if (buf[idx]) /* check if we errored during H5Awrite */
+ buf[idx] = NULL; /* don't free label */
+ /* free all the ptr's from the H5Aread() */
+ for (i = 0; i < (unsigned int) rank; i++)
+ {
+ if (buf[i])
+ free((void *)buf[i]);
+ }
+ free(buf);
+ }
+ H5E_BEGIN_TRY
+ {
+ H5Sclose(sid);
+ H5Aclose(aid);
+ H5Tclose(tid);
+ }H5E_END_TRY;
+ return FAIL;
}
/*-------------------------------------------------------------------------
- * Function: H5DSget_label
- *
- * Purpose: Read the label LABEL for dimension IDX of dataset DID
- * Up to 'size' characters are stored in 'label' followed by a '\0' string
- * terminator. If the label is longer than 'size'-1,
- * the string terminator is stored in the last position of the buffer to
- * properly terminate the string.
- *
- * Return: 0 if no label found, size of label if found, Failure: FAIL
- *
- * Programmer: pvn@ncsa.uiuc.edu
- *
- * Date: January 11, 2005
- *
- * Comments:
- *
- * Modifications:
- *
- *-------------------------------------------------------------------------
- */
-ssize_t H5DSget_label(hid_t did,
- unsigned int idx,
- char *label,
- size_t size)
+* Function: H5DSget_label
+*
+* Purpose: Read the label LABEL for dimension IDX of dataset DID
+* Up to 'size' characters are stored in 'label' followed by a '\0' string
+* terminator. If the label is longer than 'size'-1,
+* the string terminator is stored in the last position of the buffer to
+* properly terminate the string.
+*
+* Return: 0 if no label found, size of label if found, Failure: FAIL
+*
+* Programmer: pvn@ncsa.uiuc.edu
+*
+* Date: January 11, 2005
+*
+* Comments:
+*
+* Modifications:
+*
+*-------------------------------------------------------------------------
+*/
+ssize_t H5DSget_label(hid_t did, unsigned int idx, char *label, size_t size)
{
- int has_labels;
- hid_t sid; /* space ID */
- hid_t tid = -1; /* attribute type ID */
- hid_t aid = -1; /* attribute ID */
- int rank; /* rank of dataset */
- char **buf=NULL; /* buffer to store in the attribute */
- H5I_type_t it; /* ID type */
- size_t nbytes;
- size_t copy_len;
+ int has_labels;
+ hid_t sid = -1; /* space ID */
+ hid_t tid = -1; /* attribute type ID */
+ hid_t aid = -1; /* attribute ID */
+ int rank; /* rank of dataset */
+ char **buf = NULL; /* buffer to store in the attribute */
+ H5I_type_t it; /* ID type */
+ size_t nbytes;
+ size_t copy_len;
+ int i;
+
+ /*-------------------------------------------------------------------------
+ * parameter checking
+ *-------------------------------------------------------------------------
+ */
+ /* get ID type */
+ if ((it = H5Iget_type(did)) < 0)
+ return FAIL;
+
+ if (H5I_DATASET != it)
+ return FAIL;
+
+ /* get dataset space */
+ if ((sid = H5Dget_space(did)) < 0)
+ return FAIL;
+
+ /* get rank */
+ if ((rank = H5Sget_simple_extent_ndims(sid)) < 0)
+ goto out;
+
+ /* close dataset space */
+ if (H5Sclose(sid) < 0)
+ goto out;
+
+ if ( idx >= (unsigned)rank )
+ return FAIL;
+
+ /*-------------------------------------------------------------------------
+ * attribute "DIMENSION_LABELS"
+ *-------------------------------------------------------------------------
+ */
+
+ /* try to find the attribute "DIMENSION_LABELS" on the >>data<< dataset */
+ if ((has_labels = H5LT_find_attribute(did, DIMENSION_LABELS)) < 0)
+ return FAIL;
+
+ /* return 0 and NULL for label if no label found */
+ if (has_labels == 0)
+ {
+ if (label)
+ label[0] = 0;
+ return 0;
+ }
-/*-------------------------------------------------------------------------
- * parameter checking
- *-------------------------------------------------------------------------
- */
- /* get ID type */
- if ((it = H5Iget_type(did)) < 0)
- return FAIL;
+ /*-------------------------------------------------------------------------
+ * open the attribute and read label
+ *-------------------------------------------------------------------------
+ */
- if (H5I_DATASET!=it)
- return FAIL;
+ assert (has_labels == 1);
+ if ((aid = H5Aopen(did, DIMENSION_LABELS, H5P_DEFAULT)) < 0)
+ goto out;
-/*-------------------------------------------------------------------------
- * attribute "DIMENSION_LABELS"
- *-------------------------------------------------------------------------
- */
-
- /* try to find the attribute "DIMENSION_LABELS" on the >>data<< dataset */
- if ((has_labels = H5LT_find_attribute(did,DIMENSION_LABELS)) < 0)
- return FAIL;
-
- /* return 0 and NULL for label if no label found */
- if (has_labels == 0)
- {
- if (label)
- label=NULL;
- return 0;
- }
-
- /* get dataset space */
- if ((sid = H5Dget_space(did)) < 0)
- return FAIL;
-
- /* get rank */
- if((rank = H5Sget_simple_extent_ndims(sid)) < 0)
- goto out;
-
- /* close dataset space */
- if(H5Sclose(sid) < 0)
- goto out;
+ if ((tid = H5Aget_type(aid)) < 0)
+ goto out;
-/*-------------------------------------------------------------------------
- * open the attribute and read label
- *-------------------------------------------------------------------------
- */
+ /* allocate and initialize */
+ buf = (char **) malloc((size_t) rank * sizeof(char *));
- assert (has_labels == 1);
- if((aid = H5Aopen(did, DIMENSION_LABELS, H5P_DEFAULT)) < 0)
- goto out;
+ if (buf == NULL)
+ goto out;
- if((tid = H5Aget_type(aid)) < 0)
- goto out;
+ /* read */
+ if (H5Aread(aid, tid, buf) < 0)
+ goto out;
- /* allocate and initialize */
- buf = (char **)malloc((size_t)rank * sizeof(char *));
+ /* get the real string length */
+ nbytes = strlen(buf[idx]);
- if(buf == NULL)
- goto out;
+ /* compute the string length which will fit into the user's buffer */
+ copy_len = MIN(size-1, nbytes);
- /* read */
- if(H5Aread(aid, tid, buf) < 0)
- goto out;
-
- /* get the real string length */
- nbytes = strlen(buf[idx]);
-
- /* compute the string length which will fit into the user's buffer */
- copy_len = MIN(size-1, nbytes);
+ /* copy all/some of the name */
+ if (label)
+ {
+ memcpy(label, buf[idx], copy_len);
- /* copy all/some of the name */
- if( label ) {
- memcpy(label, buf[idx], copy_len);
+ /* terminate the string */
+ label[copy_len] = '\0';
+ }
- /* terminate the string */
- label[copy_len]='\0';
+ /* free all the ptr's from the H5Aread() */
+ for (i = 0; i < rank; i++)
+ {
+ if (buf[i])
+ free(buf[i]);
+ }
- /* close */
- if (H5Tclose(tid) < 0)
- goto out;
- if (H5Aclose(aid) < 0)
- goto out;
- if (buf)
- free(buf);
- }
+ /* close */
+ if (H5Tclose(tid) < 0)
+ goto out;
+ if (H5Aclose(aid) < 0)
+ goto out;
+ if (buf)
+ {
+ free(buf);
+ buf = NULL;
+ }
- return (ssize_t) nbytes;
+ return (ssize_t) nbytes;
- /* error zone, gracefully close */
-out:
- H5E_BEGIN_TRY {
- H5Sclose(sid);
- H5Aclose(aid);
- H5Tclose(tid);
- } H5E_END_TRY;
- return FAIL;
+ /* error zone */
+out:
+ if (buf)
+ {
+ /* free all the ptr's from the H5Aread() */
+ for (i = 0; i < rank; i++)
+ {
+ if (buf[i])
+ free(buf[i]);
+ }
+ free(buf);
+ }
+ H5E_BEGIN_TRY
+ {
+ H5Sclose(sid);
+ H5Aclose(aid);
+ H5Tclose(tid);
+ }H5E_END_TRY;
+ return FAIL;
}
/*-------------------------------------------------------------------------
- * Function: H5DSget_scale_name
- *
- * Purpose: Read the name of dataset scale DID into buffer NAME
- * Up to 'size' characters are stored in 'name' followed by a '\0' string
- * terminator. If the name is longer than 'size'-1,
- * the string terminator is stored in the last position of the buffer to
- * properly terminate the string.
- *
- * Return: size of name if found, zero if not found, Failure: FAIL
- *
- * Programmer: pvn@ncsa.uiuc.edu
- *
- * Date: January 04, 2005
- *
- * Comments:
- *
- * Modifications:
- *
- *-------------------------------------------------------------------------
- */
+* Function: H5DSget_scale_name
+*
+* Purpose: Read the name of dataset scale DID into buffer NAME
+* Up to 'size' characters are stored in 'name' followed by a '\0' string
+* terminator. If the name is longer than 'size'-1,
+* the string terminator is stored in the last position of the buffer to
+* properly terminate the string.
+*
+* Return: size of name if found, zero if not found, Failure: FAIL
+*
+* Programmer: pvn@ncsa.uiuc.edu
+*
+* Date: January 04, 2005
+*
+* Comments:
+*
+* Modifications:
+*
+*-------------------------------------------------------------------------
+*/
ssize_t H5DSget_scale_name(hid_t did,
char *name,
size_t size)
{
- hid_t aid; /* attribute ID */
- hid_t tid = -1; /* attribute type ID */
- hid_t sid; /* space ID */
- H5I_type_t it; /* ID type */
- size_t nbytes;
- size_t copy_len;
- int has_name;
- char *buf=NULL;
-
-/*-------------------------------------------------------------------------
- * parameter checking
- *-------------------------------------------------------------------------
- */
- /* get ID type */
- if ((it = H5Iget_type(did)) < 0)
- return FAIL;
-
- if (H5I_DATASET!=it)
- return FAIL;
-
- if ((H5DSis_scale(did))<=0)
- return FAIL;
-
-/*-------------------------------------------------------------------------
- * check if the DS has a name
- *-------------------------------------------------------------------------
- */
+ hid_t aid; /* attribute ID */
+ hid_t tid = -1; /* attribute type ID */
+ hid_t sid; /* space ID */
+ H5I_type_t it; /* ID type */
+ size_t nbytes;
+ size_t copy_len;
+ int has_name;
+ char *buf=NULL;
+
+ /*-------------------------------------------------------------------------
+ * parameter checking
+ *-------------------------------------------------------------------------
+ */
+ /* get ID type */
+ if ((it = H5Iget_type(did)) < 0)
+ return FAIL;
+
+ if (H5I_DATASET!=it)
+ return FAIL;
+
+ if ((H5DSis_scale(did))<=0)
+ return FAIL;
+
+ /*-------------------------------------------------------------------------
+ * check if the DS has a name
+ *-------------------------------------------------------------------------
+ */
+
+ /* try to find the attribute "NAME" on the >>DS<< dataset */
+ if ((has_name = H5LT_find_attribute(did, "NAME")) < 0)
+ return FAIL;
+
+ if (has_name == 0)
+ return 0;
+
+ /*-------------------------------------------------------------------------
+ * open the attribute
+ *-------------------------------------------------------------------------
+ */
+
+ if((aid = H5Aopen(did, "NAME", H5P_DEFAULT)) < 0)
+ return FAIL;
+
+ /* get space */
+ if((sid = H5Aget_space(aid)) < 0)
+ goto out;
+
+ /* get type */
+ if((tid = H5Aget_type(aid)) < 0)
+ goto out;
+
+ /* get the size */
+ if((nbytes = H5Tget_size(tid)) == 0)
+ goto out;
+
+ /* allocate a temporary buffer */
+ buf = (char*)malloc(nbytes * sizeof(char));
+ if (buf == NULL)
+ goto out;
+
+ /* read */
+ if (H5Aread(aid,tid,buf) < 0)
+ goto out;
+
+ /* compute the string length which will fit into the user's buffer */
+ copy_len = MIN(size-1, nbytes);
+
+ /* copy all/some of the name */
+ if (name) {
+ memcpy(name, buf, copy_len);
+
+ /* terminate the string */
+ name[copy_len]='\0';
+ }
- /* try to find the attribute "NAME" on the >>DS<< dataset */
- if((has_name = H5LT_find_attribute(did, "NAME")) < 0)
- return FAIL;
+ /* close */
+ if (H5Tclose(tid) < 0)
+ goto out;
+ if (H5Aclose(aid) < 0)
+ goto out;
+ if (H5Sclose(sid) < 0)
+ goto out;
+ if (buf)
+ {
+ free(buf);
+ buf=NULL;
+ }
- if(has_name == 0)
- return 0;
+ return (ssize_t) nbytes;
-/*-------------------------------------------------------------------------
- * open the attribute
- *-------------------------------------------------------------------------
- */
-
- if((aid = H5Aopen(did, "NAME", H5P_DEFAULT)) < 0)
- return FAIL;
-
- /* get space */
- if((sid = H5Aget_space(aid)) < 0)
- goto out;
-
- /* get type */
- if((tid = H5Aget_type(aid)) < 0)
- goto out;
-
- /* get the size */
- if((nbytes = H5Tget_size(tid)) == 0)
- goto out;
-
- /* allocate a temporary buffer */
- buf = (char*)malloc(nbytes * sizeof(char));
- if (buf == NULL)
- goto out;
-
- /* read */
- if (H5Aread(aid,tid,buf) < 0)
- goto out;
-
- /* compute the string length which will fit into the user's buffer */
- copy_len = MIN(size-1, nbytes);
-
- /* copy all/some of the name */
- if (name) {
- memcpy(name, buf, copy_len);
-
- /* terminate the string */
- name[copy_len]='\0';
- }
-
- /* close */
- if (H5Tclose(tid) < 0)
- goto out;
- if (H5Aclose(aid) < 0)
- goto out;
- if (H5Sclose(sid) < 0)
- goto out;
- if (buf)
- {
- free(buf);
- buf=NULL;
- }
-
- return (ssize_t) nbytes;
-
- /* error zone, gracefully close */
+ /* error zone */
out:
- H5E_BEGIN_TRY {
- H5Aclose(aid);
- H5Tclose(tid);
- H5Sclose(sid);
- } H5E_END_TRY;
- if (buf)
- free(buf);
- return FAIL;
+ H5E_BEGIN_TRY {
+ H5Aclose(aid);
+ H5Tclose(tid);
+ H5Sclose(sid);
+ } H5E_END_TRY;
+ if (buf)
+ {
+ free(buf);
+ buf=NULL;
+ }
+ return FAIL;
}
/*-------------------------------------------------------------------------
- * Function: H5DSis_scale
- *
- * Purpose: check if the dataset DID is a dimension scale
- *
- * Return: 1, is, 0, not, FAIL, error
- *
- * Programmer: pvn@ncsa.uiuc.edu
- *
- * Date: January 04, 2005
- *
- * Comments:
- *
- * Modifications:
- *
- *-------------------------------------------------------------------------
- */
+* Function: H5DSis_scale
+*
+* Purpose: check if the dataset DID is a dimension scale
+*
+* Return: 1, is, 0, not, FAIL, error
+*
+* Programmer: pvn@ncsa.uiuc.edu
+*
+* Date: January 04, 2005
+*
+* Comments:
+*
+* Modifications:
+*
+*-------------------------------------------------------------------------
+*/
htri_t H5DSis_scale(hid_t did)
{
- hid_t tid = -1; /* attribute type ID */
- hid_t aid; /* attribute ID */
- herr_t has_class; /* has the "CLASS" attribute */
- htri_t is_ds; /* boolean return value */
- H5I_type_t it; /* ID type */
- char buf[20];
-
-/*-------------------------------------------------------------------------
- * parameter checking
- *-------------------------------------------------------------------------
- */
- /* get ID type */
- if ((it = H5Iget_type(did)) < 0)
- return FAIL;
-
- if(H5I_DATASET != it)
- return FAIL;
-
- /* try to find the attribute "CLASS" on the dataset */
- if((has_class = H5LT_find_attribute(did, "CLASS")) < 0)
- return FAIL;
-
- if(has_class == 0)
- is_ds = 0;
-
- else
- {
- if((aid = H5Aopen(did, "CLASS", H5P_DEFAULT)) < 0)
- goto out;
+ hid_t tid = -1; /* attribute type ID */
+ hid_t aid; /* attribute ID */
+ herr_t has_class; /* has the "CLASS" attribute */
+ htri_t is_ds; /* boolean return value */
+ H5I_type_t it; /* ID type */
+ char buf[20];
+
+ /*-------------------------------------------------------------------------
+ * parameter checking
+ *-------------------------------------------------------------------------
+ */
+ /* get ID type */
+ if ((it = H5Iget_type(did)) < 0)
+ return FAIL;
+
+ if(H5I_DATASET != it)
+ return FAIL;
+
+ /* try to find the attribute "CLASS" on the dataset */
+ if((has_class = H5LT_find_attribute(did, "CLASS")) < 0)
+ return FAIL;
+
+ if(has_class == 0)
+ is_ds = 0;
+
+ else
+ {
+ if((aid = H5Aopen(did, "CLASS", H5P_DEFAULT)) < 0)
+ goto out;
- if((tid = H5Aget_type(aid)) < 0)
- goto out;
+ if((tid = H5Aget_type(aid)) < 0)
+ goto out;
- if(H5Aread(aid, tid, buf) < 0)
- goto out;
+ if(H5Aread(aid, tid, buf) < 0)
+ goto out;
- if(strcmp(buf, DIMENSION_SCALE_CLASS)==0)
- is_ds = 1;
- else
- is_ds = 0;
+ if(strcmp(buf, DIMENSION_SCALE_CLASS)==0)
+ is_ds = 1;
+ else
+ is_ds = 0;
- if(H5Tclose(tid) < 0)
- goto out;
+ if(H5Tclose(tid) < 0)
+ goto out;
- if (H5Aclose(aid) < 0)
- goto out;
- }
+ if (H5Aclose(aid) < 0)
+ goto out;
+ }
- return is_ds;
+ return is_ds;
-/* error zone, gracefully close */
+ /* error zone */
out:
- H5E_BEGIN_TRY {
- H5Aclose(aid);
- H5Tclose(tid);
- } H5E_END_TRY;
- return FAIL;
+ H5E_BEGIN_TRY {
+ H5Aclose(aid);
+ H5Tclose(tid);
+ } H5E_END_TRY;
+ return FAIL;
}
/*-------------------------------------------------------------------------
- * Function: H5DSget_num_scales
- *
- * Purpose: get the number of scales linked to the IDX dimension of dataset DID
- *
- * Return:
- * Success: number of scales
- * Failure: FAIL
- *
- * Programmer: pvn@ncsa.uiuc.edu
- *
- * Date: January 13, 2005
- *
- * Comments:
- *
- * Modifications:
- *
- *-------------------------------------------------------------------------
- */
+* Function: H5DSget_num_scales
+*
+* Purpose: get the number of scales linked to the IDX dimension of dataset DID
+*
+* Return:
+* Success: number of scales
+* Failure: FAIL
+*
+* Programmer: pvn@ncsa.uiuc.edu
+*
+* Date: January 13, 2005
+*
+* Comments:
+*
+* Modifications:
+*
+*-------------------------------------------------------------------------
+*/
int H5DSget_num_scales(hid_t did,
unsigned int idx)
{
- int has_dimlist;
- hid_t sid; /* space ID */
- hid_t tid = -1; /* attribute type ID */
- hid_t aid = -1; /* attribute ID */
- int rank; /* rank of dataset */
- hvl_t *buf; /* VL buffer to store in the attribute */
- H5I_type_t it; /* ID type */
- int nscales;
-
-/*-------------------------------------------------------------------------
- * parameter checking
- *-------------------------------------------------------------------------
- */
- /* get ID type */
- if ((it = H5Iget_type(did)) < 0)
- return FAIL;
-
- if (H5I_DATASET!=it)
- return FAIL;
-
-/*-------------------------------------------------------------------------
- * the attribute "DIMENSION_LIST" on the >>data<< dataset must exist
- *-------------------------------------------------------------------------
- */
- /* get dataset space */
- if ((sid = H5Dget_space(did)) < 0)
- return FAIL;
-
- /* get rank */
- if ((rank=H5Sget_simple_extent_ndims(sid)) < 0)
- goto out;
-
- /* close dataset space */
- if (H5Sclose(sid) < 0)
- goto out;
-
- /* dimemsion index IDX range checking */
- if (idx>=(unsigned int )rank)
- return FAIL;
-
- /* try to find the attribute "DIMENSION_LIST" on the >>data<< dataset */
- if((has_dimlist = H5LT_find_attribute(did, DIMENSION_LIST)) < 0)
- return FAIL;
-
- /* it does not exist */
- if(has_dimlist == 0)
- return 0;
-
-/*-------------------------------------------------------------------------
- * the attribute exists, open it
- *-------------------------------------------------------------------------
- */
-
- else
- {
- if((aid = H5Aopen(did, DIMENSION_LIST, H5P_DEFAULT)) < 0)
- goto out;
- if((tid = H5Aget_type(aid)) < 0)
- goto out;
- if((sid = H5Aget_space(aid)) < 0)
- goto out;
-
- /* allocate and initialize the VL */
- buf = (hvl_t*)malloc((size_t)rank * sizeof(hvl_t));
-
- if(buf == NULL)
- goto out;
-
- /* read */
- if(H5Aread(aid, tid, buf) < 0)
- goto out;
-
- nscales=(int)buf[idx].len;
-
- /* close */
- if (H5Dvlen_reclaim(tid,sid,H5P_DEFAULT,buf) < 0)
- goto out;
- if (H5Sclose(sid) < 0)
- goto out;
- if (H5Tclose(tid) < 0)
- goto out;
- if (H5Aclose(aid) < 0)
- goto out;
- if (buf)
- free(buf);
-
- } /* has_dimlist */
-
- return nscales;
-
-/* error zone, gracefully close */
+ int has_dimlist;
+ hid_t sid; /* space ID */
+ hid_t tid = -1; /* attribute type ID */
+ hid_t aid = -1; /* attribute ID */
+ int rank; /* rank of dataset */
+ hvl_t *buf; /* VL buffer to store in the attribute */
+ H5I_type_t it; /* ID type */
+ int nscales;
+
+ /*-------------------------------------------------------------------------
+ * parameter checking
+ *-------------------------------------------------------------------------
+ */
+ /* get ID type */
+ if ((it = H5Iget_type(did)) < 0)
+ return FAIL;
+
+ if (H5I_DATASET!=it)
+ return FAIL;
+
+ /*-------------------------------------------------------------------------
+ * the attribute "DIMENSION_LIST" on the >>data<< dataset must exist
+ *-------------------------------------------------------------------------
+ */
+ /* get dataset space */
+ if ((sid = H5Dget_space(did)) < 0)
+ return FAIL;
+
+ /* get rank */
+ if ((rank=H5Sget_simple_extent_ndims(sid)) < 0)
+ goto out;
+
+ /* close dataset space */
+ if (H5Sclose(sid) < 0)
+ goto out;
+
+ /* dimemsion index IDX range checking */
+ if (idx>=(unsigned int )rank)
+ return FAIL;
+
+ /* try to find the attribute "DIMENSION_LIST" on the >>data<< dataset */
+ if((has_dimlist = H5LT_find_attribute(did, DIMENSION_LIST)) < 0)
+ return FAIL;
+
+ /* it does not exist */
+ if(has_dimlist == 0)
+ return 0;
+
+ /*-------------------------------------------------------------------------
+ * the attribute exists, open it
+ *-------------------------------------------------------------------------
+ */
+
+ else
+ {
+ if((aid = H5Aopen(did, DIMENSION_LIST, H5P_DEFAULT)) < 0)
+ goto out;
+ if((tid = H5Aget_type(aid)) < 0)
+ goto out;
+ if((sid = H5Aget_space(aid)) < 0)
+ goto out;
+
+ /* allocate and initialize the VL */
+ buf = (hvl_t*)malloc((size_t)rank * sizeof(hvl_t));
+
+ if(buf == NULL)
+ goto out;
+
+ /* read */
+ if(H5Aread(aid, tid, buf) < 0)
+ goto out;
+
+ nscales=(int)buf[idx].len;
+
+ /* close */
+ if (H5Dvlen_reclaim(tid,sid,H5P_DEFAULT,buf) < 0)
+ goto out;
+ if (H5Sclose(sid) < 0)
+ goto out;
+ if (H5Tclose(tid) < 0)
+ goto out;
+ if (H5Aclose(aid) < 0)
+ goto out;
+ if (buf)
+ {
+ free(buf);
+ buf = NULL;
+ }
+
+ } /* has_dimlist */
+
+ return nscales;
+
+ /* error zone */
out:
- H5E_BEGIN_TRY {
- H5Sclose(sid);
- H5Aclose(aid);
- H5Tclose(tid);
- } H5E_END_TRY;
- return FAIL;
+ H5E_BEGIN_TRY {
+ H5Sclose(sid);
+ H5Aclose(aid);
+ H5Tclose(tid);
+ } H5E_END_TRY;
+
+ if (buf)
+ {
+ free(buf);
+ buf = NULL;
+ }
+ return FAIL;
}
/*-------------------------------------------------------------------------
- * Function: H5DS_is_reserved
- *
- * Purpose: Verify that a dataset's CLASS is either an image, palette or table
- *
- * Return: true, false, fail
- *
- * Programmer: pvn@ncsa.uiuc.edu
- *
- * Date: March 19, 2005
- *
- * Comments:
- *
- * Modifications:
- *
- *-------------------------------------------------------------------------
- */
+* Function: H5DS_is_reserved
+*
+* Purpose: Verify that a dataset's CLASS is either an image, palette or table
+*
+* Return: true, false, fail
+*
+* Programmer: pvn@ncsa.uiuc.edu
+*
+* Date: March 19, 2005
+*
+* Comments:
+*
+* Modifications:
+*
+*-------------------------------------------------------------------------
+*/
herr_t H5DS_is_reserved(hid_t did)
{
- int has_class;
- hid_t tid = -1;
- hid_t aid = -1;
- char buf[40];
- herr_t ret;
+ int has_class;
+ hid_t tid = -1;
+ hid_t aid = -1;
+ char buf[40];
+ herr_t ret;
- /* try to find the attribute "CLASS" on the dataset */
- if((has_class = H5LT_find_attribute(did, "CLASS")) < 0)
- return -1;
+ /* try to find the attribute "CLASS" on the dataset */
+ if((has_class = H5LT_find_attribute(did, "CLASS")) < 0)
+ return -1;
- if(has_class == 0)
- return 0;
+ if(has_class == 0)
+ return 0;
- assert(has_class == 1);
- if((aid = H5Aopen(did, "CLASS", H5P_DEFAULT)) < 0)
- goto out;
+ assert(has_class == 1);
+ if((aid = H5Aopen(did, "CLASS", H5P_DEFAULT)) < 0)
+ goto out;
- if((tid = H5Aget_type(aid)) < 0)
- goto out;
+ if((tid = H5Aget_type(aid)) < 0)
+ goto out;
- if(H5Aread(aid, tid, buf) < 0)
- goto out;
+ if(H5Aread(aid, tid, buf) < 0)
+ goto out;
- if(strcmp(buf, IMAGE_CLASS) == 0 ||
- strcmp(buf, PALETTE_CLASS) == 0 ||
- strcmp(buf, TABLE_CLASS) == 0 )
- ret = 1;
- else
- ret = 0;
+ if(strcmp(buf, IMAGE_CLASS) == 0 ||
+ strcmp(buf, PALETTE_CLASS) == 0 ||
+ strcmp(buf, TABLE_CLASS) == 0 )
+ ret = 1;
+ else
+ ret = 0;
- if (H5Tclose(tid) < 0)
- goto out;
+ if (H5Tclose(tid) < 0)
+ goto out;
- if (H5Aclose(aid) < 0)
- goto out;
+ if (H5Aclose(aid) < 0)
+ goto out;
- return ret;
+ return ret;
-/* error zone, gracefully close */
+ /* error zone */
out:
- H5E_BEGIN_TRY {
- H5Tclose(tid);
- H5Aclose(aid);
- } H5E_END_TRY;
- return FAIL;
+ H5E_BEGIN_TRY
+ {
+ H5Tclose(tid);
+ H5Aclose(aid);
+ } H5E_END_TRY;
+ return FAIL;
}
diff --git a/hl/src/H5IM.c b/hl/src/H5IM.c
index d760675..361a65b 100644
--- a/hl/src/H5IM.c
+++ b/hl/src/H5IM.c
@@ -1,17 +1,17 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- * Copyright by The HDF Group. *
- * Copyright by the Board of Trustees of the University of Illinois. *
- * All rights reserved. *
- * *
- * This file is part of HDF5. The full HDF5 copyright notice, including *
- * terms governing use, modification, and redistribution, is contained in *
- * the files COPYING and Copyright.html. COPYING can be found at the root *
- * of the source code distribution tree; Copyright.html can be found at the *
- * root level of an installed copy of the electronic HDF5 document set and *
- * is linked from the top-level documents page. It can also be found at *
- * http://hdfgroup.org/HDF5/doc/Copyright.html. If you do not have *
- * access to either file, you may request a copy from help@hdfgroup.org. *
- * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
+* Copyright by The HDF Group. *
+* Copyright by the Board of Trustees of the University of Illinois. *
+* All rights reserved. *
+* *
+* This file is part of HDF5. The full HDF5 copyright notice, including *
+* terms governing use, modification, and redistribution, is contained in *
+* the files COPYING and Copyright.html. COPYING can be found at the root *
+* of the source code distribution tree; Copyright.html can be found at the *
+* root level of an installed copy of the electronic HDF5 document set and *
+* is linked from the top-level documents page. It can also be found at *
+* http://hdfgroup.org/HDF5/doc/Copyright.html. If you do not have *
+* access to either file, you may request a copy from help@hdfgroup.org. *
+* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#include "H5IMprivate.h"
#include "H5LTprivate.h"
@@ -19,155 +19,156 @@
#include <stdlib.h>
/*-------------------------------------------------------------------------
- * Function: H5IMmake_image_8bit
- *
- * Purpose: Creates and writes an image an 8 bit image
- *
- * Return: Success: 0, Failure: -1
- *
- * Programmer: Pedro Vicente Nunes, pvn@ncsa.uiuc.edu
- *
- * Date: June 13, 2001
- *
- * Comments:
- * based on HDF5 Image and Palette Specification
- * http://hdf.ncsa.uiuc.edu/HDF5/H5Image/ImageSpec.html
- *
- * Modifications:
- *
- *-------------------------------------------------------------------------
- */
+* Function: H5IMmake_image_8bit
+*
+* Purpose: Creates and writes an image an 8 bit image
+*
+* Return: Success: 0, Failure: -1
+*
+* Programmer: Pedro Vicente Nunes, pvn@ncsa.uiuc.edu
+*
+* Date: June 13, 2001
+*
+* Comments:
+* based on HDF5 Image and Palette Specification
+* http://hdf.ncsa.uiuc.edu/HDF5/H5Image/ImageSpec.html
+*
+* Modifications:
+*
+*-------------------------------------------------------------------------
+*/
herr_t H5IMmake_image_8bit( hid_t loc_id,
- const char *dset_name,
- hsize_t width,
- hsize_t height,
- const unsigned char *buffer )
+ const char *dset_name,
+ hsize_t width,
+ hsize_t height,
+ const unsigned char *buf )
{
- hsize_t dims[IMAGE8_RANK];
+ hsize_t dims[IMAGE8_RANK];
- /* Initialize the image dimensions */
- dims[0] = height;
- dims[1] = width;
+ /* Initialize the image dimensions */
+ dims[0] = height;
+ dims[1] = width;
- /* Make the dataset */
- if ( H5LTmake_dataset( loc_id, dset_name, IMAGE8_RANK, dims, H5T_NATIVE_UCHAR, buffer ) < 0)
- return -1;
+ /* Make the dataset */
+ if ( H5LTmake_dataset( loc_id, dset_name, IMAGE8_RANK, dims, H5T_NATIVE_UCHAR, buf ) < 0)
+ return -1;
- /* Attach the CLASS attribute */
- if ( H5LTset_attribute_string( loc_id, dset_name, "CLASS", IMAGE_CLASS ) < 0)
- return -1;
+ /* Attach the CLASS attribute */
+ if ( H5LTset_attribute_string( loc_id, dset_name, "CLASS", IMAGE_CLASS ) < 0)
+ return -1;
- /* Attach the VERSION attribute */
- if ( H5LTset_attribute_string( loc_id, dset_name, "IMAGE_VERSION", IMAGE_VERSION ) < 0)
- return -1;
+ /* Attach the VERSION attribute */
+ if ( H5LTset_attribute_string( loc_id, dset_name, "IMAGE_VERSION", IMAGE_VERSION ) < 0)
+ return -1;
- /* Attach the IMAGE_SUBCLASS attribute */
- if ( H5LTset_attribute_string( loc_id, dset_name, "IMAGE_SUBCLASS", "IMAGE_INDEXED" ) < 0)
- return -1;
+ /* Attach the IMAGE_SUBCLASS attribute */
+ if ( H5LTset_attribute_string( loc_id, dset_name, "IMAGE_SUBCLASS", "IMAGE_INDEXED" ) < 0)
+ return -1;
- return 0;
+ return 0;
}
/*-------------------------------------------------------------------------
- * Function: H5IMmake_image_24bit
- *
- * Purpose:
- *
- * Return: Success: 0, Failure: -1
- *
- * Programmer: Pedro Vicente Nunes, pvn@ncsa.uiuc.edu
- *
- * Date: June 13, 2001
- *
- * Comments:
- * based on HDF5 Image and Palette Specification
- * http://hdf.ncsa.uiuc.edu/HDF5/H5Image/ImageSpec.html
- *
- * Interlace Mode Dimensions in the Dataspace
- * INTERLACE_PIXEL [height][width][pixel components]
- * INTERLACE_PLANE [pixel components][height][width]
- *
- *
- * Modifications:
- *
- *-------------------------------------------------------------------------
- */
+* Function: H5IMmake_image_24bit
+*
+* Purpose:
+*
+* Return: Success: 0, Failure: -1
+*
+* Programmer: Pedro Vicente Nunes, pvn@ncsa.uiuc.edu
+*
+* Date: June 13, 2001
+*
+* Comments:
+* based on HDF5 Image and Palette Specification
+* http://hdf.ncsa.uiuc.edu/HDF5/H5Image/ImageSpec.html
+*
+* Interlace Mode Dimensions in the Dataspace
+* INTERLACE_PIXEL [height][width][pixel components]
+* INTERLACE_PLANE [pixel components][height][width]
+*
+*
+* Modifications:
+*
+*-------------------------------------------------------------------------
+*/
herr_t H5IMmake_image_24bit( hid_t loc_id,
- const char *dset_name,
- hsize_t width,
- hsize_t height,
- const char *interlace,
- const unsigned char *buffer )
+ const char *dset_name,
+ hsize_t width,
+ hsize_t height,
+ const char *interlace,
+ const unsigned char *buf )
{
- hsize_t dims[IMAGE24_RANK];
-
- /* Initialize the image dimensions */
-
- if ( strcmp( interlace, "INTERLACE_PIXEL" ) == 0 )
- {
- /* Number of color planes is defined as the third dimension */
- dims[0] = height;
- dims[1] = width;
- dims[2] = IMAGE24_RANK;
- }
- else
- if ( strcmp( interlace, "INTERLACE_PLANE" ) == 0 )
- {
- /* Number of color planes is defined as the first dimension */
- dims[0] = IMAGE24_RANK;
- dims[1] = height;
- dims[2] = width;
- }
- else return -1;
-
- /* Make the dataset */
- if ( H5LTmake_dataset( loc_id, dset_name, IMAGE24_RANK, dims, H5T_NATIVE_UCHAR, buffer ) < 0)
- return -1;
-
- /* Attach the CLASS attribute */
- if ( H5LTset_attribute_string( loc_id, dset_name, "CLASS", IMAGE_CLASS ) < 0)
- return -1;
-
- /* Attach the VERSION attribute */
- if ( H5LTset_attribute_string( loc_id, dset_name, "IMAGE_VERSION", IMAGE_VERSION ) < 0)
- return -1;
-
- /* Attach the IMAGE_SUBCLASS attribute */
- if ( H5LTset_attribute_string( loc_id, dset_name, "IMAGE_SUBCLASS", "IMAGE_TRUECOLOR" ) < 0)
- return -1;
-
- /* Attach the INTERLACE_MODE attribute. This attributes is only for true color images */
- if ( H5LTset_attribute_string( loc_id, dset_name, "INTERLACE_MODE", interlace ) < 0)
- return -1;
-
- return 0;
+ hsize_t dims[IMAGE24_RANK];
+
+ /* Initialize the image dimensions */
+
+ if ( strcmp( interlace, "INTERLACE_PIXEL" ) == 0 )
+ {
+ /* Number of color planes is defined as the third dimension */
+ dims[0] = height;
+ dims[1] = width;
+ dims[2] = IMAGE24_RANK;
+ }
+ else
+ if ( strcmp( interlace, "INTERLACE_PLANE" ) == 0 )
+ {
+ /* Number of color planes is defined as the first dimension */
+ dims[0] = IMAGE24_RANK;
+ dims[1] = height;
+ dims[2] = width;
+ }
+ else return -1;
+
+ /* Make the dataset */
+ if ( H5LTmake_dataset( loc_id, dset_name, IMAGE24_RANK, dims, H5T_NATIVE_UCHAR, buf ) < 0)
+ return -1;
+
+ /* Attach the CLASS attribute */
+ if ( H5LTset_attribute_string( loc_id, dset_name, "CLASS", IMAGE_CLASS ) < 0)
+ return -1;
+
+ /* Attach the VERSION attribute */
+ if ( H5LTset_attribute_string( loc_id, dset_name, "IMAGE_VERSION", IMAGE_VERSION ) < 0)
+ return -1;
+
+ /* Attach the IMAGE_SUBCLASS attribute */
+ if ( H5LTset_attribute_string( loc_id, dset_name, "IMAGE_SUBCLASS", "IMAGE_TRUECOLOR" ) < 0)
+ return -1;
+
+ /* Attach the INTERLACE_MODE attribute. This attributes is only for true color images */
+ if ( H5LTset_attribute_string( loc_id, dset_name, "INTERLACE_MODE", interlace ) < 0)
+ return -1;
+
+ return 0;
}
/*-------------------------------------------------------------------------
- * Function: find_palette
- *
- * Purpose: operator function used by H5LT_find_palette
- *
- * Return:
- *
- * Programmer: Pedro Vicente Nunes, pvn@ncsa.uiuc.edu
- *
- * Date: May 28, 2001
- *
- * Comments:
- *
- * Modifications:
- *
- *-------------------------------------------------------------------------
- */
-static herr_t
-find_palette(hid_t loc_id, const char *name, const H5A_info_t *ainfo,
- void *op_data)
+* Function: find_palette
+*
+* Purpose: operator function used by H5LT_find_palette
+*
+* Return:
+*
+* Programmer: Pedro Vicente Nunes, pvn@ncsa.uiuc.edu
+*
+* Date: May 28, 2001
+*
+* Comments:
+*
+* Modifications:
+*
+*-------------------------------------------------------------------------
+*/
+static herr_t find_palette(hid_t loc_id,
+ const char *name,
+ const H5A_info_t *ainfo,
+ void *op_data)
{
int ret = H5_ITER_CONT;
@@ -175,9 +176,9 @@ find_palette(hid_t loc_id, const char *name, const H5A_info_t *ainfo,
loc_id = loc_id; ainfo = ainfo; op_data = op_data;
/* Define a positive value for return value if the attribute was found. This will
- * cause the iterator to immediately return that positive value,
- * indicating short-circuit success
- */
+ * cause the iterator to immediately return that positive value,
+ * indicating short-circuit success
+ */
if(strcmp(name, "PALETTE") == 0)
ret = H5_ITER_STOP;
@@ -186,23 +187,23 @@ find_palette(hid_t loc_id, const char *name, const H5A_info_t *ainfo,
/*-------------------------------------------------------------------------
- * Function: H5IM_find_palette
- *
- * Purpose: Private function. Find the attribute "PALETTE" in the image dataset
- *
- * Return: Success: 1, Failure: 0
- *
- * Programmer: Pedro Vicente Nunes, pvn@ncsa.uiuc.edu
- *
- * Date: May 11, 2001
- *
- * Comments:
- * The function uses H5Aiterate2 with the operator function find_palette
- *
- * Modifications:
- *
- *-------------------------------------------------------------------------
- */
+* Function: H5IM_find_palette
+*
+* Purpose: Private function. Find the attribute "PALETTE" in the image dataset
+*
+* Return: Success: 1, Failure: 0
+*
+* Programmer: Pedro Vicente Nunes, pvn@ncsa.uiuc.edu
+*
+* Date: May 11, 2001
+*
+* Comments:
+* The function uses H5Aiterate2 with the operator function find_palette
+*
+* Modifications:
+*
+*-------------------------------------------------------------------------
+*/
herr_t H5IM_find_palette( hid_t loc_id )
{
@@ -211,1010 +212,1011 @@ herr_t H5IM_find_palette( hid_t loc_id )
/*-------------------------------------------------------------------------
- * Function: H5IMget_image_info
- *
- * Purpose: Gets information about an image dataset (dimensions, interlace mode
- * and number of associated palettes).
- *
- * Return: Success: 0, Failure: -1
- *
- * Programmer: Pedro Vicente Nunes, pvn@ncsa.uiuc.edu
- *
- * Date: July 25, 2001
- *
- * Comments:
- * based on HDF5 Image and Palette Specification
- * http://hdf.ncsa.uiuc.edu/HDF5/H5Image/ImageSpec.html
- *
- * Modifications:
- *
- *-------------------------------------------------------------------------
- */
+* Function: H5IMget_image_info
+*
+* Purpose: Gets information about an image dataset (dimensions, interlace mode
+* and number of associated palettes).
+*
+* Return: Success: 0, Failure: -1
+*
+* Programmer: Pedro Vicente Nunes, pvn@ncsa.uiuc.edu
+*
+* Date: July 25, 2001
+*
+* Comments:
+* based on HDF5 Image and Palette Specification
+* http://hdf.ncsa.uiuc.edu/HDF5/H5Image/ImageSpec.html
+*
+* Modifications:
+*
+*-------------------------------------------------------------------------
+*/
herr_t H5IMget_image_info( hid_t loc_id,
- const char *dset_name,
- hsize_t *width,
- hsize_t *height,
- hsize_t *planes,
- char *interlace,
- hssize_t *npals )
+ const char *dset_name,
+ hsize_t *width,
+ hsize_t *height,
+ hsize_t *planes,
+ char *interlace,
+ hssize_t *npals )
{
- hid_t did, sid;
- hsize_t dims[IMAGE24_RANK];
- hid_t attr_id;
- hid_t attr_type;
- int has_attr;
- hid_t attr_space_id;
- hid_t attr_class;
- int has_pal;
+ hid_t did;
+ hid_t sid;
+ hsize_t dims[IMAGE24_RANK];
+ hid_t aid;
+ hid_t asid;
+ hid_t atid;
+ H5T_class_t aclass;
+ int has_pal;
+ int has_attr;
- /*assume initially we have no palettes attached*/
- *npals = 0;
+ /*assume initially we have no palettes attached*/
+ *npals = 0;
- /* Open the dataset. */
- if((did = H5Dopen2(loc_id, dset_name, H5P_DEFAULT)) < 0)
- return -1;
+ /* Open the dataset. */
+ if((did = H5Dopen2(loc_id, dset_name, H5P_DEFAULT)) < 0)
+ return -1;
- /* Try to find the attribute "INTERLACE_MODE" on the >>image<< dataset */
- has_attr = H5LT_find_attribute(did, "INTERLACE_MODE");
+ /* Try to find the attribute "INTERLACE_MODE" on the >>image<< dataset */
+ has_attr = H5LT_find_attribute(did, "INTERLACE_MODE");
- /* It exists, get it */
- if(has_attr == 1)
- {
+ /* It exists, get it */
+ if(has_attr == 1)
+ {
- if((attr_id = H5Aopen(did, "INTERLACE_MODE", H5P_DEFAULT)) < 0)
- goto out;
+ if((aid = H5Aopen(did, "INTERLACE_MODE", H5P_DEFAULT)) < 0)
+ goto out;
- if((attr_type = H5Aget_type(attr_id)) < 0)
- goto out;
+ if((atid = H5Aget_type(aid)) < 0)
+ goto out;
- if(H5Aread(attr_id, attr_type, interlace) < 0)
- goto out;
+ if(H5Aread(aid, atid, interlace) < 0)
+ goto out;
- if(H5Tclose(attr_type) < 0)
- goto out;
+ if(H5Tclose(atid) < 0)
+ goto out;
- if(H5Aclose(attr_id) < 0)
- goto out;
- }
+ if(H5Aclose(aid) < 0)
+ goto out;
+ }
- /* Get the dataspace handle */
- if ( (sid = H5Dget_space( did )) < 0)
- goto out;
+ /* Get the dataspace handle */
+ if ( (sid = H5Dget_space( did )) < 0)
+ goto out;
- /* Get dimensions */
- if ( H5Sget_simple_extent_dims( sid, dims, NULL) < 0)
- goto out;
+ /* Get dimensions */
+ if ( H5Sget_simple_extent_dims( sid, dims, NULL) < 0)
+ goto out;
- /* Initialize the image dimensions */
+ /* Initialize the image dimensions */
- if ( has_attr == 1 )
- /* This is a 24 bit image */
- {
+ if ( has_attr == 1 )
+ /* This is a 24 bit image */
+ {
- if ( strcmp( interlace, "INTERLACE_PIXEL" ) == 0 )
- {
- /* Number of color planes is defined as the third dimension */
- *height = dims[0];
- *width = dims[1];
- *planes = dims[2];
- }
- else
- if ( strcmp( interlace, "INTERLACE_PLANE" ) == 0 )
- {
- /* Number of color planes is defined as the first dimension */
- *planes = dims[0];
- *height = dims[1];
- *width = dims[2];
- }
- else return -1;
- }
- else
- /* This is a 8 bit image */
- {
- *height = dims[0];
- *width = dims[1];
- *planes = 1;
- }
+ if ( strcmp( interlace, "INTERLACE_PIXEL" ) == 0 )
+ {
+ /* Number of color planes is defined as the third dimension */
+ *height = dims[0];
+ *width = dims[1];
+ *planes = dims[2];
+ }
+ else
+ if ( strcmp( interlace, "INTERLACE_PLANE" ) == 0 )
+ {
+ /* Number of color planes is defined as the first dimension */
+ *planes = dims[0];
+ *height = dims[1];
+ *width = dims[2];
+ }
+ else return -1;
+ }
+ else
+ /* This is a 8 bit image */
+ {
+ *height = dims[0];
+ *width = dims[1];
+ *planes = 1;
+ }
- /* Close */
- if ( H5Sclose( sid ) < 0)
- goto out;
+ /* Close */
+ if ( H5Sclose( sid ) < 0)
+ goto out;
- /* Get number of palettes */
+ /* Get number of palettes */
- /* Try to find the attribute "PALETTE" on the >>image<< dataset */
- has_pal = H5IM_find_palette(did);
+ /* Try to find the attribute "PALETTE" on the >>image<< dataset */
+ has_pal = H5IM_find_palette(did);
- if(has_pal == 1)
- {
+ if(has_pal == 1)
+ {
- if((attr_id = H5Aopen(did, "PALETTE", H5P_DEFAULT)) < 0)
- goto out;
+ if((aid = H5Aopen(did, "PALETTE", H5P_DEFAULT)) < 0)
+ goto out;
- if((attr_type = H5Aget_type(attr_id)) < 0)
- goto out;
+ if((atid = H5Aget_type(aid)) < 0)
+ goto out;
- if((attr_class = H5Tget_class(attr_type)) < 0)
- goto out;
+ if((aclass = H5Tget_class(atid)) < 0)
+ goto out;
- /* Check if it is really a reference */
+ /* Check if it is really a reference */
- if(attr_class == H5T_REFERENCE)
- {
+ if(aclass == H5T_REFERENCE)
+ {
- /* Get the reference(s) */
+ /* Get the reference(s) */
- if ( (attr_space_id = H5Aget_space( attr_id )) < 0)
- goto out;
+ if ( (asid = H5Aget_space( aid )) < 0)
+ goto out;
- *npals = H5Sget_simple_extent_npoints( attr_space_id );
+ *npals = H5Sget_simple_extent_npoints( asid );
- if ( H5Sclose( attr_space_id ) < 0)
- goto out;
+ if ( H5Sclose( asid ) < 0)
+ goto out;
- } /* H5T_REFERENCE */
+ } /* H5T_REFERENCE */
- if ( H5Tclose( attr_type ) < 0)
- goto out;
+ if ( H5Tclose( atid ) < 0)
+ goto out;
- /* Close the attribute. */
- if ( H5Aclose( attr_id ) < 0)
- goto out;
+ /* Close the attribute. */
+ if ( H5Aclose( aid ) < 0)
+ goto out;
- }
+ }
- /* End access to the dataset and release resources used by it. */
- if ( H5Dclose( did ) < 0)
- goto out;
+ /* End access to the dataset and release resources used by it. */
+ if ( H5Dclose( did ) < 0)
+ goto out;
- return 0;
+ return 0;
out:
- H5Dclose( did );
- return -1;
+ H5Dclose( did );
+ H5Aclose( aid );
+ H5Sclose( asid );
+ H5Tclose( atid );
+ return -1;
}
/*-------------------------------------------------------------------------
- * Function: H5IMread_image
- *
- * Purpose: Reads image data from disk.
- *
- * Return: Success: 0, Failure: -1
- *
- * Programmer: Pedro Vicente Nunes, pvn@ncsa.uiuc.edu
- *
- * Date: June 13, 2001
- *
- * Comments:
- * based on HDF5 Image and Palette Specification
- * http://hdf.ncsa.uiuc.edu/HDF5/H5Image/ImageSpec.html
- *
- * Modifications:
- *
- *-------------------------------------------------------------------------
- */
+* Function: H5IMread_image
+*
+* Purpose: Reads image data from disk.
+*
+* Return: Success: 0, Failure: -1
+*
+* Programmer: Pedro Vicente Nunes, pvn@ncsa.uiuc.edu
+*
+* Date: June 13, 2001
+*
+* Comments:
+* based on HDF5 Image and Palette Specification
+* http://hdf.ncsa.uiuc.edu/HDF5/H5Image/ImageSpec.html
+*
+* Modifications:
+*
+*-------------------------------------------------------------------------
+*/
herr_t H5IMread_image( hid_t loc_id,
const char *dset_name,
- unsigned char *buffer )
+ unsigned char *buf )
{
- hid_t did;
+ hid_t did;
- /* Open the dataset. */
- if((did = H5Dopen2(loc_id, dset_name, H5P_DEFAULT)) < 0)
- return -1;
+ /* Open the dataset. */
+ if((did = H5Dopen2(loc_id, dset_name, H5P_DEFAULT)) < 0)
+ return -1;
- /* Read */
- if ( H5Dread( did, H5T_NATIVE_UCHAR, H5S_ALL, H5S_ALL, H5P_DEFAULT, buffer ) < 0)
- goto out;
+ /* Read */
+ if ( H5Dread( did, H5T_NATIVE_UCHAR, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf ) < 0)
+ goto out;
- /* End access to the dataset and release resources used by it. */
- if ( H5Dclose( did ) )
- return -1;
+ /* End access to the dataset and release resources used by it. */
+ if ( H5Dclose( did ) )
+ return -1;
- return 0;
+ return 0;
out:
- H5Dclose( did );
- return -1;
+ H5Dclose( did );
+ return -1;
}
/*-------------------------------------------------------------------------
- * Function: H5IMmake_palette
- *
- * Purpose: Creates and writes a palette.
- *
- * Return: Success: 0, Failure: -1
- *
- * Programmer: Pedro Vicente Nunes, pvn@ncsa.uiuc.edu
- *
- * Date: May 01, 2001
- *
- * Comments:
- * based on HDF5 Image and Palette Specification
- * http://hdf.ncsa.uiuc.edu/HDF5/H5Image/ImageSpec.html
- *
- * Modifications:
- *
- *-------------------------------------------------------------------------
- */
+* Function: H5IMmake_palette
+*
+* Purpose: Creates and writes a palette.
+*
+* Return: Success: 0, Failure: -1
+*
+* Programmer: Pedro Vicente Nunes, pvn@ncsa.uiuc.edu
+*
+* Date: May 01, 2001
+*
+* Comments:
+* based on HDF5 Image and Palette Specification
+* http://hdf.ncsa.uiuc.edu/HDF5/H5Image/ImageSpec.html
+*
+* Modifications:
+*
+*-------------------------------------------------------------------------
+*/
herr_t H5IMmake_palette( hid_t loc_id,
- const char *pal_name,
- const hsize_t *pal_dims,
- const unsigned char *pal_data )
+ const char *pal_name,
+ const hsize_t *pal_dims,
+ const unsigned char *pal_data )
{
- int has_pal;
+ int has_pal;
- /* Check if the dataset already exists */
- has_pal = H5LTfind_dataset( loc_id, pal_name );
+ /* Check if the dataset already exists */
+ has_pal = H5LTfind_dataset( loc_id, pal_name );
- /* It exists. Return */
- if ( has_pal == 1 )
- return 0;
+ /* It exists. Return */
+ if ( has_pal == 1 )
+ return 0;
- /* Make the palette dataset. */
- if ( H5LTmake_dataset( loc_id, pal_name, 2, pal_dims, H5T_NATIVE_UCHAR, pal_data ) < 0 )
- return -1;
+ /* Make the palette dataset. */
+ if ( H5LTmake_dataset( loc_id, pal_name, 2, pal_dims, H5T_NATIVE_UCHAR, pal_data ) < 0 )
+ return -1;
- /* Attach the attribute "CLASS" to the >>palette<< dataset*/
- if ( H5LTset_attribute_string( loc_id, pal_name, "CLASS", PALETTE_CLASS ) < 0)
- return -1;
+ /* Attach the attribute "CLASS" to the >>palette<< dataset*/
+ if ( H5LTset_attribute_string( loc_id, pal_name, "CLASS", PALETTE_CLASS ) < 0)
+ return -1;
- /* Attach the attribute "PAL_VERSION" to the >>palette<< dataset*/
- if ( H5LTset_attribute_string( loc_id, pal_name, "PAL_VERSION", "1.2" ) < 0)
- return -1;
+ /* Attach the attribute "PAL_VERSION" to the >>palette<< dataset*/
+ if ( H5LTset_attribute_string( loc_id, pal_name, "PAL_VERSION", "1.2" ) < 0)
+ return -1;
- return 0;
+ return 0;
}
/*-------------------------------------------------------------------------
- * Function: H5IMlink_palette
- *
- * Purpose: This function attaches a palette to an existing image dataset
- *
- * Return: Success: 0, Failure: -1
- *
- * Programmer: Pedro Vicente Nunes, pvn@ncsa.uiuc.edu
- *
- * Date: May 01, 2001
- *
- * Comments:
- * based on HDF5 Image and Palette Specification
- * http://hdf.ncsa.uiuc.edu/HDF5/H5Image/ImageSpec.html
- *
- * An image (dataset) within an HDF5 file may optionally specify an array of
- * palettes to be viewed with. The dataset will have an attribute
- * which contains an array of object reference pointers which refer to palettes in the file.
- *
- * Modifications:
- *
- *-------------------------------------------------------------------------
- */
+* Function: H5IMlink_palette
+*
+* Purpose: This function attaches a palette to an existing image dataset
+*
+* Return: Success: 0, Failure: -1
+*
+* Programmer: Pedro Vicente Nunes, pvn@ncsa.uiuc.edu
+*
+* Date: May 01, 2001
+*
+* Comments:
+* based on HDF5 Image and Palette Specification
+* http://hdf.ncsa.uiuc.edu/HDF5/H5Image/ImageSpec.html
+*
+* An image (dataset) within an HDF5 file may optionally specify an array of
+* palettes to be viewed with. The dataset will have an attribute
+* which contains an array of object reference pointers which refer to palettes in the file.
+*
+* Modifications:
+*
+*-------------------------------------------------------------------------
+*/
herr_t H5IMlink_palette( hid_t loc_id,
- const char *image_name,
- const char *pal_name )
+ const char *image_name,
+ const char *pal_name )
{
- hid_t image_id;
- hid_t attr_type=-1;
- hid_t attr_id=-1;
- hid_t attr_space_id=-1;
- hid_t attr_class=-1;
- hobj_ref_t ref; /* write a new reference */
- hobj_ref_t *refbuf; /* buffer to read references */
- hssize_t n_refs;
- hsize_t dim_ref;
- int ok_pal;
-
- /* The image dataset may or may not have the attribute "PALETTE"
- * First we try to open to see if it is already there; if not, it is created.
- * If it exists, the array of references is extended to hold the reference
- * to the new palette
- */
-
- /* First we get the image id */
- if((image_id = H5Dopen2(loc_id, image_name, H5P_DEFAULT)) < 0)
- return -1;
-
- /* Try to find the attribute "PALETTE" on the >>image<< dataset */
- ok_pal = H5LT_find_attribute( image_id, "PALETTE" );
+ hid_t did;
+ hid_t atid=-1;
+ hid_t aid=-1;
+ hid_t asid=-1;
+ hobj_ref_t ref; /* write a new reference */
+ hobj_ref_t *refbuf; /* buffer to read references */
+ hssize_t n_refs;
+ hsize_t dim_ref;
+ int ok_pal;
+
+ /* The image dataset may or may not have the attribute "PALETTE"
+ * First we try to open to see if it is already there; if not, it is created.
+ * If it exists, the array of references is extended to hold the reference
+ * to the new palette
+ */
+
+ /* First we get the image id */
+ if((did = H5Dopen2(loc_id, image_name, H5P_DEFAULT)) < 0)
+ return -1;
+
+ /* Try to find the attribute "PALETTE" on the >>image<< dataset */
+ ok_pal = H5LT_find_attribute( did, "PALETTE" );
+
+ /*-------------------------------------------------------------------------
+ * It does not exist. We create the attribute and one reference
+ *-------------------------------------------------------------------------
+ */
+ if(ok_pal == 0 )
+ {
+ if((asid = H5Screate(H5S_SCALAR)) < 0)
+ goto out;
-/*-------------------------------------------------------------------------
- * It does not exist. We create the attribute and one reference
- *-------------------------------------------------------------------------
- */
- if(ok_pal == 0 )
- {
- if((attr_space_id = H5Screate(H5S_SCALAR)) < 0)
- goto out;
-
- /* Create the attribute type for the reference */
- if((attr_type = H5Tcopy(H5T_STD_REF_OBJ)) < 0)
- goto out;
-
- /* Create the attribute "PALETTE" to be attached to the image*/
- if((attr_id = H5Acreate2(image_id, "PALETTE", attr_type, attr_space_id, H5P_DEFAULT, H5P_DEFAULT)) < 0)
- goto out;
-
- /* Create a reference. The reference is created on the local id. */
- if(H5Rcreate(&ref, loc_id, pal_name, H5R_OBJECT, -1) < 0)
- goto out;
-
- /* Write the attribute with the reference */
- if(H5Awrite(attr_id, attr_type, &ref) < 0)
- goto out;
-
- /* close */
- if(H5Sclose(attr_space_id) < 0)
- goto out;
- if ( H5Tclose( attr_type ) < 0)
- goto out;
- if(H5Aclose(attr_id) < 0)
- goto out;
-
- }
+ /* Create the attribute type for the reference */
+ if((atid = H5Tcopy(H5T_STD_REF_OBJ)) < 0)
+ goto out;
-/*-------------------------------------------------------------------------
- * The attribute already exists, open it
- *-------------------------------------------------------------------------
- */
- else if(ok_pal == 1)
- {
- if((attr_id = H5Aopen(image_id, "PALETTE", H5P_DEFAULT)) < 0)
- goto out;
-
- if((attr_type = H5Aget_type(attr_id)) < 0)
- goto out;
-
- if((attr_class = H5Tget_class(attr_type)) < 0)
- goto out;
-
- /* Get and save the old reference(s) */
- if((attr_space_id = H5Aget_space(attr_id)) < 0)
- goto out;
-
- n_refs = H5Sget_simple_extent_npoints(attr_space_id);
-
- dim_ref = n_refs + 1;
-
- refbuf = malloc( sizeof(hobj_ref_t) * (int)dim_ref );
-
- if ( H5Aread( attr_id, attr_type, refbuf ) < 0)
- goto out;
-
- /* The attribute must be deleted, in order to the new one can reflect the changes*/
- if(H5Adelete(image_id, "PALETTE") < 0)
- goto out;
-
- /* Create a new reference for this palette. */
- if ( H5Rcreate( &ref, loc_id, pal_name, H5R_OBJECT, -1 ) < 0)
- goto out;
-
- refbuf[n_refs] = ref;
-
- /* Create the data space for the new references */
- if(H5Sclose(attr_space_id) < 0)
- goto out;
-
- if((attr_space_id = H5Screate_simple(1, &dim_ref, NULL)) < 0)
- goto out;
-
- /* Create the attribute again with the changes of space */
- if(H5Aclose(attr_id) < 0)
- goto out;
-
- if((attr_id = H5Acreate2(image_id, "PALETTE", attr_type, attr_space_id, H5P_DEFAULT, H5P_DEFAULT)) < 0)
- goto out;
-
- /* Write the attribute with the new references */
- if(H5Awrite(attr_id, attr_type, refbuf) < 0)
- goto out;
-
- /* close */
- if(H5Sclose(attr_space_id) < 0)
- goto out;
- if(H5Aclose(attr_id) < 0)
- goto out;
-
- free( refbuf );
-
- } /* ok_pal == 1 */
-
- /* Close the image dataset. */
- if ( H5Dclose( image_id ) < 0)
- return -1;
-
- return 0;
+ /* Create the attribute "PALETTE" to be attached to the image*/
+ if((aid = H5Acreate2(did, "PALETTE", atid, asid, H5P_DEFAULT, H5P_DEFAULT)) < 0)
+ goto out;
+
+ /* Create a reference. The reference is created on the local id. */
+ if(H5Rcreate(&ref, loc_id, pal_name, H5R_OBJECT, -1) < 0)
+ goto out;
+
+ /* Write the attribute with the reference */
+ if(H5Awrite(aid, atid, &ref) < 0)
+ goto out;
+
+ /* close */
+ if(H5Sclose(asid) < 0)
+ goto out;
+ if ( H5Tclose( atid ) < 0)
+ goto out;
+ if(H5Aclose(aid) < 0)
+ goto out;
+
+ }
+
+ /*-------------------------------------------------------------------------
+ * The attribute already exists, open it
+ *-------------------------------------------------------------------------
+ */
+ else if(ok_pal == 1)
+ {
+ if((aid = H5Aopen(did, "PALETTE", H5P_DEFAULT)) < 0)
+ goto out;
+
+ if((atid = H5Aget_type(aid)) < 0)
+ goto out;
+
+ if(H5Tget_class(atid) < 0)
+ goto out;
+
+ /* Get and save the old reference(s) */
+ if((asid = H5Aget_space(aid)) < 0)
+ goto out;
+
+ n_refs = H5Sget_simple_extent_npoints(asid);
+
+ dim_ref = n_refs + 1;
+
+ refbuf = (hobj_ref_t*)malloc( sizeof(hobj_ref_t) * (int)dim_ref );
+
+ if ( H5Aread( aid, atid, refbuf ) < 0)
+ goto out;
+
+ /* The attribute must be deleted, in order to the new one can reflect the changes*/
+ if(H5Adelete(did, "PALETTE") < 0)
+ goto out;
+
+ /* Create a new reference for this palette. */
+ if ( H5Rcreate( &ref, loc_id, pal_name, H5R_OBJECT, -1 ) < 0)
+ goto out;
+
+ refbuf[n_refs] = ref;
+
+ /* Create the data space for the new references */
+ if(H5Sclose(asid) < 0)
+ goto out;
+
+ if((asid = H5Screate_simple(1, &dim_ref, NULL)) < 0)
+ goto out;
+
+ /* Create the attribute again with the changes of space */
+ if(H5Aclose(aid) < 0)
+ goto out;
+
+ if((aid = H5Acreate2(did, "PALETTE", atid, asid, H5P_DEFAULT, H5P_DEFAULT)) < 0)
+ goto out;
+
+ /* Write the attribute with the new references */
+ if(H5Awrite(aid, atid, refbuf) < 0)
+ goto out;
+
+ /* close */
+ if(H5Sclose(asid) < 0)
+ goto out;
+ if(H5Aclose(aid) < 0)
+ goto out;
+
+ free( refbuf );
+
+ } /* ok_pal == 1 */
+
+ /* Close the image dataset. */
+ if ( H5Dclose( did ) < 0)
+ return -1;
+
+ return 0;
out:
- H5Dclose( image_id );
- H5Sclose( attr_space_id );
- H5Tclose( attr_type );
- H5Aclose( attr_id );
- return -1;
+ H5Dclose( did );
+ H5Sclose( asid );
+ H5Tclose( atid );
+ H5Aclose( aid );
+ return -1;
}
/*-------------------------------------------------------------------------
- * Function: H5IMunlink_palette
- *
- * Purpose: This function dettaches a palette from an existing image dataset
- *
- * Return: Success: 0, Failure: -1
- *
- * Programmer: Pedro Vicente Nunes, pvn@ncsa.uiuc.edu
- *
- * Date: September 10, 2001
- *
- * Comments:
- * based on HDF5 Image and Palette Specification
- * http://hdf.ncsa.uiuc.edu/HDF5/H5Image/ImageSpec.html
- *
- * Modifications:
- *
- *-------------------------------------------------------------------------
- */
+* Function: H5IMunlink_palette
+*
+* Purpose: This function dettaches a palette from an existing image dataset
+*
+* Return: Success: 0, Failure: -1
+*
+* Programmer: Pedro Vicente Nunes, pvn@ncsa.uiuc.edu
+*
+* Date: September 10, 2001
+*
+* Comments:
+* based on HDF5 Image and Palette Specification
+* http://hdf.ncsa.uiuc.edu/HDF5/H5Image/ImageSpec.html
+*
+* Modifications:
+*
+*-------------------------------------------------------------------------
+*/
herr_t H5IMunlink_palette( hid_t loc_id,
- const char *image_name,
- const char *pal_name )
+ const char *image_name,
+ const char *pal_name )
{
- hid_t image_id;
- hid_t attr_type;
- hid_t attr_id;
- hid_t attr_class;
- int ok_pal, has_pal;
+ hid_t did;
+ hid_t atid;
+ hid_t aid;
+ H5T_class_t aclass;
+ int ok_pal, has_pal;
- /* Try to find the palette dataset */
- has_pal = H5LTfind_dataset( loc_id, pal_name );
+ /* Try to find the palette dataset */
+ has_pal = H5LTfind_dataset( loc_id, pal_name );
- /* It does not exist. Return */
- if ( has_pal == 0 )
- return -1;
+ /* It does not exist. Return */
+ if ( has_pal == 0 )
+ return -1;
- /* The image dataset may or not have the attribute "PALETTE"
- * First we try to open to see if it is already there; if not, it is created.
- * If it exists, the array of references is extended to hold the reference
- * to the new palette
- */
+ /* The image dataset may or not have the attribute "PALETTE"
+ * First we try to open to see if it is already there; if not, it is created.
+ * If it exists, the array of references is extended to hold the reference
+ * to the new palette
+ */
- /* First we get the image id */
- if((image_id = H5Dopen2(loc_id, image_name, H5P_DEFAULT)) < 0)
- return -1;
+ /* First we get the image id */
+ if((did = H5Dopen2(loc_id, image_name, H5P_DEFAULT)) < 0)
+ return -1;
- /* Try to find the attribute "PALETTE" on the >>image<< dataset */
- ok_pal = H5LT_find_attribute(image_id, "PALETTE");
+ /* Try to find the attribute "PALETTE" on the >>image<< dataset */
+ ok_pal = H5LT_find_attribute(did, "PALETTE");
- /* It does not exist. Nothing to do */
- if(ok_pal == 0)
- return -1;
+ /* It does not exist. Nothing to do */
+ if(ok_pal == 0)
+ return -1;
- /* The attribute exists, open it */
- else if(ok_pal == 1)
- {
- if((attr_id = H5Aopen(image_id, "PALETTE", H5P_DEFAULT)) < 0)
- goto out;
+ /* The attribute exists, open it */
+ else if(ok_pal == 1)
+ {
+ if((aid = H5Aopen(did, "PALETTE", H5P_DEFAULT)) < 0)
+ goto out;
- if((attr_type = H5Aget_type(attr_id)) < 0)
- goto out;
+ if((atid = H5Aget_type(aid)) < 0)
+ goto out;
- if((attr_class = H5Tget_class(attr_type)) < 0)
- goto out;
+ if((aclass = H5Tget_class(atid)) < 0)
+ goto out;
- /* Check if it is really a reference */
- if(attr_class == H5T_REFERENCE)
- {
- /* Delete the attribute */
- if(H5Adelete(image_id, "PALETTE") < 0)
- goto out;
+ /* Check if it is really a reference */
+ if(aclass == H5T_REFERENCE)
+ {
+ /* Delete the attribute */
+ if(H5Adelete(did, "PALETTE") < 0)
+ goto out;
- } /* H5T_REFERENCE */
+ } /* H5T_REFERENCE */
- if(H5Tclose(attr_type) < 0)
- goto out;
+ if(H5Tclose(atid) < 0)
+ goto out;
- /* Close the attribute. */
- if(H5Aclose(attr_id) < 0)
- goto out;
+ /* Close the attribute. */
+ if(H5Aclose(aid) < 0)
+ goto out;
- } /* ok_pal */
+ } /* ok_pal */
- /* Close the image dataset. */
- if(H5Dclose(image_id) < 0)
- return -1;
+ /* Close the image dataset. */
+ if(H5Dclose(did) < 0)
+ return -1;
- return 0;
+ return 0;
out:
- H5Dclose( image_id );
- return -1;
+ H5Dclose( did );
+ return -1;
}
/*-------------------------------------------------------------------------
- * Function: H5IMget_npalettes
- *
- * Purpose: Gets the number of palettes associated to an image
- *
- * Return: Success: 0, Failure: -1
- *
- * Programmer: Pedro Vicente Nunes, pvn@ncsa.uiuc.edu
- *
- * Date: July 22, 2001
- *
- * Comments:
- *
- * Modifications:
- *
- *-------------------------------------------------------------------------
- */
+* Function: H5IMget_npalettes
+*
+* Purpose: Gets the number of palettes associated to an image
+*
+* Return: Success: 0, Failure: -1
+*
+* Programmer: Pedro Vicente Nunes, pvn@ncsa.uiuc.edu
+*
+* Date: July 22, 2001
+*
+* Comments:
+*
+* Modifications:
+*
+*-------------------------------------------------------------------------
+*/
herr_t H5IMget_npalettes( hid_t loc_id,
- const char *image_name,
- hssize_t *npals )
+ const char *image_name,
+ hssize_t *npals )
{
- hid_t image_id;
- hid_t attr_type;
- hid_t attr_id;
- hid_t attr_space_id;
- hid_t attr_class;
- int has_pal;
+ hid_t did;
+ hid_t atid;
+ hid_t aid;
+ hid_t asid;
+ H5T_class_t aclass;
+ int has_pal;
- /*assume initially we have no palettes attached*/
- *npals = 0;
+ /*assume initially we have no palettes attached*/
+ *npals = 0;
- /* Open the dataset. */
- if((image_id = H5Dopen2(loc_id, image_name, H5P_DEFAULT)) < 0)
- return -1;
+ /* Open the dataset. */
+ if((did = H5Dopen2(loc_id, image_name, H5P_DEFAULT)) < 0)
+ return -1;
- /* Try to find the attribute "PALETTE" on the >>image<< dataset */
- has_pal = H5IM_find_palette(image_id);
+ /* Try to find the attribute "PALETTE" on the >>image<< dataset */
+ has_pal = H5IM_find_palette(did);
- if(has_pal == 1 )
- {
+ if(has_pal == 1 )
+ {
- if((attr_id = H5Aopen(image_id, "PALETTE", H5P_DEFAULT)) < 0)
- goto out;
+ if((aid = H5Aopen(did, "PALETTE", H5P_DEFAULT)) < 0)
+ goto out;
- if((attr_type = H5Aget_type(attr_id)) < 0)
- goto out;
+ if((atid = H5Aget_type(aid)) < 0)
+ goto out;
- if((attr_class = H5Tget_class(attr_type)) < 0)
- goto out;
+ if((aclass = H5Tget_class(atid)) < 0)
+ goto out;
- /* Check if it is really a reference */
+ /* Check if it is really a reference */
- if(attr_class == H5T_REFERENCE)
- {
- if((attr_space_id = H5Aget_space(attr_id)) < 0)
- goto out;
+ if(aclass == H5T_REFERENCE)
+ {
+ if((asid = H5Aget_space(aid)) < 0)
+ goto out;
- *npals = H5Sget_simple_extent_npoints( attr_space_id );
+ *npals = H5Sget_simple_extent_npoints( asid );
- if ( H5Sclose( attr_space_id ) < 0)
- goto out;
+ if ( H5Sclose( asid ) < 0)
+ goto out;
- } /* H5T_REFERENCE */
+ } /* H5T_REFERENCE */
- if ( H5Tclose( attr_type ) < 0)
- goto out;
+ if ( H5Tclose( atid ) < 0)
+ goto out;
- /* Close the attribute. */
- if ( H5Aclose( attr_id ) < 0)
- goto out;
+ /* Close the attribute. */
+ if ( H5Aclose( aid ) < 0)
+ goto out;
- }
+ }
- /* Close the image dataset. */
- if ( H5Dclose( image_id ) < 0)
- return -1;
+ /* Close the image dataset. */
+ if ( H5Dclose( did ) < 0)
+ return -1;
- return 0;
+ return 0;
out:
- H5Dclose( image_id );
- return -1;
+ H5Dclose( did );
+ return -1;
}
/*-------------------------------------------------------------------------
- * Function: H5IMget_palette_info
- *
- * Purpose: Get palette information
- *
- * Return: Success: 0, Failure: -1
- *
- * Programmer: Pedro Vicente Nunes, pvn@ncsa.uiuc.edu
- *
- * Date: July 22, 2001
- *
- * Comments:
- * based on HDF5 Image and Palette Specification
- * http://hdf.ncsa.uiuc.edu/HDF5/H5Image/ImageSpec.html
- *
- * Modifications:
- *
- *-------------------------------------------------------------------------
- */
+* Function: H5IMget_palette_info
+*
+* Purpose: Get palette information
+*
+* Return: Success: 0, Failure: -1
+*
+* Programmer: Pedro Vicente Nunes, pvn@ncsa.uiuc.edu
+*
+* Date: July 22, 2001
+*
+* Comments:
+* based on HDF5 Image and Palette Specification
+* http://hdf.ncsa.uiuc.edu/HDF5/H5Image/ImageSpec.html
+*
+* Modifications:
+*
+*-------------------------------------------------------------------------
+*/
herr_t H5IMget_palette_info( hid_t loc_id,
- const char *image_name,
- int pal_number,
- hsize_t *pal_dims )
+ const char *image_name,
+ int pal_number,
+ hsize_t *pal_dims )
{
- hid_t image_id;
- int has_pal;
- hid_t attr_type=-1;
- hid_t attr_id;
- hid_t attr_space_id=-1;
- hid_t attr_class;
- hssize_t n_refs;
- hsize_t dim_ref;
- hobj_ref_t *refbuf; /* buffer to read references */
- hid_t pal_id;
- hid_t pal_space_id;
- hsize_t pal_maxdims[2];
-
- /* Open the dataset. */
- if((image_id = H5Dopen2(loc_id, image_name, H5P_DEFAULT)) < 0)
- return -1;
-
- /* Try to find the attribute "PALETTE" on the >>image<< dataset */
- has_pal = H5IM_find_palette(image_id);
-
- if(has_pal == 1)
- {
- if((attr_id = H5Aopen(image_id, "PALETTE", H5P_DEFAULT)) < 0)
- goto out;
-
- if((attr_type = H5Aget_type(attr_id)) < 0)
- goto out;
-
- if((attr_class = H5Tget_class(attr_type)) < 0)
- goto out;
-
- /* Get the reference(s) */
- if((attr_space_id = H5Aget_space(attr_id)) < 0)
- goto out;
-
- n_refs = H5Sget_simple_extent_npoints(attr_space_id);
-
- dim_ref = n_refs;
-
- refbuf = malloc( sizeof(hobj_ref_t) * (int)dim_ref );
-
- if ( H5Aread( attr_id, attr_type, refbuf ) < 0)
- goto out;
-
- /* Get the actual palette */
- if ( (pal_id = H5Rdereference( image_id, H5R_OBJECT, &refbuf[pal_number] )) < 0)
- goto out;
-
- if ( (pal_space_id = H5Dget_space( pal_id )) < 0)
- goto out;
-
- if ( H5Sget_simple_extent_ndims( pal_space_id ) < 0)
- goto out;
-
- if ( H5Sget_simple_extent_dims( pal_space_id, pal_dims, pal_maxdims ) < 0)
- goto out;
-
- /* close */
- if (H5Dclose(pal_id)<0)
- goto out;
- if ( H5Sclose( pal_space_id ) < 0)
- goto out;
- if ( H5Sclose( attr_space_id ) < 0)
- goto out;
- if ( H5Tclose( attr_type ) < 0)
- goto out;
- if ( H5Aclose( attr_id ) < 0)
- goto out;
- free( refbuf );
-
-
- }
-
- /* Close the image dataset. */
- if ( H5Dclose( image_id ) < 0)
- return -1;
-
- return 0;
-
+ hid_t did;
+ int has_pal;
+ hid_t atid=-1;
+ hid_t aid;
+ hid_t asid=-1;
+ hssize_t n_refs;
+ hsize_t dim_ref;
+ hobj_ref_t *refbuf; /* buffer to read references */
+ hid_t pal_id;
+ hid_t pal_space_id;
+ hsize_t pal_maxdims[2];
+
+ /* Open the dataset. */
+ if((did = H5Dopen2(loc_id, image_name, H5P_DEFAULT)) < 0)
+ return -1;
+
+ /* Try to find the attribute "PALETTE" on the >>image<< dataset */
+ has_pal = H5IM_find_palette(did);
+
+ if(has_pal == 1)
+ {
+ if((aid = H5Aopen(did, "PALETTE", H5P_DEFAULT)) < 0)
+ goto out;
+
+ if((atid = H5Aget_type(aid)) < 0)
+ goto out;
+
+ if(H5Tget_class(atid) < 0)
+ goto out;
+
+ /* Get the reference(s) */
+ if((asid = H5Aget_space(aid)) < 0)
+ goto out;
+
+ n_refs = H5Sget_simple_extent_npoints(asid);
+
+ dim_ref = n_refs;
+
+ refbuf = (hobj_ref_t*)malloc( sizeof(hobj_ref_t) * (int)dim_ref );
+
+ if ( H5Aread( aid, atid, refbuf ) < 0)
+ goto out;
+
+ /* Get the actual palette */
+ if ( (pal_id = H5Rdereference( did, H5R_OBJECT, &refbuf[pal_number] )) < 0)
+ goto out;
+
+ if ( (pal_space_id = H5Dget_space( pal_id )) < 0)
+ goto out;
+
+ if ( H5Sget_simple_extent_ndims( pal_space_id ) < 0)
+ goto out;
+
+ if ( H5Sget_simple_extent_dims( pal_space_id, pal_dims, pal_maxdims ) < 0)
+ goto out;
+
+ /* close */
+ if (H5Dclose(pal_id)<0)
+ goto out;
+ if ( H5Sclose( pal_space_id ) < 0)
+ goto out;
+ if ( H5Sclose( asid ) < 0)
+ goto out;
+ if ( H5Tclose( atid ) < 0)
+ goto out;
+ if ( H5Aclose( aid ) < 0)
+ goto out;
+ free( refbuf );
+
+
+ }
+
+ /* Close the image dataset. */
+ if ( H5Dclose( did ) < 0)
+ return -1;
+
+ return 0;
+
out:
- H5Dclose( image_id );
- H5Sclose( attr_space_id );
- H5Tclose( attr_type );
- H5Aclose( attr_id );
- return -1;
-
+ H5Dclose( did );
+ H5Sclose( asid );
+ H5Tclose( atid );
+ H5Aclose( aid );
+ return -1;
+
}
/*-------------------------------------------------------------------------
- * Function: H5IMget_palette
- *
- * Purpose: Read palette
- *
- * Return: Success: 0, Failure: -1
- *
- * Programmer: Pedro Vicente Nunes, pvn@ncsa.uiuc.edu
- *
- * Date: August 30, 2001
- *
- * Comments:
- * based on HDF5 Image and Palette Specification
- * http://hdf.ncsa.uiuc.edu/HDF5/H5Image/ImageSpec.html
- *
- * Modifications:
- *
- *-------------------------------------------------------------------------
- */
+* Function: H5IMget_palette
+*
+* Purpose: Read palette
+*
+* Return: Success: 0, Failure: -1
+*
+* Programmer: Pedro Vicente Nunes, pvn@ncsa.uiuc.edu
+*
+* Date: August 30, 2001
+*
+* Comments:
+* based on HDF5 Image and Palette Specification
+* http://hdf.ncsa.uiuc.edu/HDF5/H5Image/ImageSpec.html
+*
+* Modifications:
+*
+*-------------------------------------------------------------------------
+*/
herr_t H5IMget_palette( hid_t loc_id,
- const char *image_name,
- int pal_number,
- unsigned char *pal_data )
+ const char *image_name,
+ int pal_number,
+ unsigned char *pal_data )
{
- hid_t image_id;
- int has_pal;
- hid_t attr_type=-1;
- hid_t attr_id;
- hid_t attr_space_id=-1;
- hid_t attr_class;
- hssize_t n_refs;
- hsize_t dim_ref;
- hobj_ref_t *refbuf; /* buffer to read references */
- hid_t pal_id;
-
- /* Open the dataset. */
- if((image_id = H5Dopen2(loc_id, image_name, H5P_DEFAULT)) < 0)
- return -1;
-
- /* Try to find the attribute "PALETTE" on the >>image<< dataset */
- has_pal = H5IM_find_palette(image_id);
-
- if(has_pal == 1 )
- {
- if((attr_id = H5Aopen(image_id, "PALETTE", H5P_DEFAULT)) < 0)
- goto out;
-
- if((attr_type = H5Aget_type(attr_id)) < 0)
- goto out;
-
- if((attr_class = H5Tget_class(attr_type)) < 0)
- goto out;
-
- /* Get the reference(s) */
- if((attr_space_id = H5Aget_space(attr_id)) < 0)
- goto out;
-
- n_refs = H5Sget_simple_extent_npoints(attr_space_id);
-
- dim_ref = n_refs;
-
- refbuf = malloc( sizeof(hobj_ref_t) * (int)dim_ref );
-
- if ( H5Aread( attr_id, attr_type, refbuf ) < 0)
- goto out;
-
- /* Get the palette id */
- if ( (pal_id = H5Rdereference( image_id, H5R_OBJECT, &refbuf[pal_number] )) < 0)
- goto out;
-
- /* Read the palette dataset */
- if ( H5Dread( pal_id, H5Dget_type(pal_id), H5S_ALL, H5S_ALL, H5P_DEFAULT, pal_data ) < 0)
- goto out;
-
- /* close */
- if (H5Dclose(pal_id)<0)
- goto out;
- if ( H5Sclose( attr_space_id ) < 0)
- goto out;
- if ( H5Tclose( attr_type ) < 0)
- goto out;
- if ( H5Aclose( attr_id ) < 0)
- goto out;
- free( refbuf );
- }
-
- /* Close the image dataset. */
- if ( H5Dclose( image_id ) < 0)
- return -1;
-
- return 0;
+ hid_t did;
+ int has_pal;
+ hid_t atid=-1;
+ hid_t aid;
+ hid_t asid=-1;
+ hssize_t n_refs;
+ hsize_t dim_ref;
+ hobj_ref_t *refbuf; /* buffer to read references */
+ hid_t pal_id;
+
+ /* Open the dataset. */
+ if((did = H5Dopen2(loc_id, image_name, H5P_DEFAULT)) < 0)
+ return -1;
+
+ /* Try to find the attribute "PALETTE" on the >>image<< dataset */
+ has_pal = H5IM_find_palette(did);
+
+ if(has_pal == 1 )
+ {
+ if((aid = H5Aopen(did, "PALETTE", H5P_DEFAULT)) < 0)
+ goto out;
+
+ if((atid = H5Aget_type(aid)) < 0)
+ goto out;
+
+ if(H5Tget_class(atid) < 0)
+ goto out;
+
+ /* Get the reference(s) */
+ if((asid = H5Aget_space(aid)) < 0)
+ goto out;
+
+ n_refs = H5Sget_simple_extent_npoints(asid);
+
+ dim_ref = n_refs;
+
+ refbuf = (hobj_ref_t*)malloc( sizeof(hobj_ref_t) * (int)dim_ref );
+
+ if ( H5Aread( aid, atid, refbuf ) < 0)
+ goto out;
+
+ /* Get the palette id */
+ if ( (pal_id = H5Rdereference( did, H5R_OBJECT, &refbuf[pal_number] )) < 0)
+ goto out;
+
+ /* Read the palette dataset */
+ if ( H5Dread( pal_id, H5Dget_type(pal_id), H5S_ALL, H5S_ALL, H5P_DEFAULT, pal_data ) < 0)
+ goto out;
+
+ /* close */
+ if (H5Dclose(pal_id)<0)
+ goto out;
+ if ( H5Sclose( asid ) < 0)
+ goto out;
+ if ( H5Tclose( atid ) < 0)
+ goto out;
+ if ( H5Aclose( aid ) < 0)
+ goto out;
+ free( refbuf );
+ }
+
+ /* Close the image dataset. */
+ if ( H5Dclose( did ) < 0)
+ return -1;
+
+ return 0;
out:
- H5Dclose( image_id );
- H5Sclose( attr_space_id );
- H5Tclose( attr_type );
- H5Aclose( attr_id );
- return -1;
+ H5Dclose( did );
+ H5Sclose( asid );
+ H5Tclose( atid );
+ H5Aclose( aid );
+ return -1;
}
/*-------------------------------------------------------------------------
- * Function: H5IMis_image
- *
- * Purpose:
- *
- * Return: true, false, fail
- *
- * Programmer: Pedro Vicente Nunes, pvn@ncsa.uiuc.edu
- *
- * Date: August 30, 2001
- *
- * Comments:
- * based on HDF5 Image and Palette Specification
- * http://hdf.ncsa.uiuc.edu/HDF5/H5Image/ImageSpec.html
- *
- * Modifications:
- *
- *-------------------------------------------------------------------------
- */
+* Function: H5IMis_image
+*
+* Purpose:
+*
+* Return: true, false, fail
+*
+* Programmer: Pedro Vicente Nunes, pvn@ncsa.uiuc.edu
+*
+* Date: August 30, 2001
+*
+* Comments:
+* based on HDF5 Image and Palette Specification
+* http://hdf.ncsa.uiuc.edu/HDF5/H5Image/ImageSpec.html
+*
+* Modifications:
+*
+*-------------------------------------------------------------------------
+*/
herr_t H5IMis_image( hid_t loc_id,
- const char *dset_name )
+ const char *dset_name )
{
- hid_t did;
- int has_class;
- hid_t attr_type;
- hid_t attr_id;
- char attr_data[20];
- herr_t ret;
+ hid_t did;
+ int has_class;
+ hid_t atid;
+ hid_t aid;
+ char attr_data[20];
+ herr_t ret;
- /* Assume initially fail condition */
- ret = -1;
+ /* Assume initially fail condition */
+ ret = -1;
- /* Open the dataset. */
- if((did = H5Dopen2(loc_id, dset_name, H5P_DEFAULT)) < 0)
- return -1;
+ /* Open the dataset. */
+ if((did = H5Dopen2(loc_id, dset_name, H5P_DEFAULT)) < 0)
+ return -1;
- /* Try to find the attribute "CLASS" on the dataset */
- has_class = H5LT_find_attribute(did, "CLASS");
+ /* Try to find the attribute "CLASS" on the dataset */
+ has_class = H5LT_find_attribute(did, "CLASS");
- if(has_class == 0)
- {
- H5Dclose(did);
- return 0;
- }
- else if(has_class == 1)
- {
+ if(has_class == 0)
+ {
+ H5Dclose(did);
+ return 0;
+ }
+ else if(has_class == 1)
+ {
- if((attr_id = H5Aopen(did, "CLASS", H5P_DEFAULT)) < 0)
- goto out;
+ if((aid = H5Aopen(did, "CLASS", H5P_DEFAULT)) < 0)
+ goto out;
- if((attr_type = H5Aget_type(attr_id)) < 0)
- goto out;
+ if((atid = H5Aget_type(aid)) < 0)
+ goto out;
- if(H5Tget_class(attr_type) < 0)
- goto out;
+ if(H5Tget_class(atid) < 0)
+ goto out;
- if(H5Aread(attr_id, attr_type, attr_data) < 0)
- goto out;
+ if(H5Aread(aid, atid, attr_data) < 0)
+ goto out;
- if(strcmp(attr_data, IMAGE_CLASS) == 0)
- ret = 1;
- else
- ret = 0;
+ if(strcmp(attr_data, IMAGE_CLASS) == 0)
+ ret = 1;
+ else
+ ret = 0;
- if ( H5Tclose( attr_type ) < 0)
- goto out;
+ if ( H5Tclose( atid ) < 0)
+ goto out;
- if ( H5Aclose( attr_id ) < 0)
- goto out;
+ if ( H5Aclose( aid ) < 0)
+ goto out;
- }
+ }
- /* Close the dataset. */
- if ( H5Dclose( did ) < 0)
- return -1;
+ /* Close the dataset. */
+ if ( H5Dclose( did ) < 0)
+ return -1;
- return ret;
+ return ret;
out:
- H5Dclose( did );
- return -1;
+ H5Dclose( did );
+ return -1;
}
/*-------------------------------------------------------------------------
- * Function: H5IMis_palette
- *
- * Purpose:
- *
- * Return: true, false, fail
- *
- * Programmer: Pedro Vicente Nunes, pvn@ncsa.uiuc.edu
- *
- * Date: August 30, 2001
- *
- * Comments:
- * based on HDF5 Image and Palette Specification
- * http://hdf.ncsa.uiuc.edu/HDF5/H5Image/ImageSpec.html
- *
- * Modifications:
- *
- *-------------------------------------------------------------------------
- */
+* Function: H5IMis_palette
+*
+* Purpose:
+*
+* Return: true, false, fail
+*
+* Programmer: Pedro Vicente Nunes, pvn@ncsa.uiuc.edu
+*
+* Date: August 30, 2001
+*
+* Comments:
+* based on HDF5 Image and Palette Specification
+* http://hdf.ncsa.uiuc.edu/HDF5/H5Image/ImageSpec.html
+*
+* Modifications:
+*
+*-------------------------------------------------------------------------
+*/
herr_t H5IMis_palette( hid_t loc_id,
- const char *dset_name )
+ const char *dset_name )
{
- hid_t did;
- int has_class;
- hid_t attr_type;
- hid_t attr_id;
- char attr_data[20];
- herr_t ret;
+ hid_t did;
+ int has_class;
+ hid_t atid;
+ hid_t aid;
+ char attr_data[20];
+ herr_t ret;
- /* Assume initially fail condition */
- ret = -1;
+ /* Assume initially fail condition */
+ ret = -1;
- /* Open the dataset. */
- if((did = H5Dopen2(loc_id, dset_name, H5P_DEFAULT)) < 0)
- return -1;
+ /* Open the dataset. */
+ if((did = H5Dopen2(loc_id, dset_name, H5P_DEFAULT)) < 0)
+ return -1;
- /* Try to find the attribute "CLASS" on the dataset */
- has_class = H5LT_find_attribute(did, "CLASS");
+ /* Try to find the attribute "CLASS" on the dataset */
+ has_class = H5LT_find_attribute(did, "CLASS");
- if(has_class == 0)
- {
- H5Dclose( did );
- return 0;
- }
- else if(has_class == 1)
- {
+ if(has_class == 0)
+ {
+ H5Dclose( did );
+ return 0;
+ }
+ else if(has_class == 1)
+ {
- if((attr_id = H5Aopen(did, "CLASS", H5P_DEFAULT)) < 0)
- goto out;
+ if((aid = H5Aopen(did, "CLASS", H5P_DEFAULT)) < 0)
+ goto out;
- if((attr_type = H5Aget_type(attr_id)) < 0)
- goto out;
+ if((atid = H5Aget_type(aid)) < 0)
+ goto out;
- if(H5Tget_class(attr_type) < 0)
- goto out;
+ if(H5Tget_class(atid) < 0)
+ goto out;
- if(H5Aread(attr_id, attr_type, attr_data) < 0)
- goto out;
+ if(H5Aread(aid, atid, attr_data) < 0)
+ goto out;
- if(strcmp(attr_data, PALETTE_CLASS) == 0)
- ret = 1;
- else
- ret = 0;
+ if(strcmp(attr_data, PALETTE_CLASS) == 0)
+ ret = 1;
+ else
+ ret = 0;
- if ( H5Tclose( attr_type ) < 0)
- goto out;
+ if ( H5Tclose( atid ) < 0)
+ goto out;
- if ( H5Aclose( attr_id ) < 0)
- goto out;
+ if ( H5Aclose( aid ) < 0)
+ goto out;
- }
+ }
- /* Close the dataset. */
- if ( H5Dclose( did ) < 0)
- return -1;
+ /* Close the dataset. */
+ if ( H5Dclose( did ) < 0)
+ return -1;
- return ret;
+ return ret;
out:
- H5Dclose( did );
- return -1;
+ H5Dclose( did );
+ return -1;
}
diff --git a/hl/src/H5LT.c b/hl/src/H5LT.c
index 78df61a..c38d383 100644
--- a/hl/src/H5LT.c
+++ b/hl/src/H5LT.c
@@ -1,17 +1,17 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- * Copyright by The HDF Group. *
- * Copyright by the Board of Trustees of the University of Illinois. *
- * All rights reserved. *
- * *
- * This file is part of HDF5. The full HDF5 copyright notice, including *
- * terms governing use, modification, and redistribution, is contained in *
- * the files COPYING and Copyright.html. COPYING can be found at the root *
- * of the source code distribution tree; Copyright.html can be found at the *
- * root level of an installed copy of the electronic HDF5 document set and *
- * is linked from the top-level documents page. It can also be found at *
- * http://hdfgroup.org/HDF5/doc/Copyright.html. If you do not have *
- * access to either file, you may request a copy from help@hdfgroup.org. *
- * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
+* Copyright by The HDF Group. *
+* Copyright by the Board of Trustees of the University of Illinois. *
+* All rights reserved. *
+* *
+* This file is part of HDF5. The full HDF5 copyright notice, including *
+* terms governing use, modification, and redistribution, is contained in *
+* the files COPYING and Copyright.html. COPYING can be found at the root *
+* of the source code distribution tree; Copyright.html can be found at the *
+* root level of an installed copy of the electronic HDF5 document set and *
+* is linked from the top-level documents page. It can also be found at *
+* http://hdfgroup.org/HDF5/doc/Copyright.html. If you do not have *
+* access to either file, you may request a copy from help@hdfgroup.org. *
+* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#include <string.h>
#include <stdlib.h>
@@ -33,38 +33,38 @@ int indent = 0;
/*-------------------------------------------------------------------------
- *
- * internal functions
- *
- *-------------------------------------------------------------------------
- */
+*
+* internal functions
+*
+*-------------------------------------------------------------------------
+*/
static herr_t H5LT_get_attribute_mem(hid_t loc_id,
- const char *obj_name,
- const char *attr_name,
- hid_t mem_type_id,
- void *data);
-
-/*-------------------------------------------------------------------------
- * Function: H5LT_make_dataset
- *
- * Purpose: Creates and writes a dataset of a type tid
- *
- * Return: Success: 0, Failure: -1
- *
- * Programmer: Quincey Koziol, koziol@hdfgroup.org
- *
- * Date: October 10, 2007
- *
- *-------------------------------------------------------------------------
- */
+ const char *obj_name,
+ const char *attr_name,
+ hid_t mem_type_id,
+ void *data);
+
+/*-------------------------------------------------------------------------
+* Function: H5LT_make_dataset
+*
+* Purpose: Creates and writes a dataset of a type tid
+*
+* Return: Success: 0, Failure: -1
+*
+* Programmer: Quincey Koziol, koziol@hdfgroup.org
+*
+* Date: October 10, 2007
+*
+*-------------------------------------------------------------------------
+*/
static herr_t
H5LT_make_dataset_numerical( hid_t loc_id,
- const char *dset_name,
- int rank,
- const hsize_t *dims,
- hid_t tid,
- const void *data )
+ const char *dset_name,
+ int rank,
+ const hsize_t *dims,
+ hid_t tid,
+ const void *data )
{
hid_t did = -1, sid = -1;
@@ -100,124 +100,124 @@ out:
}
/*-------------------------------------------------------------------------
- *
- * Public functions
- *
- *-------------------------------------------------------------------------
- */
-
-/*-------------------------------------------------------------------------
- * Function: H5LTmake_dataset
- *
- * Purpose: Creates and writes a dataset of a type tid
- *
- * Return: Success: 0, Failure: -1
- *
- * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
- *
- * Date: March 19, 2001
- *
- * Comments:
- *
- * Modifications:
- *
- *
- *-------------------------------------------------------------------------
- */
+*
+* Public functions
+*
+*-------------------------------------------------------------------------
+*/
+
+/*-------------------------------------------------------------------------
+* Function: H5LTmake_dataset
+*
+* Purpose: Creates and writes a dataset of a type tid
+*
+* Return: Success: 0, Failure: -1
+*
+* Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
+*
+* Date: March 19, 2001
+*
+* Comments:
+*
+* Modifications:
+*
+*
+*-------------------------------------------------------------------------
+*/
herr_t H5LTmake_dataset( hid_t loc_id,
- const char *dset_name,
- int rank,
- const hsize_t *dims,
- hid_t tid,
- const void *data )
+ const char *dset_name,
+ int rank,
+ const hsize_t *dims,
+ hid_t tid,
+ const void *data )
{
return(H5LT_make_dataset_numerical(loc_id, dset_name, rank, dims, tid, data));
}
/*-------------------------------------------------------------------------
- * Function: H5LTmake_dataset_char
- *
- * Purpose: Creates and writes a dataset of H5T_NATIVE_CHAR type
- *
- * Return: Success: 0, Failure: -1
- *
- * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
- *
- * Date: September 14, 2001
- *
- * Comments:
- *
- * Modifications:
- *
- *
- *-------------------------------------------------------------------------
- */
+* Function: H5LTmake_dataset_char
+*
+* Purpose: Creates and writes a dataset of H5T_NATIVE_CHAR type
+*
+* Return: Success: 0, Failure: -1
+*
+* Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
+*
+* Date: September 14, 2001
+*
+* Comments:
+*
+* Modifications:
+*
+*
+*-------------------------------------------------------------------------
+*/
herr_t H5LTmake_dataset_char( hid_t loc_id,
- const char *dset_name,
- int rank,
- const hsize_t *dims,
- const char *data )
+ const char *dset_name,
+ int rank,
+ const hsize_t *dims,
+ const char *data )
{
return(H5LT_make_dataset_numerical(loc_id, dset_name, rank, dims, H5T_NATIVE_CHAR, data));
}
/*-------------------------------------------------------------------------
- * Function: H5LTmake_dataset_short
- *
- * Purpose: Creates and writes a dataset of H5T_NATIVE_SHORT type
- *
- * Return: Success: 0, Failure: -1
- *
- * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
- *
- * Date: September 14, 2001
- *
- * Comments:
- *
- * Modifications:
- *
- *
- *-------------------------------------------------------------------------
- */
+* Function: H5LTmake_dataset_short
+*
+* Purpose: Creates and writes a dataset of H5T_NATIVE_SHORT type
+*
+* Return: Success: 0, Failure: -1
+*
+* Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
+*
+* Date: September 14, 2001
+*
+* Comments:
+*
+* Modifications:
+*
+*
+*-------------------------------------------------------------------------
+*/
herr_t H5LTmake_dataset_short( hid_t loc_id,
- const char *dset_name,
- int rank,
- const hsize_t *dims,
- const short *data )
+ const char *dset_name,
+ int rank,
+ const hsize_t *dims,
+ const short *data )
{
return(H5LT_make_dataset_numerical(loc_id, dset_name, rank, dims, H5T_NATIVE_SHORT, data));
}
/*-------------------------------------------------------------------------
- * Function: H5LTmake_dataset_int
- *
- * Purpose: Creates and writes a dataset of H5T_NATIVE_INT type
- *
- * Return: Success: 0, Failure: -1
- *
- * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
- *
- * Date: September 14, 2001
- *
- * Comments:
- *
- * Modifications:
- *
- *
- *-------------------------------------------------------------------------
- */
+* Function: H5LTmake_dataset_int
+*
+* Purpose: Creates and writes a dataset of H5T_NATIVE_INT type
+*
+* Return: Success: 0, Failure: -1
+*
+* Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
+*
+* Date: September 14, 2001
+*
+* Comments:
+*
+* Modifications:
+*
+*
+*-------------------------------------------------------------------------
+*/
herr_t H5LTmake_dataset_int( hid_t loc_id,
- const char *dset_name,
- int rank,
- const hsize_t *dims,
- const int *data )
+ const char *dset_name,
+ int rank,
+ const hsize_t *dims,
+ const int *data )
{
return(H5LT_make_dataset_numerical(loc_id, dset_name, rank, dims, H5T_NATIVE_INT, data));
}
@@ -225,59 +225,59 @@ herr_t H5LTmake_dataset_int( hid_t loc_id,
/*-------------------------------------------------------------------------
- * Function: H5LTmake_dataset_long
- *
- * Purpose: Creates and writes a dataset of H5T_NATIVE_LONG type
- *
- * Return: Success: 0, Failure: -1
- *
- * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
- *
- * Date: September 14, 2001
- *
- * Comments:
- *
- * Modifications:
- *
- *
- *-------------------------------------------------------------------------
- */
+* Function: H5LTmake_dataset_long
+*
+* Purpose: Creates and writes a dataset of H5T_NATIVE_LONG type
+*
+* Return: Success: 0, Failure: -1
+*
+* Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
+*
+* Date: September 14, 2001
+*
+* Comments:
+*
+* Modifications:
+*
+*
+*-------------------------------------------------------------------------
+*/
herr_t H5LTmake_dataset_long( hid_t loc_id,
- const char *dset_name,
- int rank,
- const hsize_t *dims,
- const long *data )
+ const char *dset_name,
+ int rank,
+ const hsize_t *dims,
+ const long *data )
{
return(H5LT_make_dataset_numerical(loc_id, dset_name, rank, dims, H5T_NATIVE_LONG, data));
}
/*-------------------------------------------------------------------------
- * Function: H5LTmake_dataset_float
- *
- * Purpose: Creates and writes a dataset of H5T_NATIVE_FLOAT type
- *
- * Return: Success: 0, Failure: -1
- *
- * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
- *
- * Date: September 14, 2001
- *
- * Comments:
- *
- * Modifications:
- *
- *
- *-------------------------------------------------------------------------
- */
+* Function: H5LTmake_dataset_float
+*
+* Purpose: Creates and writes a dataset of H5T_NATIVE_FLOAT type
+*
+* Return: Success: 0, Failure: -1
+*
+* Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
+*
+* Date: September 14, 2001
+*
+* Comments:
+*
+* Modifications:
+*
+*
+*-------------------------------------------------------------------------
+*/
herr_t H5LTmake_dataset_float( hid_t loc_id,
- const char *dset_name,
- int rank,
- const hsize_t *dims,
- const float *data )
+ const char *dset_name,
+ int rank,
+ const hsize_t *dims,
+ const float *data )
{
return(H5LT_make_dataset_numerical(loc_id, dset_name, rank, dims, H5T_NATIVE_FLOAT, data));
}
@@ -285,53 +285,53 @@ herr_t H5LTmake_dataset_float( hid_t loc_id,
/*-------------------------------------------------------------------------
- * Function: H5LTmake_dataset_double
- *
- * Purpose: Creates and writes a dataset of H5T_NATIVE_DOUBLE type
- *
- * Return: Success: 0, Failure: -1
- *
- * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
- *
- * Date: September 14, 2001
- *
- * Comments:
- *
- * Modifications:
- *
- *
- *-------------------------------------------------------------------------
- */
+* Function: H5LTmake_dataset_double
+*
+* Purpose: Creates and writes a dataset of H5T_NATIVE_DOUBLE type
+*
+* Return: Success: 0, Failure: -1
+*
+* Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
+*
+* Date: September 14, 2001
+*
+* Comments:
+*
+* Modifications:
+*
+*
+*-------------------------------------------------------------------------
+*/
herr_t H5LTmake_dataset_double( hid_t loc_id,
- const char *dset_name,
- int rank,
- const hsize_t *dims,
- const double *data )
+ const char *dset_name,
+ int rank,
+ const hsize_t *dims,
+ const double *data )
{
return(H5LT_make_dataset_numerical(loc_id, dset_name, rank, dims, H5T_NATIVE_DOUBLE, data));
}
/*-------------------------------------------------------------------------
- * Function: H5LTmake_dataset_string
- *
- * Purpose: Creates and writes a dataset of H5T_C_S1 type
- *
- * Return: Success: 0, Failure: -1
- *
- * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
- *
- * Date: October 05, 2004
- *
- * Comments:
- *
- * Modifications:
- *
- *
- *-------------------------------------------------------------------------
- */
+* Function: H5LTmake_dataset_string
+*
+* Purpose: Creates and writes a dataset of H5T_C_S1 type
+*
+* Return: Success: 0, Failure: -1
+*
+* Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
+*
+* Date: October 05, 2004
+*
+* Comments:
+*
+* Modifications:
+*
+*
+*-------------------------------------------------------------------------
+*/
herr_t H5LTmake_dataset_string(hid_t loc_id,
@@ -389,18 +389,18 @@ out:
/*-------------------------------------------------------------------------
- * Function: H5LT_read_dataset
- *
- * Purpose: Reads a dataset from disk.
- *
- * Return: Success: 0, Failure: -1
- *
- * Programmer: Quincey Koziol, koziol@hdfgroup.org
- *
- * Date: October 8, 2007
- *
- *-------------------------------------------------------------------------
- */
+* Function: H5LT_read_dataset
+*
+* Purpose: Reads a dataset from disk.
+*
+* Return: Success: 0, Failure: -1
+*
+* Programmer: Quincey Koziol, koziol@hdfgroup.org
+*
+* Date: October 8, 2007
+*
+*-------------------------------------------------------------------------
+*/
static herr_t
H5LT_read_dataset_numerical(hid_t loc_id, const char *dset_name, hid_t tid, void *data)
@@ -427,18 +427,18 @@ out:
}
/*-------------------------------------------------------------------------
- * Function: H5LTread_dataset
- *
- * Purpose: Reads a dataset from disk.
- *
- * Return: Success: 0, Failure: -1
- *
- * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
- *
- * Date: June 13, 2001
- *
- *-------------------------------------------------------------------------
- */
+* Function: H5LTread_dataset
+*
+* Purpose: Reads a dataset from disk.
+*
+* Return: Success: 0, Failure: -1
+*
+* Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
+*
+* Date: June 13, 2001
+*
+*-------------------------------------------------------------------------
+*/
herr_t H5LTread_dataset(hid_t loc_id,
const char *dset_name,
@@ -450,150 +450,150 @@ herr_t H5LTread_dataset(hid_t loc_id,
/*-------------------------------------------------------------------------
- * Function: H5LTread_dataset_char
- *
- * Purpose: Reads a dataset from disk.
- *
- * Return: Success: 0, Failure: -1
- *
- * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
- *
- * Date: November 5, 2001
- *
- *-------------------------------------------------------------------------
- */
+* Function: H5LTread_dataset_char
+*
+* Purpose: Reads a dataset from disk.
+*
+* Return: Success: 0, Failure: -1
+*
+* Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
+*
+* Date: November 5, 2001
+*
+*-------------------------------------------------------------------------
+*/
herr_t H5LTread_dataset_char( hid_t loc_id,
- const char *dset_name,
- char *data )
+ const char *dset_name,
+ char *data )
{
return(H5LT_read_dataset_numerical(loc_id, dset_name, H5T_NATIVE_CHAR, data));
}
/*-------------------------------------------------------------------------
- * Function: H5LTread_dataset_short
- *
- * Purpose: Reads a dataset from disk.
- *
- * Return: Success: 0, Failure: -1
- *
- * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
- *
- * Date: November 5, 2001
- *
- *-------------------------------------------------------------------------
- */
+* Function: H5LTread_dataset_short
+*
+* Purpose: Reads a dataset from disk.
+*
+* Return: Success: 0, Failure: -1
+*
+* Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
+*
+* Date: November 5, 2001
+*
+*-------------------------------------------------------------------------
+*/
herr_t H5LTread_dataset_short( hid_t loc_id,
- const char *dset_name,
- short *data )
+ const char *dset_name,
+ short *data )
{
return(H5LT_read_dataset_numerical(loc_id, dset_name, H5T_NATIVE_SHORT, data));
}
/*-------------------------------------------------------------------------
- * Function: H5LTread_dataset_int
- *
- * Purpose: Reads a dataset from disk.
- *
- * Return: Success: 0, Failure: -1
- *
- * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
- *
- * Date: November 5, 2001
- *
- *-------------------------------------------------------------------------
- */
+* Function: H5LTread_dataset_int
+*
+* Purpose: Reads a dataset from disk.
+*
+* Return: Success: 0, Failure: -1
+*
+* Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
+*
+* Date: November 5, 2001
+*
+*-------------------------------------------------------------------------
+*/
herr_t H5LTread_dataset_int( hid_t loc_id,
- const char *dset_name,
- int *data )
+ const char *dset_name,
+ int *data )
{
return(H5LT_read_dataset_numerical(loc_id, dset_name, H5T_NATIVE_INT, data));
}
/*-------------------------------------------------------------------------
- * Function: H5LTread_dataset_long
- *
- * Purpose: Reads a dataset from disk.
- *
- * Return: Success: 0, Failure: -1
- *
- * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
- *
- * Date: November 5, 2001
- *
- *-------------------------------------------------------------------------
- */
+* Function: H5LTread_dataset_long
+*
+* Purpose: Reads a dataset from disk.
+*
+* Return: Success: 0, Failure: -1
+*
+* Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
+*
+* Date: November 5, 2001
+*
+*-------------------------------------------------------------------------
+*/
herr_t H5LTread_dataset_long( hid_t loc_id,
- const char *dset_name,
- long *data )
+ const char *dset_name,
+ long *data )
{
return(H5LT_read_dataset_numerical(loc_id, dset_name, H5T_NATIVE_LONG, data));
}
/*-------------------------------------------------------------------------
- * Function: H5LTread_dataset_float
- *
- * Purpose: Reads a dataset from disk.
- *
- * Return: Success: 0, Failure: -1
- *
- * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
- *
- * Date: November 5, 2001
- *
- *-------------------------------------------------------------------------
- */
+* Function: H5LTread_dataset_float
+*
+* Purpose: Reads a dataset from disk.
+*
+* Return: Success: 0, Failure: -1
+*
+* Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
+*
+* Date: November 5, 2001
+*
+*-------------------------------------------------------------------------
+*/
herr_t H5LTread_dataset_float( hid_t loc_id,
- const char *dset_name,
- float *data )
+ const char *dset_name,
+ float *data )
{
return(H5LT_read_dataset_numerical(loc_id, dset_name, H5T_NATIVE_FLOAT, data));
}
/*-------------------------------------------------------------------------
- * Function: H5LTread_dataset_double
- *
- * Purpose: Reads a dataset from disk.
- *
- * Return: Success: 0, Failure: -1
- *
- * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
- *
- * Date: November 5, 2001
- *
- *-------------------------------------------------------------------------
- */
+* Function: H5LTread_dataset_double
+*
+* Purpose: Reads a dataset from disk.
+*
+* Return: Success: 0, Failure: -1
+*
+* Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
+*
+* Date: November 5, 2001
+*
+*-------------------------------------------------------------------------
+*/
herr_t H5LTread_dataset_double( hid_t loc_id,
- const char *dset_name,
- double *data )
+ const char *dset_name,
+ double *data )
{
return(H5LT_read_dataset_numerical(loc_id, dset_name, H5T_NATIVE_DOUBLE, data));
}
/*-------------------------------------------------------------------------
- * Function: H5LTread_dataset_string
- *
- * Purpose: Reads a dataset
- *
- * Return: Success: 0, Failure: -1
- *
- * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
- *
- * Date: October 05, 2004
- *
- *-------------------------------------------------------------------------
- */
+* Function: H5LTread_dataset_string
+*
+* Purpose: Reads a dataset
+*
+* Return: Success: 0, Failure: -1
+*
+* Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
+*
+* Date: October 05, 2004
+*
+*-------------------------------------------------------------------------
+*/
herr_t H5LTread_dataset_string( hid_t loc_id,
- const char *dset_name,
- char *buf )
+ const char *dset_name,
+ char *buf )
{
hid_t did = -1;
hid_t tid = -1;
@@ -627,22 +627,22 @@ out:
/*-------------------------------------------------------------------------
- * Function: H5LTget_dataset_ndims
- *
- * Purpose: Gets the dimensionality of a dataset.
- *
- * Return: Success: 0, Failure: -1
- *
- * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
- *
- * Date: September 4, 2001
- *
- *-------------------------------------------------------------------------
- */
+* Function: H5LTget_dataset_ndims
+*
+* Purpose: Gets the dimensionality of a dataset.
+*
+* Return: Success: 0, Failure: -1
+*
+* Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
+*
+* Date: September 4, 2001
+*
+*-------------------------------------------------------------------------
+*/
herr_t H5LTget_dataset_ndims( hid_t loc_id,
- const char *dset_name,
- int *rank )
+ const char *dset_name,
+ int *rank )
{
hid_t did = -1;
hid_t sid = -1;
@@ -679,25 +679,25 @@ out:
/*-------------------------------------------------------------------------
- * Function: H5LTget_dataset_info
- *
- * Purpose: Gets information about a dataset.
- *
- * Return: Success: 0, Failure: -1
- *
- * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
- *
- * Date: September 4, 2001
- * Modified: February 28, 2006: checked for NULL parameters
- *
- *-------------------------------------------------------------------------
- */
+* Function: H5LTget_dataset_info
+*
+* Purpose: Gets information about a dataset.
+*
+* Return: Success: 0, Failure: -1
+*
+* Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
+*
+* Date: September 4, 2001
+* Modified: February 28, 2006: checked for NULL parameters
+*
+*-------------------------------------------------------------------------
+*/
herr_t H5LTget_dataset_info( hid_t loc_id,
- const char *dset_name,
- hsize_t *dims,
- H5T_class_t *type_class,
- size_t *type_size )
+ const char *dset_name,
+ hsize_t *dims,
+ H5T_class_t *type_class,
+ size_t *type_size )
{
hid_t did = -1;
hid_t tid = -1;
@@ -753,27 +753,27 @@ out:
}
/*-------------------------------------------------------------------------
- * Function: find_dataset
- *
- * Purpose: operator function used by H5LTfind_dataset
- *
- * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
- *
- * Date: June 21, 2001
- *
- * Comments:
- *
- * Modifications:
- *
- *-------------------------------------------------------------------------
- */
+* Function: find_dataset
+*
+* Purpose: operator function used by H5LTfind_dataset
+*
+* Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
+*
+* Date: June 21, 2001
+*
+* Comments:
+*
+* Modifications:
+*
+*-------------------------------------------------------------------------
+*/
static herr_t
find_dataset(hid_t loc_id, const char *name, const H5L_info_t *linfo, void *op_data)
{
/* Define a default zero value for return. This will cause the iterator to continue if
- * the dataset is not found yet.
- */
+ * the dataset is not found yet.
+ */
int ret = 0;
/* Shut the compiler up */
@@ -781,9 +781,9 @@ find_dataset(hid_t loc_id, const char *name, const H5L_info_t *linfo, void *op_d
linfo = linfo;
/* Define a positive value for return value if the dataset was found. This will
- * cause the iterator to immediately return that positive value,
- * indicating short-circuit success
- */
+ * cause the iterator to immediately return that positive value,
+ * indicating short-circuit success
+ */
if(strcmp(name, (char *)op_data) == 0)
ret = 1;
@@ -792,26 +792,26 @@ find_dataset(hid_t loc_id, const char *name, const H5L_info_t *linfo, void *op_d
/*-------------------------------------------------------------------------
- * Function: H5LTfind_dataset
- *
- * Purpose: Inquires if a dataset named dset_name exists attached
- * to the object loc_id.
- *
- * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
- *
- * Date: July 15, 2001
- *
- * Return:
- * Success: The return value of the first operator that
- * returns non-zero, or zero if all members were
- * processed with no operator returning non-zero.
- *
- * Failure: Negative if something goes wrong within the
- * library, or the negative value returned by one
- * of the operators.
- *
- *-------------------------------------------------------------------------
- */
+* Function: H5LTfind_dataset
+*
+* Purpose: Inquires if a dataset named dset_name exists attached
+* to the object loc_id.
+*
+* Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
+*
+* Date: July 15, 2001
+*
+* Return:
+* Success: The return value of the first operator that
+* returns non-zero, or zero if all members were
+* processed with no operator returning non-zero.
+*
+* Failure: Negative if something goes wrong within the
+* library, or the negative value returned by one
+* of the operators.
+*
+*-------------------------------------------------------------------------
+*/
herr_t
H5LTfind_dataset( hid_t loc_id, const char *dset_name )
@@ -821,98 +821,98 @@ H5LTfind_dataset( hid_t loc_id, const char *dset_name )
/*-------------------------------------------------------------------------
- *
- * Set attribute functions
- *
- *-------------------------------------------------------------------------
- */
+*
+* Set attribute functions
+*
+*-------------------------------------------------------------------------
+*/
/*-------------------------------------------------------------------------
- * Function: H5LTset_attribute_string
- *
- * Purpose: Creates and writes a string attribute named attr_name and attaches
- * it to the object specified by the name obj_name.
- *
- * Return: Success: 0, Failure: -1
- *
- * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
- *
- * Date: July 23, 2001
- *
- * Comments: If the attribute already exists, it is overwritten
- *
- * Modifications:
- *
- *-------------------------------------------------------------------------
- */
+* Function: H5LTset_attribute_string
+*
+* Purpose: Creates and writes a string attribute named attr_name and attaches
+* it to the object specified by the name obj_name.
+*
+* Return: Success: 0, Failure: -1
+*
+* Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
+*
+* Date: July 23, 2001
+*
+* Comments: If the attribute already exists, it is overwritten
+*
+* Modifications:
+*
+*-------------------------------------------------------------------------
+*/
herr_t H5LTset_attribute_string( hid_t loc_id,
- const char *obj_name,
- const char *attr_name,
- const char *attr_data )
+ const char *obj_name,
+ const char *attr_name,
+ const char *attr_data )
{
- hid_t attr_type;
- hid_t attr_space_id;
- hid_t attr_id;
- hid_t obj_id;
- int has_attr;
- size_t attr_size;
+ hid_t attr_type;
+ hid_t attr_space_id;
+ hid_t attr_id;
+ hid_t obj_id;
+ int has_attr;
+ size_t attr_size;
- /* Open the object */
- if ((obj_id = H5Oopen(loc_id, obj_name, H5P_DEFAULT)) < 0)
- return -1;
+ /* Open the object */
+ if ((obj_id = H5Oopen(loc_id, obj_name, H5P_DEFAULT)) < 0)
+ return -1;
- /* Create the attribute */
- if ( (attr_type = H5Tcopy( H5T_C_S1 )) < 0 )
- goto out;
+ /* Create the attribute */
+ if ( (attr_type = H5Tcopy( H5T_C_S1 )) < 0 )
+ goto out;
- attr_size = strlen( attr_data ) + 1; /* extra null term */
+ attr_size = strlen( attr_data ) + 1; /* extra null term */
- if ( H5Tset_size( attr_type, (size_t)attr_size) < 0 )
- goto out;
+ if ( H5Tset_size( attr_type, (size_t)attr_size) < 0 )
+ goto out;
- if ( H5Tset_strpad( attr_type, H5T_STR_NULLTERM ) < 0 )
- goto out;
+ if ( H5Tset_strpad( attr_type, H5T_STR_NULLTERM ) < 0 )
+ goto out;
- if ( (attr_space_id = H5Screate( H5S_SCALAR )) < 0 )
- goto out;
+ if ( (attr_space_id = H5Screate( H5S_SCALAR )) < 0 )
+ goto out;
- /* Verify if the attribute already exists */
- has_attr = H5LT_find_attribute(obj_id, attr_name);
+ /* Verify if the attribute already exists */
+ has_attr = H5LT_find_attribute(obj_id, attr_name);
- /* The attribute already exists, delete it */
- if(has_attr == 1)
- if(H5Adelete(obj_id, attr_name) < 0)
- goto out;
+ /* The attribute already exists, delete it */
+ if(has_attr == 1)
+ if(H5Adelete(obj_id, attr_name) < 0)
+ goto out;
- /* Create and write the attribute */
+ /* Create and write the attribute */
- if((attr_id = H5Acreate2(obj_id, attr_name, attr_type, attr_space_id, H5P_DEFAULT, H5P_DEFAULT)) < 0)
- goto out;
+ if((attr_id = H5Acreate2(obj_id, attr_name, attr_type, attr_space_id, H5P_DEFAULT, H5P_DEFAULT)) < 0)
+ goto out;
- if(H5Awrite(attr_id, attr_type, attr_data) < 0)
- goto out;
+ if(H5Awrite(attr_id, attr_type, attr_data) < 0)
+ goto out;
- if(H5Aclose(attr_id) < 0)
- goto out;
+ if(H5Aclose(attr_id) < 0)
+ goto out;
- if(H5Sclose(attr_space_id) < 0)
- goto out;
+ if(H5Sclose(attr_space_id) < 0)
+ goto out;
- if(H5Tclose(attr_type) < 0)
- goto out;
+ if(H5Tclose(attr_type) < 0)
+ goto out;
- /* Close the object */
- if(H5Oclose(obj_id) < 0)
- return -1;
+ /* Close the object */
+ if(H5Oclose(obj_id) < 0)
+ return -1;
- return 0;
+ return 0;
out:
- H5Oclose(obj_id);
- return -1;
+ H5Oclose(obj_id);
+ return -1;
}
@@ -920,185 +920,185 @@ out:
/*-------------------------------------------------------------------------
- * Function: H5LT_set_attribute_numerical
- *
- * Purpose: Private function used by H5LTset_attribute_int and H5LTset_attribute_float
- *
- * Return: Success: 0, Failure: -1
- *
- * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
- *
- * Date: July 25, 2001
- *
- * Comments:
- *
- *-------------------------------------------------------------------------
- */
+* Function: H5LT_set_attribute_numerical
+*
+* Purpose: Private function used by H5LTset_attribute_int and H5LTset_attribute_float
+*
+* Return: Success: 0, Failure: -1
+*
+* Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
+*
+* Date: July 25, 2001
+*
+* Comments:
+*
+*-------------------------------------------------------------------------
+*/
herr_t H5LT_set_attribute_numerical( hid_t loc_id,
- const char *obj_name,
- const char *attr_name,
- size_t size,
- hid_t tid,
- const void *data )
+ const char *obj_name,
+ const char *attr_name,
+ size_t size,
+ hid_t tid,
+ const void *data )
{
- hid_t obj_id, sid, attr_id;
- hsize_t dim_size=size;
- int has_attr;
+ hid_t obj_id, sid, attr_id;
+ hsize_t dim_size=size;
+ int has_attr;
- /* Open the object */
- if ((obj_id = H5Oopen(loc_id, obj_name, H5P_DEFAULT)) < 0)
- return -1;
+ /* Open the object */
+ if ((obj_id = H5Oopen(loc_id, obj_name, H5P_DEFAULT)) < 0)
+ return -1;
- /* Create the data space for the attribute. */
- if ( (sid = H5Screate_simple( 1, &dim_size, NULL )) < 0 )
- goto out;
+ /* Create the data space for the attribute. */
+ if ( (sid = H5Screate_simple( 1, &dim_size, NULL )) < 0 )
+ goto out;
- /* Verify if the attribute already exists */
- has_attr = H5LT_find_attribute(obj_id, attr_name);
+ /* Verify if the attribute already exists */
+ has_attr = H5LT_find_attribute(obj_id, attr_name);
- /* The attribute already exists, delete it */
- if(has_attr == 1)
- if(H5Adelete(obj_id, attr_name) < 0)
- goto out;
+ /* The attribute already exists, delete it */
+ if(has_attr == 1)
+ if(H5Adelete(obj_id, attr_name) < 0)
+ goto out;
- /* Create the attribute. */
- if((attr_id = H5Acreate2(obj_id, attr_name, tid, sid, H5P_DEFAULT, H5P_DEFAULT)) < 0)
- goto out;
+ /* Create the attribute. */
+ if((attr_id = H5Acreate2(obj_id, attr_name, tid, sid, H5P_DEFAULT, H5P_DEFAULT)) < 0)
+ goto out;
- /* Write the attribute data. */
- if(H5Awrite(attr_id, tid, data) < 0)
- goto out;
+ /* Write the attribute data. */
+ if(H5Awrite(attr_id, tid, data) < 0)
+ goto out;
- /* Close the attribute. */
- if(H5Aclose(attr_id) < 0)
- goto out;
+ /* Close the attribute. */
+ if(H5Aclose(attr_id) < 0)
+ goto out;
- /* Close the dataspace. */
- if(H5Sclose(sid) < 0)
- goto out;
+ /* Close the dataspace. */
+ if(H5Sclose(sid) < 0)
+ goto out;
- /* Close the object */
- if(H5Oclose(obj_id) < 0)
- return -1;
+ /* Close the object */
+ if(H5Oclose(obj_id) < 0)
+ return -1;
- return 0;
+ return 0;
out:
- H5Oclose(obj_id);
- return -1;
+ H5Oclose(obj_id);
+ return -1;
}
/*-------------------------------------------------------------------------
- * Function: H5LTset_attribute_char
- *
- * Purpose: Create and write an attribute.
- *
- * Return: Success: 0, Failure: -1
- *
- * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
- *
- * Date: November 7, 2001
- *
- * Comments:
- *
- *-------------------------------------------------------------------------
- */
+* Function: H5LTset_attribute_char
+*
+* Purpose: Create and write an attribute.
+*
+* Return: Success: 0, Failure: -1
+*
+* Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
+*
+* Date: November 7, 2001
+*
+* Comments:
+*
+*-------------------------------------------------------------------------
+*/
herr_t H5LTset_attribute_char( hid_t loc_id,
- const char *obj_name,
- const char *attr_name,
- const char *data,
- size_t size )
+ const char *obj_name,
+ const char *attr_name,
+ const char *data,
+ size_t size )
{
- if ( H5LT_set_attribute_numerical( loc_id, obj_name, attr_name, size,
- H5T_NATIVE_CHAR, data ) < 0 )
- return -1;
+ if ( H5LT_set_attribute_numerical( loc_id, obj_name, attr_name, size,
+ H5T_NATIVE_CHAR, data ) < 0 )
+ return -1;
- return 0;
+ return 0;
}
/*-------------------------------------------------------------------------
- * Function: H5LTset_attribute_uchar
- *
- * Purpose: Create and write an attribute.
- *
- * Return: Success: 0, Failure: -1
- *
- * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
- *
- * Date: March 8, 2004
- *
- * Comments:
- *
- *-------------------------------------------------------------------------
- */
+* Function: H5LTset_attribute_uchar
+*
+* Purpose: Create and write an attribute.
+*
+* Return: Success: 0, Failure: -1
+*
+* Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
+*
+* Date: March 8, 2004
+*
+* Comments:
+*
+*-------------------------------------------------------------------------
+*/
herr_t H5LTset_attribute_uchar( hid_t loc_id,
- const char *obj_name,
- const char *attr_name,
- const unsigned char *data,
- size_t size )
+ const char *obj_name,
+ const char *attr_name,
+ const unsigned char *data,
+ size_t size )
{
- if ( H5LT_set_attribute_numerical( loc_id, obj_name, attr_name, size,
- H5T_NATIVE_UCHAR, data ) < 0 )
- return -1;
+ if ( H5LT_set_attribute_numerical( loc_id, obj_name, attr_name, size,
+ H5T_NATIVE_UCHAR, data ) < 0 )
+ return -1;
- return 0;
+ return 0;
}
/*-------------------------------------------------------------------------
- * Function: H5LTset_attribute_short
- *
- * Purpose: Create and write an attribute.
- *
- * Return: Success: 0, Failure: -1
- *
- * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
- *
- * Date: November 7, 2001
- *
- * Comments:
- *
- *-------------------------------------------------------------------------
- */
+* Function: H5LTset_attribute_short
+*
+* Purpose: Create and write an attribute.
+*
+* Return: Success: 0, Failure: -1
+*
+* Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
+*
+* Date: November 7, 2001
+*
+* Comments:
+*
+*-------------------------------------------------------------------------
+*/
herr_t H5LTset_attribute_short( hid_t loc_id,
- const char *obj_name,
- const char *attr_name,
- const short *data,
- size_t size )
+ const char *obj_name,
+ const char *attr_name,
+ const short *data,
+ size_t size )
{
- if ( H5LT_set_attribute_numerical( loc_id, obj_name, attr_name, size,
- H5T_NATIVE_SHORT, data ) < 0 )
- return -1;
+ if ( H5LT_set_attribute_numerical( loc_id, obj_name, attr_name, size,
+ H5T_NATIVE_SHORT, data ) < 0 )
+ return -1;
- return 0;
+ return 0;
}
/*-------------------------------------------------------------------------
- * Function: H5LTset_attribute_ushort
- *
- * Purpose: Create and write an attribute.
- *
- * Return: Success: 0, Failure: -1
- *
- * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
- *
- * Date: March 8, 2004
- *
- * Comments:
- *
- *-------------------------------------------------------------------------
- */
+* Function: H5LTset_attribute_ushort
+*
+* Purpose: Create and write an attribute.
+*
+* Return: Success: 0, Failure: -1
+*
+* Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
+*
+* Date: March 8, 2004
+*
+* Comments:
+*
+*-------------------------------------------------------------------------
+*/
herr_t H5LTset_attribute_ushort( hid_t loc_id,
const char *obj_name,
@@ -1107,60 +1107,60 @@ herr_t H5LTset_attribute_ushort( hid_t loc_id,
size_t size )
{
- if ( H5LT_set_attribute_numerical( loc_id, obj_name, attr_name, size,
- H5T_NATIVE_USHORT, data ) < 0 )
- return -1;
+ if ( H5LT_set_attribute_numerical( loc_id, obj_name, attr_name, size,
+ H5T_NATIVE_USHORT, data ) < 0 )
+ return -1;
- return 0;
+ return 0;
}
/*-------------------------------------------------------------------------
- * Function: H5LTset_attribute_int
- *
- * Purpose: Create and write an attribute.
- *
- * Return: Success: 0, Failure: -1
- *
- * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
- *
- * Date: November 7, 2001
- *
- * Comments:
- *
- *-------------------------------------------------------------------------
- */
+* Function: H5LTset_attribute_int
+*
+* Purpose: Create and write an attribute.
+*
+* Return: Success: 0, Failure: -1
+*
+* Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
+*
+* Date: November 7, 2001
+*
+* Comments:
+*
+*-------------------------------------------------------------------------
+*/
herr_t H5LTset_attribute_int( hid_t loc_id,
- const char *obj_name,
- const char *attr_name,
- const int *data,
- size_t size )
+ const char *obj_name,
+ const char *attr_name,
+ const int *data,
+ size_t size )
{
- if ( H5LT_set_attribute_numerical( loc_id, obj_name, attr_name, size,
- H5T_NATIVE_INT, data ) < 0 )
- return -1;
+ if ( H5LT_set_attribute_numerical( loc_id, obj_name, attr_name, size,
+ H5T_NATIVE_INT, data ) < 0 )
+ return -1;
- return 0;
+ return 0;
}
/*-------------------------------------------------------------------------
- * Function: H5LTset_attribute_uint
- *
- * Purpose: Create and write an attribute.
- *
- * Return: Success: 0, Failure: -1
- *
- * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
- *
- * Date: March 8, 2004
- *
- * Comments:
- *
- *-------------------------------------------------------------------------
- */
+* Function: H5LTset_attribute_uint
+*
+* Purpose: Create and write an attribute.
+*
+* Return: Success: 0, Failure: -1
+*
+* Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
+*
+* Date: March 8, 2004
+*
+* Comments:
+*
+*-------------------------------------------------------------------------
+*/
herr_t H5LTset_attribute_uint( hid_t loc_id,
const char *obj_name,
@@ -1169,92 +1169,92 @@ herr_t H5LTset_attribute_uint( hid_t loc_id,
size_t size )
{
- if ( H5LT_set_attribute_numerical( loc_id, obj_name, attr_name, size,
- H5T_NATIVE_UINT, data ) < 0 )
- return -1;
+ if ( H5LT_set_attribute_numerical( loc_id, obj_name, attr_name, size,
+ H5T_NATIVE_UINT, data ) < 0 )
+ return -1;
- return 0;
+ return 0;
}
/*-------------------------------------------------------------------------
- * Function: H5LTset_attribute_long
- *
- * Purpose: Create and write an attribute.
- *
- * Return: Success: 0, Failure: -1
- *
- * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
- *
- * Date: November 7, 2001
- *
- * Comments:
- *
- *-------------------------------------------------------------------------
- */
+* Function: H5LTset_attribute_long
+*
+* Purpose: Create and write an attribute.
+*
+* Return: Success: 0, Failure: -1
+*
+* Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
+*
+* Date: November 7, 2001
+*
+* Comments:
+*
+*-------------------------------------------------------------------------
+*/
herr_t H5LTset_attribute_long( hid_t loc_id,
- const char *obj_name,
- const char *attr_name,
- const long *data,
- size_t size )
+ const char *obj_name,
+ const char *attr_name,
+ const long *data,
+ size_t size )
{
- if ( H5LT_set_attribute_numerical( loc_id, obj_name, attr_name, size,
- H5T_NATIVE_LONG, data ) < 0 )
- return -1;
+ if ( H5LT_set_attribute_numerical( loc_id, obj_name, attr_name, size,
+ H5T_NATIVE_LONG, data ) < 0 )
+ return -1;
- return 0;
+ return 0;
}
/*-------------------------------------------------------------------------
- * Function: H5LTset_attribute_long_long
- *
- * Purpose: Create and write an attribute.
- *
- * Return: Success: 0, Failure: -1
- *
- * Programmer: Elena Pourmal, epourmal@ncsa.uiuc.edu
- *
- * Date: June 17, 2005
- *
- * Comments: This function was added to support attributes of type long long
- *
- *-------------------------------------------------------------------------
- */
+* Function: H5LTset_attribute_long_long
+*
+* Purpose: Create and write an attribute.
+*
+* Return: Success: 0, Failure: -1
+*
+* Programmer: Elena Pourmal, epourmal@ncsa.uiuc.edu
+*
+* Date: June 17, 2005
+*
+* Comments: This function was added to support attributes of type long long
+*
+*-------------------------------------------------------------------------
+*/
herr_t H5LTset_attribute_long_long( hid_t loc_id,
- const char *obj_name,
- const char *attr_name,
- const long_long *data,
- size_t size )
+ const char *obj_name,
+ const char *attr_name,
+ const long long *data,
+ size_t size )
{
- if ( H5LT_set_attribute_numerical( loc_id, obj_name, attr_name, size,
- H5T_NATIVE_LLONG, data ) < 0 )
- return -1;
+ if ( H5LT_set_attribute_numerical( loc_id, obj_name, attr_name, size,
+ H5T_NATIVE_LLONG, data ) < 0 )
+ return -1;
- return 0;
+ return 0;
}
/*-------------------------------------------------------------------------
- * Function: H5LTset_attribute_ulong
- *
- * Purpose: Create and write an attribute.
- *
- * Return: Success: 0, Failure: -1
- *
- * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
- *
- * Date: March 8, 2004
- *
- * Comments:
- *
- *-------------------------------------------------------------------------
- */
+* Function: H5LTset_attribute_ulong
+*
+* Purpose: Create and write an attribute.
+*
+* Return: Success: 0, Failure: -1
+*
+* Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
+*
+* Date: March 8, 2004
+*
+* Comments:
+*
+*-------------------------------------------------------------------------
+*/
herr_t H5LTset_attribute_ulong( hid_t loc_id,
const char *obj_name,
@@ -1263,99 +1263,99 @@ herr_t H5LTset_attribute_ulong( hid_t loc_id,
size_t size )
{
- if ( H5LT_set_attribute_numerical( loc_id, obj_name, attr_name, size,
- H5T_NATIVE_ULONG, data ) < 0 )
- return -1;
+ if ( H5LT_set_attribute_numerical( loc_id, obj_name, attr_name, size,
+ H5T_NATIVE_ULONG, data ) < 0 )
+ return -1;
- return 0;
+ return 0;
}
/*-------------------------------------------------------------------------
- * Function: H5LTset_attribute_float
- *
- * Purpose: Create and write an attribute.
- *
- * Return: Success: 0, Failure: -1
- *
- * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
- *
- * Date: July 25, 2001
- *
- * Comments:
- *
- *-------------------------------------------------------------------------
- */
+* Function: H5LTset_attribute_float
+*
+* Purpose: Create and write an attribute.
+*
+* Return: Success: 0, Failure: -1
+*
+* Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
+*
+* Date: July 25, 2001
+*
+* Comments:
+*
+*-------------------------------------------------------------------------
+*/
herr_t H5LTset_attribute_float( hid_t loc_id,
- const char *obj_name,
- const char *attr_name,
- const float *data,
- size_t size )
+ const char *obj_name,
+ const char *attr_name,
+ const float *data,
+ size_t size )
{
- if ( H5LT_set_attribute_numerical( loc_id, obj_name, attr_name, size,
- H5T_NATIVE_FLOAT, data ) < 0 )
- return -1;
+ if ( H5LT_set_attribute_numerical( loc_id, obj_name, attr_name, size,
+ H5T_NATIVE_FLOAT, data ) < 0 )
+ return -1;
- return 0;
+ return 0;
}
/*-------------------------------------------------------------------------
- * Function: H5LTset_attribute_double
- *
- * Purpose: Create and write an attribute.
- *
- * Return: Success: 0, Failure: -1
- *
- * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
- *
- * Date: November 7, 2001
- *
- * Comments:
- *
- *-------------------------------------------------------------------------
- */
+* Function: H5LTset_attribute_double
+*
+* Purpose: Create and write an attribute.
+*
+* Return: Success: 0, Failure: -1
+*
+* Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
+*
+* Date: November 7, 2001
+*
+* Comments:
+*
+*-------------------------------------------------------------------------
+*/
herr_t H5LTset_attribute_double( hid_t loc_id,
- const char *obj_name,
- const char *attr_name,
- const double *data,
- size_t size )
+ const char *obj_name,
+ const char *attr_name,
+ const double *data,
+ size_t size )
{
- if ( H5LT_set_attribute_numerical( loc_id, obj_name, attr_name, size,
- H5T_NATIVE_DOUBLE, data ) < 0 )
- return -1;
+ if ( H5LT_set_attribute_numerical( loc_id, obj_name, attr_name, size,
+ H5T_NATIVE_DOUBLE, data ) < 0 )
+ return -1;
- return 0;
+ return 0;
}
/*-------------------------------------------------------------------------
- * Function: find_attr
- *
- * Purpose: operator function used by H5LT_find_attribute
- *
- * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
- *
- * Date: June 21, 2001
- *
- * Comments:
- *
- * Modifications:
- *
- *-------------------------------------------------------------------------
- */
+* Function: find_attr
+*
+* Purpose: operator function used by H5LT_find_attribute
+*
+* Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
+*
+* Date: June 21, 2001
+*
+* Comments:
+*
+* Modifications:
+*
+*-------------------------------------------------------------------------
+*/
static herr_t
find_attr(hid_t loc_id, const char *name, const H5A_info_t *ainfo,
- void *op_data)
+ void *op_data)
{
int ret = H5_ITER_CONT;
@@ -1363,9 +1363,9 @@ find_attr(hid_t loc_id, const char *name, const H5A_info_t *ainfo,
loc_id = loc_id; ainfo = ainfo;
/* Define a positive value for return value if the attribute was found. This will
- * cause the iterator to immediately return that positive value,
- * indicating short-circuit success
- */
+ * cause the iterator to immediately return that positive value,
+ * indicating short-circuit success
+ */
if(strcmp(name, (char *)op_data) == 0)
ret = H5_ITER_STOP;
@@ -1374,51 +1374,51 @@ find_attr(hid_t loc_id, const char *name, const H5A_info_t *ainfo,
/*-------------------------------------------------------------------------
- * Function: H5LTfind_attribute
- *
- * Purpose: Inquires if an attribute named attr_name exists attached to
- * the object loc_id.
- *
- * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
- *
- * Date: May 17, 2006
- *
- * Comments:
- * Calls the private version of the function
- *
- *-------------------------------------------------------------------------
- */
+* Function: H5LTfind_attribute
+*
+* Purpose: Inquires if an attribute named attr_name exists attached to
+* the object loc_id.
+*
+* Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
+*
+* Date: May 17, 2006
+*
+* Comments:
+* Calls the private version of the function
+*
+*-------------------------------------------------------------------------
+*/
herr_t H5LTfind_attribute( hid_t loc_id, const char* attr_name )
{
- return H5LT_find_attribute(loc_id,attr_name);
+ return H5LT_find_attribute(loc_id,attr_name);
}
/*-------------------------------------------------------------------------
- * Function: H5LT_find_attribute
- *
- * Purpose: Inquires if an attribute named attr_name exists attached to the object loc_id.
- *
- * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
- *
- * Date: June 21, 2001
- *
- * Comments:
- * The function uses H5Aiterate2 with the operator function find_attr
- *
- * Return:
- * Success: The return value of the first operator that
- * returns non-zero, or zero if all members were
- * processed with no operator returning non-zero.
- *
- * Failure: Negative if something goes wrong within the
- * library, or the negative value returned by one
- * of the operators.
- *
- *-------------------------------------------------------------------------
- */
+* Function: H5LT_find_attribute
+*
+* Purpose: Inquires if an attribute named attr_name exists attached to the object loc_id.
+*
+* Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
+*
+* Date: June 21, 2001
+*
+* Comments:
+* The function uses H5Aiterate2 with the operator function find_attr
+*
+* Return:
+* Success: The return value of the first operator that
+* returns non-zero, or zero if all members were
+* processed with no operator returning non-zero.
+*
+* Failure: Negative if something goes wrong within the
+* library, or the negative value returned by one
+* of the operators.
+*
+*-------------------------------------------------------------------------
+*/
herr_t
H5LT_find_attribute( hid_t loc_id, const char* attr_name )
@@ -1429,146 +1429,146 @@ H5LT_find_attribute( hid_t loc_id, const char* attr_name )
/*-------------------------------------------------------------------------
- * Function: H5LTget_attribute_ndims
- *
- * Purpose: Gets the dimensionality of an attribute.
- *
- * Return: Success: 0, Failure: -1
- *
- * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
- *
- * Date: September 4, 2001
- *
- *-------------------------------------------------------------------------
- */
+* Function: H5LTget_attribute_ndims
+*
+* Purpose: Gets the dimensionality of an attribute.
+*
+* Return: Success: 0, Failure: -1
+*
+* Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
+*
+* Date: September 4, 2001
+*
+*-------------------------------------------------------------------------
+*/
herr_t H5LTget_attribute_ndims( hid_t loc_id,
- const char *obj_name,
- const char *attr_name,
- int *rank )
+ const char *obj_name,
+ const char *attr_name,
+ int *rank )
{
- hid_t attr_id;
- hid_t sid;
- hid_t obj_id;
+ hid_t attr_id;
+ hid_t sid;
+ hid_t obj_id;
- /* Open the object */
- if((obj_id = H5Oopen(loc_id, obj_name, H5P_DEFAULT)) < 0)
- return -1;
+ /* Open the object */
+ if((obj_id = H5Oopen(loc_id, obj_name, H5P_DEFAULT)) < 0)
+ return -1;
- /* Open the attribute. */
- if((attr_id = H5Aopen(obj_id, attr_name, H5P_DEFAULT)) < 0)
- {
- H5Oclose(obj_id);
- return -1;
- }
+ /* Open the attribute. */
+ if((attr_id = H5Aopen(obj_id, attr_name, H5P_DEFAULT)) < 0)
+ {
+ H5Oclose(obj_id);
+ return -1;
+ }
- /* Get the dataspace handle */
- if((sid = H5Aget_space(attr_id)) < 0)
- goto out;
+ /* Get the dataspace handle */
+ if((sid = H5Aget_space(attr_id)) < 0)
+ goto out;
- /* Get rank */
- if((*rank = H5Sget_simple_extent_ndims(sid)) < 0)
- goto out;
+ /* Get rank */
+ if((*rank = H5Sget_simple_extent_ndims(sid)) < 0)
+ goto out;
- /* Terminate access to the attribute */
- if ( H5Sclose( sid ) < 0 )
- goto out;
+ /* Terminate access to the attribute */
+ if ( H5Sclose( sid ) < 0 )
+ goto out;
- /* End access to the attribute */
- if ( H5Aclose( attr_id ) )
- goto out;;
+ /* End access to the attribute */
+ if ( H5Aclose( attr_id ) )
+ goto out;;
- /* Close the object */
- if(H5Oclose(obj_id) < 0 )
- return -1;
+ /* Close the object */
+ if(H5Oclose(obj_id) < 0 )
+ return -1;
- return 0;
+ return 0;
out:
- H5Aclose( attr_id );
- H5Oclose(obj_id);
- return -1;
+ H5Aclose( attr_id );
+ H5Oclose(obj_id);
+ return -1;
}
/*-------------------------------------------------------------------------
- * Function: H5LTget_attribute_info
- *
- * Purpose: Gets information about an attribute.
- *
- * Return: Success: 0, Failure: -1
- *
- * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
- *
- * Date: September 4, 2001
- *
- *-------------------------------------------------------------------------
- */
+* Function: H5LTget_attribute_info
+*
+* Purpose: Gets information about an attribute.
+*
+* Return: Success: 0, Failure: -1
+*
+* Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
+*
+* Date: September 4, 2001
+*
+*-------------------------------------------------------------------------
+*/
herr_t H5LTget_attribute_info( hid_t loc_id,
- const char *obj_name,
- const char *attr_name,
- hsize_t *dims,
- H5T_class_t *type_class,
- size_t *type_size )
+ const char *obj_name,
+ const char *attr_name,
+ hsize_t *dims,
+ H5T_class_t *type_class,
+ size_t *type_size )
{
- hid_t attr_id;
- hid_t tid;
- hid_t sid;
- hid_t obj_id;
+ hid_t attr_id;
+ hid_t tid;
+ hid_t sid;
+ hid_t obj_id;
- /* Open the object */
- if((obj_id = H5Oopen(loc_id, obj_name, H5P_DEFAULT)) < 0)
- return -1;
+ /* Open the object */
+ if((obj_id = H5Oopen(loc_id, obj_name, H5P_DEFAULT)) < 0)
+ return -1;
- /* Open the attribute. */
- if((attr_id = H5Aopen(obj_id, attr_name, H5P_DEFAULT)) < 0)
- {
- H5Oclose(obj_id);
- return -1;
- }
+ /* Open the attribute. */
+ if((attr_id = H5Aopen(obj_id, attr_name, H5P_DEFAULT)) < 0)
+ {
+ H5Oclose(obj_id);
+ return -1;
+ }
- /* Get an identifier for the datatype. */
- tid = H5Aget_type(attr_id);
+ /* Get an identifier for the datatype. */
+ tid = H5Aget_type(attr_id);
- /* Get the class. */
- *type_class = H5Tget_class(tid);
+ /* Get the class. */
+ *type_class = H5Tget_class(tid);
- /* Get the size. */
- *type_size = H5Tget_size( tid );
+ /* Get the size. */
+ *type_size = H5Tget_size( tid );
- /* Get the dataspace handle */
- if ( (sid = H5Aget_space( attr_id )) < 0 )
- goto out;
+ /* Get the dataspace handle */
+ if ( (sid = H5Aget_space( attr_id )) < 0 )
+ goto out;
- /* Get dimensions */
- if ( H5Sget_simple_extent_dims( sid, dims, NULL) < 0 )
- goto out;
+ /* Get dimensions */
+ if ( H5Sget_simple_extent_dims( sid, dims, NULL) < 0 )
+ goto out;
- /* Terminate access to the dataspace */
- if ( H5Sclose( sid ) < 0 )
- goto out;
+ /* Terminate access to the dataspace */
+ if ( H5Sclose( sid ) < 0 )
+ goto out;
- /* Release the datatype. */
- if ( H5Tclose( tid ) )
- goto out;
+ /* Release the datatype. */
+ if ( H5Tclose( tid ) )
+ goto out;
- /* End access to the attribute */
- if ( H5Aclose( attr_id ) )
- goto out;
+ /* End access to the attribute */
+ if ( H5Aclose( attr_id ) )
+ goto out;
- /* Close the object */
- if(H5Oclose(obj_id) < 0 )
- return -1;
+ /* Close the object */
+ if(H5Oclose(obj_id) < 0 )
+ return -1;
- return 0;
+ return 0;
out:
- H5Tclose(tid);
- H5Aclose(attr_id);
- H5Oclose(obj_id);
- return -1;
+ H5Tclose(tid);
+ H5Aclose(attr_id);
+ H5Oclose(obj_id);
+ return -1;
}
@@ -1576,65 +1576,65 @@ out:
/*-------------------------------------------------------------------------
- * Function: H5LTtext_to_dtype
- *
- * Purpose: Convert DDL description to HDF5 data type.
- *
- * Return: Success: 0, Failure: -1
- *
- * Programmer: Raymond Lu, slu@ncsa.uiuc.edu
- *
- * Date: October 6, 2004
- *
- * Comments:
- *
- * Modifications:
- *
- *-------------------------------------------------------------------------
- */
+* Function: H5LTtext_to_dtype
+*
+* Purpose: Convert DDL description to HDF5 data type.
+*
+* Return: Success: 0, Failure: -1
+*
+* Programmer: Raymond Lu, slu@ncsa.uiuc.edu
+*
+* Date: October 6, 2004
+*
+* Comments:
+*
+* Modifications:
+*
+*-------------------------------------------------------------------------
+*/
hid_t H5LTtext_to_dtype(const char *text, H5LT_lang_t lang_type)
{
- extern int H5LTyyparse(void);
- hid_t type_id;
+ extern int H5LTyyparse(void);
+ hid_t type_id;
- if(lang_type <= H5LT_LANG_ERR || lang_type >= H5LT_NO_LANG)
- goto out;
+ if(lang_type <= H5LT_LANG_ERR || lang_type >= H5LT_NO_LANG)
+ goto out;
- if(lang_type != H5LT_DDL) {
- fprintf(stderr, "only DDL is supported for now.\n");
- goto out;
- }
+ if(lang_type != H5LT_DDL) {
+ fprintf(stderr, "only DDL is supported for now.\n");
+ goto out;
+ }
- input_len = strlen(text);
- myinput = strdup(text);
+ input_len = strlen(text);
+ myinput = strdup(text);
- if((type_id = H5LTyyparse()) < 0)
- goto out;
+ if((type_id = H5LTyyparse()) < 0)
+ goto out;
- free(myinput);
- input_len = 0;
+ free(myinput);
+ input_len = 0;
- return type_id;
+ return type_id;
out:
- return -1;
+ return -1;
}
/*-------------------------------------------------------------------------
- * Function: indentation
- *
- * Purpose: Print spaces for indentation
- *
- * Return: void
- *
- * Programmer: Raymond Lu, slu@ncsa.uiuc.edu
- *
- * Date: December 6, 2005
- *
- * Modifications:
- *
- *-------------------------------------------------------------------------
- */
+* Function: indentation
+*
+* Purpose: Print spaces for indentation
+*
+* Return: void
+*
+* Programmer: Raymond Lu, slu@ncsa.uiuc.edu
+*
+* Date: December 6, 2005
+*
+* Modifications:
+*
+*-------------------------------------------------------------------------
+*/
static void
indentation(int x, char* str)
{
@@ -1648,17 +1648,17 @@ indentation(int x, char* str)
}
/*-------------------------------------------------------------------------
- * Function: print_enum
- *
- * Purpose: prints the enum data
- *
- * Return: Success: 0, Failure: -1
- *
- * Programmer: Raymond Lu
- *
- * Modifications:
- *
- *-----------------------------------------------------------------------*/
+* Function: print_enum
+*
+* Purpose: prints the enum data
+*
+* Return: Success: 0, Failure: -1
+*
+* Programmer: Raymond Lu
+*
+* Modifications:
+*
+*-----------------------------------------------------------------------*/
static herr_t
print_enum(hid_t type, char* str, int indt)
{
@@ -1668,7 +1668,7 @@ print_enum(hid_t type, char* str, int indt)
int nmembs; /*number of members */
char tmp_str[256];
int nchars; /*number of output characters */
- hid_t super; /*enum base integer type */
+ hid_t super = -1; /*enum base integer type */
hid_t native = -1; /*native integer data type */
size_t super_size; /*enum base type size */
size_t dst_size; /*destination value type size */
@@ -1682,9 +1682,9 @@ print_enum(hid_t type, char* str, int indt)
goto out;
/* Use buffer of INT or UNSIGNED INT to print enum values because
- * we don't expect these values to be so big that INT or UNSIGNED
- * INT can't hold.
- */
+ * we don't expect these values to be so big that INT or UNSIGNED
+ * INT can't hold.
+ */
if (H5T_SGN_NONE == H5Tget_sign(super)) {
native = H5T_NATIVE_UINT;
} else {
@@ -1699,9 +1699,9 @@ print_enum(hid_t type, char* str, int indt)
value = (unsigned char*)calloc((size_t)nmembs, MAX(dst_size, super_size));
for (i = 0; i < nmembs; i++) {
- if((name[i] = H5Tget_member_name(type, (unsigned)i))==NULL)
+ if((name[i] = H5Tget_member_name(type, (unsigned)i))==NULL)
goto out;
- if(H5Tget_member_value(type, (unsigned)i, value + i * super_size) < 0)
+ if(H5Tget_member_value(type, (unsigned)i, value + i * super_size) < 0)
goto out;
}
@@ -1712,71 +1712,85 @@ print_enum(hid_t type, char* str, int indt)
}
/*
- * Sort members by increasing value
- * ***not implemented yet***
- */
+ * Sort members by increasing value
+ * ***not implemented yet***
+ */
/* Print members */
for (i = 0; i < nmembs; i++) {
- indentation(indt + COL, str);
- nchars = sprintf(tmp_str, "\"%s\"", name[i]);
+ indentation(indt + COL, str);
+ nchars = sprintf(tmp_str, "\"%s\"", name[i]);
strcat(str, tmp_str);
- sprintf(tmp_str, "%*s ", MAX(0, 16 - nchars), "");
+ sprintf(tmp_str, "%*s ", MAX(0, 16 - nchars), "");
strcat(str, tmp_str);
- if (H5T_SGN_NONE == H5Tget_sign(native)) {
- /*On SGI Altix(cobalt), wrong values were printed out with "value+i*dst_size"
- *strangely, unless use another pointer "copy".*/
- copy = value+i*dst_size;
- sprintf(tmp_str,"%u", *((unsigned int*)((void *)copy)));
+ if (H5T_SGN_NONE == H5Tget_sign(native)) {
+ /*On SGI Altix(cobalt), wrong values were printed out with "value+i*dst_size"
+ *strangely, unless use another pointer "copy".*/
+ copy = value+i*dst_size;
+ sprintf(tmp_str,"%u", *((unsigned int*)((void *)copy)));
strcat(str, tmp_str);
- } else {
- /*On SGI Altix(cobalt), wrong values were printed out with "value+i*dst_size"
- *strangely, unless use another pointer "copy".*/
- copy = value+i*dst_size;
- sprintf(tmp_str,"%d", *((int*)((void *)copy)));
+ } else {
+ /*On SGI Altix(cobalt), wrong values were printed out with "value+i*dst_size"
+ *strangely, unless use another pointer "copy".*/
+ copy = value+i*dst_size;
+ sprintf(tmp_str,"%d", *((int*)((void *)copy)));
strcat(str, tmp_str);
- }
+ }
- strcat(str, ";\n");
+ strcat(str, ";\n");
}
/* Release resources */
- for (i = 0; i < nmembs; i++)
- free(name[i]);
+ for(i = 0; i < nmembs; i++)
+ free(name[i]);
free(name);
free(value);
H5Tclose(super);
- if (0 == nmembs) {
- sprintf(tmp_str, "\n%*s <empty>", indt + 4, "");
+ if(0 == nmembs) {
+ sprintf(tmp_str, "\n%*s <empty>", indt + 4, "");
strcat(str, tmp_str);
- }
+ } /* end if */
return ret;
out:
+ /* Release resources */
+ if(name) {
+ for(i = 0; i < nmembs; i++)
+ if(name[i])
+ free(name[i]);
+ free(name);
+ } /* end if */
+
+ if(value)
+ free(value);
+
+ if(super >= 0)
+ H5Tclose(super);
+
return FAIL;
}
/*-------------------------------------------------------------------------
- * Function: H5LTdtype_to_text
- *
- * Purpose: Convert HDF5 data type to DDL description.
- *
- * Return: Success: 0, Failure: -1
- *
- * Programmer: Raymond Lu, slu@ncsa.uiuc.edu
- *
- * Date: December 6, 2005
- *
- * Comments:
- *
- * Modifications:
- *
- *-------------------------------------------------------------------------
- */
+* Function: H5LTdtype_to_text
+*
+* Purpose: Convert HDF5 data type to DDL description.
+*
+* Return: Success: 0, Failure: -1
+*
+* Programmer: Raymond Lu, slu@ncsa.uiuc.edu
+*
+* Date: December 6, 2005
+*
+* Comments:
+*
+* Modifications:
+*
+*-------------------------------------------------------------------------
+*/
herr_t H5LTdtype_to_text(hid_t dtype, char *str, H5LT_lang_t lang_type, size_t *len)
{
size_t str_len = INCREMENT;
@@ -1792,6 +1806,7 @@ herr_t H5LTdtype_to_text(hid_t dtype, char *str, H5LT_lang_t lang_type, size_t *
if((ret = H5LT_dtype_to_text(dtype, &text_str, lang_type, &str_len, 1)) < 0)
goto out;
*len = strlen(text_str) + 1;
+ free(text_str);
} else if(len && str) {
if((ret = H5LT_dtype_to_text(dtype, &str, lang_type, len, 0)) < 0)
goto out;
@@ -1805,24 +1820,24 @@ out:
}
/*-------------------------------------------------------------------------
- * Function: H5LT_dtype_to_text
- *
- * Purpose: Private function to convert HDF5 data type to DDL description.
- *
- * Return: Success: 0, Failure: -1
- *
- * Programmer: Raymond Lu, slu@ncsa.uiuc.edu
- *
- * Date: December 20, 2005
- *
- * Comments:
- *
- * Modifications:
- *
- *-------------------------------------------------------------------------
- */
+* Function: H5LT_dtype_to_text
+*
+* Purpose: Private function to convert HDF5 data type to DDL description.
+*
+* Return: Success: 0, Failure: -1
+*
+* Programmer: Raymond Lu, slu@ncsa.uiuc.edu
+*
+* Date: December 20, 2005
+*
+* Comments:
+*
+* Modifications:
+*
+*-------------------------------------------------------------------------
+*/
herr_t H5LT_dtype_to_text(hid_t dtype, char **dt_str, H5LT_lang_t lang, size_t *slen,
- hbool_t no_user_buf)
+ hbool_t no_user_buf)
{
H5T_class_t tcls;
char tmp_str[256];
@@ -1834,8 +1849,8 @@ herr_t H5LT_dtype_to_text(hid_t dtype, char **dt_str, H5LT_lang_t lang, size_t *
*slen += INCREMENT;
tmp = (char*)realloc(*dt_str, *slen);
if(tmp != *dt_str) {
- free(*dt_str);
- *dt_str = tmp;
+ free(*dt_str);
+ *dt_str = tmp;
}
}
@@ -1930,152 +1945,155 @@ herr_t H5LT_dtype_to_text(hid_t dtype, char **dt_str, H5LT_lang_t lang, size_t *
break;
case H5T_STRING:
{
- /* Make a copy of type in memory in case when DTYPE is on disk, the size
- * will be bigger than in memory. This makes it easier to compare
- * types in memory. */
- hid_t str_type;
- H5T_order_t order;
- hid_t tmp_type;
- size_t size;
- H5T_str_t str_pad;
- H5T_cset_t cset;
- htri_t is_vlstr;
-
- if((tmp_type = H5Tcopy(dtype)) < 0)
- goto out;
- if((size = H5Tget_size(tmp_type))==0)
- goto out;
- if((str_pad = H5Tget_strpad(tmp_type)) < 0)
- goto out;
- if((cset = H5Tget_cset(tmp_type)) < 0)
- goto out;
- if((is_vlstr = H5Tis_variable_str(tmp_type)) < 0)
- goto out;
+ /* Make a copy of type in memory in case when DTYPE is on disk, the size
+ * will be bigger than in memory. This makes it easier to compare
+ * types in memory. */
+ hid_t str_type;
+ H5T_order_t order;
+ hid_t tmp_type;
+ size_t size;
+ H5T_str_t str_pad;
+ H5T_cset_t cset;
+ htri_t is_vlstr;
+
+ if((tmp_type = H5Tcopy(dtype)) < 0)
+ goto out;
+ if((size = H5Tget_size(tmp_type))==0)
+ goto out;
+ if((str_pad = H5Tget_strpad(tmp_type)) < 0)
+ goto out;
+ if((cset = H5Tget_cset(tmp_type)) < 0)
+ goto out;
+ if((is_vlstr = H5Tis_variable_str(tmp_type)) < 0)
+ goto out;
- /* Print lead-in */
- sprintf(*dt_str, "H5T_STRING {\n");
- indent += COL;
+ /* Print lead-in */
+ sprintf(*dt_str, "H5T_STRING {\n");
+ indent += COL;
- indentation(indent + COL, *dt_str);
+ indentation(indent + COL, *dt_str);
- if(is_vlstr)
- strcat(*dt_str, "STRSIZE H5T_VARIABLE;\n");
- else {
- sprintf(tmp_str, "STRSIZE %d;\n", (int)size);
- strcat(*dt_str, tmp_str);
- }
+ if(is_vlstr)
+ strcat(*dt_str, "STRSIZE H5T_VARIABLE;\n");
+ else {
+ sprintf(tmp_str, "STRSIZE %d;\n", (int)size);
+ strcat(*dt_str, tmp_str);
+ }
- indentation(indent + COL, *dt_str);
+ indentation(indent + COL, *dt_str);
- if (str_pad == H5T_STR_NULLTERM)
- strcat(*dt_str, "STRPAD H5T_STR_NULLTERM;\n");
- else if (str_pad == H5T_STR_NULLPAD)
- strcat(*dt_str, "STRPAD H5T_STR_NULLPAD;\n");
- else if (str_pad == H5T_STR_SPACEPAD)
- strcat(*dt_str, "STRPAD H5T_STR_SPACEPAD;\n");
- else
- strcat(*dt_str, "STRPAD H5T_STR_ERROR;\n");
+ if (str_pad == H5T_STR_NULLTERM)
+ strcat(*dt_str, "STRPAD H5T_STR_NULLTERM;\n");
+ else if (str_pad == H5T_STR_NULLPAD)
+ strcat(*dt_str, "STRPAD H5T_STR_NULLPAD;\n");
+ else if (str_pad == H5T_STR_SPACEPAD)
+ strcat(*dt_str, "STRPAD H5T_STR_SPACEPAD;\n");
+ else
+ strcat(*dt_str, "STRPAD H5T_STR_ERROR;\n");
- indentation(indent + COL, *dt_str);
+ indentation(indent + COL, *dt_str);
- if (cset == H5T_CSET_ASCII)
- strcat(*dt_str, "CSET H5T_CSET_ASCII;\n");
- else if (cset == H5T_CSET_UTF8)
- strcat(*dt_str, "CSET H5T_CSET_UTF8;\n");
- else
- strcat(*dt_str, "CSET unknown;\n");
+ if (cset == H5T_CSET_ASCII)
+ strcat(*dt_str, "CSET H5T_CSET_ASCII;\n");
+ else if (cset == H5T_CSET_UTF8)
+ strcat(*dt_str, "CSET H5T_CSET_UTF8;\n");
+ else
+ strcat(*dt_str, "CSET unknown;\n");
- /* Reproduce a C type string */
- if((str_type = H5Tcopy(H5T_C_S1)) < 0)
- goto out;
- if(is_vlstr) {
- if(H5Tset_size(str_type, H5T_VARIABLE) < 0)
+ /* Reproduce a C type string */
+ if((str_type = H5Tcopy(H5T_C_S1)) < 0)
goto out;
- } else {
- if(H5Tset_size(str_type, size) < 0)
+ if(is_vlstr) {
+ if(H5Tset_size(str_type, H5T_VARIABLE) < 0)
+ goto out;
+ } else {
+ if(H5Tset_size(str_type, size) < 0)
+ goto out;
+ }
+ if(H5Tset_cset(str_type, cset) < 0)
+ goto out;
+ if(H5Tset_strpad(str_type, str_pad) < 0)
goto out;
- }
- if(H5Tset_cset(str_type, cset) < 0)
- goto out;
- if(H5Tset_strpad(str_type, str_pad) < 0)
- goto out;
- indentation(indent + COL, *dt_str);
+ indentation(indent + COL, *dt_str);
- /* Check C variable-length string first. Are the two types equal? */
- if (H5Tequal(tmp_type, str_type)) {
- strcat(*dt_str, "CTYPE H5T_C_S1;\n");
- goto next;
- }
+ /* Check C variable-length string first. Are the two types equal? */
+ if (H5Tequal(tmp_type, str_type)) {
+ strcat(*dt_str, "CTYPE H5T_C_S1;\n");
+ goto next;
+ }
- /* Change the endianness and see if they're equal. */
- if((order = H5Tget_order(tmp_type)) < 0)
- goto out;
- if(order==H5T_ORDER_LE) {
- if(H5Tset_order(str_type, H5T_ORDER_LE) < 0)
+ /* Change the endianness and see if they're equal. */
+ if((order = H5Tget_order(tmp_type)) < 0)
goto out;
- } else if(order==H5T_ORDER_BE) {
- if(H5Tset_order(str_type, H5T_ORDER_BE) < 0)
+ if(order==H5T_ORDER_LE) {
+ if(H5Tset_order(str_type, H5T_ORDER_LE) < 0)
+ goto out;
+ } else if(order==H5T_ORDER_BE) {
+ if(H5Tset_order(str_type, H5T_ORDER_BE) < 0)
+ goto out;
+ }
+
+ if (H5Tequal(tmp_type, str_type)) {
+ strcat(*dt_str, "H5T_C_S1;\n");
+ goto next;
+ }
+
+ /* If not equal to C variable-length string, check Fortran type.
+ * Actually H5Tequal can't tell difference between H5T_C_S1 and H5T_FORTRAN_S1!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
+ if(H5Tclose(str_type) < 0)
goto out;
- }
-
- if (H5Tequal(tmp_type, str_type)) {
- strcat(*dt_str, "H5T_C_S1;\n");
- goto next;
- }
-
- /* If not equal to C variable-length string, check Fortran type.
- * Actually H5Tequal can't tell difference between H5T_C_S1 and H5T_FORTRAN_S1!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
- if(H5Tclose(str_type) < 0)
- goto out;
- if((str_type = H5Tcopy(H5T_FORTRAN_S1)) < 0)
- goto out;
- if(H5Tset_cset(str_type, cset) < 0)
- goto out;
- if(H5Tset_size(str_type, size) < 0)
- goto out;
- if(H5Tset_strpad(str_type, str_pad) < 0)
- goto out;
-
- /* Are the two types equal? */
- if (H5Tequal(tmp_type, str_type)) {
- strcat(*dt_str, "CTYPE H5T_FORTRAN_S1;\n");
- goto next;
- }
-
- /* Change the endianness and see if they're equal. */
- if((order = H5Tget_order(tmp_type)) < 0)
- goto out;
- if(order==H5T_ORDER_LE) {
- if(H5Tset_order(str_type, H5T_ORDER_LE) < 0)
+ if((str_type = H5Tcopy(H5T_FORTRAN_S1)) < 0)
goto out;
- } else if(order==H5T_ORDER_BE) {
- if(H5Tset_order(str_type, H5T_ORDER_BE) < 0)
+ if(H5Tset_cset(str_type, cset) < 0)
+ goto out;
+ if(H5Tset_size(str_type, size) < 0)
+ goto out;
+ if(H5Tset_strpad(str_type, str_pad) < 0)
goto out;
- }
- /* Are the two types equal? */
- if (H5Tequal(tmp_type, str_type)) {
- strcat(*dt_str, "CTYPE H5T_FORTRAN_S1;\n");
- goto next;
- }
+ /* Are the two types equal? */
+ if (H5Tequal(tmp_type, str_type)) {
+ strcat(*dt_str, "CTYPE H5T_FORTRAN_S1;\n");
+ goto next;
+ }
- /* Type doesn't match any of above. */
- strcat(*dt_str, "CTYPE unknown_one_character_type;\n ");
+ /* Change the endianness and see if they're equal. */
+ if((order = H5Tget_order(tmp_type)) < 0)
+ goto out;
+ if(order==H5T_ORDER_LE) {
+ if(H5Tset_order(str_type, H5T_ORDER_LE) < 0)
+ goto out;
+ } else if(order==H5T_ORDER_BE) {
+ if(H5Tset_order(str_type, H5T_ORDER_BE) < 0)
+ goto out;
+ }
+
+ /* Are the two types equal? */
+ if (H5Tequal(tmp_type, str_type)) {
+ strcat(*dt_str, "CTYPE H5T_FORTRAN_S1;\n");
+ goto next;
+ }
+
+ /* Type doesn't match any of above. */
+ strcat(*dt_str, "CTYPE unknown_one_character_type;\n ");
next:
- H5Tclose(str_type);
- H5Tclose(tmp_type);
+ H5Tclose(str_type);
+ H5Tclose(tmp_type);
- /* Print closing */
- indent -= COL;
- indentation(indent + COL, *dt_str);
- strcat(*dt_str, "}");
+ /* Print closing */
+ indent -= COL;
+ indentation(indent + COL, *dt_str);
+ strcat(*dt_str, "}");
- break;
+ break;
}
case H5T_OPAQUE:
+ {
+ char *tag;
+
/* Print lead-in */
sprintf(*dt_str, "H5T_OPAQUE {\n");
indent += COL;
@@ -2085,7 +2103,12 @@ next:
strcat(*dt_str, tmp_str);
indentation(indent + COL, *dt_str);
- sprintf(tmp_str, "OPQ_TAG \"%s\";\n", H5Tget_tag(dtype));
+ tag = H5Tget_tag(dtype);
+ if(tag) {
+ sprintf(tmp_str, "OPQ_TAG \"%s\";\n", tag);
+ free(tag);
+ } else
+ sprintf(tmp_str, "OPQ_TAG \"\";\n");
strcat(*dt_str, tmp_str);
/* Print closing */
@@ -2094,168 +2117,169 @@ next:
strcat(*dt_str, "}");
break;
+ }
case H5T_ENUM:
{
- hid_t super;
- size_t super_len;
- char* stmp;
+ hid_t super;
+ size_t super_len;
+ char* stmp;
- /* Print lead-in */
- sprintf(*dt_str, "H5T_ENUM {\n");
- indent += COL;
- indentation(indent + COL, *dt_str);
+ /* Print lead-in */
+ sprintf(*dt_str, "H5T_ENUM {\n");
+ indent += COL;
+ indentation(indent + COL, *dt_str);
- if((super = H5Tget_super(dtype)) < 0)
- goto out;
- if(H5LTdtype_to_text(super, NULL, lang, &super_len) < 0)
- goto out;
- stmp = (char*)calloc(super_len, sizeof(char));
- if(H5LTdtype_to_text(super, stmp, lang, &super_len) < 0)
- goto out;
- strcat(*dt_str, stmp);
- free(stmp);
- strcat(*dt_str, ";\n");
- H5Tclose(super);
-
- if(print_enum(dtype, *dt_str, indent) < 0)
- goto out;
+ if((super = H5Tget_super(dtype)) < 0)
+ goto out;
+ if(H5LTdtype_to_text(super, NULL, lang, &super_len) < 0)
+ goto out;
+ stmp = (char*)calloc(super_len, sizeof(char));
+ if(H5LTdtype_to_text(super, stmp, lang, &super_len) < 0)
+ goto out;
+ strcat(*dt_str, stmp);
+ free(stmp);
+ strcat(*dt_str, ";\n");
+ H5Tclose(super);
- /* Print closing */
- indent -= COL;
- indentation(indent + COL, *dt_str);
- strcat(*dt_str, "}");
+ if(print_enum(dtype, *dt_str, indent) < 0)
+ goto out;
- break;
+ /* Print closing */
+ indent -= COL;
+ indentation(indent + COL, *dt_str);
+ strcat(*dt_str, "}");
+
+ break;
}
case H5T_VLEN:
{
- hid_t super;
- size_t super_len;
- char* stmp;
+ hid_t super;
+ size_t super_len;
+ char* stmp;
- /* Print lead-in */
- sprintf(*dt_str, "H5T_VLEN {\n");
- indent += COL;
- indentation(indent + COL, *dt_str);
+ /* Print lead-in */
+ sprintf(*dt_str, "H5T_VLEN {\n");
+ indent += COL;
+ indentation(indent + COL, *dt_str);
- if((super = H5Tget_super(dtype)) < 0)
- goto out;
- if(H5LTdtype_to_text(super, NULL, lang, &super_len) < 0)
- goto out;
- stmp = (char*)calloc(super_len, sizeof(char));
- if(H5LTdtype_to_text(super, stmp, lang, &super_len) < 0)
- goto out;
- strcat(*dt_str, stmp);
- free(stmp);
- strcat(*dt_str, "\n");
- H5Tclose(super);
+ if((super = H5Tget_super(dtype)) < 0)
+ goto out;
+ if(H5LTdtype_to_text(super, NULL, lang, &super_len) < 0)
+ goto out;
+ stmp = (char*)calloc(super_len, sizeof(char));
+ if(H5LTdtype_to_text(super, stmp, lang, &super_len) < 0)
+ goto out;
+ strcat(*dt_str, stmp);
+ free(stmp);
+ strcat(*dt_str, "\n");
+ H5Tclose(super);
- /* Print closing */
- indent -= COL;
- indentation(indent + COL, *dt_str);
- strcat(*dt_str, "}");
+ /* Print closing */
+ indent -= COL;
+ indentation(indent + COL, *dt_str);
+ strcat(*dt_str, "}");
- break;
+ break;
}
case H5T_ARRAY:
{
- hid_t super;
- size_t super_len;
- char* stmp;
- hsize_t dims[H5S_MAX_RANK];
- int ndims;
-
- /* Print lead-in */
- sprintf(*dt_str, "H5T_ARRAY {\n");
- indent += COL;
- indentation(indent + COL, *dt_str);
-
- /* Get array information */
- if((ndims = H5Tget_array_ndims(dtype)) < 0)
- goto out;
- if(H5Tget_array_dims2(dtype, dims) < 0)
- goto out;
-
- /* Print array dimensions */
- for (i = 0; i < ndims; i++) {
- sprintf(tmp_str, "[%d]", (int) dims[i]);
- strcat(*dt_str, tmp_str);
- }
- strcat(*dt_str, " ");
-
- if((super = H5Tget_super(dtype)) < 0)
- goto out;
- if(H5LTdtype_to_text(super, NULL, lang, &super_len) < 0)
- goto out;
- stmp = (char*)calloc(super_len, sizeof(char));
- if(H5LTdtype_to_text(super, stmp, lang, &super_len) < 0)
- goto out;
- strcat(*dt_str, stmp);
- free(stmp);
- strcat(*dt_str, "\n");
- H5Tclose(super);
-
- /* Print closing */
- indent -= COL;
- indentation(indent + COL, *dt_str);
- strcat(*dt_str, "}");
-
- break;
- }
- case H5T_COMPOUND:
- {
- char *mname;
- hid_t mtype;
- size_t moffset;
- H5T_class_t mclass;
- size_t mlen;
- char* mtmp;
- int nmembs;
-
- if((nmembs = H5Tget_nmembers(dtype)) < 0)
- goto out;
-
- sprintf(*dt_str, "H5T_COMPOUND {\n");
- indent += COL;
+ hid_t super;
+ size_t super_len;
+ char* stmp;
+ hsize_t dims[H5S_MAX_RANK];
+ int ndims;
+
+ /* Print lead-in */
+ sprintf(*dt_str, "H5T_ARRAY {\n");
+ indent += COL;
+ indentation(indent + COL, *dt_str);
- for (i = 0; i < nmembs; i++) {
- if((mname = H5Tget_member_name(dtype, (unsigned)i))==NULL)
+ /* Get array information */
+ if((ndims = H5Tget_array_ndims(dtype)) < 0)
goto out;
- if((mtype = H5Tget_member_type(dtype, (unsigned)i)) < 0)
+ if(H5Tget_array_dims2(dtype, dims) < 0)
goto out;
- moffset = H5Tget_member_offset(dtype, (unsigned)i);
- indentation(indent + COL, *dt_str);
- if((mclass = H5Tget_class(mtype)) < 0)
- goto out;
- if (H5T_COMPOUND == mclass)
- indent += COL;
+ /* Print array dimensions */
+ for (i = 0; i < ndims; i++) {
+ sprintf(tmp_str, "[%d]", (int) dims[i]);
+ strcat(*dt_str, tmp_str);
+ }
+ strcat(*dt_str, " ");
- if(H5LTdtype_to_text(mtype, NULL, lang, &mlen) < 0)
+ if((super = H5Tget_super(dtype)) < 0)
goto out;
- mtmp = (char*)calloc(mlen, sizeof(char));
- if(H5LTdtype_to_text(mtype, mtmp, lang, &mlen) < 0)
+ if(H5LTdtype_to_text(super, NULL, lang, &super_len) < 0)
goto out;
- strcat(*dt_str, mtmp);
- free(mtmp);
-
- if (H5T_COMPOUND == mclass)
- indent -= COL;
+ stmp = (char*)calloc(super_len, sizeof(char));
+ if(H5LTdtype_to_text(super, stmp, lang, &super_len) < 0)
+ goto out;
+ strcat(*dt_str, stmp);
+ free(stmp);
+ strcat(*dt_str, "\n");
+ H5Tclose(super);
- sprintf(tmp_str, " \"%s\"", mname);
- strcat(*dt_str, tmp_str);
- free(mname);
+ /* Print closing */
+ indent -= COL;
+ indentation(indent + COL, *dt_str);
+ strcat(*dt_str, "}");
- sprintf(tmp_str, " : %lu;\n", (unsigned long)moffset);
- strcat(*dt_str, tmp_str);
+ break;
}
+ case H5T_COMPOUND:
+ {
+ char *mname;
+ hid_t mtype;
+ size_t moffset;
+ H5T_class_t mclass;
+ size_t mlen;
+ char* mtmp;
+ int nmembs;
+
+ if((nmembs = H5Tget_nmembers(dtype)) < 0)
+ goto out;
- /* Print closing */
- indent -= COL;
- indentation(indent + COL, *dt_str);
- strcat(*dt_str, "}");
+ sprintf(*dt_str, "H5T_COMPOUND {\n");
+ indent += COL;
+
+ for (i = 0; i < nmembs; i++) {
+ if((mname = H5Tget_member_name(dtype, (unsigned)i))==NULL)
+ goto out;
+ if((mtype = H5Tget_member_type(dtype, (unsigned)i)) < 0)
+ goto out;
+ moffset = H5Tget_member_offset(dtype, (unsigned)i);
+ indentation(indent + COL, *dt_str);
+
+ if((mclass = H5Tget_class(mtype)) < 0)
+ goto out;
+ if (H5T_COMPOUND == mclass)
+ indent += COL;
+
+ if(H5LTdtype_to_text(mtype, NULL, lang, &mlen) < 0)
+ goto out;
+ mtmp = (char*)calloc(mlen, sizeof(char));
+ if(H5LTdtype_to_text(mtype, mtmp, lang, &mlen) < 0)
+ goto out;
+ strcat(*dt_str, mtmp);
+ free(mtmp);
+
+ if (H5T_COMPOUND == mclass)
+ indent -= COL;
+
+ sprintf(tmp_str, " \"%s\"", mname);
+ strcat(*dt_str, tmp_str);
+ free(mname);
+
+ sprintf(tmp_str, " : %lu;\n", (unsigned long)moffset);
+ strcat(*dt_str, tmp_str);
+ }
+
+ /* Print closing */
+ indent -= COL;
+ indentation(indent + COL, *dt_str);
+ strcat(*dt_str, "}");
- break;
+ break;
}
case H5T_TIME:
sprintf(*dt_str, "H5T_TIME: not yet implemented");
@@ -2278,77 +2302,77 @@ out:
/*-------------------------------------------------------------------------
- *
- * Get attribute functions
- *
- *-------------------------------------------------------------------------
- */
+*
+* Get attribute functions
+*
+*-------------------------------------------------------------------------
+*/
/*-------------------------------------------------------------------------
- * Function: H5LTget_attribute_string
- *
- * Purpose: Reads an attribute named attr_name
- *
- * Return: Success: 0, Failure: -1
- *
- * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
- *
- * Date: September 19, 2002
- *
- * Comments:
- *
- * Modifications:
- *
- *-------------------------------------------------------------------------
- */
+* Function: H5LTget_attribute_string
+*
+* Purpose: Reads an attribute named attr_name
+*
+* Return: Success: 0, Failure: -1
+*
+* Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
+*
+* Date: September 19, 2002
+*
+* Comments:
+*
+* Modifications:
+*
+*-------------------------------------------------------------------------
+*/
herr_t H5LTget_attribute_string( hid_t loc_id,
- const char *obj_name,
- const char *attr_name,
- char *data )
+ const char *obj_name,
+ const char *attr_name,
+ char *data )
{
- /* identifiers */
- hid_t obj_id;
+ /* identifiers */
+ hid_t obj_id;
- /* Open the object */
- if ((obj_id = H5Oopen( loc_id, obj_name, H5P_DEFAULT)) < 0)
- return -1;
+ /* Open the object */
+ if ((obj_id = H5Oopen( loc_id, obj_name, H5P_DEFAULT)) < 0)
+ return -1;
- /* Get the attribute */
- if ( H5LT_get_attribute_disk( obj_id, attr_name, data ) < 0 )
- return -1;
+ /* Get the attribute */
+ if ( H5LT_get_attribute_disk( obj_id, attr_name, data ) < 0 )
+ return -1;
- /* Close the object */
- if(H5Oclose(obj_id) < 0)
- return -1;
+ /* Close the object */
+ if(H5Oclose(obj_id) < 0)
+ return -1;
- return 0;
+ return 0;
}
/*-------------------------------------------------------------------------
- * Function: H5LTget_attribute_char
- *
- * Purpose: Reads an attribute named attr_name
- *
- * Return: Success: 0, Failure: -1
- *
- * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
- *
- * Date: September 19, 2002
- *
- * Comments:
- *
- * Modifications:
- *
- *-------------------------------------------------------------------------
- */
+* Function: H5LTget_attribute_char
+*
+* Purpose: Reads an attribute named attr_name
+*
+* Return: Success: 0, Failure: -1
+*
+* Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
+*
+* Date: September 19, 2002
+*
+* Comments:
+*
+* Modifications:
+*
+*-------------------------------------------------------------------------
+*/
herr_t H5LTget_attribute_char( hid_t loc_id,
- const char *obj_name,
- const char *attr_name,
- char *data )
+ const char *obj_name,
+ const char *attr_name,
+ char *data )
{
/* Get the attribute */
if(H5LT_get_attribute_mem(loc_id, obj_name, attr_name, H5T_NATIVE_CHAR, data) < 0)
@@ -2358,26 +2382,26 @@ herr_t H5LTget_attribute_char( hid_t loc_id,
}
/*-------------------------------------------------------------------------
- * Function: H5LTget_attribute_uchar
- *
- * Purpose: Reads an attribute named attr_name
- *
- * Return: Success: 0, Failure: -1
- *
- * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
- *
- * Date: March 8, 2004
- *
- * Comments:
- *
- * Modifications:
- *
- *-------------------------------------------------------------------------
- */
+* Function: H5LTget_attribute_uchar
+*
+* Purpose: Reads an attribute named attr_name
+*
+* Return: Success: 0, Failure: -1
+*
+* Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
+*
+* Date: March 8, 2004
+*
+* Comments:
+*
+* Modifications:
+*
+*-------------------------------------------------------------------------
+*/
herr_t H5LTget_attribute_uchar( hid_t loc_id,
- const char *obj_name,
- const char *attr_name,
- unsigned char *data )
+ const char *obj_name,
+ const char *attr_name,
+ unsigned char *data )
{
/* Get the attribute */
if(H5LT_get_attribute_mem(loc_id, obj_name, attr_name, H5T_NATIVE_UCHAR, data) < 0)
@@ -2389,26 +2413,26 @@ herr_t H5LTget_attribute_uchar( hid_t loc_id,
/*-------------------------------------------------------------------------
- * Function: H5LTget_attribute_short
- *
- * Purpose: Reads an attribute named attr_name
- *
- * Return: Success: 0, Failure: -1
- *
- * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
- *
- * Date: September 19, 2002
- *
- * Comments:
- *
- * Modifications:
- *
- *-------------------------------------------------------------------------
- */
+* Function: H5LTget_attribute_short
+*
+* Purpose: Reads an attribute named attr_name
+*
+* Return: Success: 0, Failure: -1
+*
+* Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
+*
+* Date: September 19, 2002
+*
+* Comments:
+*
+* Modifications:
+*
+*-------------------------------------------------------------------------
+*/
herr_t H5LTget_attribute_short( hid_t loc_id,
- const char *obj_name,
- const char *attr_name,
- short *data )
+ const char *obj_name,
+ const char *attr_name,
+ short *data )
{
/* Get the attribute */
if(H5LT_get_attribute_mem(loc_id, obj_name, attr_name, H5T_NATIVE_SHORT, data) < 0)
@@ -2418,22 +2442,22 @@ herr_t H5LTget_attribute_short( hid_t loc_id,
}
/*-------------------------------------------------------------------------
- * Function: H5LTget_attribute_ushort
- *
- * Purpose: Reads an attribute named attr_name
- *
- * Return: Success: 0, Failure: -1
- *
- * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
- *
- * Date: March 8, 2004
- *
- * Comments:
- *
- * Modifications:
- *
- *-------------------------------------------------------------------------
- */
+* Function: H5LTget_attribute_ushort
+*
+* Purpose: Reads an attribute named attr_name
+*
+* Return: Success: 0, Failure: -1
+*
+* Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
+*
+* Date: March 8, 2004
+*
+* Comments:
+*
+* Modifications:
+*
+*-------------------------------------------------------------------------
+*/
herr_t H5LTget_attribute_ushort( hid_t loc_id,
const char *obj_name,
const char *attr_name,
@@ -2449,26 +2473,26 @@ herr_t H5LTget_attribute_ushort( hid_t loc_id,
/*-------------------------------------------------------------------------
- * Function: H5LTget_attribute_int
- *
- * Purpose: Reads an attribute named attr_name
- *
- * Return: Success: 0, Failure: -1
- *
- * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
- *
- * Date: September 19, 2002
- *
- * Comments:
- *
- * Modifications:
- *
- *-------------------------------------------------------------------------
- */
+* Function: H5LTget_attribute_int
+*
+* Purpose: Reads an attribute named attr_name
+*
+* Return: Success: 0, Failure: -1
+*
+* Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
+*
+* Date: September 19, 2002
+*
+* Comments:
+*
+* Modifications:
+*
+*-------------------------------------------------------------------------
+*/
herr_t H5LTget_attribute_int( hid_t loc_id,
- const char *obj_name,
- const char *attr_name,
- int *data )
+ const char *obj_name,
+ const char *attr_name,
+ int *data )
{
/* Get the attribute */
if(H5LT_get_attribute_mem(loc_id, obj_name, attr_name, H5T_NATIVE_INT, data) < 0)
@@ -2478,22 +2502,22 @@ herr_t H5LTget_attribute_int( hid_t loc_id,
}
/*-------------------------------------------------------------------------
- * Function: H5LTget_attribute_uint
- *
- * Purpose: Reads an attribute named attr_name
- *
- * Return: Success: 0, Failure: -1
- *
- * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
- *
- * Date: March 8, 2004
- *
- * Comments:
- *
- * Modifications:
- *
- *-------------------------------------------------------------------------
- */
+* Function: H5LTget_attribute_uint
+*
+* Purpose: Reads an attribute named attr_name
+*
+* Return: Success: 0, Failure: -1
+*
+* Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
+*
+* Date: March 8, 2004
+*
+* Comments:
+*
+* Modifications:
+*
+*-------------------------------------------------------------------------
+*/
herr_t H5LTget_attribute_uint( hid_t loc_id,
const char *obj_name,
const char *attr_name,
@@ -2509,22 +2533,22 @@ herr_t H5LTget_attribute_uint( hid_t loc_id,
/*-------------------------------------------------------------------------
- * Function: H5LTget_attribute_long
- *
- * Purpose: Reads an attribute named attr_name
- *
- * Return: Success: 0, Failure: -1
- *
- * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
- *
- * Date: September 19, 2002
- *
- * Comments:
- *
- * Modifications:
- *
- *-------------------------------------------------------------------------
- */
+* Function: H5LTget_attribute_long
+*
+* Purpose: Reads an attribute named attr_name
+*
+* Return: Success: 0, Failure: -1
+*
+* Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
+*
+* Date: September 19, 2002
+*
+* Comments:
+*
+* Modifications:
+*
+*-------------------------------------------------------------------------
+*/
herr_t H5LTget_attribute_long( hid_t loc_id,
const char *obj_name,
const char *attr_name,
@@ -2538,26 +2562,26 @@ herr_t H5LTget_attribute_long( hid_t loc_id,
}
/*-------------------------------------------------------------------------
- * Function: H5LTget_attribute_long_long
- *
- * Purpose: Reads an attribute named attr_name
- *
- * Return: Success: 0, Failure: -1
- *
- * Programmer: Elena Pourmal, epourmal@ncsa.uiuc.edu
- *
- * Date: June 17, 2005
- *
- * Comments: This funstion was added to suuport INTEGER*8 Fortran types
- *
- * Modifications:
- *
- *-------------------------------------------------------------------------
- */
+* Function: H5LTget_attribute_long_long
+*
+* Purpose: Reads an attribute named attr_name
+*
+* Return: Success: 0, Failure: -1
+*
+* Programmer: Elena Pourmal, epourmal@ncsa.uiuc.edu
+*
+* Date: June 17, 2005
+*
+* Comments: This funstion was added to suuport INTEGER*8 Fortran types
+*
+* Modifications:
+*
+*-------------------------------------------------------------------------
+*/
herr_t H5LTget_attribute_long_long( hid_t loc_id,
- const char *obj_name,
- const char *attr_name,
- long_long *data )
+ const char *obj_name,
+ const char *attr_name,
+ long long *data )
{
/* Get the attribute */
if(H5LT_get_attribute_mem(loc_id, obj_name, attr_name, H5T_NATIVE_LLONG, data) < 0)
@@ -2568,26 +2592,26 @@ herr_t H5LTget_attribute_long_long( hid_t loc_id,
/*-------------------------------------------------------------------------
- * Function: H5LTget_attribute_ulong
- *
- * Purpose: Reads an attribute named attr_name
- *
- * Return: Success: 0, Failure: -1
- *
- * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
- *
- * Date: March 8, 2004
- *
- * Comments:
- *
- * Modifications:
- *
- *-------------------------------------------------------------------------
- */
+* Function: H5LTget_attribute_ulong
+*
+* Purpose: Reads an attribute named attr_name
+*
+* Return: Success: 0, Failure: -1
+*
+* Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
+*
+* Date: March 8, 2004
+*
+* Comments:
+*
+* Modifications:
+*
+*-------------------------------------------------------------------------
+*/
herr_t H5LTget_attribute_ulong( hid_t loc_id,
- const char *obj_name,
- const char *attr_name,
- unsigned long *data )
+ const char *obj_name,
+ const char *attr_name,
+ unsigned long *data )
{
/* Get the attribute */
if(H5LT_get_attribute_mem(loc_id, obj_name, attr_name, H5T_NATIVE_ULONG, data) < 0)
@@ -2598,28 +2622,28 @@ herr_t H5LTget_attribute_ulong( hid_t loc_id,
/*-------------------------------------------------------------------------
- * Function: H5LTget_attribute_float
- *
- * Purpose: Reads an attribute named attr_name
- *
- * Return: Success: 0, Failure: -1
- *
- * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
- *
- * Date: September 19, 2002
- *
- * Comments:
- *
- * Modifications:
- *
- *-------------------------------------------------------------------------
- */
+* Function: H5LTget_attribute_float
+*
+* Purpose: Reads an attribute named attr_name
+*
+* Return: Success: 0, Failure: -1
+*
+* Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
+*
+* Date: September 19, 2002
+*
+* Comments:
+*
+* Modifications:
+*
+*-------------------------------------------------------------------------
+*/
herr_t H5LTget_attribute_float( hid_t loc_id,
- const char *obj_name,
- const char *attr_name,
- float *data )
+ const char *obj_name,
+ const char *attr_name,
+ float *data )
{
/* Get the attribute */
if(H5LT_get_attribute_mem(loc_id, obj_name, attr_name, H5T_NATIVE_FLOAT, data) < 0)
@@ -2630,28 +2654,28 @@ herr_t H5LTget_attribute_float( hid_t loc_id,
/*-------------------------------------------------------------------------
- * Function: H5LTget_attribute_double
- *
- * Purpose: Reads an attribute named attr_name
- *
- * Return: Success: 0, Failure: -1
- *
- * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
- *
- * Date: September 19, 2002
- *
- * Comments:
- *
- * Modifications:
- *
- *-------------------------------------------------------------------------
- */
+* Function: H5LTget_attribute_double
+*
+* Purpose: Reads an attribute named attr_name
+*
+* Return: Success: 0, Failure: -1
+*
+* Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
+*
+* Date: September 19, 2002
+*
+* Comments:
+*
+* Modifications:
+*
+*-------------------------------------------------------------------------
+*/
herr_t H5LTget_attribute_double( hid_t loc_id,
- const char *obj_name,
- const char *attr_name,
- double *data )
+ const char *obj_name,
+ const char *attr_name,
+ double *data )
{
/* Get the attribute */
if(H5LT_get_attribute_mem(loc_id, obj_name, attr_name, H5T_NATIVE_DOUBLE, data) < 0)
@@ -2662,29 +2686,29 @@ herr_t H5LTget_attribute_double( hid_t loc_id,
/*-------------------------------------------------------------------------
- * Function: H5LTget_attribute
- *
- * Purpose: Reads an attribute named attr_name with the memory type mem_type_id
- *
- * Return: Success: 0, Failure: -1
- *
- * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
- *
- * Date: September 19, 2002
- *
- * Comments: Private function
- *
- * Modifications:
- *
- *-------------------------------------------------------------------------
- */
+* Function: H5LTget_attribute
+*
+* Purpose: Reads an attribute named attr_name with the memory type mem_type_id
+*
+* Return: Success: 0, Failure: -1
+*
+* Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
+*
+* Date: September 19, 2002
+*
+* Comments: Private function
+*
+* Modifications:
+*
+*-------------------------------------------------------------------------
+*/
herr_t H5LTget_attribute( hid_t loc_id,
- const char *obj_name,
- const char *attr_name,
- hid_t mem_type_id,
- void *data )
+ const char *obj_name,
+ const char *attr_name,
+ hid_t mem_type_id,
+ void *data )
{
/* Get the attribute */
if(H5LT_get_attribute_mem(loc_id, obj_name, attr_name, mem_type_id, data) < 0)
@@ -2695,35 +2719,35 @@ herr_t H5LTget_attribute( hid_t loc_id,
/*-------------------------------------------------------------------------
- * private functions
- *-------------------------------------------------------------------------
- */
+* private functions
+*-------------------------------------------------------------------------
+*/
/*-------------------------------------------------------------------------
- * Function: H5LT_get_attribute_mem
- *
- * Purpose: Reads an attribute named attr_name with the memory type mem_type_id
- *
- * Return: Success: 0, Failure: -1
- *
- * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
- *
- * Date: September 19, 2002
- *
- * Comments: Private function
- *
- * Modifications:
- *
- *-------------------------------------------------------------------------
- */
+* Function: H5LT_get_attribute_mem
+*
+* Purpose: Reads an attribute named attr_name with the memory type mem_type_id
+*
+* Return: Success: 0, Failure: -1
+*
+* Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
+*
+* Date: September 19, 2002
+*
+* Comments: Private function
+*
+* Modifications:
+*
+*-------------------------------------------------------------------------
+*/
static herr_t H5LT_get_attribute_mem(hid_t loc_id,
- const char *obj_name,
- const char *attr_name,
- hid_t mem_type_id,
- void *data)
+ const char *obj_name,
+ const char *attr_name,
+ hid_t mem_type_id,
+ void *data)
{
/* identifiers */
hid_t obj_id = -1;
@@ -2745,7 +2769,7 @@ static herr_t H5LT_get_attribute_mem(hid_t loc_id,
/* Close the object */
if(H5Oclose(obj_id) < 0)
- goto out;
+ goto out;
obj_id = -1;
return 0;
@@ -2757,138 +2781,138 @@ out:
}
/*-------------------------------------------------------------------------
- * Function: H5LT_get_attribute_disk
- *
- * Purpose: Reads an attribute named attr_name with the datatype stored on disk
- *
- * Return: Success: 0, Failure: -1
- *
- * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
- *
- * Date: September 19, 2002
- *
- * Comments:
- *
- * Modifications:
- *
- *-------------------------------------------------------------------------
- */
+* Function: H5LT_get_attribute_disk
+*
+* Purpose: Reads an attribute named attr_name with the datatype stored on disk
+*
+* Return: Success: 0, Failure: -1
+*
+* Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
+*
+* Date: September 19, 2002
+*
+* Comments:
+*
+* Modifications:
+*
+*-------------------------------------------------------------------------
+*/
herr_t H5LT_get_attribute_disk( hid_t loc_id,
- const char *attr_name,
- void *attr_out )
+ const char *attr_name,
+ void *attr_out )
{
- /* identifiers */
- hid_t attr_id;
- hid_t attr_type;
+ /* identifiers */
+ hid_t attr_id;
+ hid_t attr_type;
- if(( attr_id = H5Aopen(loc_id, attr_name, H5P_DEFAULT)) < 0)
- return -1;
+ if(( attr_id = H5Aopen(loc_id, attr_name, H5P_DEFAULT)) < 0)
+ return -1;
- if((attr_type = H5Aget_type(attr_id)) < 0)
- goto out;
+ if((attr_type = H5Aget_type(attr_id)) < 0)
+ goto out;
- if(H5Aread(attr_id, attr_type, attr_out) < 0)
- goto out;
+ if(H5Aread(attr_id, attr_type, attr_out) < 0)
+ goto out;
- if(H5Tclose(attr_type) < 0)
- goto out;
+ if(H5Tclose(attr_type) < 0)
+ goto out;
- if ( H5Aclose( attr_id ) < 0 )
- return -1;;
+ if ( H5Aclose( attr_id ) < 0 )
+ return -1;;
- return 0;
+ return 0;
out:
- H5Tclose( attr_type );
- H5Aclose( attr_id );
- return -1;
+ H5Tclose( attr_type );
+ H5Aclose( attr_id );
+ return -1;
}
/*-------------------------------------------------------------------------
- * Function: H5LT_set_attribute_string
- *
- * Purpose: creates and writes an attribute named NAME to the dataset DSET_ID
- *
- * Return: FAIL on error, SUCCESS on success
- *
- * Programmer: pvn@ncsa.uiuc.edu
- *
- * Date: January 04, 2005
- *
- * Comments:
- *
- * Modifications:
- *
- *-------------------------------------------------------------------------
- */
+* Function: H5LT_set_attribute_string
+*
+* Purpose: creates and writes an attribute named NAME to the dataset DSET_ID
+*
+* Return: FAIL on error, SUCCESS on success
+*
+* Programmer: pvn@ncsa.uiuc.edu
+*
+* Date: January 04, 2005
+*
+* Comments:
+*
+* Modifications:
+*
+*-------------------------------------------------------------------------
+*/
herr_t H5LT_set_attribute_string(hid_t dset_id,
const char *name,
const char *buf )
{
- hid_t tid;
- hid_t sid = -1;
- hid_t aid = -1;
- int has_attr;
- size_t size;
-
- /* verify if the attribute already exists */
- has_attr = H5LT_find_attribute(dset_id,name);
-
- /* the attribute already exists, delete it */
- if(has_attr == 1)
- if(H5Adelete(dset_id, name) < 0)
- return FAIL;
+ hid_t tid;
+ hid_t sid = -1;
+ hid_t aid = -1;
+ int has_attr;
+ size_t size;
-/*-------------------------------------------------------------------------
- * create the attribute type
- *-------------------------------------------------------------------------
- */
- if((tid = H5Tcopy(H5T_C_S1)) < 0)
- return FAIL;
+ /* verify if the attribute already exists */
+ has_attr = H5LT_find_attribute(dset_id,name);
- size = strlen(buf) + 1; /* extra null term */
+ /* the attribute already exists, delete it */
+ if(has_attr == 1)
+ if(H5Adelete(dset_id, name) < 0)
+ return FAIL;
+
+ /*-------------------------------------------------------------------------
+ * create the attribute type
+ *-------------------------------------------------------------------------
+ */
+ if((tid = H5Tcopy(H5T_C_S1)) < 0)
+ return FAIL;
+
+ size = strlen(buf) + 1; /* extra null term */
- if(H5Tset_size(tid,(size_t)size) < 0)
- goto out;
+ if(H5Tset_size(tid,(size_t)size) < 0)
+ goto out;
- if(H5Tset_strpad(tid, H5T_STR_NULLTERM) < 0)
- goto out;
+ if(H5Tset_strpad(tid, H5T_STR_NULLTERM) < 0)
+ goto out;
- if((sid = H5Screate(H5S_SCALAR)) < 0)
- goto out;
+ if((sid = H5Screate(H5S_SCALAR)) < 0)
+ goto out;
-/*-------------------------------------------------------------------------
- * create and write the attribute
- *-------------------------------------------------------------------------
- */
- if((aid = H5Acreate2(dset_id, name, tid, sid, H5P_DEFAULT, H5P_DEFAULT)) < 0)
- goto out;
+ /*-------------------------------------------------------------------------
+ * create and write the attribute
+ *-------------------------------------------------------------------------
+ */
+ if((aid = H5Acreate2(dset_id, name, tid, sid, H5P_DEFAULT, H5P_DEFAULT)) < 0)
+ goto out;
- if(H5Awrite(aid, tid, buf) < 0)
- goto out;
+ if(H5Awrite(aid, tid, buf) < 0)
+ goto out;
- if(H5Aclose(aid) < 0)
- goto out;
+ if(H5Aclose(aid) < 0)
+ goto out;
- if(H5Sclose(sid) < 0)
- goto out;
+ if(H5Sclose(sid) < 0)
+ goto out;
- if(H5Tclose(tid) < 0)
- goto out;
+ if(H5Tclose(tid) < 0)
+ goto out;
- return SUCCEED;
+ return SUCCEED;
- /* error zone, gracefully close */
+ /* error zone */
out:
- H5E_BEGIN_TRY {
- H5Aclose(aid);
- H5Tclose(tid);
- H5Sclose(sid);
- } H5E_END_TRY;
- return FAIL;
+ H5E_BEGIN_TRY {
+ H5Aclose(aid);
+ H5Tclose(tid);
+ H5Sclose(sid);
+ } H5E_END_TRY;
+ return FAIL;
}
diff --git a/hl/src/H5LTanalyze.c b/hl/src/H5LTanalyze.c
index f46b9ea..9e9eec2 100644
--- a/hl/src/H5LTanalyze.c
+++ b/hl/src/H5LTanalyze.c
@@ -849,7 +849,7 @@ hbool_t first_quote = 1;
/* For Lex and Yacc */
/*int input_len;
char *myinput;*/
-
+
#define TAG_STRING 1
#line 834 "H5LTanalyze.c"
@@ -1288,17 +1288,17 @@ YY_RULE_SETUP
case 40:
YY_RULE_SETUP
#line 121 "H5LTanalyze.l"
-{return token(H5T_STR_NULLTERM_TOKEN);}
+{return token(H5T_STR_NULLTERM_TOKEN);}
YY_BREAK
case 41:
YY_RULE_SETUP
#line 122 "H5LTanalyze.l"
-{return token(H5T_STR_NULLPAD_TOKEN);}
+{return token(H5T_STR_NULLPAD_TOKEN);}
YY_BREAK
case 42:
YY_RULE_SETUP
#line 123 "H5LTanalyze.l"
-{return token(H5T_STR_SPACEPAD_TOKEN);}
+{return token(H5T_STR_SPACEPAD_TOKEN);}
YY_BREAK
case 43:
YY_RULE_SETUP
@@ -1363,12 +1363,12 @@ YY_RULE_SETUP
case 55:
YY_RULE_SETUP
#line 139 "H5LTanalyze.l"
-{
- if( is_str_size || (is_enum && is_enum_memb) ||
+{
+ if( is_str_size || (is_enum && is_enum_memb) ||
is_opq_size || (asindex>-1 && arr_stack[asindex].is_dim) ||
(csindex>-1 && cmpd_stack[csindex].is_field) ) {
H5LTyylval.ival = atoi(yytext);
- return NUMBER;
+ return NUMBER;
} else
REJECT;
}
@@ -1378,7 +1378,7 @@ YY_RULE_SETUP
#line 149 "H5LTanalyze.l"
{
/*if it's first quote, and is a compound field name or an enum symbol*/
- if((is_opq_tag || is_enum || (csindex>-1 && cmpd_stack[csindex].is_field))
+ if((is_opq_tag || is_enum || (csindex>-1 && cmpd_stack[csindex].is_field))
&& first_quote) {
first_quote = 0;
BEGIN TAG_STRING;
@@ -2323,8 +2323,8 @@ int main()
int my_yyinput(char *buf, int max_size)
{
int ret;
-
- memcpy(buf, myinput, input_len);
+
+ memcpy(buf, myinput, input_len);
ret = input_len;
return ret;
}
diff --git a/hl/src/H5LTparse.c b/hl/src/H5LTparse.c
index 35c4670..98dcbd5 100644
--- a/hl/src/H5LTparse.c
+++ b/hl/src/H5LTparse.c
@@ -14,9 +14,8 @@
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* This file was generated by Yacc with the command "yacc -pH5LTyy -o H5LTparse.c -d H5LTparse.y"
- * Do NOT modify it by hand.
+ * on jam. Do NOT modify it by hand.
*/
-
#ifndef lint
static char const
yyrcsid[] = "$FreeBSD: src/usr.bin/yacc/skeleton.c,v 1.28 2000/01/17 02:04:06 bde Exp $";
@@ -1053,22 +1052,35 @@ case 92:
short short_val=(short)yylval.ival;
int int_val=(int)yylval.ival;
long long_val=(long)yylval.ival;
- long_long llong_val=(long_long)yylval.ival;
+ long long llong_val=(long long)yylval.ival;
hid_t super = H5Tget_super(enum_id);
hid_t native = H5Tget_native_type(super, H5T_DIR_ASCEND);
-
+ H5T_order_t super_order = H5Tget_order(super);
+ H5T_order_t native_order = H5Tget_order(native);
+
if(is_enum && is_enum_memb) { /*if it's an enum member*/
/*To handle machines of different endianness*/
- if(H5Tequal(native, H5T_NATIVE_SCHAR) || H5Tequal(native, H5T_NATIVE_UCHAR))
+ if(H5Tequal(native, H5T_NATIVE_SCHAR) || H5Tequal(native, H5T_NATIVE_UCHAR)) {
+ if(super_order != native_order)
+ H5Tconvert(native, super, 1, &char_val, NULL, H5P_DEFAULT);
H5Tenum_insert(enum_id, enum_memb_symbol, &char_val);
- else if(H5Tequal(native, H5T_NATIVE_SHORT) || H5Tequal(native, H5T_NATIVE_USHORT))
+ } else if(H5Tequal(native, H5T_NATIVE_SHORT) || H5Tequal(native, H5T_NATIVE_USHORT)) {
+ if(super_order != native_order)
+ H5Tconvert(native, super, 1, &short_val, NULL, H5P_DEFAULT);
H5Tenum_insert(enum_id, enum_memb_symbol, &short_val);
- else if(H5Tequal(native, H5T_NATIVE_INT) || H5Tequal(native, H5T_NATIVE_UINT))
+ } else if(H5Tequal(native, H5T_NATIVE_INT) || H5Tequal(native, H5T_NATIVE_UINT)) {
+ if(super_order != native_order)
+ H5Tconvert(native, super, 1, &int_val, NULL, H5P_DEFAULT);
H5Tenum_insert(enum_id, enum_memb_symbol, &int_val);
- else if(H5Tequal(native, H5T_NATIVE_LONG) || H5Tequal(native, H5T_NATIVE_ULONG))
+ } else if(H5Tequal(native, H5T_NATIVE_LONG) || H5Tequal(native, H5T_NATIVE_ULONG)) {
+ if(super_order != native_order)
+ H5Tconvert(native, super, 1, &long_val, NULL, H5P_DEFAULT);
H5Tenum_insert(enum_id, enum_memb_symbol, &long_val);
- else if(H5Tequal(native, H5T_NATIVE_LLONG) || H5Tequal(native, H5T_NATIVE_ULLONG))
+ } else if(H5Tequal(native, H5T_NATIVE_LLONG) || H5Tequal(native, H5T_NATIVE_ULLONG)) {
+ if(super_order != native_order)
+ H5Tconvert(native, super, 1, &llong_val, NULL, H5P_DEFAULT);
H5Tenum_insert(enum_id, enum_memb_symbol, &llong_val);
+ }
is_enum_memb = 0;
if(enum_memb_symbol) free(enum_memb_symbol);
@@ -1078,7 +1090,7 @@ case 92:
H5Tclose(native);
}
break;
-#line 1063 "H5LTparse.c"
+#line 1076 "H5LTparse.c"
}
yyssp -= yym;
yystate = *yyssp;
diff --git a/hl/src/H5LTparse.y b/hl/src/H5LTparse.y
index 7866add..a021efc 100644
--- a/hl/src/H5LTparse.y
+++ b/hl/src/H5LTparse.y
@@ -337,22 +337,35 @@ enum_def : '"' enum_symbol '"' {
short short_val=(short)yylval.ival;
int int_val=(int)yylval.ival;
long long_val=(long)yylval.ival;
- long_long llong_val=(long_long)yylval.ival;
+ long long llong_val=(long long)yylval.ival;
hid_t super = H5Tget_super(enum_id);
hid_t native = H5Tget_native_type(super, H5T_DIR_ASCEND);
-
+ H5T_order_t super_order = H5Tget_order(super);
+ H5T_order_t native_order = H5Tget_order(native);
+
if(is_enum && is_enum_memb) { /*if it's an enum member*/
/*To handle machines of different endianness*/
- if(H5Tequal(native, H5T_NATIVE_SCHAR) || H5Tequal(native, H5T_NATIVE_UCHAR))
+ if(H5Tequal(native, H5T_NATIVE_SCHAR) || H5Tequal(native, H5T_NATIVE_UCHAR)) {
+ if(super_order != native_order)
+ H5Tconvert(native, super, 1, &char_val, NULL, H5P_DEFAULT);
H5Tenum_insert(enum_id, enum_memb_symbol, &char_val);
- else if(H5Tequal(native, H5T_NATIVE_SHORT) || H5Tequal(native, H5T_NATIVE_USHORT))
+ } else if(H5Tequal(native, H5T_NATIVE_SHORT) || H5Tequal(native, H5T_NATIVE_USHORT)) {
+ if(super_order != native_order)
+ H5Tconvert(native, super, 1, &short_val, NULL, H5P_DEFAULT);
H5Tenum_insert(enum_id, enum_memb_symbol, &short_val);
- else if(H5Tequal(native, H5T_NATIVE_INT) || H5Tequal(native, H5T_NATIVE_UINT))
+ } else if(H5Tequal(native, H5T_NATIVE_INT) || H5Tequal(native, H5T_NATIVE_UINT)) {
+ if(super_order != native_order)
+ H5Tconvert(native, super, 1, &int_val, NULL, H5P_DEFAULT);
H5Tenum_insert(enum_id, enum_memb_symbol, &int_val);
- else if(H5Tequal(native, H5T_NATIVE_LONG) || H5Tequal(native, H5T_NATIVE_ULONG))
+ } else if(H5Tequal(native, H5T_NATIVE_LONG) || H5Tequal(native, H5T_NATIVE_ULONG)) {
+ if(super_order != native_order)
+ H5Tconvert(native, super, 1, &long_val, NULL, H5P_DEFAULT);
H5Tenum_insert(enum_id, enum_memb_symbol, &long_val);
- else if(H5Tequal(native, H5T_NATIVE_LLONG) || H5Tequal(native, H5T_NATIVE_ULLONG))
+ } else if(H5Tequal(native, H5T_NATIVE_LLONG) || H5Tequal(native, H5T_NATIVE_ULLONG)) {
+ if(super_order != native_order)
+ H5Tconvert(native, super, 1, &llong_val, NULL, H5P_DEFAULT);
H5Tenum_insert(enum_id, enum_memb_symbol, &llong_val);
+ }
is_enum_memb = 0;
if(enum_memb_symbol) free(enum_memb_symbol);
diff --git a/hl/src/H5LTpublic.h b/hl/src/H5LTpublic.h
index 05670d2..7fb873a 100644
--- a/hl/src/H5LTpublic.h
+++ b/hl/src/H5LTpublic.h
@@ -203,7 +203,7 @@ H5_HLDLL herr_t H5LTset_attribute_long( hid_t loc_id,
H5_HLDLL herr_t H5LTset_attribute_long_long( hid_t loc_id,
const char *obj_name,
const char *attr_name,
- const long_long *buffer,
+ const long long *buffer,
size_t size );
H5_HLDLL herr_t H5LTset_attribute_ulong( hid_t loc_id,
@@ -280,7 +280,7 @@ H5_HLDLL herr_t H5LTget_attribute_long( hid_t loc_id,
H5_HLDLL herr_t H5LTget_attribute_long_long( hid_t loc_id,
const char *obj_name,
const char *attr_name,
- long_long *data );
+ long long *data );
H5_HLDLL herr_t H5LTget_attribute_ulong( hid_t loc_id,
const char *obj_name,
diff --git a/hl/src/H5PT.c b/hl/src/H5PT.c
index 2119cca..3d16db5 100644
--- a/hl/src/H5PT.c
+++ b/hl/src/H5PT.c
@@ -33,10 +33,10 @@ static H5I_type_t H5PT_ptable_id_type = H5I_UNINIT;
#define H5PT_HASH_TABLE_SIZE 64
/* Packet Table private functions */
-herr_t H5PT_close( htbl_t* table );
-herr_t H5PT_create_index(htbl_t *table_id);
-herr_t H5PT_set_index(htbl_t *table_id, hsize_t pt_index);
-herr_t H5PT_get_index(htbl_t *table_id, hsize_t *pt_index);
+static herr_t H5PT_close( htbl_t* table );
+static herr_t H5PT_create_index(htbl_t *table_id);
+static herr_t H5PT_set_index(htbl_t *table_id, hsize_t pt_index);
+static herr_t H5PT_get_index(htbl_t *table_id, hsize_t *pt_index);
/*-------------------------------------------------------------------------
*
@@ -269,6 +269,8 @@ hid_t H5PTopen( hid_t loc_id,
goto out;
if( H5Sget_simple_extent_dims( space_id, dims, NULL) < 0)
goto out;
+ if(H5Sclose(space_id) < 0)
+ goto out;
table->size = dims[0];
/* Get an ID for this table */
@@ -284,6 +286,7 @@ hid_t H5PTopen( hid_t loc_id,
out:
H5E_BEGIN_TRY
H5Tclose(type_id);
+ H5Sclose(space_id);
if(table)
{
H5Dclose(table->dset_id);
@@ -314,7 +317,8 @@ out:
*
*-------------------------------------------------------------------------
*/
-herr_t H5PT_close( htbl_t* table)
+static herr_t
+H5PT_close( htbl_t* table)
{
if(table == NULL)
goto out;
@@ -567,7 +571,8 @@ out:
*
*-------------------------------------------------------------------------
*/
-herr_t H5PT_create_index(htbl_t *table)
+static herr_t
+H5PT_create_index(htbl_t *table)
{
if( table != NULL)
{
@@ -577,7 +582,8 @@ herr_t H5PT_create_index(htbl_t *table)
return -1;
}
-herr_t H5PT_set_index(htbl_t *table, hsize_t index)
+static herr_t
+H5PT_set_index(htbl_t *table, hsize_t index)
{
/* Ensure index is valid */
if( table != NULL )
@@ -591,7 +597,8 @@ herr_t H5PT_set_index(htbl_t *table, hsize_t index)
return -1;
}
-herr_t H5PT_get_index(htbl_t *table, hsize_t *index)
+static herr_t
+H5PT_get_index(htbl_t *table, hsize_t *index)
{
/* Ensure index is valid */
if( table != NULL )
diff --git a/hl/src/H5TB.c b/hl/src/H5TB.c
index e80f86c..a035319 100644
--- a/hl/src/H5TB.c
+++ b/hl/src/H5TB.c
@@ -1,17 +1,17 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- * Copyright by The HDF Group. *
- * Copyright by the Board of Trustees of the University of Illinois. *
- * All rights reserved. *
- * *
- * This file is part of HDF5. The full HDF5 copyright notice, including *
- * terms governing use, modification, and redistribution, is contained in *
- * the files COPYING and Copyright.html. COPYING can be found at the root *
- * of the source code distribution tree; Copyright.html can be found at the *
- * root level of an installed copy of the electronic HDF5 document set and *
- * is linked from the top-level documents page. It can also be found at *
- * http://hdfgroup.org/HDF5/doc/Copyright.html. If you do not have *
- * access to either file, you may request a copy from help@hdfgroup.org. *
- * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
+* Copyright by The HDF Group. *
+* Copyright by the Board of Trustees of the University of Illinois. *
+* All rights reserved. *
+* *
+* This file is part of HDF5. The full HDF5 copyright notice, including *
+* terms governing use, modification, and redistribution, is contained in *
+* the files COPYING and Copyright.html. COPYING can be found at the root *
+* of the source code distribution tree; Copyright.html can be found at the *
+* root level of an installed copy of the electronic HDF5 document set and *
+* is linked from the top-level documents page. It can also be found at *
+* http://hdfgroup.org/HDF5/doc/Copyright.html. If you do not have *
+* access to either file, you may request a copy from help@hdfgroup.org. *
+* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#include <stdlib.h>
#include <string.h>
@@ -20,11 +20,11 @@
/*-------------------------------------------------------------------------
- *
- * internal functions
- *
- *-------------------------------------------------------------------------
- */
+*
+* internal functions
+*
+*-------------------------------------------------------------------------
+*/
static int H5TB_find_field(const char *field,
const char *field_list);
@@ -43,974 +43,436 @@ static hid_t H5TB_create_type(hid_t loc_id,
hid_t ftype_id);
/*-------------------------------------------------------------------------
- *
- * Create functions
- *
- *-------------------------------------------------------------------------
- */
-
-/*-------------------------------------------------------------------------
- * Function: H5TBmake_table
- *
- * Purpose: Make a table
- *
- * Return: Success: 0, Failure: -1
- *
- * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
- * Quincey Koziol
- *
- * Date: January 17, 2001
- *
- * Comments:
- *
- * Modifications:
- *
- *-------------------------------------------------------------------------
- */
+*
+* Create functions
+*
+*-------------------------------------------------------------------------
+*/
+
+/*-------------------------------------------------------------------------
+* Function: H5TBmake_table
+*
+* Purpose: Make a table
+*
+* Return: Success: 0, Failure: -1
+*
+* Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
+* Quincey Koziol
+*
+* Date: January 17, 2001
+*
+* Comments:
+*
+* Modifications:
+*
+*-------------------------------------------------------------------------
+*/
herr_t H5TBmake_table( const char *table_title,
- hid_t loc_id,
- const char *dset_name,
- hsize_t nfields,
- hsize_t nrecords,
- size_t type_size,
- const char *field_names[],
- const size_t *field_offset,
- const hid_t *field_types,
- hsize_t chunk_size,
- void *fill_data,
- int compress,
- const void *data )
+ hid_t loc_id,
+ const char *dset_name,
+ hsize_t nfields,
+ hsize_t nrecords,
+ size_t type_size,
+ const char *field_names[],
+ const size_t *field_offset,
+ const hid_t *field_types,
+ hsize_t chunk_size,
+ void *fill_data,
+ int compress,
+ const void *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 = H5Dcreate2(loc_id, dset_name, mem_type_id, sid, H5P_DEFAULT, plist_id, H5P_DEFAULT)) < 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_CLASS ) < 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 );
+ 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;
+ }
- /* Attach the attribute */
- if(H5LTset_attribute_string( loc_id, dset_name, attr_name, member_name ) < 0)
- goto out;
+ /* create a simple data space with unlimited size */
+ if ((sid = H5Screate_simple( 1, dims, maxdims )) < 0)
+ return -1;
- free( member_name );
+ /* 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;
+ }
- /* Attach the FIELD_ fill value attribute */
- if(fill_data )
- {
+ /*
+ 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;
+ }
- tmp_buf = fill_data;
+ /* create the dataset. */
+ if ((did = H5Dcreate2(loc_id, dset_name, mem_type_id, sid, H5P_DEFAULT, plist_id, H5P_DEFAULT)) < 0)
+ goto out;
- /* Open the dataset. */
- if((did = H5Dopen2(loc_id, dset_name, H5P_DEFAULT)) < 0)
- return -1;
+ /* 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;
+ }
- if (( sid = H5Screate(H5S_SCALAR)) < 0)
- goto out;
+ /* terminate access to the data space. */
+ if (H5Sclose(sid) < 0)
+ goto out;
- for ( i = 0; i < nfields; i++)
- {
+ /* end access to the dataset */
+ if (H5Dclose(did) < 0)
+ goto out;
- /* Get the member name */
- member_name = H5Tget_member_name(mem_type_id, (unsigned)i);
+ /* end access to the property list */
+ if (H5Pclose(plist_id) < 0)
+ goto out;
- strcpy(attr_name, "FIELD_");
- sprintf(aux, "%d", (int)i);
- strcat(attr_name, aux);
- sprintf(aux, "%s", "_FILL");
- strcat(attr_name, aux);
+ /*-------------------------------------------------------------------------
+ * set the conforming table attributes
+ *-------------------------------------------------------------------------
+ */
- if((attr_id = H5Acreate2(did, attr_name, field_types[i], sid, H5P_DEFAULT, H5P_DEFAULT)) < 0)
- goto out;
+ /* attach the CLASS attribute */
+ if (H5LTset_attribute_string( loc_id, dset_name, "CLASS", TABLE_CLASS ) < 0)
+ goto out;
- if(H5Awrite(attr_id, field_types[i], tmp_buf+field_offset[i]) < 0)
- goto out;
+ /* attach the VERSION attribute */
+ if (H5LTset_attribute_string( loc_id, dset_name, "VERSION", TABLE_VERSION ) < 0)
+ goto out;
- if(H5Aclose(attr_id) < 0)
- goto out;
+ /* attach the TITLE attribute */
+ if (H5LTset_attribute_string( loc_id, dset_name, "TITLE", table_title ) < 0)
+ goto out;
- free(member_name);
- }
+ /* 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 );
- /* Close the dataset. */
- H5Dclose( did );
+ strcpy( attr_name, "FIELD_" );
+ sprintf( aux, "%d", (int)i );
+ strcat( attr_name, aux );
+ sprintf( aux, "%s", "_NAME" );
+ strcat( attr_name, aux );
- /* Close data space. */
- H5Sclose( sid );
- }
+ /* attach the attribute */
+ if (H5LTset_attribute_string( loc_id, dset_name, attr_name, member_name ) < 0)
+ goto out;
- /* Release the datatype. */
- if(H5Tclose( mem_type_id ) < 0)
- return -1;
+ free( member_name );
-return 0;
+ }
-/* error zone, gracefully close */
-out:
- H5E_BEGIN_TRY {
- H5Dclose(did);
- H5Sclose(sid);
- H5Pclose(plist_id);
- H5Tclose(mem_type_id);
- } H5E_END_TRY;
- return -1;
+ /* attach the FIELD_ fill value attribute */
+ if (fill_data )
+ {
-}
+ tmp_buf = (unsigned char *) fill_data;
-/*-------------------------------------------------------------------------
- *
- * Write functions
- *
- *-------------------------------------------------------------------------
- */
+ /* open the dataset. */
+ if ((did = H5Dopen2(loc_id, dset_name, H5P_DEFAULT)) < 0)
+ return -1;
-/*-------------------------------------------------------------------------
- * Function: H5TBappend_records
- *
- * Purpose: Appends records to a table
- *
- * Return: Success: 0, Failure: -1
- *
- * Programmers:
- * Pedro Vicente, pvn@ncsa.uiuc.edu
- * Quincey Koziol
- *
- * Date: November 19, 2001
- *
- * Comments: Uses memory offsets
- *
- * Modifications: April 1, 2004
- * the DST_SIZES parameter is used to define the memory type ID
- * returned by H5TB_create_type
- *
- *-------------------------------------------------------------------------
- */
+ if (( sid = H5Screate(H5S_SCALAR)) < 0)
+ goto out;
-herr_t H5TBappend_records( hid_t loc_id,
- const char *dset_name,
- hsize_t nrecords,
- size_t type_size,
- const size_t *field_offset,
- const size_t *field_sizes,
- const void *data )
-{
- hid_t did;
- hid_t tid=-1;
- hid_t mem_type_id=-1;
- hid_t sid=-1;
- hid_t mem_space_id=-1;
- hsize_t nrecords_orig;
- hsize_t nfields;
+ for ( i = 0; i < nfields; i++)
+ {
- /* Get the original number of records and fields */
- if(H5TBget_table_info ( loc_id, dset_name, &nfields, &nrecords_orig ) < 0)
- return -1;
+ /* get the member name */
+ member_name = H5Tget_member_name(mem_type_id, (unsigned)i);
- /* Open the dataset. */
- if((did = H5Dopen2(loc_id, dset_name, H5P_DEFAULT)) < 0)
- goto out;
+ strcpy(attr_name, "FIELD_");
+ sprintf(aux, "%d", (int)i);
+ strcat(attr_name, aux);
+ sprintf(aux, "%s", "_FILL");
+ strcat(attr_name, aux);
- /* Get the datatypes */
- if((tid = H5Dget_type( did )) < 0)
- goto out;
+ if ((attr_id = H5Acreate2(did, attr_name, field_types[i], sid, H5P_DEFAULT, H5P_DEFAULT)) < 0)
+ goto out;
- if ((mem_type_id=H5TB_create_type(loc_id,dset_name,type_size,field_offset,field_sizes,tid)) < 0)
- goto out;
+ if (H5Awrite(attr_id, field_types[i], tmp_buf+field_offset[i]) < 0)
+ goto out;
- /* Append the records */
- if ((H5TB_common_append_records(did, mem_type_id, (size_t)nrecords, nrecords_orig, data)) < 0)
- goto out;
+ if (H5Aclose(attr_id) < 0)
+ goto out;
- /* Release the datatype. */
- if(H5Tclose( tid ) < 0)
- return -1;
+ free(member_name);
+ }
- /* Release the datatype. */
- if(H5Tclose( mem_type_id ) < 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 dataset */
+ if (H5Dclose(did) < 0)
+ goto out;
+ }
+ /* release the datatype. */
+ if (H5Tclose( mem_type_id ) < 0)
+ return -1;
-return 0;
+ return 0;
-/* error zone, gracefully close */
+ /* 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);
+ H5Sclose(sid);
+ H5Pclose(plist_id);
+ H5Tclose(mem_type_id);
+ } H5E_END_TRY;
+ return -1;
+
}
/*-------------------------------------------------------------------------
- * Function: H5TBwrite_records
- *
- * Purpose: Writes records
- *
- * Return: Success: 0, Failure: -1
- *
- * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
- *
- * Date: November 19, 2001
- *
- * Comments: Uses memory offsets
- *
- * Modifications: April 1, 2004
- * the DST_SIZES parameter is used to define the memory type ID
- * returned by H5TB_create_type
- *
- *-------------------------------------------------------------------------
- */
-
+*
+* Write functions
+*
+*-------------------------------------------------------------------------
+*/
+
+/*-------------------------------------------------------------------------
+* Function: H5TBappend_records
+*
+* Purpose: Appends records to a table
+*
+* Return: Success: 0, Failure: -1
+*
+* Programmers:
+* Pedro Vicente, pvn@ncsa.uiuc.edu
+* Quincey Koziol
+*
+* Date: November 19, 2001
+*
+* Comments: Uses memory offsets
+*
+* Modifications: April 1, 2004
+* the FIELD_SIZES parameter is used to define the memory type ID
+* returned by H5TB_create_type
+*
+*-------------------------------------------------------------------------
+*/
-herr_t H5TBwrite_records( hid_t loc_id,
+herr_t H5TBappend_records( hid_t loc_id,
const char *dset_name,
- hsize_t start,
hsize_t nrecords,
size_t type_size,
const size_t *field_offset,
const size_t *field_sizes,
- const void *data )
-{
-
- 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 = H5Dopen2(loc_id, dset_name, H5P_DEFAULT)) < 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((mem_space_id = H5Screate_simple( 1, mem_size, NULL )) < 0)
- goto out;
-
- if(H5Dwrite( did, mem_type_id, mem_space_id, sid, H5P_DEFAULT, data ) < 0)
- goto out;
-
- /* Terminate access to the memory dataspace */
- if(H5Sclose( mem_space_id ) < 0)
- goto out;
-
- /* Terminate access to the dataspace */
- if(H5Sclose( sid ) < 0)
- goto out;
-
- /* Release the datatype. */
- if(H5Tclose( tid ) < 0)
- goto out;
-
- /* Release the datatype. */
- if(H5Tclose( mem_type_id ) < 0)
- return -1;
-
- /* End access to the dataset */
- if(H5Dclose( did ) < 0)
- return -1;
-
-
-return 0;
-
-/* error zone, gracefully close */
-out:
- H5E_BEGIN_TRY {
- H5Dclose(did);
- H5Tclose(mem_type_id);
- H5Tclose(tid);
- H5Sclose(mem_space_id);
- H5Sclose(sid);
- } H5E_END_TRY;
- return -1;
-}
-
-/*-------------------------------------------------------------------------
- * Function: H5TBwrite_fields_name
- *
- * Purpose: Writes fields
- *
- * Return: Success: 0, Failure: -1
- *
- * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
- *
- * Date: November 21, 2001
- *
- * Comments:
- *
- * Modifications: April 1, 2004
- * the DST_SIZES parameter is used to define the memory type ID
- * returned by H5TB_create_type
- *
- *-------------------------------------------------------------------------
- */
-herr_t H5TBwrite_fields_name( hid_t loc_id,
- const char *dset_name,
- const char *field_names,
- hsize_t start,
- hsize_t nrecords,
- size_t type_size,
- const size_t *field_offset,
- const size_t *field_sizes,
- const void *data )
-{
-
- hid_t did;
- hid_t tid=-1;
- hid_t write_type_id=-1;
- hid_t member_type_id;
- hid_t nmtype_id;
- hsize_t count[1];
- 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 = H5Dopen2(loc_id, dset_name, H5P_DEFAULT)) < 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((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 */
-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;
-
-}
-
-
-
-/*-------------------------------------------------------------------------
- * Function: H5TBwrite_fields_index
- *
- * Purpose: Writes fields
- *
- * Return: Success: 0, Failure: -1
- *
- * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
- *
- * Date: November 21, 2001
- *
- * Comments: Uses memory offsets
- *
- * Modifications: April 1, 2004
- * the DST_SIZES parameter is used to define the memory type ID
- * returned by H5TB_create_type
- *
- *-------------------------------------------------------------------------
- */
-
-
-herr_t H5TBwrite_fields_index( hid_t loc_id,
- const char *dset_name,
- hsize_t nfields,
- const int *field_index,
- hsize_t start,
- hsize_t nrecords,
- size_t type_size,
- const size_t *field_offset,
- const size_t *field_sizes,
- const void *data )
+ 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 = H5Dopen2(loc_id, dset_name, H5P_DEFAULT)) < 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((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 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 = H5Dopen2(loc_id, dset_name, H5P_DEFAULT)) < 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 {
- H5Pclose(PRESERVE);
- H5Dclose(did);
- H5Sclose(file_space_id);
- H5Sclose(mem_space_id);
- H5Tclose(write_type_id);
- H5Tclose(tid);
- } H5E_END_TRY;
- return -1;
-}
-
-
-/*-------------------------------------------------------------------------
- *
- * Read functions
- *
- *-------------------------------------------------------------------------
- */
-
-
-/*-------------------------------------------------------------------------
- * Function: H5TBread_table
- *
- * Purpose: Reads a table
- *
- * Return: Success: 0, Failure: -1
- *
- * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
- *
- * Date: November 20, 2001
- *
- * Comments:
- *
- * Modifications: April 1, 2004
- * used a memory type ID returned by H5TB_create_type
- *
- *-------------------------------------------------------------------------
- */
-
-herr_t H5TBread_table( hid_t loc_id,
- const char *dset_name,
- size_t 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 = H5Dopen2(loc_id, dset_name, H5P_DEFAULT)) < 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, gracefully close */
-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(tid);
+ H5Sclose(m_sid);
+ H5Sclose(sid);
+ } H5E_END_TRY;
+ return -1;
}
/*-------------------------------------------------------------------------
- * Function: H5TBread_records
- *
- * Purpose: Reads records
- *
- * Return: Success: 0, Failure: -1
- *
- * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
- *
- * Date: November 19, 2001
- *
- * Comments:
- *
- * Modifications: April 1, 2004
- * the DST_SIZES parameter is used to define the memory type ID
- * returned by H5TB_create_type
- *
- *-------------------------------------------------------------------------
- */
+* Function: H5TBwrite_records
+*
+* Purpose: Writes records
+*
+* Return: Success: 0, Failure: -1
+*
+* Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
+*
+* Date: November 19, 2001
+*
+* Comments: Uses memory offsets
+*
+* Modifications: April 1, 2004
+* the FIELD_SIZES parameter is used to define the memory type ID
+* returned by H5TB_create_type
+*
+*-------------------------------------------------------------------------
+*/
-herr_t H5TBread_records( hid_t loc_id,
+herr_t H5TBwrite_records( hid_t loc_id,
const char *dset_name,
hsize_t start,
hsize_t nrecords,
size_t type_size,
const size_t *field_offset,
const size_t *field_sizes,
- void *data )
+ const 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 = H5Dopen2(loc_id, dset_name, H5P_DEFAULT)) < 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, data)) < 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 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 = H5Dopen2(loc_id, dset_name, H5P_DEFAULT)) < 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(ftype_id);
- 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;
}
-
/*-------------------------------------------------------------------------
- * Function: H5TBread_fields_name
- *
- * Purpose: Reads fields
- *
- * Return: Success: 0, Failure: -1
- *
- * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
- *
- * Date: November 19, 2001
- *
- * Comments:
- *
- * Modifications: April 1, 2004
- * the DST_SIZES parameter is used to define the memory type ID
- * returned by H5TB_create_type
- *
- *-------------------------------------------------------------------------
- */
-
-
-herr_t H5TBread_fields_name( hid_t loc_id,
+* Function: H5TBwrite_fields_name
+*
+* Purpose: Writes fields
+*
+* Return: Success: 0, Failure: -1
+*
+* Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
+*
+* Date: November 21, 2001
+*
+* Comments:
+*
+* Modifications: April 1, 2004
+* the FIELD_SIZES parameter is used to define a memory type ID
+*
+*-------------------------------------------------------------------------
+*/
+herr_t H5TBwrite_fields_name( hid_t loc_id,
const char *dset_name,
const char *field_names,
hsize_t start,
@@ -1018,154 +480,169 @@ herr_t H5TBread_fields_name( hid_t loc_id,
size_t type_size,
const size_t *field_offset,
const size_t *field_sizes,
- void *data )
+ 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 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 = H5Dopen2(loc_id, dset_name, H5P_DEFAULT)) < 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 );
- 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 = H5Dopen2(loc_id, dset_name, H5P_DEFAULT)) < 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((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 */
+ }
+
+ /* 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 {
- H5Dclose(did);
- H5Tclose(mem_type_id);
- H5Tclose(ftype_id);
- H5Sclose(mem_space_id);
- H5Sclose(sid);
- } 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;
}
+
/*-------------------------------------------------------------------------
- * Function: H5TBread_fields_index
- *
- * Purpose: Reads fields
- *
- * Return: Success: 0, Failure: -1
- *
- * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
- *
- * Date: November 19, 2001
- *
- * Comments:
- *
- * Modifications: April 1, 2004
- * the DST_SIZES parameter is used to define the memory type ID
- * returned by H5TB_create_type
- *
- *-------------------------------------------------------------------------
- */
+* Function: H5TBwrite_fields_index
+*
+* Purpose: Writes fields
+*
+* Return: Success: 0, Failure: -1
+*
+* Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
+*
+* Date: November 21, 2001
+*
+* Comments: Uses memory offsets
+*
+* Modifications: April 1, 2004
+* the FIELD_SIZES parameter is used to define a memory type ID
+*
+*-------------------------------------------------------------------------
+*/
-herr_t H5TBread_fields_index( hid_t loc_id,
+herr_t H5TBwrite_fields_index( hid_t loc_id,
const char *dset_name,
hsize_t nfields,
const int *field_index,
@@ -1174,2376 +651,2801 @@ herr_t H5TBread_fields_index( hid_t loc_id,
size_t type_size,
const size_t *field_offset,
const size_t *field_sizes,
- void *data )
-{
-
- hid_t did;
- hid_t tid=-1;
- hid_t read_type_id=-1;
- hid_t member_type_id;
- hid_t nmtype_id;
- 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 = H5Dopen2(loc_id, dset_name, H5P_DEFAULT)) < 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((mem_space_id = H5Screate_simple( 1, mem_size, NULL )) < 0)
- goto out;
-
- /* Read */
- if(H5Dread( did, read_type_id, mem_space_id, sid, H5P_DEFAULT, data ) < 0)
- goto out;
-
- /* Terminate access to the dataspace */
- if(H5Sclose( sid ) < 0)
- goto out;
-
- /* Terminate access to the memory dataspace */
- if(H5Sclose( mem_space_id ) < 0)
- goto out;
-
- /* End access to the read id */
- if(H5Tclose( read_type_id ) )
- goto out;
-
- /* Release the datatype. */
- if(H5Tclose( tid ) < 0)
- return -1;
-
- /* End access to the dataset */
- if(H5Dclose( did ) < 0)
- return -1;
-
-return 0;
-
-/* error zone, gracefully close */
-out:
- H5E_BEGIN_TRY {
- H5Dclose(did);
- H5Tclose(read_type_id);
- H5Tclose(tid);
- H5Sclose(mem_space_id);
- H5Sclose(sid);
- } H5E_END_TRY;
- return -1;
-
-}
-
-
-/*-------------------------------------------------------------------------
- *
- * Manipulation functions
- *
- *-------------------------------------------------------------------------
- */
-
-/*-------------------------------------------------------------------------
- * Function: H5TBdelete_record
- *
- * Purpose: Delete records from middle of table ("pulling up" all the records after it)
- *
- * Return: Success: 0, Failure: -1
- *
- * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
- *
- * Date: November 26, 2001
- *
- * Modifications: April 29, 2003
- *
- *
- *-------------------------------------------------------------------------
- */
-
-herr_t H5TBdelete_record( hid_t loc_id,
- const char *dset_name,
- hsize_t start,
- hsize_t nrecords )
+ 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 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 = H5Dopen2(loc_id, dset_name, H5P_DEFAULT)) < 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++)
+ {
- 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 = H5Dopen2(loc_id, dset_name, H5P_DEFAULT)) < 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",(size_t)1,
- H5T_NATIVE_LLONG,&nrows) < 0)
- return -1;
-
+ 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 );
- return 0;
+ }
+ /* 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:
- H5Dclose( did );
- 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;
}
-/*-------------------------------------------------------------------------
- * Function: H5TBinsert_record
- *
- * Purpose: Inserts records into middle of table ("pushing down" all the records after it)
- *
- * Return: Success: 0, Failure: -1
- *
- * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
- *
- * Date: November 26, 2001
- *
- * Comments: Uses memory offsets
- *
- * Modifications: April 1, 2004
- * the DST_SIZES parameter is used to define the memory type ID
- * returned by H5TB_create_type
- *
- *-------------------------------------------------------------------------
- */
-
-
-herr_t H5TBinsert_record( hid_t loc_id,
- const char *dset_name,
- hsize_t start,
- hsize_t nrecords,
- size_t type_size,
- const size_t *field_offset,
- const size_t *field_sizes,
- void *data )
-{
-
- hsize_t nfields;
- hsize_t ntotal_records;
- hsize_t read_nrecords;
- hid_t did;
- hid_t tid=-1;
- hid_t mem_type_id=-1;
- hsize_t count[1];
- 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 = H5Dopen2(loc_id, dset_name, H5P_DEFAULT)) < 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 functions
+*
+*-------------------------------------------------------------------------
+*/
- /* 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((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;
+* Function: H5TBread_table
+*
+* Purpose: Reads a table
+*
+* Return: Success: 0, Failure: -1
+*
+* Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
+*
+* Date: November 20, 2001
+*
+* Comments:
+*
+* Modifications: April 1, 2004
+* used a memory type ID returned by H5TB_create_type
+*
+*-------------------------------------------------------------------------
+*/
- /* 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 */
+herr_t H5TBread_table( hid_t loc_id,
+ const char *dset_name,
+ 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 = H5Dopen2(loc_id, dset_name, H5P_DEFAULT)) < 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);
- H5Sclose(sid);
- H5Sclose(mem_space_id);
- H5Tclose(mem_type_id);
- H5Tclose(tid);
- } H5E_END_TRY;
- return -1;
+ H5E_BEGIN_TRY
+ {
+ H5Dclose(did);
+ H5Tclose(mem_type_id);
+ H5Tclose(ftype_id);
+ H5Sclose(sid);
+ } H5E_END_TRY;
+ return -1;
}
/*-------------------------------------------------------------------------
- * Function: H5TBadd_records_from
- *
- * Purpose: Add records from first table to second table
- *
- * Return: Success: 0, Failure: -1
- *
- * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
- *
- * Date: December 5, 2001
- *
- * Comments:
- *
- * Modifications:
- *
- *
- *-------------------------------------------------------------------------
- */
-
-herr_t H5TBadd_records_from( hid_t loc_id,
- const char *dset_name1,
- hsize_t start1,
- hsize_t nrecords,
- const char *dset_name2,
- hsize_t start2 )
-{
+* Function: H5TBread_records
+*
+* Purpose: Reads records
+*
+* Return: Success: 0, Failure: -1
+*
+* Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
+*
+* Date: November 19, 2001
+*
+* Comments:
+*
+* Modifications: April 1, 2004
+* the FIELD_SIZES parameter is used to define the memory type ID
+* returned by H5TB_create_type
+*
+*-------------------------------------------------------------------------
+*/
- /* 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 = H5Dopen2(loc_id, dset_name1, H5P_DEFAULT)) < 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;
+herr_t H5TBread_records( hid_t loc_id,
+ const char *dset_name,
+ hsize_t start,
+ hsize_t nrecords,
+ size_t type_size,
+ const size_t *field_offset,
+ const size_t *field_sizes,
+ void *buf )
+{
-/*-------------------------------------------------------------------------
- * 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;
+ 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;
-/*-------------------------------------------------------------------------
- * Close resources for table 1
- *-------------------------------------------------------------------------
- */
+ /* get the number of records and fields */
+ if (H5TBget_table_info ( loc_id, dset_name, &nfields, &nrecords_orig ) < 0)
+ return -1;
- /* Terminate access to the memory dataspace */
- if(H5Sclose( mem_space_id1 ) < 0)
- goto out;
+ /* open the dataset */
+ if ((did = H5Dopen2(loc_id, dset_name, H5P_DEFAULT)) < 0)
+ return -1;
- /* Terminate access to the dataspace */
- if(H5Sclose( space_id1 ) < 0)
- goto out;
+ /* get the datatypes */
+ if ((ftype_id = H5Dget_type( did )) < 0)
+ goto out;
- /* Release the datatype. */
- if(H5Tclose( type_id1 ) < 0)
- return -1;
+ if ((mem_type_id=H5TB_create_type(loc_id,dset_name,type_size,field_offset,field_sizes,ftype_id)) < 0)
+ goto out;
- /* End access to the dataset */
- if(H5Dclose( dataset_id1 ) < 0)
- return -1;
+ /* read the records */
+ if ((H5TB_common_read_records(did, mem_type_id, start, (size_t)nrecords, nrecords_orig, buf)) < 0)
+ goto out;
- free( tmp_buf );
- free( src_offset );
- free( src_sizes );
+ /* close */
+ if (H5Tclose( ftype_id ) < 0)
+ return -1;
+ if (H5Tclose( mem_type_id ) < 0)
+ return -1;
+ if (H5Dclose( did ) < 0)
+ return -1;
-return 0;
+ return 0;
- /* error zone, gracefully close */
+ /* 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);
+ H5Tclose(mem_type_id);
+ H5Tclose(ftype_id);
+ H5Sclose(m_sid);
+ H5Sclose(sid);
+ } H5E_END_TRY;
+ return -1;
}
-/*-------------------------------------------------------------------------
- * Function: H5TBcombine_tables
- *
- * Purpose: Combine records from two tables into a third
- *
- * Return: Success: 0, Failure: -1
- *
- * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
- *
- * Date: December 10, 2001
- *
- * Comments:
- *
- * Modifications:
- *
- *
- *-------------------------------------------------------------------------
- */
-herr_t H5TBcombine_tables( hid_t loc_id1,
- const char *dset_name1,
- hid_t loc_id2,
- const char *dset_name2,
- const char *dset_name3 )
-{
-
- /* Identifiers for the 1st dataset. */
- hid_t dataset_id1;
- hid_t type_id1;
- hid_t space_id1;
- hid_t plist_id1;
-
- /* Identifiers for the 2nd dataset. */
- hid_t dataset_id2;
- hid_t type_id2;
- hid_t space_id2;
- hid_t plist_id2;
-
- /* Identifiers for the 3rd dataset. */
- hid_t dataset_id3;
- hid_t type_id3;
- hid_t space_id3;
- hid_t plist_id3;
-
- hsize_t count[1];
- 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));
-
+* Function: H5TBread_fields_name
+*
+* Purpose: Reads fields
+*
+* Return: Success: 0, Failure: -1
+*
+* Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
+*
+* Date: November 19, 2001
+*
+* Comments:
+*
+* Modifications: April 1, 2004
+* the FIELD_SIZES parameter is used to define the memory type ID
+* returned by H5TB_create_type
+*
+*-------------------------------------------------------------------------
+*/
- 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 = H5Dopen2(loc_id1, dset_name1, H5P_DEFAULT)) < 0)
- goto out;
+herr_t H5TBread_fields_name( hid_t loc_id,
+ const char *dset_name,
+ const char *field_names,
+ hsize_t start,
+ hsize_t nrecords,
+ size_t type_size,
+ const size_t *field_offset,
+ const size_t *field_sizes,
+ void *buf )
+{
- /* Get the datatype */
- if((type_id1 = H5Dget_type( dataset_id1 )) < 0)
- goto out;
+ 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 = H5Dopen2(loc_id, dset_name, H5P_DEFAULT)) < 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((space_id1 = H5Dget_space( dataset_id1 )) < 0)
- goto out;
+ /* 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(m_sid);
+ H5Sclose(sid);
+ } H5E_END_TRY;
+ return -1;
- /* 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
- *-------------------------------------------------------------------------
- */
+* Function: H5TBread_fields_index
+*
+* Purpose: Reads fields
+*
+* Return: Success: 0, Failure: -1
+*
+* Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
+*
+* Date: November 19, 2001
+*
+* Comments:
+*
+* Modifications: April 1, 2004
+* the FIELD_SIZES parameter is used to define the memory type ID
+* returned by H5TB_create_type
+*
+*-------------------------------------------------------------------------
+*/
- /* 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;
+herr_t H5TBread_fields_index( hid_t loc_id,
+ const char *dset_name,
+ hsize_t nfields,
+ const int *field_index,
+ hsize_t start,
+ hsize_t nrecords,
+ size_t type_size,
+ const size_t *field_offset,
+ const size_t *field_sizes,
+ void *buf )
+{
-/*-------------------------------------------------------------------------
- * 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;
+ 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 = H5Dopen2(loc_id, dset_name, H5P_DEFAULT)) < 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 );
+ }
-/* Create a simple data space with unlimited size */
- if((space_id3 = H5Screate_simple(1, dims, maxdims)) < 0)
- return -1;
+ /* 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(m_sid);
+ H5Sclose(sid);
+ } H5E_END_TRY;
+ return -1;
- /* Create the dataset */
- if((dataset_id3 = H5Dcreate2(loc_id1, dset_name3, type_id3, space_id3, H5P_DEFAULT, plist_id3, H5P_DEFAULT)) < 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(type_size);
-
- /* Get the fill value attributes */
- has_fill = H5TBAget_fill(loc_id1, dset_name1, dataset_id1, tmp_fill_buf);
+*
+* Manipulation functions
+*
+*-------------------------------------------------------------------------
+*/
/*-------------------------------------------------------------------------
- * Attach the fill attributes from previous table
- *-------------------------------------------------------------------------
- */
- if(has_fill == 1 )
- {
-
- if (( sid = H5Screate(H5S_SCALAR)) < 0)
- goto out;
+* Function: H5TBdelete_record
+*
+* Purpose: Delete records from middle of table ("pulling up" all the records after it)
+*
+* Return: Success: 0, Failure: -1
+*
+* Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
+*
+* Date: November 26, 2001
+*
+* Modifications: April 29, 2003
+*
+*
+*-------------------------------------------------------------------------
+*/
- for ( i = 0; i < nfields; i++)
- {
-
- /* Get the member type */
- if(( member_type_id = H5Tget_member_type( type_id3, (unsigned) i )) < 0)
- goto out;
+herr_t H5TBdelete_record( hid_t loc_id,
+ const char *dset_name,
+ hsize_t start,
+ hsize_t nrecords )
+{
- /* Get the member offset */
- member_offset = H5Tget_member_offset(type_id3, (unsigned)i);
+ 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;
+
+ /* open the dataset. */
+ if ((did = H5Dopen2(loc_id, dset_name, H5P_DEFAULT)) < 0)
+ return -1;
+
+ /*-------------------------------------------------------------------------
+ * read the records after the deleted one(s)
+ *-------------------------------------------------------------------------
+ */
+
+ read_start = start + nrecords;
+ read_nrecords = ntotal_records - read_start;
+
+ if ( read_nrecords )
+ {
+ tmp_buf = (unsigned char *)calloc((size_t) read_nrecords, src_size );
- strcpy(attr_name, "FIELD_");
- sprintf(aux, "%d", (int)i);
- strcat(attr_name, aux);
- sprintf(aux, "%s", "_FILL");
- strcat(attr_name, aux);
+ if (tmp_buf == NULL )
+ return -1;
- if((attr_id = H5Acreate2(dataset_id3, attr_name, member_type_id, sid, H5P_DEFAULT, H5P_DEFAULT)) < 0)
- goto out;
+ /* 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;
- if(H5Awrite(attr_id, member_type_id, tmp_fill_buf+member_offset) < 0)
- goto out;
+ /*-------------------------------------------------------------------------
+ * write the records in another position
+ *-------------------------------------------------------------------------
+ */
- if(H5Aclose(attr_id) < 0)
- goto out;
+ /* get the datatype */
+ if ((tid = H5Dget_type( did )) < 0)
+ goto out;
- if(H5Tclose(member_type_id) < 0)
- goto out;
- }
+ /* get the dataspace handle */
+ if ((sid = H5Dget_space( did )) < 0)
+ goto out;
- /* Close data space. */
- if(H5Sclose( sid ) < 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;
-/*-------------------------------------------------------------------------
- * Read data from 1st table
- *-------------------------------------------------------------------------
- */
+ /* create a memory dataspace handle */
+ mem_size[0] = count[0];
+ if ((m_sid = H5Screate_simple( 1, mem_size, NULL )) < 0)
+ goto out;
- tmp_buf = (unsigned char *)calloc((size_t) nrecords, type_size );
+ if (H5Dwrite( did, tid, m_sid, sid, H5P_DEFAULT, tmp_buf ) < 0)
+ goto out;
- /* 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;
+ /* close */
+ if (H5Sclose( m_sid ) < 0)
+ goto out;
+ if (H5Sclose( sid ) < 0)
+ goto out;
+ if (H5Tclose( tid ) < 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_nrecords */
- 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
- *-------------------------------------------------------------------------
- */
+ /*-------------------------------------------------------------------------
+ * change the dataset dimension
+ *-------------------------------------------------------------------------
+ */
+ dims[0] = ntotal_records - nrecords;
+ if (H5Dset_extent( did, dims ) < 0)
+ goto out;
- /* 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;
+ /* close dataset */
+ if (H5Dclose( did ) < 0)
+ return -1;
-/*-------------------------------------------------------------------------
- * Release resources from 1st table
- *-------------------------------------------------------------------------
- */
+ if (tmp_buf !=NULL)
+ free( tmp_buf );
+ free( src_offset );
+ free( src_sizes );
- /* 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;
+ return 0;
- /* Release the datatype. */
- if(H5Tclose( type_id1 ) < 0)
- goto out;
+ /* error zone */
+out:
- /* Terminate access to a property list */
- if(H5Pclose( plist_id1 ) < 0)
- goto out;
+ if (tmp_buf !=NULL )
+ free( tmp_buf );
+ H5E_BEGIN_TRY
+ {
+ H5Dclose(did);
+ H5Tclose(tid);
+ H5Sclose(sid);
+ } H5E_END_TRY;
+ return -1;
- /* 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 = H5Dopen2(loc_id2, dset_name2, H5P_DEFAULT)) < 0)
- goto out;
-
- /* Get the datatype */
- if((type_id2 = H5Dget_type( dataset_id2 )) < 0)
- goto out;
+* Function: H5TBinsert_record
+*
+* Purpose: Inserts records into middle of table ("pushing down" all the records after it)
+*
+* Return: Success: 0, Failure: -1
+*
+* Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
+*
+* Date: November 26, 2001
+*
+* Comments: Uses memory offsets
+*
+* Modifications: April 1, 2004
+* the FIELD_SIZES parameter is used to define the memory type ID
+* returned by H5TB_create_type
+*
+*-------------------------------------------------------------------------
+*/
- /* 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;
+herr_t H5TBinsert_record( hid_t loc_id,
+ const char *dset_name,
+ hsize_t start,
+ hsize_t nrecords,
+ size_t type_size,
+ const size_t *field_offset,
+ const size_t *field_sizes,
+ void *buf )
+{
- /* Get the dimensions */
- if(H5TBget_table_info ( loc_id2, dset_name2, &nfields, &nrecords ) < 0)
- return -1;
+ 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 = H5Dopen2(loc_id, dset_name, H5P_DEFAULT)) < 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(m_sid);
+ H5Tclose(mem_type_id);
+ H5Tclose(tid);
+ } H5E_END_TRY;
+ return -1;
+}
/*-------------------------------------------------------------------------
- * Read data from 2nd table
- *-------------------------------------------------------------------------
- */
-
- tmp_buf = (unsigned char *)calloc((size_t) nrecords, type_size );
+* Function: H5TBadd_records_from
+*
+* Purpose: Add records from first table to second table
+*
+* Return: Success: 0, Failure: -1
+*
+* Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
+*
+* Date: December 5, 2001
+*
+* Comments:
+*
+* Modifications:
+*
+*
+*-------------------------------------------------------------------------
+*/
- /* 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
- *-------------------------------------------------------------------------
- */
+herr_t H5TBadd_records_from( hid_t loc_id,
+ const char *dset_name1,
+ hsize_t start1,
+ hsize_t nrecords,
+ const char *dset_name2,
+ hsize_t start2 )
+{
+ 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 = H5Dopen2(loc_id, dset_name1, H5P_DEFAULT)) < 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(did_1);
+ H5Sclose(sid_1);
+ H5Sclose(msid_1);
+ H5Tclose(tid_1);
+ } H5E_END_TRY;
+ return -1;
- /* 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;
+* Function: H5TBcombine_tables
+*
+* Purpose: Combine records from two tables into a third
+*
+* Return: Success: 0, Failure: -1
+*
+* Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
+*
+* Date: December 10, 2001
+*
+* Comments:
+*
+* Modifications:
+*
+*
+*-------------------------------------------------------------------------
+*/
+herr_t H5TBcombine_tables( hid_t loc_id1,
+ const char *dset_name1,
+ hid_t loc_id2,
+ const char *dset_name2,
+ const char *dset_name3 )
+{
- /* Terminate access to the dataspace */
- if(H5Sclose( space_id2 ) < 0)
- goto out;
+ /* 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 = H5Dopen2(loc_id1, dset_name1, H5P_DEFAULT)) < 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 = H5Dcreate2(loc_id1, dset_name3, tid_3, sid_3, H5P_DEFAULT, pid_3, H5P_DEFAULT)) < 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 )
+ {
- /* Release the datatype. */
- if(H5Tclose( type_id2 ) < 0)
- return -1;
+ if (( sid = H5Screate(H5S_SCALAR)) < 0)
+ goto out;
- /* Terminate access to a property list */
- if(H5Pclose( plist_id2 ) < 0)
- goto out;
+ for ( i = 0; i < nfields; i++)
+ {
- /* End access to the dataset */
- if(H5Dclose( dataset_id2 ) < 0)
- return -1;
+ /* get the member type */
+ if (( member_type_id = H5Tget_member_type( tid_3, (unsigned) i )) < 0)
+ goto out;
-/*-------------------------------------------------------------------------
- * Release resources from 3rd table
- *-------------------------------------------------------------------------
- */
+ /* get the member offset */
+ member_offset = H5Tget_member_offset(tid_3, (unsigned)i);
- /* Terminate access to the dataspace */
- if(H5Sclose( space_id3 ) < 0)
- return -1;
+ strcpy(attr_name, "FIELD_");
+ sprintf(aux, "%d", (int)i);
+ strcat(attr_name, aux);
+ sprintf(aux, "%s", "_FILL");
+ strcat(attr_name, aux);
- /* Release the datatype. */
- if(H5Tclose( type_id3 ) < 0)
- return -1;
+ if ((attr_id = H5Acreate2(did_3, attr_name, member_type_id, sid, H5P_DEFAULT, H5P_DEFAULT)) < 0)
+ goto out;
- /* Terminate access to a property list */
- if(H5Pclose( plist_id3 ) < 0)
- return -1;
+ if (H5Awrite(attr_id, member_type_id, tmp_fill_buf+member_offset) < 0)
+ goto out;
- /* End access to the dataset */
- if(H5Dclose( dataset_id3 ) < 0)
- return -1;
+ if (H5Aclose(attr_id) < 0)
+ goto out;
- /* Release resources. */
- free( tmp_buf );
- free( tmp_fill_buf );
- free( src_offset );
- free( src_sizes );
+ if (H5Tclose(member_type_id) < 0)
+ goto out;
+ }
-return 0;
+ /* 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 = H5Dopen2(loc_id2, dset_name2, H5P_DEFAULT)) < 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
- *
- * Purpose: Inserts a field
- *
- * Return: Success: 0, Failure: -1
- *
- * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
- *
- * Date: January 30, 2002
- *
- * Comments:
- *
- * Modifications:
- *
- *-------------------------------------------------------------------------
- */
+* Function: H5TBinsert_field
+*
+* Purpose: Inserts a field
+*
+* Return: Success: 0, Failure: -1
+*
+* Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
+*
+* Date: January 30, 2002
+*
+* Comments:
+*
+* Modifications:
+*
+*-------------------------------------------------------------------------
+*/
herr_t H5TBinsert_field( hid_t loc_id,
- const char *dset_name,
- const char *field_name,
- hid_t field_type,
- hsize_t position,
- const void *fill_data,
- const void *data )
+ const char *dset_name,
+ const char *field_name,
+ hid_t field_type,
+ hsize_t position,
+ const void *fill_data,
+ const void *buf )
{
+ /* 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 = H5Dopen2(loc_id, dset_name, H5P_DEFAULT)) < 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;
- /* 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 = H5Dopen2(loc_id, dset_name, H5P_DEFAULT)) < 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 = H5Dcreate2(loc_id, "new", type_id2, space_id2, H5P_DEFAULT, plist_id2, H5P_DEFAULT)) < 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
- *-------------------------------------------------------------------------
- */
+ if (i == position )
+ {
+ /* get the new member size */
+ new_member_size = H5Tget_size( field_type );
- /* Write */
- if(H5Dwrite( dataset_id2, type_id1, mem_space_id1, H5S_ALL, H5P_DEFAULT, tmp_buf ) < 0)
- goto out;
+ /* insert the new field type */
+ if (H5Tinsert( tid_2, field_name, curr_offset, field_type ) < 0)
+ goto out;
+ curr_offset += new_member_size;
-/*-------------------------------------------------------------------------
- * Save the function supplied data of the new field
- *-------------------------------------------------------------------------
- */
+ inserted = 1;
+ continue;
+ }
- /* Create a write id */
- if(( write_type_id = H5Tcreate( H5T_COMPOUND, (size_t)new_member_size )) < 0)
- goto out;
+ /* get the member name */
+ member_name = H5Tget_member_name( tid_1, (unsigned)idx );
- /* 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;
+ /* get the member type */
+ if (( member_type_id = H5Tget_member_type( tid_1,(unsigned)idx )) < 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;
+ /* get the member size */
+ member_size = H5Tget_size( member_type_id );
- /* Only write if there is something to write */
- if(data )
- {
+ /* insert it into the new type */
+ if (H5Tinsert( tid_2, member_name, curr_offset, member_type_id ) < 0)
+ goto out;
- /* Create a memory dataspace handle */
- if((mem_space_id2 = H5Screate_simple( 1, mem_size, NULL )) < 0)
- goto out;
+ curr_offset += member_size;
- /* Write */
- if(H5Dwrite( dataset_id2, write_type_id, mem_space_id2, space_id2, PRESERVE, data ) < 0)
- goto out;
+ free( member_name );
- /* Terminate access to the memory dataspace */
- if(H5Sclose( mem_space_id2 ) < 0)
- goto out;
- }
+ /* close the member type */
+ if(H5Tclose( member_type_id ) < 0)
+ goto out;
- /* End access to the property list */
- if(H5Pclose( PRESERVE ) < 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;
-/*-------------------------------------------------------------------------
- * Release resources from 1st table
- *-------------------------------------------------------------------------
- */
+ /* create a new simple data space with unlimited size, using the dimension */
+ if ((sid_2 = H5Screate_simple( 1, dims, maxdims)) < 0)
+ return -1;
- /* Terminate access to the memory dataspace */
- if(H5Sclose( mem_space_id1 ) < 0)
- goto out;
+ /* 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;
- /* Release the datatype. */
- if(H5Tclose( type_id1 ) < 0)
- goto out;
+ /* create the dataset. */
+ if ((did_2 = H5Dcreate2(loc_id, "new", tid_2, sid_2, H5P_DEFAULT, pid_2, H5P_DEFAULT)) < 0)
+ goto out;
- /* Terminate access to a property list */
- if(H5Pclose( plist_id1 ) < 0)
- goto out;
+ /*-------------------------------------------------------------------------
+ * read data from 1st table
+ *-------------------------------------------------------------------------
+ */
- /* Terminate access to the data space */
- if(H5Sclose( space_id1 ) < 0)
- goto out;
+ tmp_buf = (unsigned char *)calloc((size_t)nrecords, (size_t)total_size);
- /* End access to the dataset */
- if(H5Dclose( dataset_id1 ) < 0)
- goto out;
+ /* 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;
-/*-------------------------------------------------------------------------
- * Release resources from 2nd table
- *-------------------------------------------------------------------------
- */
+ if (H5Dread(did_1, tid_1, msid_1, H5S_ALL, H5P_DEFAULT, tmp_buf) < 0)
+ goto out;
- /* Terminate access to the dataspace */
- if(H5Sclose( space_id2 ) < 0)
- goto out;
+ /*-------------------------------------------------------------------------
+ * save data from 1st table into new table, using the 1st type id
+ *-------------------------------------------------------------------------
+ */
- /* Release the datatype. */
- if(H5Tclose( type_id2 ) < 0)
- return -1;
+ /* write */
+ if (H5Dwrite( did_2, tid_1, msid_1, H5S_ALL, H5P_DEFAULT, tmp_buf ) < 0)
+ goto out;
- /* Terminate access to a property list */
- if(H5Pclose( plist_id2 ) < 0)
- goto out;
+ /*-------------------------------------------------------------------------
+ * save the function supplied data of the new field
+ *-------------------------------------------------------------------------
+ */
- /* End access to the dataset */
- if(H5Dclose( dataset_id2 ) < 0)
- return -1;
-/*-------------------------------------------------------------------------
- * Delete 1st table
- *-------------------------------------------------------------------------
- */
- if(H5Ldelete( loc_id, dset_name, H5P_DEFAULT ) < 0)
- return -1;
-
-/*-------------------------------------------------------------------------
- * Rename 2nd table
- *-------------------------------------------------------------------------
- */
+ /* create a write id */
+ if (( write_type_id = H5Tcreate( H5T_COMPOUND, (size_t)new_member_size )) < 0)
+ goto out;
- if(H5Lmove( loc_id, "new", H5L_SAME_LOC, dset_name, H5P_DEFAULT, H5P_DEFAULT ) < 0)
- return -1;
+ /* 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;
-/*-------------------------------------------------------------------------
- * Attach the conforming table attributes
- *-------------------------------------------------------------------------
- */
+ /* 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;
- /* 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 = H5Dopen2(loc_id, dset_name, H5P_DEFAULT)) < 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;
+ /* 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;
- /* Get the member offset */
- member_offset = H5Tget_member_offset(type_id1, (unsigned)i);
+ /* write */
+ if (H5Dwrite( did_2, write_type_id, msid_2, sid_2, preserve_id, buf ) < 0)
+ goto out;
- strcpy(attr_name, "FIELD_");
- sprintf(aux, "%d", (int)i);
- strcat(attr_name, aux);
- sprintf(aux, "%s", "_FILL");
- strcat(attr_name, aux);
+ /* terminate access to the memory dataspace */
+ if (H5Sclose( msid_2 ) < 0)
+ goto out;
+ }
- if((attr_id = H5Acreate2(dataset_id1, attr_name, member_type_id, space_id1, H5P_DEFAULT, H5P_DEFAULT)) < 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
+ *-------------------------------------------------------------------------
+ */
+ if (H5Ldelete( loc_id, dset_name, H5P_DEFAULT ) < 0)
+ return -1;
+
+ /*-------------------------------------------------------------------------
+ * rename 2nd table
+ *-------------------------------------------------------------------------
+ */
+
+ if (H5Lmove( loc_id, "new", H5L_SAME_LOC, dset_name, H5P_DEFAULT, H5P_DEFAULT ) < 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 ((did_1 = H5Dopen2(loc_id, dset_name, H5P_DEFAULT)) < 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;
- if(H5Awrite(attr_id, member_type_id, tmp_fill_buf+member_offset) < 0)
- goto out;
+ /* get the member offset */
+ member_offset = H5Tget_member_offset(tid_1, (unsigned)i);
- if(H5Aclose(attr_id) < 0)
- goto out;
+ strcpy(attr_name, "FIELD_");
+ sprintf(aux, "%d", (int)i);
+ strcat(attr_name, aux);
+ sprintf(aux, "%s", "_FILL");
+ strcat(attr_name, aux);
- /* Close the member type */
- if(H5Tclose(member_type_id) < 0)
- goto out;
- }
+ if ((attr_id = H5Acreate2(did_1, attr_name, member_type_id, sid_1, H5P_DEFAULT, H5P_DEFAULT)) < 0)
+ goto out;
-/*-------------------------------------------------------------------------
- * Attach the fill attribute from the new field, if present
- *-------------------------------------------------------------------------
- */
- if(fill_data)
- {
+ if (H5Awrite(attr_id, member_type_id, tmp_fill_buf+member_offset) < 0)
+ goto out;
- strcpy(attr_name, "FIELD_");
- sprintf(aux, "%d",(int)(nfields - 1));
- strcat(attr_name, aux);
- sprintf(aux, "%s", "_FILL");
- strcat(attr_name, aux);
+ if (H5Aclose(attr_id) < 0)
+ goto out;
- /* Get the member type */
- if((member_type_id = H5Tget_member_type(type_id1, (unsigned)nfields - 1)) < 0)
- goto out;
+ /* close the member type */
+ if (H5Tclose(member_type_id) < 0)
+ goto out;
+ }
- if((attr_id = H5Acreate2(dataset_id1, attr_name, member_type_id, space_id1, H5P_DEFAULT, H5P_DEFAULT)) < 0)
- goto out;
+ /*-------------------------------------------------------------------------
+ * attach the fill attribute from the new field, if present
+ *-------------------------------------------------------------------------
+ */
+ if (fill_data)
+ {
- if(H5Awrite(attr_id, member_type_id, fill_data) < 0)
- goto out;
+ strcpy(attr_name, "FIELD_");
+ sprintf(aux, "%d",(int)(nfields - 1));
+ strcat(attr_name, aux);
+ sprintf(aux, "%s", "_FILL");
+ strcat(attr_name, aux);
- if(H5Aclose(attr_id) < 0)
- goto out;
+ /* get the member type */
+ if ((member_type_id = H5Tget_member_type(tid_1, (unsigned)nfields - 1)) < 0)
+ goto out;
- if(H5Tclose(member_type_id) < 0)
- goto out;
+ if ((attr_id = H5Acreate2(did_1, attr_name, member_type_id, sid_1, H5P_DEFAULT, H5P_DEFAULT)) < 0)
+ goto out;
- }
+ if (H5Awrite(attr_id, member_type_id, fill_data) < 0)
+ goto out;
- /* Close data space. */
- if(H5Sclose( space_id1 ) < 0)
- goto out;
+ if (H5Aclose(attr_id) < 0)
+ goto out;
- /* Release the datatype. */
- if(H5Tclose( type_id1 ) < 0)
- goto out;
+ if (H5Tclose(member_type_id) < 0)
+ goto out;
- /* End access to the dataset */
- if(H5Dclose( dataset_id1 ) < 0)
- goto out;
+ }
- /* Release resources. */
- free ( tmp_buf );
- free ( tmp_fill_buf );
+ /* 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;
+ 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
- *
- * Purpose: Deletes a field
- *
- * Return: Success: 0, Failure: -1
- *
- * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
- *
- * Date: January 30, 2002
- *
- * Comments:
- *
- * Modifications:
- *
- *
- *-------------------------------------------------------------------------
- */
+* Function: H5TBdelete_field
+*
+* Purpose: Deletes a field
+*
+* Return: Success: 0, Failure: -1
+*
+* Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
+*
+* Date: January 30, 2002
+*
+* Comments:
+*
+* Modifications:
+*
+*
+*-------------------------------------------------------------------------
+*/
herr_t H5TBdelete_field( hid_t loc_id,
- const char *dset_name,
- const char *field_name )
+ const char *dset_name,
+ const char *field_name )
{
+ /* 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 = H5Dopen2(loc_id, dset_name, H5P_DEFAULT)) < 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;
+ }
- /* 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 = H5Dopen2(loc_id, dset_name, H5P_DEFAULT)) < 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;
+ /* get the member type */
+ if (( member_type_id = H5Tget_member_type( tid_1, (unsigned)i )) < 0)
+ goto out;
- /* Create the data type. */
- if (( type_id2 = H5Tcreate (H5T_COMPOUND, type_size2 )) < 0)
- goto out;
+ /* get the member size */
+ member_size = H5Tget_size( member_type_id );
- curr_offset = 0;
+ /* insert it into the new type */
+ if (H5Tinsert( tid_2, member_name, curr_offset, member_type_id ) < 0)
+ goto out;
- /* alloc fill value attribute buffer */
- tmp_fill_buf = (unsigned char *)malloc((size_t) type_size2 );
+ /*-------------------------------------------------------------------------
+ * 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 );
-/*-------------------------------------------------------------------------
- * 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
- *-------------------------------------------------------------------------
- */
+ /* 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;
+ }
- strcpy( attr_name, "FIELD_" );
- sprintf( aux, "%d", (int)i );
- strcat( attr_name, aux );
- sprintf( aux, "%s", "_FILL" );
- strcat( attr_name, aux );
+ curr_offset += member_size;
- /* Check if we have the _FILL attribute */
- has_fill = H5LT_find_attribute( dataset_id1, attr_name );
+ free(member_name);
- /* Get it */
- if(has_fill == 1 )
- {
- if(H5LT_get_attribute_disk( dataset_id1, attr_name, tmp_fill_buf+curr_offset ) < 0)
- goto out;
- }
+ /* close the member type */
+ if (H5Tclose(member_type_id) < 0)
+ goto out;
+ } /* i */
- curr_offset += member_size;
+ /*-------------------------------------------------------------------------
+ * create a new temporary dataset
+ *-------------------------------------------------------------------------
+ */
- 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 = H5Dcreate2(loc_id, "new", type_id2, space_id2, H5P_DEFAULT, plist_id2, H5P_DEFAULT)) < 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);
+ /* retrieve the size of chunk */
+ if (H5Pget_chunk(pid_1, 1, dims_chunk) < 0)
+ goto out;
- /* Skip the field to delete */
- if(H5TB_find_field(member_name, field_name) > 0) {
- free(member_name);
- continue;
- }
+ /* create a new simple data space with unlimited size, using the dimension */
+ if ((sid_2 = H5Screate_simple(1, dims, maxdims)) < 0)
+ return -1;
- /* 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, (size_t)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, (size_t)0, member_type_id ) < 0)
- goto out;
-
- /* Create xfer properties to preserve initialized data */
- if ((PRESERVE = H5Pcreate (H5P_DATASET_XFER)) < 0)
- goto out;
- if (H5Pset_preserve (PRESERVE, 1) < 0)
- goto out;
-
- /* Write */
- if(H5Dwrite( dataset_id2, write_type_id, H5S_ALL, H5S_ALL, PRESERVE, tmp_buf ) < 0)
- goto out;
-
- /* End access to the property list */
- if(H5Pclose( PRESERVE ) < 0)
- goto out;
-
- /* Close the member type */
- if(H5Tclose( member_type_id ) < 0)
- goto out;
-
- /* Close the read type */
- if(H5Tclose( read_type_id ) < 0)
- goto out;
-
- /* Close the write type */
- if(H5Tclose( write_type_id ) < 0)
- goto out;
-
- /* Release resources. */
- free( member_name );
- free ( tmp_buf );
-
- } /* i */
-
-/*-------------------------------------------------------------------------
- * Release resources from 1st table
- *-------------------------------------------------------------------------
- */
-
- /* Release the datatype. */
- if(H5Tclose( type_id1 ) < 0)
- goto out;
-
- /* Terminate access to a property list */
- if(H5Pclose( plist_id1 ) < 0)
- goto out;
-
- /* Terminate access to the data space */
- if(H5Sclose( space_id1 ) < 0)
- goto out;
-
- /* End access to the dataset */
- if(H5Dclose( dataset_id1 ) < 0)
- goto out;
-
-
-/*-------------------------------------------------------------------------
- * Release resources from 2nd table
- *-------------------------------------------------------------------------
- */
-
- /* Terminate access to the dataspace */
- if(H5Sclose( space_id2 ) < 0)
- goto out;
-
- /* Release the datatype. */
- if(H5Tclose( type_id2 ) < 0)
- return -1;
-
- /* Terminate access to a property list */
- if(H5Pclose( plist_id2 ) < 0)
- goto out;
-
- /* End access to the dataset */
- if(H5Dclose( dataset_id2 ) < 0)
- return -1;
-
-/*-------------------------------------------------------------------------
- * Delete 1st table
- *-------------------------------------------------------------------------
- */
-
- if(H5Ldelete( loc_id, dset_name, H5P_DEFAULT ) < 0)
- return -1;
-
-/*-------------------------------------------------------------------------
- * Rename 2nd table
- *-------------------------------------------------------------------------
- */
-
- if(H5Lmove( loc_id, "new", H5L_SAME_LOC, dset_name, H5P_DEFAULT, H5P_DEFAULT ) < 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 = H5Dopen2(loc_id, dset_name, H5P_DEFAULT)) < 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;
+ /* 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 = H5Dcreate2(loc_id, "new", tid_2, sid_2, H5P_DEFAULT, pid_2, H5P_DEFAULT)) < 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
+ *-------------------------------------------------------------------------
+ */
+
+ if (H5Ldelete( loc_id, dset_name, H5P_DEFAULT ) < 0)
+ return -1;
+
+ /*-------------------------------------------------------------------------
+ * rename 2nd table
+ *-------------------------------------------------------------------------
+ */
+
+ if (H5Lmove( loc_id, "new", H5L_SAME_LOC, dset_name, H5P_DEFAULT, H5P_DEFAULT ) < 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 ((did_1 = H5Dopen2(loc_id, dset_name, H5P_DEFAULT)) < 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++)
- {
+ 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 type */
+ if (( member_type_id = H5Tget_member_type( tid_1, (unsigned)i )) < 0)
+ goto out;
- /* Get the member offset */
- member_offset = H5Tget_member_offset(type_id1, (unsigned)i);
+ /* 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);
+ strcpy(attr_name, "FIELD_");
+ sprintf(aux, "%d", (int)i);
+ strcat(attr_name, aux);
+ sprintf(aux, "%s", "_FILL");
+ strcat(attr_name, aux);
- if((attr_id = H5Acreate2(dataset_id1, attr_name, member_type_id, space_id1, H5P_DEFAULT, H5P_DEFAULT)) < 0)
- goto out;
+ if ((attr_id = H5Acreate2(did_1, attr_name, member_type_id, sid_1, H5P_DEFAULT, H5P_DEFAULT)) < 0)
+ goto out;
- if(H5Awrite(attr_id, member_type_id, tmp_fill_buf+member_offset) < 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 (H5Aclose(attr_id) < 0)
+ goto out;
- /* Close the member type */
- if(H5Tclose(member_type_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;
+ /* close data space. */
+ if (H5Sclose(sid_1) < 0)
+ goto out;
- } /*has_fill*/
+ } /*has_fill*/
- /* Release the datatype. */
- if(H5Tclose( type_id1 ) < 0)
- goto out;
+ /* release the datatype. */
+ if (H5Tclose( tid_1 ) < 0)
+ goto out;
- /* End access to the dataset */
- if(H5Dclose( dataset_id1 ) < 0)
- goto out;
+ /* end access to the dataset */
+ if (H5Dclose( did_1 ) < 0)
+ goto out;
- /* Release resources. */
- free ( tmp_fill_buf );
+ /* Release resources. */
+ free ( tmp_fill_buf );
-return 0;
+ return 0;
+ /* error zone */
out:
- H5Dclose( dataset_id1 );
- return -1;
-}
-
-/*-------------------------------------------------------------------------
- *
- * Table attribute functions
- *
- *-------------------------------------------------------------------------
- */
+ 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: H5TBAget_title
- *
- * Purpose: Read the table title
- *
- * Return: Success: 0, Failure: -1
- *
- * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
- *
- * Date: January 30, 2001
- *
- * Comments:
- *
- * Modifications:
- *
- *-------------------------------------------------------------------------
- */
+*
+* Table attribute functions
+*
+*-------------------------------------------------------------------------
+*/
+
+/*-------------------------------------------------------------------------
+* Function: H5TBAget_title
+*
+* Purpose: Read the table title
+*
+* Return: Success: 0, Failure: -1
+*
+* Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
+*
+* Date: January 30, 2001
+*
+* Comments:
+*
+* Modifications:
+*
+*-------------------------------------------------------------------------
+*/
herr_t H5TBAget_title( hid_t loc_id,
- char *table_title )
+ char *table_title )
{
- /* Get the TITLE attribute */
- if(H5LT_get_attribute_disk( loc_id, "TITLE", table_title ) < 0)
- return -1;
+ /* Get the TITLE attribute */
+ if(H5LT_get_attribute_disk( loc_id, "TITLE", table_title ) < 0)
+ return -1;
- return 0;
+ return 0;
}
/*-------------------------------------------------------------------------
- * Function: H5TBAget_fill
- *
- * Purpose: Read the table attribute fill values
- *
- * Return: Success: 0, Failure: -1
- *
- * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
- *
- * Date: January 30, 2002
- *
- * Comments:
- *
- * Modifications:
- *
- *-------------------------------------------------------------------------
- */
+* Function: H5TBAget_fill
+*
+* Purpose: Read the table attribute fill values
+*
+* Return: Success: 0, Failure: -1
+*
+* Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
+*
+* Date: January 30, 2002
+*
+* Comments:
+*
+* Modifications:
+*
+*-------------------------------------------------------------------------
+*/
herr_t H5TBAget_fill( hid_t loc_id,
- const char *dset_name,
- hid_t dset_id,
- unsigned char *dst_buf )
+ const char *dset_name,
+ hid_t dset_id,
+ unsigned char *dst_buf )
{
- hsize_t nfields;
- hsize_t nrecords;
- char attr_name[255];
- char aux[255];
- hsize_t i;
- size_t *src_offset;
- int has_fill=0;
-
- /* Get the number of records and fields */
- if(H5TBget_table_info ( loc_id, dset_name, &nfields, &nrecords ) < 0)
- return -1;
-
- src_offset = (size_t *)malloc((size_t)nfields * sizeof(size_t));
+ hsize_t nfields;
+ hsize_t nrecords;
+ char attr_name[255];
+ char aux[255];
+ hsize_t i;
+ size_t *src_offset;
+ int has_fill=0;
- if (src_offset == NULL )
- return -1;
+ /* get the number of records and fields */
+ if (H5TBget_table_info ( loc_id, dset_name, &nfields, &nrecords ) < 0)
+ return -1;
- /* Get field info */
- if(H5TBget_field_info( loc_id, dset_name, NULL, NULL, src_offset, NULL ) < 0)
- goto out;
+ src_offset = (size_t *)malloc((size_t)nfields * sizeof(size_t));
- 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 );
+ if (src_offset == NULL )
+ return -1;
- /* Check if we have the _FILL attribute */
- has_fill = H5LT_find_attribute( dset_id, attr_name );
+ /* get field info */
+ if (H5TBget_field_info( loc_id, dset_name, NULL, NULL, src_offset, NULL ) < 0)
+ goto out;
- /* Get it */
- if(has_fill == 1 )
- {
- if(H5LT_get_attribute_disk( dset_id, attr_name, dst_buf+src_offset[i] ) < 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 );
+ free( src_offset );
- return has_fill;
+ return has_fill;
out:
- free( src_offset );
- return -1;
+ free( src_offset );
+ return -1;
}
/*-------------------------------------------------------------------------
- *
- * Inquiry functions
- *
- *-------------------------------------------------------------------------
- */
-
-/*-------------------------------------------------------------------------
- * Function: H5TBget_table_info
- *
- * Purpose: Gets the number of records and fields of a table
- *
- * Return: Success: 0, Failure: -1
- *
- * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
- *
- * Date: November 19, 2001
- *
- * Comments:
- *
- * Modifications: May 08, 2003
- * In version 2.0 of Table, the number of records is stored as an
- * attribute "NROWS"
- *
- *
- *-------------------------------------------------------------------------
- */
+*
+* Inquiry functions
+*
+*-------------------------------------------------------------------------
+*/
+
+/*-------------------------------------------------------------------------
+* Function: H5TBget_table_info
+*
+* Purpose: Gets the number of records and fields of a table
+*
+* Return: Success: 0, Failure: -1
+*
+* Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
+*
+* Date: November 19, 2001
+*
+* Comments:
+*
+* Modifications:
+* May 08, 2003
+* In version 2.0 of Table, the number of records is stored as an
+* attribute "NROWS"
+* November 24, 2008
+* In version 3.0 of Table, "NROWS" was deprecated
+*
+*
+*-------------------------------------------------------------------------
+*/
herr_t H5TBget_table_info ( hid_t loc_id,
- const char *dset_name,
- hsize_t *nfields,
- hsize_t *nrecords )
+ const char *dset_name,
+ hsize_t *nfields,
+ hsize_t *nrecords )
{
- hid_t tid;
- hid_t sid=-1;
- hid_t did;
- int num_members;
- hsize_t dims[1];
- int has_attr;
- hsize_t n[1];
-
- /* Open the dataset. */
- if((did = H5Dopen2(loc_id, dset_name, H5P_DEFAULT)) < 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;
+ hid_t tid=-1;
+ hid_t sid=-1;
+ hid_t did=-1;
+ int num_members;
+ hsize_t dims[1];
+
+ /* open the dataset. */
+ if ((did = H5Dopen2(loc_id, dset_name, H5P_DEFAULT)) < 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)
- {
- /* 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;
+ /*-------------------------------------------------------------------------
+ * get number of records
+ *-------------------------------------------------------------------------
+ */
- /**nrecords = *n;*/
- *nrecords = n[0];
- }
- else
- {
- /* Get the dataspace handle */
- if((sid = H5Dget_space( did )) < 0)
- goto out;
+ if (nrecords)
+ {
+ /* 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;
+ /* get dimension */
+ if (H5Sget_simple_extent_dims( sid, dims, NULL) < 0)
+ goto out;
- /* Terminate access to the dataspace */
- if(H5Sclose( sid ) < 0)
- goto out;
+ /* terminate access to the dataspace */
+ if (H5Sclose( sid ) < 0)
+ goto out;
- *nrecords = dims[0];
- }
- }/*nrecords*/
+ *nrecords = dims[0];
+ }
- /* close */
- if(H5Tclose( tid ) < 0)
- goto out;
- if(H5Dclose( did ) < 0)
- return -1;
+ /* close */
+ if (H5Tclose( tid ) < 0)
+ goto out;
+ if (H5Dclose( did ) < 0)
+ return -1;
-return 0;
+ return 0;
-/* error zone, gracefully close */
+ /* 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;
}
/*-------------------------------------------------------------------------
- * Function: H5TBget_field_info
- *
- * Purpose: Get information about fields
- *
- * Return: Success: 0, Failure: -1
- *
- * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
- *
- * Date: November 19, 2001
- *
- * Comments:
- *
- * Modifications:
- *
- *
- *-------------------------------------------------------------------------
- */
+* Function: H5TBget_field_info
+*
+* Purpose: Get information about fields
+*
+* Return: Success: 0, Failure: -1
+*
+* Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
+*
+* Date: November 19, 2001
+*
+* Comments:
+*
+* Modifications:
+*
+*
+*-------------------------------------------------------------------------
+*/
herr_t H5TBget_field_info( hid_t loc_id,
- const char *dset_name,
- char *field_names[],
- size_t *field_sizes,
- size_t *field_offsets,
- size_t *type_size )
+ const char *dset_name,
+ char *field_names[],
+ size_t *field_sizes,
+ size_t *field_offsets,
+ size_t *type_size )
{
- hid_t did;
- hid_t ftype_id;
- hid_t native_type_id;
- hssize_t nfields;
- char *member_name;
- hid_t member_type_id;
- hid_t nativem_type_id;
- size_t member_size;
- size_t member_offset;
- size_t size;
- hssize_t i;
-
- /* Open the dataset. */
- if((did = H5Dopen2(loc_id, dset_name, H5P_DEFAULT)) < 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;
+ 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 = H5Dopen2(loc_id, dset_name, H5P_DEFAULT)) < 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;
+ }
- /* Iterate tru the members */
- for ( i = 0; i < nfields; i++)
- {
- /* Get the member name */
- member_name = H5Tget_member_name( ftype_id, (unsigned)i );
+ /* get the number of members */
+ if (( nfields = H5Tget_nmembers( tid )) < 0)
+ goto out;
- if(field_names )
- strcpy( field_names[i], member_name );
+ /* iterate tru the members */
+ for ( i = 0; i < nfields; i++)
+ {
+ /* get the member name */
+ member_name = H5Tget_member_name( tid, (unsigned)i );
- /* 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;
+ if (field_names )
+ {
+ strcpy( field_names[i], member_name );
+ }
- /* Get the member size */
- member_size = H5Tget_size( nativem_type_id );
+ /* 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;
- if(field_sizes )
- field_sizes[i] = member_size;
+ /* get the member size */
+ member_size = H5Tget_size( nm_tid );
- /* Get the member offset */
- member_offset = H5Tget_member_offset( native_type_id,(unsigned) i );
+ if(field_sizes )
+ {
+ field_sizes[i] = member_size;
+ }
- if(field_offsets )
- field_offsets[i] = member_offset;
+ /* get the member offset */
+ member_offset = H5Tget_member_offset( n_tid,(unsigned) i );
- /* Close the member type */
- if(H5Tclose( member_type_id ) < 0)
- goto out;
- if(H5Tclose( nativem_type_id ) < 0)
- goto out;
+ if(field_offsets )
+ {
+ field_offsets[i] = member_offset;
+ }
- free( member_name );
+ /* close the member types */
+ if (H5Tclose( m_tid ) < 0)
+ goto out;
+ if (H5Tclose( nm_tid ) < 0)
+ goto out;
- } /* i */
+ free( member_name );
- /* Release the datatype. */
- if(H5Tclose( ftype_id ) < 0)
- return -1;
- if(H5Tclose( native_type_id ) < 0)
- return -1;
+ } /* i */
- /* End access to the dataset */
- if(H5Dclose( did ) < 0)
- return -1;
+ /* close */
+ if (H5Tclose( tid ) < 0)
+ goto out;
+ if (H5Tclose( n_tid ) < 0)
+ goto out;
+ if (H5Dclose( did ) < 0)
+ return -1;
-return 0;
+ return 0;
+ /* error zone */
out:
- H5Dclose( did );
- return -1;
+ H5E_BEGIN_TRY
+ {
+ H5Dclose(did);
+ H5Tclose(tid);
+ H5Tclose(n_tid);
+ } H5E_END_TRY;
+ return -1;
}
/*-------------------------------------------------------------------------
- *
- * internal functions
- *
- *-------------------------------------------------------------------------
- */
+*
+* internal functions
+*
+*-------------------------------------------------------------------------
+*/
/*-------------------------------------------------------------------------
- * Function: H5TB_find_field
- *
- * Purpose: Find a string field
- *
- * Return: Success: 0, Failure: -1
- *
- * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
- *
- * Date: November 19, 2001
- *
- *-------------------------------------------------------------------------
- */
+* Function: H5TB_find_field
+*
+* Purpose: Find a string field
+*
+* Return: Success: 0, Failure: -1
+*
+* Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
+*
+* Date: November 19, 2001
+*
+*-------------------------------------------------------------------------
+*/
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) )
return 1;
start = end + 1;
}
-
+
if(strcmp( start, field ) == 0 )
return 1;
-
+
return -1;
-
+
}
/*-------------------------------------------------------------------------
- * Function: H5TB_attach_attributes
- *
- * Purpose: Private function that creates the conforming table attributes;
- * Used by H5TBcombine_tables; not used by H5TBmake_table, which does not read
- * the fill value attributes from an existing table
- *
- * Return: Success: 0, Failure: -1
- *
- * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
- *
- * Date: December 6, 2001
- *
- * Comments:
- *
- * Modifications:
- *
- *-------------------------------------------------------------------------
- */
+* Function: H5TB_attach_attributes
+*
+* Purpose: Private function that creates the conforming table attributes;
+* Used by H5TBcombine_tables; not used by H5TBmake_table, which does not read
+* the fill value attributes from an existing table
+*
+* Return: Success: 0, Failure: -1
+*
+* Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
+*
+* Date: December 6, 2001
+*
+* Comments:
+*
+* Modifications:
+*
+*-------------------------------------------------------------------------
+*/
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 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;
+ 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 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", "2.0" ) < 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 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++)
- {
+ /* attach the FIELD_ name attribute */
+ for ( i = 0; i < nfields; i++)
+ {
- /* Get the member name */
- member_name = H5Tget_member_name( tid, (unsigned)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 );
+ 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;
+ /* attach the attribute */
+ if (H5LTset_attribute_string( loc_id, dset_name, attr_name, member_name ) < 0)
+ goto out;
- free( member_name );
+ free( member_name );
- }
+ }
- return 0;
+ return 0;
out:
- return -1;
+ return -1;
}
/*-------------------------------------------------------------------------
- * Function: H5TB_create_type
- *
- * Purpose: Private function that creates a memory type ID
- *
- * Return: Success: the memory type ID, Failure: -1
- *
- * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
- *
- * Date: March 31, 2004
- *
- * Comments:
- *
- * Modifications:
- *
- *-------------------------------------------------------------------------
- */
+* Function: H5TB_create_type
+*
+* Purpose: Private function that creates a memory type ID
+*
+* Return: Success: the memory type ID, Failure: -1
+*
+* Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
+*
+* Date: March 31, 2004
+*
+* Comments:
+*
+* Modifications:
+*
+*-------------------------------------------------------------------------
+*/
static
hid_t H5TB_create_type(hid_t loc_id,
@@ -3553,232 +3455,235 @@ hid_t H5TB_create_type(hid_t loc_id,
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;
-
- 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, gracefully close and free */
+ 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 = (char**) malloc(sizeof(char*)*(size_t)nfields))==NULL)
+ return -1;
+
+ for ( i = 0; i < nfields; i++)
+ {
+ if ((fnames[i] = (char*) 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;
+ 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;
}
/*-------------------------------------------------------------------------
- *
- * 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:
- *
- *-------------------------------------------------------------------------
- */
+*
+* 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 * data)
+ const void * buf)
{
- hsize_t count[1];
- hsize_t offset[1];
- hid_t space_id = H5I_BADID;
- hid_t mem_space_id = 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((mem_space_id = H5Screate_simple(1, mem_dims, NULL)) < 0)
- goto out;
-
- /* Get a copy of the new file data space for writing */
- if((space_id = H5Dget_space(dataset_id)) < 0)
- goto out;
-
- /* Define a hyperslab in the dataset */
- offset[0] = orig_table_size;
- count[0] = nrecords;
- if(H5Sselect_hyperslab( space_id, H5S_SELECT_SET, offset, NULL, count, NULL) < 0)
- goto out;
-
- /* Write the records */
- if(H5Dwrite( dataset_id, mem_type_id, mem_space_id, space_id, H5P_DEFAULT, data ) < 0)
- goto out;
-
- /* Terminate access to the dataspace */
- if(H5Sclose( mem_space_id ) < 0)
- goto out;
-
- if(H5Sclose( space_id ) < 0)
- goto out;
-
- return 0;
+ 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
- H5Sclose(mem_space_id);
- H5Sclose(space_id);
- H5E_END_TRY
- 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:
- *
- *
- *-------------------------------------------------------------------------
- */
+* 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 *data)
+ void *buf)
{
- hsize_t count[1];
- hsize_t offset[1];
- hid_t space_id = H5I_BADID;
- hid_t mem_space_id = 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((space_id = 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( space_id, 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_id, mem_type_id, mem_space_id, space_id, 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( space_id ) < 0)
- goto out;
-
- return 0;
+ 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(space_id);
- H5Sclose(mem_space_id);
- H5E_END_TRY
- return -1;
+ H5E_BEGIN_TRY
+ {
+ H5Sclose(sid);
+ H5Sclose(m_sid);
+ }
+ H5E_END_TRY;
+ return -1;
}
diff --git a/hl/src/H5TBprivate.h b/hl/src/H5TBprivate.h
index d4e5635..e2b668d 100644
--- a/hl/src/H5TBprivate.h
+++ b/hl/src/H5TBprivate.h
@@ -24,6 +24,7 @@
#define TABLE_CLASS "TABLE"
+#define TABLE_VERSION "3.0"
#define HLTB_MAX_FIELD_LEN 255
/*-------------------------------------------------------------------------
diff --git a/hl/src/H5TBpublic.h b/hl/src/H5TBpublic.h
index 143ceeb..4dd17bb 100644
--- a/hl/src/H5TBpublic.h
+++ b/hl/src/H5TBpublic.h
@@ -41,7 +41,7 @@ H5_HLDLL herr_t H5TBmake_table( const char *table_title,
hsize_t chunk_size,
void *fill_data,
int compress,
- const void *data );
+ const void *buf );
/*-------------------------------------------------------------------------
@@ -57,7 +57,7 @@ H5_HLDLL herr_t H5TBappend_records( hid_t loc_id,
size_t type_size,
const size_t *field_offset,
const size_t *dst_sizes,
- const void *data );
+ const void *buf );
H5_HLDLL herr_t H5TBwrite_records( hid_t loc_id,
const char *dset_name,
@@ -66,7 +66,7 @@ H5_HLDLL herr_t H5TBwrite_records( hid_t loc_id,
size_t type_size,
const size_t *field_offset,
const size_t *dst_sizes,
- const void *data );
+ const void *buf );
H5_HLDLL herr_t H5TBwrite_fields_name( hid_t loc_id,
@@ -77,7 +77,7 @@ H5_HLDLL herr_t H5TBwrite_fields_name( hid_t loc_id,
size_t type_size,
const size_t *field_offset,
const size_t *dst_sizes,
- const void *data );
+ const void *buf );
H5_HLDLL herr_t H5TBwrite_fields_index( hid_t loc_id,
const char *dset_name,
@@ -88,7 +88,7 @@ H5_HLDLL herr_t H5TBwrite_fields_index( hid_t loc_id,
size_t type_size,
const size_t *field_offset,
const size_t *dst_sizes,
- const void *data );
+ const void *buf );
/*-------------------------------------------------------------------------
@@ -116,7 +116,7 @@ H5_HLDLL herr_t H5TBread_fields_name( hid_t loc_id,
size_t type_size,
const size_t *field_offset,
const size_t *dst_sizes,
- void *data );
+ void *buf );
H5_HLDLL herr_t H5TBread_fields_index( hid_t loc_id,
const char *dset_name,
@@ -127,7 +127,7 @@ H5_HLDLL herr_t H5TBread_fields_index( hid_t loc_id,
size_t type_size,
const size_t *field_offset,
const size_t *dst_sizes,
- void *data );
+ void *buf );
H5_HLDLL herr_t H5TBread_records( hid_t loc_id,
@@ -137,7 +137,7 @@ H5_HLDLL herr_t H5TBread_records( hid_t loc_id,
size_t type_size,
const size_t *dst_offset,
const size_t *dst_sizes,
- void *data );
+ void *buf );
/*-------------------------------------------------------------------------
*
@@ -181,7 +181,7 @@ H5_HLDLL herr_t H5TBinsert_record( hid_t loc_id,
size_t dst_size,
const size_t *dst_offset,
const size_t *dst_sizes,
- void *data );
+ void *buf );
H5_HLDLL herr_t H5TBadd_records_from( hid_t loc_id,
const char *dset_name1,
@@ -202,7 +202,7 @@ H5_HLDLL 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 );
H5_HLDLL herr_t H5TBdelete_field( hid_t loc_id,
const char *dset_name,
diff --git a/hl/src/Makefile.am b/hl/src/Makefile.am
index 37bff7b..0eecbbb 100644
--- a/hl/src/Makefile.am
+++ b/hl/src/Makefile.am
@@ -19,13 +19,17 @@
#
include $(top_srcdir)/config/commence.am
+include $(top_srcdir)/config/lt_vers.am
# Add include directories to the C preprocessor flags
-AM_CPPFLAGS=-I$(top_srcdir)/src
+AM_CPPFLAGS+=-I$(top_srcdir)/src
# This library is our main target.
lib_LTLIBRARIES=libhdf5_hl.la
+# Add libtool numbers to the HDF5 hl library (from config/lt_vers.am)
+libhdf5_hl_la_LDFLAGS= -version-info $(LT_VERS_INTERFACE):$(LT_VERS_REVISION):$(LT_VERS_AGE) $(AM_LDFLAGS)
+
libhdf5_hl_la_SOURCES=H5DS.c H5IM.c H5LT.c H5LTanalyze.c H5LTparse.c H5PT.c H5TB.c
# Public header files (to be installed)
diff --git a/hl/src/Makefile.in b/hl/src/Makefile.in
index 10d5d03..20cbf7b 100644
--- a/hl/src/Makefile.in
+++ b/hl/src/Makefile.in
@@ -1,8 +1,9 @@
-# Makefile.in generated by automake 1.10.1 from Makefile.am.
+# Makefile.in generated by automake 1.11 from Makefile.am.
# @configure_input@
# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
-# 2003, 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
+# 2003, 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation,
+# Inc.
# This Makefile.in is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.
@@ -34,8 +35,9 @@
VPATH = @srcdir@
pkgdatadir = $(datadir)/@PACKAGE@
-pkglibdir = $(libdir)/@PACKAGE@
pkgincludedir = $(includedir)/@PACKAGE@
+pkglibdir = $(libdir)/@PACKAGE@
+pkglibexecdir = $(libexecdir)/@PACKAGE@
am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd
install_sh_DATA = $(install_sh) -c -m 644
install_sh_PROGRAM = $(install_sh) -c
@@ -52,7 +54,8 @@ build_triplet = @build@
host_triplet = @host@
DIST_COMMON = $(include_HEADERS) $(srcdir)/Makefile.am \
$(srcdir)/Makefile.in $(top_srcdir)/config/commence.am \
- $(top_srcdir)/config/conclude.am COPYING
+ $(top_srcdir)/config/conclude.am \
+ $(top_srcdir)/config/lt_vers.am COPYING
TESTS =
subdir = hl/src
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
@@ -62,22 +65,41 @@ am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
mkinstalldirs = $(SHELL) $(top_srcdir)/bin/mkinstalldirs
CONFIG_HEADER = $(top_builddir)/src/H5config.h
CONFIG_CLEAN_FILES =
+CONFIG_CLEAN_VPATH_FILES =
am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`;
am__vpath_adj = case $$p in \
$(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \
*) f=$$p;; \
esac;
-am__strip_dir = `echo $$p | sed -e 's|^.*/||'`;
+am__strip_dir = f=`echo $$p | sed -e 's|^.*/||'`;
+am__install_max = 40
+am__nobase_strip_setup = \
+ srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*|]/\\\\&/g'`
+am__nobase_strip = \
+ for p in $$list; do echo "$$p"; done | sed -e "s|$$srcdirstrip/||"
+am__nobase_list = $(am__nobase_strip_setup); \
+ for p in $$list; do echo "$$p $$p"; done | \
+ sed "s| $$srcdirstrip/| |;"' / .*\//!s/ .*/ ./; s,\( .*\)/[^/]*$$,\1,' | \
+ $(AWK) 'BEGIN { files["."] = "" } { files[$$2] = files[$$2] " " $$1; \
+ if (++n[$$2] == $(am__install_max)) \
+ { print $$2, files[$$2]; n[$$2] = 0; files[$$2] = "" } } \
+ END { for (dir in files) print dir, files[dir] }'
+am__base_list = \
+ sed '$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;s/\n/ /g' | \
+ sed '$$!N;$$!N;$$!N;$$!N;s/\n/ /g'
am__installdirs = "$(DESTDIR)$(libdir)" "$(DESTDIR)$(includedir)"
-libLTLIBRARIES_INSTALL = $(INSTALL)
LTLIBRARIES = $(lib_LTLIBRARIES)
libhdf5_hl_la_LIBADD =
am_libhdf5_hl_la_OBJECTS = H5DS.lo H5IM.lo H5LT.lo H5LTanalyze.lo \
H5LTparse.lo H5PT.lo H5TB.lo
libhdf5_hl_la_OBJECTS = $(am_libhdf5_hl_la_OBJECTS)
+libhdf5_hl_la_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) \
+ $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
+ $(libhdf5_hl_la_LDFLAGS) $(LDFLAGS) -o $@
DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)/src
depcomp = $(SHELL) $(top_srcdir)/bin/depcomp
am__depfiles_maybe = depfiles
+am__mv = mv -f
COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
$(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
LTCOMPILE = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \
@@ -89,14 +111,27 @@ LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \
$(LDFLAGS) -o $@
SOURCES = $(libhdf5_hl_la_SOURCES)
DIST_SOURCES = $(libhdf5_hl_la_SOURCES)
-includeHEADERS_INSTALL = $(INSTALL_HEADER)
HEADERS = $(include_HEADERS)
ETAGS = etags
CTAGS = ctags
+am__tty_colors = \
+red=; grn=; lgn=; blu=; std=
DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
ACLOCAL = /home1/packages/automake/automake-1.9.6/bin/aclocal-1.9 -I /afs/ncsa/projects/hdf/packages/libtool_1.5.14/Linux_2.4/share/aclocal
ADD_PARALLEL_FILES = @ADD_PARALLEL_FILES@
AMTAR = @AMTAR@
+
+# H5_CFLAGS holds flags that should be used when building hdf5,
+# but which should not be exported to h5cc for building other programs.
+# AM_CFLAGS is an automake construct which should be used by Makefiles
+# instead of CFLAGS, as CFLAGS is reserved solely for the user to define.
+AM_CFLAGS = @AM_CFLAGS@ @H5_CFLAGS@
+
+# Add include directories to the C preprocessor flags
+AM_CPPFLAGS = @AM_CPPFLAGS@ @H5_CPPFLAGS@ -I$(top_srcdir)/src
+AM_CXXFLAGS = @AM_CXXFLAGS@ @H5_CXXFLAGS@
+AM_FCFLAGS = @AM_FCFLAGS@ @H5_FCFLAGS@
+AM_LDFLAGS = @AM_LDFLAGS@
AM_MAKEFLAGS = @AM_MAKEFLAGS@
AR = @AR@
@@ -110,21 +145,18 @@ BYTESEX = @BYTESEX@
CC = @CC@
CCDEPMODE = @CCDEPMODE@
CC_VERSION = @CC_VERSION@
-
-# H5_CFLAGS holds flags that should be used as CFLAGS when building hdf5,
-# but which shouldn't be exported to h5cc for building other programs.
-CFLAGS = @CFLAGS@ @H5_CFLAGS@
+CFLAGS = @CFLAGS@
CLEARFILEBUF = @CLEARFILEBUF@
CODESTACK = @CODESTACK@
CONFIG_DATE = @CONFIG_DATE@
CONFIG_MODE = @CONFIG_MODE@
CONFIG_USER = @CONFIG_USER@
CPP = @CPP@
-CPPFLAGS = @CPPFLAGS@ @H5_CPPFLAGS@
+CPPFLAGS = @CPPFLAGS@
CXX = @CXX@
CXXCPP = @CXXCPP@
CXXDEPMODE = @CXXDEPMODE@
-CXXFLAGS = @CXXFLAGS@ @H5_CXXFLAGS@
+CXXFLAGS = @CXXFLAGS@
CYGPATH_W = @CYGPATH_W@
DEBUG_PKG = @DEBUG_PKG@
DEFAULT_API_VERSION = @DEFAULT_API_VERSION@
@@ -147,7 +179,7 @@ F9XMODEXT = @F9XMODEXT@
F9XMODFLAG = @F9XMODFLAG@
F9XSUFFIXFLAG = @F9XSUFFIXFLAG@
FC = @FC@
-FCFLAGS = @FCFLAGS@ @H5_FCFLAGS@
+FCFLAGS = @FCFLAGS@
FCFLAGS_f90 = @FCFLAGS_f90@
FCLIBS = @FCLIBS@
FGREP = @FGREP@
@@ -185,6 +217,8 @@ LIBOBJS = @LIBOBJS@
LIBS = @LIBS@
LIBTOOL = @LIBTOOL@
LINUX_LFS = @LINUX_LFS@
+LIPO = @LIPO@
+LL_PATH = @LL_PATH@
LN_S = @LN_S@
LTLIBOBJS = @LTLIBOBJS@
LT_STATIC_EXEC = @LT_STATIC_EXEC@
@@ -195,13 +229,17 @@ MPE = @MPE@
MPI_GET_SIZE = @MPI_GET_SIZE@
NM = @NM@
NMEDIT = @NMEDIT@
+OBJDUMP = @OBJDUMP@
OBJECT_NAMELEN_DEFAULT_F = @OBJECT_NAMELEN_DEFAULT_F@
OBJEXT = @OBJEXT@
+OTOOL = @OTOOL@
+OTOOL64 = @OTOOL64@
PACKAGE = @PACKAGE@
PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@
PACKAGE_NAME = @PACKAGE_NAME@
PACKAGE_STRING = @PACKAGE_STRING@
PACKAGE_TARNAME = @PACKAGE_TARNAME@
+PACKAGE_URL = @PACKAGE_URL@
PACKAGE_VERSION = @PACKAGE_VERSION@
PARALLEL = @PARALLEL@
PATH_SEPARATOR = @PATH_SEPARATOR@
@@ -217,12 +255,7 @@ SEARCH = @SEARCH@
SED = @SED@
SETX = @SETX@
SET_MAKE = @SET_MAKE@
-
-# Hardcode SHELL to be /bin/sh. Most machines have this shell, and
-# on at least one machine configure fails to detect its existence (janus).
-# Also, when HDF5 is configured on one machine but run on another,
-# configure's automatic SHELL detection may not work on the build machine.
-SHELL = /bin/sh
+SHELL = @SHELL@
SIZE_T = @SIZE_T@
STATIC_EXEC = @STATIC_EXEC@
STATIC_SHARED = @STATIC_SHARED@
@@ -242,6 +275,7 @@ USE_FILTER_SHUFFLE = @USE_FILTER_SHUFFLE@
USE_FILTER_SZIP = @USE_FILTER_SZIP@
USINGMEMCHECKER = @USINGMEMCHECKER@
VERSION = @VERSION@
+WORDS_BIGENDIAN = @WORDS_BIGENDIAN@
abs_builddir = @abs_builddir@
abs_srcdir = @abs_srcdir@
abs_top_builddir = @abs_top_builddir@
@@ -264,6 +298,8 @@ build_vendor = @build_vendor@
builddir = @builddir@
datadir = @datadir@
datarootdir = @datarootdir@
+
+# Install directories that automake doesn't know about
docdir = $(exec_prefix)/doc
dvidir = @dvidir@
enable_shared = @enable_shared@
@@ -275,9 +311,7 @@ host_cpu = @host_cpu@
host_os = @host_os@
host_vendor = @host_vendor@
htmldir = @htmldir@
-
-# Install directories that automake doesn't know about
-includedir = $(exec_prefix)/include
+includedir = @includedir@
infodir = @infodir@
install_sh = @install_sh@
libdir = @libdir@
@@ -297,6 +331,7 @@ sharedstatedir = @sharedstatedir@
srcdir = @srcdir@
sysconfdir = @sysconfdir@
target_alias = @target_alias@
+top_build_prefix = @top_build_prefix@
top_builddir = @top_builddir@
top_srcdir = @top_srcdir@
@@ -342,11 +377,17 @@ TRACE = perl $(top_srcdir)/bin/trace
# *.clog are from the MPE option.
CHECK_CLEANFILES = *.chkexe *.chklog *.clog
-# Add include directories to the C preprocessor flags
-AM_CPPFLAGS = -I$(top_srcdir)/src
+# Add libtool shared library version numbers to the HDF5 library
+# See libtool versioning documentation online.
+LT_VERS_INTERFACE = 6
+LT_VERS_REVISION = 45
+LT_VERS_AGE = 0
# This library is our main target.
lib_LTLIBRARIES = libhdf5_hl.la
+
+# Add libtool numbers to the HDF5 hl library (from config/lt_vers.am)
+libhdf5_hl_la_LDFLAGS = -version-info $(LT_VERS_INTERFACE):$(LT_VERS_REVISION):$(LT_VERS_AGE) $(AM_LDFLAGS)
libhdf5_hl_la_SOURCES = H5DS.c H5IM.c H5LT.c H5LTanalyze.c H5LTparse.c H5PT.c H5TB.c
# Public header files (to be installed)
@@ -371,18 +412,18 @@ all: all-am
.SUFFIXES:
.SUFFIXES: .c .lo .o .obj
-$(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am $(top_srcdir)/config/commence.am $(top_srcdir)/config/conclude.am $(am__configure_deps)
+$(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am $(top_srcdir)/config/commence.am $(top_srcdir)/config/lt_vers.am $(top_srcdir)/config/conclude.am $(am__configure_deps)
@for dep in $?; do \
case '$(am__configure_deps)' in \
*$$dep*) \
- cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh \
- && exit 0; \
+ ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \
+ && { if test -f $@; then exit 0; else break; fi; }; \
exit 1;; \
esac; \
done; \
- echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign hl/src/Makefile'; \
- cd $(top_srcdir) && \
- $(AUTOMAKE) --foreign hl/src/Makefile
+ echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign hl/src/Makefile'; \
+ $(am__cd) $(top_srcdir) && \
+ $(AUTOMAKE) --foreign hl/src/Makefile
.PRECIOUS: Makefile
Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
@case '$?' in \
@@ -400,23 +441,28 @@ $(top_srcdir)/configure: @MAINTAINER_MODE_TRUE@ $(am__configure_deps)
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
$(ACLOCAL_M4): @MAINTAINER_MODE_TRUE@ $(am__aclocal_m4_deps)
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+$(am__aclocal_m4_deps):
install-libLTLIBRARIES: $(lib_LTLIBRARIES)
@$(NORMAL_INSTALL)
test -z "$(libdir)" || $(MKDIR_P) "$(DESTDIR)$(libdir)"
- @list='$(lib_LTLIBRARIES)'; for p in $$list; do \
+ @list='$(lib_LTLIBRARIES)'; test -n "$(libdir)" || list=; \
+ list2=; for p in $$list; do \
if test -f $$p; then \
- f=$(am__strip_dir) \
- echo " $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(libLTLIBRARIES_INSTALL) $(INSTALL_STRIP_FLAG) '$$p' '$(DESTDIR)$(libdir)/$$f'"; \
- $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(libLTLIBRARIES_INSTALL) $(INSTALL_STRIP_FLAG) "$$p" "$(DESTDIR)$(libdir)/$$f"; \
+ list2="$$list2 $$p"; \
else :; fi; \
- done
+ done; \
+ test -z "$$list2" || { \
+ echo " $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL) $(INSTALL_STRIP_FLAG) $$list2 '$(DESTDIR)$(libdir)'"; \
+ $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL) $(INSTALL_STRIP_FLAG) $$list2 "$(DESTDIR)$(libdir)"; \
+ }
uninstall-libLTLIBRARIES:
@$(NORMAL_UNINSTALL)
- @list='$(lib_LTLIBRARIES)'; for p in $$list; do \
- p=$(am__strip_dir) \
- echo " $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=uninstall rm -f '$(DESTDIR)$(libdir)/$$p'"; \
- $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=uninstall rm -f "$(DESTDIR)$(libdir)/$$p"; \
+ @list='$(lib_LTLIBRARIES)'; test -n "$(libdir)" || list=; \
+ for p in $$list; do \
+ $(am__strip_dir) \
+ echo " $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=uninstall rm -f '$(DESTDIR)$(libdir)/$$f'"; \
+ $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=uninstall rm -f "$(DESTDIR)$(libdir)/$$f"; \
done
clean-libLTLIBRARIES:
@@ -428,7 +474,7 @@ clean-libLTLIBRARIES:
rm -f "$${dir}/so_locations"; \
done
libhdf5_hl.la: $(libhdf5_hl_la_OBJECTS) $(libhdf5_hl_la_DEPENDENCIES)
- $(LINK) -rpath $(libdir) $(libhdf5_hl_la_OBJECTS) $(libhdf5_hl_la_LIBADD) $(LIBS)
+ $(libhdf5_hl_la_LINK) -rpath $(libdir) $(libhdf5_hl_la_OBJECTS) $(libhdf5_hl_la_LIBADD) $(LIBS)
mostlyclean-compile:
-rm -f *.$(OBJEXT)
@@ -446,21 +492,21 @@ distclean-compile:
.c.o:
@am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
-@am__fastdepCC_TRUE@ mv -f $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
+@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(COMPILE) -c $<
.c.obj:
@am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'`
-@am__fastdepCC_TRUE@ mv -f $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
+@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(COMPILE) -c `$(CYGPATH_W) '$<'`
.c.lo:
@am__fastdepCC_TRUE@ $(LTCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
-@am__fastdepCC_TRUE@ mv -f $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Plo
+@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Plo
@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(LTCOMPILE) -c -o $@ $<
@@ -473,34 +519,37 @@ clean-libtool:
install-includeHEADERS: $(include_HEADERS)
@$(NORMAL_INSTALL)
test -z "$(includedir)" || $(MKDIR_P) "$(DESTDIR)$(includedir)"
- @list='$(include_HEADERS)'; for p in $$list; do \
+ @list='$(include_HEADERS)'; test -n "$(includedir)" || list=; \
+ for p in $$list; do \
if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \
- f=$(am__strip_dir) \
- echo " $(includeHEADERS_INSTALL) '$$d$$p' '$(DESTDIR)$(includedir)/$$f'"; \
- $(includeHEADERS_INSTALL) "$$d$$p" "$(DESTDIR)$(includedir)/$$f"; \
+ echo "$$d$$p"; \
+ done | $(am__base_list) | \
+ while read files; do \
+ echo " $(INSTALL_HEADER) $$files '$(DESTDIR)$(includedir)'"; \
+ $(INSTALL_HEADER) $$files "$(DESTDIR)$(includedir)" || exit $$?; \
done
uninstall-includeHEADERS:
@$(NORMAL_UNINSTALL)
- @list='$(include_HEADERS)'; for p in $$list; do \
- f=$(am__strip_dir) \
- echo " rm -f '$(DESTDIR)$(includedir)/$$f'"; \
- rm -f "$(DESTDIR)$(includedir)/$$f"; \
- done
+ @list='$(include_HEADERS)'; test -n "$(includedir)" || list=; \
+ files=`for p in $$list; do echo $$p; done | sed -e 's|^.*/||'`; \
+ test -n "$$files" || exit 0; \
+ echo " ( cd '$(DESTDIR)$(includedir)' && rm -f" $$files ")"; \
+ cd "$(DESTDIR)$(includedir)" && rm -f $$files
ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES)
list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
unique=`for i in $$list; do \
if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
done | \
- $(AWK) '{ files[$$0] = 1; nonemtpy = 1; } \
+ $(AWK) '{ files[$$0] = 1; nonempty = 1; } \
END { if (nonempty) { for (i in files) print i; }; }'`; \
mkid -fID $$unique
tags: TAGS
TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \
$(TAGS_FILES) $(LISP)
- tags=; \
+ set x; \
here=`pwd`; \
list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
unique=`for i in $$list; do \
@@ -508,29 +557,34 @@ TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \
done | \
$(AWK) '{ files[$$0] = 1; nonempty = 1; } \
END { if (nonempty) { for (i in files) print i; }; }'`; \
- if test -z "$(ETAGS_ARGS)$$tags$$unique"; then :; else \
+ shift; \
+ if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \
test -n "$$unique" || unique=$$empty_fix; \
- $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
- $$tags $$unique; \
+ if test $$# -gt 0; then \
+ $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
+ "$$@" $$unique; \
+ else \
+ $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
+ $$unique; \
+ fi; \
fi
ctags: CTAGS
CTAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \
$(TAGS_FILES) $(LISP)
- tags=; \
list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
unique=`for i in $$list; do \
if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
done | \
$(AWK) '{ files[$$0] = 1; nonempty = 1; } \
END { if (nonempty) { for (i in files) print i; }; }'`; \
- test -z "$(CTAGS_ARGS)$$tags$$unique" \
+ test -z "$(CTAGS_ARGS)$$unique" \
|| $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \
- $$tags $$unique
+ $$unique
GTAGS:
here=`$(am__cd) $(top_builddir) && pwd` \
- && cd $(top_srcdir) \
- && gtags -i $(GTAGS_ARGS) $$here
+ && $(am__cd) $(top_srcdir) \
+ && gtags -i $(GTAGS_ARGS) "$$here"
distclean-tags:
-rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags
@@ -551,13 +605,17 @@ distdir: $(DISTFILES)
if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \
if test -d $$d/$$file; then \
dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \
+ if test -d "$(distdir)/$$file"; then \
+ find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \
+ fi; \
if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \
- cp -pR $(srcdir)/$$file $(distdir)$$dir || exit 1; \
+ cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \
+ find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \
fi; \
- cp -pR $$d/$$file $(distdir)$$dir || exit 1; \
+ cp -fpR $$d/$$file "$(distdir)$$dir" || exit 1; \
else \
- test -f $(distdir)/$$file \
- || cp -p $$d/$$file $(distdir)/$$file \
+ test -f "$(distdir)/$$file" \
+ || cp -p $$d/$$file "$(distdir)/$$file" \
|| exit 1; \
fi; \
done
@@ -589,6 +647,7 @@ clean-generic:
distclean-generic:
-test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES)
+ -test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES)
maintainer-clean-generic:
@echo "This command is intended for maintainers to use"
@@ -610,6 +669,8 @@ dvi-am:
html: html-am
+html-am:
+
info: info-am
info-am:
@@ -618,18 +679,28 @@ install-data-am: install-includeHEADERS
install-dvi: install-dvi-am
+install-dvi-am:
+
install-exec-am: install-libLTLIBRARIES
install-html: install-html-am
+install-html-am:
+
install-info: install-info-am
+install-info-am:
+
install-man:
install-pdf: install-pdf-am
+install-pdf-am:
+
install-ps: install-ps-am
+install-ps-am:
+
installcheck-am:
maintainer-clean: maintainer-clean-am
@@ -652,7 +723,7 @@ ps-am:
uninstall-am: uninstall-includeHEADERS uninstall-libLTLIBRARIES
-.MAKE: install-am install-strip
+.MAKE: check-am install-am install-strip
.PHONY: CTAGS GTAGS all all-am all-local check check-TESTS check-am \
clean clean-generic clean-libLTLIBRARIES clean-libtool ctags \
@@ -682,6 +753,19 @@ uninstall-am: uninstall-includeHEADERS uninstall-libLTLIBRARIES
help:
@$(top_srcdir)/bin/makehelp
+# Copyright by The HDF Group.
+# Copyright by the Board of Trustees of the University of Illinois.
+# All rights reserved.
+#
+# This file is part of HDF5. The full HDF5 copyright notice, including
+# terms governing use, modification, and redistribution, is contained in
+# the files COPYING and Copyright.html. COPYING can be found at the root
+# of the source code distribution tree; Copyright.html can be found at the
+# root level of an installed copy of the electronic HDF5 document set and
+# is linked from the top-level documents page. It can also be found at
+# http://hdfgroup.org/HDF5/doc/Copyright.html. If you do not have
+# access to either file, you may request a copy from help@hdfgroup.org.
+
# lib/progs/tests targets recurse into subdirectories. build-* targets
# build files in this directory.
build-lib: $(LIB)
@@ -876,6 +960,7 @@ check-vfd: $(LIB) $(PROGS) $(TESTS)
HDF5_DRIVER=$$vfd $(MAKE) $(AM_MAKEFLAGS) check || exit 1; \
fi; \
done
+
# Tell versions [3.59,3.63) of GNU make to not export all variables.
# Otherwise a system limit (for SysV at least) may be exceeded.
.NOEXPORT: