summaryrefslogtreecommitdiffstats
path: root/hl
diff options
context:
space:
mode:
Diffstat (limited to 'hl')
-rw-r--r--hl/src/H5DS.c798
1 files changed, 404 insertions, 394 deletions
diff --git a/hl/src/H5DS.c b/hl/src/H5DS.c
index 723b159..e3088da 100644
--- a/hl/src/H5DS.c
+++ b/hl/src/H5DS.c
@@ -24,8 +24,11 @@
/*-------------------------------------------------------------------------
* Function: H5DSset_scale
*
- * Purpose: Convert dataset DSID to a dimension scale, by writing the standard
- * attributes for a Dimension Scale dataset; optionally set its name
+ * 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: SUCCESS, Failure: FAIL
*
@@ -91,12 +94,17 @@ herr_t H5DSset_scale(hid_t dsid,
/*-------------------------------------------------------------------------
* Function: H5DSattach_scale
*
- * Purpose: attach a DS with DSID to the IDX dimension of the existing
- * dataset DID
+ * 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: SUCCESS
* 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
*
@@ -547,12 +555,20 @@ out:
/*-------------------------------------------------------------------------
* Function: H5DSdetach_scale
*
- * Purpose: detach a DS with DSID to the IDX dimension of the existing
- * dataset DID
+ * 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: SUCCESS
* 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
*
@@ -904,17 +920,24 @@ out:
}
/*-------------------------------------------------------------------------
- * Function: H5DSget_num_scales
+ * Function: H5DSis_attached
*
- * Purpose: get the number of scales linked to the IDX dimension of dataset DID
+ * 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:
- * Success: number of scales
- * Failure: FAIL
+ * 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: January 13, 2005
+ * Date: February 18, 2005
*
* Comments:
*
@@ -923,33 +946,60 @@ out:
*-------------------------------------------------------------------------
*/
-int H5DSget_num_scales(hid_t did,
+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; /* attribute type ID */
hid_t aid; /* 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 */
- H5I_type_t it; /* ID type */
- int nscales;
+ hid_t dsid_j; /* DS dataset ID in DIMENSION_LIST */
+ H5G_stat_t sb1, sb2, sb3, sb4;
+ 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 (H5Gget_objinfo(did,".",TRUE,&sb1)<0)
+ return FAIL;
+
+ /* get info for the scale in the parameter list */
+ if (H5Gget_objinfo(dsid,".",TRUE,&sb2)<0)
+ return FAIL;
+
+ /* same object, not valid */
+ if (sb1.fileno==sb2.fileno && sb1.u.obj.objno==sb2.u.obj.objno)
+ return FAIL;
+
/* get ID type */
- if ((it = H5Iget_type(did))<0)
+ if ((it1 = H5Iget_type(did))<0)
+ return FAIL;
+ if ((it2 = H5Iget_type(dsid))<0)
return FAIL;
- if (H5I_DATASET!=it)
+ if (H5I_DATASET!=it1 || H5I_DATASET!=it2)
return FAIL;
/*-------------------------------------------------------------------------
- * the attribute "DIMENSION_LIST" on the >>data<< dataset must exist
+ * get space
*-------------------------------------------------------------------------
*/
+
/* get dataset space */
if ((sid = H5Dget_space(did))<0)
return FAIL;
@@ -962,29 +1012,27 @@ int H5DSget_num_scales(hid_t did,
if (H5Sclose(sid)<0)
goto out;
- /* dimemsion index IDX range checking */
- if (idx>=(unsigned int )rank)
- return FAIL;
+ /* 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;
- /* it does not exist */
- if (has_dimlist == 0)
- return 0;
-
/*-------------------------------------------------------------------------
- * the attribute exists, open it
+ * open "DIMENSION_LIST"
*-------------------------------------------------------------------------
*/
- else if ( has_dimlist == 1 )
+ 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;
@@ -998,7 +1046,36 @@ int H5DSget_num_scales(hid_t did,
if (H5Aread(aid,tid,buf)<0)
goto out;
- nscales=(int)buf[idx].len;
+ /* 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 (H5Gget_objinfo(dsid,".",TRUE,&sb1)<0)
+ goto out;
+
+ /* get info for this DS */
+ if (H5Gget_objinfo(dsid_j,".",TRUE,&sb2)<0)
+ goto out;
+
+ /* same object */
+ if (sb1.fileno==sb2.fileno && sb1.u.obj.objno==sb2.u.obj.objno)
+ {
+ found_ds = 1;
+ }
+
+ /* close the dereferenced dataset */
+ if (H5Dclose(dsid_j)<0)
+ goto out;
+
+ }
+
/* close */
if (H5Dvlen_reclaim(tid,sid,H5P_DEFAULT,buf)<0)
@@ -1011,10 +1088,97 @@ int H5DSget_num_scales(hid_t did,
goto out;
if (buf)
free(buf);
-
} /* has_dimlist */
- return nscales;
+/*-------------------------------------------------------------------------
+ * 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_name(dsid,REFERENCE_LIST))<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 DS id */
+ if ((dsid_j = H5Rdereference(did,H5R_OBJECT,&ref))<0)
+ goto out;
+
+ /* get info for dataset in the parameter list */
+ if (H5Gget_objinfo(did,".",TRUE,&sb3)<0)
+ goto out;
+
+ /* get info for this DS */
+ if (H5Gget_objinfo(dsid_j,".",TRUE,&sb4)<0)
+ goto out;
+
+ /* same object */
+ if (sb3.fileno==sb4.fileno && sb3.u.obj.objno==sb4.u.obj.objno && (int)idx==dsbuf[i].dim_idx) {
+ found_dset=1;
+ } /* if */
+
+ /* close the dereferenced dataset */
+ if (H5Dclose(dsid_j)<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 */
out:
@@ -1026,6 +1190,193 @@ out:
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:
+ *
+ *-------------------------------------------------------------------------
+ */
+
+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 */
+ 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 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)[ 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)
+ {
+ /* set the return IDX OUT value at current scale index and break */
+ if (idx!=NULL)
+ {
+ *idx = i;
+ }
+
+ /* 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);
+
+ } /* 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;
+}
/*-------------------------------------------------------------------------
* Function: H5DSset_label
@@ -1195,7 +1546,7 @@ out:
/*-------------------------------------------------------------------------
* Function: H5DSget_label
*
- * Purpose: Read the label LABEL for dimension IDX of datsset DID
+ * 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
@@ -1326,8 +1677,6 @@ out:
return FAIL;
}
-
-
/*-------------------------------------------------------------------------
* Function: H5DSget_scale_name
*
@@ -1456,9 +1805,6 @@ out:
return FAIL;
}
-
-
-
/*-------------------------------------------------------------------------
* Function: H5DSis_scale
*
@@ -1539,211 +1885,18 @@ out:
}
-
-/*-------------------------------------------------------------------------
- * 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 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:
- *
- *-------------------------------------------------------------------------
- */
-
-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 */
- 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 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)[ 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)
- {
- /* set the return IDX OUT value at current scale index and break */
- if (idx!=NULL)
- {
- *idx = i;
- }
-
- /* 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);
-
- } /* 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;
-}
-
-
/*-------------------------------------------------------------------------
- * Function: H5DSis_attached
+ * Function: H5DSget_num_scales
*
- * 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
+ * Purpose: get the number of scales linked to the IDX dimension of dataset DID
*
* Return:
- * 1: both the DS and the dataset pointers match
- * 0: one of them or both do not match
- * FAIL (-1): error
+ * Success: number of scales
+ * Failure: FAIL
*
* Programmer: pvn@ncsa.uiuc.edu
*
- * Date: February 18, 2005
+ * Date: January 13, 2005
*
* Comments:
*
@@ -1752,60 +1905,33 @@ out:
*-------------------------------------------------------------------------
*/
-htri_t H5DSis_attached(hid_t did,
- hid_t dsid,
+int H5DSget_num_scales(hid_t did,
unsigned int idx)
{
int has_dimlist;
- int has_reflist;
- hssize_t nelmts;
hid_t sid; /* space ID */
hid_t tid; /* attribute type ID */
hid_t aid; /* 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 */
- H5G_stat_t sb1, sb2, sb3, sb4;
- H5I_type_t it1, it2;
- int i;
- int found_dset=0, found_ds=0;
+ H5I_type_t it; /* ID type */
+ int nscales;
/*-------------------------------------------------------------------------
* 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 (H5Gget_objinfo(did,".",TRUE,&sb1)<0)
- return FAIL;
-
- /* get info for the scale in the parameter list */
- if (H5Gget_objinfo(dsid,".",TRUE,&sb2)<0)
- return FAIL;
-
- /* same object, not valid */
- if (sb1.fileno==sb2.fileno && sb1.u.obj.objno==sb2.u.obj.objno)
- return FAIL;
-
/* get ID type */
- if ((it1 = H5Iget_type(did))<0)
- return FAIL;
- if ((it2 = H5Iget_type(dsid))<0)
+ if ((it = H5Iget_type(did))<0)
return FAIL;
- if (H5I_DATASET!=it1 || H5I_DATASET!=it2)
+ if (H5I_DATASET!=it)
return FAIL;
/*-------------------------------------------------------------------------
- * get space
+ * the attribute "DIMENSION_LIST" on the >>data<< dataset must exist
*-------------------------------------------------------------------------
*/
-
/* get dataset space */
if ((sid = H5Dget_space(did))<0)
return FAIL;
@@ -1818,27 +1944,29 @@ htri_t H5DSis_attached(hid_t did,
if (H5Sclose(sid)<0)
goto out;
- /* parameter range checking */
- if (idx>(unsigned)rank-1)
- 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;
+
/*-------------------------------------------------------------------------
- * open "DIMENSION_LIST"
+ * the attribute exists, open it
*-------------------------------------------------------------------------
*/
- if ( has_dimlist == 1 )
+ 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;
@@ -1852,36 +1980,7 @@ htri_t H5DSis_attached(hid_t did,
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 (H5Gget_objinfo(dsid,".",TRUE,&sb1)<0)
- goto out;
-
- /* get info for this DS */
- if (H5Gget_objinfo(dsid_j,".",TRUE,&sb2)<0)
- goto out;
-
- /* same object */
- if (sb1.fileno==sb2.fileno && sb1.u.obj.objno==sb2.u.obj.objno)
- {
- found_ds = 1;
- }
-
- /* close the dereferenced dataset */
- if (H5Dclose(dsid_j)<0)
- goto out;
-
- }
-
+ nscales=(int)buf[idx].len;
/* close */
if (H5Dvlen_reclaim(tid,sid,H5P_DEFAULT,buf)<0)
@@ -1894,97 +1993,10 @@ htri_t H5DSis_attached(hid_t did,
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_name(dsid,REFERENCE_LIST))<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 DS id */
- if ((dsid_j = H5Rdereference(did,H5R_OBJECT,&ref))<0)
- goto out;
-
- /* get info for dataset in the parameter list */
- if (H5Gget_objinfo(did,".",TRUE,&sb3)<0)
- goto out;
-
- /* get info for this DS */
- if (H5Gget_objinfo(dsid_j,".",TRUE,&sb4)<0)
- goto out;
-
- /* same object */
- if (sb3.fileno==sb4.fileno && sb3.u.obj.objno==sb4.u.obj.objno && (int)idx==dsbuf[i].dim_idx) {
- found_dset=1;
- } /* if */
- /* close the dereferenced dataset */
- if (H5Dclose(dsid_j)<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 */
+ } /* has_dimlist */
- if (found_ds && found_dset)
- return 1;
- else
- return 0;
+ return nscales;
/* error zone, gracefully close */
out:
@@ -1996,8 +2008,6 @@ out:
return FAIL;
}
-
-
/*-------------------------------------------------------------------------
* Function: H5DS_is_reserved
*