Skip to content

Commit

Permalink
Update more of examples
Browse files Browse the repository at this point in the history
  • Loading branch information
byrnHDF committed Nov 25, 2024
1 parent e155df1 commit 820853f
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 62 deletions.
38 changes: 14 additions & 24 deletions HDF5Examples/HFCXX/H5D/chunks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,16 @@
*/

#include <iostream>
using std::cout;
using std::endl;

#include <string>
#include "H5Cpp.h"
using namespace H5;
#include <highfive/highfive.hpp>
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)
Expand All @@ -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
Expand All @@ -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;

Expand Down
67 changes: 29 additions & 38 deletions HDF5Examples/HFCXX/H5D/writedata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,38 +10,36 @@
* [email protected]. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

/*
* 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 <iostream>
using std::cout;
using std::endl;

#include <string>
#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 <highfive/highfive.hpp>
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)
Expand All @@ -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.
Expand Down

0 comments on commit 820853f

Please sign in to comment.