summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPedro Vicente Nunes <pvn@hdfgroup.org>2005-02-16 20:45:38 (GMT)
committerPedro Vicente Nunes <pvn@hdfgroup.org>2005-02-16 20:45:38 (GMT)
commita68c4c7981ba4224e72f64556483f3707be94ffc (patch)
tree4051507c2313d05c194080debf999f6c92d4f0ad
parent67cac7fdf7af78390a0275cba46ef0e7595c15b4 (diff)
downloadhdf5-a68c4c7981ba4224e72f64556483f3707be94ffc.zip
hdf5-a68c4c7981ba4224e72f64556483f3707be94ffc.tar.gz
hdf5-a68c4c7981ba4224e72f64556483f3707be94ffc.tar.bz2
[svn-r10019] Purpose:
new test Description: added a test for the iterator function that verifies if the scales meet certain criteria (having the same size as the dimensions sizes of the dataset and they are not empty datasets) Solution: Platforms tested: linux solaris Misc. update:
-rw-r--r--hl/src/H5DS.c290
-rw-r--r--hl/test/test_ds.c254
2 files changed, 256 insertions, 288 deletions
diff --git a/hl/src/H5DS.c b/hl/src/H5DS.c
index 0615a80..902fb9b 100644
--- a/hl/src/H5DS.c
+++ b/hl/src/H5DS.c
@@ -1267,7 +1267,7 @@ out:
* Parameters:
*
* hid_t DID; IN: the dataset
- * unsigned int dim; IN: the dimension of dset
+ * 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
@@ -1303,7 +1303,7 @@ herr_t H5DSiterate_scales(hid_t did,
H5DS_iterate_t visitor,
void *visitor_data )
{
- hid_t scale_id;
+ hid_t scale_id=0;
int rank;
hobj_ref_t ref; /* reference to the DS */
hid_t sid; /* space ID */
@@ -1369,14 +1369,18 @@ herr_t H5DSiterate_scales(hid_t did,
for(i=j_idx; i<nscales; i++)
{
/* get the reference */
- ref = ((hobj_ref_t *)buf[dim].p)[j_idx];
+ ref = ((hobj_ref_t *)buf[dim].p)[ i ];
/* 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))!=0)
+ {
+ /* set the return IDX OUT value at current scale index and break */
+ if (idx!=NULL) *idx = i;
break;
+ }
} /* i */
} /* if */
@@ -1390,7 +1394,7 @@ herr_t H5DSiterate_scales(hid_t did,
goto out;
if (H5Aclose(aid)<0)
goto out;
- if (H5Dclose(scale_id)<0)
+ if (scale_id && H5Dclose(scale_id)<0)
goto out;
if (buf)
free(buf);
@@ -1404,281 +1408,3 @@ out:
}
-#if 0
-/*-------------------------------------------------------------------------
- * 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;
-}
-
-#endif
-
-
diff --git a/hl/test/test_ds.c b/hl/test/test_ds.c
index f891889..8ab29da 100644
--- a/hl/test/test_ds.c
+++ b/hl/test/test_ds.c
@@ -20,6 +20,8 @@
/* operator functions */
static herr_t verifiy_scale(hid_t dset, unsigned dim, hid_t scale, void *visitor_data);
static herr_t read_scale(hid_t dset, unsigned dim, hid_t scale, void *visitor_data);
+static herr_t match_dim_scale(hid_t did, unsigned dim, hid_t dsid, void *visitor_data);
+
/* prototypes */
static int test_simple(void);
static int test_errors(void);
@@ -74,6 +76,7 @@ static int test_simple(void)
hid_t fid; /* file ID */
hid_t did; /* dataset ID */
hid_t dsid; /* DS dataset ID */
+ hid_t sid; /* space ID */
int rank = RANK; /* rank of data dataset */
int rankds = 1; /* rank of DS dataset */
hsize_t dims[RANK] = {DIM1_SIZE,DIM2_SIZE}; /* size of data dataset */
@@ -532,7 +535,7 @@ static int test_simple(void)
* test 6: test iterate scales with a function verifiy_scale
*-------------------------------------------------------------------------
*/
- TESTING2("iterate scales");
+ TESTING2("iterate scales (verify scale)");
/* get the dataset id for "dset_a" */
if ((did = H5Dopen(fid,"dset_a"))<0)
@@ -560,10 +563,11 @@ static int test_simple(void)
/*-------------------------------------------------------------------------
- * test 6: test iterate scales with a function read_scale
+ * test 7: test iterate scales with a function read_scale
*-------------------------------------------------------------------------
*/
- TESTING2("read scale values with iterate scales");
+ TESTING2("iterate scales (read scale values)");
+
/* get the dataset id for "dset_a" */
if ((did = H5Dopen(fid,"dset_a"))<0)
@@ -590,6 +594,162 @@ static int test_simple(void)
PASSED();
/*-------------------------------------------------------------------------
+ * test 8: test iterate scales with a function match_dim_scale
+ *-------------------------------------------------------------------------
+ */
+ TESTING2("iterate scales (verify the scale sizes match)");
+
+ /* get the dataset id for "dset_a" */
+ if ((did = H5Dopen(fid,"dset_a"))<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;
+
+ /* get dimensions of dataset */
+ if (H5Sget_simple_extent_dims(sid,dims,NULL)<0)
+ goto out;
+
+ {
+ int match_size; /* does this scale size matches the dataset DIM size */
+ int idx=0; /* scale index to start iterating, on return, index where iterator stoped */
+
+ /* iterate trough all the dimensions */
+ for(dim=0; dim<(unsigned)rank; dim++)
+ {
+ if ((match_size=H5DSiterate_scales(did,dim,&idx,match_dim_scale,NULL))<0)
+ goto out;
+
+ /* "dset_a" was defined with all dimension scales size matching the size of its dimensions */
+ if (match_size==0)
+ goto out;
+
+ /* both "ds1" and "ds2" are the on the first index */
+ if (idx!=0)
+ goto out;
+ }
+ }
+
+
+ /* close */
+ if (H5Dclose(did)<0)
+ goto out;
+ if (H5Sclose(sid)<0)
+ goto out;
+
+ PASSED();
+
+/*-------------------------------------------------------------------------
+ * test 9: test iterate scales with a function match_dim_scale
+ *-------------------------------------------------------------------------
+ */
+ TESTING2("iterate scales (verify the scale sizes do not match)");
+
+/*-------------------------------------------------------------------------
+ * create 3 datasets: 1 "data" dataset and dimension scales (some are empty)
+ *-------------------------------------------------------------------------
+ */
+ if (H5LTmake_dataset_int(fid,"dset_d",rank,dims,buf)<0)
+ goto out;
+ if (H5LTmake_dataset_int(fid,"ds6_1_1",rankds,s1_dim,NULL)<0)
+ goto out;
+ if (H5LTmake_dataset_int(fid,"ds6_1_2",rankds,s1_dim,s1_wbuf)<0)
+ goto out;
+ if (H5LTmake_dataset_int(fid,"ds7_2_1",rankds,s2_dim,NULL)<0)
+ goto out;
+
+/*-------------------------------------------------------------------------
+ * attach them
+ *-------------------------------------------------------------------------
+ */
+ if ((did = H5Dopen(fid,"dset_d"))<0)
+ goto out;
+
+ if ((dsid = H5Dopen(fid,"ds6_1_1"))<0)
+ goto out;
+ if (H5DSattach_scale(did,dsid,0)<0)
+ goto out;
+ if (H5Dclose(dsid)<0)
+ goto out;
+ if ((dsid = H5Dopen(fid,"ds6_1_2"))<0)
+ goto out;
+ if (H5DSattach_scale(did,dsid,0)<0)
+ goto out;
+ if (H5Dclose(dsid)<0)
+ goto out;
+ if ((dsid = H5Dopen(fid,"ds7_2_1"))<0)
+ goto out;
+ if (H5DSattach_scale(did,dsid,1)<0)
+ goto out;
+ if (H5Dclose(dsid)<0)
+ goto out;
+
+ if (H5Dclose(did)<0)
+ goto out;
+
+/*-------------------------------------------------------------------------
+ * verify match
+ *-------------------------------------------------------------------------
+ */
+ /* get the dataset id for "dset_d" */
+ if ((did = H5Dopen(fid,"dset_d"))<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;
+
+ /* get dimensions of dataset */
+ if (H5Sget_simple_extent_dims(sid,dims,NULL)<0)
+ goto out;
+
+ {
+ int match_size; /* does this scale size matches the dataset DIM size */
+ int idx; /* scale index to start iterating, on return, index where iterator stoped */
+
+ /* iterate trough all the dimensions */
+ for(dim=0; dim<(unsigned)rank; dim++)
+ {
+ /* always start at 1st scale */
+ idx=0;
+
+ if ((match_size=H5DSiterate_scales(did,dim,&idx,match_dim_scale,NULL))<0)
+ goto out;
+
+ /* "dset_d" was defined with :
+ dim 0: 2 scales, first is empty
+ dim 1: 1 scale, empty */
+ switch(dim)
+ {
+ case 0: /* for DIM 0, we get a valid scale at IDX 1 */
+ if (match_size!=1 && idx!=1)
+ goto out;
+ break;
+ case 1: /* for DIM 1, we get no valid scales */
+ if (match_size!=0 && idx!=0)
+ goto out;
+ }/*switch*/
+ }/*for*/
+ }
+
+ /* close */
+ if (H5Dclose(did)<0)
+ goto out;
+ if (H5Sclose(sid)<0)
+ goto out;
+
+ PASSED();
+
+/*-------------------------------------------------------------------------
* end
*-------------------------------------------------------------------------
*/
@@ -730,7 +890,7 @@ out:
* Function: verifiy_scale
*
* Purpose: example operator function used by H5DSiterate_scales, used
- * to veify that SCALE_ID refers to a valid DS dataset
+ * to verify that SCALE_ID refers to a valid DS dataset
*
* Return:
* The return values from an operator are:
@@ -745,9 +905,7 @@ out:
static herr_t verifiy_scale(hid_t dset, unsigned dim, hid_t scale_id, void *visitor_data)
{
-
/* define a default zero value for return. This will cause the iterator to continue */
-
int ret = 0;
/* unused */
@@ -863,3 +1021,87 @@ static herr_t read_scale(hid_t dset, unsigned dim, hid_t scale_id, void *visitor
return FAIL;
}
+
+/*-------------------------------------------------------------------------
+ * Function: match_dim_scale
+ *
+ * Purpose: example operator function used by H5DSiterate_scales, used
+ * to verify the the DSID scale size matches the dataset DIM size
+ *
+ * Return:
+ * The return values from an operator are:
+ * Zero causes the iterator to continue, returning zero when all group members have been processed.
+ * Positive causes the iterator to immediately return that positive value, indicating
+ * short-circuit success. The iterator can be restarted at the next group member.
+ * Negative causes the iterator to immediately return that value, indicating failure.
+ * The iterator can be restarted at the next group member.
+ *
+ *-------------------------------------------------------------------------
+ */
+
+static herr_t match_dim_scale(hid_t did, unsigned dim, hid_t dsid, void *visitor_data)
+{
+ int ret = 0; /* define a default zero value for return. This will cause the iterator to continue */
+ hid_t sid; /* space ID */
+ hssize_t nelmts; /* size of a dimension scale array */
+ int rank; /* rank of dataset */
+ hsize_t dims[H5S_MAX_RANK]; /* dimensions of dataset */
+ hsize_t storage_size;
+
+/*-------------------------------------------------------------------------
+ * get DID (dataset) space info
+ *-------------------------------------------------------------------------
+ */
+
+ /* get dataset space */
+ if ((sid = H5Dget_space(did))<0)
+ goto out;
+
+ /* get rank */
+ if ((rank=H5Sget_simple_extent_ndims(sid))<0)
+ goto out;
+
+ /* get dimensions of dataset */
+ if (H5Sget_simple_extent_dims(sid,dims,NULL)<0)
+ goto out;
+
+ /* close the dataspace id */
+ if (H5Sclose(sid)<0)
+ goto out;
+
+/*-------------------------------------------------------------------------
+ * get DSID (scale) space info
+ *-------------------------------------------------------------------------
+ */
+
+ /* get the space for the scale */
+ if ((sid = H5Dget_space(dsid))<0)
+ goto out;
+
+ /* get size of the DS array */
+ if ((nelmts = H5Sget_simple_extent_npoints(sid))<0)
+ goto out;
+
+ /* close */
+ if (H5Sclose(sid)<0)
+ goto out;
+
+ /* the size of the DS array must match the dimension of the dataset */
+ if (nelmts == (hssize_t)dims[dim])
+ ret = 1;
+
+ /* if the scale is empty assume it cannot be used */
+ if ((storage_size=H5Dget_storage_size(dsid))<0)
+ goto out;
+
+ if (storage_size==0)
+ ret = 0;
+
+ return ret;
+
+out:
+ H5E_BEGIN_TRY {
+ H5Sclose(sid);
+ } H5E_END_TRY;
+ return FAIL;
+} \ No newline at end of file