summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--hl/src/H5DS.c38
-rw-r--r--hl/test/test_ds.c72
2 files changed, 80 insertions, 30 deletions
diff --git a/hl/src/H5DS.c b/hl/src/H5DS.c
index 1d1e245..c3b444c 100644
--- a/hl/src/H5DS.c
+++ b/hl/src/H5DS.c
@@ -1292,11 +1292,12 @@ out:
* 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.
+* 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.
@@ -1324,7 +1325,7 @@ out:
herr_t H5DSiterate_scales(hid_t did,
unsigned int dim,
- int *idx,
+ int *ds_idx,
H5DS_iterate_t visitor,
void *visitor_data )
{
@@ -1358,9 +1359,9 @@ herr_t H5DSiterate_scales(hid_t did,
return FAIL;
/* parameter range checking */
- if (idx!=NULL)
+ if (ds_idx!=NULL)
{
- if (*idx>=nscales)
+ if (*ds_idx>=nscales)
return FAIL;
}
@@ -1376,6 +1377,9 @@ herr_t H5DSiterate_scales(hid_t did,
if(H5Sclose(sid) < 0)
goto out;
+ if ( dim >= (unsigned)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;
@@ -1404,8 +1408,8 @@ herr_t H5DSiterate_scales(hid_t did,
if ( buf[dim].len > 0 )
{
- if (idx!=NULL)
- j_idx = *idx;
+ if (ds_idx!=NULL)
+ j_idx = *ds_idx;
else
j_idx=0;
@@ -1422,14 +1426,16 @@ herr_t H5DSiterate_scales(hid_t did,
goto out;
} H5E_END_TRY;
- if((ret_value=(visitor)(did,dim,scale_id,visitor_data))!=0)
+ /* set the return IDX OUT value at current scale index */
+ if (ds_idx!=NULL)
{
- /* set the return IDX OUT value at current scale index and break */
- if (idx!=NULL)
- {
- *idx = i;
- }
+ *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;
diff --git a/hl/test/test_ds.c b/hl/test/test_ds.c
index 48f149a..c8d8227 100644
--- a/hl/test/test_ds.c
+++ b/hl/test/test_ds.c
@@ -1680,7 +1680,8 @@ out:
/*-------------------------------------------------------------------------
* Function: op_continue
*
- * Purpose: example operator function used by H5DSiterate_scales, that does nothing
+ * Purpose: example operator function used by H5DSiterate_scales that continues
+ * iteration and increments visitor_data (Note: int*)
*
* Return:
* The return values from an operator are:
@@ -1699,7 +1700,11 @@ static herr_t op_continue(hid_t dset, unsigned dim, hid_t scale_id, void *visito
dset = dset;
dim = dim;
scale_id = scale_id;
- visitor_data = visitor_data;
+
+ if ( visitor_data != NULL )
+ {
+ (*(int *)visitor_data)++;
+ }
/* define a default zero value for return. This will cause the iterator to continue */
return 0;
@@ -1709,7 +1714,8 @@ static herr_t op_continue(hid_t dset, unsigned dim, hid_t scale_id, void *visito
/*-------------------------------------------------------------------------
* Function: op_stop
*
- * Purpose: example operator function used by H5DSiterate_scales, that does nothing
+ * Purpose: example operator function used by H5DSiterate_scales that stops
+ * iteration and increments visitor_data (Note: int*)
*
* Return:
* The return values from an operator are:
@@ -1728,7 +1734,11 @@ static herr_t op_stop(hid_t dset, unsigned dim, hid_t scale_id, void *visitor_da
dset = dset;
dim = dim;
scale_id = scale_id;
- visitor_data = visitor_data;
+
+ if ( visitor_data != NULL )
+ {
+ (*(int *)visitor_data)++;
+ }
/* define a default 1 value for return. This will cause the iterator to stop */
return 1;
@@ -2946,8 +2956,10 @@ static int test_errors2(void)
hsize_t dimd[2] = {3,3}; /* size of data dataset */
hsize_t dims[1] = {3}; /* size of scale dataset */
char lbuf[255]; /* label buffer */
- size_t label_len;
- int ds_idx;
+ size_t label_len; /* label lenght */
+ int scale_idx; /* scale index */
+ int nscales; /* number of scales in DIM */
+ int count; /* visitor data */
printf("Testing parameter errors\n");
@@ -2968,6 +2980,11 @@ static int test_errors2(void)
if(H5LTmake_dataset_int(fid,"ds1",1,dims,NULL) < 0)
goto out;
+ /* make a scale dataset */
+ if(H5LTmake_dataset_int(fid,"ds2",1,dims,NULL) < 0)
+ goto out;
+
+
/*-------------------------------------------------------------------------
* attach with invalid indices
@@ -3027,11 +3044,12 @@ static int test_errors2(void)
/*-------------------------------------------------------------------------
- * iterate_scales invalid indices
+ * iterate_scales invalid indices and return DS_IDX and visitor data
*-------------------------------------------------------------------------
*/
if ((did = H5Dopen2(fid,"dset", H5P_DEFAULT)) < 0)
goto out;
+
if ((dsid = H5Dopen2(fid,"ds1", H5P_DEFAULT)) < 0)
goto out;
if (H5DSattach_scale(did,dsid,0) < 0)
@@ -3039,22 +3057,48 @@ static int test_errors2(void)
if (H5Dclose(dsid) < 0)
goto out;
+ if ((dsid = H5Dopen2(fid,"ds2", H5P_DEFAULT)) < 0)
+ goto out;
+ if (H5DSattach_scale(did,dsid,0) < 0)
+ goto out;
+ if (H5Dclose(dsid) < 0)
+ goto out;
+
+ if((nscales = H5DSget_num_scales(did,0)) < 0)
+ goto out;
+ if(nscales!=2)
+ goto out;
+ /* invalid DIM */
if (H5DSiterate_scales(did,2,NULL,op_continue,NULL)== SUCCEED)
goto out;
- ds_idx = 2; /* invalid */
- if (H5DSiterate_scales(did,0,&ds_idx,op_continue,NULL)== SUCCEED)
+ /* invalid DS_IDX */
+ scale_idx = 2;
+ if (H5DSiterate_scales(did,0,&scale_idx,op_continue,NULL)== SUCCEED)
goto out;
- if (H5DSiterate_scales(did,0,NULL,op_continue,NULL) < 0)
+
+ /* continue iteration */
+ scale_idx = 0;
+ count = 0;
+ if (H5DSiterate_scales(did,0,&scale_idx,op_continue,(void *)&count) < 0)
goto out;
- ds_idx = 0;
- /* stop at first scale iteration and return ds_idx*/
- if (H5DSiterate_scales(did,0,&ds_idx,op_stop,NULL) < 0)
+
+ if ( scale_idx != 1 && count != nscales )
+ {
goto out;
- if ( ds_idx != 0 )
+ }
+
+ /* stop iteration */
+ scale_idx = 0;
+ count = 0;
+ if (H5DSiterate_scales(did,0,&scale_idx,op_stop,(void *)&count) < 0)
+ goto out;
+
+ if ( scale_idx != 0 && count != 1 )
{
goto out;
}
+
if (H5Dclose(did) < 0)
goto out;