Fix bug for when local cross_sections.xml is specified

This commit is contained in:
Paul Romano 2021-10-20 10:48:27 -05:00
parent ab4ef1d7be
commit 32d041ec90

View file

@ -76,8 +76,10 @@ Library::Library(pugi::xml_node node, const std::string& directory)
path_ = path;
} else if (ends_with(directory, "/")) {
path_ = directory + path;
} else {
} else if (!directory.empty()) {
path_ = directory + "/" + path;
} else {
path_ = path;
}
if (!file_exists(path_)) {
@ -135,6 +137,13 @@ void read_cross_sections_xml()
}
} else {
settings::path_cross_sections = get_node_value(root, "cross_sections");
// If no '/' found, the file is probably in the input directory
auto pos = settings::path_cross_sections.rfind("/");
if (pos == std::string::npos && !settings::path_input.empty()) {
settings::path_cross_sections =
settings::path_input + "/" + settings::path_cross_sections;
}
}
// Now that the cross_sections.xml or mgxs.h5 has been located, read it in
@ -295,10 +304,12 @@ void read_ce_cross_sections_xml()
// TODO: Use std::filesystem functionality when C++17 is adopted
auto pos = filename.rfind("/");
if (pos == std::string::npos) {
// no '/' found, probably a Windows directory
pos = filename.rfind("\\");
// No '\\' found, so the file must be in the same directory as
// materials.xml
directory = settings::path_input;
} else {
directory = filename.substr(0, pos);
}
directory = filename.substr(0, pos);
}
for (const auto& node_library : root.children("library")) {