diff --git a/hl/src/H5DS.c b/hl/src/H5DS.c index e3b90149c4..8b5c7c3cff 100644 --- a/hl/src/H5DS.c +++ b/hl/src/H5DS.c @@ -110,15 +110,28 @@ herr_t H5DSattach_scale(hid_t did, 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 */ + H5G_stat_t sb1, sb2; int i, len; /*------------------------------------------------------------------------- - * verify that the datasets are valid + * 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.objno==sb2.objno) + return FAIL; /*------------------------------------------------------------------------- * The dataset may or may not have the associated DS attribute @@ -1399,6 +1412,278 @@ 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 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. + * + * 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 */ + 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>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