summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--hl/src/H5DS.c288
-rw-r--r--hl/src/H5LT.h1
-rw-r--r--hl/test/test_ds.c164
-rw-r--r--hl/test/test_table.c1
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<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
diff --git a/hl/src/H5LT.h b/hl/src/H5LT.h
index bdf7f8f..3380888 100644
--- a/hl/src/H5LT.h
+++ b/hl/src/H5LT.h
@@ -27,6 +27,7 @@
#endif
#define TESTING(WHAT) {printf("%-70s", "Testing " WHAT); fflush(stdout);}
+#define TESTING2(WHAT) {printf("%-70s", "Testing " WHAT); fflush(stdout);}
#define PASSED() {puts(" PASSED");fflush(stdout);}
#define H5_FAILED() {puts("*FAILED*");fflush(stdout);}
#define SKIPPED() {puts(" -SKIP-");fflush(stdout);}
diff --git a/hl/test/test_ds.c b/hl/test/test_ds.c
index 64f8cff..556f00a 100644
--- a/hl/test/test_ds.c
+++ b/hl/test/test_ds.c
@@ -20,8 +20,37 @@
/* operator functions */
static herr_t verifiy_scale(hid_t dset, unsigned dim, hid_t scale, void *visitor_data);
static herr_t read_scale(hid_t dset, unsigned dim, hid_t scale, void *visitor_data);
+/* prototypes */
+static int test_simple();
+static int test_errors();
+#define RANK 2
+#define DIM_DATA 12
+#define DIM1_SIZE 3
+#define DIM2_SIZE 4
+
+/*-------------------------------------------------------------------------
+ * the main program
+ *-------------------------------------------------------------------------
+ */
+
+int main(void)
+{
+ int nerrors=0;
+
+ nerrors += test_simple()<0 ?1:0;
+ nerrors += test_errors()<0 ?1:0;
+
+ if (nerrors) goto error;
+ printf("All dimension scales tests passed.\n");
+ return 0;
+
+error:
+ printf("***** %d DIMENSION SCALES TEST%s FAILED! *****\n",nerrors, 1 == nerrors ? "" : "S");
+ return 1;
+}
+
/*-------------------------------------------------------------------------
* DS API test
@@ -29,21 +58,18 @@ static herr_t read_scale(hid_t dset, unsigned dim, hid_t scale, void *visitor_da
* Functions tested:
*
* H5DSattach_scale
+ * H5DSdetach_scale
+ * H5DSset_label
+ * H5DSget_label
+ * H5DSset_scale
+ * H5DSget_scale_name
+ * H5DSis_scale
*
*-------------------------------------------------------------------------
*/
-#define RANK 2
-#define DIM_DATA 12
-#define DIM1_SIZE 3
-#define DIM2_SIZE 4
-
-/*-------------------------------------------------------------------------
- * the main program
- *-------------------------------------------------------------------------
- */
-int main(void)
+static int test_simple()
{
hid_t fid; /* file ID */
hid_t did; /* dataset ID */
@@ -60,15 +86,18 @@ int main(void)
char s1_label[16]; /* read label for DS 1 */
char s2_label[16]; /* read label for DS 2 */
unsigned int dim; /* dataset dimension index */
- int scale_idx; /* scale index */
-
+ int scale_idx;
+
+
+ printf("Testing API functions\n");
+
/*-------------------------------------------------------------------------
* create a file for the test
*-------------------------------------------------------------------------
*/
/* create a file using default properties */
- if ((fid=H5Fcreate("test_ds.h5",H5F_ACC_TRUNC,H5P_DEFAULT,H5P_DEFAULT))<0)
+ if ((fid=H5Fcreate("test_ds1.h5",H5F_ACC_TRUNC,H5P_DEFAULT,H5P_DEFAULT))<0)
goto out;
/*-------------------------------------------------------------------------
@@ -106,7 +135,7 @@ int main(void)
*-------------------------------------------------------------------------
*/
- TESTING("attach scales");
+ TESTING2("attach scales");
/* get the dataset id for "dset_a" */
if ((did = H5Dopen(fid,"dset_a"))<0)
@@ -252,7 +281,7 @@ int main(void)
*-------------------------------------------------------------------------
*/
- TESTING("has scales");
+ TESTING2("has scales");
/*-------------------------------------------------------------------------
* verify that "dset_a" has dimension scales
@@ -298,7 +327,7 @@ int main(void)
*-------------------------------------------------------------------------
*/
- TESTING("detach scales ");
+ TESTING2("detach scales ");
/*-------------------------------------------------------------------------
@@ -396,7 +425,7 @@ int main(void)
*-------------------------------------------------------------------------
*/
- TESTING("set/get label");
+ TESTING2("set/get label");
if ((did = H5Dopen(fid,"dset_a"))<0)
goto out;
@@ -429,7 +458,7 @@ int main(void)
*/
- TESTING("set scale/get scale name");
+ TESTING2("set scale/get scale name");
/*-------------------------------------------------------------------------
* make a dataset named "ds5" and convert it to a DS dataset
@@ -468,7 +497,7 @@ int main(void)
* test 6: test iterate scales with a function verifiy_scale
*-------------------------------------------------------------------------
*/
- TESTING("iterate scales");
+ TESTING2("iterate scales");
/* get the dataset id for "dset_a" */
if ((did = H5Dopen(fid,"dset_a"))<0)
@@ -499,7 +528,7 @@ int main(void)
* test 6: test iterate scales with a function read_scale
*-------------------------------------------------------------------------
*/
- TESTING("read scale values with iterate scales");
+ TESTING2("read scale values with iterate scales");
/* get the dataset id for "dset_a" */
if ((did = H5Dopen(fid,"dset_a"))<0)
@@ -525,7 +554,6 @@ int main(void)
PASSED();
-
/*-------------------------------------------------------------------------
* end
*-------------------------------------------------------------------------
@@ -543,10 +571,102 @@ out:
H5Fclose(fid);
} H5E_END_TRY;
H5_FAILED();
- return 1;
+ return FAIL;
}
+/*-------------------------------------------------------------------------
+ * test error conditions
+ *-------------------------------------------------------------------------
+ */
+
+static int test_errors()
+{
+ hid_t fid; /* file ID */
+ int rank = RANK; /* rank of data dataset */
+ int rankds = 1; /* rank of DS dataset */
+ hsize_t dims[RANK] = {DIM1_SIZE,DIM2_SIZE}; /* size of data dataset */
+ int buf[DIM_DATA] = {1,2,3,4,5,6,7,8,9,10,11,12}; /* data of data dataset */
+ hsize_t s1_dim[1] = {DIM1_SIZE}; /* size of DS 1 dataset */
+ hsize_t s2_dim[1] = {DIM2_SIZE}; /* size of DS 2 dataset */
+ hid_t dset; /* dataset ID */
+ hid_t scale; /* scale ID */
+ hid_t gid; /* group ID */
+ hid_t sid; /* space ID */
+ hid_t sidds;
+
+ printf("Testing error conditions\n");
+
+/*-------------------------------------------------------------------------
+ * create a file for the test
+ *-------------------------------------------------------------------------
+ */
+
+ /* create a file using default properties */
+ if ((fid=H5Fcreate("test_ds2.h5",H5F_ACC_TRUNC,H5P_DEFAULT,H5P_DEFAULT))<0)
+ goto out;
+
+/*-------------------------------------------------------------------------
+ * attempt to attach the dataset with the dataset
+ *-------------------------------------------------------------------------
+ */
+ TESTING2("attach a dataset to itself");
+
+ /* create the data space for the dataset. */
+ if ((sid=H5Screate_simple(rank,dims,NULL))<0)
+ goto out;
+ 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)
+ goto out;
+
+ /* create a dataset. */
+ if ((scale=H5Dcreate(fid,"scale_1",H5T_NATIVE_INT,sidds,H5P_DEFAULT))<0)
+ goto out;
+
+ /* attempt to attach the dataset with the dataset, it should fail */
+ if (H5DSattach_scale(dset,dset,0)==SUCCESS)
+ goto out;
+
+
+
+ if (H5Dclose(scale)<0)
+ goto out;
+ if (H5Dclose(dset)<0)
+ goto out;
+ if (H5Sclose(sid)<0)
+ goto out;
+ if (H5Sclose(sidds)<0)
+ goto out;
+
+ PASSED();
+
+
+
+/*-------------------------------------------------------------------------
+ * end
+ *-------------------------------------------------------------------------
+ */
+
+ /* close */
+ H5Fclose(fid);
+
+ return 0;
+
+ /* error zone, gracefully close */
+out:
+ H5E_BEGIN_TRY {
+ H5Sclose(sid);
+ H5Sclose(sidds);
+ H5Dclose(dset);
+ H5Dclose(scale);
+ H5Fclose(fid);
+ } H5E_END_TRY;
+ H5_FAILED();
+ return FAIL;
+}
/*-------------------------------------------------------------------------
diff --git a/hl/test/test_table.c b/hl/test/test_table.c
index 578ad59..82c6d91 100644
--- a/hl/test/test_table.c
+++ b/hl/test/test_table.c
@@ -50,7 +50,6 @@
#define TITLE "Title"
#define NFIELDS (hsize_t)5
#define NRECORDS (hsize_t)8
-#define TESTING2(WHAT) {printf("%-70s", "Testing " WHAT); fflush(stdout);}
/*-------------------------------------------------------------------------
* structure used for all tests, a particle with properties