summaryrefslogtreecommitdiffstats
path: root/hl/src
diff options
context:
space:
mode:
Diffstat (limited to 'hl/src')
-rw-r--r--hl/src/H5DS.c290
1 files changed, 8 insertions, 282 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
-
-