Program Listing for File hdf5.h

Return to documentation for file (include/amici/hdf5.h)

#ifndef AMICI_HDF5_H
#define AMICI_HDF5_H

#include <memory>
#include <string>
#include <vector>

#include <H5Cpp.h>

#include <gsl/gsl-lite.hpp>

/* Macros for enabling/disabling  HDF5 error auto-printing
 * AMICI_H5_SAVE_ERROR_HANDLER and AMICI_H5_RESTORE_ERROR_HANDLER must be called
 * within the same context, otherwise the stack handler is lost. */
#define AMICI_H5_SAVE_ERROR_HANDLER                                            \
    herr_t (*old_func)(void*);                                                 \
    void* old_client_data;                                                     \
    H5Eget_auto1(&old_func, &old_client_data);                                 \
    H5Eset_auto1(NULL, NULL)

#define AMICI_H5_RESTORE_ERROR_HANDLER H5Eset_auto1(old_func, old_client_data)

namespace amici {

class ReturnData;
class ExpData;
class Model;
class Solver;

namespace hdf5 {

/* Functions for reading and writing AMICI data to/from HDF5 files. */

H5::H5File createOrOpenForWriting(std::string const& hdf5filename);

void readSolverSettingsFromHDF5(
    const H5::H5File& file, Solver& solver, std::string const& datasetPath
);

void writeSolverSettingsToHDF5(
    Solver const& solver, std::string const& hdf5Filename,
    std::string const& hdf5Location
);

void writeSolverSettingsToHDF5(
    Solver const& solver, H5::H5File const& file,
    std::string const& hdf5Location
);

void readSolverSettingsFromHDF5(
    std::string const& hdffile, Solver& solver, std::string const& datasetPath
);

void readModelDataFromHDF5(
    std::string const& hdffile, Model& model, std::string const& datasetPath
);

void readModelDataFromHDF5(
    H5::H5File const& file, Model& model, std::string const& datasetPath
);

void writeReturnData(
    ReturnData const& rdata, H5::H5File const& file,
    std::string const& hdf5Location
);

void writeReturnData(
    ReturnData const& rdata, std::string const& hdf5Filename,
    std::string const& hdf5Location
);

void writeReturnDataDiagnosis(
    ReturnData const& rdata, H5::H5File const& file,
    std::string const& hdf5Location
);

void createGroup(
    const H5::H5File& file, std::string const& groupPath,
    bool recursively = true
);

std::unique_ptr<ExpData> readSimulationExpData(
    std::string const& hdf5Filename, std::string const& hdf5Root,
    Model const& model
);

void writeSimulationExpData(
    ExpData const& edata, H5::H5File const& file,
    std::string const& hdf5Location
);

bool attributeExists(
    H5::H5File const& file, std::string const& optionsObject,
    std::string const& attributeName
);

bool attributeExists(
    H5::H5Object const& object, std::string const& attributeName
);

void createAndWriteInt1DDataset(
    H5::H5File const& file, std::string const& datasetName,
    gsl::span<int const> buffer
);

void createAndWriteInt2DDataset(
    H5::H5File const& file, std::string const& datasetName,
    gsl::span<int const> buffer, hsize_t m, hsize_t n
);

void createAndWriteDouble1DDataset(
    H5::H5File const& file, std::string const& datasetName,
    gsl::span<double const> buffer
);

void createAndWriteDouble2DDataset(
    H5::H5File const& file, std::string const& datasetName,
    gsl::span<double const> buffer, hsize_t m, hsize_t n
);

void createAndWriteDouble3DDataset(
    H5::H5File const& file, std::string const& datasetName,
    gsl::span<double const> buffer, hsize_t m, hsize_t n, hsize_t o
);

std::string getStringAttribute(
    H5::H5File const& file, std::string const& optionsObject,
    std::string const& attributeName
);

double getDoubleScalarAttribute(
    const H5::H5File& file, std::string const& optionsObject,
    std::string const& attributeName
);

int getIntScalarAttribute(
    const H5::H5File& file, std::string const& optionsObject,
    std::string const& attributeName
);

std::vector<int>
getIntDataset1D(const H5::H5File& file, std::string const& name);

std::vector<double>
getDoubleDataset1D(const H5::H5File& file, std::string const& name);

std::vector<double> getDoubleDataset2D(
    const H5::H5File& file, std::string const& name, hsize_t& m, hsize_t& n
);

std::vector<double> getDoubleDataset3D(
    const H5::H5File& file, std::string const& name, hsize_t& m, hsize_t& n,
    hsize_t& o
);

bool locationExists(std::string const& filename, std::string const& location);

bool locationExists(H5::H5File const& file, std::string const& location);

} // namespace hdf5
} // namespace amici

#endif