mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
#2003 Observed Data : Add basic support for fixed width in parser
This commit is contained in:
@@ -66,14 +66,28 @@ const ColumnInfo* RifColumnBasedUserDataParser::columnInfo(size_t tableIndex, si
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RifColumnBasedUserDataParser::parseTableData(const QString& data)
|
||||
{
|
||||
std::string stdData = data.toStdString();
|
||||
bool isFixedWidth = RifEclipseUserDataParserTools::isFixedWidthHeader(stdData);
|
||||
|
||||
std::stringstream streamData;
|
||||
streamData.str(data.toStdString());
|
||||
streamData.str(stdData);
|
||||
|
||||
do
|
||||
{
|
||||
std::vector<std::string> errorStrings;
|
||||
|
||||
auto table = RifEclipseUserDataParserTools::tableDataFromText(streamData, &errorStrings);
|
||||
TableData table;
|
||||
|
||||
if (isFixedWidth)
|
||||
{
|
||||
auto columnInfos = RifEclipseUserDataParserTools::columnInfoForFixedColumnWidth(streamData);
|
||||
table = TableData("", "", "", columnInfos);
|
||||
}
|
||||
else
|
||||
{
|
||||
table = RifEclipseUserDataParserTools::tableDataFromText(streamData, &errorStrings);
|
||||
}
|
||||
|
||||
if (m_errorText)
|
||||
{
|
||||
for (auto s : errorStrings)
|
||||
|
||||
@@ -503,11 +503,7 @@ TableData RifEclipseUserDataParserTools::tableDataFromText(std::stringstream& st
|
||||
|
||||
RifEclipseSummaryAddress adr = RifEclipseUserDataKeywordTools::makeAndFillAddress(quantity, columnHeader);
|
||||
|
||||
ColumnInfo ci(adr, unit);
|
||||
if (quantity == "DATE")
|
||||
{
|
||||
ci.isStringData = true;
|
||||
}
|
||||
ColumnInfo ci = ColumnInfo::createColumnInfo(quantity, unit, adr);
|
||||
|
||||
columnInfos.push_back(ci);
|
||||
}
|
||||
@@ -728,28 +724,11 @@ std::vector<ColumnInfo> RifEclipseUserDataParserTools::columnInfoFromColumnHeade
|
||||
|
||||
RifEclipseSummaryAddress adr = RifEclipseUserDataKeywordTools::makeAndFillAddress(quantity, restOfHeader);
|
||||
|
||||
ColumnInfo columnInfo;
|
||||
columnInfo.unitName = unit;
|
||||
ColumnInfo ci = ColumnInfo::createColumnInfo(quantity, unit, adr);
|
||||
|
||||
// if (hasDateUnit(unit) ||
|
||||
// hasDateUnit(quantity))
|
||||
// {
|
||||
// columnInfo.isAVector = false;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// columnInfo.isAVector = true;
|
||||
// }
|
||||
//columnInfo.origin = origin;
|
||||
//columnInfo.dateFormatString = dateFormat;
|
||||
//columnInfo.startDateString = startDate;
|
||||
|
||||
columnInfo.summaryAddress = adr;
|
||||
|
||||
table.push_back(columnInfo);
|
||||
table.push_back(ci);
|
||||
}
|
||||
|
||||
|
||||
return table;
|
||||
}
|
||||
|
||||
@@ -859,3 +838,17 @@ bool RifEclipseUserDataParserTools::isUnitText(const std::string& word)
|
||||
return false;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
ColumnInfo ColumnInfo::createColumnInfo(const std::string& quantity, const std::string& unit, const RifEclipseSummaryAddress& adr)
|
||||
{
|
||||
ColumnInfo ci(adr, unit);
|
||||
|
||||
if (RifEclipseUserDataParserTools::hasDateUnit(quantity))
|
||||
{
|
||||
ci.isStringData = true;
|
||||
}
|
||||
|
||||
return ci;
|
||||
}
|
||||
|
||||
@@ -49,6 +49,8 @@ public:
|
||||
}
|
||||
|
||||
public:
|
||||
static ColumnInfo createColumnInfo(const std::string& quantity, const std::string& unit, const RifEclipseSummaryAddress& adr);
|
||||
|
||||
RifEclipseSummaryAddress summaryAddress;
|
||||
std::string unitName;
|
||||
double scaleFactor;
|
||||
|
||||
@@ -149,15 +149,12 @@ TEST(FixedWidthDataParser, DetectFixedWidth)
|
||||
|
||||
EXPECT_TRUE(RifEclipseUserDataParserTools::isFixedWidthHeader(data.toStdString()));
|
||||
|
||||
// RifColumnBasedUserDataParser parser(data);
|
||||
// auto tables = parser.tableData();
|
||||
// EXPECT_EQ(3, tables.size());
|
||||
RifColumnBasedUserDataParser parser(data);
|
||||
auto tables = parser.tableData();
|
||||
EXPECT_EQ(size_t(3), tables.size());
|
||||
|
||||
/*
|
||||
auto mergedTables = RifEclipseUserDataParserTools::mergeEqualTimeSteps(tables);
|
||||
EXPECT_EQ(1, mergedTables.size());
|
||||
EXPECT_EQ(28, mergedTables[0].size());
|
||||
*/
|
||||
EXPECT_EQ(size_t(10), tables[0].columnInfos().size());
|
||||
EXPECT_EQ(size_t(13), tables[0].columnInfos()[0].stringValues.size());
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@@ -210,13 +207,8 @@ TEST(FixedWidthDataParser, VaryingTimeStepCount)
|
||||
" 14-NOV-1997 0 2637960. 5415305. 592557.9 0 10541.03 0 14.09936 -38974.5 \n"
|
||||
;
|
||||
|
||||
// RifColumnBasedUserDataParser parser(data);
|
||||
// auto tables = parser.tableData();
|
||||
// EXPECT_EQ(2, tables.size());
|
||||
|
||||
/*
|
||||
auto mergedTables = RifEclipseUserDataParserTools::mergeEqualTimeSteps(tables);
|
||||
EXPECT_EQ(2, mergedTables.size());
|
||||
*/
|
||||
RifColumnBasedUserDataParser parser(data);
|
||||
auto tables = parser.tableData();
|
||||
EXPECT_EQ(2, tables.size());
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user