#include <libdash.h>
#include <iostream>
#ifdef DASH_ENABLE_HDF5
#define FILENAME "example.hdf5"
using std::cout;
using std::cerr;
using std::endl;
void print_file(){
int status;
std::string syscall = "h5dump ";
status = system((syscall + FILENAME).c_str());
}
}
void print_separator(){
cout << "=======================================================" << endl;
}
}
int main(int argc, char * argv[])
{
pattern_t pattern_a(extent, dash::TILE(10));
pattern_t pattern_b(extent, dash::TILE(7));
if(myid == 0){
cout << "DASH HDF5 API example. After each change in the hdf5 file "
<< "the contents are printed using h5dump" << endl;
}
{
if(myid == 0) {
print_separator();
cout << "Write Array A to " << FILENAME << " / group/data" << endl;
}
StoreHDF::write(array_a, FILENAME, "group/data");
print_file();
}
{
if(myid == 0){
print_separator();
cout << "Read " << FILENAME << " / group/data into Array C, "
<< "reconstruct pattern" << endl;
}
StoreHDF::read(array_c, FILENAME, "group/data");
}
{
if(myid == 0){
print_separator();
cout << "Read " << FILENAME
<< " / group/data into already allocated Array C" << endl;
}
StoreHDF::read(array_c, FILENAME, "group/data");
if(myid == 0){
cout << "Array A Pattern: Tilesize: "
<< array_a.
pattern().blocksize(0) << endl;
cout << "Array C Pattern: Tilesize: "
<< array_c.
pattern().blocksize(0) << endl;
}
}
{
if(myid == 0){
print_separator();
cout << "Add dataset temperature to " << FILENAME << endl;
}
hdf5_options fopts;
fopts.overwrite_file = false;
StoreHDF::write(array_b, FILENAME, "temperature", fopts);
print_file();
}
{
if(myid == 0){
print_separator();
cout << "Modify " << FILENAME << " / temperature dataset" << endl;
}
hdf5_options fopts;
fopts.overwrite_file = false;
fopts.modify_dataset = true;
StoreHDF::write(array_a, FILENAME, "temperature", fopts);
print_file();
}
sleep(1);
if(myid == 0){
remove(FILENAME);
}
return EXIT_SUCCESS;
}
#else
int main(int argc, char * argv[])
{
std::cout << "To run this example build DASH with HDF5 support" << std::endl;
return EXIT_SUCCESS;
}
#endif // DASH_ENABLE_HDF5