diff --git a/opm/parser/eclipse/Deck/Deck.hpp b/opm/parser/eclipse/Deck/Deck.hpp index 43818cd2d..b4adca354 100644 --- a/opm/parser/eclipse/Deck/Deck.hpp +++ b/opm/parser/eclipse/Deck/Deck.hpp @@ -141,7 +141,8 @@ namespace Opm { UnitSystem& getActiveUnitSystem(); UnitSystem& getDefaultUnitSystem(); - const std::string getDataFile() const; + const std::string& getInputPath() const; + const std::string& getDataFile() const; void setDataFile(const std::string& dataFile); iterator begin(); @@ -156,6 +157,7 @@ namespace Opm { UnitSystem activeUnits; std::string m_dataFile; + std::string input_path; }; } #endif /* DECK_HPP */ diff --git a/src/opm/parser/eclipse/Deck/Deck.cpp b/src/opm/parser/eclipse/Deck/Deck.cpp index 0577f761f..d8382f727 100644 --- a/src/opm/parser/eclipse/Deck/Deck.cpp +++ b/src/opm/parser/eclipse/Deck/Deck.cpp @@ -13,7 +13,6 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - You should have received a copy of the GNU General Public License along with OPM. If not, see . */ @@ -139,7 +138,8 @@ namespace Opm { keywordList( std::move( x ) ), defaultUnits( UnitSystem::newMETRIC() ), activeUnits( UnitSystem::newMETRIC() ), - m_dataFile("") + m_dataFile(""), + input_path("") { /* * If multiple unit systems are requested, metric is preferred over @@ -169,8 +169,8 @@ namespace Opm { keywordList( d.keywordList ), defaultUnits( d.defaultUnits ), activeUnits( d.activeUnits ), - m_dataFile( d.m_dataFile ) { - + m_dataFile( d.m_dataFile ), + input_path( d.input_path ) { this->reinit(this->keywordList.begin(), this->keywordList.end()); } @@ -209,12 +209,22 @@ namespace Opm { return this->activeUnits; } - const std::string Deck::getDataFile() const { + const std::string& Deck::getDataFile() const { return m_dataFile; } + const std::string& Deck::getInputPath() const { + return this->input_path; + } + void Deck::setDataFile(const std::string& dataFile) { - m_dataFile = dataFile; + this->m_dataFile = dataFile; + + auto slash_pos = dataFile.find_last_of("/\\"); + if (slash_pos == std::string::npos) + this->input_path = ""; + else + this->input_path = dataFile.substr(0, slash_pos); } Deck::iterator Deck::begin() { diff --git a/tests/parser/DeckTests.cpp b/tests/parser/DeckTests.cpp index 8d4fb6b37..ec257e439 100644 --- a/tests/parser/DeckTests.cpp +++ b/tests/parser/DeckTests.cpp @@ -166,9 +166,15 @@ BOOST_AUTO_TEST_CASE(keywordList_getbyindex_correctkeywordreturned) { BOOST_AUTO_TEST_CASE(set_and_get_data_file) { Deck deck; BOOST_CHECK_EQUAL("", deck.getDataFile()); + BOOST_CHECK_EQUAL("", deck.getInputPath()); std::string file("/path/to/file.DATA"); deck.setDataFile( file ); BOOST_CHECK_EQUAL(file, deck.getDataFile()); + BOOST_CHECK_EQUAL("/path/to", deck.getInputPath()); + + deck.setDataFile("FILE"); + BOOST_CHECK_EQUAL("FILE", deck.getDataFile()); + BOOST_CHECK_EQUAL("", deck.getInputPath()); } BOOST_AUTO_TEST_CASE(DummyDefaultsString) {