diff options
author | Scot Breitenfeld <brtnfld@hdfgroup.org> | 2009-06-08 15:32:57 (GMT) |
---|---|---|
committer | Scot Breitenfeld <brtnfld@hdfgroup.org> | 2009-06-08 15:32:57 (GMT) |
commit | 875ff1c1435c2c743d67c506f0a27dd16eb9db82 (patch) | |
tree | 171966d5ab808d3acbbc4ac4765545c65589e349 | |
parent | c09ba63c9b0a8ee5167defea6ed6b8fe1be3e433 (diff) | |
download | hdf5-875ff1c1435c2c743d67c506f0a27dd16eb9db82.zip hdf5-875ff1c1435c2c743d67c506f0a27dd16eb9db82.tar.gz hdf5-875ff1c1435c2c743d67c506f0a27dd16eb9db82.tar.bz2 |
[svn-r17015] Description:
Implemented test for H5LRcreate_regref_to_all.
-rw-r--r-- | hl/test/test_bitfield.c | 2 | ||||
-rw-r--r-- | hl/test/test_regref_hyper.c | 526 |
2 files changed, 375 insertions, 153 deletions
diff --git a/hl/test/test_bitfield.c b/hl/test/test_bitfield.c index 7488e3a..2e334df 100644 --- a/hl/test/test_bitfield.c +++ b/hl/test/test_bitfield.c @@ -73,7 +73,7 @@ int main(void) * store it in a char buffer. This selects all the elements (H5S_ALL) */ status = H5LTread_bitfield_value(qf_dset, num_flags, offset, length, - H5S_ALL, H5T_NATIVE_UCHAR, qf_data); + H5S_ALL, qf_data); printf("Bit Field:\n"); for (i = 0; i<DIM0; i++) { printf (" ["); diff --git a/hl/test/test_regref_hyper.c b/hl/test/test_regref_hyper.c index cf88823..e81153b 100644 --- a/hl/test/test_regref_hyper.c +++ b/hl/test/test_regref_hyper.c @@ -36,7 +36,7 @@ #define TESTING2(WHAT) {printf("%-70s", "Testing " WHAT); fflush(stdout);} -int main(void) +static int test_regref_hyper( void ) { hid_t file_id; /* file identifier */ hid_t space_id; /* dataspace identifiers */ @@ -51,81 +51,65 @@ int main(void) int rank = 2; int rank1D = 1; int rank3D = 3; - hsize_t dims1D[1] = {17}; - hsize_t dims3D[3] = {6,6,6}; - int rankr =1; + hsize_t dims1D[1] = {9}; + hsize_t dims3D[3] = {9,8,6}; herr_t status; hdset_reg_ref_t ref[4]; int data[9][8], data_read_2D[9][8]; - int data1D[17] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16}; - int data3D[6][6][6]; + int data1D[9]; + int data3D[9][8][6]; hsize_t start[2]; hsize_t count[2]; hsize_t start3D[3]; hsize_t count3D[3]; - hsize_t coord[5] = {1,6,9,10,14}; - unsigned num_points = 5; - int i, j, k; + hsize_t coord[5] = {1,2,4,6,7}; + size_t num_points = 5; + int i, ii, iii, j, jj, k, kk; size_t nlength; - int rank_out; + int rank_out[3]; hid_t dtype; hsize_t *buf; char *name; - size_t numelem; + size_t numelem[3]; + size_t numelem_size; H5S_sel_type sel_type; + int *data_out; int data_out2[3][2]; - int data_out3[2][2][2]; hsize_t block_coord_3D[6] ={ 0, 1, 2, 1, 2, 3}; hsize_t block_coord[4] ={ 3, 3, 5, 4}; hsize_t num_elem = 2; const char *path[num_elem]; - hsize_t block_coord_6[8] ={ 4, 6, 5, 7, 0, 0, 2, 1}; + hsize_t block_coord_6[8] ={ 3, 6, 5, 7, 0, 0, 2, 1}; hsize_t block_coord_4[4] ={ 1, 3, 3, 4}; - hsize_t block_coord_1D_src[2] ={ 0, 5}; - hsize_t block_coord_1D_dest[2] ={ 5, 10}; hsize_t block_coord_2D_src[4] ={ 0, 0, 1, 2}; hsize_t block_coord_2D_dest[4] ={5, 5, 7, 6 }; hsize_t block_coord_2D_dest_a[4] ={0, 3, 2, 4 }; + hsize_t block_coord_3D_refblock[6] ={ 3, 3, 3, 4, 4, 4 }; hdset_reg_ref_t ref6[num_elem]; hdset_reg_ref_t ref_new; hid_t file_id_array[num_elem]; + + TESTING("creating dataset for region reference"); + path[0] ="/Group_2D/DS2"; path[1] ="/Group_2D/DS2"; - - printf("FULL 3D ARRAY:"); - for (i=0; i<6; i++) { - printf("\n"); - for (k=0; k<6; k++) { - printf("[ "); - for (j=0; j<6; j++){ - data3D[i][j][k] = 100*(i+1)+10*(j+1) + k + 1; - printf("%d ", data3D[i][j][k]); + for (i=0; i<dims3D[0]; i++) { + data1D[i] = i; + for (j=0; j<dims3D[1]; j++) { + data[i][j] = 10*(i+1)+j+1; + for (k=0; k<dims3D[2]; k++){ + data3D[i][j][k] = 100*(i+1)+10*(k+1) + j + 1; } - printf("] "); } } - printf("\n"); - - printf("FULL 2D ARRAY:"); - for (i=0; i<9; i++) { - printf("\n[ "); - for (j=0; j<8; j++) { - data[i][j] = 10*(i+1)+j+1; - printf("%d ", data[i][j]); - } - printf("]"); - } - printf("\n"); /* * Create file with default file access and file creation properties. */ file_id = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT); - spacer_id = H5Screate_simple(rankr, dimsr, NULL); - /* * Create dataspace for datasets. */ @@ -181,6 +165,7 @@ int main(void) /* * Dataset with references. */ + spacer_id = H5Screate_simple(rank1D, dimsr, NULL); dsetr_id = H5Dcreate2(file_id, dsetnamer, H5T_STD_REF_DSETREG, spacer_id, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); /* @@ -238,120 +223,273 @@ int main(void) status = H5Fclose(file_id); status = H5Gclose(group_id); - /* Start Reading section */ + PASSED(); + /* START READING SECTION */ + TESTING("H5LRget_region_info with NULL entries, 1D dataset"); /* * Reopen the file to read selections back. */ file_id = H5Fopen(filename, H5F_ACC_RDWR, H5P_DEFAULT); + if(file_id < 0) + goto out; nlength = 0; - rank_out = 0; - - /* set wrong object id */ + rank_out[0] = 0; -/* status = H5LRget_region_info(110101, */ -/* ref[1], */ -/* NULL, */ -/* &nlength, */ -/* &rank_out, */ -/* NULL, */ -/* NULL, */ -/* H5R_DATASET_REGION ); */ - -/* if(status < 0 ) */ -/* printf(" Testing for incorrect object id, PASSED \n"); */ + /* 1D element section region reference infomation */ + status = H5LRget_region_info(file_id, + (const hdset_reg_ref_t*)ref[0], + &nlength, + NULL, + &rank_out[0], + NULL, + &sel_type, + &numelem[0], + NULL); + if(status < 0) + goto out; + if( nlength != 14) + goto out; + if( rank_out[0] != rank1D) + goto out; + if( sel_type != H5S_SEL_POINTS) + goto out; + if(numelem[0] != num_points) + goto out; + + PASSED(); + + /*------------------------------------------------------------------------- + * H5LRget_region_info test + *------------------------------------------------------------------------- + */ + TESTING("H5LRget_region_info with NULL entries, 3D dataset"); + /* 3D hyperslab section region reference infomation*/ + status = H5LRget_region_info(file_id, + (const hdset_reg_ref_t*)ref[3], + &nlength, + NULL, + &rank_out[2], + NULL, + &sel_type, + &numelem[2], + NULL); + if(status < 0) + goto out; + if( nlength != 14) + goto out; + if( sel_type != H5S_SEL_HYPERSLABS) + goto out; + if(numelem[2] != 1) + goto out; + PASSED(); + + /*------------------------------------------------------------------------- + * H5LRget_region_info test + *------------------------------------------------------------------------- + */ + TESTING("H5LRget_region_info with NULL entries, 2D dataset"); + rank_out[1] =0; + /* 2D hyperslab section region reference infomation*/ status = H5LRget_region_info(file_id, (const hdset_reg_ref_t*)ref[1], &nlength, NULL, - &rank_out, + &rank_out[1], NULL, &sel_type, - &numelem, + &numelem[1], NULL); - - if(status < 0 ) - printf(" ERROR: H5LRget_region_info <1>\n"); + if(status < 0) + goto out; + if( nlength != 14) + goto out; + if( rank_out[1] != rank) + goto out; + if( sel_type != H5S_SEL_HYPERSLABS) + goto out; + if(numelem[1] != 1) + goto out; + PASSED(); /* allocate the name */ - name = (char *) malloc (nlength); + if(name == NULL) + goto out; /* allocate space for hyperslab block | NUMBLOCKS | RANK | SIZEOF DATA TYPE | NUMBER COORDINATE POINTS | */ - buf = (hsize_t *)malloc( numelem * rank_out * sizeof(hsize_t) * 2 ); + buf = (hsize_t *)malloc( numelem[1] * rank_out[1] * sizeof(hsize_t) * 2 ); + if(buf == NULL) + goto out; - /* Get region refererce information */ + /*------------------------------------------------------------------------- + * H5LRget_region_info test + *------------------------------------------------------------------------- + */ + /* Get region reference information */ + TESTING("H5LRget_region_info, 2D dataset"); status = H5LRget_region_info(file_id, (const hdset_reg_ref_t*)ref[1], &nlength, name, - &rank_out, + &rank_out[1], &dtype, &sel_type, - &numelem, + &numelem[1], buf ); + if(status < 0) + goto out; + if(strcmp(name, "/Group_2D/DS2")) + goto out; + /* check values */ + + for(i=0; i<rank_out[1]*2*numelem[1];i++) { + if(buf[i] != block_coord[i]) goto out; + } + + free(buf); + free(name); + + PASSED(); - if(status < 0 ) - printf(" ERROR: H5LRget_region_info <2>\n"); + /*------------------------------------------------------------------------- + * H5LRget_region_info test + *------------------------------------------------------------------------- + */ + + TESTING("H5LRget_region_info, 3D dataset"); + /* allocate the name */ + name = (char *) malloc (nlength); + if(name == NULL) + goto out; + + + /* allocate space for hyperslab block + | NUMBLOCKS | RANK | SIZEOF DATA TYPE | NUMBER COORDINATE POINTS | */ + buf = (hsize_t *)malloc( numelem[2] * rank_out[2] * sizeof(hsize_t) * 2 ); + if(buf == NULL) + goto out; + + /* Get region reference information */ + + status = H5LRget_region_info(file_id, + (const hdset_reg_ref_t*)ref[3], + &nlength, + name, + &rank_out[2], + &dtype, + &sel_type, + &numelem[2], + buf ); + if(status < 0) + goto out; + if(strcmp(name, "/Group_3D/DS3")) + goto out; /* check values */ + + for(i=0; i<rank_out[2]*2*numelem[2];i++) { + if(buf[i] != block_coord_3D_refblock[i]) goto out; + } - if(buf[0] != 3 || buf[1] != 3 || buf[2] != 5 || buf[3] != 4) - printf(" VALIDATION ERROR: hyperslab coordinates\n"); + free(buf); + free(name); - /* Read a region of the data using a region reference */ - /* file_id = -1; */ + PASSED(); + /*------------------------------------------------------------------------- + * H5LRget_region test + *------------------------------------------------------------------------- + */ + TESTING("H5LRget_region, 2D dataset"); + /* Read a region of the 2D data using a region reference */ if ( H5LRread_region(file_id, - &ref[1], + (const hdset_reg_ref_t*)ref[1], H5T_NATIVE_INT, - &numelem, - data_out2) < 0) goto out; + &numelem_size, + NULL) < 0) goto out; + + /* check size of data from region reference */ + if( (int)numelem_size != (block_coord[2]-block_coord[0]+1) * (block_coord[3]-block_coord[1]+1) ) + goto out; + + data_out = (int *)malloc( numelem_size * sizeof(int)); + + if ( H5LRread_region(file_id, + (const hdset_reg_ref_t*)ref[1], + H5T_NATIVE_INT, + &numelem_size, + data_out) < 0) goto out; - printf("REGION REFERENCED 2D HYPERSLAB (H5LRread_region),"); - printf(" COORDINATES (%d,%d)-(%d,%d):\n", - (int)block_coord[0],(int)block_coord[1],(int)block_coord[2],(int)block_coord[3]); - for (i=0; i<3; i++) - { - printf("\n [ "); - for (j=0; j<2; j++) { - printf("%d ", data_out2[i][j]); - } - printf("]"); +/* printf("REGION REFERENCED 2D HYPERSLAB (H5LRread_region),"); */ + + ii = 0; jj = 0; + for (i=0; i<numelem_size; i++){ + if( data_out[i] != data[ii+(int)block_coord[0]][jj+(int)block_coord[1]]) + goto out; + if( jj+1 == ( (int)block_coord[3]-(int)block_coord[1] + 1) ) { + ii = ii + 1; + jj = 0; + } else { + jj = jj + 1; } - printf("\n"); + } + free(data_out); status = H5Fclose(file_id); + PASSED(); + + /*------------------------------------------------------------------------- + * H5LTget_region test + *------------------------------------------------------------------------- + */ + + TESTING("H5LTread_region, 3D dataset"); + /* Read a region of the data using corner coordinates of a block */ + numelem_size = (block_coord_3D[3]-block_coord_3D[0]+1) * (block_coord_3D[4]-block_coord_3D[1]+1) * (block_coord_3D[5]-block_coord_3D[2]+1); + + data_out = (int *)malloc( numelem_size * sizeof(int)); + + status = H5LTread_region(filename, "/Group_3D/DS3", block_coord_3D, H5T_NATIVE_INT, - data_out3); - - printf("REGION REFERENCED 3D HYPERSLAB (H5LTread_region),"); - printf(" COORDINATES (%d,%d,%d)-(%d,%d,%d):\n",(int)block_coord_3D[0],(int)block_coord_3D[1],(int)block_coord_3D[2], - (int)block_coord_3D[3],(int)block_coord_3D[4],(int)block_coord_3D[5]); - - for (k=0; k<2; k++){ - for (i=0; i<2; i++) - { - printf("\n [ "); - for (j=0; j<2; j++) { - printf("%d ", data_out3[i][j][k]); - } - printf("]"); - } - printf("\n"); - } + data_out); + if(status < 0) goto out; +/* printf("REGION REFERENCED 3D HYPERSLAB (H5LTread_region),"); */ +/* printf(" COORDINATES (%d,%d,%d)-(%d,%d,%d):\n",(int)block_coord_3D[0],(int)block_coord_3D[1],(int)block_coord_3D[2], */ +/* (int)block_coord_3D[3],(int)block_coord_3D[4],(int)block_coord_3D[5]); */ + + ii = 0; jj = 0; kk = 0; + for (i=0; i<numelem_size; i++){ + if( data_out[i] != data3D[ii+(int)block_coord_3D[0]][jj+(int)block_coord_3D[1]][kk+(int)block_coord_3D[2]]) + goto out; + if( ( jj +1 == ( (int)block_coord_3D[4]-(int)block_coord_3D[1] + 1) ) && ( kk+1 == ( (int)block_coord_3D[5]-(int)block_coord_3D[2] + 1 ) ) ) { + ii = ii + 1; + jj = 0; + kk = 0; + } else if( kk+1 == ( (int)block_coord_3D[5]-(int)block_coord_3D[2] + 1)) { + jj = jj+1; + kk = 0; + } + else { + kk = kk + 1; + } + } + free(data_out); + PASSED(); + + TESTING("H5LTcopy_region, 2D dataset"); /* copy a region described by blocks to another region described by another block */ status = H5LTcopy_region(filename, "/Group_2D/DS2", @@ -359,104 +497,188 @@ int main(void) filename, "/Group_2D/DS2", block_coord_2D_dest); + if(status < 0) goto out; - /*check the region was copied correctly */ + /* check the region was copied correctly */ file_id = H5Fopen(filename, H5F_ACC_RDWR, H5P_DEFAULT); status = H5LTread_dataset(file_id,"/Group_2D/DS2",H5T_NATIVE_INT,data_read_2D); + status = H5Fclose(file_id); - printf("2D DATA AFTER H5LTCOPY_REGION: [(%d,%d)-(%d,%d)] --> [(%d,%d)-(%d,%d)]", - (int)block_coord_2D_src[0],(int)block_coord_2D_src[1], (int)block_coord_2D_src[2],(int)block_coord_2D_src[3], - (int)block_coord_2D_dest[0], (int)block_coord_2D_dest[1],(int)block_coord_2D_dest[2], (int)block_coord_2D_dest[3]); - for (i=0; i<9; i++) { - printf("\n[ "); - for (j=0; j<8; j++) { - printf("%d ", data_read_2D[i][j]); + ii = block_coord_2D_src[0]; + for (i=0; i< (int)block_coord_2D_dest[2] - (int)block_coord_2D_dest[0] + 1 ; i++) { + jj = block_coord_2D_src[1]; + for (j=0; j< (int)block_coord_2D_dest[3] - (int)block_coord_2D_dest[1] + 1 ; j++) { + if(data_read_2D[i][j] != data[ii][jj]) + goto out; + jj = jj + 1; } - printf("]"); + ii = ii + 1; } - printf("\n"); + + PASSED(); + + TESTING("H5LRcopy_references, 2D dataset"); file_id = H5Fopen(filename, H5F_ACC_RDWR, H5P_DEFAULT); status = H5LRcopy_references( file_id, &ref[1], filename, "/Group_2D/DS2", block_coord_2D_dest_a, &ref_new); + /* check the region was copied correctly and the region reference is correct */ status = H5LTread_dataset(file_id,"/Group_2D/DS2",H5T_NATIVE_INT,data_read_2D); - printf("2D DATA AFTER H5LRCOPY_REFERENCES: [(%d,%d)-(%d,%d)] --> [(%d,%d)-(%d,%d)]", - (int)block_coord[0],(int)block_coord[1],(int)block_coord[2],(int)block_coord[3], - (int)block_coord_2D_dest_a[0], (int)block_coord_2D_dest_a[1],(int)block_coord_2D_dest_a[2], (int)block_coord_2D_dest_a[3]); - - for (i=0; i<9; i++) { - printf("\n[ "); - for (j=0; j<8; j++) { - printf("%d ", data_read_2D[i][j]); + /* data_read_2D is the full dataset located at given path */ + + ii = block_coord[0]; + for (i=block_coord_2D_dest_a[0]; i< (int)block_coord_2D_dest_a[2] + 1; i++) { + jj = block_coord[1]; + for (j=block_coord_2D_dest_a[1]; j< (int)block_coord_2D_dest_a[3] + 1 ; j++) { + if(data_read_2D[i][j] != data[ii][jj]) + goto out; + jj = jj + 1; } - printf("]"); + ii = ii + 1; } - printf("\n"); - printf("NEW 2D REGION REFERENCE AFTER COPY: [(%d,%d)-(%d,%d)]", - (int)block_coord[0],(int)block_coord[1],(int)block_coord[2],(int)block_coord[3]); - /* check the data pointed to by the new region reference */ status = H5LRread_region(file_id, - &ref_new, + (const hdset_reg_ref_t*)ref_new, H5T_NATIVE_INT, - &numelem, + &numelem_size, data_out2); - if(status<0){ - printf("\nH5LRread_region FAILED--STOPPING\n"); - abort(); - } + if(status<0) goto out; - for (i=0; i<3; i++) - { - printf("\n [ "); - for (j=0; j<2; j++) { - printf("%d ", data_out2[i][j]); - } - printf("]"); + ii = block_coord[0]; + for (i = 0 ; i < (int)block_coord[2] - (int)block_coord[0] + 1; i++) { + jj = block_coord[1]; + for (j = 0; j < (int)block_coord[3] - (int)block_coord[1] + 1 ; j++) { + if(data_out2[i][j] != data[ii][jj]) + goto out; + jj = jj + 1; } - printf("\n"); + ii = ii + 1; + } + + PASSED(); + + TESTING("H5LRcopy_region, 2D dataset"); /* copy the region reference into a block_coord */ status = H5LRcopy_region(file_id, &ref[1], filename, "/Group_2D/DS2", block_coord_4); - /* check the region was copied correctly */ + if(status<0) goto out; + + /* check the region was copied correctly */ status = H5LTread_dataset(file_id,"/Group_2D/DS2",H5T_NATIVE_INT,data_read_2D); - printf("2D DATA AFTER H5LRCOPY_REGION: [(%d,%d)-(%d,%d)] --> [(%d,%d)-(%d,%d)]", - (int)block_coord[0],(int)block_coord[1],(int)block_coord[2],(int)block_coord[3], - (int)block_coord_4[0], (int)block_coord_4[1],(int)block_coord_4[2], (int)block_coord_4[3]); - - for (i=0; i<9; i++) { - printf("\n[ "); - for (j=0; j<8; j++) { - printf("%d ", data_read_2D[i][j]); + if(status<0) goto out; + + ii = block_coord[0]; + for (i=block_coord_4[0]; i< (int)block_coord_4[2] + 1; i++) { + jj = block_coord[1]; + for (j=block_coord_4[1]; j< (int)block_coord_4[3] + 1 ; j++) { + if(data_read_2D[i][j] != data[ii][jj]) + goto out; + jj = jj + 1; } - printf("]"); + ii = ii + 1; } - printf("\n"); + + PASSED(); + + TESTING("H5LRcreate_region_references, 2D dataset"); status = H5LRcreate_region_references(file_id, num_elem, path, block_coord_6, ref6); - for (i=0; i<num_elem; i++) + if(status < 0) goto out; + + PASSED(); + + for (i=0; i< (int)num_elem; i++) file_id_array[i] = file_id; - status = H5LRmake_dataset(file_id, "/Group_2D/DS2a", H5T_NATIVE_INT, num_elem, file_id_array, ref6); + + TESTING("H5LRmake_dataset, 2D dataset"); + status = H5LRmake_dataset(file_id, "/Group_2D/DS2a", H5T_NATIVE_INT, num_elem, file_id_array, ( const hdset_reg_ref_t *)ref6); + + /* check the regions and check they were made correctly */ + + kk = 0; + for (iii=0; iii< (int)num_elem; iii++) { + status = H5LRread_region(file_id, + (const hdset_reg_ref_t*)ref6[iii], + H5T_NATIVE_INT, + &numelem_size, + data_out2); + if(status < 0) goto out; + + /* check the values */ + ii = block_coord_6[0+kk]; + for (i=0 ; i < (int)block_coord_6[kk+2] - (int)block_coord_6[0+kk] + 1; i++) { + jj = block_coord_6[1+kk]; + for (j=0 ; j < (int)block_coord_6[kk+3] - (int)block_coord_6[1+kk] + 1; j++) { + if(data_out2[i][j] != data_read_2D[ii][jj]) + goto out; + + jj = jj + 1; + } + ii = ii + 1; + } + kk = kk + 4; + } + + PASSED(); + + + /*------------------------------------------------------------------------- + * Testing H5LRcreate_regref_to_all + *------------------------------------------------------------------------- + */ + + TESTING("H5LRcreate_regref_to_all"); + + status = H5LRcreate_regref_to_all(file_id, "/", + "/Group_2D/DS2c", H5_INDEX_NAME, H5_ITER_INC); + + if(status < 0) goto out; + + PASSED(); + + +/* close(file_id); */ return 0; out: - return 1; + H5_FAILED(); + return -1; } +/*------------------------------------------------------------------------- +* the main program +*------------------------------------------------------------------------- +*/ +int main( void ) +{ + int nerrors=0; + + /* test region region references and hyperslab selections */ + nerrors += test_regref_hyper(); + + /* check for errors */ + if (nerrors) + goto error; + + return 0; +error: + return 1; + +} |