From 3906298cb66a81ace71b74f18989f1a7a3a7341f Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Thu, 7 Feb 2013 08:35:04 +0100 Subject: [PATCH] Added support for reading more than one timestep per day. If this is detected, show hours and minutes in animation toolbar. p4#: 20399 --- .../RifEclipseOutputFileTools.cpp | 139 ++++++++++++------ .../FileInterface/RifEclipseOutputFileTools.h | 4 +- .../UserInterface/RIMainWindow.cpp | 20 ++- 3 files changed, 115 insertions(+), 48 deletions(-) diff --git a/ApplicationCode/FileInterface/RifEclipseOutputFileTools.cpp b/ApplicationCode/FileInterface/RifEclipseOutputFileTools.cpp index 58e2a9f960..a0e36cc2d7 100644 --- a/ApplicationCode/FileInterface/RifEclipseOutputFileTools.cpp +++ b/ApplicationCode/FileInterface/RifEclipseOutputFileTools.cpp @@ -24,6 +24,7 @@ #include "ecl_kw_magic.h" #include +#include #include "cafProgressInfo.h" @@ -46,74 +47,123 @@ RifEclipseOutputFileTools::~RifEclipseOutputFileTools() //-------------------------------------------------------------------------------------------------- /// Get list of time step texts (dates) //-------------------------------------------------------------------------------------------------- -bool RifEclipseOutputFileTools::timeStepsText(ecl_file_type* ecl_file, QStringList* timeSteps) +void RifEclipseOutputFileTools::timeStepsText(ecl_file_type* ecl_file, QStringList* timeSteps) { CVF_ASSERT(timeSteps); CVF_ASSERT(ecl_file); - // Get the number of occurrences of the INTEHEAD keyword - int numINTEHEAD = ecl_file_get_num_named_kw(ecl_file, INTEHEAD_KW); + QList timeStepDates; + bool hasFractionOfDays = false; + RifEclipseOutputFileTools::timeSteps(ecl_file, &timeStepDates, &hasFractionOfDays); - QStringList timeStepsFound; - int i; - for (i = 0; i < numINTEHEAD; i++) + QString formatString = "dd/MM/yyyy"; + if (hasFractionOfDays) { - ecl_kw_type* kwINTEHEAD = ecl_file_iget_named_kw(ecl_file, INTEHEAD_KW, i); - if (kwINTEHEAD) - { - // Get date info - time_t stepTime = ecl_intehead_date(kwINTEHEAD); - - // Hack!!! We seem to get 01/01/1970 (time -1) for sub grids! - if (stepTime < 0) continue; - - // Build date string - char* dateString = util_alloc_date_string(stepTime); - timeStepsFound += QString(dateString); - util_safe_free(dateString); - } + formatString += "- hh:mm"; } - // Time steps are given for both the main grid and all sub grids, - // so we need to make sure that duplicates are removed - timeStepsFound.removeDuplicates(); - - // Return time step info to caller - *timeSteps = timeStepsFound; - - return true; + for (int i = 0; i < timeStepDates.size(); i++) + { + QString timeString = timeStepDates[i].toString(formatString); + timeSteps->push_back(timeString); + } } //-------------------------------------------------------------------------------------------------- /// Get list of time step texts (dates) //-------------------------------------------------------------------------------------------------- -bool RifEclipseOutputFileTools::timeSteps(ecl_file_type* ecl_file, QList* timeSteps) +void RifEclipseOutputFileTools::timeSteps(ecl_file_type* ecl_file, QList* timeSteps, bool* detectedFractionOfDay ) { CVF_ASSERT(timeSteps); CVF_ASSERT(ecl_file); // Get the number of occurrences of the INTEHEAD keyword int numINTEHEAD = ecl_file_get_num_named_kw(ecl_file, INTEHEAD_KW); + + // Get the number of occurrences of the DOUBHEAD keyword + int numDOUBHEAD = ecl_file_get_num_named_kw(ecl_file, DOUBHEAD_KW); + + CVF_ASSERT(numINTEHEAD == numDOUBHEAD); + + bool hasFractionOfDay = false; + bool foundAllDayValues = false; + const double delta = 0.001; + + // Find all days, and stop when the double value is lower than the previous + QList days; + for (int i = 0; i < numDOUBHEAD; i++) + { + if (foundAllDayValues) continue;; + + ecl_kw_type* kwDOUBHEAD = ecl_file_iget_named_kw(ecl_file, DOUBHEAD_KW, i); + if (kwDOUBHEAD) + { + double dayValue = ecl_kw_iget_double(kwDOUBHEAD, DOUBHEAD_DAYS_INDEX); + qDebug() << dayValue; + + double floorDayValue = cvf::Math::floor(dayValue); + + if (dayValue - floorDayValue > delta) + { + hasFractionOfDay = true; + } + + days.push_back(dayValue); + } + } QList timeStepsFound; - int i; - for (i = 0; i < numINTEHEAD; i++) + + if (hasFractionOfDay) { - ecl_kw_type* kwINTEHEAD = ecl_file_iget_named_kw(ecl_file, INTEHEAD_KW, i); + ecl_kw_type* kwINTEHEAD = ecl_file_iget_named_kw(ecl_file, INTEHEAD_KW, 0); if (kwINTEHEAD) { - // Get date info - time_t stepTime = ecl_intehead_date(kwINTEHEAD); + int day = ecl_kw_iget_int(kwINTEHEAD, INTEHEAD_DAY_INDEX); + int month = ecl_kw_iget_int(kwINTEHEAD, INTEHEAD_MONTH_INDEX); + int year = ecl_kw_iget_int(kwINTEHEAD, INTEHEAD_YEAR_INDEX); + QDate simulationStart(year, month, day); - // Hack!!! We seem to get 01/01/1970 (time -1) for sub grids! - if (stepTime < 0) continue; - - // Build date string - QDateTime dateTime = QDateTime::fromTime_t(stepTime); - - if (timeStepsFound.indexOf(dateTime) < 0) + for (int i = 0; i < days.size(); i++) { - timeStepsFound.push_back(dateTime); + double dayValue = days[i]; + double floorDayValue = cvf::Math::floor(dayValue); + double dayFraction = dayValue - floorDayValue; + + int seconds = (dayFraction * 24.0 * 60.0 * 60.0); + QTime time(0, 0); + time = time.addSecs(seconds); + + QDate reportDate = simulationStart; + reportDate = reportDate.addDays(floorDayValue); + + QDateTime reportDateTime(reportDate, time); + if (timeStepsFound.indexOf(reportDateTime) < 0) + { + timeStepsFound.push_back(reportDateTime); + } + } + } + } + else + { + for (int i = 0; i < numINTEHEAD; i++) + { + ecl_kw_type* kwINTEHEAD = ecl_file_iget_named_kw(ecl_file, INTEHEAD_KW, i); + if (kwINTEHEAD) + { + int day = ecl_kw_iget_int(kwINTEHEAD, INTEHEAD_DAY_INDEX); + int month = ecl_kw_iget_int(kwINTEHEAD, INTEHEAD_MONTH_INDEX); + int year = ecl_kw_iget_int(kwINTEHEAD, INTEHEAD_YEAR_INDEX); + + QDate reportDate(year, month, day); + CVF_ASSERT(reportDate.isValid()); + + QDateTime reportDateTime(reportDate); + if (timeStepsFound.indexOf(reportDateTime) < 0) + { + timeStepsFound.push_back(reportDateTime); + } } } } @@ -121,7 +171,10 @@ bool RifEclipseOutputFileTools::timeSteps(ecl_file_type* ecl_file, QList* keywordDataItemCounts); static bool keywordData(ecl_file_type* ecl_file, const QString& keyword, size_t fileKeywordOccurrence, std::vector* values); - static bool timeStepsText(ecl_file_type* ecl_file, QStringList* timeSteps); - static bool timeSteps(ecl_file_type* ecl_file, QList* timeSteps); + static void timeStepsText(ecl_file_type* ecl_file, QStringList* timeSteps); + static void timeSteps(ecl_file_type* ecl_file, QList* timeSteps, bool* detectedFractionOfDay = NULL); static bool fileSet(const QString& fileName, QStringList* fileSet); diff --git a/ApplicationCode/UserInterface/RIMainWindow.cpp b/ApplicationCode/UserInterface/RIMainWindow.cpp index 3be53cf49b..594b507b12 100644 --- a/ApplicationCode/UserInterface/RIMainWindow.cpp +++ b/ApplicationCode/UserInterface/RIMainWindow.cpp @@ -541,10 +541,24 @@ void RIMainWindow::refreshAnimationActions() || app->activeReservoirView()->wellCollection()->hasVisibleWellPipes()) { QList timeStepDates = app->activeReservoirView()->gridCellResults()->timeStepDates(0); - int i; - for (i = 0; i < timeStepDates.size(); i++) + bool showHoursAndMinutes = false; + for (int i = 0; i < timeStepDates.size(); i++) { - timeStepStrings += timeStepDates[i].toString("dd.MMM yyyy"); + if (timeStepDates[i].time().hour() != 0.0 || timeStepDates[i].time().minute() != 0.0) + { + showHoursAndMinutes = true; + } + } + + QString formatString = "dd.MMM yyyy"; + if (showHoursAndMinutes) + { + formatString += " - hh:mm"; + } + + for (int i = 0; i < timeStepDates.size(); i++) + { + timeStepStrings += timeStepDates[i].toString(formatString); } currentTimeStepIndex = RIApplication::instance()->activeReservoirView()->currentTimeStep(); }