summaryrefslogtreecommitdiffstats
path: root/hl/src/H5DS.c
diff options
context:
space:
mode:
Diffstat (limited to 'hl/src/H5DS.c')
-rw-r--r--hl/src/H5DS.c329
1 files changed, 308 insertions, 21 deletions
diff --git a/hl/src/H5DS.c b/hl/src/H5DS.c
index 3bec833..e3b9014 100644
--- a/hl/src/H5DS.c
+++ b/hl/src/H5DS.c
@@ -10,6 +10,7 @@
* *
****************************************************************************/
+
#include "H5DS.h"
#include "H5LT.h"
#include <stdlib.h>
@@ -139,6 +140,10 @@ herr_t H5DSattach_scale(hid_t did,
if (H5Sclose(sid)<0)
goto out;
+ /* parameter range checking */
+ if (idx>(unsigned)rank-1)
+ goto out;
+
/*-------------------------------------------------------------------------
* two references are created: one to the DS, saved in "DIMENSION_LIST"
* and one to the dataset, saved in "REFERENCE_LIST"
@@ -1212,28 +1217,34 @@ herr_t H5DShas_scale(hid_t did)
{
/* get the reference */
ref = ((hobj_ref_t *)buf[i].p)[0];
-
- /* get the DS id */
- if ((dsid = H5Rdereference(did,H5R_OBJECT,&ref))<0)
- goto out;
-
- /* check information in referenced dataset */
- if ((dssid = H5Dget_space(dsid))<0)
- goto out;
-
- /* get size of the DS array */
- if ((dsnelmts = H5Sget_simple_extent_npoints(dssid))<0)
- goto out;
-
- /* the size of the DS array must match the dimension of the dataset */
- if (dsnelmts != (hssize_t)dims[i])
+
+ if (ref==0)
has_ds = 0;
-
- /* close the dereferenced dataset */
- if (H5Dclose(dsid)<0)
- goto out;
- if (H5Sclose(dssid)<0)
- goto out;
+
+ if (ref)
+ {
+ /* get the DS id */
+ if ((dsid = H5Rdereference(did,H5R_OBJECT,&ref))<0)
+ goto out;
+
+ /* check information in referenced dataset */
+ if ((dssid = H5Dget_space(dsid))<0)
+ goto out;
+
+ /* get size of the DS array */
+ if ((dsnelmts = H5Sget_simple_extent_npoints(dssid))<0)
+ goto out;
+
+ /* the size of the DS array must match the dimension of the dataset */
+ if (dsnelmts != (hssize_t)dims[i])
+ has_ds = 0;
+
+ /* close the dereferenced dataset */
+ if (H5Dclose(dsid)<0)
+ goto out;
+ if (H5Sclose(dssid)<0)
+ goto out;
+ }
}
}
@@ -1265,3 +1276,279 @@ out:
}
+
+
+/*-------------------------------------------------------------------------
+ * Function: H5DSget_nscales
+ *
+ * Purpose: get the number of scales linked to the IDX dimension of DNAME
+ *
+ * Return:
+ * Success: SUCCESS: both the DS and the dataset exist
+ * Failure: FAIL: if either one of them does not exist
+ *
+ * Programmer: pvn@ncsa.uiuc.edu
+ *
+ * Date: January 13, 2005
+ *
+ * Comments:
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+
+herr_t H5DSget_nscales(hid_t did,
+ unsigned int dim,
+ int *nscales)
+{
+ int has_dimlist;
+ hid_t sid; /* space ID */
+ hid_t tid; /* attribute type ID */
+ hid_t aid; /* attribute ID */
+ int rank; /* rank of dataset */
+ hvl_t *buf; /* VL buffer to store in the attribute */
+ hobj_ref_t ref; /* reference to the DS */
+ int i, n;
+
+/*-------------------------------------------------------------------------
+ * the attribute "DIMENSION_LIST" on the >>data<< dataset must exist
+ *-------------------------------------------------------------------------
+ */
+ /* get dataset space */
+ if ((sid = H5Dget_space(did))<0)
+ goto out;
+
+ /* get rank */
+ if ((rank=H5Sget_simple_extent_ndims(sid))<0)
+ goto out;
+
+ /* close dataset space */
+ if (H5Sclose(sid)<0)
+ goto out;
+
+ /* DIM range checking */
+ if (dim>=(unsigned int )rank)
+ 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;
+
+ /* it does not exist */
+ if (has_dimlist == 0)
+ goto out;
+
+/*-------------------------------------------------------------------------
+ * the attribute exists, open it
+ *-------------------------------------------------------------------------
+ */
+
+ else if ( has_dimlist == 1 )
+ {
+ if ((aid = H5Aopen_name(did,DIMENSION_LIST))<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;
+
+ for(i=0,n=0; i<buf[dim].len; i++)
+ {
+ ref = ((hobj_ref_t *)buf[dim].p)[i];
+ if (ref) n++;
+ }
+ /* return value */
+ *nscales =n;
+
+ /* 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 SUCCESS;
+
+/* error zone, gracefully close */
+out:
+ H5E_BEGIN_TRY {
+ H5Dclose(did);
+ H5Sclose(sid);
+ H5Aclose(aid);
+ H5Tclose(tid);
+ } H5E_END_TRY;
+ return FAIL;
+
+}
+
+/*-------------------------------------------------------------------------
+ * Function: H5DSiterate_scales
+ *
+ * Purpose: H5DSiterate_scales iterates over the scales attached to dimension dim
+ * of dataset dset. 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 dset
+ * 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.
+ *
+ * Programmer: pvn@ncsa.uiuc.edu
+ *
+ * Date: January 31, 2005
+ *
+ * Comments:
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+
+herr_t H5DSiterate_scales(hid_t did,
+ unsigned int dim,
+ int *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; /* attribute type ID */
+ hid_t aid; /* attribute ID */
+ hvl_t *buf=NULL; /* VL buffer to store in the attribute */
+ herr_t ret_value=0;
+ int j_idx;
+ int nscales;
+ int has_dimlist;
+ int i;
+
+ /* get the number of scales assotiated with this DIM */
+ if (H5DSget_nscales(did,dim,&nscales)<0)
+ goto out;
+
+ /* get dataset space */
+ if ((sid = H5Dget_space(did))<0)
+ goto out;
+
+ /* 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)
+ goto out;
+
+ if (has_dimlist == 0)
+ return SUCCESS;
+
+ else if (has_dimlist == 1 )
+ {
+ if ((aid = H5Aopen_name(did,DIMENSION_LIST))<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)[j_idx];
+
+ /* get the DS id */
+ if ((scale_id = H5Rdereference(did,H5R_OBJECT,&ref))<0)
+ goto out;
+
+ if((ret_value=(visitor)(did,dim,scale_id,visitor_data))==1)
+ {
+ /* 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 (H5Dclose(scale_id)<0)
+ goto out;
+ if (buf)
+ free(buf);
+ return SUCCESS;
+ } /* if */
+ } /* 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 (H5Dclose(scale_id)<0)
+ goto out;
+ if (buf)
+ free(buf);
+
+ if (ret_value<0)
+ goto out;
+
+ } /* if has_dimlist */
+
+ return 0;
+
+out:
+ return FAIL;
+}
+