mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
#2003 Observed Data : Use time with highest available resolution
This commit is contained in:
parent
97d67f2d49
commit
9d06ef857e
@ -174,94 +174,96 @@ std::vector<time_t> RifColumnBasedUserData::createTimeSteps(const TableData& tab
|
|||||||
{
|
{
|
||||||
std::vector<time_t> tsVector;
|
std::vector<time_t> tsVector;
|
||||||
|
|
||||||
// Find time index
|
|
||||||
size_t dateColumnIndex = tableData.columnInfos().size();
|
size_t dateColumnIndex = tableData.columnInfos().size();
|
||||||
size_t dayOrYearColumnIndex = tableData.columnInfos().size();
|
size_t daysColumnIndex = tableData.columnInfos().size();
|
||||||
|
size_t yearsColumnIndex = tableData.columnInfos().size();
|
||||||
size_t yearXColumnIndex = tableData.columnInfos().size();
|
size_t yearXColumnIndex = tableData.columnInfos().size();
|
||||||
|
|
||||||
|
// Find first column matching the text criteria
|
||||||
|
|
||||||
for (size_t columIndex = 0; columIndex < tableData.columnInfos().size(); columIndex++)
|
for (size_t columIndex = 0; columIndex < tableData.columnInfos().size(); columIndex++)
|
||||||
{
|
{
|
||||||
const ColumnInfo& ci = tableData.columnInfos()[columIndex];
|
const ColumnInfo& ci = tableData.columnInfos()[columIndex];
|
||||||
|
|
||||||
if (dateColumnIndex == tableData.columnInfos().size() &&
|
if (dateColumnIndex == tableData.columnInfos().size() &&
|
||||||
RifEclipseUserDataKeywordTools::isDate(ci.summaryAddress.quantityName()))
|
RifEclipseUserDataKeywordTools::isDate(ci.summaryAddress.quantityName()))
|
||||||
{
|
{
|
||||||
dateColumnIndex = columIndex;
|
dateColumnIndex = columIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dayOrYearColumnIndex == tableData.columnInfos().size() &&
|
if (daysColumnIndex == tableData.columnInfos().size() &&
|
||||||
RifEclipseUserDataParserTools::hasTimeUnit(ci.unitName))
|
RifEclipseUserDataKeywordTools::isTime(ci.summaryAddress.quantityName()) &&
|
||||||
|
RifEclipseUserDataKeywordTools::isDays(ci.unitName))
|
||||||
{
|
{
|
||||||
dayOrYearColumnIndex = columIndex;
|
daysColumnIndex = columIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (yearsColumnIndex == tableData.columnInfos().size() &&
|
||||||
|
RifEclipseUserDataKeywordTools::isYears(ci.summaryAddress.quantityName()) &&
|
||||||
|
RifEclipseUserDataKeywordTools::isYears(ci.unitName))
|
||||||
|
{
|
||||||
|
yearsColumnIndex = columIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (yearXColumnIndex == tableData.columnInfos().size() &&
|
if (yearXColumnIndex == tableData.columnInfos().size() &&
|
||||||
ci.summaryAddress.quantityName() == "YEARX")
|
RifEclipseUserDataKeywordTools::isYearX(ci.summaryAddress.quantityName()) &&
|
||||||
|
RifEclipseUserDataKeywordTools::isYears(ci.unitName))
|
||||||
{
|
{
|
||||||
yearXColumnIndex = columIndex;
|
yearXColumnIndex = columIndex;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dateColumnIndex < tableData.columnInfos().size() ||
|
// YEARX is interpreted as absolute decimal year (2014.32)
|
||||||
dayOrYearColumnIndex < tableData.columnInfos().size())
|
if (tsVector.empty() && yearXColumnIndex != tableData.columnInfos().size())
|
||||||
{
|
{
|
||||||
if (dateColumnIndex != tableData.columnInfos().size())
|
const ColumnInfo& ci = tableData.columnInfos()[yearXColumnIndex];
|
||||||
|
|
||||||
|
for (const auto& timeStepValue : ci.values)
|
||||||
{
|
{
|
||||||
const ColumnInfo& ci = tableData.columnInfos()[dateColumnIndex];
|
QDateTime dateTime = RiaQDateTimeTools::fromYears(timeStepValue);
|
||||||
|
tsVector.push_back(dateTime.toTime_t());
|
||||||
QString dateFormat;
|
|
||||||
for (auto s : ci.stringValues)
|
|
||||||
{
|
|
||||||
QDateTime dt = RiaDateStringParser::parseDateString(s);
|
|
||||||
|
|
||||||
tsVector.push_back(dt.toTime_t());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else if (yearXColumnIndex != tableData.columnInfos().size())
|
}
|
||||||
{
|
|
||||||
const ColumnInfo& ci = tableData.columnInfos()[yearXColumnIndex];
|
|
||||||
|
|
||||||
for (const auto& timeStepValue : ci.values)
|
// DAYS is interpreted as decimal days since simulation start (23.32)
|
||||||
{
|
if (tsVector.empty() && daysColumnIndex != tableData.columnInfos().size())
|
||||||
QDateTime dateTime = RiaQDateTimeTools::fromYears(timeStepValue);
|
{
|
||||||
tsVector.push_back(dateTime.toTime_t());
|
const ColumnInfo& ci = tableData.columnInfos()[daysColumnIndex];
|
||||||
}
|
|
||||||
|
QDateTime simulationStartDate = tableData.findFirstDate();
|
||||||
|
|
||||||
|
for (const auto& timeStepValue : ci.values)
|
||||||
|
{
|
||||||
|
QDateTime dateTime = RiaQDateTimeTools::addDays(simulationStartDate, timeStepValue);
|
||||||
|
tsVector.push_back(dateTime.toTime_t());
|
||||||
}
|
}
|
||||||
else
|
}
|
||||||
|
|
||||||
|
// YEARS is interpreted as decimal years since simulation start (23.32)
|
||||||
|
if (tsVector.empty() && yearsColumnIndex != tableData.columnInfos().size())
|
||||||
|
{
|
||||||
|
const ColumnInfo& ci = tableData.columnInfos()[yearsColumnIndex];
|
||||||
|
|
||||||
|
QDateTime simulationStartDate = tableData.findFirstDate();
|
||||||
|
|
||||||
|
for (const auto& timeStepValue : ci.values)
|
||||||
{
|
{
|
||||||
QDateTime startDate = RiaQDateTimeTools::epoch();
|
QDateTime dateTime = RiaQDateTimeTools::addYears(simulationStartDate, timeStepValue);
|
||||||
|
tsVector.push_back(dateTime.toTime_t());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!tableData.startDate().empty())
|
// DATE is interpreted as date string (6-NOV-1997)
|
||||||
{
|
if (tsVector.empty() && dateColumnIndex != tableData.columnInfos().size())
|
||||||
QDateTime candidate = RiaDateStringParser::parseDateString(tableData.startDate());
|
{
|
||||||
if (candidate.isValid())
|
const ColumnInfo& ci = tableData.columnInfos()[dateColumnIndex];
|
||||||
{
|
|
||||||
startDate = candidate;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (dayOrYearColumnIndex != tableData.columnInfos().size())
|
QString dateFormat;
|
||||||
{
|
for (auto s : ci.stringValues)
|
||||||
const ColumnInfo& ci = tableData.columnInfos()[dayOrYearColumnIndex];
|
{
|
||||||
|
QDateTime dt = RiaDateStringParser::parseDateString(s);
|
||||||
|
|
||||||
QString unit = QString::fromStdString(ci.unitName).trimmed().toUpper();
|
tsVector.push_back(dt.toTime_t());
|
||||||
|
|
||||||
if (unit == "DAY" || unit == "DAYS")
|
|
||||||
{
|
|
||||||
for (const auto& timeStepValue : ci.values)
|
|
||||||
{
|
|
||||||
QDateTime dateTime = RiaQDateTimeTools::addDays(startDate, timeStepValue);
|
|
||||||
tsVector.push_back(dateTime.toTime_t());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (unit == "YEAR" || unit == "YEARS")
|
|
||||||
{
|
|
||||||
for (const auto& timeStepValue : ci.values)
|
|
||||||
{
|
|
||||||
QDateTime dateTime = RiaQDateTimeTools::addYears(startDate, timeStepValue);
|
|
||||||
tsVector.push_back(dateTime.toTime_t());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -106,14 +106,44 @@ std::vector<std::vector<std::string>> RifEclipseUserDataKeywordTools::buildColum
|
|||||||
return tableHeaderText;
|
return tableHeaderText;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
bool RifEclipseUserDataKeywordTools::isTime(const std::string& identifier)
|
||||||
|
{
|
||||||
|
return (identifier == "TIME");
|
||||||
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
///
|
///
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
bool RifEclipseUserDataKeywordTools::isDate(const std::string& identifier)
|
bool RifEclipseUserDataKeywordTools::isDate(const std::string& identifier)
|
||||||
{
|
{
|
||||||
if (identifier.find("DATE") != std::string::npos) return true;
|
return (identifier == "DATE");
|
||||||
|
}
|
||||||
|
|
||||||
return false;
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
bool RifEclipseUserDataKeywordTools::isDays(const std::string& identifier)
|
||||||
|
{
|
||||||
|
return (identifier.find("DAYS") != std::string::npos);
|
||||||
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
bool RifEclipseUserDataKeywordTools::isYears(const std::string& identifier)
|
||||||
|
{
|
||||||
|
return (identifier.find("YEARS") != std::string::npos);
|
||||||
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
bool RifEclipseUserDataKeywordTools::isYearX(const std::string& identifier)
|
||||||
|
{
|
||||||
|
return (identifier.find("YEARX") != std::string::npos);
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
@ -35,7 +35,11 @@ public:
|
|||||||
const std::vector<std::vector<std::string>>& restOfHeaderRows,
|
const std::vector<std::vector<std::string>>& restOfHeaderRows,
|
||||||
std::vector<std::string>* errorText = nullptr);
|
std::vector<std::string>* errorText = nullptr);
|
||||||
|
|
||||||
|
static bool isTime(const std::string& identifier);
|
||||||
static bool isDate(const std::string& identifier);
|
static bool isDate(const std::string& identifier);
|
||||||
|
static bool isDays(const std::string& identifier);
|
||||||
|
static bool isYears(const std::string& identifier);
|
||||||
|
static bool isYearX(const std::string& identifier);
|
||||||
|
|
||||||
static RifEclipseSummaryAddress makeAndFillAddress(const std::string quantityName, const std::vector<std::string>& columnHeaderText);
|
static RifEclipseSummaryAddress makeAndFillAddress(const std::string quantityName, const std::vector<std::string>& columnHeaderText);
|
||||||
|
|
||||||
|
@ -871,3 +871,26 @@ ColumnInfo ColumnInfo::createColumnInfo(const std::string& quantity, const std::
|
|||||||
|
|
||||||
return ci;
|
return ci;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
QDateTime TableData::findFirstDate() const
|
||||||
|
{
|
||||||
|
QDateTime dt;
|
||||||
|
|
||||||
|
for (auto ci : m_columnInfos)
|
||||||
|
{
|
||||||
|
if (RifEclipseUserDataKeywordTools::isDate(ci.summaryAddress.quantityName()))
|
||||||
|
{
|
||||||
|
if (ci.stringValues.size() > 0)
|
||||||
|
{
|
||||||
|
std::string firstDateString = ci.stringValues[0];
|
||||||
|
|
||||||
|
dt = RiaDateStringParser::parseDateString(firstDateString);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return dt;
|
||||||
|
}
|
||||||
|
@ -106,6 +106,8 @@ public:
|
|||||||
return m_columnInfos;
|
return m_columnInfos;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QDateTime findFirstDate() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::string m_origin;
|
std::string m_origin;
|
||||||
std::string m_dateFormat;
|
std::string m_dateFormat;
|
||||||
|
Loading…
Reference in New Issue
Block a user