mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
#1839 Observed data: Parser for data with keyword VECTOR
This commit is contained in:
parent
ef56591555
commit
8f14016eed
@ -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
|
||||
|
106
ApplicationCode/FileInterface/RifKeywordVectorParser.cpp
Normal file
106
ApplicationCode/FileInterface/RifKeywordVectorParser.cpp
Normal file
@ -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 <http://www.gnu.org/licenses/gpl.html>
|
||||
// for more details.
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "RifKeywordVectorParser.h"
|
||||
|
||||
#include "RifRsmspecParserTools.h"
|
||||
|
||||
#include "RiaLogging.h"
|
||||
|
||||
#include "cvfAssert.h"
|
||||
|
||||
#include <QString>
|
||||
#include <QStringList>
|
||||
#include <QTextStream>
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RifKeywordVectorParser::RifKeywordVectorParser(const QString& data)
|
||||
{
|
||||
parseData(data);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
const std::vector<KeywordBasedVector>& 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());
|
||||
}
|
53
ApplicationCode/FileInterface/RifKeywordVectorParser.h
Normal file
53
ApplicationCode/FileInterface/RifKeywordVectorParser.h
Normal file
@ -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 <http://www.gnu.org/licenses/gpl.html>
|
||||
// for more details.
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "RifEclipseSummaryAddress.h"
|
||||
|
||||
#include <QDateTime>
|
||||
#include <QLocale>
|
||||
#include <QString>
|
||||
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
struct KeywordBasedVector
|
||||
{
|
||||
std::vector<std::string> header;
|
||||
std::vector<double> values;
|
||||
};
|
||||
|
||||
//==================================================================================================
|
||||
///
|
||||
//==================================================================================================
|
||||
class RifKeywordVectorParser
|
||||
{
|
||||
public:
|
||||
RifKeywordVectorParser(const QString& data);
|
||||
|
||||
const std::vector<KeywordBasedVector>& keywordBasedVectors() const;
|
||||
static bool canBeParsed(const QString& data);
|
||||
|
||||
private:
|
||||
void parseData(const QString& data);
|
||||
|
||||
private:
|
||||
std::vector<KeywordBasedVector> m_keywordBasedVectors;
|
||||
};
|
@ -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<std::string> RifRsmspecParserTools::headerReader(std::stringstream& streamData, std::string& line)
|
||||
{
|
||||
std::vector<std::string> header;
|
||||
|
||||
while (!isANumber(line) && !streamData.eof())
|
||||
{
|
||||
header.push_back(line);
|
||||
std::getline(streamData, line);
|
||||
}
|
||||
return header;
|
||||
}
|
@ -59,4 +59,6 @@ public:
|
||||
static RifEclipseSummaryAddress::SummaryVarCategory identifyCategory(const std::string& word);
|
||||
static void splitLineToDoubles(const std::string& line, std::vector<double>& values);
|
||||
static std::vector<ColumnInfo> columnInfoForTable(std::stringstream& data, std::string& line);
|
||||
static bool isANumber(const std::string& line);
|
||||
static std::vector<std::string> headerReader(std::stringstream& streamData, std::string& line);
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user