From a43bce5d04a25db3fcc12fd5896328e9e63bba05 Mon Sep 17 00:00:00 2001 From: Xiaowen Wu Date: Thu, 6 Jan 2005 13:27:26 -0500 Subject: [svn-r9756] Purpose: For debugging N-bit filter; it will not affect the library. Description: Adding N-bit tests, the library will not run those tests. Solution: Platforms tested: heping(Linux 2.4), copper(AIX 5.1),arabica(sol 2.7) Misc. update: --- test/dsets.c | 256 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 255 insertions(+), 1 deletion(-) diff --git a/test/dsets.c b/test/dsets.c index afce193..842021b 100644 --- a/test/dsets.c +++ b/test/dsets.c @@ -74,6 +74,8 @@ 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_COMPARE_DCPL_NAME "compare_dcpl" #define DSET_COMPARE_DCPL_NAME_2 "compare_dcpl_2" @@ -2497,6 +2499,256 @@ error: /*------------------------------------------------------------------------- + * Function: test_nbit_simple + * + * Purpose: Tests the simple version of nbit filter + * + * Return: Success: 0 + * + * Failure: -1 + * + * Programmer: Xiaowen Wu + * Wednesday, , 2004 Dec. 23th + * + * Modifications: + * + *------------------------------------------------------------------------- + */ +static herr_t +test_nbit_simple(hid_t file, char *fname) +{ +#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]; + 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)"); +#ifdef H5_HAVE_FILTER_NBIT + /* Define data type (integer), and set precision, offset, order */ + datatype = H5Tcopy(H5T_NATIVE_INT); + if(H5Tset_order(datatype, H5T_ORDER_BE)<0) goto error; + precision = 24; + if(H5Tset_precision(datatype,precision)<0) goto error; + offset = 0; + if(H5Tset_offset(datatype,offset)<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, fname, datatype, + space,dc))<0) goto error; + + for (i= 0;i< 10; i++) + for (j = 0; j < 20; j++) + orig_data[i][j] = ((long long int)random() % (long long int)pow(2, precision)) << offset; + + PASSED(); +#else + SKIPPED(); + puts(not_supported); +#endif + + /*---------------------------------------------------------------------- + * STEP 1: Test nbit by setting up a chunked dataset and writing + * to it. + *---------------------------------------------------------------------- + */ + TESTING("nbit simple (write)"); + +#ifdef H5_HAVE_FILTER_NBIT + if (H5Dwrite(dataset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, + orig_data)<0) + goto error; + + if (H5Dclose(dataset)<0) goto error; + PASSED(); +#else + SKIPPED(); + puts(not_supported); +#endif + + /*---------------------------------------------------------------------- + * STEP 2: Try to read the data we just wrote. + *---------------------------------------------------------------------- + */ + TESTING("nbit simple (read)"); + +#ifdef H5_HAVE_FILTER_NBIT + if ((dataset = H5Dopen(file, fname))<0) goto error; + /* Read the dataset back */ + if (H5Dread(dataset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, + new_data)<0) + goto error; + + /* Check that the values read are the same as the values written */ + for (i=0; i