6 #include "flame/h5loader.h"
11 #define CATCH() catch(H5::Exception& he) { \
12 std::ostringstream strm; \
13 strm<<"H5 Error "<<he.getDetailMsg(); \
14 throw std::runtime_error(strm.str()); \
17 struct H5Loader::Pvt {
39 }
catch(std::runtime_error& e) {
40 std::cerr<<
"H5Loader is ignoring exception in dtor : "<<e.what()<<
"\n";
45 void H5Loader::open(
const char *spec)
47 open(std::string(spec));
50 void H5Loader::open(
const std::string& spec)
59 size_t sep = spec.npos;
62 sep = spec.find_last_of(
'/', sep-1);
64 std::string fname(spec.substr(0, sep));
67 pvt->file.openFile(fname, H5F_ACC_RDONLY);
68 }
catch(H5::FileIException& e) {
71 throw std::runtime_error(
"Unable to open file");
76 std::
string group(spec.substr(sep+1));
79 pvt->group = pvt->file.openGroup(group);
80 }
catch(H5::FileIException& e) {
81 throw std::runtime_error(
"Unable to open group");
97 H5Loader::load(
const char * setname)
101 dset = pvt->group.openDataSet(setname);
102 }
catch(H5::GroupIException& e) {
103 throw std::runtime_error(
"H5 group does not exist");
107 H5::DataSpace fspace(dset.getSpace());
109 size_t N = fspace.getSimpleExtentNdims();
111 throw std::runtime_error(
"Can't load > 2d as matrix");
113 hsize_t fsize[2] = {1,1};
114 fspace.getSimpleExtentDims(fsize);
116 H5::DataSpace mspace(2, fsize);
123 matrix_t::array_type& storage(ret.data());
124 dset.read(&storage[0], H5::PredType::NATIVE_DOUBLE, mspace, fspace);
131 H5Loader::load(
const std::string& set)
133 return load(set.c_str());
136 void H5Loader::dontPrint()
139 H5::Exception::dontPrint();
H5Loader()
Construct w/o opening. Must call open()
boost::numeric::ublas::matrix< double, boost::numeric::ublas::row_major, boost::numeric::ublas::unbounded_array< double > > matrix_t
A 2d matrix.
Helper to read 2d matricies.