diff --git a/.gitignore b/.gitignore index d87e48003..de6768f01 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ *~ gmon.out log.log +build diff --git a/opm/parser/eclipse/Applications/CMakeLists.txt b/opm/parser/eclipse/Applications/CMakeLists.txt new file mode 100644 index 000000000..a9cf34df0 --- /dev/null +++ b/opm/parser/eclipse/Applications/CMakeLists.txt @@ -0,0 +1,4 @@ +add_definitions( -DJSON_CONFIG_FILE="${PROJECT_SOURCE_DIR}/opm/parser/share/parser_config.json") +add_executable(eclipsedatadoctor EclipseDataDoctor.cpp) +target_link_libraries(eclipsedatadoctor Parser) + diff --git a/opm/parser/eclipse/Applications/EclipseDataDoctor.cpp b/opm/parser/eclipse/Applications/EclipseDataDoctor.cpp new file mode 100644 index 000000000..0a009e485 --- /dev/null +++ b/opm/parser/eclipse/Applications/EclipseDataDoctor.cpp @@ -0,0 +1,56 @@ +/* + * File: EclipseDataDoctor.cpp + * Author: kflik + * + * Created on August 20, 2013, 1:19 PM + */ + +#include +#include +#include + + +void printDeckDiagnostics(Opm::DeckConstPtr deck, bool printAllKeywords) { + int recognizedKeywords = 0; + int unrecognizedKeywords = 0; + for (size_t i = 0; i < deck->size(); i++) { + if (!deck->getKeyword(i)->isKnown()) { + unrecognizedKeywords++; + std::cout << "Warning, this looks like a keyword, but is not in the configuration: " << deck->getKeyword(i)->name() << std::endl; + } else + recognizedKeywords++; + + if (printAllKeywords) { + std::cout << "Keyword (" << i << "): " << deck->getKeyword(i)->name() << " " << std::endl; + } + } + std::cout << "Number of recognized keywords: " << recognizedKeywords << std::endl; + std::cout << "Number of unrecognized keywords: " << unrecognizedKeywords << std::endl; + std::cout << "Total number of keywords: " << deck->size() << std::endl; + +} +/* + * + */ +int main(int argc, char** argv) { + if (argc < 2) { + std::cout << "Usage: " << argv[0] << " " << "[-l] (list keywords)" << std::endl; + exit(1); + } + + bool printKeywords = false; + if (argc == 3) { + std::string arg(argv[2]); + if (arg == "-l") + printKeywords = true; + } + + Opm::ParserPtr parser(new Opm::Parser(JSON_CONFIG_FILE)); + std::string file = argv[1]; + Opm::DeckConstPtr deck = parser->parse(file, false); + + printDeckDiagnostics(deck, printKeywords); + + return 0; +} + diff --git a/opm/parser/eclipse/CMakeLists.txt b/opm/parser/eclipse/CMakeLists.txt index 8dc0fabb5..7b5d30e15 100644 --- a/opm/parser/eclipse/CMakeLists.txt +++ b/opm/parser/eclipse/CMakeLists.txt @@ -4,6 +4,8 @@ add_subdirectory(RawDeck/tests) add_subdirectory(Deck/tests) add_subdirectory(IntegrationTests) +add_subdirectory( Applications ) + set( rawdeck_source RawDeck/RawKeyword.cpp RawDeck/RawRecord.cpp ) diff --git a/opm/parser/eclipse/Deck/Deck.cpp b/opm/parser/eclipse/Deck/Deck.cpp index 0e73da8f4..971d46072 100644 --- a/opm/parser/eclipse/Deck/Deck.cpp +++ b/opm/parser/eclipse/Deck/Deck.cpp @@ -43,6 +43,10 @@ namespace Opm { return m_keywords->getKeyword(keyword); } + DeckKeywordConstPtr Deck::getKeyword(size_t index) const { + return m_keywords->getKeyword(index); + } + size_t Deck::numKeywords(const std::string& keyword) { return m_keywords->numKeywords( keyword ); } diff --git a/opm/parser/eclipse/Deck/Deck.hpp b/opm/parser/eclipse/Deck/Deck.hpp index 5e8b334c9..ffd1156ef 100644 --- a/opm/parser/eclipse/Deck/Deck.hpp +++ b/opm/parser/eclipse/Deck/Deck.hpp @@ -35,6 +35,8 @@ namespace Opm { void addKeyword( DeckKeywordConstPtr keyword); DeckKeywordConstPtr getKeyword(const std::string& keyword , size_t index) const; DeckKeywordConstPtr getKeyword(const std::string& keyword) const; + DeckKeywordConstPtr getKeyword(size_t index) const; + size_t numKeywords(const std::string& keyword); const std::vector& getKeywordList(const std::string& keyword); size_t size() const; diff --git a/opm/parser/eclipse/Deck/DeckKeyword.cpp b/opm/parser/eclipse/Deck/DeckKeyword.cpp index 77e55cc2c..f492f0de4 100644 --- a/opm/parser/eclipse/Deck/DeckKeyword.cpp +++ b/opm/parser/eclipse/Deck/DeckKeyword.cpp @@ -22,6 +22,12 @@ namespace Opm { DeckKeyword::DeckKeyword(const std::string& keywordName) { + m_knownKeyword = true; + m_keywordName = keywordName; + } + + DeckKeyword::DeckKeyword(const std::string& keywordName, bool knownKeyword) { + m_knownKeyword = knownKeyword; m_keywordName = keywordName; } @@ -33,6 +39,10 @@ namespace Opm { return m_recordList.size(); } + bool DeckKeyword::isKnown() const { + return m_knownKeyword; + } + void DeckKeyword::addRecord(DeckRecordConstPtr record) { m_recordList.push_back(record); } @@ -43,6 +53,5 @@ namespace Opm { } else throw std::range_error("Index out of range"); } - } diff --git a/opm/parser/eclipse/Deck/DeckKeyword.hpp b/opm/parser/eclipse/Deck/DeckKeyword.hpp index 0b932fa20..4fe7652e3 100644 --- a/opm/parser/eclipse/Deck/DeckKeyword.hpp +++ b/opm/parser/eclipse/Deck/DeckKeyword.hpp @@ -19,14 +19,18 @@ namespace Opm { class DeckKeyword { public: DeckKeyword(const std::string& keywordName); + DeckKeyword(const std::string& keywordName, bool knownKeyword); + std::string name() const; size_t size() const; void addRecord(DeckRecordConstPtr record); DeckRecordConstPtr getRecord(size_t index) const; + bool isKnown() const; private: std::string m_keywordName; std::vector m_recordList; + bool m_knownKeyword; }; typedef boost::shared_ptr DeckKeywordPtr; diff --git a/opm/parser/eclipse/Deck/KeywordContainer.cpp b/opm/parser/eclipse/Deck/KeywordContainer.cpp index 008089fdc..faee32dd5 100644 --- a/opm/parser/eclipse/Deck/KeywordContainer.cpp +++ b/opm/parser/eclipse/Deck/KeywordContainer.cpp @@ -63,7 +63,7 @@ namespace Opm { if (index < keywordList.size()) return keywordList[index]; else - throw std::invalid_argument("Keyword index is out of range."); + throw std::out_of_range("Keyword index is out of range."); } @@ -72,6 +72,12 @@ namespace Opm { return keywordList.back(); } + DeckKeywordConstPtr KeywordContainer::getKeyword(size_t index) const { + if (index < m_keywordList.size()) + return m_keywordList[index]; + else + throw std::out_of_range("Keyword index is out of range."); + } size_t KeywordContainer::numKeywords(const std::string& keyword) const{ if (hasKeyword(keyword)) { diff --git a/opm/parser/eclipse/Deck/KeywordContainer.hpp b/opm/parser/eclipse/Deck/KeywordContainer.hpp index f856cad44..75ccf892a 100644 --- a/opm/parser/eclipse/Deck/KeywordContainer.hpp +++ b/opm/parser/eclipse/Deck/KeywordContainer.hpp @@ -25,6 +25,8 @@ namespace Opm { void addKeyword(DeckKeywordConstPtr keyword); DeckKeywordConstPtr getKeyword(const std::string& keyword, size_t index) const; DeckKeywordConstPtr getKeyword(const std::string& keyword) const; + DeckKeywordConstPtr getKeyword(size_t index) const; + const std::vector& getKeywordList(const std::string& keyword) const; size_t numKeywords(const std::string& keyword) const; diff --git a/opm/parser/eclipse/Deck/tests/DeckKeywordTests.cpp b/opm/parser/eclipse/Deck/tests/DeckKeywordTests.cpp index 216b042a9..c5cde38b2 100644 --- a/opm/parser/eclipse/Deck/tests/DeckKeywordTests.cpp +++ b/opm/parser/eclipse/Deck/tests/DeckKeywordTests.cpp @@ -63,6 +63,10 @@ BOOST_AUTO_TEST_CASE(getRecord_outofrange_exceptionthrown) { BOOST_CHECK_THROW(deckKeyword->getRecord(1), std::range_error); } +BOOST_AUTO_TEST_CASE(setUnknown_wasknown_nowunknown) { + DeckKeywordPtr deckKeyword(new DeckKeyword("KW", false)); + BOOST_CHECK(!deckKeyword->isKnown()); +} diff --git a/opm/parser/eclipse/Deck/tests/DeckTests.cpp b/opm/parser/eclipse/Deck/tests/DeckTests.cpp index 9ab94415d..db70bf1de 100644 --- a/opm/parser/eclipse/Deck/tests/DeckTests.cpp +++ b/opm/parser/eclipse/Deck/tests/DeckTests.cpp @@ -65,7 +65,7 @@ BOOST_AUTO_TEST_CASE(getKeyword_singlekeyword_outRange_throws) { Deck deck; DeckKeywordConstPtr keyword(new DeckKeyword("BJARNE")); deck.addKeyword(keyword); - BOOST_CHECK_THROW(deck.getKeyword("BJARNE" , 10) , std::invalid_argument); + BOOST_CHECK_THROW(deck.getKeyword("BJARNE" , 10) , std::out_of_range); } @@ -77,6 +77,13 @@ BOOST_AUTO_TEST_CASE(getKeywordList_returnOK) { } +BOOST_AUTO_TEST_CASE(getKeyword_indexok_returnskeyword) { + Deck deck; + DeckKeywordConstPtr keyword(new DeckKeyword("BJARNE")); + deck.addKeyword(keyword); + BOOST_CHECK_NO_THROW(deck.getKeyword(0)); +} + BOOST_AUTO_TEST_CASE(numKeyword_singlekeyword_return1) { Deck deck; DeckKeywordConstPtr keyword(new DeckKeyword("BJARNE")); diff --git a/opm/parser/eclipse/Deck/tests/KeywordContainerTests.cpp b/opm/parser/eclipse/Deck/tests/KeywordContainerTests.cpp index ff9114be5..68efb384d 100644 --- a/opm/parser/eclipse/Deck/tests/KeywordContainerTests.cpp +++ b/opm/parser/eclipse/Deck/tests/KeywordContainerTests.cpp @@ -83,7 +83,7 @@ BOOST_AUTO_TEST_CASE(getKeyword_outOfRange_throws) { KeywordContainerPtr container(new KeywordContainer()); DeckKeywordPtr keyword = DeckKeywordPtr(new DeckKeyword("TRULS")); container->addKeyword(keyword); - BOOST_CHECK_THROW( container->getKeyword("TRULS" , 3) , std::invalid_argument) + BOOST_CHECK_THROW( container->getKeyword("TRULS" , 3) , std::out_of_range) } @@ -126,7 +126,31 @@ BOOST_AUTO_TEST_CASE(keywordList_getnum_OK) { } - +BOOST_AUTO_TEST_CASE(keywordList_getbyindexoutofbounds_exceptionthrown) { + KeywordContainerPtr container(new KeywordContainer()); + BOOST_CHECK_THROW(container->getKeyword(0), std::out_of_range); + DeckKeywordPtr keyword1 = DeckKeywordPtr(new DeckKeyword("TRULS")); + DeckKeywordPtr keyword2 = DeckKeywordPtr(new DeckKeyword("TRULS")); + DeckKeywordPtr keyword3 = DeckKeywordPtr(new DeckKeyword("TRULSX")); + container->addKeyword(keyword1); + container->addKeyword(keyword2); + container->addKeyword(keyword3); + BOOST_CHECK_NO_THROW(container->getKeyword(2)); + BOOST_CHECK_THROW(container->getKeyword(3), std::out_of_range); +} + +BOOST_AUTO_TEST_CASE(keywordList_getbyindex_correctkeywordreturned) { + KeywordContainerPtr container(new KeywordContainer()); + DeckKeywordPtr keyword1 = DeckKeywordPtr(new DeckKeyword("TRULS")); + DeckKeywordPtr keyword2 = DeckKeywordPtr(new DeckKeyword("TRULS")); + DeckKeywordPtr keyword3 = DeckKeywordPtr(new DeckKeyword("TRULSX")); + container->addKeyword(keyword1); + container->addKeyword(keyword2); + container->addKeyword(keyword3); + BOOST_CHECK_EQUAL("TRULS", container->getKeyword(0)->name()); + BOOST_CHECK_EQUAL("TRULS", container->getKeyword(1)->name()); + BOOST_CHECK_EQUAL("TRULSX", container->getKeyword(2)->name()); +} diff --git a/opm/parser/eclipse/IntegrationTests/IntegrationTests.cpp b/opm/parser/eclipse/IntegrationTests/IntegrationTests.cpp index f33dbb63e..942689ae5 100644 --- a/opm/parser/eclipse/IntegrationTests/IntegrationTests.cpp +++ b/opm/parser/eclipse/IntegrationTests/IntegrationTests.cpp @@ -147,7 +147,6 @@ BOOST_AUTO_TEST_CASE(parse_fileWithBPRKeyword_dataiscorrect) { BOOST_CHECK_EQUAL(3, K1->getInt(0)); K1 = record2->getItem("K"); BOOST_CHECK_EQUAL(3, K1->getInt(0)); - } @@ -157,52 +156,22 @@ BOOST_AUTO_TEST_CASE(Parse_InvalidInputFile_Throws) { } BOOST_AUTO_TEST_CASE(Parse_ValidInputFile_NoThrow) { - boost::filesystem::path singleKeywordFile("testdata/small.data"); + boost::filesystem::path singleKeywordFile("testdata/integration_tests/small.data"); ParserPtr parser(new Parser(JSON_CONFIG_FILE)); BOOST_CHECK_NO_THROW(parser->parse(singleKeywordFile.string())); } - - -/* -BOOST_AUTO_TEST_CASE(ParseFileWithFewKeywords) { - boost::filesystem::path singleKeywordFile("testdata/small.data"); - +/***************** Testing non-recognized keywords ********************/ +BOOST_AUTO_TEST_CASE(parse_unknownkeywordWithnonstrictparsing_keywordmarked) { ParserPtr parser(new Parser(JSON_CONFIG_FILE)); - - DeckPtr Deck = parser->parse(singleKeywordFile.string()); - - BOOST_CHECK_EQUAL(7U, Deck->size()); - - RawKeywordConstPtr matchingKeyword = rawDeck->getKeyword(0); - BOOST_CHECK_EQUAL("OIL", matchingKeyword->getKeywordName()); - BOOST_CHECK_EQUAL(0U, matchingKeyword->size()); - - // The two next come in via the include of the include path/readthis.sch file - matchingKeyword = rawDeck->getKeyword(1); - BOOST_CHECK_EQUAL("GRUPTREE", matchingKeyword->getKeywordName()); - BOOST_CHECK_EQUAL(2U, matchingKeyword->size()); - - matchingKeyword = rawDeck->getKeyword(2); - BOOST_CHECK_EQUAL("WHISTCTL", matchingKeyword->getKeywordName()); - BOOST_CHECK_EQUAL(1U, matchingKeyword->size()); - - matchingKeyword = rawDeck->getKeyword(3); - BOOST_CHECK_EQUAL("METRIC", matchingKeyword->getKeywordName()); - BOOST_CHECK_EQUAL(0U, matchingKeyword->size()); - - matchingKeyword = rawDeck->getKeyword(4); - BOOST_CHECK_EQUAL("GRIDUNIT", matchingKeyword->getKeywordName()); - BOOST_CHECK_EQUAL(1U, matchingKeyword->size()); - - matchingKeyword = rawDeck->getKeyword(5); - BOOST_CHECK_EQUAL("RADFIN4", matchingKeyword->getKeywordName()); - BOOST_CHECK_EQUAL(1U, matchingKeyword->size()); - - matchingKeyword = rawDeck->getKeyword(6); - BOOST_CHECK_EQUAL("ABCDAD", matchingKeyword->getKeywordName()); - - BOOST_CHECK_EQUAL(2U, matchingKeyword->size()); + DeckPtr deck = parser->parse("testdata/integration_tests/someobscureelements.data", false); + BOOST_CHECK_EQUAL(4U, deck->size()); + DeckKeywordConstPtr unknown = deck->getKeyword("GRUDINT"); + BOOST_CHECK(!unknown->isKnown()); +} + +BOOST_AUTO_TEST_CASE(parse_unknownkeywordWithstrictparsing_exceptionthrown) { + ParserPtr parser(new Parser(JSON_CONFIG_FILE)); + BOOST_CHECK_THROW(parser->parse("testdata/integration_tests/someobscureelements.data", true), std::invalid_argument); } -*/ diff --git a/opm/parser/eclipse/IntegrationTests/ParseEQUIL.cpp b/opm/parser/eclipse/IntegrationTests/ParseEQUIL.cpp index 44b220af8..56d383e2e 100644 --- a/opm/parser/eclipse/IntegrationTests/ParseEQUIL.cpp +++ b/opm/parser/eclipse/IntegrationTests/ParseEQUIL.cpp @@ -37,7 +37,7 @@ using namespace Opm; BOOST_AUTO_TEST_CASE( parse_EQUIL_OK ) { ParserPtr parser(new Parser(JSON_CONFIG_FILE)); - boost::filesystem::path wconhistFile("testdata/EQUIL/EQUIL1"); + boost::filesystem::path wconhistFile("testdata/integration_tests/EQUIL/EQUIL1"); DeckPtr deck = parser->parse(wconhistFile.string()); DeckKeywordConstPtr kw1 = deck->getKeyword("EQUIL" , 0); BOOST_CHECK_EQUAL( 3U , kw1->size() ); diff --git a/opm/parser/eclipse/IntegrationTests/ParseWCONHIST.cpp b/opm/parser/eclipse/IntegrationTests/ParseWCONHIST.cpp index bcd50815b..4eabeb437 100644 --- a/opm/parser/eclipse/IntegrationTests/ParseWCONHIST.cpp +++ b/opm/parser/eclipse/IntegrationTests/ParseWCONHIST.cpp @@ -38,7 +38,7 @@ using namespace Opm; BOOST_AUTO_TEST_CASE( parse_WCHONHIST_OK ) { ParserPtr parser(new Parser()); parser->loadKeywordsFromDirectory(KEYWORD_DIRECTORY); - boost::filesystem::path wconhistFile("testdata/WCONHIST/WCONHIST1"); + boost::filesystem::path wconhistFile("testdata/integration_tests/WCONHIST/WCONHIST1"); DeckPtr deck = parser->parse(wconhistFile.string()); DeckKeywordConstPtr kw1 = deck->getKeyword("WCONHIST" , 0); BOOST_CHECK_EQUAL( 3U , kw1->size() ); diff --git a/opm/parser/eclipse/Parser/Parser.cpp b/opm/parser/eclipse/Parser/Parser.cpp index 39c07be9b..25acdd94f 100644 --- a/opm/parser/eclipse/Parser/Parser.cpp +++ b/opm/parser/eclipse/Parser/Parser.cpp @@ -33,103 +33,104 @@ namespace Opm { } Parser::Parser(const boost::filesystem::path& jsonFile) { - initializeFromJsonFile( jsonFile ); + initializeFromJsonFile(jsonFile); } - DeckPtr Parser::parse(const std::string &dataFile) { - DeckPtr deck(new Deck()); + return parse(dataFile, true); + } - parseFile( deck , dataFile ); + DeckPtr Parser::parse(const std::string &dataFile, bool strictParsing) { + DeckPtr deck(new Deck()); + parseFile(deck, dataFile, strictParsing); return deck; } +<<<<<<< HEAD size_t Parser::size() const { return m_parserKeywords.size(); } void Parser::parseFile(DeckPtr deck , const std::string &file) { +======= + void Parser::parseFile(DeckPtr deck, const std::string &file, bool parseStrict) { +>>>>>>> upstream/master std::ifstream inputstream; - inputstream.open( file.c_str() ); - + inputstream.open(file.c_str()); + if (inputstream) { - RawKeywordPtr rawKeyword; - - while (tryParseKeyword(deck , inputstream , rawKeyword)) { - if (rawKeyword->getKeywordName() == Opm::RawConsts::include) { - boost::filesystem::path dataFolderPath = verifyValidInputPath(file); - RawRecordConstPtr firstRecord = rawKeyword->getRecord(0); - std::string includeFileString = firstRecord->getItem(0); - boost::filesystem::path pathToIncludedFile(dataFolderPath); - pathToIncludedFile /= includeFileString; - - parseFile( deck , pathToIncludedFile.string() ); - } else { - ParserKeywordConstPtr parserKeyword = m_parserKeywords[rawKeyword->getKeywordName()]; - DeckKeywordConstPtr deckKeyword = parserKeyword->parse(rawKeyword); - deck->addKeyword( deckKeyword ); + RawKeywordPtr rawKeyword; + + while (tryParseKeyword(deck, inputstream, rawKeyword, parseStrict)) { + if (rawKeyword->getKeywordName() == Opm::RawConsts::include) { + boost::filesystem::path dataFolderPath = verifyValidInputPath(file); + RawRecordConstPtr firstRecord = rawKeyword->getRecord(0); + std::string includeFileString = firstRecord->getItem(0); + boost::filesystem::path pathToIncludedFile(dataFolderPath); + pathToIncludedFile /= includeFileString; + + parseFile(deck, pathToIncludedFile.string(), parseStrict); + } else { + if (hasKeyword(rawKeyword->getKeywordName())) { + ParserKeywordConstPtr parserKeyword = m_parserKeywords[rawKeyword->getKeywordName()]; + DeckKeywordConstPtr deckKeyword = parserKeyword->parse(rawKeyword); + deck->addKeyword(deckKeyword); + } else { + DeckKeywordPtr deckKeyword(new DeckKeyword(rawKeyword->getKeywordName(), false)); + deck->addKeyword(deckKeyword); + } + } + rawKeyword.reset(); } - rawKeyword.reset(); - } - - inputstream.close(); + + inputstream.close(); } else - throw std::invalid_argument("Failed to open file: " + file); + throw std::invalid_argument("Failed to open file: " + file); } - - void Parser::addKeyword(ParserKeywordConstPtr parserKeyword) { m_parserKeywords.insert(std::make_pair(parserKeyword->getName(), parserKeyword)); } - - void Parser::initializeFromJsonFile( const boost::filesystem::path& jsonFile ) { + void Parser::initializeFromJsonFile(const boost::filesystem::path& jsonFile) { Json::JsonObject jsonConfig(jsonFile); if (jsonConfig.has_item("keywords")) { Json::JsonObject jsonKeywords = jsonConfig.get_item("keywords"); - loadKeywords( jsonKeywords ); + loadKeywords(jsonKeywords); } else throw std::invalid_argument("Missing \"keywords\" section in config file: " + jsonFile.string()); } - void Parser::loadKeywords(const Json::JsonObject& jsonKeywords) { if (jsonKeywords.is_array()) { for (size_t index = 0; index < jsonKeywords.size(); index++) { - Json::JsonObject jsonKeyword = jsonKeywords.get_array_item( index ); - ParserKeywordConstPtr parserKeyword( new ParserKeyword( jsonKeyword )); - - addKeyword( parserKeyword ); + Json::JsonObject jsonKeyword = jsonKeywords.get_array_item(index); + ParserKeywordConstPtr parserKeyword(new ParserKeyword(jsonKeyword)); + + addKeyword(parserKeyword); } } else throw std::invalid_argument("Input JSON object is not an array"); } - - - bool Parser::hasKeyword(const std::string& keyword) const { return m_parserKeywords.find(keyword) != m_parserKeywords.end(); } - - - - RawKeywordPtr Parser::newRawKeyword(const DeckConstPtr deck , const std::string& keywordString) { + RawKeywordPtr Parser::createRawKeyword(const DeckConstPtr deck, const std::string& keywordString, bool strictParsing) { if (hasKeyword(keywordString)) { ParserKeywordConstPtr parserKeyword = m_parserKeywords.find(keywordString)->second; - if (parserKeyword->getSizeType() == UNDEFINED) + if (parserKeyword->getSizeType() == UNDEFINED) return RawKeywordPtr(new RawKeyword(keywordString)); else { size_t targetSize; - + if (parserKeyword->hasFixedSize()) targetSize = parserKeyword->getFixedSize(); else { - const std::pair sizeKeyword = parserKeyword->getSizeDefinitionPair(); + const std::pair sizeKeyword = parserKeyword->getSizeDefinitionPair(); DeckKeywordConstPtr sizeDefinitionKeyword = deck->getKeyword(sizeKeyword.first); DeckItemConstPtr sizeDefinitionItem; { @@ -138,38 +139,40 @@ namespace Opm { } targetSize = sizeDefinitionItem->getInt(0); } - return RawKeywordPtr(new RawKeyword(keywordString , targetSize)); + return RawKeywordPtr(new RawKeyword(keywordString, targetSize)); } - } else - throw std::invalid_argument("Keyword " + keywordString + " not recognized "); + } else { + if (strictParsing) { + throw std::invalid_argument("Keyword " + keywordString + " not recognized "); + } else { + return RawKeywordPtr(new RawKeyword(keywordString, 0)); + } + } } - - - - bool Parser::tryParseKeyword(const DeckConstPtr deck , std::ifstream& inputstream , RawKeywordPtr& rawKeyword) { + bool Parser::tryParseKeyword(const DeckConstPtr deck, std::ifstream& inputstream, RawKeywordPtr& rawKeyword, bool strictParsing) { std::string line; while (std::getline(inputstream, line)) { std::string keywordString; if (rawKeyword == NULL) { - if (RawKeyword::tryParseKeyword(line, keywordString)) - rawKeyword = newRawKeyword( deck , keywordString ); + if (RawKeyword::tryParseKeyword(line, keywordString)) { + rawKeyword = createRawKeyword(deck, keywordString, strictParsing); + } } else { - if (RawKeyword::useLine(line)) + if (RawKeyword::useLine(line)) { rawKeyword->addRawRecordString(line); - } - + } + } + if (rawKeyword != NULL && rawKeyword->isFinished()) return true; } - + return false; } - - boost::filesystem::path Parser::verifyValidInputPath(const std::string& inputPath) const { Logger::info("Verifying path: " + inputPath); boost::filesystem::path pathToInputFile(inputPath); diff --git a/opm/parser/eclipse/Parser/Parser.hpp b/opm/parser/eclipse/Parser/Parser.hpp index 62ce14ce4..f204f3a2f 100644 --- a/opm/parser/eclipse/Parser/Parser.hpp +++ b/opm/parser/eclipse/Parser/Parser.hpp @@ -44,6 +44,7 @@ namespace Opm { /// The starting point of the parsing process. The supplied file is parsed, and the resulting Deck is returned. DeckPtr parse(const std::string &dataFile); + DeckPtr parse(const std::string &dataFile, bool strictParsing); /// Method to add ParserKeyword instances, these holding type and size information about the keywords and their data. void addKeyword(ParserKeywordConstPtr parserKeyword); @@ -57,11 +58,11 @@ namespace Opm { size_t size() const; private: std::map m_parserKeywords; - bool tryParseKeyword(const DeckConstPtr deck , std::ifstream& inputstream , RawKeywordPtr& rawKeyword); - void parseFile(DeckPtr deck , const std::string &file) ; + bool tryParseKeyword(const DeckConstPtr deck , std::ifstream& inputstream , RawKeywordPtr& rawKeyword, bool strictParsing); + void parseFile(DeckPtr deck , const std::string &file, bool strictParsing) ; boost::filesystem::path verifyValidInputPath(const std::string& inputPath) const; void populateDefaultKeywords(); - RawKeywordPtr newRawKeyword(const DeckConstPtr deck , const std::string& keywordString); + RawKeywordPtr createRawKeyword(const DeckConstPtr deck , const std::string& keywordString, bool strictParsing); }; diff --git a/opm/parser/eclipse/Parser/tests/ParserTests.cpp b/opm/parser/eclipse/Parser/tests/ParserTests.cpp index c7bd363d8..2fd968bec 100644 --- a/opm/parser/eclipse/Parser/tests/ParserTests.cpp +++ b/opm/parser/eclipse/Parser/tests/ParserTests.cpp @@ -242,6 +242,7 @@ BOOST_AUTO_TEST_CASE(loadConfigFromDirectory_default) { + /***************** Simple Int parsing ********************************/ ParserKeywordPtr setupParserKeywordInt(std::string name, int numberOfItems) { diff --git a/opm/parser/eclipse/RawDeck/RawRecord.cpp b/opm/parser/eclipse/RawDeck/RawRecord.cpp index ef49acfac..67087b94b 100644 --- a/opm/parser/eclipse/RawDeck/RawRecord.cpp +++ b/opm/parser/eclipse/RawDeck/RawRecord.cpp @@ -95,7 +95,7 @@ namespace Opm { void RawRecord::splitSingleRecordString() { char currentChar; - char tokenStartCharacter; + char tokenStartCharacter=' '; std::string currentToken = ""; for (unsigned i = 0; i < m_sanitizedRecordString.size(); i++) { currentChar = m_sanitizedRecordString[i]; diff --git a/testdata/EQUIL/EQUIL1 b/testdata/integration_tests/EQUIL/EQUIL1 similarity index 100% rename from testdata/EQUIL/EQUIL1 rename to testdata/integration_tests/EQUIL/EQUIL1 diff --git a/testdata/WCONHIST/WCONHIST1 b/testdata/integration_tests/WCONHIST/WCONHIST1 similarity index 100% rename from testdata/WCONHIST/WCONHIST1 rename to testdata/integration_tests/WCONHIST/WCONHIST1 diff --git a/testdata/include path/readthis.sch b/testdata/integration_tests/include path/readthis.sch similarity index 100% rename from testdata/include path/readthis.sch rename to testdata/integration_tests/include path/readthis.sch diff --git a/testdata/mini.data b/testdata/integration_tests/mini.data similarity index 100% rename from testdata/mini.data rename to testdata/integration_tests/mini.data diff --git a/testdata/small.data b/testdata/integration_tests/small.data similarity index 100% rename from testdata/small.data rename to testdata/integration_tests/small.data diff --git a/testdata/integration_tests/someobscureelements.data b/testdata/integration_tests/someobscureelements.data new file mode 100644 index 000000000..64c1279c0 --- /dev/null +++ b/testdata/integration_tests/someobscureelements.data @@ -0,0 +1,16 @@ +-- Comment +OIL + +GRIDUNIT +METRES / + +GRUDINT -- A wrong, or unknown keyword + "text" 3 5 / + 3 3 3 3 3 3 / +/ + + + +RADFIN4 +213 123 123 / +