From 9aed26ea4af4444092fe8d7b769cfa7487659f9a Mon Sep 17 00:00:00 2001 From: Pedro Vicente Nunes Date: Mon, 14 Feb 2005 16:29:59 -0500 Subject: [svn-r10006] Purpose: new features Description: added a 1st batch of tests for error conditions Solution: Platforms tested: linux solaris Misc. update: --- hl/src/H5DS.c | 288 ++++++++++++++++++++++++++++++++++++++++++++++++++- hl/src/H5LT.h | 1 + hl/test/test_ds.c | 164 +++++++++++++++++++++++++---- hl/test/test_table.c | 1 - 4 files changed, 430 insertions(+), 24 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>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