summaryrefslogtreecommitdiffstats
path: root/test/tselect.c
diff options
context:
space:
mode:
authorQuincey Koziol <koziol@hdfgroup.org>1998-07-15 00:48:16 (GMT)
committerQuincey Koziol <koziol@hdfgroup.org>1998-07-15 00:48:16 (GMT)
commit5b6f42727c81c0ec8f70cf8277fd01fb8fabe549 (patch)
tree584c17689fd9170688a78339a54d49fb2ef7293e /test/tselect.c
parente350a69a55f2101d7e31dc8b3565da50ef452643 (diff)
downloadhdf5-5b6f42727c81c0ec8f70cf8277fd01fb8fabe549.zip
hdf5-5b6f42727c81c0ec8f70cf8277fd01fb8fabe549.tar.gz
hdf5-5b6f42727c81c0ec8f70cf8277fd01fb8fabe549.tar.bz2
[svn-r494] Added test to take several differently shaped hyperslabs and perform I/O
on them to verify the iterators are processed in the correct order.
Diffstat (limited to 'test/tselect.c')
-rw-r--r--test/tselect.c82
1 files changed, 76 insertions, 6 deletions
diff --git a/test/tselect.c b/test/tselect.c
index 6b0d46d..3edd9b5 100644
--- a/test/tselect.c
+++ b/test/tselect.c
@@ -60,14 +60,19 @@ test_select_hyper(void)
{
hid_t fid1; /* HDF5 File IDs */
hid_t dataset; /* Dataset ID */
- hid_t group; /* Group ID */
hid_t sid1,sid2; /* Dataspace ID */
- hid_t attr; /* Attribute ID */
hsize_t dims1[] = {SPACE1_DIM1, SPACE1_DIM2, SPACE1_DIM3};
hsize_t dims2[] = {SPACE2_DIM1, SPACE2_DIM2};
hsize_t dims3[] = {SPACE3_DIM1, SPACE3_DIM2};
+ 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 */
+ *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 */
@@ -75,7 +80,12 @@ test_select_hyper(void)
/* Allocate write & read buffers */
wbuf=malloc(sizeof(uint8)*SPACE2_DIM1*SPACE2_DIM2);
- rbuf=malloc(sizeof(uint8)*SPACE3_DIM1*SPACE3_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);
@@ -85,16 +95,72 @@ test_select_hyper(void)
sid1 = H5Screate_simple(SPACE1_RANK, dims1, NULL);
CHECK(sid1, FAIL, "H5Screate_simple");
- /* Create dataspace for memory */
+ /* Create dataspace for writing buffer */
sid2 = H5Screate_simple(SPACE2_RANK, dims2, NULL);
CHECK(sid2, FAIL, "H5Screate_simple");
+ /* Select 2x15x13 hyperslab for disk dataset */
+ start[0]=1; start[1]=0; start[2]=0;
+ stride[0]=1; stride[1]=1; stride[2]=1;
+ count[0]=2; count[1]=15; count[2]=13;
+ block[0]=1; block[1]=1; block[2]=1;
+ ret = H5Sselect_hyperslab(sid1,H5S_SELECT_SET,start,stride,count,block);
+ CHECK(ret, FAIL, "H5Sselect_hyperslab");
+
+ /* Select 15x26 hyperslab for memory dataset */
+ start[0]=15; start[1]=0;
+ stride[0]=1; stride[1]=1;
+ count[0]=15; count[1]=26;
+ 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);
- ret = H5Sclose(sid1);
+ /* 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 15x26 hyperslab for reading memory dataset */
+ start[0]=0; start[1]=0;
+ stride[0]=1; stride[1]=1;
+ count[0]=15; count[1]=26;
+ 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<SPACE3_DIM1; i++) {
+ tbuf=wbuf+((i+15)*SPACE2_DIM2);
+ tbuf2=rbuf+(i*SPACE3_DIM2);
+ for(j=0; j<SPACE3_DIM2; j++, tbuf++, tbuf2++) {
+ if(*tbuf!=*tbuf2) {
+ printf("hyperslab values don't match!, i=%d, j=%d\n",i,j);
+ } /* end if */
+ } /* end for */
+ } /* 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");
@@ -102,6 +168,10 @@ test_select_hyper(void)
/* Close file */
ret = H5Fclose(fid1);
CHECK(ret, FAIL, "H5Fclose");
+
+ /* Free memory buffers */
+ free(wbuf);
+ free(rbuf);
} /* test_select_hyper() */
/****************************************************************