diff --git a/src/opm/input/eclipse/EclipseState/Grid/EclipseGrid.cpp b/src/opm/input/eclipse/EclipseState/Grid/EclipseGrid.cpp index 57fd01256..f033f86c1 100644 --- a/src/opm/input/eclipse/EclipseState/Grid/EclipseGrid.cpp +++ b/src/opm/input/eclipse/EclipseState/Grid/EclipseGrid.cpp @@ -564,7 +564,7 @@ EclipseGrid::EclipseGrid(const Deck& deck, const int * actnum) void EclipseGrid::initBinaryGrid(const Deck& deck) { const DeckKeyword& gdfile_kw = deck["GDFILE"].back(); - const std::string& gdfile_arg = gdfile_kw.getRecord(0).getItem("filename").get(0); + const std::string& gdfile_arg = gdfile_kw.getRecord(0).getItem("filename").getTrimmedString(0); std::string filename = deck.makeDeckPath(gdfile_arg); std::unique_ptr egridfile; diff --git a/src/opm/input/eclipse/EclipseState/Grid/GridDims.cpp b/src/opm/input/eclipse/EclipseState/Grid/GridDims.cpp index cde1a4f52..8f0efc47e 100644 --- a/src/opm/input/eclipse/EclipseState/Grid/GridDims.cpp +++ b/src/opm/input/eclipse/EclipseState/Grid/GridDims.cpp @@ -159,7 +159,7 @@ namespace Opm { void GridDims::binary_init(const Deck& deck) { const DeckKeyword& gdfile_kw = deck["GDFILE"].back(); - const std::string& gdfile_arg = gdfile_kw.getRecord(0).getItem("filename").get(0); + const std::string& gdfile_arg = gdfile_kw.getRecord(0).getItem("filename").getTrimmedString(0); const EclIO::EGrid egrid( deck.makeDeckPath(gdfile_arg) ); const auto& dimens = egrid.dimension(); diff --git a/src/opm/input/eclipse/Parser/Parser.cpp b/src/opm/input/eclipse/Parser/Parser.cpp index 4e6b46ea1..6ac2076de 100644 --- a/src/opm/input/eclipse/Parser/Parser.cpp +++ b/src/opm/input/eclipse/Parser/Parser.cpp @@ -66,6 +66,7 @@ #include #include #include +#include #include #include @@ -680,7 +681,10 @@ std::optional ParserState::getIncludeFilePath( std::strin OpmLog::warning("Replaced one or more backslash with a slash in an INCLUDE path."); } - std::filesystem::path includeFilePath(path); + // trim leading and trailing whitespace just like the other simulator + std::regex trim_regex("^\\s+|\\s+$"); + const auto& trimmed_path = std::regex_replace(path, trim_regex, ""); + std::filesystem::path includeFilePath(trimmed_path); if (includeFilePath.is_relative()) includeFilePath = this->rootPath / includeFilePath; @@ -688,7 +692,11 @@ std::optional ParserState::getIncludeFilePath( std::strin try { includeFilePath = std::filesystem::canonical(includeFilePath); } catch (const std::filesystem::filesystem_error& fs_error) { - parseContext.handleError( ParseContext::PARSE_MISSING_INCLUDE , fmt::format("No such file: {}", includeFilePath.string()), {}, errors); + parseContext.handleError( ParseContext::PARSE_MISSING_INCLUDE , + fmt::format("File '{}' included via INCLUDE" + " directive does not exist.", + trimmed_path), + {}, errors); return {}; } @@ -1186,7 +1194,7 @@ bool parseState( ParserState& parserState, const Parser& parser ) { if (deck_keyword.name() == ParserKeywords::IMPORT::keywordName) { bool formatted = deck_keyword.getRecord(0).getItem(1).get(0)[0] == 'F'; - const auto& import_file = parserState.getIncludeFilePath(deck_keyword.getRecord(0).getItem(0).get(0)); + const auto& import_file = parserState.getIncludeFilePath(deck_keyword.getRecord(0).getItem(0).getTrimmedString(0)); ImportContainer import(parser, parserState.deck.getActiveUnitSystem(), import_file.value().string(), formatted, parserState.deck.size()); for (auto kw : import)