diff options
-rw-r--r-- | test/tselect.c | 590 |
1 files changed, 573 insertions, 17 deletions
diff --git a/test/tselect.c b/test/tselect.c index 6a9d8d1..32b7226 100644 --- a/test/tselect.c +++ b/test/tselect.c @@ -38,6 +38,8 @@ #define SPACE2_RANK 2 #define SPACE2_DIM1 30 #define SPACE2_DIM2 26 +#define SPACE2A_RANK 1 +#define SPACE2A_DIM1 (SPACE2_DIM1*SPACE2_DIM2) /* 2-D dataset with fixed dimensions */ #define SPACE3_NAME "Space3" @@ -1041,10 +1043,8 @@ test_select_hyper_stride(void) tbuf2=rbuf+loc2[i]; if(*tbuf!=*tbuf2) { printf("%d: hyperslab values don't match!, loc1[%d]=%d, loc2[%d]=%d\n",__LINE__,i,(int)loc1[i],i,(int)loc2[i]); -#ifndef QAK printf("wbuf=%p, tbuf=%p, rbuf=%p, tbuf2=%p\n",wbuf,tbuf,rbuf,tbuf2); printf("*tbuf=%u, *tbuf2=%u\n",(unsigned)*tbuf,(unsigned)*tbuf2); -#endif /* QAK */ num_errs++; } /* end if */ } /* end for */ @@ -1068,7 +1068,7 @@ test_select_hyper_stride(void) /* Free memory buffers */ free(wbuf); free(rbuf); -} /* test_select_hyper() */ +} /* test_select_hyper_stride() */ /**************************************************************** ** @@ -1931,6 +1931,9 @@ test_select_hyper_union(void) ret = H5Sselect_hyperslab(sid1,H5S_SELECT_SET,start,stride,count,block); CHECK(ret, FAIL, "H5Sselect_hyperslab"); + npoints = H5Sget_select_npoints(sid1); + VERIFY(npoints, 2*15*13, "H5Sget_select_npoints"); + /* Select 8x26 hyperslab for memory dataset */ start[0]=15; start[1]=0; stride[0]=1; stride[1]=1; @@ -2384,10 +2387,12 @@ test_select_hyper_union(void) free(rbuf); } /* test_select_hyper_union() */ +#ifdef NEW_HYPERSLAB_API /**************************************************************** ** ** test_select_hyper_union_stagger(): Test basic H5S (dataspace) selection code. -** Tests unions of staggered hyperslabs +** Tests unions of staggered hyperslabs. (Uses H5Scombine_hyperslab +** and H5Sselect_select instead of H5Sselect_hyperslab) ** ****************************************************************/ static void @@ -2397,6 +2402,8 @@ test_select_hyper_union_stagger(void) hid_t dset_id; /* Dataset ID */ hid_t dataspace; /* File dataspace ID */ hid_t memspace; /* Memory dataspace ID */ + hid_t tmp_space; /* Temporary dataspace ID */ + hid_t tmp2_space; /* Another emporary dataspace ID */ hsize_t dimsm[2]={7,7}; /* Memory array dimensions */ hsize_t dimsf[2]={6,5}; /* File array dimensions */ hsize_t count[2]={3,1}; /* 1st Hyperslab size */ @@ -2479,11 +2486,19 @@ test_select_hyper_union_stagger(void) /* Select the hyperslabs */ error=H5Sselect_hyperslab(dataspace,H5S_SELECT_SET,offset,stride,count,block); CHECK(error, FAIL, "H5Sselect_hyperslab"); - error=H5Sselect_hyperslab(dataspace,H5S_SELECT_OR,offset2,stride,count2,block); - CHECK(error, FAIL, "H5Sselect_hyperslab"); - error=H5Sselect_hyperslab(dataspace,H5S_SELECT_OR,offset3,stride,count3,block); + tmp_space=H5Scombine_hyperslab(dataspace,H5S_SELECT_OR,offset2,stride,count2,block); + CHECK(tmp_space, FAIL, "H5Scombine_hyperslab"); + + /* Copy the file dataspace and select hyperslab */ + tmp2_space=H5Scopy(dataspace); + CHECK(tmp2_space, FAIL, "H5Scopy"); + error=H5Sselect_hyperslab(tmp2_space,H5S_SELECT_SET,offset3,stride,count3,block); CHECK(error, FAIL, "H5Sselect_hyperslab"); + /* Combine the copied dataspace with the temporary dataspace */ + error=H5Sselect_select(tmp_space,H5S_SELECT_OR,tmp2_space); + CHECK(error, FAIL, "H5Sselect_select"); + /* Create Memory Dataspace */ memspace=H5Screate_simple(memrank,dimsm,NULL); CHECK(memspace, FAIL, "H5Screate_simple"); @@ -2493,7 +2508,7 @@ test_select_hyper_union_stagger(void) CHECK(error, FAIL, "H5Sselect_hyperslab"); /* Read File Dataset */ - error=H5Dread(dset_id,H5T_NATIVE_INT,memspace,dataspace,H5P_DEFAULT,data_out); + error=H5Dread(dset_id,H5T_NATIVE_INT,memspace,tmp_space,H5P_DEFAULT,data_out); CHECK(error, FAIL, "H5Dread"); /* Verify input data */ @@ -2509,6 +2524,10 @@ test_select_hyper_union_stagger(void) } /* end for */ /* Close things */ + error=H5Sclose(tmp2_space); + CHECK(error, FAIL, "H5Sclose"); + error=H5Sclose(tmp_space); + CHECK(error, FAIL, "H5Sclose"); error=H5Sclose(dataspace); CHECK(error, FAIL, "H5Sclose"); error=H5Sclose(memspace); @@ -2522,7 +2541,8 @@ test_select_hyper_union_stagger(void) /**************************************************************** ** ** test_select_hyper_union_3d(): Test basic H5S (dataspace) selection code. -** Tests unions of hyperslabs in 3-D +** Tests unions of hyperslabs in 3-D (Uses H5Scombine_hyperslab +** and H5Scombine_select instead of H5Sselect_hyperslab) ** ****************************************************************/ static void @@ -2531,6 +2551,8 @@ test_select_hyper_union_3d(void) hid_t fid1; /* HDF5 File IDs */ hid_t dataset; /* Dataset ID */ hid_t sid1,sid2; /* Dataspace ID */ + hid_t tmp_space; /* Temporary Dataspace ID */ + hid_t tmp2_space; /* Another temporary Dataspace ID */ hsize_t dims1[] = {SPACE1_DIM1, SPACE1_DIM2, SPACE1_DIM3}; hsize_t dims2[] = {SPACE4_DIM1, SPACE4_DIM2, SPACE4_DIM3}; hsize_t dims3[] = {SPACE3_DIM1, SPACE3_DIM2}; @@ -2648,19 +2670,29 @@ test_select_hyper_union_3d(void) stride[0]=1; stride[1]=1; stride[2]=1; count[0]=6; count[1]=6; count[2]=8; block[0]=1; block[1]=1; block[2]=1; - ret = H5Sselect_hyperslab(sid2,H5S_SELECT_OR,start,stride,count,block); - CHECK(ret, FAIL, "H5Sselect_hyperslab"); + tmp_space = H5Scombine_hyperslab(sid2,H5S_SELECT_SET,start,stride,count,block); + CHECK(tmp_space, FAIL, "H5Sselect_hyperslab"); - npoints = H5Sget_select_npoints(sid2); + /* Combine dataspaces and create new dataspace */ + tmp2_space = H5Scombine_select(sid2,H5S_SELECT_OR,tmp_space); + CHECK(tmp2_space, FAIL, "H5Scombin_select"); + + npoints = H5Sget_select_npoints(tmp2_space); VERIFY(npoints, 15*26, "H5Sget_select_npoints"); /* 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); + ret=H5Dwrite(dataset,H5T_NATIVE_UCHAR,tmp2_space,sid1,H5P_DEFAULT,wbuf); CHECK(ret, FAIL, "H5Dwrite"); + /* Close temporary dataspaces */ + ret = H5Sclose(tmp_space); + CHECK(ret, FAIL, "H5Sclose"); + ret = H5Sclose(tmp2_space); + CHECK(ret, FAIL, "H5Sclose"); + /* Close memory dataspace */ ret = H5Sclose(sid2); CHECK(ret, FAIL, "H5Sclose"); @@ -2715,6 +2747,515 @@ test_select_hyper_union_3d(void) /**************************************************************** ** +** test_select_hyper_and_2d(): Test basic H5S (dataspace) selection code. +** Tests 'and' of hyperslabs in 2-D +** +****************************************************************/ +static void +test_select_hyper_and_2d(void) +{ + hid_t fid1; /* HDF5 File IDs */ + hid_t dataset; /* Dataset ID */ + hid_t sid1,sid2; /* Dataspace ID */ + hsize_t dims1[] = {SPACE2_DIM1, SPACE2_DIM2}; + hsize_t dims2[] = {SPACE2A_DIM1}; + hssize_t start[SPACE2_RANK]; /* Starting location of hyperslab */ + hsize_t stride[SPACE2_RANK]; /* Stride of hyperslab */ + hsize_t count[SPACE2_RANK]; /* Element count of hyperslab */ + hsize_t block[SPACE2_RANK]; /* Block size of hyperslab */ + uint8_t *wbuf, /* buffer to write to disk */ + *rbuf, /* buffer read from disk */ + *tbuf, /* temporary buffer pointer */ + *tbuf2; /* temporary buffer pointer */ + int i,j; /* Counters */ + herr_t ret; /* Generic return value */ + hsize_t npoints; /* Number of elements in selection */ + + /* Output message about test being performed */ + MESSAGE(5, ("Testing Hyperslab Selection Functions with intersection of 2-D hyperslabs\n")); + + /* Allocate write & read buffers */ + wbuf=malloc(sizeof(uint8_t)*SPACE2_DIM1*SPACE2_DIM2); + rbuf=calloc(sizeof(uint8_t),SPACE2_DIM1*SPACE2_DIM2); + + /* Initialize write buffer */ + for(i=0, tbuf=wbuf; i<SPACE2_DIM1; i++) + for(j=0; j<SPACE2_DIM2; j++) + *tbuf++=(uint8_t)((i*SPACE2_DIM2)+j); + + /* Create file */ + fid1 = H5Fcreate(FILENAME, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT); + CHECK(fid1, FAIL, "H5Fcreate"); + + /* Create dataspace for dataset on disk */ + sid1 = H5Screate_simple(SPACE2_RANK, dims1, NULL); + CHECK(sid1, FAIL, "H5Screate_simple"); + + /* Create dataspace for writing buffer */ + sid2 = H5Screate_simple(SPACE2A_RANK, dims2, NULL); + CHECK(sid2, FAIL, "H5Screate_simple"); + + /* Select 10x10 hyperslab for disk dataset */ + start[0]=0; start[1]=0; + stride[0]=1; stride[1]=1; + count[0]=10; count[1]=10; + block[0]=1; block[1]=1; + ret = H5Sselect_hyperslab(sid1,H5S_SELECT_SET,start,stride,count,block); + CHECK(ret, FAIL, "H5Sselect_hyperslab"); + + /* Intersect overlapping 10x10 hyperslab */ + start[0]=5; start[1]=5; + stride[0]=1; stride[1]=1; + count[0]=10; count[1]=10; + block[0]=1; block[1]=1; + ret = H5Sselect_hyperslab(sid1,H5S_SELECT_AND,start,stride,count,block); + CHECK(ret, FAIL, "H5Sselect_hyperslab"); + + npoints = H5Sget_select_npoints(sid1); + VERIFY(npoints, 5*5, "H5Sget_select_npoints"); + + /* Select 25 hyperslab for memory dataset */ + start[0]=0; + stride[0]=1; + count[0]=25; + block[0]=1; + ret = H5Sselect_hyperslab(sid2,H5S_SELECT_SET,start,stride,count,block); + CHECK(ret, FAIL, "H5Sselect_hyperslab"); + + npoints = H5Sget_select_npoints(sid2); + VERIFY(npoints, 5*5, "H5Sget_select_npoints"); + + /* 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"); + + /* Read entire dataset from disk */ + ret=H5Dread(dataset,H5T_NATIVE_UCHAR,H5S_ALL,H5S_ALL,H5P_DEFAULT,rbuf); + CHECK(ret, FAIL, "H5Dread"); + + /* Initialize write buffer */ + for(i=0, tbuf=rbuf, tbuf2=wbuf; i<SPACE2_DIM1; i++) + for(j=0; j<SPACE2_DIM2; j++, tbuf++) { + if((i>=5 && i<=9) && (j>=5 && j<=9)) { + if(*tbuf!=*tbuf2) + printf("%d: hyperslab values don't match!, i=%d, j=%d, *tbuf=%d, *tbuf2=%d\n",__LINE__,i,j,(int)*tbuf,(int)*tbuf2); + tbuf2++; + } /* end if */ + else { + if(*tbuf!=0) + printf("%d: hyperslab element has wrong value!, i=%d, j=%d, *tbuf=%d\n",__LINE__,i,j,(int)*tbuf); + } /* end else */ + } /* 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_and_2d() */ + +/**************************************************************** +** +** test_select_hyper_xor_2d(): Test basic H5S (dataspace) selection code. +** Tests 'xor' of hyperslabs in 2-D +** +****************************************************************/ +static void +test_select_hyper_xor_2d(void) +{ + hid_t fid1; /* HDF5 File IDs */ + hid_t dataset; /* Dataset ID */ + hid_t sid1,sid2; /* Dataspace ID */ + hsize_t dims1[] = {SPACE2_DIM1, SPACE2_DIM2}; + hsize_t dims2[] = {SPACE2A_DIM1}; + hssize_t start[SPACE2_RANK]; /* Starting location of hyperslab */ + hsize_t stride[SPACE2_RANK]; /* Stride of hyperslab */ + hsize_t count[SPACE2_RANK]; /* Element count of hyperslab */ + hsize_t block[SPACE2_RANK]; /* Block size of hyperslab */ + uint8_t *wbuf, /* buffer to write to disk */ + *rbuf, /* buffer read from disk */ + *tbuf, /* temporary buffer pointer */ + *tbuf2; /* temporary buffer pointer */ + int i,j; /* Counters */ + herr_t ret; /* Generic return value */ + hsize_t npoints; /* Number of elements in selection */ + + /* Output message about test being performed */ + MESSAGE(5, ("Testing Hyperslab Selection Functions with XOR of 2-D hyperslabs\n")); + + /* Allocate write & read buffers */ + wbuf=malloc(sizeof(uint8_t)*SPACE2_DIM1*SPACE2_DIM2); + rbuf=calloc(sizeof(uint8_t),SPACE2_DIM1*SPACE2_DIM2); + + /* Initialize write buffer */ + for(i=0, tbuf=wbuf; i<SPACE2_DIM1; i++) + for(j=0; j<SPACE2_DIM2; j++) + *tbuf++=(uint8_t)((i*SPACE2_DIM2)+j); + + /* Create file */ + fid1 = H5Fcreate(FILENAME, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT); + CHECK(fid1, FAIL, "H5Fcreate"); + + /* Create dataspace for dataset on disk */ + sid1 = H5Screate_simple(SPACE2_RANK, dims1, NULL); + CHECK(sid1, FAIL, "H5Screate_simple"); + + /* Create dataspace for writing buffer */ + sid2 = H5Screate_simple(SPACE2A_RANK, dims2, NULL); + CHECK(sid2, FAIL, "H5Screate_simple"); + + /* Select 10x10 hyperslab for disk dataset */ + start[0]=0; start[1]=0; + stride[0]=1; stride[1]=1; + count[0]=10; count[1]=10; + block[0]=1; block[1]=1; + ret = H5Sselect_hyperslab(sid1,H5S_SELECT_SET,start,stride,count,block); + CHECK(ret, FAIL, "H5Sselect_hyperslab"); + + /* Intersect overlapping 10x10 hyperslab */ + start[0]=5; start[1]=5; + stride[0]=1; stride[1]=1; + count[0]=10; count[1]=10; + block[0]=1; block[1]=1; + ret = H5Sselect_hyperslab(sid1,H5S_SELECT_XOR,start,stride,count,block); + CHECK(ret, FAIL, "H5Sselect_hyperslab"); + + npoints = H5Sget_select_npoints(sid1); + VERIFY(npoints, 150, "H5Sget_select_npoints"); + + /* Select 25 hyperslab for memory dataset */ + start[0]=0; + stride[0]=1; + count[0]=150; + block[0]=1; + ret = H5Sselect_hyperslab(sid2,H5S_SELECT_SET,start,stride,count,block); + CHECK(ret, FAIL, "H5Sselect_hyperslab"); + + npoints = H5Sget_select_npoints(sid2); + VERIFY(npoints, 150, "H5Sget_select_npoints"); + + /* 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"); + + /* Read entire dataset from disk */ + ret=H5Dread(dataset,H5T_NATIVE_UCHAR,H5S_ALL,H5S_ALL,H5P_DEFAULT,rbuf); + CHECK(ret, FAIL, "H5Dread"); + + /* Initialize write buffer */ + for(i=0, tbuf=rbuf, tbuf2=wbuf; i<SPACE2_DIM1; i++) + for(j=0; j<SPACE2_DIM2; j++, tbuf++) { + if(((i>=0 && i<=4) && (j>=0 && j<=9)) || + ((i>=5 && i<=9) && ((j>=0 && j<=4) || (j>=10 && j<=14))) || + ((i>=10 && i<=14) && (j>=5 && j<=14))) { + if(*tbuf!=*tbuf2) + printf("%d: hyperslab values don't match!, i=%d, j=%d, *tbuf=%d, *tbuf2=%d\n",__LINE__,i,j,(int)*tbuf,(int)*tbuf2); + tbuf2++; + } /* end if */ + else { + if(*tbuf!=0) + printf("%d: hyperslab element has wrong value!, i=%d, j=%d, *tbuf=%d\n",__LINE__,i,j,(int)*tbuf); + } /* end else */ + } /* 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_xor_2d() */ + +/**************************************************************** +** +** test_select_hyper_notb_2d(): Test basic H5S (dataspace) selection code. +** Tests 'notb' of hyperslabs in 2-D +** +****************************************************************/ +static void +test_select_hyper_notb_2d(void) +{ + hid_t fid1; /* HDF5 File IDs */ + hid_t dataset; /* Dataset ID */ + hid_t sid1,sid2; /* Dataspace ID */ + hsize_t dims1[] = {SPACE2_DIM1, SPACE2_DIM2}; + hsize_t dims2[] = {SPACE2A_DIM1}; + hssize_t start[SPACE2_RANK]; /* Starting location of hyperslab */ + hsize_t stride[SPACE2_RANK]; /* Stride of hyperslab */ + hsize_t count[SPACE2_RANK]; /* Element count of hyperslab */ + hsize_t block[SPACE2_RANK]; /* Block size of hyperslab */ + uint8_t *wbuf, /* buffer to write to disk */ + *rbuf, /* buffer read from disk */ + *tbuf, /* temporary buffer pointer */ + *tbuf2; /* temporary buffer pointer */ + int i,j; /* Counters */ + herr_t ret; /* Generic return value */ + hsize_t npoints; /* Number of elements in selection */ + + /* Output message about test being performed */ + MESSAGE(5, ("Testing Hyperslab Selection Functions with NOTB of 2-D hyperslabs\n")); + + /* Allocate write & read buffers */ + wbuf=malloc(sizeof(uint8_t)*SPACE2_DIM1*SPACE2_DIM2); + rbuf=calloc(sizeof(uint8_t),SPACE2_DIM1*SPACE2_DIM2); + + /* Initialize write buffer */ + for(i=0, tbuf=wbuf; i<SPACE2_DIM1; i++) + for(j=0; j<SPACE2_DIM2; j++) + *tbuf++=(uint8_t)((i*SPACE2_DIM2)+j); + + /* Create file */ + fid1 = H5Fcreate(FILENAME, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT); + CHECK(fid1, FAIL, "H5Fcreate"); + + /* Create dataspace for dataset on disk */ + sid1 = H5Screate_simple(SPACE2_RANK, dims1, NULL); + CHECK(sid1, FAIL, "H5Screate_simple"); + + /* Create dataspace for writing buffer */ + sid2 = H5Screate_simple(SPACE2A_RANK, dims2, NULL); + CHECK(sid2, FAIL, "H5Screate_simple"); + + /* Select 10x10 hyperslab for disk dataset */ + start[0]=0; start[1]=0; + stride[0]=1; stride[1]=1; + count[0]=10; count[1]=10; + block[0]=1; block[1]=1; + ret = H5Sselect_hyperslab(sid1,H5S_SELECT_SET,start,stride,count,block); + CHECK(ret, FAIL, "H5Sselect_hyperslab"); + + /* Intersect overlapping 10x10 hyperslab */ + start[0]=5; start[1]=5; + stride[0]=1; stride[1]=1; + count[0]=10; count[1]=10; + block[0]=1; block[1]=1; + ret = H5Sselect_hyperslab(sid1,H5S_SELECT_NOTB,start,stride,count,block); + CHECK(ret, FAIL, "H5Sselect_hyperslab"); + + npoints = H5Sget_select_npoints(sid1); + VERIFY(npoints, 75, "H5Sget_select_npoints"); + + /* Select 75 hyperslab for memory dataset */ + start[0]=0; + stride[0]=1; + count[0]=75; + block[0]=1; + ret = H5Sselect_hyperslab(sid2,H5S_SELECT_SET,start,stride,count,block); + CHECK(ret, FAIL, "H5Sselect_hyperslab"); + + npoints = H5Sget_select_npoints(sid2); + VERIFY(npoints, 75, "H5Sget_select_npoints"); + + /* 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"); + + /* Read entire dataset from disk */ + ret=H5Dread(dataset,H5T_NATIVE_UCHAR,H5S_ALL,H5S_ALL,H5P_DEFAULT,rbuf); + CHECK(ret, FAIL, "H5Dread"); + + /* Initialize write buffer */ + for(i=0, tbuf=rbuf, tbuf2=wbuf; i<SPACE2_DIM1; i++) + for(j=0; j<SPACE2_DIM2; j++, tbuf++) { + if(((i>=0 && i<=4) && (j>=0 && j<=9)) || + ((i>=5 && i<=9) && (j>=0 && j<=4))) { + if(*tbuf!=*tbuf2) + printf("%d: hyperslab values don't match!, i=%d, j=%d, *tbuf=%d, *tbuf2=%d\n",__LINE__,i,j,(int)*tbuf,(int)*tbuf2); + tbuf2++; + } /* end if */ + else { + if(*tbuf!=0) + printf("%d: hyperslab element has wrong value!, i=%d, j=%d, *tbuf=%d\n",__LINE__,i,j,(int)*tbuf); + } /* end else */ + } /* 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_notb_2d() */ + +/**************************************************************** +** +** test_select_hyper_nota_2d(): Test basic H5S (dataspace) selection code. +** Tests 'nota' of hyperslabs in 2-D +** +****************************************************************/ +static void +test_select_hyper_nota_2d(void) +{ + hid_t fid1; /* HDF5 File IDs */ + hid_t dataset; /* Dataset ID */ + hid_t sid1,sid2; /* Dataspace ID */ + hsize_t dims1[] = {SPACE2_DIM1, SPACE2_DIM2}; + hsize_t dims2[] = {SPACE2A_DIM1}; + hssize_t start[SPACE2_RANK]; /* Starting location of hyperslab */ + hsize_t stride[SPACE2_RANK]; /* Stride of hyperslab */ + hsize_t count[SPACE2_RANK]; /* Element count of hyperslab */ + hsize_t block[SPACE2_RANK]; /* Block size of hyperslab */ + uint8_t *wbuf, /* buffer to write to disk */ + *rbuf, /* buffer read from disk */ + *tbuf, /* temporary buffer pointer */ + *tbuf2; /* temporary buffer pointer */ + int i,j; /* Counters */ + herr_t ret; /* Generic return value */ + hsize_t npoints; /* Number of elements in selection */ + + /* Output message about test being performed */ + MESSAGE(5, ("Testing Hyperslab Selection Functions with NOTA of 2-D hyperslabs\n")); + + /* Allocate write & read buffers */ + wbuf=malloc(sizeof(uint8_t)*SPACE2_DIM1*SPACE2_DIM2); + rbuf=calloc(sizeof(uint8_t),SPACE2_DIM1*SPACE2_DIM2); + + /* Initialize write buffer */ + for(i=0, tbuf=wbuf; i<SPACE2_DIM1; i++) + for(j=0; j<SPACE2_DIM2; j++) + *tbuf++=(uint8_t)((i*SPACE2_DIM2)+j); + + /* Create file */ + fid1 = H5Fcreate(FILENAME, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT); + CHECK(fid1, FAIL, "H5Fcreate"); + + /* Create dataspace for dataset on disk */ + sid1 = H5Screate_simple(SPACE2_RANK, dims1, NULL); + CHECK(sid1, FAIL, "H5Screate_simple"); + + /* Create dataspace for writing buffer */ + sid2 = H5Screate_simple(SPACE2A_RANK, dims2, NULL); + CHECK(sid2, FAIL, "H5Screate_simple"); + + /* Select 10x10 hyperslab for disk dataset */ + start[0]=0; start[1]=0; + stride[0]=1; stride[1]=1; + count[0]=10; count[1]=10; + block[0]=1; block[1]=1; + ret = H5Sselect_hyperslab(sid1,H5S_SELECT_SET,start,stride,count,block); + CHECK(ret, FAIL, "H5Sselect_hyperslab"); + + /* Intersect overlapping 10x10 hyperslab */ + start[0]=5; start[1]=5; + stride[0]=1; stride[1]=1; + count[0]=10; count[1]=10; + block[0]=1; block[1]=1; + ret = H5Sselect_hyperslab(sid1,H5S_SELECT_NOTA,start,stride,count,block); + CHECK(ret, FAIL, "H5Sselect_hyperslab"); + + npoints = H5Sget_select_npoints(sid1); + VERIFY(npoints, 75, "H5Sget_select_npoints"); + + /* Select 75 hyperslab for memory dataset */ + start[0]=0; + stride[0]=1; + count[0]=75; + block[0]=1; + ret = H5Sselect_hyperslab(sid2,H5S_SELECT_SET,start,stride,count,block); + CHECK(ret, FAIL, "H5Sselect_hyperslab"); + + npoints = H5Sget_select_npoints(sid2); + VERIFY(npoints, 75, "H5Sget_select_npoints"); + + /* 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"); + + /* Read entire dataset from disk */ + ret=H5Dread(dataset,H5T_NATIVE_UCHAR,H5S_ALL,H5S_ALL,H5P_DEFAULT,rbuf); + CHECK(ret, FAIL, "H5Dread"); + + /* Initialize write buffer */ + for(i=0, tbuf=rbuf, tbuf2=wbuf; i<SPACE2_DIM1; i++) + for(j=0; j<SPACE2_DIM2; j++, tbuf++) { + if(((i>=10 && i<=14) && (j>=5 && j<=14)) || + ((i>=5 && i<=9) && (j>=10 && j<=14))) { + if(*tbuf!=*tbuf2) + printf("%d: hyperslab values don't match!, i=%d, j=%d, *tbuf=%d, *tbuf2=%d\n",__LINE__,i,j,(int)*tbuf,(int)*tbuf2); + tbuf2++; + } /* end if */ + else { + if(*tbuf!=0) + printf("%d: hyperslab element has wrong value!, i=%d, j=%d, *tbuf=%d\n",__LINE__,i,j,(int)*tbuf); + } /* end else */ + } /* 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_nota_2d() */ +#endif /* NEW_HYPERSLAB_API */ + +/**************************************************************** +** ** test_select_hyper_iter2(): Iterator for checking hyperslab iteration ** ****************************************************************/ @@ -2735,7 +3276,7 @@ test_select_hyper_iter2(void *_elem, hid_t UNUSED type_id, hsize_t ndim, hssize_ printf(", "); } /* end for */ printf("}\n"); - printf("*tbuf=%d, **tbuf2==%d\n",*tbuf,**tbuf2); + printf("*tbuf=%d, **tbuf2=%d\n",*tbuf,**tbuf2); return(-1); } /* end if */ else { @@ -2812,13 +3353,21 @@ test_select_hyper_union_random_5d(hid_t read_plist) for(test_num=0; test_num<NRAND_HYPER; test_num++) { /* Save random # seed for later use */ /* (Used in case of errors, to regenerate the hyperslab sequence) */ +#ifndef QAK seed+=(unsigned)clock(); +#else /* QAK */ + seed=987909620; +#endif /* QAK */ srand(seed); #ifdef QAK printf("test_num=%d, seed=%u\n",test_num,seed); #endif /* QAK */ +#ifndef QAK for(i=0; i<NHYPERSLABS; i++) { +#else /* QAK */ + for(i=0; i<2; i++) { +#endif /* QAK */ #ifdef QAK printf("hyperslab=%d\n",i); #endif /* QAK */ @@ -2827,7 +3376,7 @@ printf("hyperslab=%d\n",i); start[j]=rand()%dims1[j]; count[j]=(rand()%(dims1[j]-start[j]))+1; #ifdef QAK -printf("start[%d]=%d, count[%d]=%d\n",j,(int)start[j],j,(int)count[j]); +printf("start[%d]=%d, count[%d]=%d (end[%d]=%d)\n",j,(int)start[j],j,(int)count[j],j,(int)(start[j]+count[j]-1)); #endif /* QAK */ } /* end for */ @@ -2850,9 +3399,9 @@ printf("start[%d]=%d, count[%d]=%d\n",j,(int)start[j],j,(int)count[j]); VERIFY(npoints, npoints2, "H5Sget_select_npoints"); #ifdef QAK -printf("random I/O, before H5Dread()\n"); +printf("random I/O, before H5Dread(), npoints=%lu\n",(unsigned long)npoints); { - hsize_t blocks[15][2][SPACE5_RANK]; + hsize_t blocks[128][2][SPACE5_RANK]; hssize_t nblocks; int k; @@ -2891,6 +3440,7 @@ printf("random I/O, after H5Dread()\n"); if(ret<0) { num_errs++; printf("Random hyperslabs for seed %u failed!\n",seed); + break; } /* Set the read buffer back to all zeroes */ @@ -3196,8 +3746,14 @@ test_select(void) test_select_hyper_offset(); /* Test selection offset code with hyperslabs */ test_select_point_offset(); /* Test selection offset code with elements */ test_select_hyper_union(); /* Test hyperslab union code */ +#ifdef NEW_HYPERSLAB_API test_select_hyper_union_stagger(); /* Test hyperslab union code for staggered slabs */ test_select_hyper_union_3d(); /* Test hyperslab union code for 3-D dataset */ + test_select_hyper_and_2d(); /* Test hyperslab intersection (AND) code for 2-D dataset */ + test_select_hyper_xor_2d(); /* Test hyperslab XOR code for 2-D dataset */ + test_select_hyper_notb_2d(); /* Test hyperslab NOTB code for 2-D dataset */ + test_select_hyper_nota_2d(); /* Test hyperslab NOTA code for 2-D dataset */ +#endif /* NEW_HYPERSLAB_API */ /* test the random hyperslab I/O with the default property list for reading */ test_select_hyper_union_random_5d(H5P_DEFAULT); /* Test hyperslab union code for random 5-D hyperslabs */ |