diff --git a/ApplicationCode/FileInterface/RifColumnBasedUserDataParser.cpp b/ApplicationCode/FileInterface/RifColumnBasedUserDataParser.cpp index 58aec5deda..3b9c8714c8 100644 --- a/ApplicationCode/FileInterface/RifColumnBasedUserDataParser.cpp +++ b/ApplicationCode/FileInterface/RifColumnBasedUserDataParser.cpp @@ -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(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(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++) diff --git a/ApplicationCode/FileInterface/RifEclipseUserDataKeywordTools.cpp b/ApplicationCode/FileInterface/RifEclipseUserDataKeywordTools.cpp index 81f29dde4e..6a9049d719 100644 --- a/ApplicationCode/FileInterface/RifEclipseUserDataKeywordTools.cpp +++ b/ApplicationCode/FileInterface/RifEclipseUserDataKeywordTools.cpp @@ -247,3 +247,11 @@ RifEclipseSummaryAddress RifEclipseUserDataKeywordTools::makeAndFillAddress(cons } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +bool RifEclipseUserDataKeywordTools::isStepType(const std::string& identifier) +{ + return (identifier.find("STEPTYPE") != std::string::npos); +} + diff --git a/ApplicationCode/FileInterface/RifEclipseUserDataKeywordTools.h b/ApplicationCode/FileInterface/RifEclipseUserDataKeywordTools.h index 86375eb98c..68a16d4cd0 100644 --- a/ApplicationCode/FileInterface/RifEclipseUserDataKeywordTools.h +++ b/ApplicationCode/FileInterface/RifEclipseUserDataKeywordTools.h @@ -38,5 +38,7 @@ public: static bool isDate(const std::string& identifier); static RifEclipseSummaryAddress makeAndFillAddress(const std::string quantityName, const std::vector& columnHeaderText); + + static bool isStepType(const std::string& identifier); }; diff --git a/ApplicationCode/FileInterface/RifEclipseUserDataParserTools.cpp b/ApplicationCode/FileInterface/RifEclipseUserDataParserTools.cpp index a0001e0ac6..f93d34c085 100644 --- a/ApplicationCode/FileInterface/RifEclipseUserDataParserTools.cpp +++ b/ApplicationCode/FileInterface/RifEclipseUserDataParserTools.cpp @@ -593,6 +593,7 @@ std::vector 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 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 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 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); } diff --git a/ApplicationCode/UnitTests/FixedWidthDataParser-Test.cpp b/ApplicationCode/UnitTests/FixedWidthDataParser-Test.cpp index e7d5e469d8..c75458672c 100644 --- a/ApplicationCode/UnitTests/FixedWidthDataParser-Test.cpp +++ b/ApplicationCode/UnitTests/FixedWidthDataParser-Test.cpp @@ -212,3 +212,72 @@ TEST(FixedWidthDataParser, VaryingTimeStepCount) EXPECT_EQ(size_t(2), tables.size()); } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +TEST(FixedWidthDataParser, HandlingOfStepType) +{ + QString data = R"( +1 + ------------------------------------------------------------------------------------------------------------------------------- + SUMMARY OF RUN NORNE_ATW2013_RFTPLT_V3 ECLIPSE 2016.2 DATESTAMP 13-DEC-2016 USER dtb MACHINE stj-lcb01-01-03 + ------------------------------------------------------------------------------------------------------------------------------- + DATE YEARS NEWTON MLINEARS DAY MONTH YEAR NEWTON TCPU ELAPSED + YEARS SECONDS SECONDS + + + ------------------------------------------------------------------------------------------------------------------------------- + 6-NOV-1997 0 0 0 6 11 1997 0 4.880000 9.720000 + 7-NOV-1997 0.002738 3 28 7 11 1997 3 5.240000 10.11000 + 8-NOV-1997 0.006556 4 42 8 11 1997 4 5.730000 10.60000 + 9-NOV-1997 0.009231 3 28 9 11 1997 3 6.080000 10.95000 + 10-NOV-1997 0.011462 4 32 10 11 1997 4 6.500000 11.37000 + 11-NOV-1997 0.013710 4 35 11 11 1997 4 6.940001 11.81000 + 11-NOV-1997 0.015950 3 25 11 11 1997 3 7.270000 12.14000 + 12-NOV-1997 0.018477 4 35 12 11 1997 4 7.710001 12.58000 + 13-NOV-1997 0.020190 3 24 13 11 1997 3 8.040000 12.91000 + 14-NOV-1997 0.021903 3 27 14 11 1997 3 8.380000 13.25000 + 14-NOV-1997 0.024232 2 17 14 11 1997 2 8.640000 13.57000 + 17-NOV-1997 0.030838 3 26 17 11 1997 3 8.980000 13.91000 + 19-NOV-1997 0.037060 3 30 19 11 1997 3 9.350000 14.28000 + 21-NOV-1997 0.042841 4 35 21 11 1997 4 9.790001 14.71000 + 23-NOV-1997 0.049239 5 45 23 11 1997 5 10.33000 15.26000 + 25-NOV-1997 0.054613 3 25 25 11 1997 3 10.67000 15.60000 + 28-NOV-1997 0.061135 3 27 28 11 1997 3 11.01000 15.94000 + 29-NOV-1997 0.064791 3 23 29 11 1997 3 11.33000 16.26000 +1 + ------------------------------------------------------------------------------------------------------------------------------- + SUMMARY OF RUN NORNE_ATW2013_RFTPLT_V3 ECLIPSE 2016.2 DATESTAMP 13-DEC-2016 USER dtb MACHINE stj-lcb01-01-03 + ------------------------------------------------------------------------------------------------------------------------------- + DATE TIMESTEP TCPUTS TCPUDAY MLINEARS MSUMLINS NLINEARS STEPTYPE TELAPLIN MSUMNEWT + DAYS SECONDS SEC/D SECONDS + + + ------------------------------------------------------------------------------------------------------------------------------- + 6-NOV-1997 0 4.880000 0 0 0 0 0 0 + 7-NOV-1997 1.000000 5.240000 5.240000 28 28 9.333333 INIT 0.361071 3 + 8-NOV-1997 1.394612 0.490000 0.351352 42 70 10.50000 TRNC 0.151429 7 + 9-NOV-1997 0.977053 0.350000 0.358220 28 98 9.333333 TRNC 0.111735 10 + 10-NOV-1997 0.814727 0.420000 0.515510 32 130 8.000000 TRNC 0.087462 14 + 11-NOV-1997 0.821321 0.430000 0.523547 35 165 8.750000 TRNC 0.071576 18 + 11-NOV-1997 0.817933 0.320000 0.391230 25 190 8.333333 TRNC 0.063895 21 + 12-NOV-1997 0.923225 0.430000 0.465759 35 225 8.750000 TRNC 0.055911 25 + 13-NOV-1997 0.625564 0.320000 0.511538 24 249 8.000000 HALF 0.051847 28 + 14-NOV-1997 0.625564 0.340000 0.543509 27 276 9.000000 REPT 0.048007 31 + 14-NOV-1997 0.850771 0.240000 0.282097 17 293 8.500000 TRNC 0.046314 33 + 17-NOV-1997 2.412731 0.340000 0.140919 26 319 8.666667 TRNC 0.043605 36 + 19-NOV-1997 2.272543 0.360000 0.158413 30 349 10.00000 TRNC 0.040917 39 + 21-NOV-1997 2.111558 0.440000 0.208377 35 384 8.750000 TRNC 0.038307 43 + 23-NOV-1997 2.336865 0.540000 0.231079 45 429 9.000000 TRNC 0.035571 48 + 25-NOV-1997 1.962967 0.330000 0.168113 25 454 8.333333 EFF+ 0.034361 51 + 28-NOV-1997 2.382306 0.340000 0.142719 27 481 9.000000 TRNC 0.033139 54 + 29-NOV-1997 1.335130 0.310000 0.232187 23 504 7.666667 HALF 0.032262 57 +)"; + + RifColumnBasedUserDataParser parser(data); + auto tables = parser.tableData(); + EXPECT_EQ(size_t(1), tables.size()); + + EXPECT_EQ(size_t(19), tables[0].columnInfos().size()); +} +