From a594026a470785ae882d5a822b2ac50866038615 Mon Sep 17 00:00:00 2001 From: Raymond Lu Date: Wed, 9 Jan 2008 16:32:25 -0500 Subject: [svn-r14386] Bug fix for #956. The calculation of the coordinates for dataspace selection went wrong when the selection of some dimensions are full and these dimensions are optimized through "flattenning". The calculation of the coordinates wasn't general enough in H5Shyper.c. Also added a test program for it. Tested on smirom only because the same code was tested on 3 platforms for v1.8. --- c++/configure | 2 +- configure | 2 +- fortran/configure | 2 +- src/H5Shyper.c | 66 ++++++-- src/H5Sprivate.h | 1 + test/Makefile.in | 4 +- test/tcoords.c | 495 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ test/testhdf5.c | 1 + test/testhdf5.h | 2 + 9 files changed, 558 insertions(+), 17 deletions(-) create mode 100644 test/tcoords.c diff --git a/c++/configure b/c++/configure index 03d45ef..e2d73c3 100755 --- a/c++/configure +++ b/c++/configure @@ -1,5 +1,5 @@ #! /bin/sh -# From c++/configure.in Id: configure.in 14330 2007-12-09 23:52:11Z hdftest . +# From c++/configure.in Id: configure.in 14347 2007-12-16 23:54:09Z hdftest . # Guess values for system-dependent variables and create Makefiles. # Generated by GNU Autoconf 2.61 for HDF5 C++ 1.6.6-post4. # diff --git a/configure b/configure index fa028e8..17f700b 100755 --- a/configure +++ b/configure @@ -1,5 +1,5 @@ #! /bin/sh -# From configure.in Id: configure.in 14330 2007-12-09 23:52:11Z hdftest . +# From configure.in Id: configure.in 14347 2007-12-16 23:54:09Z hdftest . # Guess values for system-dependent variables and create Makefiles. # Generated by GNU Autoconf 2.61 for HDF5 1.6.6-post4. # diff --git a/fortran/configure b/fortran/configure index e9df295..7d9085d 100755 --- a/fortran/configure +++ b/fortran/configure @@ -1,5 +1,5 @@ #! /bin/sh -# From fortran/configure.in Id: configure.in 14330 2007-12-09 23:52:11Z hdftest . +# From fortran/configure.in Id: configure.in 14347 2007-12-16 23:54:09Z hdftest . # Guess values for system-dependent variables and create Makefiles. # Generated by GNU Autoconf 2.61 for HDF5 Fortran 1.6.6-post4. # diff --git a/src/H5Shyper.c b/src/H5Shyper.c index 81b9d1c..9aa1748 100644 --- a/src/H5Shyper.c +++ b/src/H5Shyper.c @@ -267,9 +267,13 @@ H5S_hyper_iter_init(H5S_sel_iter_t *iter, const H5S_t *space) if(iter->elmt_size>0) { /* Check for any "contiguous" blocks that can be flattened */ for(u=rank-1; u>0; u--) { - if(tdiminfo[u].count==1 && tdiminfo[u].block==mem_size[u]) + if(tdiminfo[u].count==1 && tdiminfo[u].block==mem_size[u]) { cont_dim++; + iter->u.hyp.flattened[u] = TRUE; + } else + iter->u.hyp.flattened[u] = FALSE; } /* end for */ + iter->u.hyp.flattened[0] = FALSE; } /* end if */ /* Check if the regular selection can be "flattened" */ @@ -402,7 +406,9 @@ H5S_hyper_iter_init(H5S_sel_iter_t *iter, const H5S_t *space) * Tuesday, April 22, 2003 * * Modifications: - * + * Raymond Lu + * 9 January 2008 + * Modified the algorithm to cover general cases. *------------------------------------------------------------------------- */ static herr_t @@ -419,23 +425,59 @@ H5S_hyper_iter_coords (const H5S_sel_iter_t *iter, hsize_t *coords) /* Check for a single "regular" hyperslab */ if(iter->u.hyp.diminfo_valid) { /* Check if this is a "flattened" regular hyperslab selection */ - if(iter->u.hyp.iter_rank!=0 && iter->u.hyp.iter_rankrank) { - unsigned flat_dim; /* The rank of the flattened dimension */ + if(iter->u.hyp.iter_rank != 0 && iter->u.hyp.iter_rank < iter->rank) { + int u, v; /* Dimension indices */ + + /* Set the starting rank of both the "natural" & "flattened" dimensions */ + u = iter->rank - 1; + v = iter->u.hyp.iter_rank - 1; + + /* Construct the "natural" dimensions from a set of flattened coordinates */ + while(u >= 0) { + if(iter->u.hyp.flattened[u]) { + int begin = u; /* The rank of the first flattened dimension */ + + /* Walk up through as many flattened dimensions as possible */ + do { + u--; + } while(u >= 0 && iter->u.hyp.flattened[u]); - /* Get the rank of the flattened dimension */ - flat_dim=iter->u.hyp.iter_rank-1; + /* Compensate for possibly overshooting dim 0 */ + if(u < 0) + u = 0; - /* Copy the coordinates up to where things got flattened */ - HDmemcpy(coords,iter->u.hyp.off,sizeof(hsize_t)*flat_dim); + /* Sanity check */ + HDassert(v >= 0); - /* Compute the coordinates for the flattened dimensions */ - H5V_array_calc(iter->u.hyp.off[flat_dim],iter->rank-flat_dim,&(iter->dims[flat_dim]),&(coords[flat_dim])); + /* Compute the coords for the flattened dimensions */ + H5V_array_calc(iter->u.hyp.off[v], (unsigned)((begin - u) + 1), &(iter->dims[u]), &(coords[u])); + + /* Continue to faster dimension in both indices */ + u--; + v--; + } /* end if */ + else { + /* Walk up through as many non-flattened dimensions as possible */ + while(u >= 0 && !iter->u.hyp.flattened[u]) { + /* Sanity check */ + HDassert(v >= 0); + + /* Copy the coordinate */ + coords[u] = iter->u.hyp.off[v]; + + /* Continue to faster dimension in both indices */ + u--; + v--; + } /* end while */ + } /* end else */ + } /* end while */ + HDassert(v < 0); } /* end if */ else - HDmemcpy(coords,iter->u.hyp.off,sizeof(hsize_t)*iter->rank); + HDmemcpy(coords, iter->u.hyp.off, sizeof(hsize_t) * iter->rank); } /* end if */ else - HDmemcpy(coords,iter->u.hyp.off,sizeof(hsize_t)*iter->rank); + HDmemcpy(coords, iter->u.hyp.off, sizeof(hsize_t) * iter->rank); FUNC_LEAVE_NOAPI(SUCCEED); } /* H5S_hyper_iter_coords() */ diff --git a/src/H5Sprivate.h b/src/H5Sprivate.h index 779bd56..172489d 100644 --- a/src/H5Sprivate.h +++ b/src/H5Sprivate.h @@ -78,6 +78,7 @@ typedef struct { H5S_hyper_dim_t diminfo[H5S_MAX_RANK]; /* "Flattened" regular selection information */ hsize_t size[H5S_MAX_RANK]; /* "Flattened" dataspace extent information */ hssize_t sel_off[H5S_MAX_RANK]; /* "Flattened" selection offset information */ + hbool_t flattened[H5S_MAX_RANK]; /* Whether this dimension has been flattened */ /* Irregular hyperslab selection fields */ H5S_hyper_span_info_t *spans; /* Pointer to copy of the span tree */ diff --git a/test/Makefile.in b/test/Makefile.in index d2e4814..a3137be 100644 --- a/test/Makefile.in +++ b/test/Makefile.in @@ -51,7 +51,7 @@ MOSTLYCLEAN=cmpd_dset.h5 compact_dataset.h5 dataset.h5 extend.h5 istore.h5 \ tfile[1-3].h5 th5s1.h5 th5s3.h5 lheap.h5 ohdr.h5 stab[1-2].h5 \ extern_[1-3].h5 extern_[1-4][ab].raw gheap[0-4].h5 \ links.h5 links[1-3].h5 big.data big[0-9][0-9][0-9][0-9][0-9].h5 \ - sec2.h5 stdio.h5 dtypes[1-7].h5 tattr.h5 \ + sec2.h5 stdio.h5 dtypes[1-7].h5 tattr.h5 coord.h5 \ tselect.h5 mtime.h5 unlink.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 \ @@ -107,7 +107,7 @@ check test _test: $(TEST_PROGS) $(TEST_PROGS): $(LIB) $(LIBHDF5) TESTHDF5_OBJ=testhdf5.lo tarray.lo tattr.lo tconfig.lo tfile.lo \ - tgenprop.lo th5s.lo theap.lo titerate.lo tmeta.lo tmisc.lo \ + tgenprop.lo th5s.lo tcoords.lo theap.lo titerate.lo tmeta.lo tmisc.lo \ trefer.lo trefstr.lo tselect.lo tskiplist.lo ttime.lo ttst.lo \ tvltypes.lo tvlstr.lo diff --git a/test/tcoords.c b/test/tcoords.c new file mode 100644 index 0000000..8ecf75d --- /dev/null +++ b/test/tcoords.c @@ -0,0 +1,495 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * Copyright by The HDF Group. * + * Copyright by the Board of Trustees of the University of Illinois. * + * All rights reserved. * + * * + * This file is part of HDF5. The full HDF5 copyright notice, including * + * terms governing use, modification, and redistribution, is contained in * + * the files COPYING and Copyright.html. COPYING can be found at the root * + * of the source code distribution tree; Copyright.html can be found at the * + * root level of an installed copy of the electronic HDF5 document set and * + * is linked from the top-level documents page. It can also be found at * + * http://hdfgroup.org/HDF5/doc/Copyright.html. If you do not have * + * access to either file, you may request a copy from help@hdfgroup.org. * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +/*********************************************************** +* +* Test program: tcoords +* +* 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" + +/*********************************************************** +** +** test_single_end(): Test full hyperslab selection of only +** one block. +** +*************************************************************/ +static void test_single_end(hid_t file) +{ + 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 = H5Dcreate(file, "single_end", H5T_NATIVE_INT, sid, plid); + CHECK(did, FAIL, "H5Dcreate"); + + 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; + } + } + } + + 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 selection in the fastest-growing end */ + did = H5Dopen(file, "single_end"); + 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(4, 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<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 = H5Dopen(file, "single_end"); + 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 = H5Dopen(file, "single_end"); + 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"); +} + + +/*********************************************************** +** +** test_multiple_end(): Test full hyperslab selection of +** multiple blocks. +** +*************************************************************/ +static void test_multiple_ends(hid_t file) +{ + 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 = H5Dcreate(file, "multiple_ends", H5T_NATIVE_INT, sid, plid); + CHECK(did, FAIL, "H5Dcreate"); + + 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 = H5Dopen(file, "multiple_ends"); + 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 = H5Dopen(file, "multiple_ends"); + 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 = H5Dopen(file, "multiple_ends"); + 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(8, 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<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); + } + + /* ****** Case 4: ****** + * Testing the full selections in the fastest-growing end and the slowest-growing end */ + did = H5Dopen(file, "multiple_ends"); + CHECK(did, FAIL, "H5Dopen"); + + /* 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 = H5Dopen(file, "multiple_ends"); + 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) +{ + hid_t fid; + herr_t ret; /* Generic error return */ + + fid = H5Fcreate("coord.h5", H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT); + CHECK(fid, FAIL, "H5Fcreate"); + + test_single_end(fid); + test_multiple_ends(fid); + + ret = H5Fclose(fid); + CHECK(ret, FAIL, "H5Fclose"); +} + + +/*------------------------------------------------------------------------- + * Function: cleanup_coords + * + * Purpose: Cleanup temporary test files + * + * Return: none + * + * Programmer: Raymond Lu + * 20 Dec. 2007 + * + * Modifications: + * + *------------------------------------------------------------------------- + */ +void +cleanup_coords(void) +{ + remove("coord.h5"); +} diff --git a/test/testhdf5.c b/test/testhdf5.c index 9d85b08..6065d64 100644 --- a/test/testhdf5.c +++ b/test/testhdf5.c @@ -52,6 +52,7 @@ main(int argc, char *argv[]) AddTest("refstr", test_refstr, NULL, "Reference Counted Strings", NULL); AddTest("file", test_file, cleanup_file, "Low-Level File I/O", NULL); AddTest("h5s", test_h5s, cleanup_h5s, "Dataspaces", NULL); + AddTest("coords", test_coords, cleanup_coords, "Dataspace coordinates", NULL); AddTest("attr", test_attr, cleanup_attr, "Attributes", NULL); AddTest("select", test_select, cleanup_select, "Selections", NULL); AddTest("time", test_time, cleanup_time, "Time Datatypes", NULL); diff --git a/test/testhdf5.h b/test/testhdf5.h index 0bc00d7..777ec1d 100644 --- a/test/testhdf5.h +++ b/test/testhdf5.h @@ -130,6 +130,7 @@ void test_refstr(void); void test_file(void); void test_h5t(void); void test_h5s(void); +void test_coords(void); void test_h5d(void); void test_attr(void); void test_select(void); @@ -148,6 +149,7 @@ void test_skiplist(void); void cleanup_metadata(void); void cleanup_file(void); void cleanup_h5s(void); +void cleanup_coords(void); void cleanup_attr(void); void cleanup_select(void); void cleanup_time(void); -- cgit v0.12