H5CPP  v1.14.0
Modern C++ templates for HDF5 serial and parallel I/O
Loading...
Searching...
No Matches
FILE

Open or create HDF5 files. RAII-managed handles close automatically on scope exit.

File operations

H5CPP exposes two free functions for the HDF5 file lifecycle — h5::open and h5::create — both returning an h5::fd_t RAII handle. There is no explicit h5::close(fd): let the handle go out of scope and H5Fclose runs automatically.

h5::fd_t is the entry point for everything else — datasets, attributes, and groups all open relative to an fd_t. See Object handles for the broader handle taxonomy and the conversion rules to/from raw hid_t.

Operations

  • h5::create — create a new file
  • h5::open — open an existing file
  • Close: RAII (let h5::fd_t destruct, or static_cast<::hid_t> to consume)

Both calls take optional property lists to tune low-level behaviour (cache size, MPI communicator, file driver, …); the defaults work for the common cases.

Notes on lifetime

h5::fd_t follows the rule-of-five RAII contract from Object handles. Copies share the underlying HDF5 reference (via H5Iinc_ref); moves transfer ownership without bumping the refcount; destruction calls H5Fclose only when the last reference goes away.

Practical implication: passing an h5::fd_t by value to a function is cheap (refcount bump, no copy of file data) and the file stays open for as long as any handle exists.

void process(h5::fd_t fd) { // by value: refcount bump
auto v = h5::read<std::vector<float>>(fd, "/grid");
} // refcount decrements; file stays open if caller still holds
h5::fd_t outer = h5::open("data.h5", H5F_ACC_RDONLY);
process(outer); // outer still valid here
T aread(const hid_t &ds, const std::string &name, const h5::acpl_t &acpl=h5::default_acpl)
Read an attribute by name and return its value as type T.
Definition H5Aread.hpp:76
h5::at_t open(const hid_t &parent, const std::string &path, const h5::acpl_t &acpl=h5::default_acpl)
Open an existing attribute by name on a parent HDF5 object.
Definition H5Aopen.hpp:56

Cross-references