From 8493009bd427a705d9bc755981dfe744d4d8537a Mon Sep 17 00:00:00 2001 From: Xiaowen Wu Date: Wed, 16 Feb 2005 22:14:05 -0500 Subject: [svn-r10026] Purpose: New feature. Description: Add a test case for scaleoffset filter (integer type). For debugging purpose only. The test case is not turned on. Solution: Platforms tested: heping, copper, arabica Misc. update: --- test/dsets.c | 131 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 130 insertions(+), 1 deletion(-) diff --git a/test/dsets.c b/test/dsets.c index c647f39..da5c5d5 100644 --- a/test/dsets.c +++ b/test/dsets.c @@ -80,6 +80,7 @@ const char *FILENAME[] = { #define DSET_NBIT_ARRAY_NAME "nbit_array" #define DSET_NBIT_COMPOUND_NAME "nbit_compound" #define DSET_NBIT_COMPOUND_NAME_2 "nbit_compound_2" +#define DSET_SCALEOFFSET_INT_NAME "scaleoffset_int" #define DSET_COMPARE_DCPL_NAME "compare_dcpl" #define DSET_COMPARE_DCPL_NAME_2 "compare_dcpl_2" @@ -3543,6 +3544,133 @@ error: /*------------------------------------------------------------------------- + * Function: test_scaleoffset_int + * + * Purpose: Tests the integer datatype for scaleoffset filter + * + * Return: Success: 0 + * + * Failure: -1 + * + * Programmer: Xiaowen Wu + * Monday, Feb. 14th, 2005 + * + * Modifications: + * + *------------------------------------------------------------------------- + */ +static herr_t +test_scaleoffset_int(hid_t file) +{ +#ifdef H5_HAVE_FILTER_SCALEOFFSET + hid_t dataset, 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]; + hsize_t i, j; +#else /* H5_HAVE_FILTER_SCALEOFFSET */ + const char *not_supported= " Scaleoffset is not enabled."; +#endif /* H5_HAVE_FILTER_SCALEOFFSET */ + + puts("Testing scaleoffset filter"); + TESTING(" scaleoffset int (setup)"); +#ifdef H5_HAVE_FILTER_SCALEOFFSET + datatype = H5Tcopy(H5T_NATIVE_INT); +#if 0 + /* Set order of dataset datatype */ + if(H5Tset_order(datatype, H5T_ORDER_BE)<0) goto error; +#endif + /* Create the data space */ + if ((space = H5Screate_simple(2, size, NULL))<0) goto error; + + /* Createa the dataset property list */ + if((dc = H5Pcreate(H5P_DATASET_CREATE))<0) goto error; + if (H5Pset_chunk(dc, 2, chunk_size)<0) goto error; + if (H5Pset_scaleoffset(dc, 0)<0) goto error; + if (H5Pset_fill_value(dc, datatype, NULL)<0) goto error; + + /* Create the dataset */ + if ((dataset = H5Dcreate(file, DSET_SCALEOFFSET_INT_NAME, datatype, + space,dc))<0) goto error; + + /* Initialize data, assuming size of long_long >= size of int */ + for (i= 0;i< size[0]; i++) + for (j = 0; j < size[1]; j++) { + orig_data[i][j] = (long_long)HDrandom() % + 10000; + /* even-numbered values are negtive */ + if((i*size[1]+j+1)%2 == 0) + orig_data[i][j] = -orig_data[i][j]; + } + + PASSED(); +#else + SKIPPED(); + puts(not_supported); +#endif + + /*---------------------------------------------------------------------- + * STEP 1: Test scaleoffset by setting up a chunked dataset and writing + * to it. + *---------------------------------------------------------------------- + */ + TESTING(" scaleoffset int (write)"); + +#ifdef H5_HAVE_FILTER_SCALEOFFSET + if (H5Dwrite(dataset, H5T_NATIVE_INT, 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(" scaleoffset int (read)"); + +#ifdef H5_HAVE_FILTER_SCALEOFFSET + /* 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