From 631394faa8943003cc2380348299448e4709efa0 Mon Sep 17 00:00:00 2001 From: Xiaowen Wu Date: Fri, 21 Jan 2005 13:19:51 -0500 Subject: [svn-r9855] Purpose: Adding N-bit testing source code into CVS tree. This is for debugging purpose only. N-bit filter won't be included in the daily test. Description: Integer, Float, Array datatype and Compound datatype tests are included. More comprehensive tests need to be done. Solution: Platforms tested: copper(AIX 5.1) and heping(Linux 2.4). Misc. update: --- test/dsets.c | 795 +++++++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 742 insertions(+), 53 deletions(-) diff --git a/test/dsets.c b/test/dsets.c index 842021b..851b68f 100644 --- a/test/dsets.c +++ b/test/dsets.c @@ -74,8 +74,12 @@ const char *FILENAME[] = { #define DSET_SET_LOCAL_NAME "set_local" #define DSET_SET_LOCAL_NAME_2 "set_local_2" #define DSET_ONEBYTE_SHUF_NAME "onebyte_shuffle" -#define DSET_NBIT_NAME "nbit" -#define DSET_NBIT_FLOAT_NAME "nbit_float" +#define DSET_NBIT_INT_NAME "nbit_int" +#define DSET_NBIT_ARRAY_NAME "nbit_array" +#define DSET_NBIT_ARRAY_NAME_2 "nbit_array_2" +#define DSET_NBIT_COMPOUND_NAME "nbit_compound" +#define DSET_NBIT_COMPOUND_NAME_2 "nbit_compound_2" +#define DSET_NBIT_FLOAT_NAME "nbit_float" #define DSET_COMPARE_DCPL_NAME "compare_dcpl" #define DSET_COMPARE_DCPL_NAME_2 "compare_dcpl_2" @@ -2499,9 +2503,9 @@ error: /*------------------------------------------------------------------------- - * Function: test_nbit_simple + * Function: test_nbit_int * - * Purpose: Tests the simple version of nbit filter + * Purpose: Tests the integer datatype for nbit filter * * Return: Success: 0 * @@ -2515,29 +2519,188 @@ error: *------------------------------------------------------------------------- */ static herr_t -test_nbit_simple(hid_t file, char *fname) +test_nbit_int(hid_t file) { #ifdef H5_HAVE_FILTER_NBIT - hid_t dataset, datatype, space, dc; - const hsize_t size[2] = {10, 20}; - const hsize_t chunk_size[2] = {10, 20}; - int orig_data[10][20]; - int new_data[10][20]; + hid_t dataset, datatype, mem_datatype, space, dc; + const hsize_t size[2] = {2, 5}; + const hsize_t chunk_size[2] = {2,5}; + int orig_data[2][5]; + int new_data[2][5]; size_t precision, offset; hsize_t i, j; #else /* H5_HAVE_FILTER_NBIT */ const char *not_supported= " Nbit is not enabled."; #endif /* H5_HAVE_FILTER_NBIT */ - TESTING("nbit simple (setup)"); + TESTING("nbit int (setup)"); #ifdef H5_HAVE_FILTER_NBIT - /* Define data type (integer), and set precision, offset, order */ + /* Define dataset datatype (integer), and set precision, offset */ datatype = H5Tcopy(H5T_NATIVE_INT); - if(H5Tset_order(datatype, H5T_ORDER_BE)<0) goto error; - precision = 24; + precision = 16; if(H5Tset_precision(datatype,precision)<0) goto error; - offset = 0; + offset = 4; if(H5Tset_offset(datatype,offset)<0) goto error; + + /* Copy to memory datatype before setting order */ + mem_datatype = H5Tcopy(datatype); + + /* Set order of dataset datatype */ + if(H5Tset_order(datatype, H5T_ORDER_BE)<0) goto error; + + /* Create the data space */ + if ((space = H5Screate_simple(2, size, NULL))<0) goto error; + + /* Use nbit filter */ + if((dc = H5Pcreate(H5P_DATASET_CREATE))<0) goto error; + if (H5Pset_chunk(dc, 2, chunk_size)<0) goto error; + /*if (H5Pset_nbit(dc)<0) goto error;*/ + + /* Create the dataset */ + if ((dataset = H5Dcreate(file, DSET_NBIT_INT_NAME, datatype, + space,dc))<0) goto error; + + for (i= 0;i< size[0]; i++) + for (j = 0; j < size[1]; j++) + orig_data[i][j] = ((long_long)HDrandom() % + (long_long)HDpow(2, precision - 1)) << offset; + + /*printf("\n"); + for (i= 0;i< size[0]; i++) + for (j = 0; j < size[1]; j++) { + printf("orig[%d]", i); printf("[%d]: ", j); + printf("%08x ", orig_data[i][j]); + if((i*size[1]+j+1)%4 == 0) printf("\n"); + } + printf("\n"); */ + + PASSED(); + /*printf("*** Dataset datatype precision is %d, offset is %d\n", precision, offset);*/ +#else + SKIPPED(); + puts(not_supported); +#endif + + /*---------------------------------------------------------------------- + * STEP 1: Test nbit by setting up a chunked dataset and writing + * to it. + *---------------------------------------------------------------------- + */ + TESTING("nbit int (write)"); + +#ifdef H5_HAVE_FILTER_NBIT + if (H5Dwrite(dataset, mem_datatype /*H5T_NATIVE_UINT*/, H5S_ALL, H5S_ALL, H5P_DEFAULT, + orig_data)<0) + goto error; + PASSED(); +#else + SKIPPED(); + puts(not_supported); +#endif + + /*---------------------------------------------------------------------- + * STEP 2: Try to read the data we just wrote. + *---------------------------------------------------------------------- + */ + TESTING("nbit int (read)"); + +#ifdef H5_HAVE_FILTER_NBIT + /* Read the dataset back */ + if (H5Dread(dataset, mem_datatype /*H5T_NATIVE_UINT*/, H5S_ALL, H5S_ALL, H5P_DEFAULT, + new_data)<0) + goto error; + + /* Check that the values read are the same as the values written */ + /*printf("\n");*/ + for (i=0; i