From 5352cb3f539647b2bd57d61ee8daf4087bd2ac0b Mon Sep 17 00:00:00 2001 From: Pedro Vicente Nunes Date: Fri, 18 Feb 2005 14:40:12 -0500 Subject: [svn-r10043] Purpose: new features/tests Description: add a couple more tests for the attach/detach pair of functions together with a verify function for it (used only for test purposes) avoided addind the same scale twice to a dimension all seems to be working very well Solution: Platforms tested: linux solaris Misc. update: --- hl/src/H5DS.c | 377 ++++++++++++++++++++++++++++++++++++++++++++++++++---- hl/src/H5DS.h | 10 ++ hl/test/test_ds.c | 208 ++++++++++++++++++++++++++++-- 3 files changed, 565 insertions(+), 30 deletions(-) diff --git a/hl/src/H5DS.c b/hl/src/H5DS.c index ba410ec..232109f 100644 --- a/hl/src/H5DS.c +++ b/hl/src/H5DS.c @@ -118,11 +118,14 @@ herr_t H5DSattach_scale(hid_t did, hsize_t *dims; /* dimension of the "REFERENCE_LIST" array */ ds_list_t dsl; /* attribute data in the DS pointing to the dataset */ ds_list_t *dsbuf; /* array of attribute data in the DS pointing to the dataset */ - hobj_ref_t ref; /* reference to the DS */ + hobj_ref_t ref_to_ds; /* reference to the DS */ + hobj_ref_t ref_j; /* iterator reference */ hvl_t *buf; /* VL buffer to store in the attribute */ + hid_t dsid_j; /* DS dataset ID in DIMENSION_LIST */ H5G_stat_t sb1, sb2; H5I_type_t it1, it2; int i, len; + int found_ds=0; /*------------------------------------------------------------------------- * parameter checking @@ -183,7 +186,7 @@ herr_t H5DSattach_scale(hid_t did, *------------------------------------------------------------------------- */ /* create a reference for the >>DS<< dataset */ - if (H5Rcreate(&ref,dsid,".",H5R_OBJECT,-1)<0) + if (H5Rcreate(&ref_to_ds,dsid,".",H5R_OBJECT,-1)<0) goto out; /* create a reference for the >>data<< dataset */ @@ -235,7 +238,7 @@ herr_t H5DSattach_scale(hid_t did, /* store the REF information in the index of the dataset that has the DS */ buf[idx].len = 1; buf[idx].p = malloc( 1 * sizeof(hobj_ref_t)); - ((hobj_ref_t *)buf[idx].p)[0] = ref; + ((hobj_ref_t *)buf[idx].p)[0] = ref_to_ds; /* write the attribute with the reference */ if (H5Awrite(aid,tid,buf)<0) @@ -285,20 +288,53 @@ herr_t H5DSattach_scale(hid_t did, if (H5Aread(aid,tid,buf)<0) goto out; - /* we are adding one more DS to this dimension */ - if ( buf[idx].len > 0 ) + /* check to avoid inserting duplicates. it is not FAIL, just do nothing */ + /* iterate all the REFs in this dimension IDX */ + for (i=0; i<(int)buf[idx].len; i++) { - buf[idx].len++; - len = buf[idx].len; - buf[idx].p = realloc( buf[idx].p, len * sizeof(hobj_ref_t)); - ((hobj_ref_t *)buf[idx].p)[ len-1 ] = ref; + /* get the reference */ + ref_j = ((hobj_ref_t *)buf[idx].p)[i]; + + /* get the scale id for this REF */ + if ((dsid_j = H5Rdereference(did,H5R_OBJECT,&ref_j))<0) + goto out; + + /* get info for DS in the parameter list */ + if (H5Gget_objinfo(dsid,".",TRUE,&sb1)<0) + goto out; + + /* get info for this DS */ + if (H5Gget_objinfo(dsid_j,".",TRUE,&sb2)<0) + goto out; + + /* same object, so this DS scale is already in this DIM IDX */ + if (sb1.fileno==sb2.fileno && sb1.objno==sb2.objno) + { + found_ds = 1; + } + + /* close the dereferenced dataset */ + if (H5Dclose(dsid_j)<0) + goto out; } - else + + if (found_ds==0) { - /* store the REF information in the index of the dataset that has the DS */ - buf[idx].len = 1; - buf[idx].p = malloc( 1 * sizeof(hobj_ref_t)); - ((hobj_ref_t *)buf[idx].p)[0] = ref; + /* we are adding one more DS to this dimension */ + if ( buf[idx].len > 0 ) + { + buf[idx].len++; + len = buf[idx].len; + buf[idx].p = realloc( buf[idx].p, len * sizeof(hobj_ref_t)); + ((hobj_ref_t *)buf[idx].p)[ len-1 ] = ref_to_ds; + } + else + { + /* store the REF information in the index of the dataset that has the DS */ + buf[idx].len = 1; + buf[idx].p = malloc( 1 * sizeof(hobj_ref_t)); + ((hobj_ref_t *)buf[idx].p)[0] = ref_to_ds; + } } /* write the attribute with the new references */ @@ -461,7 +497,7 @@ herr_t H5DSattach_scale(hid_t did, if (dsbuf) free(dsbuf); - } /* has_dimlist */ + } /* has_reflist */ /*------------------------------------------------------------------------- * write the standard attributes for a Dimension Scale dataset @@ -623,7 +659,7 @@ herr_t H5DSdetach_scale(hid_t did, /* reset */ if ( buf[idx].len > 0 ) { - for(j=0; j(unsigned)rank-1) + 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; + +/*------------------------------------------------------------------------- + * open "DIMENSION_LIST" + *------------------------------------------------------------------------- + */ + + 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; + + /* iterate all the REFs in this dimension IDX */ + for (i=0; i<(int)buf[idx].len; i++) + { + /* get the reference */ + ref = ((hobj_ref_t *)buf[idx].p)[i]; + + /* get the scale id for this REF */ + if ((dsid_j = H5Rdereference(did,H5R_OBJECT,&ref))<0) + goto out; + + /* get info for DS in the parameter list */ + if (H5Gget_objinfo(dsid,".",TRUE,&sb1)<0) + goto out; + + /* get info for this DS */ + if (H5Gget_objinfo(dsid_j,".",TRUE,&sb2)<0) + goto out; + + /* same object */ + if (sb1.fileno==sb2.fileno && sb1.objno==sb2.objno) + { + found_ds = 1; + } + + /* close the dereferenced dataset */ + if (H5Dclose(dsid_j)<0) + goto out; + + } + + + /* 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 */ + +/*------------------------------------------------------------------------- + * info on the >>DS<< dataset + *------------------------------------------------------------------------- + */ + + /* try to find the attribute "REFERENCE_LIST" on the >>DS<< dataset */ + if ((has_reflist = H5LT_find_attribute(dsid,REFERENCE_LIST))<0) + goto out; + +/*------------------------------------------------------------------------- + * open "REFERENCE_LIST" + *------------------------------------------------------------------------- + */ + + if ( has_reflist == 1 ) + { + if ((aid = H5Aopen_name(dsid,REFERENCE_LIST))<0) + goto out; + + if ((tid = H5Aget_type(aid))<0) + goto out; + + /* get and save the old reference(s) */ + if ((sid = H5Aget_space(aid))<0) + goto out; + + if ((nelmts = H5Sget_simple_extent_npoints(sid))<0) + goto out; + + dsbuf = malloc((size_t)nelmts * sizeof(ds_list_t)); + + if (dsbuf == NULL) + goto out; + + if (H5Aread(aid,tid,dsbuf)<0) + goto out; + +/*------------------------------------------------------------------------- + * iterate + *------------------------------------------------------------------------- + */ + + for(i=0; i