diff options
-rw-r--r-- | hl/src/H5DS.c | 130 | ||||
-rw-r--r-- | hl/src/H5DS.h | 8 | ||||
-rw-r--r-- | hl/test/test_ds.c | 140 |
3 files changed, 250 insertions, 28 deletions
diff --git a/hl/src/H5DS.c b/hl/src/H5DS.c index 8707f2c..b40f342 100644 --- a/hl/src/H5DS.c +++ b/hl/src/H5DS.c @@ -38,6 +38,18 @@ herr_t H5DSset_scale(hid_t did, char *dimname) { int has_dimlist; + H5I_type_t it; + +/*------------------------------------------------------------------------- + * parameter checking + *------------------------------------------------------------------------- + */ + /* get ID type */ + if ((it = H5Iget_type(did))<0) + return FAIL; + + if (H5I_DATASET!=it) + return FAIL; /*------------------------------------------------------------------------- * check if the dataset is a dataset wich has references to dimension scales @@ -508,13 +520,37 @@ herr_t H5DSdetach_scale(hid_t did, unsigned i, j, jj; H5G_stat_t sb1, sb2, sb3, sb4; int found_dset=0, found_ds=0; + H5I_type_t it1, it2; /*------------------------------------------------------------------------- - * check if the dataset is a DS dataset + * 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; + + /* get ID type */ + if ((it1 = H5Iget_type(did))<0) + return FAIL; + if ((it2 = H5Iget_type(dsid))<0) + return FAIL; + + if (H5I_DATASET!=it1 || H5I_DATASET!=it2) + return FAIL; + /*------------------------------------------------------------------------- * Find "DIMENSION_LIST" @@ -748,6 +784,18 @@ herr_t H5DSget_nscales(hid_t did, hid_t aid; /* attribute ID */ int rank; /* rank of dataset */ hvl_t *buf; /* VL buffer to store in the attribute */ + H5I_type_t it; /* ID type */ + +/*------------------------------------------------------------------------- + * parameter checking + *------------------------------------------------------------------------- + */ + /* get ID type */ + if ((it = H5Iget_type(did))<0) + return FAIL; + + if (H5I_DATASET!=it) + return FAIL; /*------------------------------------------------------------------------- * the attribute "DIMENSION_LIST" on the >>data<< dataset must exist @@ -860,8 +908,25 @@ herr_t H5DSset_label(hid_t did, int rank; /* rank of dataset */ hsize_t dims[1]; /* dimensions of dataset */ char **buf=NULL; /* buffer to store in the attribute */ + H5I_type_t it; /* ID type */ unsigned int i; +/*------------------------------------------------------------------------- + * parameter checking + *------------------------------------------------------------------------- + */ + /* get ID type */ + if ((it = H5Iget_type(did))<0) + return FAIL; + + if (H5I_DATASET!=it) + return FAIL; + +/*------------------------------------------------------------------------- + * attribute "DIMENSION_LABELS" + *------------------------------------------------------------------------- + */ + /* try to find the attribute "DIMENSION_LABELS" on the >>data<< dataset */ if ((has_labels = H5LT_find_attribute(did,DIMENSION_LABELS))<0) return FAIL; @@ -1017,8 +1082,25 @@ herr_t H5DSget_label(hid_t did, hid_t aid; /* attribute ID */ int rank; /* rank of dataset */ char **buf=NULL; /* buffer to store in the attribute */ + H5I_type_t it; /* ID type */ unsigned int i; +/*------------------------------------------------------------------------- + * parameter checking + *------------------------------------------------------------------------- + */ + /* get ID type */ + if ((it = H5Iget_type(did))<0) + return FAIL; + + if (H5I_DATASET!=it) + return FAIL; + +/*------------------------------------------------------------------------- + * attribute "DIMENSION_LABELS" + *------------------------------------------------------------------------- + */ + /* try to find the attribute "DIMENSION_LABELS" on the >>data<< dataset */ if ((has_labels = H5LT_find_attribute(did,DIMENSION_LABELS))<0) return FAIL; @@ -1120,12 +1202,20 @@ out: herr_t H5DSget_scale_name(hid_t did, char *buf) { + H5I_type_t it; /* ID type */ int has_name; /*------------------------------------------------------------------------- - * check if the dataset is a DS dataset + * parameter checking *------------------------------------------------------------------------- */ + /* get ID type */ + if ((it = H5Iget_type(did))<0) + return FAIL; + + if (H5I_DATASET!=it) + return FAIL; + if ((H5DSis_scale(did))<=0) return FAIL; @@ -1171,11 +1261,24 @@ herr_t H5DSget_scale_name(hid_t did, herr_t H5DSis_scale(hid_t did) { - hid_t tid; /* attribute type ID */ - hid_t aid; /* attribute ID */ - herr_t has_class; /* has the "CLASS" attribute */ - herr_t is_ds; /* boolean return value */ - char buf[20]; + hid_t tid; /* attribute type ID */ + hid_t aid; /* attribute ID */ + herr_t has_class; /* has the "CLASS" attribute */ + herr_t is_ds; /* boolean return value */ + H5I_type_t it; /* ID type */ + char buf[20]; + +/*------------------------------------------------------------------------- + * parameter checking + *------------------------------------------------------------------------- + */ + /* get ID type */ + if ((it = H5Iget_type(did))<0) + return FAIL; + + if (H5I_DATASET!=it) + return FAIL; + /* try to find the attribute "CLASS" on the dataset */ if ((has_class = H5LT_find_attribute(did,"CLASS"))<0) @@ -1276,12 +1379,24 @@ herr_t H5DSiterate_scales(hid_t did, 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 (H5DSget_nscales(did,dim,&nscales)<0) goto out; @@ -1372,4 +1487,3 @@ out: return FAIL; } - diff --git a/hl/src/H5DS.h b/hl/src/H5DS.h index 95886db..6089e67 100644 --- a/hl/src/H5DS.h +++ b/hl/src/H5DS.h @@ -40,9 +40,6 @@ typedef struct ds_list_t { extern "C" { #endif -herr_t H5DSset_scale(hid_t did, - char *dimname); - herr_t H5DSattach_scale(hid_t did, hid_t dsid, unsigned int idx); @@ -51,6 +48,9 @@ herr_t H5DSdetach_scale(hid_t did, hid_t dsid, unsigned int idx); +herr_t H5DSset_scale(hid_t did, + char *dimname); + herr_t H5DSget_nscales(hid_t did, unsigned int dim, int *nscales); @@ -66,10 +66,8 @@ herr_t H5DSget_label(hid_t did, herr_t H5DSget_scale_name(hid_t did, char *buf); - herr_t H5DSis_scale(hid_t did); - herr_t H5DSiterate_scales(hid_t did, unsigned int dim, int *idx, diff --git a/hl/test/test_ds.c b/hl/test/test_ds.c index 9290844..4197c60 100644 --- a/hl/test/test_ds.c +++ b/hl/test/test_ds.c @@ -849,6 +849,7 @@ static int test_simple(void) PASSED(); + /*------------------------------------------------------------------------- * end *------------------------------------------------------------------------- @@ -882,8 +883,9 @@ static int test_errors(void) int rankds = 1; /* rank of DS dataset */ hsize_t dims[RANK] = {DIM1_SIZE,DIM2_SIZE}; /* size of data dataset */ hsize_t s1_dim[1] = {DIM1_SIZE}; /* size of DS 1 dataset */ - hid_t dset; /* dataset ID */ - hid_t scale; /* scale ID */ + hsize_t s2_dim[1] = {DIM2_SIZE}; /* size of DS 2 dataset */ + hid_t did; /* dataset ID */ + hid_t dsid; /* scale ID */ hid_t gid; /* group ID */ hid_t sid; /* space ID */ hid_t sidds; @@ -907,21 +909,21 @@ static int test_errors(void) /* create the data space for the scale */ if ((sidds=H5Screate_simple(rankds,s1_dim,NULL))<0) goto out; - /* create a dataset */ - if ((dset=H5Dcreate(fid,"dset_1",H5T_NATIVE_INT,sid,H5P_DEFAULT))<0) + /* create a dataset */ + if ((did=H5Dcreate(fid,"dset_a",H5T_NATIVE_INT,sid,H5P_DEFAULT))<0) goto out; /* create a dataset for the scale */ - if ((scale=H5Dcreate(fid,"scale_1",H5T_NATIVE_INT,sidds,H5P_DEFAULT))<0) + if ((dsid=H5Dcreate(fid,"ds_a",H5T_NATIVE_INT,sidds,H5P_DEFAULT))<0) goto out; - /*------------------------------------------------------------------------- * attempt to attach a dataset to itself, it should fail *------------------------------------------------------------------------- */ + TESTING2("attach a dataset to itself"); - if (H5DSattach_scale(dset,dset,0)==SUCCESS) + if (H5DSattach_scale(did,did,0)==SUCCESS) goto out; PASSED(); @@ -932,7 +934,7 @@ static int test_errors(void) */ TESTING2("attach a group with a dataset"); - if (H5DSattach_scale(gid,scale,0)==SUCCESS) + if (H5DSattach_scale(gid,dsid,0)==SUCCESS) goto out; PASSED(); @@ -943,22 +945,31 @@ static int test_errors(void) */ TESTING2("attach a dataset with a group"); - if (H5DSattach_scale(dset,gid,0)==SUCCESS) + if (H5DSattach_scale(did,gid,0)==SUCCESS) goto out; PASSED(); +/*------------------------------------------------------------------------- + * attempt to set scale for a group, it should fail + *------------------------------------------------------------------------- + */ + TESTING2("set scale for a group"); + + if (H5DSset_scale(gid,"scale 1")==SUCCESS) + goto out; + PASSED(); /*------------------------------------------------------------------------- - * end + * close IDs for this set *------------------------------------------------------------------------- - */ + */ /* close */ - if (H5Dclose(scale)<0) + if (H5Dclose(dsid)<0) goto out; - if (H5Dclose(dset)<0) + if (H5Dclose(did)<0) goto out; if (H5Sclose(sid)<0) goto out; @@ -966,6 +977,105 @@ static int test_errors(void) goto out; if (H5Gclose(gid)<0) goto out; + + +/*------------------------------------------------------------------------- + * test 10: attach/detach scales + *------------------------------------------------------------------------- + */ + TESTING2("attach/detach scales"); + +/*------------------------------------------------------------------------- + * create 3 datasets: 1 "data" dataset and 2 dimension scales + *------------------------------------------------------------------------- + */ + if (H5LTmake_dataset_int(fid,"dset_b",rank,dims,NULL)<0) + goto out; + if (H5LTmake_dataset_int(fid,"ds_b_1",rankds,s1_dim,NULL)<0) + goto out; + if (H5LTmake_dataset_int(fid,"ds_b_2",rankds,s2_dim,NULL)<0) + goto out; + +/*------------------------------------------------------------------------- + * attach them + *------------------------------------------------------------------------- + */ + if ((did = H5Dopen(fid,"dset_b"))<0) + goto out; + + if ((dsid = H5Dopen(fid,"ds_b_1"))<0) + goto out; + if (H5DSattach_scale(did,dsid,0)<0) + goto out; + if (H5Dclose(dsid)<0) + goto out; + if ((dsid = H5Dopen(fid,"ds_b_2"))<0) + goto out; + if (H5DSattach_scale(did,dsid,1)<0) + goto out; + if (H5Dclose(dsid)<0) + goto out; + + if (H5Dclose(did)<0) + goto out; + +/*------------------------------------------------------------------------- + * attach/attach + *------------------------------------------------------------------------- + */ + + /* get the dataset id for "dset_b" */ + if ((did = H5Dopen(fid,"dset_b"))<0) + goto out; + + /* get the DS dataset id */ + if ((dsid = H5Dopen(fid,"ds_b_1"))<0) + goto out; + + /* attach "ds_b_1" again in DIM 0 */ + if (H5DSattach_scale(did,dsid,0)<0) + goto out; + + /* close DS id */ + if (H5Dclose(dsid)<0) + goto out; + + /* close dataset ID of "dset_b" */ + if (H5Dclose(did)<0) + goto out; + +/*------------------------------------------------------------------------- + * detach/detach + *------------------------------------------------------------------------- + */ + + /* get the dataset id for "dset_b" */ + if ((did = H5Dopen(fid,"dset_b"))<0) + goto out; + + /* get the DS dataset id */ + if ((dsid = H5Dopen(fid,"ds_b_2"))<0) + goto out; + + /* detach the "ds_b_2" dimension scale to "dset_b" in DIM 1 */ + if (H5DSdetach_scale(did,dsid,1)<0) + goto out; + + /* detach again, it should fail */ + if (H5DSdetach_scale(did,dsid,1)==SUCCESS) + goto out; + + /* close DS id */ + if (H5Dclose(dsid)<0) + goto out; + + /* close dataset ID of "dset_b" */ + if (H5Dclose(did)<0) + goto out; + + PASSED(); + + /* close */ if (H5Fclose(fid)<0) goto out; @@ -976,8 +1086,8 @@ out: H5E_BEGIN_TRY { H5Sclose(sid); H5Sclose(sidds); - H5Dclose(dset); - H5Dclose(scale); + H5Dclose(did); + H5Dclose(dsid); H5Gclose(gid); H5Fclose(fid); } H5E_END_TRY; |