///////////////////////////////////////////////////////////////////////////////// // // Copyright (C) 2011- Statoil ASA // Copyright (C) 2013- Ceetron Solutions AS // Copyright (C) 2011-2012 Ceetron AS // // ResInsight is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY // WARRANTY; without even the implied warranty of MERCHANTABILITY or // FITNESS FOR A PARTICULAR PURPOSE. // // See the GNU General Public License at // for more details. // ///////////////////////////////////////////////////////////////////////////////// #include "RifEclipseUnifiedRestartFileAccess.h" #include "RifEclipseOutputFileTools.h" #include #include #include #include //-------------------------------------------------------------------------------------------------- /// Constructor //-------------------------------------------------------------------------------------------------- RifEclipseUnifiedRestartFileAccess::RifEclipseUnifiedRestartFileAccess() : RifEclipseRestartDataAccess() { m_ecl_file = NULL; } //-------------------------------------------------------------------------------------------------- /// Destructor //-------------------------------------------------------------------------------------------------- RifEclipseUnifiedRestartFileAccess::~RifEclipseUnifiedRestartFileAccess() { if (m_ecl_file) { ecl_file_close(m_ecl_file); } } //-------------------------------------------------------------------------------------------------- /// Open file //-------------------------------------------------------------------------------------------------- bool RifEclipseUnifiedRestartFileAccess::open() { return true; } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- bool RifEclipseUnifiedRestartFileAccess::openFile() { if (!m_ecl_file) { m_ecl_file = ecl_file_open(m_filename.toAscii().data(), ECL_FILE_CLOSE_STREAM); } if (!m_ecl_file) return false; return true; } //-------------------------------------------------------------------------------------------------- /// Close file //-------------------------------------------------------------------------------------------------- void RifEclipseUnifiedRestartFileAccess::close() { } //-------------------------------------------------------------------------------------------------- /// Get the number of time steps //-------------------------------------------------------------------------------------------------- size_t RifEclipseUnifiedRestartFileAccess::timeStepCount() { if (!openFile()) { return 0; } return timeSteps().size(); } //-------------------------------------------------------------------------------------------------- /// Get the time steps //-------------------------------------------------------------------------------------------------- std::vector RifEclipseUnifiedRestartFileAccess::timeSteps() { std::vector timeSteps; if (openFile()) { RifEclipseOutputFileTools::timeSteps(m_ecl_file, &timeSteps); } return timeSteps; } //-------------------------------------------------------------------------------------------------- /// Get list of result names //-------------------------------------------------------------------------------------------------- void RifEclipseUnifiedRestartFileAccess::resultNames(QStringList* resultNames, std::vector* resultDataItemCounts) { if (openFile()) { RifEclipseOutputFileTools::findKeywordsAndDataItemCounts(m_ecl_file, resultNames, resultDataItemCounts); } } //-------------------------------------------------------------------------------------------------- /// Get result values for given time step //-------------------------------------------------------------------------------------------------- bool RifEclipseUnifiedRestartFileAccess::results(const QString& resultName, size_t timeStep, size_t gridCount, std::vector* values) { if (!openFile()) { return false; } size_t numOccurrences = ecl_file_get_num_named_kw(m_ecl_file, resultName.toAscii().data()); size_t startIndex = timeStep * gridCount; CVF_ASSERT(startIndex + gridCount <= numOccurrences); size_t occurrenceIdx; for (occurrenceIdx = startIndex; occurrenceIdx < startIndex + gridCount; occurrenceIdx++) { std::vector partValues; RifEclipseOutputFileTools::keywordData(m_ecl_file, resultName, occurrenceIdx, &partValues); values->insert(values->end(), partValues.begin(), partValues.end()); } return true; } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- void RifEclipseUnifiedRestartFileAccess::readWellData(well_info_type* well_info) { if (!well_info) return; if (openFile()) { well_info_add_UNRST_wells(well_info, m_ecl_file); } } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- void RifEclipseUnifiedRestartFileAccess::setRestartFiles(const QStringList& fileSet) { m_filename = fileSet[0]; } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- int RifEclipseUnifiedRestartFileAccess::readUnitsType() { openFile(); return RifEclipseOutputFileTools::readUnitsType(m_ecl_file); }