Beispiel #1
0
void SimPlot::startStop()
{
    if (mThread == 0)
    {
        mWidgetTab->simStarted();
        mWidgetToolbar->simStarted();
        simulationStart();
    }
    else
    {
        if (mSimThread)
        {
            if (mSimThread->isPaused())
            {
                mSimThread->setPause(false);
                mWidgetTab->simStarted();
                mWidgetToolbar->simStarted();
            }
            else
            {
                mSimThread->setPause(true);
                mWidgetTab->simPaused();
                mWidgetToolbar->simPaused();
            }
        }
    }
}
//--------------------------------------------------------------------------------------------------
/// Get list of time step texts (dates)
//--------------------------------------------------------------------------------------------------
void RifEclipseOutputFileTools::timeSteps(ecl_file_type* ecl_file, std::vector<QDateTime>* 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<double> 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);
            double floorDayValue = cvf::Math::floor(dayValue);

            if (dayValue - floorDayValue > delta)
            {
                hasFractionOfDay = true;
            }

            days.push_back(dayValue);
        }
    }

    std::vector<QDateTime> timeStepsFound;

    if (hasFractionOfDay)
    {
        ecl_kw_type* kwINTEHEAD = ecl_file_iget_named_kw(ecl_file, INTEHEAD_KW, 0);
        if (kwINTEHEAD)
        {
            int day = 0;
            int month = 0;
            int year = 0;
            getDayMonthYear(kwINTEHEAD, &day, &month, &year);

            QDateTime simulationStart(QDate(year, month, day));
            for (int i = 0; i < days.size(); i++)
            {
                QDateTime reportDateTime(simulationStart);
                CVF_ASSERT(reportDateTime.isValid());

                double dayValue = days[i];
                double floorDayValue = cvf::Math::floor(dayValue);
                reportDateTime = reportDateTime.addDays(static_cast<int>(floorDayValue));

                double dayFraction = dayValue - floorDayValue;
                int seconds = static_cast<int>(dayFraction * 24.0 * 60.0 * 60.0);
                QTime time(0, 0);
                time = time.addSecs(seconds);

                reportDateTime.setTime(time);

                if (std::find(timeStepsFound.begin(), timeStepsFound.end(), reportDateTime) ==  timeStepsFound.end())
                {
                    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 = 0;
                int month = 0;
                int year = 0;
                getDayMonthYear(kwINTEHEAD, &day, &month, &year);

                QDateTime reportDateTime(QDate(year, month, day));
                QTime time(0, 0);
                reportDateTime.setTime(time);

                CVF_ASSERT(reportDateTime.isValid());

                if (std::find(timeStepsFound.begin(), timeStepsFound.end(), reportDateTime) ==  timeStepsFound.end())
                {
                    timeStepsFound.push_back(reportDateTime);
                }
            }
        }
    }

    // Return time step info to caller
    *timeSteps = timeStepsFound;

    if (detectedFractionOfDay)
    {
        *detectedFractionOfDay = hasFractionOfDay;
    }
}