Merged upstream/master
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,3 +1,4 @@
|
||||
*~
|
||||
gmon.out
|
||||
log.log
|
||||
build
|
||||
|
||||
4
opm/parser/eclipse/Applications/CMakeLists.txt
Normal file
4
opm/parser/eclipse/Applications/CMakeLists.txt
Normal file
@@ -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)
|
||||
|
||||
56
opm/parser/eclipse/Applications/EclipseDataDoctor.cpp
Normal file
56
opm/parser/eclipse/Applications/EclipseDataDoctor.cpp
Normal file
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* File: EclipseDataDoctor.cpp
|
||||
* Author: kflik
|
||||
*
|
||||
* Created on August 20, 2013, 1:19 PM
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
#include <opm/parser/eclipse/Parser/Parser.hpp>
|
||||
#include <opm/parser/eclipse/Deck/Deck.hpp>
|
||||
|
||||
|
||||
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] << " <Filename>" << "[-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;
|
||||
}
|
||||
|
||||
@@ -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 )
|
||||
|
||||
@@ -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 );
|
||||
}
|
||||
|
||||
@@ -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<DeckKeywordConstPtr>& getKeywordList(const std::string& keyword);
|
||||
size_t size() const;
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -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<DeckRecordConstPtr> m_recordList;
|
||||
bool m_knownKeyword;
|
||||
|
||||
};
|
||||
typedef boost::shared_ptr<DeckKeyword> DeckKeywordPtr;
|
||||
|
||||
@@ -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)) {
|
||||
|
||||
@@ -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<DeckKeywordConstPtr>& getKeywordList(const std::string& keyword) const;
|
||||
size_t numKeywords(const std::string& keyword) const;
|
||||
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -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"));
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
*/
|
||||
|
||||
@@ -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() );
|
||||
|
||||
@@ -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() );
|
||||
|
||||
@@ -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<std::string,std::string> sizeKeyword = parserKeyword->getSizeDefinitionPair();
|
||||
const std::pair<std::string, std::string> 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);
|
||||
|
||||
@@ -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<std::string, ParserKeywordConstPtr> 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);
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -242,6 +242,7 @@ BOOST_AUTO_TEST_CASE(loadConfigFromDirectory_default) {
|
||||
|
||||
|
||||
|
||||
|
||||
/***************** Simple Int parsing ********************************/
|
||||
|
||||
ParserKeywordPtr setupParserKeywordInt(std::string name, int numberOfItems) {
|
||||
|
||||
@@ -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];
|
||||
|
||||
16
testdata/integration_tests/someobscureelements.data
vendored
Normal file
16
testdata/integration_tests/someobscureelements.data
vendored
Normal file
@@ -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 /
|
||||
|
||||
Reference in New Issue
Block a user