From 8f14016eed2698d79d923156b19e7baa2f478416 Mon Sep 17 00:00:00 2001 From: Rebecca Cox Date: Mon, 25 Sep 2017 14:34:02 +0200 Subject: [PATCH] #1839 Observed data: Parser for data with keyword VECTOR --- .../FileInterface/CMakeLists_files.cmake | 2 + .../FileInterface/RifKeywordVectorParser.cpp | 106 ++++++++++++++++++ .../FileInterface/RifKeywordVectorParser.h | 53 +++++++++ .../FileInterface/RifRsmspecParserTools.cpp | 33 +++++- .../FileInterface/RifRsmspecParserTools.h | 2 + 5 files changed, 195 insertions(+), 1 deletion(-) create mode 100644 ApplicationCode/FileInterface/RifKeywordVectorParser.cpp create mode 100644 ApplicationCode/FileInterface/RifKeywordVectorParser.h diff --git a/ApplicationCode/FileInterface/CMakeLists_files.cmake b/ApplicationCode/FileInterface/CMakeLists_files.cmake index 3e026fc628..ff00b7c610 100644 --- a/ApplicationCode/FileInterface/CMakeLists_files.cmake +++ b/ApplicationCode/FileInterface/CMakeLists_files.cmake @@ -19,6 +19,7 @@ ${CEE_CURRENT_LIST_DIR}RifSummaryReaderInterface.h ${CEE_CURRENT_LIST_DIR}RifColumnBasedAsciiParser.h ${CEE_CURRENT_LIST_DIR}RifRsmspecParserTools.h ${CEE_CURRENT_LIST_DIR}RifColumnBasedRsmspecParser.h +${CEE_CURRENT_LIST_DIR}RifKeywordVectorParser.h ${CEE_CURRENT_LIST_DIR}RifReaderObservedData.h ${CEE_CURRENT_LIST_DIR}RifReaderEclipseSummary.h ${CEE_CURRENT_LIST_DIR}RifJsonEncodeDecode.h @@ -56,6 +57,7 @@ ${CEE_CURRENT_LIST_DIR}RifSummaryReaderInterface.cpp ${CEE_CURRENT_LIST_DIR}RifColumnBasedAsciiParser.cpp ${CEE_CURRENT_LIST_DIR}RifRsmspecParserTools.cpp ${CEE_CURRENT_LIST_DIR}RifColumnBasedRsmspecParser.cpp +${CEE_CURRENT_LIST_DIR}RifKeywordVectorParser.cpp ${CEE_CURRENT_LIST_DIR}RifReaderObservedData.cpp ${CEE_CURRENT_LIST_DIR}RifReaderEclipseSummary.cpp ${CEE_CURRENT_LIST_DIR}RifJsonEncodeDecode.cpp diff --git a/ApplicationCode/FileInterface/RifKeywordVectorParser.cpp b/ApplicationCode/FileInterface/RifKeywordVectorParser.cpp new file mode 100644 index 0000000000..7f6fc36048 --- /dev/null +++ b/ApplicationCode/FileInterface/RifKeywordVectorParser.cpp @@ -0,0 +1,106 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2017- Statoil ASA +// +// ResInsight 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. +// +// ResInsight 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 at +// for more details. +// +///////////////////////////////////////////////////////////////////////////////// + +#include "RifKeywordVectorParser.h" + +#include "RifRsmspecParserTools.h" + +#include "RiaLogging.h" + +#include "cvfAssert.h" + +#include +#include +#include + + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +RifKeywordVectorParser::RifKeywordVectorParser(const QString& data) +{ + parseData(data); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +const std::vector& RifKeywordVectorParser::keywordBasedVectors() const +{ + return m_keywordBasedVectors; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +bool RifKeywordVectorParser::canBeParsed(const QString& data) +{ + std::stringstream streamData; + streamData.str(data.toStdString()); + std::string line; + std::getline(streamData, line); + + while (streamData.good()) + { + if (line.size() > 1 && line[0] == '-' && line[1] == '-') + { + std::getline(streamData, line); + } + else if (line.find("VECTOR") == 0) + { + return true; + } + else + { + return false; + } + } + return false; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RifKeywordVectorParser::parseData(const QString& data) +{ + std::stringstream streamData; + streamData.str(data.toStdString()); + std::string line; + std::getline(streamData, line); + + do + { + while (RifRsmspecParserTools::isLineSkippable(line) && !streamData.eof()) + { + std::getline(streamData, line); + } + + KeywordBasedVector keywordBasedVector; + keywordBasedVector.header = RifRsmspecParserTools::headerReader(streamData, line); + if (keywordBasedVector.header.empty()) break; + + while (RifRsmspecParserTools::isANumber(line)) + { + keywordBasedVector.values.push_back(std::stod(line)); + std::getline(streamData, line); + } + + m_keywordBasedVectors.push_back(keywordBasedVector); + + } while (!streamData.eof()); +} diff --git a/ApplicationCode/FileInterface/RifKeywordVectorParser.h b/ApplicationCode/FileInterface/RifKeywordVectorParser.h new file mode 100644 index 0000000000..d9eb7f2ed6 --- /dev/null +++ b/ApplicationCode/FileInterface/RifKeywordVectorParser.h @@ -0,0 +1,53 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2017- Statoil ASA +// +// ResInsight 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. +// +// ResInsight 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 at +// for more details. +// +///////////////////////////////////////////////////////////////////////////////// + +#pragma once + +#include "RifEclipseSummaryAddress.h" + +#include +#include +#include + +#include +#include +#include + +struct KeywordBasedVector +{ + std::vector header; + std::vector values; +}; + +//================================================================================================== +/// +//================================================================================================== +class RifKeywordVectorParser +{ +public: + RifKeywordVectorParser(const QString& data); + + const std::vector& keywordBasedVectors() const; + static bool canBeParsed(const QString& data); + +private: + void parseData(const QString& data); + +private: + std::vector m_keywordBasedVectors; +}; diff --git a/ApplicationCode/FileInterface/RifRsmspecParserTools.cpp b/ApplicationCode/FileInterface/RifRsmspecParserTools.cpp index c5bda0826c..1267b005b3 100644 --- a/ApplicationCode/FileInterface/RifRsmspecParserTools.cpp +++ b/ApplicationCode/FileInterface/RifRsmspecParserTools.cpp @@ -35,7 +35,7 @@ bool RifRsmspecParserTools::isLineSkippable(const std::string& line) { return true; } - else if (line[0] == '-') + else if (line.size() > 1 && line[0] == '-' && line[1] == '-') { return true; } @@ -244,3 +244,34 @@ void RifRsmspecParserTools::splitLineToDoubles(const std::string& line, std::vec values.push_back(d); } } + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +bool RifRsmspecParserTools::isANumber(const std::string& line) +{ + try + { + std::stod(line); + } + catch (...) + { + return false; + } + return true; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +std::vector RifRsmspecParserTools::headerReader(std::stringstream& streamData, std::string& line) +{ + std::vector header; + + while (!isANumber(line) && !streamData.eof()) + { + header.push_back(line); + std::getline(streamData, line); + } + return header; +} \ No newline at end of file diff --git a/ApplicationCode/FileInterface/RifRsmspecParserTools.h b/ApplicationCode/FileInterface/RifRsmspecParserTools.h index fbda03d184..012cef3146 100644 --- a/ApplicationCode/FileInterface/RifRsmspecParserTools.h +++ b/ApplicationCode/FileInterface/RifRsmspecParserTools.h @@ -59,4 +59,6 @@ public: static RifEclipseSummaryAddress::SummaryVarCategory identifyCategory(const std::string& word); static void splitLineToDoubles(const std::string& line, std::vector& values); static std::vector columnInfoForTable(std::stringstream& data, std::string& line); + static bool isANumber(const std::string& line); + static std::vector headerReader(std::stringstream& streamData, std::string& line); };