diff options
Diffstat (limited to 'hl')
-rw-r--r-- | hl/src/H5DS.c | 141 | ||||
-rw-r--r-- | hl/src/H5DS.h | 10 | ||||
-rw-r--r-- | hl/test/test_ds.c | 673 |
3 files changed, 461 insertions, 363 deletions
diff --git a/hl/src/H5DS.c b/hl/src/H5DS.c index 232109f..5ad4b0c 100644 --- a/hl/src/H5DS.c +++ b/hl/src/H5DS.c @@ -558,9 +558,11 @@ herr_t H5DSdetach_scale(hid_t did, 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 */ + ds_list_t *dsbuf=NULL; /* array of attribute data in the DS pointing to the dataset */ + ds_list_t *dsbufn=NULL; /* array of attribute data in the DS pointing to the dataset */ + hsize_t *dims=NULL; /* dimension of the "REFERENCE_LIST" array */ hobj_ref_t ref; /* reference to the DS */ - hvl_t *buf; /* VL buffer to store in the attribute */ + hvl_t *buf=NULL; /* VL buffer to store in the attribute */ unsigned i, j, jj; H5G_stat_t sb1, sb2, sb3, sb4; int found_dset=0, found_ds=0; @@ -686,6 +688,11 @@ herr_t H5DSdetach_scale(hid_t did, buf[idx].len--; found_ds = 1; + + /* close the dereferenced dataset and break */ + if (H5Dclose(dsid_j)<0) + goto out; + break; } /* close the dereferenced dataset */ @@ -733,7 +740,6 @@ herr_t H5DSdetach_scale(hid_t did, goto out; dsbuf = malloc((size_t)nelmts * sizeof(ds_list_t)); - if (dsbuf == NULL) goto out; @@ -758,34 +764,106 @@ herr_t H5DSdetach_scale(hid_t did, goto out; /* same object, reset. we want to detach only for this DIM */ - if (sb3.fileno==sb4.fileno && sb3.objno==sb4.objno && (int)idx==dsbuf[i].dim_idx) { - dsbuf[i].ref=0; - dsbuf[i].dim_idx=-1; + if (sb3.fileno==sb4.fileno && sb3.objno==sb4.objno && (int)idx==dsbuf[i].dim_idx) + { + for(jj=i; jj<nelmts-1; jj++) + { + dsbuf[jj] = dsbuf[jj+1]; + } + nelmts--; found_dset=1; + + /* close the dereferenced dataset and break */ + if (H5Dclose(dsid_j)<0) + goto out; + break; } /* if */ /* close the dereferenced dataset */ if (H5Dclose(dsid_j)<0) goto out; + } /* i */ - - /* update on disk */ - if (H5Awrite(aid,tid,dsbuf)<0) + + /* close space and attribute */ + if (H5Sclose(sid)<0) + goto out; + if (H5Aclose(aid)<0) goto out; - /* close */ - if (H5Sclose(sid)<0) +/*------------------------------------------------------------------------- + * check if we found the pointed dataset + *------------------------------------------------------------------------- + */ + + /* the pointed dataset must exist */ + if (found_dset == 0) goto out; - if (H5Tclose(tid)<0) + +/*------------------------------------------------------------------------- + * create a new attribute + *------------------------------------------------------------------------- + */ + + /* the attribute must be deleted, in order to the new one can reflect the changes*/ + if (H5Adelete(dsid,REFERENCE_LIST)<0) goto out; - if (H5Aclose(aid)<0) + + /* don't do anything for an empty array */ + if (nelmts) + { + /* create a new data space for the new references array */ + dims = (hsize_t*) malloc ( (size_t)nelmts * sizeof (hsize_t)); + if (dims == NULL) + goto out; + dims[0] = nelmts; + + dsbufn = malloc((size_t)nelmts * sizeof(ds_list_t)); + if (dsbufn == NULL) + goto out; + + /* store the new information */ + for(i=0; i<nelmts; i++) + { + dsbufn[i] = dsbuf[i]; + } + + if ((sid = H5Screate_simple(1,dims,NULL))<0) + goto out; + + /* create the attribute again with the changes of space */ + if ((aid = H5Acreate(dsid,REFERENCE_LIST,tid,sid,H5P_DEFAULT))<0) + goto out; + + /* write the new attribute with the new references */ + if (H5Awrite(aid,tid,dsbufn)<0) + goto out; + + /* close space and attribute */ + if (H5Sclose(sid)<0) + goto out; + if (H5Aclose(aid)<0) + goto out; + + } /* nelmts */ + + /* close type */ + if (H5Tclose(tid)<0) goto out; - if (dsbuf) + + if (dsbuf) { free(dsbuf); + dsbuf=NULL; + } + if (dsbufn) { + free(dsbufn); + dsbufn=NULL; + } + if (dims) { + free(dims); + dims=NULL; + } - /* the pointed dataset must exist */ - if (found_dset == 0) - goto out; return SUCCESS; @@ -795,6 +873,12 @@ out: H5Sclose(sid); H5Aclose(aid); H5Tclose(tid); + if (dsbuf) + free(dsbuf); + if (dsbufn) + free(dsbufn); + if (dims) + free(dims); } H5E_END_TRY; return FAIL; @@ -1564,16 +1648,13 @@ out: *------------------------------------------------------------------------- */ -htri_t H5DS_is_attached(hid_t loc_id, - const char *dname, - const char *dsname, +htri_t H5DS_is_attached(hid_t did, + hid_t dsid, unsigned int idx) { int has_dimlist; int has_reflist; hssize_t nelmts; - hid_t did; /* dataset ID */ - hid_t dsid; /* scale dataset ID */ hid_t sid; /* space ID */ hid_t tid; /* attribute type ID */ hid_t aid; /* attribute ID */ @@ -1587,14 +1668,6 @@ htri_t H5DS_is_attached(hid_t loc_id, int i; int found_dset=0, found_ds=0; - /* get the dataset id */ - if ((did = H5Dopen(loc_id,dname))<0) - return FAIL; - - /* get the DS dataset id */ - if ((dsid = H5Dopen(loc_id,dsname))<0) - return FAIL; - /*------------------------------------------------------------------------- * parameter checking *------------------------------------------------------------------------- @@ -1803,14 +1876,6 @@ htri_t H5DS_is_attached(hid_t loc_id, if (dsbuf) free(dsbuf); } /* has_reflist */ - - /* close the dataset */ - if (H5Dclose(did)<0) - goto out; - - /* close the scale */ - if (H5Dclose(dsid)<0) - goto out; if (found_ds && found_dset) return 1; diff --git a/hl/src/H5DS.h b/hl/src/H5DS.h index b179a19..2bd57d9 100644 --- a/hl/src/H5DS.h +++ b/hl/src/H5DS.h @@ -74,14 +74,8 @@ herr_t H5DSiterate_scales(hid_t did, H5DS_iterate_t visitor, void *visitor_data); - -/*------------------------------------------------------------------------- - * private functions - *------------------------------------------------------------------------- - */ -htri_t H5DS_is_attached(hid_t loc_id, - const char *dname, - const char *dsname, +htri_t H5DS_is_attached(hid_t did, + hid_t dsid, unsigned int idx); diff --git a/hl/test/test_ds.c b/hl/test/test_ds.c index b591a2f..89c803b 100644 --- a/hl/test/test_ds.c +++ b/hl/test/test_ds.c @@ -22,6 +22,7 @@ static herr_t verifiy_scale(hid_t dset, unsigned dim, hid_t scale, void *visitor static herr_t read_scale(hid_t dset, unsigned dim, hid_t scale, void *visitor_data); static herr_t match_dim_scale(hid_t did, unsigned dim, hid_t dsid, void *visitor_data); + /* prototypes */ static int test_simple(void); static int test_errors(void); @@ -39,7 +40,6 @@ static int test_errors(void); * the main program *------------------------------------------------------------------------- */ -#if 1 int main(void) { int nerrors=0; @@ -87,6 +87,7 @@ static int test_simple(void) hsize_t s1_dim[1] = {DIM1_SIZE}; /* size of DS 1 dataset */ hsize_t s2_dim[1] = {DIM2_SIZE}; /* size of DS 2 dataset */ char sname[30]; /* scale name */ + char dname[30]; /* dataset name */ int s1_wbuf[DIM1_SIZE] = {10,20,30}; /* data of DS 1 dataset */ int s2_wbuf[DIM2_SIZE] = {100,200,300,400}; /* data of DS 2 dataset */ char s1_label[16]; /* read label for DS 1 */ @@ -94,6 +95,7 @@ static int test_simple(void) unsigned int dim; /* dataset dimension index */ int scale_idx; /* scale index */ int nscales; /* number of scales in DIM */ + int i, j; printf("Testing API functions\n"); @@ -212,51 +214,44 @@ static int test_simple(void) if (H5Dclose(dsid)<0) goto out; - /* close dataset ID of "dset_a" */ - if (H5Dclose(did)<0) - goto out; /*------------------------------------------------------------------------- - * verify if the dimension scales are valid + * verify attachment *------------------------------------------------------------------------- */ - if ((did = H5Dopen(fid,"ds_a_1"))<0) + if ((dsid = H5Dopen(fid,"ds_a_1"))<0) goto out; - if ((H5DSis_scale(did))<=0) + if (H5DS_is_attached(did,dsid,DIM0)<=0) goto out; - if (H5Dclose(did)) + if (H5Dclose(dsid)) goto out; - if ((did = H5Dopen(fid,"ds_a_2"))<0) + if ((dsid = H5Dopen(fid,"ds_a_2"))<0) goto out; - if ((H5DSis_scale(did))<=0) + if (H5DS_is_attached(did,dsid,DIM1)<=0) goto out; - if (H5Dclose(did)) + if (H5Dclose(dsid)) goto out; - if ((did = H5Dopen(fid,"ds_a_21"))<0) + if ((dsid = H5Dopen(fid,"ds_a_21"))<0) goto out; - if ((H5DSis_scale(did))<=0) + if (H5DS_is_attached(did,dsid,DIM1)<=0) goto out; - if (H5Dclose(did)) + if (H5Dclose(dsid)) goto out; - if ((did = H5Dopen(fid,"ds_a_22"))<0) + if ((dsid = H5Dopen(fid,"ds_a_22"))<0) goto out; - if ((H5DSis_scale(did))<=0) + if (H5DS_is_attached(did,dsid,DIM1)<=0) goto out; - if (H5Dclose(did)) + if (H5Dclose(dsid)) goto out; - if (H5DS_is_attached(fid,"dset_a","ds_a_1",DIM0)<=0) - goto out; - if (H5DS_is_attached(fid,"dset_a","ds_a_2",DIM1)<=0) - goto out; - if (H5DS_is_attached(fid,"dset_a","ds_a_21",DIM1)<=0) - goto out; - if (H5DS_is_attached(fid,"dset_a","ds_a_22",DIM1)<=0) + + /* close dataset ID of "dset_a" */ + if (H5Dclose(did)<0) goto out; @@ -353,7 +348,6 @@ static int test_simple(void) PASSED(); - /*------------------------------------------------------------------------- * test 3: detach scales *------------------------------------------------------------------------- @@ -568,8 +562,327 @@ static int test_simple(void) goto out; +/*------------------------------------------------------------------------- + * create 3 datasets: 1 "data" dataset and 2 dimension scales + *------------------------------------------------------------------------- + */ + if (H5LTmake_dataset_int(fid,"dset_d",rank,dims,NULL)<0) + goto out; + if (H5LTmake_dataset_int(fid,"ds_d_1",rankds,s1_dim,NULL)<0) + goto out; + if (H5LTmake_dataset_int(fid,"ds_d_2",rankds,s2_dim,NULL)<0) + goto out; + +/*------------------------------------------------------------------------- + * attach them + *------------------------------------------------------------------------- + */ + if ((did = H5Dopen(fid,"dset_d"))<0) + goto out; + + if ((dsid = H5Dopen(fid,"ds_d_1"))<0) + goto out; + if (H5DSattach_scale(did,dsid,0)<0) + goto out; + if (H5Dclose(dsid)<0) + goto out; + if ((dsid = H5Dopen(fid,"ds_d_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; + +/*------------------------------------------------------------------------- + * verify + *------------------------------------------------------------------------- + */ + + if ((did = H5Dopen(fid,"dset_d"))<0) + goto out; + + if ((dsid = H5Dopen(fid,"ds_d_1"))<0) + goto out; + if (H5DS_is_attached(did,dsid,DIM0)<=0) + goto out; + if (H5Dclose(dsid)<0) + goto out; + + if ((dsid = H5Dopen(fid,"ds_d_2"))<0) + goto out; + if (H5DS_is_attached(did,dsid,DIM1)<=0) + goto out; + if (H5Dclose(dsid)<0) + goto out; + + if (H5Dclose(did)<0) + goto out; + + +/*------------------------------------------------------------------------- + * detach + *------------------------------------------------------------------------- + */ + + /* get the dataset id for "dset_d" */ + if ((did = H5Dopen(fid,"dset_d"))<0) + goto out; + + /* get the DS dataset id */ + if ((dsid = H5Dopen(fid,"ds_d_1"))<0) + goto out; + + /* detach the dimension scale to "dset_d" in DIM 0 */ + if (H5DSdetach_scale(did,dsid,DIM0)<0) + goto out; + + /* verify attach, it must return 0 for no attach */ + if (H5DS_is_attached(did,dsid,DIM0)!=0) + goto out; + + /* close DS id */ + if (H5Dclose(dsid)<0) + goto out; + + /* close dataset ID of "dset_d" */ + if (H5Dclose(did)<0) + goto out; + +/*------------------------------------------------------------------------- + * attach again + *------------------------------------------------------------------------- + */ + + /* get the dataset id for "dset_d" */ + if ((did = H5Dopen(fid,"dset_d"))<0) + goto out; + + /* get the DS dataset id */ + if ((dsid = H5Dopen(fid,"ds_d_1"))<0) + goto out; + + /* attach "ds_d_1" again in DIM 0 */ + if (H5DSattach_scale(did,dsid,DIM0)<0) + goto out; + + /* verify attach, it must return 1 for attach */ + if (H5DS_is_attached(did,dsid,DIM0)!=1) + goto out; + + /* verify that "ds_d_1" has only 1 scale at DIM0 */ + if (H5DSget_nscales(did,DIM0,&nscales)<0) + goto out; + if (nscales!=1) + goto out; + + /* close DS id */ + if (H5Dclose(dsid)<0) + goto out; + + /* close dataset ID of "dset_d" */ + if (H5Dclose(did)<0) + goto out; + +/*------------------------------------------------------------------------- + * detach/detach + *------------------------------------------------------------------------- + */ + + /* get the dataset id for "dset_d" */ + if ((did = H5Dopen(fid,"dset_d"))<0) + goto out; + + /* get the DS dataset id */ + if ((dsid = H5Dopen(fid,"ds_d_2"))<0) + goto out; + + /* detach the "ds_d_2" dimension scale to "dset_d" in DIM 1 */ + if (H5DSdetach_scale(did,dsid,DIM1)<0) + goto out; + + /* detach again, it should fail */ + if (H5DSdetach_scale(did,dsid,DIM1)==SUCCESS) + goto out; + + /* verify attach, it must return 0 for no attach */ + if (H5DS_is_attached(did,dsid,DIM1)!=0) + goto out; + + /* verify that "ds_d_1" has no scale at DIM1 */ + if (H5DSget_nscales(did,DIM1,&nscales)<0) + goto out; + if (nscales!=0) + goto out; + + /* close DS id */ + if (H5Dclose(dsid)<0) + goto out; + + /* close dataset ID of "dset_d" */ + if (H5Dclose(did)<0) + goto out; + +/*------------------------------------------------------------------------- + * attach twice + *------------------------------------------------------------------------- + */ + + /* get the dataset id for "dset_d" */ + if ((did = H5Dopen(fid,"dset_d"))<0) + goto out; + + /* get the DS dataset id */ + if ((dsid = H5Dopen(fid,"ds_d_2"))<0) + goto out; + + /* attach "ds_d_2" in DIM 1 */ + if (H5DSattach_scale(did,dsid,DIM1)<0) + goto out; + + /* verify attach, it must return 1 for attach */ + if (H5DS_is_attached(did,dsid,DIM1)!=1) + goto out; + + /* verify that "ds_d_2" has only 1 scale at DIM1 */ + if (H5DSget_nscales(did,DIM0,&nscales)<0) + goto out; + if (nscales!=1) + goto out; + + /* attach "ds_d_2" again in DIM 1 */ + if (H5DSattach_scale(did,dsid,DIM1)<0) + goto out; + + /* verify attach, it must return 1 for attach */ + if (H5DS_is_attached(did,dsid,DIM1)!=1) + goto out; + + /* verify that "ds_d_2" has only 1 scale at DIM1 */ + if (H5DSget_nscales(did,DIM0,&nscales)<0) + goto out; + if (nscales!=1) + goto out; + + /* close DS id */ + if (H5Dclose(dsid)<0) + goto out; + + /* close dataset ID of "dset_d" */ + if (H5Dclose(did)<0) + goto out; + + +/*------------------------------------------------------------------------- + * create 10 datasets: 5 "data" dataset and 5 dimension scales + *------------------------------------------------------------------------- + */ + + /* create the data space for the dataset */ + if ((sid=H5Screate_simple(rank,dims,NULL))<0) + goto out; + + for (i=0; i<5; i++) + { + sprintf(dname,"dset_%d",i); + if ((did = H5Dcreate(fid,dname,H5T_NATIVE_INT,sid,H5P_DEFAULT))<0) + goto out; + sprintf(sname,"ds_%d",i); + if((dsid = H5Dcreate(fid,sname,H5T_NATIVE_INT,sid,H5P_DEFAULT))<0) + goto out; + if(H5DSset_scale(dsid,"scale")<0) + goto out; + if (H5Dclose(dsid)<0) + goto out; + if (H5Dclose(did)<0) + goto out; + } + +/*------------------------------------------------------------------------- + * attach + *------------------------------------------------------------------------- + */ + + for (i=0; i<5; i++) + { + sprintf(dname,"dset_%d",i); + if ((did = H5Dopen(fid,dname))<0) + goto out; + for (j=0; j<5; j++) + { + sprintf(sname,"ds_%d",j); + if((dsid = H5Dopen(fid,sname))<0) + goto out; + if(H5DSattach_scale(did,dsid,DIM0)<0) + goto out; + if (H5Dclose(dsid)<0) + goto out; + } + if (H5Dclose(did)<0) + goto out; + } + +/*------------------------------------------------------------------------- + * dettach + *------------------------------------------------------------------------- + */ + + for (i=0; i<5; i++) + { + sprintf(dname,"dset_%d",i); + if ((did = H5Dopen(fid,dname))<0) + goto out; + for (j=0; j<5; j++) + { + sprintf(sname,"ds_%d",j); + if((dsid = H5Dopen(fid,sname))<0) + goto out; + if(H5DSdetach_scale(did,dsid,DIM0)<0) + goto out; + if (H5Dclose(dsid)<0) + goto out; + } + if (H5Dclose(did)<0) + goto out; + } + + +/*------------------------------------------------------------------------- + * attach again + *------------------------------------------------------------------------- + */ + + for (i=0; i<5; i++) + { + sprintf(dname,"dset_%d",i); + if ((did = H5Dopen(fid,dname))<0) + goto out; + for (j=0; j<5; j++) + { + sprintf(sname,"ds_%d",j); + if((dsid = H5Dopen(fid,sname))<0) + goto out; + if(H5DSattach_scale(did,dsid,DIM0)<0) + goto out; + if (H5Dclose(dsid)<0) + goto out; + } + if (H5Dclose(did)<0) + goto out; + } + + /* close */ + if (H5Sclose(sid)<0) + goto out; + + PASSED(); + + + /*------------------------------------------------------------------------- * test 4: set/get label *------------------------------------------------------------------------- @@ -611,19 +924,19 @@ static int test_simple(void) TESTING2("set scale/get scale name"); /*------------------------------------------------------------------------- - * make a dataset named "ds_1" and convert it to a DS dataset + * make a dataset named "scale_1" and convert it to a DS dataset *------------------------------------------------------------------------- */ - if (H5LTmake_dataset_int(fid,"ds_1",rankds,s1_dim,s1_wbuf)<0) + if (H5LTmake_dataset_int(fid,"scale_1",rankds,s1_dim,s1_wbuf)<0) goto out; - if ((did = H5Dopen(fid,"ds_1"))<0) + if ((did = H5Dopen(fid,"scale_1"))<0) goto out; if (H5DSset_scale(did,"scale 1")<0) goto out; - /* verify that "ds5_1" is a dimension scale dataset */ + /* verify that "scale_1" is a dimension scale dataset */ if ((H5DSis_scale(did))==0) goto out; @@ -766,37 +1079,37 @@ static int test_simple(void) * create 3 datasets: 1 "data" dataset and dimension scales (some are empty) *------------------------------------------------------------------------- */ - if (H5LTmake_dataset_int(fid,"dset_d",rank,dims,buf)<0) + if (H5LTmake_dataset_int(fid,"dset_e",rank,dims,buf)<0) goto out; - if (H5LTmake_dataset_int(fid,"ds_d_1",rankds,s1_dim,NULL)<0) + if (H5LTmake_dataset_int(fid,"ds_e_1",rankds,s1_dim,NULL)<0) goto out; - if (H5LTmake_dataset_int(fid,"ds_d_11",rankds,s1_dim,s1_wbuf)<0) + if (H5LTmake_dataset_int(fid,"ds_e_11",rankds,s1_dim,s1_wbuf)<0) goto out; - if (H5LTmake_dataset_int(fid,"ds_d_2",rankds,s2_dim,NULL)<0) + if (H5LTmake_dataset_int(fid,"ds_e_2",rankds,s2_dim,NULL)<0) goto out; /*------------------------------------------------------------------------- * attach them *------------------------------------------------------------------------- */ - if ((did = H5Dopen(fid,"dset_d"))<0) + if ((did = H5Dopen(fid,"dset_e"))<0) goto out; - if ((dsid = H5Dopen(fid,"ds_d_1"))<0) + if ((dsid = H5Dopen(fid,"ds_e_1"))<0) goto out; - if (H5DSattach_scale(did,dsid,0)<0) + if (H5DSattach_scale(did,dsid,DIM0)<0) goto out; if (H5Dclose(dsid)<0) goto out; - if ((dsid = H5Dopen(fid,"ds_d_11"))<0) + if ((dsid = H5Dopen(fid,"ds_e_11"))<0) goto out; - if (H5DSattach_scale(did,dsid,0)<0) + if (H5DSattach_scale(did,dsid,DIM0)<0) goto out; if (H5Dclose(dsid)<0) goto out; - if ((dsid = H5Dopen(fid,"ds_d_2"))<0) + if ((dsid = H5Dopen(fid,"ds_e_2"))<0) goto out; - if (H5DSattach_scale(did,dsid,1)<0) + if (H5DSattach_scale(did,dsid,DIM1)<0) goto out; if (H5Dclose(dsid)<0) goto out; @@ -808,8 +1121,8 @@ static int test_simple(void) * verify match *------------------------------------------------------------------------- */ - /* get the dataset id for "dset_d" */ - if ((did = H5Dopen(fid,"dset_d"))<0) + /* get the dataset id for "dset_e" */ + if ((did = H5Dopen(fid,"dset_e"))<0) goto out; /* get dataset space */ @@ -837,7 +1150,7 @@ static int test_simple(void) if ((match_size=H5DSiterate_scales(did,dim,&idx,match_dim_scale,NULL))<0) goto out; - /* "dset_d" was defined with : + /* "dset_e" was defined with : dim 0: 2 scales, first is empty dim 1: 1 scale, empty */ switch(dim) @@ -901,7 +1214,6 @@ static int test_errors(void) hid_t gid; /* group ID */ hid_t sid; /* space ID */ hid_t sidds; /* space ID */ - int nscales; /* number of scales in DIM IDX */ printf("Testing error conditions\n"); @@ -991,209 +1303,7 @@ static int test_errors(void) 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; - - /* verify attach */ - if (H5DS_is_attached(fid,"dset_b","ds_b_1",DIM0)<=0) - goto out; - if (H5DS_is_attached(fid,"dset_b","ds_b_2",DIM1)<=0) - goto out; - - -/*------------------------------------------------------------------------- - * 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_1"))<0) - goto out; - - /* detach the dimension scale to "dset_b" in DIM 0 */ - if (H5DSdetach_scale(did,dsid,DIM0)<0) - goto out; - - /* verify attach, it must return 0 for no attach */ - if (H5DS_is_attached(fid,"dset_b","ds_b_1",DIM0)!=0) - goto out; - - /* close DS id */ - if (H5Dclose(dsid)<0) - goto out; - - /* close dataset ID of "dset_b" */ - if (H5Dclose(did)<0) - goto out; - -/*------------------------------------------------------------------------- - * attach again - *------------------------------------------------------------------------- - */ - - /* 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,DIM0)<0) - goto out; - - /* verify attach, it must return 1 for attach */ - if (H5DS_is_attached(fid,"dset_b","ds_b_1",DIM0)!=1) - goto out; - - /* verify that "ds_b_1" has only 1 scale at DIM0 */ - if (H5DSget_nscales(did,DIM0,&nscales)<0) - goto out; - if (nscales!=1) - 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,DIM1)<0) - goto out; - - /* detach again, it should fail */ - if (H5DSdetach_scale(did,dsid,DIM1)==SUCCESS) - goto out; - - /* verify attach, it must return 0 for no attach */ - if (H5DS_is_attached(fid,"dset_b","ds_b_2",DIM1)!=0) - goto out; - - /* verify that "ds_b_1" has no scale at DIM1 */ - if (H5DSget_nscales(did,DIM1,&nscales)<0) - goto out; - if (nscales!=0) - goto out; - - /* close DS id */ - if (H5Dclose(dsid)<0) - goto out; - - /* close dataset ID of "dset_b" */ - if (H5Dclose(did)<0) - goto out; - -/*------------------------------------------------------------------------- - * attach twice - *------------------------------------------------------------------------- - */ - - /* 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; - - /* attach "ds_b_2" in DIM 1 */ - if (H5DSattach_scale(did,dsid,DIM1)<0) - goto out; - - /* verify attach, it must return 1 for attach */ - if (H5DS_is_attached(fid,"dset_b","ds_b_2",DIM1)!=1) - goto out; - - /* verify that "ds_b_2" has only 1 scale at DIM1 */ - if (H5DSget_nscales(did,DIM0,&nscales)<0) - goto out; - if (nscales!=1) - goto out; - - /* attach "ds_b_2" again in DIM 1 */ - if (H5DSattach_scale(did,dsid,DIM1)<0) - goto out; - - /* verify attach, it must return 1 for attach */ - if (H5DS_is_attached(fid,"dset_b","ds_b_2",DIM1)!=1) - goto out; - - /* verify that "ds_b_2" has only 1 scale at DIM1 */ - if (H5DSget_nscales(did,DIM0,&nscales)<0) - goto out; - if (nscales!=1) - 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) @@ -1436,74 +1546,3 @@ out: return FAIL; } - -#else - - - -#include "hdf5.h" - -#define H5FILE_NAME "SDS.h5" -#define DATASETNAME "IntArray" -#define DIMNAME "Dim1" -#define NX 5 /* dataset dimensions */ -#define NY 6 -#define RANK 2 - -int -main (void) -{ - hid_t file, dataset; /* file and dataset handles */ - hid_t datatype, dataspace; /* handles */ - hid_t scale; - hid_t grp; - hsize_t dimsf[2]; /* dataset dimensions */ - herr_t status; - int data[NX][NY]; /* data to write */ - int i, j; - - /* - * Data and output buffer initialization. - */ - for (j = 0; j < NX; j++) { - for (i = 0; i < NY; i++) - data[j][i] = i + j; - } - file = H5Fcreate(H5FILE_NAME, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT); - - dimsf[0] = NX; - dimsf[1] = NY; - dataspace = H5Screate_simple(RANK, dimsf, NULL); - - dataset = H5Dcreate(file, DATASETNAME, H5T_NATIVE_INT, dataspace, - H5P_DEFAULT); - - status = H5Dwrite(dataset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, - H5P_DEFAULT, data); - - scale = H5Dcreate(file, DIMNAME, H5T_NATIVE_INT, dataspace, - H5P_DEFAULT); - - grp = H5Gcreate(file, "/Data", 0); - - status = H5DSset_scale(scale,"foo"); - printf("set scale returns: %d\n", status); - - status = H5DSattach_scale(dataset,scale,0); - printf("attach scale returns: %d\n", status); - status = H5DSattach_scale(dataset,scale,1); - printf("attach scale returns: %d\n", status); - status = H5DSdetach_scale(dataset,scale,0); - printf("detach scale returns: %d\n", status); - - H5Sclose(dataspace); - H5Dclose(dataset); - H5Dclose(scale); - H5Fclose(file); - - return 0; -} - - - -#endif
\ No newline at end of file |