Changed: Moved all HDF5-related items inside #ifdef HAS_HDF5
This commit is contained in:
parent
f7422867d5
commit
04de5528ad
@ -13,10 +13,8 @@
|
||||
|
||||
#include "HDF5Base.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#ifdef HAS_HDF5
|
||||
#include <numeric>
|
||||
#include <iostream>
|
||||
#include <unistd.h>
|
||||
#ifdef HAVE_MPI
|
||||
#include "ProcessAdm.h"
|
||||
@ -26,26 +24,23 @@
|
||||
|
||||
|
||||
HDF5Base::HDF5Base (const std::string& name, const ProcessAdm& adm)
|
||||
: m_file(-1), m_hdf5_name(name)
|
||||
: m_hdf5_name(name)
|
||||
#ifdef HAVE_MPI
|
||||
, m_adm(adm)
|
||||
#endif
|
||||
{
|
||||
#ifdef HAS_HDF5
|
||||
m_file = -1;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
HDF5Base::~HDF5Base ()
|
||||
{
|
||||
closeFile();
|
||||
}
|
||||
|
||||
|
||||
bool HDF5Base::openFile (unsigned flags)
|
||||
bool HDF5Base::openFile (unsigned int flags)
|
||||
{
|
||||
#ifdef HAS_HDF5
|
||||
if (m_file != -1)
|
||||
return true;
|
||||
|
||||
#ifdef HAS_HDF5
|
||||
#ifdef HAVE_MPI
|
||||
MPI_Info info = MPI_INFO_NULL;
|
||||
hid_t acc_tpl = H5Pcreate(H5P_FILE_ACCESS);
|
||||
@ -80,23 +75,22 @@ void HDF5Base::closeFile()
|
||||
#ifdef HAS_HDF5
|
||||
if (m_file != -1)
|
||||
H5Fclose(m_file);
|
||||
#endif
|
||||
m_file = -1;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
#ifdef HAS_HDF5
|
||||
bool HDF5Base::checkGroupExistence (hid_t parent, const char* path)
|
||||
{
|
||||
bool result = false;
|
||||
#ifdef HAS_HDF5
|
||||
// turn off errors to avoid cout spew
|
||||
H5E_BEGIN_TRY {
|
||||
#if H5_VERS_MINOR > 8
|
||||
result = H5Lexists(parent, path, H5P_DEFAULT) == 1;
|
||||
return H5Lexists(parent,path,H5P_DEFAULT) == 1;
|
||||
#else
|
||||
result = H5Gget_objinfo((hid_t)parent,path,0,nullptr) == 0;
|
||||
return H5Gget_objinfo((hid_t)parent,path,0,nullptr) == 0;
|
||||
#endif
|
||||
} H5E_END_TRY;
|
||||
#endif
|
||||
return result;
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
@ -15,13 +15,10 @@
|
||||
#define _HDF5_BASE_H
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#ifdef HAS_HDF5
|
||||
#include <hdf5.h>
|
||||
#endif
|
||||
|
||||
|
||||
class ProcessAdm;
|
||||
|
||||
|
||||
@ -32,36 +29,32 @@ class ProcessAdm;
|
||||
class HDF5Base
|
||||
{
|
||||
public:
|
||||
#ifndef HAS_HDF5
|
||||
using hid_t = int; //!< Type alias providing hid_t without the hdf5 library
|
||||
using herr_t = int; //!< Type alias providing herr_t without the hdf5 library
|
||||
#endif
|
||||
//! \brief The constructor opens a named HDF5-file.
|
||||
//! \param[in] name The name (without extension) of the data file
|
||||
//! \param[in] adm The process administrator
|
||||
HDF5Base(const std::string& name, const ProcessAdm& adm);
|
||||
|
||||
//! \brief The destructor closes the file.
|
||||
virtual ~HDF5Base();
|
||||
virtual ~HDF5Base() { this->closeFile(); }
|
||||
|
||||
protected:
|
||||
//! \brief Open the HDF5 file.
|
||||
//!\ param flag Mode to open file using
|
||||
bool openFile (unsigned flag);
|
||||
|
||||
//! \brief Close the HDF5 file.
|
||||
//! \brief Opens the HDF5 file.
|
||||
//! \param[in] flag Mode to open file using
|
||||
bool openFile(unsigned int flag);
|
||||
//! \brief Closes the HDF5 file.
|
||||
void closeFile();
|
||||
|
||||
#ifdef HAS_HDF5
|
||||
//! \brief Internal helper function checking if a group exists in the file.
|
||||
//! \param[in] parent The HDF5 group of the parent
|
||||
//! \param[in] path Path of dataset
|
||||
//! \return \e true if group exists, otherwise \e false
|
||||
bool checkGroupExistence (hid_t parent, const char* path);
|
||||
static bool checkGroupExistence(hid_t parent, const char* path);
|
||||
|
||||
hid_t m_file; //!< The HDF5 handle for our file
|
||||
hid_t m_file; //!< The HDF5 handle for our file
|
||||
#endif
|
||||
std::string m_hdf5_name; //!< The file name of the HDF5 file
|
||||
#ifdef HAVE_MPI
|
||||
const ProcessAdm& m_adm; //!< Pointer to process adm in use
|
||||
const ProcessAdm& m_adm; //!< Pointer to process administrator in use
|
||||
#endif
|
||||
};
|
||||
|
||||
|
@ -86,10 +86,10 @@ int HDF5Writer::getLastTimeLevel ()
|
||||
|
||||
void HDF5Writer::openFile(int level)
|
||||
{
|
||||
#ifdef HAS_HDF5
|
||||
if (m_file != -1)
|
||||
return;
|
||||
|
||||
#ifdef HAS_HDF5
|
||||
if (m_flag == H5F_ACC_RDWR) {
|
||||
struct stat buffer;
|
||||
if (stat(m_name.c_str(),&buffer) != 0)
|
||||
@ -133,10 +133,10 @@ void HDF5Writer::closeFile(int level)
|
||||
}
|
||||
|
||||
|
||||
#ifdef HAS_HDF5
|
||||
void HDF5Writer::writeArray(hid_t group, const std::string& name, int patch,
|
||||
int len, const void* data, hid_t type)
|
||||
{
|
||||
#ifdef HAS_HDF5
|
||||
#ifdef HAVE_MPI
|
||||
int lens[m_size], lens2[m_size];
|
||||
std::fill(lens,lens+m_size,len);
|
||||
@ -178,10 +178,8 @@ void HDF5Writer::writeArray(hid_t group, const std::string& name, int patch,
|
||||
H5Sclose(space);
|
||||
if (group1 != -1)
|
||||
H5Gclose(group1);
|
||||
#else
|
||||
std::cout << "HDF5Writer: compiled without HDF5 support, no data written" << std::endl;
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
void HDF5Writer::writeVector(int level, const DataEntry& entry)
|
||||
@ -219,10 +217,13 @@ void HDF5Writer::writeBasis (int level, const DataEntry& entry,
|
||||
if (!entry.second.enabled || !entry.second.data)
|
||||
return;
|
||||
|
||||
#ifdef HAS_HDF5
|
||||
const SIMbase* sim = static_cast<const SIMbase*>(entry.second.data);
|
||||
|
||||
this->writeBasis(sim, prefix+sim->getName()+"-1", 1, level,
|
||||
entry.second.results & DataExporter::REDUNDANT);
|
||||
#else
|
||||
std::cout <<"HDF5Writer: Compiled without HDF5 support, no data written."<< std::endl;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@ -530,10 +531,10 @@ void HDF5Writer::writeKnotspan (int level, const DataEntry& entry,
|
||||
}
|
||||
|
||||
|
||||
#ifdef HAS_HDF5
|
||||
void HDF5Writer::writeBasis (const SIMbase* sim, const std::string& name,
|
||||
int basis, int level, bool redundant)
|
||||
{
|
||||
#ifdef HAS_HDF5
|
||||
std::stringstream str;
|
||||
str << "/" << level << '/' << name;
|
||||
hid_t group;
|
||||
@ -561,8 +562,8 @@ void HDF5Writer::writeBasis (const SIMbase* sim, const std::string& name,
|
||||
}
|
||||
}
|
||||
H5Gclose(group);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
// TODO: implement for variable time steps.
|
||||
|
@ -92,6 +92,7 @@ public:
|
||||
//! \param[in] tp The current time stepping info
|
||||
virtual bool writeTimeInfo(int level, int interval, const TimeStep& tp);
|
||||
|
||||
#ifdef HAS_HDF5
|
||||
protected:
|
||||
//! \brief Internal helper function writing a data array to file.
|
||||
//! \param[in] group The HDF5 group to write data into
|
||||
@ -113,7 +114,6 @@ protected:
|
||||
int basis, int level, bool redundant = false);
|
||||
|
||||
private:
|
||||
#ifdef HAS_HDF5
|
||||
unsigned int m_flag; //!< The file flags to open HDF5 file with
|
||||
#endif
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user