summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--test/tselect.c138
1 files changed, 135 insertions, 3 deletions
diff --git a/test/tselect.c b/test/tselect.c
index ce2c936..a488e7a 100644
--- a/test/tselect.c
+++ b/test/tselect.c
@@ -238,7 +238,7 @@ test_select_point(void)
coord1[7][0]=1; coord1[7][1]= 0; coord1[7][2]= 4;
coord1[8][0]=2; coord1[8][1]= 1; coord1[8][2]= 6;
coord1[9][0]=0; coord1[9][1]= 3; coord1[9][2]= 8;
- ret = H5Sselect_elements(sid1,H5S_SELECT_SET,POINT1_NPOINTS,coord1);
+ ret = H5Sselect_elements(sid1,H5S_SELECT_SET,POINT1_NPOINTS,(const hssize_t **)coord1);
CHECK(ret, FAIL, "H5Sselect_elements");
/* Select sequence of ten points for write dataset */
@@ -252,7 +252,7 @@ test_select_point(void)
coord2[7][0]=29; coord2[7][1]= 4;
coord2[8][0]= 8; coord2[8][1]= 8;
coord2[9][0]=19; coord2[9][1]=17;
- ret = H5Sselect_elements(sid2,H5S_SELECT_SET,POINT1_NPOINTS,coord2);
+ ret = H5Sselect_elements(sid2,H5S_SELECT_SET,POINT1_NPOINTS,(const hssize_t **)coord2);
CHECK(ret, FAIL, "H5Sselect_elements");
/* Create a dataset */
@@ -281,7 +281,7 @@ test_select_point(void)
coord3[7][0]= 1; coord3[7][1]=22;
coord3[8][0]=12; coord3[8][1]=21;
coord3[9][0]=11; coord3[9][1]= 6;
- ret = H5Sselect_elements(sid2,H5S_SELECT_SET,POINT1_NPOINTS,coord3);
+ ret = H5Sselect_elements(sid2,H5S_SELECT_SET,POINT1_NPOINTS,(const hssize_t **)coord3);
CHECK(ret, FAIL, "H5Sselect_elements");
/* Read selection from disk */
@@ -320,6 +320,137 @@ test_select_point(void)
/****************************************************************
**
+** test_select_combo(): Test basic H5S (dataspace) selection code.
+** Tests combinations of element and hyperslab selections between
+** dataspaces of various sizes and dimensionalities.
+**
+****************************************************************/
+static void
+test_select_combo(void)
+{
+ hid_t fid1; /* HDF5 File IDs */
+ hid_t dataset; /* Dataset ID */
+ hid_t sid1,sid2; /* Dataspace ID */
+ hsize_t dims1[] = {SPACE1_DIM1, SPACE1_DIM2, SPACE1_DIM3};
+ hsize_t dims2[] = {SPACE2_DIM1, SPACE2_DIM2};
+ hsize_t dims3[] = {SPACE3_DIM1, SPACE3_DIM2};
+ hssize_t coord1[POINT1_NPOINTS][SPACE1_RANK]; /* Coordinates for point selection */
+ hsize_t start[SPACE1_RANK]; /* Starting location of hyperslab */
+ hsize_t stride[SPACE1_RANK]; /* Stride of hyperslab */
+ hsize_t count[SPACE1_RANK]; /* Element count of hyperslab */
+ hsize_t block[SPACE1_RANK]; /* Block size of hyperslab */
+ uint8 *wbuf, /* buffer to write to disk */
+ *rbuf, /* buffer read from disk */
+ *tbuf, /* temporary buffer pointer */
+ *tbuf2; /* temporary buffer pointer */
+ intn i,j; /* Counters */
+ herr_t ret; /* Generic return value */
+
+ /* Output message about test being performed */
+ MESSAGE(5, ("Testing Combination of Hyperslab & Element Selection Functions\n"));
+
+ /* Allocate write & read buffers */
+ wbuf=malloc(sizeof(uint8)*SPACE2_DIM1*SPACE2_DIM2);
+ rbuf=calloc(sizeof(uint8),SPACE3_DIM1*SPACE3_DIM2);
+
+ /* Initialize write buffer */
+ for(i=0, tbuf=wbuf; i<SPACE2_DIM1; i++)
+ for(j=0; j<SPACE2_DIM2; j++)
+ *tbuf++=(uint8)((i*SPACE2_DIM2)+j);
+
+ /* Create file */
+ fid1 = H5Fcreate(FILE, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
+ CHECK(fid1, FAIL, "H5Fcreate");
+
+ /* Create dataspace for dataset */
+ sid1 = H5Screate_simple(SPACE1_RANK, dims1, NULL);
+ CHECK(sid1, FAIL, "H5Screate_simple");
+
+ /* Create dataspace for write buffer */
+ sid2 = H5Screate_simple(SPACE2_RANK, dims2, NULL);
+ CHECK(sid2, FAIL, "H5Screate_simple");
+
+ /* Select sequence of ten points for disk dataset */
+ coord1[0][0]=0; coord1[0][1]=10; coord1[0][2]= 5;
+ coord1[1][0]=1; coord1[1][1]= 2; coord1[1][2]= 7;
+ coord1[2][0]=2; coord1[2][1]= 4; coord1[2][2]= 9;
+ coord1[3][0]=0; coord1[3][1]= 6; coord1[3][2]=11;
+ coord1[4][0]=1; coord1[4][1]= 8; coord1[4][2]=13;
+ coord1[5][0]=2; coord1[5][1]=12; coord1[5][2]= 0;
+ coord1[6][0]=0; coord1[6][1]=14; coord1[6][2]= 2;
+ coord1[7][0]=1; coord1[7][1]= 0; coord1[7][2]= 4;
+ coord1[8][0]=2; coord1[8][1]= 1; coord1[8][2]= 6;
+ coord1[9][0]=0; coord1[9][1]= 3; coord1[9][2]= 8;
+ ret = H5Sselect_elements(sid1,H5S_SELECT_SET,POINT1_NPOINTS,(const hssize_t **)coord1);
+ CHECK(ret, FAIL, "H5Sselect_elements");
+
+ /* Select 1x10 hyperslab for writing memory dataset */
+ start[0]=0; start[1]=0;
+ stride[0]=1; stride[1]=1;
+ count[0]=1; count[1]=10;
+ block[0]=1; block[1]=1;
+ ret = H5Sselect_hyperslab(sid2,H5S_SELECT_SET,start,stride,count,block);
+ CHECK(ret, FAIL, "H5Sselect_hyperslab");
+
+ /* Create a dataset */
+ dataset=H5Dcreate(fid1,"Dataset1",H5T_NATIVE_UCHAR,sid1,H5P_DEFAULT);
+
+ /* Write selection to disk */
+ ret=H5Dwrite(dataset,H5T_NATIVE_UCHAR,sid2,sid1,H5P_DEFAULT,wbuf);
+ CHECK(ret, FAIL, "H5Dwrite");
+
+ /* Close memory dataspace */
+ ret = H5Sclose(sid2);
+ CHECK(ret, FAIL, "H5Sclose");
+
+ /* Create dataspace for reading buffer */
+ sid2 = H5Screate_simple(SPACE3_RANK, dims3, NULL);
+ CHECK(sid2, FAIL, "H5Screate_simple");
+
+ /* Select 10x1 hyperslab for reading memory dataset */
+ start[0]=0; start[1]=0;
+ stride[0]=1; stride[1]=1;
+ count[0]=10; count[1]=1;
+ block[0]=1; block[1]=1;
+ ret = H5Sselect_hyperslab(sid2,H5S_SELECT_SET,start,stride,count,block);
+ CHECK(ret, FAIL, "H5Sselect_hyperslab");
+
+ /* Read selection from disk */
+ ret=H5Dread(dataset,H5T_NATIVE_UCHAR,sid2,sid1,H5P_DEFAULT,rbuf);
+ CHECK(ret, FAIL, "H5Dread");
+
+ /* Compare data read with data written out */
+ for(i=0; i<POINT1_NPOINTS; i++) {
+ tbuf=wbuf+i;
+ tbuf2=rbuf+(i*SPACE3_DIM2);
+ if(*tbuf!=*tbuf2) {
+ printf("element values don't match!, i=%d\n",i);
+ } /* end if */
+ } /* end for */
+
+ /* Close memory dataspace */
+ ret = H5Sclose(sid2);
+ CHECK(ret, FAIL, "H5Sclose");
+
+ /* Close disk dataspace */
+ ret = H5Sclose(sid1);
+ CHECK(ret, FAIL, "H5Sclose");
+
+ /* Close Dataset */
+ ret = H5Dclose(dataset);
+ CHECK(ret, FAIL, "H5Dclose");
+
+ /* Close file */
+ ret = H5Fclose(fid1);
+ CHECK(ret, FAIL, "H5Fclose");
+
+ /* Free memory buffers */
+ free(wbuf);
+ free(rbuf);
+} /* test_select_point() */
+
+/****************************************************************
+**
** test_select(): Main H5S selection testing routine.
**
****************************************************************/
@@ -332,6 +463,7 @@ test_select(void)
/* These next two tests use the same file information */
test_select_hyper(); /* Test basic H5S hyperslab selection code */
test_select_point(); /* Test basic H5S element selection code */
+ test_select_combo(); /* Test combined hyperslab & element selection code */
} /* test_select() */