diff --git a/HDF5Examples/HFCXX/H5D/chunks.cpp b/HDF5Examples/HFCXX/H5D/chunks.cpp index 2b4b09ff050..1f6ca1ea230 100644 --- a/HDF5Examples/HFCXX/H5D/chunks.cpp +++ b/HDF5Examples/HFCXX/H5D/chunks.cpp @@ -16,19 +16,16 @@ */ #include -using std::cout; -using std::endl; - #include -#include "H5Cpp.h" -using namespace H5; +#include +using namespace HighFive; -const H5std_string FILE_NAME("SDSextendible.h5"); -const H5std_string DATASET_NAME("ExtendibleArray"); -const int NX = 10; -const int NY = 5; -const int RANK = 2; -const int RANKC = 1; +const std::string FILE_NAME("SDSextendible.h5"); +const std::string DATASET_NAME("ExtendibleArray"); +const int NX = 10; +const int NY = 5; +const int RANK = 2; +const int RANKC = 1; int main(void) @@ -37,17 +34,11 @@ main(void) // Try block to detect exceptions raised by any of the calls inside it try { - /* - * Turn off the auto-printing when failure occurs so that we can - * handle the errors appropriately - */ - Exception::dontPrint(); + // we open the existing hdf5 file we created before + File file(FILE_NAME, File::ReadOnly); - /* - * Open the file and the dataset. - */ - H5File file(FILE_NAME, H5F_ACC_RDONLY); - DataSet dataset = file.openDataSet(DATASET_NAME); + // we get the dataset + DataSet dataset = file.getDataSet(DATASET_NAME); /* * Get filespace for rank and dimension @@ -57,13 +48,12 @@ main(void) /* * Get number of dimensions in the file dataspace */ - int rank = filespace.getSimpleExtentNdims(); + int rank = filespace.getNumberDimensions(); /* * Get and print the dimension sizes of the file dataspace */ - hsize_t dims[2]; // dataset dimensions - rank = filespace.getSimpleExtentDims(dims); + auto dims = dspace.getDimensions(); cout << "dataset rank = " << rank << ", dimensions " << (unsigned long)(dims[0]) << " x " << (unsigned long)(dims[1]) << endl; diff --git a/HDF5Examples/HFCXX/H5D/writedata.cpp b/HDF5Examples/HFCXX/H5D/writedata.cpp index f446b2f390e..0426aece87b 100644 --- a/HDF5Examples/HFCXX/H5D/writedata.cpp +++ b/HDF5Examples/HFCXX/H5D/writedata.cpp @@ -10,38 +10,36 @@ * help@hdfgroup.org. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ -/* - * This program shows how the select_hyperslab and select_elements - * functions are used to write selected data from memory to the file. - * Program takes 48 elements from the linear buffer and writes them into - * the matrix using 3x2 blocks, (4,3) stride and (2,4) count. - * Then four elements of the matrix are overwritten with the new values and - * file is closed. Program reopens the file and reads and displays the result. - */ +// +// This program shows how the select_hyperslab and select_elements +// functions are used to write selected data from memory to the file. +// Program takes 48 elements from the linear buffer and writes them into +// the matrix using 3x2 blocks, (4,3) stride and (2,4) count. +// Then four elements of the matrix are overwritten with the new values and +// file is closed. Program reopens the file and reads and displays the result. +// #include -using std::cout; -using std::endl; #include -#include "H5Cpp.h" -using namespace H5; - -const H5std_string FILE_NAME("Select.h5"); -const H5std_string DATASET_NAME("Matrix in file"); -const int MSPACE1_RANK = 1; // Rank of the first dataset in memory -const int MSPACE1_DIM = 50; // Dataset size in memory -const int MSPACE2_RANK = 1; // Rank of the second dataset in memory -const int MSPACE2_DIM = 4; // Dataset size in memory -const int FSPACE_RANK = 2; // Dataset rank as it is stored in the file -const int FSPACE_DIM1 = 8; // Dimension sizes of the dataset as it is -const int FSPACE_DIM2 = 12; // stored in the file -const int MSPACE_RANK = 2; // Rank of the first dataset in memory -const int MSPACE_DIM1 = 8; // We will read dataset back from the file -const int MSPACE_DIM2 = 9; // to the dataset in memory with these - // dataspace parameters -const int NPOINTS = 4; // Number of points that will be selected - // and overwritten +#include +using namespace HighFive; + +const std::string FILE_NAME("Select.h5"); +const std::string DATASET_NAME("Matrix in file"); +const int MSPACE1_RANK = 1; // Rank of the first dataset in memory +const int MSPACE1_DIM = 50; // Dataset size in memory +const int MSPACE2_RANK = 1; // Rank of the second dataset in memory +const int MSPACE2_DIM = 4; // Dataset size in memory +const int FSPACE_RANK = 2; // Dataset rank as it is stored in the file +const int FSPACE_DIM1 = 8; // Dimension sizes of the dataset as it is +const int FSPACE_DIM2 = 12; // stored in the file +const int MSPACE_RANK = 2; // Rank of the first dataset in memory +const int MSPACE_DIM1 = 8; // We will read dataset back from the file +const int MSPACE_DIM2 = 9; // to the dataset in memory with these + // dataspace parameters +const int NPOINTS = 4; // Number of points that will be selected + // and overwritten int main(void) @@ -52,16 +50,9 @@ main(void) * Try block to detect exceptions raised by any of the calls inside it */ try { - /* - * Turn off the auto-printing when failure occurs so that we can - * handle the errors appropriately - */ - Exception::dontPrint(); - - /* - * Create a file. - */ - H5File *file = new H5File(FILE_NAME, H5F_ACC_TRUNC); + // We create an empty HDF55 file, by truncating an existing + // file if required: + File file(filename, File::Truncate); /* * Create property list for a dataset and set up fill values.