File indexing completed on 2025-08-05 08:19:07
0001
0002
0003
0004
0005
0006 #include "hdf5_utils.h"
0007
0008 #include <stdexcept>
0009
0010 #include <boost/filesystem.hpp>
0011
0012 namespace trento {
0013
0014 namespace hdf5 {
0015
0016 bool filename_is_hdf5(const fs::path& path) {
0017 if (!path.has_extension())
0018 return false;
0019
0020 auto hdf5_exts = {".hdf5", ".hdf", ".hd5", ".h5"};
0021 auto result = std::find(hdf5_exts.begin(), hdf5_exts.end(), path.extension());
0022
0023 return result != hdf5_exts.end();
0024 }
0025
0026 bool filename_is_hdf5(const std::string& path) {
0027 return filename_is_hdf5(fs::path{path});
0028 }
0029
0030 #ifdef TRENTO_HDF5
0031
0032 H5::H5File try_open_file(const std::string& path, unsigned int flags) {
0033 if (!fs::exists(path))
0034 throw std::invalid_argument{"file '" + path + "' does not exist"};
0035
0036 if (!H5::H5File::isHdf5(path))
0037 throw std::invalid_argument{"'" + path + "' is not a valid HDF5 file"};
0038
0039 return H5::H5File{path, flags};
0040 }
0041
0042 #endif
0043
0044 }
0045
0046 }