SpECTRE  v2024.04.12
HDF5

Functions and classes for manipulating HDF5 files. More...

Namespaces

namespace  h5
 Contains functions and classes for manipulating HDF5 files.
 

Classes

class  h5::Dat
 Represents a multicolumn dat file inside an HDF5 file. More...
 
class  h5::EosTable
 An equation of state table subfile written inside an H5 file. More...
 
class  h5::H5File< Access_t >
 Opens an HDF5 file for access and allows manipulation of data. More...
 
class  h5::Header
 Writes header info about the build, git commit, branch, etc. More...
 
class  h5::Object
 Abstract base class representing an object in an HDF5 file. More...
 
class  h5::SourceArchive
 Writes an archive of the source tree into a dataset. More...
 
class  h5::StellarCollapseEos
 Reads in tabulated equation of state file from stellarcollapse.org More...
 
class  h5::Version
 Used to store the version of the file. More...
 
class  h5::VolumeData
 A volume data subfile written inside an H5 file. More...
 

Macros

#define CHECK_H5(h5_status, m)
 Check if an HDF5 operation was successful. More...
 

Enumerations

enum class  h5::AccessType { h5::AccessType::ReadWrite , h5::AccessType::ReadOnly }
 Set the access type to the H5File. More...
 

Functions

bool h5::check_src_files_match (const std::vector< std::string > &input_filenames)
 Check if all files within input_filenames have the same source archive.
 
bool h5::check_observation_ids_match (const std::vector< std::string > &input_filenames, const std::string &subfile_name)
 Check if all files within input_filenames with volume subfile subfile_name have the same set of observation ids.
 
bool h5::types_equal (hid_t dtype1, hid_t dtype2)
 Check if dtype1 and dtype2 are the same HDF5 data type.
 
template<typename T >
void h5::write_data (hid_t group_id, const std::vector< T > &data, const std::vector< size_t > &extents, const std::string &name="scalar", const bool overwrite_existing=false)
 Write a std::vector named name to the group group_id
 
void h5::write_data (hid_t group_id, const DataVector &data, const std::string &name, const bool overwrite_existing=false)
 Write a DataVector named name to the group group_id
 
template<size_t Dim>
void h5::write_extents (hid_t group_id, const Index< Dim > &extents, const std::string &name="Extents")
 Write the extents as an attribute named name to the group group_id.
 
template<typename Type >
void h5::write_to_attribute (hid_t location_id, const std::string &name, const Type &value)
 Write a value of type Type to an HDF5 attribute named name
 
template<typename T >
void h5::write_to_attribute (hid_t group_id, const std::string &name, const std::vector< T > &data)
 Write the vector data to the attribute attribute_name in the group group_id.
 
template<typename T , size_t Size>
void h5::write_to_attribute (hid_t group_id, const std::string &name, const std::vector< std::array< T, Size > > &data)
 Write the vector<array<fundamental, size>> data to the attribute name in the group group_id.
 
template<typename Type >
Type h5::read_value_attribute (hid_t location_id, const std::string &name)
 Read a value of type Type from an HDF5 attribute named name
 
template<typename Type >
std::vector< Type > h5::read_rank1_attribute (hid_t group_id, const std::string &name)
 Read rank-1 of type Type from an HDF5 attribute named name
 
template<typename T , size_t Size>
std::vector< std::array< T, Size > > h5::read_rank1_array_attribute (hid_t group_id, const std::string &name)
 Read the vector<array<fundamental, size>> from the attribute name in the group group_id.
 
std::vector< std::stringh5::get_attribute_names (hid_t file_id, const std::string &group_name)
 Get the names of all the attributes in a group.
 
void h5::write_connectivity (hid_t group_id, const std::vector< int > &connectivity)
 Write the connectivity into the group in the H5 file.
 
void h5::delete_connectivity (hid_t group_id)
 Delete the connectivity from the group in the H5 file.
 
std::vector< std::stringh5::get_group_names (hid_t file_id, const std::string &group_name)
 Get the names of all the groups and datasets in a group.
 
bool h5::contains_dataset_or_group (hid_t id, const std::string &group_name, const std::string &dataset_name)
 Check if name is a dataset or group in the subgroup group_name of id. More...
 
bool h5::contains_attribute (hid_t file_id, const std::string &group_name, const std::string &attribute_name)
 Check if an attribute is in a group.
 
hid_t h5::open_dataset (hid_t group_id, const std::string &dataset_name)
 Open an HDF5 dataset.
 
void h5::close_dataset (hid_t dataset_id)
 Close an HDF5 dataset.
 
hid_t h5::open_dataspace (hid_t dataset_id)
 Open an HDF5 dataspace.
 
void h5::close_dataspace (hid_t dataspace_id)
 Close an HDF5 dataspace.
 
template<size_t Rank, typename T >
h5::read_data (hid_t group_id, const std::string &dataset_name)
 Read an array of rank 0-3 into an object. More...
 
template<size_t Dim>
Index< Dim > h5::read_extents (hid_t group_id, const std::string &extents_name="Extents")
 Read the HDF5 attribute representing extents from a group.
 
template<typename T >
h5::StellarCollapseEos::get_scalar_dataset (const std::string &dataset_name) const
 reads a rank-0 dataset (contains only one element)
 
std::vector< double > h5::StellarCollapseEos::get_rank1_dataset (const std::string &dataset_name) const
 reads a dataset with elements along 1 dimension
 
boost::multi_array< double, 3 > h5::StellarCollapseEos::get_rank3_dataset (const std::string &dataset_name) const
 reads a dataset with elements along 3 dimensions
 
template<typename T >
hid_t h5::h5_type ()
 Returns the HDF5 datatype for the corresponding type T More...
 
hid_t h5::fortran_string ()
 Create an H5 FORTRAN string.
 
auto h5::h5f_acc_rdonly ()
 
auto h5::h5f_acc_rdwr ()
 
auto h5::h5p_default ()
 
auto h5::h5s_all ()
 
auto h5::h5s_unlimited ()
 
auto h5::h5s_scalar ()
 

Detailed Description

Functions and classes for manipulating HDF5 files.

Macro Definition Documentation

◆ CHECK_H5

#define CHECK_H5 (   h5_status,
 
)
Value:
if (h5_status < 0) { /*NOLINT*/ \
ERROR("Failed HDF5 operation: " << m); /*NOLINT*/ \
} else \
static_cast<void>(0)

Check if an HDF5 operation was successful.

Requires: h5_status is a valid HDF5 return type, m is a stringstream syntax error message.

Effects: if h5_status is set to error then aborts execution else none

Enumeration Type Documentation

◆ AccessType

enum class h5::AccessType
strong

Set the access type to the H5File.

Enumerator
ReadWrite 

Allow read-write access to the file.

ReadOnly 

Allow only read access to the file.

Function Documentation

◆ contains_dataset_or_group()

bool h5::contains_dataset_or_group ( hid_t  id,
const std::string group_name,
const std::string dataset_name 
)

Check if name is a dataset or group in the subgroup group_name of id.

Note
To check the current id for name, pass "" as group_name.

◆ h5_type()

template<typename T >
hid_t h5::h5_type ( )

Returns the HDF5 datatype for the corresponding type T

Requires: T is a valid type with a corresponding HDF5 datatype, i.e. a fundamental or a std::string

Returns: the HDF5 datatype for the corresponding type T

Note
For strings, the returned type must be released with H5Tclose

◆ read_data()

template<size_t Rank, typename T >
T h5::read_data ( hid_t  group_id,
const std::string dataset_name 
)

Read an array of rank 0-3 into an object.

For each rank, the data can be read into objects of the following types: rank 0: double or int rank 1: std::vector or DataVector rank 2: boost::multiarray or DataVector rank 3: boost::multiarray or DataVector