static void test_null_filter() { // Output message about test being performed SUBTEST("'Null' filter"); try { //hsize_t null_size; // Size of dataset with null filter // Prepare dataset create property list DSetCreatPropList dsplist; dsplist.setChunk(2, chunk_size); if (H5Zregister (H5Z_BOGUS)<0) throw Exception("test_null_filter", "H5Zregister failed"); // Set some pretent filter dsplist.setFilter(H5Z_FILTER_BOGUS); // this function is just a stub right now; will work on it later - BMR //if(test_filter_internal(file,DSET_BOGUS_NAME,dc,DISABLE_FLETCHER32,DATA_NOT_CORRUPTED,&null_size)<0) // throw Exception("test_null_filter", "test_filter_internal failed"); // Close objects. dsplist.close(); PASSED(); } // end of try // catch all other exceptions catch (Exception E) { issue_fail_msg("test_null_filter()", __LINE__, __FILE__, E.getCDetailMsg()); } } // test_null_filter
HDF5HandlerBase::HDF5HandlerBase(const std::string &fileName, const std::string &datasetName) : FILE_NAME(H5std_string(fileName)) , DATASETNAME(H5std_string(datasetName)) { try { Exception::dontPrint(); file = H5File(FILE_NAME, H5F_ACC_TRUNC); hsize_t dims[1] = {0}; hsize_t maxdims[1] = {H5S_UNLIMITED}; hsize_t chunk_dims[1] = {10000}; DataSpace dataspace = DataSpace(1,dims,maxdims); DSetCreatPropList prop; prop.setChunk(1, chunk_dims); dataset = file.createDataSet( DATASETNAME, PredType::STD_I32BE, dataspace, prop); prop.close(); dataspace.close(); } catch (Exception &error) { // Throw FileIException, DataSetIException, DataSpaceIException throw; } }
void test_szip_filter(H5File& file1) { #ifdef H5_HAVE_FILTER_SZIP int points[DSET_DIM1][DSET_DIM2], check[DSET_DIM1][DSET_DIM2]; unsigned szip_options_mask=H5_SZIP_NN_OPTION_MASK; unsigned szip_pixels_per_block=4; // Output message about test being performed SUBTEST("szip filter (with encoder)"); if ( h5_szip_can_encode() == 1) { char* tconv_buf = new char [1000]; try { const hsize_t size[2] = {DSET_DIM1, DSET_DIM2}; // Create the data space DataSpace space1(2, size, NULL); // Create a small conversion buffer to test strip mining (?) DSetMemXferPropList xfer; xfer.setBuffer (1000, tconv_buf, NULL); // Prepare dataset create property list DSetCreatPropList dsplist; dsplist.setChunk(2, chunk_size); // Set up for szip compression dsplist.setSzip(szip_options_mask, szip_pixels_per_block); // Create a dataset with szip compression DataSpace space2 (2, size, NULL); DataSet dataset(file1.createDataSet (DSET_SZIP_NAME, PredType::NATIVE_INT, space2, dsplist)); hsize_t i, j, n; for (i=n=0; i<size[0]; i++) { for (j=0; j<size[1]; j++) { points[i][j] = (int)n++; } } // Write to the dataset then read back the values dataset.write ((void*)points, PredType::NATIVE_INT, DataSpace::ALL, DataSpace::ALL, xfer); dataset.read ((void*)check, PredType::NATIVE_INT, DataSpace::ALL, DataSpace::ALL, xfer); // 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++) { int status = check_values (i, j, points[i][j], check[i][j]); if (status == -1) throw Exception("test_szip_filter", "Failed in testing szip method"); } dsplist.close(); PASSED(); } // end of try // catch all other exceptions catch (Exception E) { issue_fail_msg("test_szip_filter()", __LINE__, __FILE__, E.getCDetailMsg()); } delete[] tconv_buf; } // if szip presents else { SKIPPED(); } #else /* H5_HAVE_FILTER_SZIP */ SUBTEST("szip filter"); SKIPPED(); puts(" Szip filter not enabled"); #endif /* H5_HAVE_FILTER_SZIP */ } // test_szip_filter
/*------------------------------------------------------------------------- * Function: test_compact_vlstring * * Purpose: Test storing VL strings in compact datasets. * * Return: None * * Programmer: Binh-Minh Ribler (use C version) * January, 2007 * *------------------------------------------------------------------------- */ static void test_compact_vlstring() { // Output message about test being performed SUBTEST("VL Strings on Compact Dataset"); try { // Create file H5File file1(FILENAME, H5F_ACC_TRUNC); // Create dataspace for datasets hsize_t dims1[] = {SPACE1_DIM1}; DataSpace sid1(SPACE1_RANK, dims1); // Create a datatype to refer to StrType vlst(0, H5T_VARIABLE); // Create dataset create property list and set layout DSetCreatPropList plist; plist.setLayout(H5D_COMPACT); // Create a dataset DataSet dataset(file1.createDataSet("Dataset5", vlst, sid1, plist)); // Write dataset to disk const char *wdata[SPACE1_DIM1] = {"one", "two", "three", "four"}; dataset.write(wdata, vlst); // Read dataset from disk char *rdata[SPACE1_DIM1]; // Information read in dataset.read(rdata, vlst); // Compare data read in hsize_t i; for (i=0; i<SPACE1_DIM1; i++) { if (HDstrlen(wdata[i])!=strlen(rdata[i])) { TestErrPrintf("VL data length don't match!, strlen(wdata[%d])=%d, strlen(rdata[%d])=%d\n",(int)i,(int)strlen(wdata[i]),(int)i,(int)strlen(rdata[i])); continue; } // end if if (HDstrcmp(wdata[i],rdata[i]) != 0) { TestErrPrintf("VL data values don't match!, wdata[%d]=%s, rdata[%d]=%s\n",(int)i,wdata[i],(int)i,rdata[i]); continue; } // end if } // end for // Reclaim the read VL data DataSet::vlenReclaim((void *)rdata, vlst, sid1); // Close objects and file dataset.close(); vlst.close(); sid1.close(); plist.close(); file1.close(); PASSED(); } // end try // Catch all exceptions. catch (Exception E) { issue_fail_msg("test_compact_vlstrings()", __LINE__, __FILE__, E.getCDetailMsg()); } } // test_compact_vlstrings
/*------------------------------------------------------------------------- * Function: test_vlstrings_special * * Purpose: Test VL string code for special string cases, nil and * zero-sized. * * Return: None * * Programmer: Binh-Minh Ribler (use C version) * January, 2007 * *------------------------------------------------------------------------- */ static void test_vlstrings_special() { const char *wdata[SPACE1_DIM1] = {"one", "two", "", "four"}; const char *wdata2[SPACE1_DIM1] = {NULL, NULL, NULL, NULL}; char *rdata[SPACE1_DIM1]; // Information read in // Output message about test being performed. SUBTEST("Special VL Strings"); try { // Create file. H5File file1(FILENAME, H5F_ACC_TRUNC); // Create dataspace for datasets. hsize_t dims1[] = {SPACE1_DIM1}; DataSpace sid1(SPACE1_RANK, dims1); // Create a datatype to refer to. StrType vlst(0, H5T_VARIABLE); // Create a dataset. DataSet dataset(file1.createDataSet("Dataset3", vlst, sid1)); // Read from the dataset before writing data. dataset.read(rdata, vlst); // Check data read in. hsize_t i; // counting variable for (i=0; i<SPACE1_DIM1; i++) if(rdata[i]!=NULL) TestErrPrintf("VL doesn't match!, rdata[%d]=%p\n",(int)i,rdata[i]); // Write dataset to disk, then read it back. dataset.write(wdata, vlst); dataset.read(rdata, vlst); // Compare data read in. for (i = 0; i < SPACE1_DIM1; i++) { size_t wlen = HDstrlen(wdata[i]); size_t rlen = HDstrlen(rdata[i]); if(wlen != rlen) { TestErrPrintf("VL data lengths don't match!, strlen(wdata[%d])=%u, strlen(rdata[%d])=%u\n", (int)i, (unsigned)wlen, (int)i, (unsigned)rlen); continue; } // end if if(HDstrcmp(wdata[i],rdata[i]) != 0) { TestErrPrintf("VL data values don't match!, wdata[%d]=%s, rdata[%d]=%s\n", (int)i, wdata[i], (int)i, rdata[i]); continue; } // end if } // end for // Reclaim the read VL data. DataSet::vlenReclaim((void *)rdata, vlst, sid1); // Close Dataset. dataset.close(); /* * Create another dataset to test nil strings. */ // Create the property list and set the fill value for the second // dataset. DSetCreatPropList dcpl; char *fill = NULL; // Fill value dcpl.setFillValue(vlst, &fill); dataset = file1.createDataSet("Dataset4", vlst, sid1, dcpl); // Close dataset creation property list. dcpl.close(); // Read from dataset before writing data. dataset.read(rdata, vlst); // Check data read in. for (i=0; i<SPACE1_DIM1; i++) if(rdata[i]!=NULL) TestErrPrintf("VL doesn't match!, rdata[%d]=%p\n",(int)i,rdata[i]); // Try to write nil strings to disk. dataset.write(wdata2, vlst); // Read nil strings back from disk. dataset.read(rdata, vlst); // Check data read in. for (i=0; i<SPACE1_DIM1; i++) if(rdata[i]!=NULL) TestErrPrintf("VL doesn't match!, rdata[%d]=%p\n",(int)i,rdata[i]); // Close objects and file. dataset.close(); vlst.close(); sid1.close(); file1.close(); PASSED(); } // end try // Catch all exceptions. catch (Exception E) { issue_fail_msg("test_vlstrings_special()", __LINE__, __FILE__, E.getCDetailMsg()); } } // test_vlstrings_special