//---------------------------------------------------------------------------- void read_data(const nexus::Path &path) { typedef dynamic_array<float64> array_type; hdf5::file::File file = nexus::open_file(path.filename()); nexus::DatasetList fields = nexus::get_objects(file.root(),path); auto data = array_type::create(hdf5::dataspace::Simple(fields[0].dataspace()).current_dimensions()); fields[0].read(data); }
//---------------------------------------------------------------------------- hdf5::file::File get_file(const nexus::Path &path) { if(path.filename().empty()) { std::cerr<<"Please provide a filename!"<<std::endl; std::exit(1); } hdf5::file::File file; try { file = hdf5::file::open(path.filename(),hdf5::file::AccessFlags::READONLY); } catch(...) { std::cerr<<"Error opening Nexus file!"<<std::endl; std::exit(1); } return file; }
//---------------------------------------------------------------------------- nexus::PathObject get_base(const hdf5::file::File &file, const nexus::Path &path) { nexus::PathObjectList objects; // check if the path references the root group if(path.size()==1 && !nexus::has_attribute_section(path)) { return file.root(); } try { nexus::Path file_root; file_root.filename(path.filename()); file_root.push_back({"/","NXroot"}); nexus::Path search_path = nexus::make_relative(file_root,path); search_path.attribute(path.attribute()); objects = nexus::get_objects(file.root(),search_path); } catch(pni::core::key_error &error) { std::cerr<<error<<std::endl; std::cerr<<"The path entered does not exist!"<<std::endl; std::exit(1); } catch(std::runtime_error &error) { std::cerr<<error.what()<<std::endl; std::exit(1); } if(objects.size()!=1) { std::stringstream ss; if(objects.size()>1) ss<<"The path ["<<path<<"] is not unique - cannot identify base object!"; else if(objects.size()==0) ss<<"Could not find base with ["<<path<<"]!"; throw std::runtime_error(ss.str()); } return objects.front(); }