#include <iostream>
using std::cout;
using std::endl;
#include <string>
#include "H5Cpp.h"
const H5std_string FILE_NAME("Group.h5");
const int RANK = 2;
extern "C" herr_t file_info(hid_t loc_id, const char *name, const H5L_info2_t *linfo, void *opdata);
int
main(void)
{
hsize_t dims[2];
hsize_t cdims[2];
try {
H5File *file = new H5File(FILE_NAME, H5F_ACC_TRUNC);
Group *group = new Group(file->createGroup("/Data"));
dims[0] = 1000;
dims[1] = 20;
cdims[0] = 20;
cdims[1] = 20;
DataSpace * dataspace = new DataSpace(RANK, dims);
DSetCreatPropList ds_creatplist;
ds_creatplist.setChunk(2, cdims);
ds_creatplist.setDeflate(6);
DataSet *dataset = new DataSet(
delete dataset;
delete dataspace;
dims[0] = 500;
dims[1] = 20;
dataspace = new DataSpace(RANK, dims);
delete dataset;
delete dataspace;
delete group;
delete file;
file = new H5File(FILE_NAME, H5F_ACC_RDWR);
group = new Group(file->openGroup("Data"));
try {
dataset = new DataSet(group->openDataSet("Compressed_Data"));
}
catch (GroupIException not_found_error) {
cout << " Dataset is not found." << endl;
}
cout << "dataset \"/Data/Compressed_Data\" is open" << endl;
delete dataset;
file->link(H5L_TYPE_HARD, "Data", "Data_new");
try {
dataset = new DataSet(file->openDataSet("/Data_new/Compressed_Data"));
}
catch (FileIException not_found_error) {
cout << " Dataset is not found." << endl;
}
cout << "dataset \"/Data_new/Compressed_Data\" is open" << endl;
delete dataset;
cout << endl << "Iterating over elements in the file" << endl;
herr_t idx = H5Literate2(file->getId(), H5_INDEX_NAME, H5_ITER_INC, NULL, file_info, NULL);
cout << endl;
cout << "Unlinking..." << endl;
try {
file->unlink("Data");
}
catch (FileIException unlink_error) {
cout << " unlink failed." << endl;
}
cout << "\"Data\" is unlinked" << endl;
cout << endl << "Iterating over elements in the file again" << endl;
idx = H5Literate2(file->getId(), H5_INDEX_NAME, H5_ITER_INC, NULL, file_info, NULL);
cout << endl;
delete group;
delete file;
}
catch (FileIException error) {
error.printErrorStack();
return -1;
}
catch (DataSetIException error) {
error.printErrorStack();
return -1;
}
catch (DataSpaceIException error) {
error.printErrorStack();
return -1;
}
catch (AttributeIException error) {
error.printErrorStack();
return -1;
}
return 0;
}
herr_t
file_info(hid_t loc_id, const char *name, const H5L_info2_t *linfo, void *opdata)
{
hid_t group;
group = H5Gopen2(loc_id, name, H5P_DEFAULT);
cout << "Name : " << name << endl;
H5Gclose(group);
return 0;
}
static void dontPrint()
Turns off the automatic error printing from the C library.
Definition: H5Exception.cpp:161
static const PredType & NATIVE_FLOAT
Definition: H5PredType.h:157
static const PredType & NATIVE_INT
Definition: H5PredType.h:151
Definition: H5AbstractDs.cpp:34