mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
#2003 Observed Data : Handle STEPTYPE with potentially missing text for first row
This commit is contained in:
@@ -18,6 +18,7 @@
|
||||
|
||||
#include "RifColumnBasedUserDataParser.h"
|
||||
|
||||
#include "RifEclipseUserDataKeywordTools.h"
|
||||
#include "RifEclipseUserDataParserTools.h"
|
||||
|
||||
#include "RiaDateStringParser.h"
|
||||
@@ -103,6 +104,15 @@ void RifColumnBasedUserDataParser::parseTableData(const QString& data)
|
||||
int columnCount = static_cast<int>(columnInfos.size());
|
||||
if (columnCount == 0) break;
|
||||
|
||||
int stepTypeIndex = -1;
|
||||
for (size_t i = 0; i < columnInfos.size(); i++)
|
||||
{
|
||||
if (RifEclipseUserDataKeywordTools::isStepType(columnInfos[i].summaryAddress.quantityName()))
|
||||
{
|
||||
stepTypeIndex = static_cast<int>(i);
|
||||
}
|
||||
}
|
||||
|
||||
std::string line;
|
||||
std::getline(streamData, line);
|
||||
|
||||
@@ -111,6 +121,12 @@ void RifColumnBasedUserDataParser::parseTableData(const QString& data)
|
||||
QString qLine = QString::fromStdString(line);
|
||||
QStringList entries = qLine.split(" ", QString::SkipEmptyParts);
|
||||
|
||||
if (stepTypeIndex > -1 &&
|
||||
entries.size() < columnInfos.size())
|
||||
{
|
||||
entries.insert(stepTypeIndex, " ");
|
||||
}
|
||||
|
||||
if (entries.size() < columnCount) break;
|
||||
|
||||
for (int i = 0; i < columnCount; i++)
|
||||
|
||||
@@ -247,3 +247,11 @@ RifEclipseSummaryAddress RifEclipseUserDataKeywordTools::makeAndFillAddress(cons
|
||||
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RifEclipseUserDataKeywordTools::isStepType(const std::string& identifier)
|
||||
{
|
||||
return (identifier.find("STEPTYPE") != std::string::npos);
|
||||
}
|
||||
|
||||
|
||||
@@ -38,5 +38,7 @@ public:
|
||||
static bool isDate(const std::string& identifier);
|
||||
|
||||
static RifEclipseSummaryAddress makeAndFillAddress(const std::string quantityName, const std::vector<std::string>& columnHeaderText);
|
||||
|
||||
static bool isStepType(const std::string& identifier);
|
||||
};
|
||||
|
||||
|
||||
@@ -593,6 +593,7 @@ std::vector<std::string> RifEclipseUserDataParserTools::findValidHeaderLines(std
|
||||
size_t columnCount = 0;
|
||||
std::string line;
|
||||
bool continueParsing = true;
|
||||
bool hasStepType = false;
|
||||
while (continueParsing)
|
||||
{
|
||||
posAtTableDataStart = streamData.tellg();
|
||||
@@ -605,25 +606,42 @@ std::vector<std::string> RifEclipseUserDataParserTools::findValidHeaderLines(std
|
||||
{
|
||||
if (!RifEclipseUserDataParserTools::isLineSkippable(line))
|
||||
{
|
||||
auto words = RifEclipseUserDataParserTools::splitLineAndRemoveComments(line);
|
||||
|
||||
if (!hasStepType)
|
||||
{
|
||||
for (size_t i = 0; i < words.size(); i++)
|
||||
{
|
||||
if (RifEclipseUserDataKeywordTools::isStepType(words[i]))
|
||||
{
|
||||
hasStepType = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (columnCount == 0)
|
||||
{
|
||||
// Fist line with valid header data defines the number of columns
|
||||
|
||||
auto words = RifEclipseUserDataParserTools::splitLineAndRemoveComments(line);
|
||||
columnCount = words.size();
|
||||
|
||||
headerLines.push_back(line);
|
||||
}
|
||||
else
|
||||
{
|
||||
auto words = RifEclipseUserDataParserTools::splitLineAndRemoveComments(line);
|
||||
std::vector<double> doubleValues = RifEclipseUserDataParserTools::splitLineToDoubles(line);
|
||||
|
||||
if (doubleValues.size() < columnCount &&
|
||||
words.size() < columnCount)
|
||||
if (doubleValues.size() < columnCount && words.size() < columnCount)
|
||||
{
|
||||
// Consider a line with double values less than column count as a table header
|
||||
headerLines.push_back(line);
|
||||
if (hasStepType && (words.size() + 1 == columnCount))
|
||||
{
|
||||
continueParsing = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Consider a line with double values less than column count as a table header
|
||||
headerLines.push_back(line);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -725,6 +743,10 @@ std::vector<ColumnInfo> RifEclipseUserDataParserTools::columnInfoFromColumnHeade
|
||||
RifEclipseSummaryAddress adr = RifEclipseUserDataKeywordTools::makeAndFillAddress(quantity, restOfHeader);
|
||||
|
||||
ColumnInfo ci = ColumnInfo::createColumnInfo(quantity, unit, adr);
|
||||
if (RifEclipseUserDataKeywordTools::isStepType(quantity))
|
||||
{
|
||||
ci.isStringData = true;
|
||||
}
|
||||
|
||||
table.push_back(ci);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user