summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorQuincey Koziol <koziol@hdfgroup.org>1998-08-04 00:30:35 (GMT)
committerQuincey Koziol <koziol@hdfgroup.org>1998-08-04 00:30:35 (GMT)
commit48f8e55c0a7aae63b741725b3c40c377959b9d35 (patch)
treeeb984bfd0b1d04efb51a3c89592fa74d8b65e0ce /test
parentb91c28331572a835e259b0fa7c49f67b5e20bd28 (diff)
downloadhdf5-48f8e55c0a7aae63b741725b3c40c377959b9d35.zip
hdf5-48f8e55c0a7aae63b741725b3c40c377959b9d35.tar.gz
hdf5-48f8e55c0a7aae63b741725b3c40c377959b9d35.tar.bz2
[svn-r566] Fixed offset code [finally :-/ ] for selections.
Diffstat (limited to 'test')
-rw-r--r--test/.distdep322
-rw-r--r--test/tselect.c340
2 files changed, 507 insertions, 155 deletions
diff --git a/test/.distdep b/test/.distdep
index 502e178..82aaa44 100644
--- a/test/.distdep
+++ b/test/.distdep
@@ -1,3 +1,34 @@
+testhdf5.o: \
+ testhdf5.c \
+ testhdf5.h \
+ ../src/H5private.h \
+ ../src/H5public.h \
+ ../src/H5config.h \
+ ../src/H5Eprivate.h \
+ ../src/H5Epublic.h
+tattr.o: \
+ tattr.c \
+ testhdf5.h \
+ ../src/H5private.h \
+ ../src/H5public.h \
+ ../src/H5config.h \
+ ../src/H5Eprivate.h \
+ ../src/H5Epublic.h \
+ ../src/H5Ipublic.h \
+ ../src/hdf5.h \
+ ../src/H5Apublic.h \
+ ../src/H5ACpublic.h \
+ ../src/H5Bpublic.h \
+ ../src/H5Dpublic.h \
+ ../src/H5Fpublic.h \
+ ../src/H5Gpublic.h \
+ ../src/H5HGpublic.h \
+ ../src/H5HLpublic.h \
+ ../src/H5MFpublic.h \
+ ../src/H5MMpublic.h \
+ ../src/H5Opublic.h \
+ ../src/H5Ppublic.h \
+ ../src/H5Zpublic.h
tfile.o: \
tfile.c \
testhdf5.h \
@@ -11,8 +42,7 @@ tfile.o: \
../src/H5Bpublic.h \
../src/H5Fprivate.h \
../src/H5Fpublic.h \
- ../src/H5Dpublic.h \
- ../src/H5Pprivate.h
+ ../src/H5Dpublic.h
theap.o: \
theap.c \
testhdf5.h \
@@ -29,8 +59,7 @@ theap.o: \
../src/H5Fpublic.h \
../src/H5Dpublic.h \
../src/H5Pprivate.h \
- ../src/H5Ppublic.h \
- ../src/H5Zpublic.h
+ ../src/H5Ppublic.h
tmeta.o: \
tmeta.c \
testhdf5.h \
@@ -39,7 +68,9 @@ tmeta.o: \
../src/H5config.h \
../src/H5Eprivate.h \
../src/H5Epublic.h \
- ../src/H5Ipublic.h
+ ../src/H5Ipublic.h \
+ ../src/H5Fprivate.h \
+ ../src/H5Fpublic.h
tohdr.o: \
tohdr.c \
testhdf5.h \
@@ -68,8 +99,30 @@ tohdr.o: \
../src/H5HGpublic.h \
../src/H5Tprivate.h \
../src/H5Tpublic.h \
- ../src/H5Sprivate.h \
- ../src/H5Spublic.h
+ ../src/H5Sprivate.h
+tselect.o: \
+ tselect.c \
+ testhdf5.h \
+ ../src/H5private.h \
+ ../src/H5public.h \
+ ../src/H5config.h \
+ ../src/H5Eprivate.h \
+ ../src/H5Epublic.h \
+ ../src/H5Ipublic.h \
+ ../src/hdf5.h \
+ ../src/H5Apublic.h \
+ ../src/H5ACpublic.h \
+ ../src/H5Bpublic.h \
+ ../src/H5Dpublic.h \
+ ../src/H5Fpublic.h \
+ ../src/H5Gpublic.h \
+ ../src/H5HGpublic.h \
+ ../src/H5HLpublic.h \
+ ../src/H5MFpublic.h \
+ ../src/H5MMpublic.h \
+ ../src/H5Opublic.h \
+ ../src/H5Ppublic.h \
+ ../src/H5Zpublic.h
tstab.o: \
tstab.c \
testhdf5.h \
@@ -98,13 +151,67 @@ tstab.o: \
../src/H5HGpublic.h \
../src/H5Tprivate.h \
../src/H5Tpublic.h \
+ ../src/H5Sprivate.h
+th5s.o: \
+ th5s.c \
+ testhdf5.h \
+ ../src/H5private.h \
+ ../src/H5public.h \
+ ../src/H5config.h \
+ ../src/H5Eprivate.h \
+ ../src/H5Epublic.h \
+ ../src/H5Ipublic.h \
+ ../src/H5Bprivate.h \
+ ../src/H5Bpublic.h \
+ ../src/H5Fprivate.h \
+ ../src/H5Fpublic.h \
+ ../src/H5Dpublic.h \
../src/H5Sprivate.h \
- ../src/H5Spublic.h
+ ../src/H5Spublic.h \
+ ../src/H5Gprivate.h \
+ ../src/H5Gpublic.h \
+ ../src/H5Oprivate.h \
+ ../src/H5Opublic.h \
+ ../src/H5HGprivate.h \
+ ../src/H5HGpublic.h \
+ ../src/H5Tprivate.h \
+ ../src/H5Tpublic.h \
+ ../src/H5Zprivate.h \
+ ../src/H5Zpublic.h
+dtypes.o: \
+ dtypes.c \
+ ../src/hdf5.h \
+ ../src/H5public.h \
+ ../src/H5config.h \
+ ../src/H5Ipublic.h \
+ ../src/H5Apublic.h \
+ ../src/H5ACpublic.h \
+ ../src/H5Bpublic.h \
+ ../src/H5Dpublic.h \
+ ../src/H5Epublic.h \
+ ../src/H5Fpublic.h \
+ ../src/H5Gpublic.h \
+ ../src/H5HGpublic.h \
+ ../src/H5HLpublic.h \
+ ../src/H5MFpublic.h \
+ ../src/H5MMpublic.h \
+ ../src/H5Opublic.h \
+ ../src/H5Ppublic.h \
+ ../src/H5Zpublic.h \
+ ../src/H5Spublic.h \
+ ../src/H5Tpublic.h \
+ ../src/H5Tpkg.h \
+ ../src/H5HGprivate.h \
+ ../src/H5Fprivate.h \
+ ../src/H5private.h \
+ ../src/H5Tprivate.h
hyperslab.o: \
hyperslab.c \
../src/H5private.h \
../src/H5public.h \
- ../src/H5config.h
+ ../src/H5config.h \
+ ../src/H5MMprivate.h \
+ ../src/H5MMpublic.h
istore.o: \
istore.c \
../src/H5private.h \
@@ -130,9 +237,11 @@ istore.o: \
../src/H5HGpublic.h \
../src/H5Tprivate.h \
../src/H5Tpublic.h \
- ../src/H5Sprivate.h
-extend.o: \
- extend.c \
+ ../src/H5Sprivate.h \
+ ../src/H5Spublic.h \
+ ../src/H5Zprivate.h
+dsets.o: \
+ dsets.c \
../src/hdf5.h \
../src/H5public.h \
../src/H5config.h \
@@ -151,9 +260,10 @@ extend.o: \
../src/H5Opublic.h \
../src/H5Ppublic.h \
../src/H5Zpublic.h \
- ../src/H5Spublic.h
-external.o: \
- external.c \
+ ../src/H5Spublic.h \
+ ../src/H5Tpublic.h
+cmpd_dset.o: \
+ cmpd_dset.c \
../src/hdf5.h \
../src/H5public.h \
../src/H5config.h \
@@ -172,27 +282,9 @@ external.o: \
../src/H5Opublic.h \
../src/H5Ppublic.h \
../src/H5Zpublic.h \
- ../src/H5Spublic.h \
- ../src/H5Tpublic.h
-gheap.o: \
- gheap.c \
- ../src/H5private.h \
- ../src/H5public.h \
- ../src/H5config.h \
- ../src/H5Eprivate.h \
- ../src/H5Epublic.h \
- ../src/H5Ipublic.h \
- ../src/H5Fprivate.h \
- ../src/H5Fpublic.h \
- ../src/H5Dpublic.h \
- ../src/H5Gprivate.h \
- ../src/H5Gpublic.h \
- ../src/H5Bprivate.h \
- ../src/H5Bpublic.h \
- ../src/H5HGprivate.h \
- ../src/H5HGpublic.h
-shtype.o: \
- shtype.c \
+ ../src/H5Spublic.h
+extend.o: \
+ extend.c \
../src/hdf5.h \
../src/H5public.h \
../src/H5config.h \
@@ -212,8 +304,8 @@ shtype.o: \
../src/H5Ppublic.h \
../src/H5Zpublic.h \
../src/H5Spublic.h
-links.o: \
- links.c \
+external.o: \
+ external.c \
../src/hdf5.h \
../src/H5public.h \
../src/H5config.h \
@@ -234,8 +326,8 @@ links.o: \
../src/H5Zpublic.h \
../src/H5Spublic.h \
../src/H5Tpublic.h
-chunk.o: \
- chunk.c \
+iopipe.o: \
+ iopipe.c \
../src/hdf5.h \
../src/H5public.h \
../src/H5config.h \
@@ -256,25 +348,27 @@ chunk.o: \
../src/H5Zpublic.h \
../src/H5Spublic.h \
../src/H5Tpublic.h
-bittests.o: \
- bittests.c \
- ../src/H5Tpkg.h \
- ../src/H5HGprivate.h \
- ../src/H5HGpublic.h \
+gheap.o: \
+ gheap.c \
+ ../src/H5private.h \
../src/H5public.h \
../src/H5config.h \
+ ../src/H5Eprivate.h \
+ ../src/H5Epublic.h \
+ ../src/H5Ipublic.h \
../src/H5Fprivate.h \
../src/H5Fpublic.h \
- ../src/H5Ipublic.h \
- ../src/H5private.h \
../src/H5Dpublic.h \
- ../src/H5Tprivate.h \
- ../src/H5Tpublic.h \
../src/H5Gprivate.h \
../src/H5Gpublic.h \
- ../src/H5Bprivate.h
-big.o: \
- big.c \
+ ../src/H5Bprivate.h \
+ ../src/H5Bpublic.h \
+ ../src/H5HGprivate.h \
+ ../src/H5HGpublic.h \
+ ../src/H5Pprivate.h \
+ ../src/H5Ppublic.h
+shtype.o: \
+ shtype.c \
../src/hdf5.h \
../src/H5public.h \
../src/H5config.h \
@@ -293,17 +387,9 @@ big.o: \
../src/H5Opublic.h \
../src/H5Ppublic.h \
../src/H5Zpublic.h \
- ../src/H5Spublic.h \
- ../src/H5Tpublic.h \
- ../src/H5private.h
-testhdf5.o: \
- testhdf5.c \
- testhdf5.h \
- ../src/H5private.h \
- ../src/H5public.h \
- ../src/H5config.h
-dsets.o: \
- dsets.c \
+ ../src/H5Spublic.h
+big.o: \
+ big.c \
../src/hdf5.h \
../src/H5public.h \
../src/H5config.h \
@@ -323,9 +409,10 @@ dsets.o: \
../src/H5Ppublic.h \
../src/H5Zpublic.h \
../src/H5Spublic.h \
- ../src/H5Tpublic.h
-dtypes.o: \
- dtypes.c \
+ ../src/H5Tpublic.h \
+ ../src/H5private.h
+links.o: \
+ links.c \
../src/hdf5.h \
../src/H5public.h \
../src/H5config.h \
@@ -345,54 +432,18 @@ dtypes.o: \
../src/H5Ppublic.h \
../src/H5Zpublic.h \
../src/H5Spublic.h \
- ../src/H5Tpublic.h \
- ../src/H5Tpkg.h \
- ../src/H5HGprivate.h \
- ../src/H5Fprivate.h \
- ../src/H5private.h \
- ../src/H5Tprivate.h \
- ../src/H5Gprivate.h
-th5s.o: \
- th5s.c \
- testhdf5.h \
- ../src/H5private.h \
- ../src/H5public.h \
- ../src/H5config.h \
- ../src/H5Eprivate.h \
- ../src/H5Epublic.h \
- ../src/H5Ipublic.h \
- ../src/H5Bprivate.h \
- ../src/H5Bpublic.h \
- ../src/H5Fprivate.h \
- ../src/H5Fpublic.h \
- ../src/H5Dpublic.h \
- ../src/H5Sprivate.h \
- ../src/H5Spublic.h \
- ../src/H5Gprivate.h \
- ../src/H5Gpublic.h \
- ../src/H5Oprivate.h \
- ../src/H5Opublic.h \
- ../src/H5HGprivate.h \
- ../src/H5HGpublic.h \
- ../src/H5Tprivate.h \
- ../src/H5Tpublic.h \
- ../src/H5Zprivate.h \
- ../src/H5Zpublic.h \
- ../src/H5Pprivate.h
-tattr.o: \
- tattr.c \
- testhdf5.h \
- ../src/H5private.h \
+ ../src/H5Tpublic.h
+chunk.o: \
+ chunk.c \
+ ../src/hdf5.h \
../src/H5public.h \
../src/H5config.h \
- ../src/H5Eprivate.h \
- ../src/H5Epublic.h \
../src/H5Ipublic.h \
- ../src/hdf5.h \
../src/H5Apublic.h \
../src/H5ACpublic.h \
../src/H5Bpublic.h \
../src/H5Dpublic.h \
+ ../src/H5Epublic.h \
../src/H5Fpublic.h \
../src/H5Gpublic.h \
../src/H5HGpublic.h \
@@ -402,53 +453,26 @@ tattr.o: \
../src/H5Opublic.h \
../src/H5Ppublic.h \
../src/H5Zpublic.h \
- ../src/H5Spublic.h
-tselect.o: \
- tselect.c \
- testhdf5.h \
- ../src/H5private.h \
- ../src/H5public.h \
- ../src/H5config.h \
- ../src/H5Eprivate.h \
- ../src/H5Epublic.h \
- ../src/H5Ipublic.h \
- ../src/hdf5.h \
- ../src/H5Apublic.h \
- ../src/H5ACpublic.h \
- ../src/H5Bpublic.h \
- ../src/H5Dpublic.h \
- ../src/H5Fpublic.h \
- ../src/H5Gpublic.h \
+ ../src/H5Spublic.h \
+ ../src/H5Tpublic.h
+bittests.o: \
+ bittests.c \
+ ../src/H5Tpkg.h \
+ ../src/H5HGprivate.h \
../src/H5HGpublic.h \
- ../src/H5HLpublic.h \
- ../src/H5MFpublic.h \
- ../src/H5MMpublic.h \
- ../src/H5Opublic.h \
- ../src/H5Ppublic.h \
- ../src/H5Zpublic.h
-cmpd_dset.o: \
- cmpd_dset.c \
- ../src/hdf5.h \
../src/H5public.h \
../src/H5config.h \
+ ../src/H5Fprivate.h \
+ ../src/H5Fpublic.h \
../src/H5Ipublic.h \
- ../src/H5Apublic.h \
- ../src/H5ACpublic.h \
- ../src/H5Bpublic.h \
+ ../src/H5private.h \
../src/H5Dpublic.h \
- ../src/H5Epublic.h \
- ../src/H5Fpublic.h \
- ../src/H5Gpublic.h \
- ../src/H5HGpublic.h \
- ../src/H5HLpublic.h \
- ../src/H5MFpublic.h \
- ../src/H5MMpublic.h \
- ../src/H5Opublic.h \
- ../src/H5Ppublic.h \
- ../src/H5Zpublic.h \
- ../src/H5Spublic.h
-iopipe.o: \
- iopipe.c \
+ ../src/H5Tprivate.h \
+ ../src/H5Tpublic.h \
+ ../src/H5Gprivate.h \
+ ../src/H5Gpublic.h
+mtime.o: \
+ mtime.c \
../src/hdf5.h \
../src/H5public.h \
../src/H5config.h \
diff --git a/test/tselect.c b/test/tselect.c
index 29fff74..c19bfdd 100644
--- a/test/tselect.c
+++ b/test/tselect.c
@@ -49,12 +49,6 @@ static char RcsId[] = "$Revision$";
#define SPACE3_DIM1 15
#define SPACE3_DIM2 26
-/* 2-D dataset with fixed dimensions */
-#define SPACE4_NAME "Space4"
-#define SPACE4_RANK 2
-#define SPACE4_DIM1 15
-#define SPACE4_DIM2 26
-
/* Element selection information */
#define POINT1_NPOINTS 10
@@ -1090,6 +1084,338 @@ test_select_point_copy(void)
/****************************************************************
**
+** test_select_hyper_offset(): Test basic H5S (dataspace) selection code.
+** Tests hyperslabs of various sizes and dimensionalities with selection
+** offsets.
+**
+****************************************************************/
+static void
+test_select_hyper_offset(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 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 */
+ hssize_t offset[SPACE1_RANK]; /* Offset of selection */
+ 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 */
+ hbool_t valid; /* Generic boolean return value */
+ H5S_class_t ext_type; /* Extent type */
+
+ /* Output message about test being performed */
+ MESSAGE(5, ("Testing Hyperslab Selection Functions with Offsets\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 writing buffer */
+ sid2 = H5Screate_simple(SPACE2_RANK, dims2, NULL);
+ CHECK(sid2, FAIL, "H5Screate_simple");
+
+ /* Verify extent type */
+ ext_type = H5Sextent_class(sid1);
+ VERIFY(ext_type, H5S_SIMPLE, "H5Sextent_class");
+
+ /* 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");
+
+ /* Check a valid offset */
+ offset[0]=-1; offset[1]=0; offset[2]=0;
+ ret = H5Soffset_simple(sid1,offset);
+ CHECK(ret, FAIL, "H5Soffset_simple");
+ valid = H5Sselect_valid(sid1);
+ VERIFY(valid, TRUE, "H5Svalid_offset");
+
+ /* Check an invalid offset */
+ offset[0]=10; offset[1]=0; offset[2]=0;
+ ret = H5Soffset_simple(sid1,offset);
+ CHECK(ret, FAIL, "H5Soffset_simple");
+ valid = H5Sselect_valid(sid1);
+ VERIFY(valid, FALSE, "H5Svalid_offset");
+
+ /* Reset offset */
+ offset[0]=0; offset[1]=0; offset[2]=0;
+ ret = H5Soffset_simple(sid1,offset);
+ CHECK(ret, FAIL, "H5Soffset_simple");
+ valid = H5Sselect_valid(sid1);
+ VERIFY(valid, TRUE, "H5Svalid_offset");
+
+ /* 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");
+
+ /* Choose a valid offset for the memory dataspace */
+ offset[0]=-10; offset[1]=0;
+ ret = H5Soffset_simple(sid2,offset);
+ CHECK(ret, FAIL, "H5Soffset_simple");
+ valid = H5Sselect_valid(sid2);
+ VERIFY(valid, TRUE, "H5Svalid_offset");
+
+ /* 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 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+5)*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");
+
+ /* Close file */
+ ret = H5Fclose(fid1);
+ CHECK(ret, FAIL, "H5Fclose");
+
+ /* Free memory buffers */
+ free(wbuf);
+ free(rbuf);
+} /* test_select_hyper_offset() */
+
+/****************************************************************
+**
+** test_select_point_offset(): Test basic H5S (dataspace) selection code.
+** Tests element selections between dataspaces of various sizes
+** and dimensionalities with selection offsets.
+**
+****************************************************************/
+static void
+test_select_point_offset(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 */
+ hssize_t coord2[POINT1_NPOINTS][SPACE2_RANK]; /* Coordinates for point selection */
+ hssize_t coord3[POINT1_NPOINTS][SPACE3_RANK]; /* Coordinates for point selection */
+ hssize_t offset[SPACE1_RANK]; /* Offset of selection */
+ 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 */
+ hbool_t valid; /* Generic boolean return value */
+
+ /* Output message about test being performed */
+ MESSAGE(5, ("Testing 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]=12;
+ 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");
+
+ /* Check a valid offset */
+ offset[0]=0; offset[1]=0; offset[2]=1;
+ ret = H5Soffset_simple(sid1,offset);
+ CHECK(ret, FAIL, "H5Soffset_simple");
+ valid = H5Sselect_valid(sid1);
+ VERIFY(valid, TRUE, "H5Svalid_offset");
+
+ /* Check an invalid offset */
+ offset[0]=10; offset[1]=0; offset[2]=0;
+ ret = H5Soffset_simple(sid1,offset);
+ CHECK(ret, FAIL, "H5Soffset_simple");
+ valid = H5Sselect_valid(sid1);
+ VERIFY(valid, FALSE, "H5Svalid_offset");
+
+ /* Reset offset */
+ offset[0]=0; offset[1]=0; offset[2]=0;
+ ret = H5Soffset_simple(sid1,offset);
+ CHECK(ret, FAIL, "H5Soffset_simple");
+ valid = H5Sselect_valid(sid1);
+ VERIFY(valid, TRUE, "H5Svalid_offset");
+
+ /* Select sequence of ten points for write dataset */
+ coord2[0][0]=12; coord2[0][1]= 3;
+ coord2[1][0]=15; coord2[1][1]=13;
+ coord2[2][0]= 7; coord2[2][1]=24;
+ coord2[3][0]= 0; coord2[3][1]= 6;
+ coord2[4][0]=13; coord2[4][1]= 0;
+ coord2[5][0]=24; coord2[5][1]=11;
+ coord2[6][0]=12; coord2[6][1]=21;
+ coord2[7][0]=23; 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,(const hssize_t **)coord2);
+ CHECK(ret, FAIL, "H5Sselect_elements");
+
+ /* Choose a valid offset for the memory dataspace */
+ offset[0]=5; offset[1]=1;
+ ret = H5Soffset_simple(sid2,offset);
+ CHECK(ret, FAIL, "H5Soffset_simple");
+ valid = H5Sselect_valid(sid2);
+ VERIFY(valid, TRUE, "H5Svalid_offset");
+
+ /* 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 sequence of points for read dataset */
+ coord3[0][0]= 0; coord3[0][1]= 2;
+ coord3[1][0]= 4; coord3[1][1]= 8;
+ coord3[2][0]=13; coord3[2][1]=13;
+ coord3[3][0]=14; coord3[3][1]=25;
+ coord3[4][0]= 7; coord3[4][1]= 9;
+ coord3[5][0]= 2; coord3[5][1]= 0;
+ coord3[6][0]= 9; coord3[6][1]=19;
+ 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,(const hssize_t **)coord3);
+ CHECK(ret, FAIL, "H5Sselect_elements");
+
+ /* 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+((coord2[i][0]+offset[0])*SPACE2_DIM2)+coord2[i][1]+offset[1];
+ tbuf2=rbuf+(coord3[i][0]*SPACE3_DIM2)+coord3[i][1];
+ 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.
**
****************************************************************/
@@ -1107,6 +1433,8 @@ test_select(void)
test_select_hyper_stride(); /* Test strided hyperslab selection code */
test_select_hyper_copy(); /* Test hyperslab selection copying code */
test_select_point_copy(); /* Test point selection copying code */
+ test_select_hyper_offset(); /* Test selection offset code with hyperslabs */
+ test_select_point_offset(); /* Test selection offset code with elements */
} /* test_select() */