From 32d041ec90deb4e2bffd9714cba7661d32a05328 Mon Sep 17 00:00:00 2001 From: Paul Romano Date: Wed, 20 Oct 2021 10:48:27 -0500 Subject: [PATCH] Fix bug for when local cross_sections.xml is specified --- src/cross_sections.cpp | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/cross_sections.cpp b/src/cross_sections.cpp index 9156bdc90..afb0a1f36 100644 --- a/src/cross_sections.cpp +++ b/src/cross_sections.cpp @@ -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")) {