diff options
author | Pedro Vicente Nunes <pvn@hdfgroup.org> | 2005-02-14 21:29:59 (GMT) |
---|---|---|
committer | Pedro Vicente Nunes <pvn@hdfgroup.org> | 2005-02-14 21:29:59 (GMT) |
commit | 9aed26ea4af4444092fe8d7b769cfa7487659f9a (patch) | |
tree | d48894f4817913c5cb4e6523c6d38b7cf1371f25 /hl/src/H5DS.c | |
parent | 2870a5d07ae0345acc6f2cc2f90123fd382fb512 (diff) | |
download | hdf5-9aed26ea4af4444092fe8d7b769cfa7487659f9a.zip hdf5-9aed26ea4af4444092fe8d7b769cfa7487659f9a.tar.gz hdf5-9aed26ea4af4444092fe8d7b769cfa7487659f9a.tar.bz2 |
[svn-r10006] Purpose:
new features
Description:
added a 1st batch of tests for error conditions
Solution:
Platforms tested:
linux
solaris
Misc. update:
Diffstat (limited to 'hl/src/H5DS.c')
-rw-r--r-- | hl/src/H5DS.c | 288 |
1 files changed, 287 insertions, 1 deletions
diff --git a/hl/src/H5DS.c b/hl/src/H5DS.c index e3b9014..8b5c7c3 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 @@ -1418,6 +1431,278 @@ out: * 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<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))!=0) + break; + + } /* 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 has_dimlist */ + + return ret_value; + +out: + return FAIL; +} + + +#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 @@ -1552,3 +1837,4 @@ out: return FAIL; } +#endif
\ No newline at end of file |