summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorRaymond Lu <songyulu@hdfgroup.org>2008-01-09 14:16:57 (GMT)
committerRaymond Lu <songyulu@hdfgroup.org>2008-01-09 14:16:57 (GMT)
commitb58ac6c8eef426e408a53a1aee5a6651eebfa5e8 (patch)
treec1cf70e812e073fe2acd8685c60384c79991051b /test
parent7e80ad2af2ad4ec811b38d139d076558866c99d9 (diff)
downloadhdf5-b58ac6c8eef426e408a53a1aee5a6651eebfa5e8.zip
hdf5-b58ac6c8eef426e408a53a1aee5a6651eebfa5e8.tar.gz
hdf5-b58ac6c8eef426e408a53a1aee5a6651eebfa5e8.tar.bz2
[svn-r14385] This checkin completely modified the test for the coordinate calculation of dataspace selection.
It covers many cases. Tested on smirom, kagiso, and linew.
Diffstat (limited to 'test')
-rw-r--r--test/Makefile.am4
-rw-r--r--test/Makefile.in4
-rw-r--r--test/tcoords.c745
3 files changed, 423 insertions, 330 deletions
diff --git a/test/Makefile.am b/test/Makefile.am
index 62b1f92..4f4951c 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -106,8 +106,8 @@ CHECK_CLEANFILES+=cmpd_dset.h5 compact_dataset.h5 dataset.h5 extend.h5 istore.h5
tfile[1-4].h5 th5s[1-3].h5 lheap.h5 fheap.h5 ohdr.h5 stab.h5 \
extern_[1-3].h5 extern_[1-4][ab].raw gheap[0-4].h5 dt_arith[1-2]\
links.h5 links[0-6]*.h5 big.data big[0-9][0-9][0-9][0-9][0-9].h5 \
- stdio.h5 sec2.h5 dtypes[1-8].h5 dt_arith[1-2].h5 tattr.h5 h5 \
- tselect.h5 mtime.h5 unlink.h5 unicode.h5 \
+ stdio.h5 sec2.h5 dtypes[1-8].h5 dt_arith[1-2].h5 tattr.h5 \
+ tselect.h5 mtime.h5 unlink.h5 unicode.h5 coord.h5 \
fillval_[0-9].h5 fillval.raw mount_[0-9].h5 testmeta.h5 ttime.h5 \
trefer[1-3].h5 tvltypes.h5 tvlstr.h5 tvlstr2.h5 flush.h5 \
enum1.h5 titerate.h5 ttsafe.h5 tarray1.h5 tgenprop.h5 \
diff --git a/test/Makefile.in b/test/Makefile.in
index a7617b3..84f0737 100644
--- a/test/Makefile.in
+++ b/test/Makefile.in
@@ -590,8 +590,8 @@ CHECK_CLEANFILES = *.chkexe *.chklog *.clog cmpd_dset.h5 \
extern_[1-3].h5 extern_[1-4][ab].raw gheap[0-4].h5 \
dt_arith[1-2] links.h5 links[0-6]*.h5 big.data \
big[0-9][0-9][0-9][0-9][0-9].h5 stdio.h5 sec2.h5 \
- dtypes[1-8].h5 dt_arith[1-2].h5 tattr.h5 h5 tselect.h5 \
- mtime.h5 unlink.h5 unicode.h5 fillval_[0-9].h5 fillval.raw \
+ dtypes[1-8].h5 dt_arith[1-2].h5 tattr.h5 tselect.h5 mtime.h5 \
+ unlink.h5 unicode.h5 coord.h5 fillval_[0-9].h5 fillval.raw \
mount_[0-9].h5 testmeta.h5 ttime.h5 trefer[1-3].h5 tvltypes.h5 \
tvlstr.h5 tvlstr2.h5 flush.h5 enum1.h5 titerate.h5 ttsafe.h5 \
tarray1.h5 tgenprop.h5 tmisc[0-9]*.h5 set_extent_read.h5 \
diff --git a/test/tcoords.c b/test/tcoords.c
index 67e7aa1..0b04f6d 100644
--- a/test/tcoords.c
+++ b/test/tcoords.c
@@ -15,369 +15,462 @@
/***********************************************************
*
-* Test program: th5s
+* Test program: tcoords
*
-* Test the element coordinates for dataspace selection.
+* Test the element coordinates for dataspace selection. For
+* chunked dataset, when the hyperslab selection of some
+* dimensions is full, the library optimize it by "flattenning"
+* the fully selected dimensions. This program tests if the
+* coordinates of selected elements are correctly calculated.
*
*************************************************************/
#include "testhdf5.h"
-/*
-** Data used to write the dataset.
-*/
-
-static int da_buffer[12][1][6][2];
-
-static hsize_t da_dims[4] = { 12, 1, 6, 2 };
-static hsize_t da_maxdims[4] = { H5S_UNLIMITED, H5S_UNLIMITED, H5S_UNLIMITED, H5S_UNLIMITED };
-/*static hsize_t da_chunksize[4] = { 3, 1, 2, 1 };*/
-static hsize_t da_chunksize[4] = { 12, 1, 6, 2 };
-
-/*
-** The dataset end of the selection is done using element selection.
-** These are the element locations.
-*/
-#ifdef TMP
-static hsize_t da_elements[12][4] = { { 11, 0, 0, 0 },
- { 11, 0, 0, 1 },
- { 11, 0, 5, 0 },
- { 11, 0, 5, 1 },
- { 11, 0, 1, 0 },
- { 11, 0, 1, 1 },
- { 11, 0, 2, 0 },
- { 11, 0, 2, 1 },
- { 11, 0, 3, 0 },
- { 11, 0, 3, 1 },
- { 11, 0, 4, 0 },
- { 11, 0, 4, 1 } };
-#else
-static hsize_t da_elements[12][4] = { { 11, 0, 0, 0 },
- { 11, 0, 0, 1 },
- { 11, 0, 1, 0 },
- { 11, 0, 1, 1 },
- { 11, 0, 2, 0 },
- { 11, 0, 2, 1 },
- { 11, 0, 3, 0 },
- { 11, 0, 3, 1 },
- { 11, 0, 4, 0 },
- { 11, 0, 4, 1 },
- { 11, 0, 5, 0 },
- { 11, 0, 5, 1 } };
-#endif
-
-/*
-** This is where it gets interesting.
+/***********************************************************
**
-** First experiment: the data being read is rank=2, so use two
-** dimensions. However, the array is 6x3, while the transfer is 6x2.
-** We use a hyperslab to select the subset. This case shows no
-** problem.
-*/
-static int mem1_buffer[6][3];
-
-static hsize_t mem1_dims[2] = { 6, 3};
-
-static hsize_t mem1_start[2] = { 0, 0 };
-static hsize_t mem1_count[2] = { 1, 1 };
-static hsize_t mem1_stride[2] = { 1, 1 };
-static hsize_t mem1_block[2] = { 6, 2 };
-
-
-/*
-** Second experiment: the transfer is the same rank as above, but we
-** add two dimensions of 1. I.e., the array is 1x1x6x2. In this
-** case, the 6x2 selection is over the entire array, not a subset of
-** the array. However, we still use hyperslab selection. This case
-** shows no problem.
-*/
-static int mem2_buffer[1][1][6][2];
-
-static hsize_t mem2_dims[4] = { 1, 1, 6, 2 };
-
-static hsize_t mem2_start[4] = { 0, 0, 0, 0 };
-static hsize_t mem2_count[4] = { 1, 1, 1, 1 };
-static hsize_t mem2_stride[4] = { 1, 1, 1, 1 };
-static hsize_t mem2_block[4] = { 1, 1, 6, 2 };
-
-
-/*
-** Third experiment: the transfer is the same rank as above, and we
-** add two dimensions of 1, but now the array is larger: 1x1x6x3.
-** The selection is now over a subset of the array (1x1x6x2). This
-** case demonstrates the problem.
-*/
-/*static int mem3_buffer[1][1][6][3];*/
-static int mem3_buffer[1][1][6][3];
-
-/*static hsize_t mem3_dims[4] = { 1, 1, 6, 3 };*/
-static hsize_t mem3_dims[4] = { 1, 1, 6, 3 };
-
-static hsize_t mem3_start[4] = { 0, 0, 0, 0 };
-static hsize_t mem3_count[4] = { 1, 1, 1, 1 };
-static hsize_t mem3_stride[4] = { 1, 1, 1, 1 };
-static hsize_t mem3_block[4] = { 1, 1, 6, 2 };
-
-/*
-** Fourth experiment: the transfer is the same rank as above, but we
-** add two dimensions of 1. I.e., the array is 1x6x3. In this
-** case, the 6x2 selection is over the entire array, not a subset of
-** the array. However, we still use hyperslab selection. This case
-** shows the problem.
-*/
-static int mem4_buffer[1][6][3];
-
-static hsize_t mem4_dims[3] = { 1, 6, 3 };
-
-static hsize_t mem4_start[3] = { 0, 0, 0 };
-static hsize_t mem4_count[3] = { 1, 1, 1 };
-static hsize_t mem4_stride[3] = { 1, 1, 1 };
-static hsize_t mem4_block[3] = { 1, 6, 2 };
-
-
-/*
-** Subroutine to write the dataset. It's probably not important to
-** this example, other than to know it's shape.
-*/
-void write_dataset()
+** test_single_end(): Test full hyperslab selection of only
+** one block.
+**
+*************************************************************/
+static void test_single_end(hid_t file)
{
- int i;
- hid_t fid, dsid, daid, msid, plid;
- herr_t rv;
-
- fid = H5Fcreate("coord.hdf", H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
- if(fid < 0)
- {
- H5Eprint2(H5E_DEFAULT, stderr);
- exit(1);
+ hid_t sid, plid, did, msid;
+ herr_t ret; /* Generic error return */
+ int i, j, k;
+ hsize_t da_dims[4] = { 2, 3, 6, 2 };
+ hsize_t da_chunksize[4] = { 1, 3, 3, 2 };
+ int da_buffer[2][3][6][2];
+
+ /* For testing the full selection in the fastest-growing end */
+ int mem1_buffer[1][1][6][2];
+ hsize_t mem1_dims[4] = { 1, 1, 6, 2 };
+ hsize_t mem1_start[4] = { 0, 0, 0, 0 };
+ hsize_t mem1_count[4] = { 1, 1, 1, 1 };
+ hsize_t mem1_stride[4] = { 1, 1, 1, 1 };
+ hsize_t mem1_block[4] = { 1, 1, 6, 2 };
+
+ /* For testing the full selection in the slowest-growing end */
+ int mem2_buffer[2][3][1][1];
+ hsize_t mem2_dims[4] = { 2, 3, 1, 1 };
+ hsize_t mem2_start[4] = { 0, 0, 0, 0 };
+ hsize_t mem2_count[4] = { 1, 1, 1, 1 };
+ hsize_t mem2_stride[4] = { 1, 1, 1, 1 };
+ hsize_t mem2_block[4] = { 2, 3, 1, 1 };
+
+ /* For testing the full selection in the middle dimensions */
+ int mem3_buffer[1][3][6][1];
+ hsize_t mem3_dims[4] = { 1, 3, 6, 1 };
+ hsize_t mem3_start[4] = { 0, 0, 0, 0 };
+ hsize_t mem3_count[4] = { 1, 1, 1, 1 };
+ hsize_t mem3_stride[4] = { 1, 1, 1, 1 };
+ hsize_t mem3_block[4] = { 1, 3, 6, 1 };
+
+ /* Create and write the dataset */
+ sid = H5Screate_simple(4, da_dims, da_dims);
+ CHECK(sid, FAIL, "H5Screate_simple");
+
+ plid = H5Pcreate(H5P_DATASET_CREATE);
+ CHECK(plid, FAIL, "H5Pcreate");
+
+ ret = H5Pset_chunk(plid, 4, da_chunksize);
+ CHECK(ret, FAIL, "H5Pset_chunk");
+
+ did = H5Dcreate2(file, "single_end", H5T_NATIVE_INT, sid, H5P_DEFAULT, plid, H5P_DEFAULT);
+ CHECK(did, FAIL, "H5Dcreate2");
+
+ for(i=0; i<2; i++) {
+ for(j=0; j<3; j++) {
+ for(k=0; k<6; k++) {
+ da_buffer[i][j][k][0] = i*100 + j*10 + k;
+ da_buffer[i][j][k][0] = i*100 + j*10 + k + 1;
+ }
+ }
}
- /*dsid = H5Screate_simple(4, da_dims, da_maxdims);*/
- dsid = H5Screate_simple(4, da_dims, da_dims);
- if(dsid < 0)
- {
- H5Eprint2(H5E_DEFAULT, stderr);
- exit(1);
- }
+ ret = H5Dwrite(did, H5T_NATIVE_INT, sid, sid, H5P_DEFAULT, da_buffer);
+ CHECK(ret, FAIL, "H5Dwrite");
- plid = H5Pcreate(H5P_DATASET_CREATE);
- if(plid < 0)
- {
- H5Eprint2(H5E_DEFAULT, stderr);
- exit(1);
- }
+ ret = H5Dclose(did);
+ CHECK(ret, FAIL, "H5Dclose");
- rv = H5Pset_layout(plid, H5D_CHUNKED);
- if(rv < 0)
- {
- H5Eprint2(H5E_DEFAULT, stderr);
- exit(1);
- }
+
+ /* ****** Case 1: ******
+ * Testing the full selection in the fastest-growing end */
+ did = H5Dopen2(file, "single_end", H5P_DEFAULT);
+ CHECK(did, FAIL, "H5Dopen");
- rv = H5Pset_chunk(plid, 4, da_chunksize);
- if(rv < 0)
- {
- H5Eprint2(H5E_DEFAULT, stderr);
- exit(1);
- }
+ /* Select the elements in the dataset */
+ ret = H5Sselect_hyperslab(sid, H5S_SELECT_SET, mem1_start, mem1_stride, mem1_count, mem1_block);
+ CHECK(ret, FAIL, "H5Sselect_hyperslab");
- daid = H5Dcreate2(fid, "dataset", H5T_NATIVE_INT, dsid, H5P_DEFAULT, plid, H5P_DEFAULT);
- if(daid < 0)
- {
- H5Eprint2(H5E_DEFAULT, stderr);
- exit(1);
- }
+ msid = H5Screate_simple(4, mem1_dims, mem1_dims);
+ CHECK(msid, FAIL, "H5Screate_simple");
- /*
- ** We'll only be interested in the front plane ([0][0][0-5[0-1]) so
- ** we only initialize that.
- */
- for(i = 0; i < 12; i++)
- {
- int j;
- for(j = 0; j < 6; j++)
- {
- da_buffer[i][0][j][0] = j * 10;
- da_buffer[i][0][j][1] = j * 10 + 1;
- }
- }
+ ret = H5Sselect_all(msid);
+ CHECK(ret, FAIL, "H5Sselect_all");
- msid = H5Screate_simple(4, da_dims, da_dims);
- if(msid < 0)
- {
- H5Eprint2(H5E_DEFAULT, stderr);
- exit(1);
- }
+ ret = H5Dread(did, H5T_NATIVE_INT, msid, sid, H5P_DEFAULT, mem1_buffer);
+ CHECK(ret, FAIL, "H5Dread");
- rv = H5Dwrite(daid, H5T_NATIVE_INT, msid, dsid, H5P_DEFAULT, da_buffer);
- if(rv < 0)
- {
- H5Eprint2(H5E_DEFAULT, stderr);
- exit(1);
- }
+ ret = H5Dclose(did);
+ CHECK(ret, FAIL, "H5Dclose");
- rv = H5Dclose(daid);
- if(rv < 0)
- {
- H5Eprint2(H5E_DEFAULT, stderr);
- exit(1);
- }
+ ret = H5Sclose(msid);
+ CHECK(ret, FAIL, "H5Sclose");
- rv = H5Fclose(fid);
- if(rv < 0)
- {
- H5Eprint2(H5E_DEFAULT, stderr);
- exit(1);
- }
+ for(i=0; i<6; i++)
+ for(j=0; j<2; j++)
+ if(da_buffer[0][0][i][j] != mem1_buffer[0][0][i][j]) {
+ TestErrPrintf("Read different values than written at index 0,0,%d,%d\n", i, j);
+ }
+
+ /* ****** Case 2: ******
+ * Testing the full selection in the slowest-growing end */
+ did = H5Dopen2(file, "single_end", H5P_DEFAULT);
+ CHECK(did, FAIL, "H5Dopen");
+
+ /* Select the elements in the dataset */
+ ret = H5Sselect_hyperslab(sid, H5S_SELECT_SET, mem2_start, mem2_stride, mem2_count, mem2_block);
+ CHECK(ret, FAIL, "H5Sselect_hyperslab");
+
+ msid = H5Screate_simple(4, mem2_dims, mem2_dims);
+ CHECK(msid, FAIL, "H5Screate_simple");
+
+ ret = H5Sselect_all(msid);
+ CHECK(ret, FAIL, "H5Sselect_all");
+
+ ret = H5Dread(did, H5T_NATIVE_INT, msid, sid, H5P_DEFAULT, mem2_buffer);
+ CHECK(ret, FAIL, "H5Dread");
+
+ ret = H5Dclose(did);
+ CHECK(ret, FAIL, "H5Dclose");
+
+ ret = H5Sclose(msid);
+ CHECK(ret, FAIL, "H5Sclose");
+
+ for(i=0; i<2; i++)
+ for(j=0; j<3; j++)
+ if(da_buffer[i][j][0][0] != mem2_buffer[i][j][0][0]) {
+ TestErrPrintf("Read different values than written at index %d,%d,0,0\n", i, j);
+ }
+
+ /* ****** Case 3: ******
+ * Testing the full selection in the middle dimensions */
+ did = H5Dopen2(file, "single_end", H5P_DEFAULT);
+ CHECK(did, FAIL, "H5Dopen");
+
+ /* Select the elements in the dataset */
+ ret = H5Sselect_hyperslab(sid, H5S_SELECT_SET, mem3_start, mem3_stride, mem3_count, mem3_block);
+ CHECK(ret, FAIL, "H5Sselect_hyperslab");
+
+ msid = H5Screate_simple(4, mem3_dims, mem3_dims);
+ CHECK(msid, FAIL, "H5Screate_simple");
+
+ ret = H5Sselect_all(msid);
+ CHECK(ret, FAIL, "H5Sselect_all");
+
+ ret = H5Dread(did, H5T_NATIVE_INT, msid, sid, H5P_DEFAULT, mem3_buffer);
+ CHECK(ret, FAIL, "H5Dread");
+
+ ret = H5Dclose(did);
+ CHECK(ret, FAIL, "H5Dclose");
+
+ ret = H5Sclose(msid);
+ CHECK(ret, FAIL, "H5Sclose");
+
+ for(i=0; i<3; i++)
+ for(j=0; j<6; j++)
+ if(da_buffer[0][i][j][0] != mem3_buffer[0][i][j][0]) {
+ TestErrPrintf("Read different values than written at index 0,%d,%d,0\n", i, j);
+ }
+
+
+ ret = H5Sclose(sid);
+ CHECK(ret, FAIL, "H5Sclose");
+
+ ret = H5Pclose(plid);
+ CHECK(ret, FAIL, "H5Pclose");
}
-/*
-** Read a dataset using the provided parameters.
-*/
-void read_dataset(int rank,
- int* buffer,
- hsize_t* mdims,
- hsize_t* start,
- hsize_t* count,
- hsize_t* stride,
- hsize_t* block)
+
+/***********************************************************
+**
+** test_multiple_end(): Test full hyperslab selection of
+** multiple blocks.
+**
+*************************************************************/
+static void test_multiple_ends(hid_t file)
{
- hid_t fid, dsid, daid, msid, plid;
- herr_t rv;
-
- fid = H5Fopen("coord.hdf", H5F_ACC_RDONLY, H5P_DEFAULT);
- if(fid < 0)
- {
- H5Eprint2(H5E_DEFAULT, stderr);
- exit(1);
- }
+ hid_t sid, plid, did, msid;
+ herr_t ret; /* Generic error return */
+ int i, j, k, l, m, n, p;
+ hsize_t da_dims[8] = { 4, 5, 3, 4, 2, 3, 6, 2 };
+ hsize_t da_chunksize[8] = { 1, 5, 3, 2, 2, 3, 3, 2 };
+ int da_buffer[4][5][3][4][2][3][6][2];
+
+ /* For testing the full selections in the fastest-growing end and in the middle dimensions */
+ int mem1_buffer[1][1][1][4][2][1][6][2];
+ hsize_t mem1_dims[8] = { 1, 1, 1, 4, 2, 1, 6, 2 };
+ hsize_t mem1_start[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };
+ hsize_t mem1_count[8] = { 1, 1, 1, 1, 1, 1, 1, 1 };
+ hsize_t mem1_stride[8] = { 1, 1, 1, 1, 1, 1, 1, 1 };
+ hsize_t mem1_block[8] = { 1, 1, 1, 4, 2, 1, 6, 2 };
+
+ /* For testing the full selections in the slowest-growing end and in the middle dimensions */
+ int mem2_buffer[4][5][1][4][2][1][1][1];
+ hsize_t mem2_dims[8] = { 4, 5, 1, 4, 2, 1, 1, 1 };
+ hsize_t mem2_start[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };
+ hsize_t mem2_count[8] = { 1, 1, 1, 1, 1, 1, 1, 1 };
+ hsize_t mem2_stride[8] = { 1, 1, 1, 1, 1, 1, 1, 1 };
+ hsize_t mem2_block[8] = { 4, 5, 1, 4, 2, 1, 1, 1 };
+
+ /* For testing two unadjacent full selections in the middle dimensions */
+ int mem3_buffer[1][5][3][1][1][3][6][1];
+ hsize_t mem3_dims[8] = { 1, 5, 3, 1, 1, 3, 6, 1 };
+ hsize_t mem3_start[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };
+ hsize_t mem3_count[8] = { 1, 1, 1, 1, 1, 1, 1, 1 };
+ hsize_t mem3_stride[8] = { 1, 1, 1, 1, 1, 1, 1, 1 };
+ hsize_t mem3_block[8] = { 1, 5, 3, 1, 1, 3, 6, 1 };
+
+ /* For testing the full selections in the fastest-growing end and the slowest-growing end */
+ int mem4_buffer[4][5][1][1][1][1][6][2];
+ hsize_t mem4_dims[8] = { 4, 5, 1, 1, 1, 1, 6, 2 };
+ hsize_t mem4_start[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };
+ hsize_t mem4_count[8] = { 1, 1, 1, 1, 1, 1, 1, 1 };
+ hsize_t mem4_stride[8] = { 1, 1, 1, 1, 1, 1, 1, 1 };
+ hsize_t mem4_block[8] = { 4, 5, 1, 1, 1, 1, 6, 2 };
+
+ /* For testing the full selections in the fastest-growing end and slowest-growing end,
+ * also in the middle dimensions */
+ int mem5_buffer[4][5][1][4][2][1][6][2];
+ hsize_t mem5_dims[8] = { 4, 5, 1, 4, 2, 1, 6, 2 };
+ hsize_t mem5_start[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };
+ hsize_t mem5_count[8] = { 1, 1, 1, 1, 1, 1, 1, 1 };
+ hsize_t mem5_stride[8] = { 1, 1, 1, 1, 1, 1, 1, 1 };
+ hsize_t mem5_block[8] = { 4, 5, 1, 4, 2, 1, 6, 2 };
+
+ /* Create and write the dataset */
+ sid = H5Screate_simple(8, da_dims, da_dims);
+ CHECK(sid, FAIL, "H5Screate_simple");
+
+ plid = H5Pcreate(H5P_DATASET_CREATE);
+ CHECK(plid, FAIL, "H5Pcreate");
+
+ ret = H5Pset_chunk(plid, 8, da_chunksize);
+ CHECK(ret, FAIL, "H5Pset_chunk");
+
+ did = H5Dcreate2(file, "multiple_ends", H5T_NATIVE_INT, sid, H5P_DEFAULT, plid, H5P_DEFAULT);
+ CHECK(did, FAIL, "H5Dcreate2");
+
+ for(i=0; i<4; i++)
+ for(j=0; j<5; j++)
+ for(k=0; k<3; k++)
+ for(l=0; l<4; l++)
+ for(m=0; m<2; m++)
+ for(n=0; n<3; n++)
+ for(p=0; p<6; p++) {
+ da_buffer[i][j][k][l][m][n][p][0] = i*1000000 + j*100000 + k*10000 + l*1000 + m*100 + n*10 + p;
+ da_buffer[i][j][k][l][m][n][p][1] = i*1000000 + j*100000 + k*10000 + l*1000 + m*100 + n*10 + p + 1;
+ }
+
+ ret = H5Dwrite(did, H5T_NATIVE_INT, sid, sid, H5P_DEFAULT, da_buffer);
+ CHECK(ret, FAIL, "H5Dwrite");
+
+ ret = H5Dclose(did);
+ CHECK(ret, FAIL, "H5Dclose");
+
+ /* ****** Case 1: ******
+ * Testing the full selections in the fastest-growing end and in the middle dimensions*/
+ did = H5Dopen2(file, "multiple_ends", H5P_DEFAULT);
+ CHECK(did, FAIL, "H5Dopen");
+
+ /* Select the elements in the dataset */
+ ret = H5Sselect_hyperslab(sid, H5S_SELECT_SET, mem1_start, mem1_stride, mem1_count, mem1_block);
+ CHECK(ret, FAIL, "H5Sselect_hyperslab");
+
+ msid = H5Screate_simple(8, mem1_dims, mem1_dims);
+ CHECK(msid, FAIL, "H5Screate_simple");
+
+ ret = H5Sselect_all(msid);
+ CHECK(ret, FAIL, "H5Sselect_all");
+
+ ret = H5Dread(did, H5T_NATIVE_INT, msid, sid, H5P_DEFAULT, mem1_buffer);
+ CHECK(ret, FAIL, "H5Dread");
+
+ ret = H5Dclose(did);
+ CHECK(ret, FAIL, "H5Dclose");
+
+ ret = H5Sclose(msid);
+ CHECK(ret, FAIL, "H5Sclose");
+
+ for(i=0; i<4; i++)
+ for(j=0; j<2; j++)
+ for(k=0; k<6; k++)
+ for(l=0; l<2; l++)
+ if(da_buffer[0][0][0][i][j][0][k][l] != mem1_buffer[0][0][0][i][j][0][k][l]) {
+ TestErrPrintf("Read different values than written at index 0,0,0,%d,%d,0,%d,%d\n", i, j, k, l);
+ }
+
+ /* ****** Case 2: ******
+ * Testing the full selections in the slowest-growing end and in the middle dimensions*/
+ did = H5Dopen2(file, "multiple_ends", H5P_DEFAULT);
+ CHECK(did, FAIL, "H5Dopen");
+
+ /* Select the elements in the dataset */
+ ret = H5Sselect_hyperslab(sid, H5S_SELECT_SET, mem2_start, mem2_stride, mem2_count, mem2_block);
+ CHECK(ret, FAIL, "H5Sselect_hyperslab");
+
+ msid = H5Screate_simple(8, mem2_dims, mem2_dims);
+ CHECK(msid, FAIL, "H5Screate_simple");
+
+ ret = H5Sselect_all(msid);
+ CHECK(ret, FAIL, "H5Sselect_all");
+
+ ret = H5Dread(did, H5T_NATIVE_INT, msid, sid, H5P_DEFAULT, mem2_buffer);
+ CHECK(ret, FAIL, "H5Dread");
+
+ ret = H5Dclose(did);
+ CHECK(ret, FAIL, "H5Dclose");
+
+ ret = H5Sclose(msid);
+ CHECK(ret, FAIL, "H5Sclose");
+
+ for(i=0; i<4; i++)
+ for(j=0; j<5; j++)
+ for(k=0; k<4; k++)
+ for(l=0; l<2; l++)
+ if(da_buffer[i][j][0][k][l][0][0][0] != mem2_buffer[i][j][0][k][l][0][0][0]) {
+ TestErrPrintf("Read different values than written at index %d,%d,0,%d,%d,0,0,0\n", i, j, k, l);
+ }
+
+ /* ****** Case 3: ******
+ * Testing two unadjacent full selections in the middle dimensions */
+ did = H5Dopen2(file, "multiple_ends", H5P_DEFAULT);
+ CHECK(did, FAIL, "H5Dopen");
- daid = H5Dopen2(fid, "dataset", H5P_DEFAULT);
- if(daid < 0)
- {
- H5Eprint2(H5E_DEFAULT, stderr);
- exit(1);
- }
+ /* Select the elements in the dataset */
+ ret = H5Sselect_hyperslab(sid, H5S_SELECT_SET, mem3_start, mem3_stride, mem3_count, mem3_block);
+ CHECK(ret, FAIL, "H5Sselect_hyperslab");
+ msid = H5Screate_simple(8, mem3_dims, mem3_dims);
+ CHECK(msid, FAIL, "H5Screate_simple");
- dsid = H5Dget_space(daid);
- if(dsid < 0)
- {
- H5Eprint2(H5E_DEFAULT, stderr);
- exit(1);
- }
+ ret = H5Sselect_all(msid);
+ CHECK(ret, FAIL, "H5Sselect_all");
- /*
- ** Element selection is used to select 18 elements from the dataset.
- */
-#ifdef TMP
- rv = H5Sselect_elements(dsid, H5S_SELECT_SET, 12, (const hsize_t**)da_elements);
-#else
- rv = H5Sselect_hyperslab(dsid, H5S_SELECT_SET, mem2_start, mem2_stride, mem2_count, mem2_block);
-#endif
- if(rv < 0)
- {
- H5Eprint2(H5E_DEFAULT, stderr);
- exit(1);
- }
+ ret = H5Dread(did, H5T_NATIVE_INT, msid, sid, H5P_DEFAULT, mem3_buffer);
+ CHECK(ret, FAIL, "H5Dread");
- msid = H5Screate_simple(rank, mdims, mdims);
- if(dsid < 0)
- {
- H5Eprint2(H5E_DEFAULT, stderr);
- exit(1);
- }
+ ret = H5Dclose(did);
+ CHECK(ret, FAIL, "H5Dclose");
- /*
- ** The element selection above is combined with hyperslab
- ** selection. The selection is always be a contiguous block. (See
- ** above.)
- */
- rv = H5Sselect_hyperslab(msid, H5S_SELECT_SET, start, stride, count, block);
- if(rv < 0)
- {
- H5Eprint2(H5E_DEFAULT, stderr);
- exit(1);
- }
+ ret = H5Sclose(msid);
+ CHECK(ret, FAIL, "H5Sclose");
- rv = H5Dread(daid, H5T_NATIVE_INT, msid, dsid, H5P_DEFAULT, buffer);
- if(rv < 0)
- {
- H5Eprint2(H5E_DEFAULT, stderr);
- exit(1);
- }
+ for(i=0; i<5; i++)
+ for(j=0; j<3; j++)
+ for(k=0; k<3; k++)
+ for(l=0; l<6; l++)
+ if(da_buffer[0][i][j][0][0][k][l][0] != mem3_buffer[0][i][j][0][0][k][l][0]) {
+ TestErrPrintf("Read different values than written at index 0,%d,%d,0,0,%d,%d,0\n", i, j, k, l);
+ }
- rv = H5Dclose(daid);
- if(rv < 0)
- {
- H5Eprint2(H5E_DEFAULT, stderr);
- exit(1);
- }
+ /* ****** Case 4: ******
+ * Testing the full selections in the fastest-growing end and the slowest-growing end */
+ did = H5Dopen2(file, "multiple_ends", H5P_DEFAULT);
+ CHECK(did, FAIL, "H5Dopen");
- rv = H5Fclose(fid);
- if(rv < 0)
- {
- H5Eprint2(H5E_DEFAULT, stderr);
- exit(1);
- }
+ /* Select the elements in the dataset */
+ ret = H5Sselect_hyperslab(sid, H5S_SELECT_SET, mem4_start, mem4_stride, mem4_count, mem4_block);
+ CHECK(ret, FAIL, "H5Sselect_hyperslab");
+
+ msid = H5Screate_simple(8, mem4_dims, mem4_dims);
+ CHECK(msid, FAIL, "H5Screate_simple");
+
+ ret = H5Sselect_all(msid);
+ CHECK(ret, FAIL, "H5Sselect_all");
+
+ ret = H5Dread(did, H5T_NATIVE_INT, msid, sid, H5P_DEFAULT, mem4_buffer);
+ CHECK(ret, FAIL, "H5Dread");
+
+ ret = H5Dclose(did);
+ CHECK(ret, FAIL, "H5Dclose");
+
+ ret = H5Sclose(msid);
+ CHECK(ret, FAIL, "H5Sclose");
+
+ for(i=0; i<4; i++)
+ for(j=0; j<5; j++)
+ for(k=0; k<6; k++)
+ for(l=0; l<2; l++)
+ if(da_buffer[i][j][0][0][0][0][k][l] != mem4_buffer[i][j][0][0][0][0][k][l]) {
+ TestErrPrintf("Read different values than written at index %d,%d,0,0,0,0,%d,%d\n", i, j, k, l);
+ }
+
+
+ /* ****** Case 5: ******
+ * Testing the full selections in the fastest-growing end and the slowest-growing end,
+ * and also in the middle dimensions */
+ did = H5Dopen2(file, "multiple_ends", H5P_DEFAULT);
+ CHECK(did, FAIL, "H5Dopen");
+
+ /* Select the elements in the dataset */
+ ret = H5Sselect_hyperslab(sid, H5S_SELECT_SET, mem5_start, mem5_stride, mem5_count, mem5_block);
+ CHECK(ret, FAIL, "H5Sselect_hyperslab");
+
+ msid = H5Screate_simple(8, mem5_dims, mem5_dims);
+ CHECK(msid, FAIL, "H5Screate_simple");
+
+ ret = H5Sselect_all(msid);
+ CHECK(ret, FAIL, "H5Sselect_all");
+
+ ret = H5Dread(did, H5T_NATIVE_INT, msid, sid, H5P_DEFAULT, mem5_buffer);
+ CHECK(ret, FAIL, "H5Dread");
+
+ ret = H5Dclose(did);
+ CHECK(ret, FAIL, "H5Dclose");
+
+ ret = H5Sclose(msid);
+ CHECK(ret, FAIL, "H5Sclose");
+
+ for(i=0; i<4; i++)
+ for(j=0; j<5; j++)
+ for(k=0; k<4; k++)
+ for(l=0; l<2; l++)
+ for(m=0; m<6; m++)
+ for(n=0; n<2; n++)
+ if(da_buffer[i][j][0][k][l][0][m][n] != mem5_buffer[i][j][0][k][l][0][m][n]) {
+ TestErrPrintf("Read different values than written at index %d,%d,0,%d,%d,0,%d,%d\n", i, j, k, l, m, n);
+ }
+
+
+ ret = H5Sclose(sid);
+ CHECK(ret, FAIL, "H5Sclose");
+
+ ret = H5Pclose(plid);
+ CHECK(ret, FAIL, "H5Pclose");
}
+
+/****************************************************************
+**
+** test_coords(): Main testing routine.
+**
+****************************************************************/
void test_coords(void)
{
- int i, j;
-
- write_dataset();
-
- /* 1.
- ** Use a rank=2 in memory array. (See above)
- */
- memset(mem1_buffer, 0, sizeof(mem1_buffer));
- read_dataset(2, (int*)mem1_buffer, mem1_dims, mem1_start, mem1_count, mem1_stride, mem1_block);
- for(i = 0; i < 6; i++)
- {
- for(j=0; j<2; j++)
- if(da_buffer[11][0][i][j] != mem1_buffer[i][j])
- TestErrPrintf(" %3d %3d\n", mem1_buffer[i][j], mem1_buffer[i][j]);
- }
-
- /* 2.
- ** Use a rank=4 in memory array. Make the array smaller and select
- ** the whole array. (See above)
- */
- memset(mem2_buffer, 0, sizeof(mem2_buffer));
- read_dataset(4, (int*)mem2_buffer, mem2_dims, mem2_start, mem2_count, mem2_stride, mem2_block);
- for(i = 0; i < 6; i++)
- {
- for(j=0; j<2; j++)
- if(da_buffer[11][0][i][j] != mem2_buffer[0][0][i][j])
- TestErrPrintf(" %3d %3d\n", mem2_buffer[0][0][i][j], mem2_buffer[0][0][i][j]);
- }
-
- /* 3.
- ** Use a rank=4 in memory array, but don't select the whole array. (See above)
- */
- memset(mem3_buffer, 0, sizeof(mem3_buffer));
- read_dataset(4, (int*)mem3_buffer, mem3_dims, mem3_start, mem3_count, mem3_stride, mem3_block);
- for(i = 0; i < 6; i++)
- {
- for(j=0; j<2; j++)
- if(da_buffer[11][0][i][j] != mem3_buffer[0][0][i][j])
- TestErrPrintf(" %3d %3d\n", mem3_buffer[0][0][i][j], mem3_buffer[0][0][i][j]);
+ hid_t fid;
+ herr_t ret; /* Generic error return */
- }
+ fid = H5Fcreate("coord.h5", H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
+ CHECK(fid, FAIL, "H5Fcreate");
- /* 4.
- ** Use a rank=3 in memory array. (See above)
- */
- memset(mem4_buffer, 0, sizeof(mem4_buffer));
- read_dataset(3, (int*)mem4_buffer, mem4_dims, mem4_start, mem4_count, mem4_stride, mem4_block);
- for(i = 0; i < 6; i++)
- {
- for(j=0; j<2; j++)
- if(da_buffer[11][0][i][j] != mem4_buffer[0][i][j])
- TestErrPrintf(" %3d %3d\n", mem4_buffer[0][i][j], mem4_buffer[0][i][j]);
- }
+ test_single_end(fid);
+ test_multiple_ends(fid);
+ ret = H5Fclose(fid);
+ CHECK(ret, FAIL, "H5Fclose");
}
@@ -398,5 +491,5 @@ void test_coords(void)
void
cleanup_coords(void)
{
- remove("coord.hdf");
+ remove("coord.h5");
}