Exemplo n.º 1
0
//--------------------------------------------------------------------------------------------------
/// 
//--------------------------------------------------------------------------------------------------
void RifEclipseOutputFileTools::createReportStepsMetaData(std::vector<ecl_file_type*> ecl_files, std::vector<RifRestartReportStep>* reportSteps)
{
    if (!reportSteps) return;

    for (auto ecl_file : ecl_files)
    {
        if (!ecl_file) continue;

        int reportStepCount = ecl_file_get_num_named_kw(ecl_file, INTEHEAD_KW);
        for (int reportStepIndex = 0; reportStepIndex < reportStepCount; reportStepIndex++)
        {
            ecl_file_view_type* rst_view = ecl_file_get_global_view(ecl_file);
            if (!rst_view) continue;

            ecl_rsthead_type* restart_header = ecl_rsthead_alloc(rst_view, reportStepIndex);
            if (restart_header)
            {
                ecl_file_push_block(ecl_file);

                {
                    ecl_file_select_block(ecl_file, INTEHEAD_KW, reportStepIndex);

                    RifRestartReportStep reportStep;

                    // Set Date
                    {
                        QDateTime reportDateTime(QDate(restart_header->year, restart_header->month, restart_header->day));
                        reportStep.dateTime = reportDateTime;
                    }

                    // Find number of keywords withing this report step
                    int numKeywords = ecl_file_get_num_distinct_kw(ecl_file);
                    for (int iKey = 0; iKey < numKeywords; iKey++)
                    {
                        const char* kw = ecl_file_iget_distinct_kw(ecl_file, iKey);

                        int namedKeywordCount = ecl_file_get_num_named_kw(ecl_file, kw);
                        for (int iOcc = 0; iOcc < namedKeywordCount; iOcc++)
                        {
                            ecl_data_type dataType = ecl_file_iget_named_data_type(ecl_file, kw, iOcc);
                            ecl_type_enum dataTypeEmum = ecl_type_get_type(dataType);
                            if (dataTypeEmum != ECL_DOUBLE_TYPE && dataTypeEmum != ECL_FLOAT_TYPE && dataTypeEmum != ECL_INT_TYPE)
                            {
                                continue;
                            }

                            int itemCount = ecl_file_iget_named_size(ecl_file, kw, iOcc);
                            reportStep.m_keywords.appendKeyword(kw, itemCount, iOcc);
                        }
                    }

                    reportSteps->push_back(reportStep);
                }

                ecl_file_pop_block(ecl_file);

                ecl_rsthead_free(restart_header);
            }
        }
    }
}
//--------------------------------------------------------------------------------------------------
/// 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;
    }
}