summaryrefslogtreecommitdiffstats
path: root/c++/examples/h5tutr_extend.cpp
diff options
context:
space:
mode:
authorAllen Byrne <byrn@hdfgroup.org>2020-10-01 14:04:36 (GMT)
committerAllen Byrne <byrn@hdfgroup.org>2020-10-01 14:04:36 (GMT)
commitf1ba03cea5b82699a984c80bd2deac14fdc8df18 (patch)
treeebe777c3e0b83f4c4cec9212731da9ebe0a0cfd3 /c++/examples/h5tutr_extend.cpp
parent10343c197906415388f2a4c8d292e21d25cf7381 (diff)
downloadhdf5-f1ba03cea5b82699a984c80bd2deac14fdc8df18.zip
hdf5-f1ba03cea5b82699a984c80bd2deac14fdc8df18.tar.gz
hdf5-f1ba03cea5b82699a984c80bd2deac14fdc8df18.tar.bz2
Source formatted
Diffstat (limited to 'c++/examples/h5tutr_extend.cpp')
-rw-r--r--c++/examples/h5tutr_extend.cpp87
1 files changed, 39 insertions, 48 deletions
diff --git a/c++/examples/h5tutr_extend.cpp b/c++/examples/h5tutr_extend.cpp
index 94e9acf..71a8ffb 100644
--- a/c++/examples/h5tutr_extend.cpp
+++ b/c++/examples/h5tutr_extend.cpp
@@ -24,34 +24,28 @@ using std::endl;
#include "H5Cpp.h"
using namespace H5;
-const H5std_string FILE_NAME("h5tutr_extend.h5");
-const H5std_string DATASETNAME("ExtendibleArray");
+const H5std_string FILE_NAME("h5tutr_extend.h5");
+const H5std_string DATASETNAME("ExtendibleArray");
-int main (void)
+int
+main(void)
{
- hsize_t dims[2] = {3,3}; // dataset dimensions at creation
- hsize_t maxdims[2] = {H5S_UNLIMITED, H5S_UNLIMITED};
- hsize_t chunk_dims[2] ={2, 5};
- int data[3][3] = { {1, 1, 1}, // data to write
- {1, 1, 1},
- {1, 1, 1} };
-
- // Variables used in extending and writing to the extended portion of dataset
-
- hsize_t size[2];
- hsize_t offset[2];
- hsize_t dimsext[2] = {7, 3}; // extend dimensions
- int dataext[7][3] = { {2, 3, 4},
- {2, 3, 4},
- {2, 3, 4},
- {2, 3, 4},
- {2, 3, 4},
- {2, 3, 4},
- {2, 3, 4} };
+ hsize_t dims[2] = {3, 3}; // dataset dimensions at creation
+ hsize_t maxdims[2] = {H5S_UNLIMITED, H5S_UNLIMITED};
+ hsize_t chunk_dims[2] = {2, 5};
+ int data[3][3] = {{1, 1, 1}, // data to write
+ {1, 1, 1},
+ {1, 1, 1}};
+
+ // Variables used in extending and writing to the extended portion of dataset
+
+ hsize_t size[2];
+ hsize_t offset[2];
+ hsize_t dimsext[2] = {7, 3}; // extend dimensions
+ int dataext[7][3] = {{2, 3, 4}, {2, 3, 4}, {2, 3, 4}, {2, 3, 4}, {2, 3, 4}, {2, 3, 4}, {2, 3, 4}};
// Try block to detect exceptions raised by any of the calls inside it
- try
- {
+ try {
// Turn off the auto-printing when failure occurs so that we can
// handle the errors appropriately
Exception::dontPrint();
@@ -63,15 +57,15 @@ int main (void)
// for the instance 'dataspace'. It can be deleted and used again
// later for another dataspace. An HDF5 identifier can be closed
// by the destructor or the method 'close()'.
- DataSpace *dataspace = new DataSpace (2, dims, maxdims);
+ DataSpace *dataspace = new DataSpace(2, dims, maxdims);
// Modify dataset creation property to enable chunking
DSetCreatPropList prop;
prop.setChunk(2, chunk_dims);
// Create the chunked dataset. Note the use of pointer.
- DataSet *dataset = new DataSet(file.createDataSet( DATASETNAME,
- PredType::STD_I32BE, *dataspace, prop) );
+ DataSet *dataset =
+ new DataSet(file.createDataSet(DATASETNAME, PredType::STD_I32BE, *dataspace, prop));
// Write data to dataset.
dataset->write(data, PredType::NATIVE_INT);
@@ -82,9 +76,9 @@ int main (void)
dataset->extend(size);
// Select a hyperslab in extended portion of the dataset.
- DataSpace *filespace = new DataSpace(dataset->getSpace ());
- offset[0] = 3;
- offset[1] = 0;
+ DataSpace *filespace = new DataSpace(dataset->getSpace());
+ offset[0] = 3;
+ offset[1] = 0;
filespace->selectHyperslab(H5S_SELECT_SET, dimsext, offset);
// Define memory space.
@@ -105,25 +99,26 @@ int main (void)
// Re-open the file and read the data back
// ---------------------------------------
- int rdata[10][3];
- int i,j, rank, rank_chunk;
- hsize_t chunk_dimsr[2], dimsr[2];
+ int rdata[10][3];
+ int i, j, rank, rank_chunk;
+ hsize_t chunk_dimsr[2], dimsr[2];
// Open the file and dataset.
file.openFile(FILE_NAME, H5F_ACC_RDONLY);
- dataset = new DataSet(file.openDataSet( DATASETNAME));
+ dataset = new DataSet(file.openDataSet(DATASETNAME));
// Get the dataset's dataspace and creation property list.
filespace = new DataSpace(dataset->getSpace());
- prop = dataset->getCreatePlist();
+ prop = dataset->getCreatePlist();
// Get information to obtain memory dataspace.
- rank = filespace->getSimpleExtentNdims();
+ rank = filespace->getSimpleExtentNdims();
herr_t status_n = filespace->getSimpleExtentDims(dimsr);
if (H5D_CHUNKED == prop.getLayout())
- rank_chunk = prop.getChunk(rank, chunk_dimsr);
- cout << "rank chunk = " << rank_chunk << endl;;
+ rank_chunk = prop.getChunk(rank, chunk_dimsr);
+ cout << "rank chunk = " << rank_chunk << endl;
+ ;
memspace = new DataSpace(rank, dimsr, NULL);
dataset->read(rdata, PredType::NATIVE_INT, *memspace, *filespace);
@@ -131,7 +126,7 @@ int main (void)
cout << endl;
for (j = 0; j < dimsr[0]; j++) {
for (i = 0; i < dimsr[1]; i++)
- cout << " " << rdata[j][i];
+ cout << " " << rdata[j][i];
cout << endl;
}
@@ -142,29 +137,25 @@ int main (void)
delete dataset;
file.close();
- } // end of try block
+ } // end of try block
// catch failure caused by the H5File operations
- catch(FileIException error)
- {
+ catch (FileIException error) {
error.printErrorStack();
return -1;
}
// catch failure caused by the DataSet operations
- catch(DataSetIException error)
- {
+ catch (DataSetIException error) {
error.printErrorStack();
return -1;
}
// catch failure caused by the DataSpace operations
- catch(DataSpaceIException error)
- {
+ catch (DataSpaceIException error) {
error.printErrorStack();
return -1;
}
- return 0; // successfully terminated
+ return 0; // successfully terminated
}
-