diff --git a/opm/parser/eclipse/CMakeLists.txt b/opm/parser/eclipse/CMakeLists.txt
index 9dd812838..9e389cf1f 100644
--- a/opm/parser/eclipse/CMakeLists.txt
+++ b/opm/parser/eclipse/CMakeLists.txt
@@ -1,4 +1,4 @@
-add_library(Parser RawDeck/RawDeck.cpp RawDeck/RawKeyword.cpp RawDeck/RawRecord.cpp Parser/Parser.cpp Parser/ParserRecordSize.cpp Parser/ParserKW.cpp)
+add_library(Parser RawDeck/RawDeck.cpp RawDeck/RawKeyword.cpp RawDeck/RawRecord.cpp RawDeck/RawParserKWs.cpp Parser/Parser.cpp Parser/ParserRecordSize.cpp Parser/ParserKW.cpp)
add_library(Logger Logger.cpp)
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
diff --git a/opm/parser/eclipse/Parser/Parser.cpp b/opm/parser/eclipse/Parser/Parser.cpp
index 60a5bf843..aa9aef2af 100644
--- a/opm/parser/eclipse/Parser/Parser.cpp
+++ b/opm/parser/eclipse/Parser/Parser.cpp
@@ -17,53 +17,24 @@
along with OPM. If not, see .
*/
#include "Parser.hpp"
+#include "RawDeck/RawParserKWs.hpp"
namespace Opm {
Parser::Parser() {
- initializeFixedKeywordLenghts();
-
}
RawDeckPtr Parser::parse(const std::string &path) {
Logger::initLogger();
Logger::setLogLevel(Logger::DEBUG);
Logger::info("Starting parsing of file: " + path);
- RawDeckPtr rawDeck(new RawDeck(m_keywordRecordLengths));
+ RawDeckPtr rawDeck(new RawDeck(RawParserKWsConstPtr(new RawParserKWs())));
rawDeck->readDataIntoDeck(path);
Logger::info("Done parsing of file: " + path);
return rawDeck;
}
- void Parser::initializeFixedKeywordLenghts() {
- m_keywordRecordLengths.insert(std::pair("GRIDUNIT", 1));
- m_keywordRecordLengths.insert(std::pair("INCLUDE", 1));
- m_keywordRecordLengths.insert(std::pair("RADFIN4", 1));
- m_keywordRecordLengths.insert(std::pair("DIMENS", 1));
- m_keywordRecordLengths.insert(std::pair("START", 1));
- m_keywordRecordLengths.insert(std::pair("GRIDOPTS", 1));
- m_keywordRecordLengths.insert(std::pair("ENDSCALE", 1));
- m_keywordRecordLengths.insert(std::pair("EQLOPTS", 1));
- m_keywordRecordLengths.insert(std::pair("TABDIMS", 1));
- m_keywordRecordLengths.insert(std::pair("EQLDIMS", 1));
- m_keywordRecordLengths.insert(std::pair("REGDIMS", 1));
- m_keywordRecordLengths.insert(std::pair("FAULTDIM", 1));
- m_keywordRecordLengths.insert(std::pair("WELLDIMS", 1));
- m_keywordRecordLengths.insert(std::pair("VFPPDIMS", 1));
- m_keywordRecordLengths.insert(std::pair("RPTSCHED", 1));
- m_keywordRecordLengths.insert(std::pair("TITLE", 0));
- m_keywordRecordLengths.insert(std::pair("RUNSPEC", 0));
- m_keywordRecordLengths.insert(std::pair("METRIC", 0));
- m_keywordRecordLengths.insert(std::pair("SCHEDULE", 0));
- m_keywordRecordLengths.insert(std::pair("SKIPREST", 0));
- m_keywordRecordLengths.insert(std::pair("NOECHO", 0));
- m_keywordRecordLengths.insert(std::pair("END", 0));
- m_keywordRecordLengths.insert(std::pair("OIL", 0));
- m_keywordRecordLengths.insert(std::pair("GAS", 0));
- m_keywordRecordLengths.insert(std::pair("WATER", 0));
- m_keywordRecordLengths.insert(std::pair("DISGAS", 0));
- m_keywordRecordLengths.insert(std::pair("VAPOIL", 0));
- }
+
Parser::~Parser() {
}
diff --git a/opm/parser/eclipse/Parser/Parser.hpp b/opm/parser/eclipse/Parser/Parser.hpp
index b41c34f1d..67a5d85c7 100644
--- a/opm/parser/eclipse/Parser/Parser.hpp
+++ b/opm/parser/eclipse/Parser/Parser.hpp
@@ -36,8 +36,6 @@ namespace Opm {
RawDeckPtr parse(const std::string &path);
virtual ~Parser();
private:
- std::map m_keywordRecordLengths;
- void initializeFixedKeywordLenghts();
};
typedef boost::shared_ptr ParserPtr;
diff --git a/opm/parser/eclipse/RawDeck/RawDeck.cpp b/opm/parser/eclipse/RawDeck/RawDeck.cpp
index fcb2d55fd..ad607d2ba 100644
--- a/opm/parser/eclipse/RawDeck/RawDeck.cpp
+++ b/opm/parser/eclipse/RawDeck/RawDeck.cpp
@@ -23,8 +23,8 @@
namespace Opm {
- RawDeck::RawDeck(std::map& keywordsWithFixedRecordNums) {
- m_keywordsWithFixedRecordNums = keywordsWithFixedRecordNums;
+ RawDeck::RawDeck(RawParserKWsConstPtr rawParserKWs) {
+ m_rawParserKWs = rawParserKWs;
}
/*
@@ -94,8 +94,8 @@ namespace Opm {
}
bool RawDeck::isKeywordFinished(RawKeywordPtr rawKeyword) {
- if ((unsigned)m_keywordsWithFixedRecordNums.count(rawKeyword->getKeyword()) != 0) {
- return rawKeyword->getNumberOfRecords() == (unsigned)m_keywordsWithFixedRecordNums[rawKeyword->getKeyword()];
+ if (m_rawParserKWs->keywordExists(rawKeyword->getKeyword())) {
+ return rawKeyword->getNumberOfRecords() == m_rawParserKWs->getFixedNumberOfRecords(rawKeyword->getKeyword());
}
return false;
}
@@ -103,11 +103,10 @@ namespace Opm {
std::ostream& operator<<(std::ostream& os, const RawDeck& deck) {
for (std::list::const_iterator keyword = deck.m_keywords.begin(); keyword != deck.m_keywords.end(); keyword++) {
os << (*keyword)->getKeyword() << " -- Keyword\n";
- std::list records;
- (*keyword)->getRecords(records);
+
+ std::list records = (*keyword)->getRecords();
for (std::list::const_iterator record = records.begin(); record != records.end(); record++) {
- std::vector recordItems;
- (*record)->getRecords(recordItems);
+ std::vector recordItems = (*record)->getRecords();
for (std::vector::const_iterator recordItem = recordItems.begin(); recordItem != recordItems.end(); recordItem++) {
os << (*recordItem) << " ";
diff --git a/opm/parser/eclipse/RawDeck/RawDeck.hpp b/opm/parser/eclipse/RawDeck/RawDeck.hpp
index 03b4611ae..694fc691f 100644
--- a/opm/parser/eclipse/RawDeck/RawDeck.hpp
+++ b/opm/parser/eclipse/RawDeck/RawDeck.hpp
@@ -25,12 +25,13 @@
#include
#include "opm/parser/eclipse/Logger.hpp"
#include "RawKeyword.hpp"
+#include "RawParserKWs.hpp"
namespace Opm {
class RawDeck {
public:
- RawDeck(std::map& keywordsWithFixedRecordNums);
+ RawDeck(RawParserKWsConstPtr rawParserKWs);
void readDataIntoDeck(const std::string& path);
RawKeywordPtr getKeyword(const std::string& keyword);
unsigned int getNumberOfKeywords();
@@ -38,7 +39,7 @@ namespace Opm {
virtual ~RawDeck();
private:
std::list m_keywords;
- std::map m_keywordsWithFixedRecordNums;
+ RawParserKWsConstPtr m_rawParserKWs;
void readDataIntoDeck(const std::string& path, std::list& keywordList);
bool isKeywordFinished(RawKeywordPtr rawKeyword);
static void verifyValidInputPath(const std::string& inputPath);
diff --git a/opm/parser/eclipse/RawDeck/RawKeyword.cpp b/opm/parser/eclipse/RawDeck/RawKeyword.cpp
index 6f12b4402..672abd192 100644
--- a/opm/parser/eclipse/RawDeck/RawKeyword.cpp
+++ b/opm/parser/eclipse/RawDeck/RawKeyword.cpp
@@ -102,11 +102,11 @@ namespace Opm {
return m_records.size();
}
- void RawKeyword::getRecords(std::list& records) {
- records = m_records;
+ const std::list& RawKeyword::getRecords() const{
+ return m_records;
}
- std::string RawKeyword::getKeyword() {
+ std::string RawKeyword::getKeyword() const{
return m_keyword;
}
diff --git a/opm/parser/eclipse/RawDeck/RawKeyword.hpp b/opm/parser/eclipse/RawDeck/RawKeyword.hpp
index 84a1fddca..24b750d5d 100644
--- a/opm/parser/eclipse/RawDeck/RawKeyword.hpp
+++ b/opm/parser/eclipse/RawDeck/RawKeyword.hpp
@@ -38,8 +38,8 @@ namespace Opm {
static bool lineContainsData(const std::string& line);
static bool lineTerminatesKeyword(const std::string& line);
- std::string getKeyword();
- void getRecords(std::list& records);
+ std::string getKeyword() const;
+ const std::list& getRecords() const;
unsigned int getNumberOfRecords();
void setKeyword(const std::string& keyword);
void addRawRecordString(const std::string& partialRecordString);
@@ -52,6 +52,8 @@ namespace Opm {
static bool isValidKeyword(const std::string& keywordCandidate);
};
typedef boost::shared_ptr RawKeywordPtr;
+ typedef boost::shared_ptr RawKeywordConstPtr;
+
}
#endif /* RAWKEYWORD_HPP */
diff --git a/opm/parser/eclipse/RawDeck/RawParserKWs.cpp b/opm/parser/eclipse/RawDeck/RawParserKWs.cpp
new file mode 100644
index 000000000..0f43c780e
--- /dev/null
+++ b/opm/parser/eclipse/RawDeck/RawParserKWs.cpp
@@ -0,0 +1,76 @@
+/*
+ Copyright 2013 Statoil ASA.
+
+ This file is part of the Open Porous Media project (OPM).
+
+ OPM is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ OPM is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ 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 .
+ */
+#include
+#include "RawParserKWs.hpp"
+
+namespace Opm {
+
+ RawParserKWs::RawParserKWs() {
+ initializeFixedKeywordLenghts();
+ }
+
+ bool RawParserKWs::keywordExists(const std::string& keyword) const {
+ return m_keywordRecordLengths.find(keyword) != m_keywordRecordLengths.end();
+ }
+
+ unsigned int RawParserKWs::getFixedNumberOfRecords(const std::string& keyword) const {
+ if (keywordExists(keyword)) {
+ return m_keywordRecordLengths.find(keyword) -> second;
+ } else
+ throw std::invalid_argument("Given keyword is not found, offending keyword: " + keyword);
+ }
+
+ void RawParserKWs::add(std::pair keywordAndNumRecords) {
+ m_keywordRecordLengths.insert(keywordAndNumRecords);
+ }
+
+ void RawParserKWs::initializeFixedKeywordLenghts() {
+ add(std::pair("GRIDUNIT", 1));
+ add(std::pair("INCLUDE", 1));
+ add(std::pair("RADFIN4", 1));
+ add(std::pair("DIMENS", 1));
+ add(std::pair("START", 1));
+ add(std::pair("GRIDOPTS", 1));
+ add(std::pair("ENDSCALE", 1));
+ add(std::pair("EQLOPTS", 1));
+ add(std::pair("TABDIMS", 1));
+ add(std::pair("EQLDIMS", 1));
+ add(std::pair("REGDIMS", 1));
+ add(std::pair("FAULTDIM", 1));
+ add(std::pair("WELLDIMS", 1));
+ add(std::pair("VFPPDIMS", 1));
+ add(std::pair("RPTSCHED", 1));
+ add(std::pair("TITLE", 0));
+ add(std::pair("RUNSPEC", 0));
+ add(std::pair("METRIC", 0));
+ add(std::pair("SCHEDULE", 0));
+ add(std::pair("SKIPREST", 0));
+ add(std::pair("NOECHO", 0));
+ add(std::pair("END", 0));
+ add(std::pair("OIL", 0));
+ add(std::pair("GAS", 0));
+ add(std::pair("WATER", 0));
+ add(std::pair("DISGAS", 0));
+ add(std::pair("VAPOIL", 0));
+ }
+
+ RawParserKWs::~RawParserKWs() {
+ }
+}
+
diff --git a/opm/parser/eclipse/RawDeck/RawParserKWs.hpp b/opm/parser/eclipse/RawDeck/RawParserKWs.hpp
new file mode 100644
index 000000000..6eae5304c
--- /dev/null
+++ b/opm/parser/eclipse/RawDeck/RawParserKWs.hpp
@@ -0,0 +1,32 @@
+/*
+ * File: RawParserKW.h
+ * Author: kflik
+ *
+ * Created on April 4, 2013, 12:12 PM
+ */
+
+#ifndef RAWPARSERKW_H
+#define RAWPARSERKW_H
+
+#include
+#include