diff options
author | Xiaowen Wu <wuxiaowe@ncsa.uiuc.edu> | 2005-02-17 03:14:05 (GMT) |
---|---|---|
committer | Xiaowen Wu <wuxiaowe@ncsa.uiuc.edu> | 2005-02-17 03:14:05 (GMT) |
commit | 8493009bd427a705d9bc755981dfe744d4d8537a (patch) | |
tree | 3b74b4cff515ebff0388ad6a26f83ef9c922d4bb /test/dsets.c | |
parent | 7b4b65be1ceffea0db89d0e7b234201d2229244a (diff) | |
download | hdf5-8493009bd427a705d9bc755981dfe744d4d8537a.zip hdf5-8493009bd427a705d9bc755981dfe744d4d8537a.tar.gz hdf5-8493009bd427a705d9bc755981dfe744d4d8537a.tar.bz2 |
[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:
Diffstat (limited to 'test/dsets.c')
-rw-r--r-- | test/dsets.c | 131 |
1 files changed, 130 insertions, 1 deletions
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<size[0]; i++) { + for (j=0; j<size[1]; j++) { + if (new_data[i][j] != orig_data[i][j]) { + H5_FAILED(); + printf(" Read different values than written.\n"); + printf(" At index %lu,%lu\n", (unsigned long)i, (unsigned long)j); + goto error; + }/* + printf("orig: %d new: %d\n", orig_data[i][j], new_data[i][j]);*/ + } + } + /*---------------------------------------------------------------------- + * Cleanup + *---------------------------------------------------------------------- + */ + if (H5Tclose(datatype)<0) goto error; + if (H5Pclose (dc)<0) goto error; + if (H5Dclose(dataset)<0) goto error; + + PASSED(); +#else + SKIPPED(); + puts(not_supported); +#endif + return 0; +error: + return -1; +} + + +/*------------------------------------------------------------------------- * Function: test_multiopen * * Purpose: Tests that a bug no longer exists. If a dataset is opened @@ -4978,7 +5106,8 @@ int main(void) nerrors += test_nbit_double(file)<0 ?1:0; nerrors += test_nbit_array(file)<0 ?1:0; nerrors += test_nbit_compound(file)<0 ?1:0; - nerrors += test_nbit_compound_2(file)<0 ?1:0; + nerrors += test_nbit_compound_2(file)<0 ?1:0; +/* nerrors += test_scaleoffset_int(file)<0 ?1:0; */ nerrors += test_multiopen (file)<0 ?1:0; nerrors += test_types(file)<0 ?1:0; nerrors += test_userblock_offset(fapl)<0 ?1:0; |