2013-03-18 13:40:14 +01:00
|
|
|
/*
|
|
|
|
|
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 <http://www.gnu.org/licenses/>.
|
2013-03-14 12:07:33 +01:00
|
|
|
*/
|
2013-03-18 13:40:14 +01:00
|
|
|
|
|
|
|
|
|
2013-03-14 14:54:53 +01:00
|
|
|
#include <boost/filesystem.hpp>
|
2013-03-15 16:09:24 +01:00
|
|
|
#include <boost/algorithm/string.hpp>
|
2013-03-14 12:07:33 +01:00
|
|
|
#include <fstream>
|
|
|
|
|
using std::ifstream;
|
|
|
|
|
|
|
|
|
|
#include "Parser.hpp"
|
|
|
|
|
|
|
|
|
|
Parser::Parser() {
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-14 14:54:53 +01:00
|
|
|
Parser::Parser(const std::string &path) {
|
2013-03-14 16:05:35 +01:00
|
|
|
m_dataFilePath = path;
|
2013-03-14 12:07:33 +01:00
|
|
|
}
|
|
|
|
|
|
2013-03-14 16:05:35 +01:00
|
|
|
EclipseDeck Parser::parse() {
|
2013-03-14 12:07:33 +01:00
|
|
|
EclipseDeck deck;
|
2013-03-18 13:40:14 +01:00
|
|
|
m_logger.debug("Initializing inputstream from file: " + m_dataFilePath);
|
2013-03-14 15:53:36 +01:00
|
|
|
|
|
|
|
|
ifstream inputstream;
|
2013-03-14 16:05:35 +01:00
|
|
|
inputstream.open(m_dataFilePath.c_str());
|
2013-03-14 15:53:36 +01:00
|
|
|
|
|
|
|
|
if (!inputstream.is_open()) {
|
2013-03-18 13:40:14 +01:00
|
|
|
m_logger.debug("ERROR: unable to open file");
|
2013-03-14 15:53:36 +01:00
|
|
|
return deck;
|
|
|
|
|
}
|
2013-03-15 16:09:24 +01:00
|
|
|
|
2013-03-14 15:53:36 +01:00
|
|
|
std::string line;
|
|
|
|
|
while (!inputstream.eof()) {
|
|
|
|
|
std::getline(inputstream, line);
|
2013-03-15 16:09:24 +01:00
|
|
|
if (line.substr(0, 2) == "--") {
|
2013-03-18 13:40:14 +01:00
|
|
|
m_logger.debug("COMMENT LINE < " + line + ">");
|
2013-03-15 16:09:24 +01:00
|
|
|
}
|
|
|
|
|
else if (boost::algorithm::trim_copy(line).length() == 0) {
|
2013-03-18 13:40:14 +01:00
|
|
|
m_logger.debug("EMPTY LINE <" + line + ">");
|
2013-03-15 16:09:24 +01:00
|
|
|
}
|
|
|
|
|
else if (line.substr(0, 1) != " " && boost::algorithm::to_upper_copy(line) == line) {
|
2013-03-14 16:05:35 +01:00
|
|
|
deck.addKeyword(line);
|
2013-03-18 13:40:14 +01:00
|
|
|
m_logger.debug("KEYWORD LINE <" + line + ">");
|
2013-03-15 16:09:24 +01:00
|
|
|
}
|
|
|
|
|
else {
|
2013-03-18 13:40:14 +01:00
|
|
|
m_logger.debug("SOMETHING ELSE <" + line + ">");
|
2013-03-14 15:53:36 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
inputstream.close();
|
2013-03-14 16:05:35 +01:00
|
|
|
return deck;
|
|
|
|
|
}
|
2013-03-14 15:53:36 +01:00
|
|
|
|
2013-03-14 12:07:33 +01:00
|
|
|
Parser::~Parser() {
|
|
|
|
|
}
|
|
|
|
|
|