2016-04-12 04:32:28 -05:00
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// Copyright (C) Statoil ASA
|
2019-09-06 03:40:57 -05:00
|
|
|
//
|
2016-04-12 04:32:28 -05:00
|
|
|
// 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.
|
2019-09-06 03:40:57 -05:00
|
|
|
//
|
2016-04-12 04:32:28 -05:00
|
|
|
// 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.
|
2019-09-06 03:40:57 -05:00
|
|
|
//
|
|
|
|
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
|
2016-04-12 04:32:28 -05:00
|
|
|
// for more details.
|
|
|
|
//
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#include "RifEclipseSummaryTools.h"
|
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
#include "RiaFilePathTools.h"
|
|
|
|
#include "RiaStringEncodingTools.h"
|
2021-04-27 02:28:23 -05:00
|
|
|
#include "RifSummaryReaderInterface.h"
|
2024-10-21 07:40:25 -05:00
|
|
|
#include "Summary/RiaSummaryAddressAnalyzer.h"
|
2016-04-12 04:32:28 -05:00
|
|
|
|
2016-06-09 03:55:48 -05:00
|
|
|
#include "cafAppEnum.h"
|
2016-04-12 04:32:28 -05:00
|
|
|
|
2021-04-27 08:08:48 -05:00
|
|
|
#include "ert/ecl/ecl_file.h"
|
|
|
|
#include "ert/ecl/ecl_kw.h"
|
|
|
|
#include "ert/ecl/ecl_kw_magic.h"
|
|
|
|
#include "ert/ecl/ecl_sum.h"
|
2017-11-24 08:17:20 -06:00
|
|
|
#include "ert/ecl/ecl_util.h"
|
2021-04-27 08:08:48 -05:00
|
|
|
#include "ert/ecl/smspec_node.hpp"
|
2016-04-12 04:32:28 -05:00
|
|
|
|
2024-11-14 04:55:02 -06:00
|
|
|
#include "opm/io/eclipse/EclFile.hpp"
|
|
|
|
|
2021-04-27 08:08:48 -05:00
|
|
|
#include <QDateTime>
|
2018-04-13 04:11:05 -05:00
|
|
|
#include <QDir>
|
2018-02-02 07:17:10 -06:00
|
|
|
#include <QString>
|
|
|
|
#include <QStringList>
|
|
|
|
|
2021-04-28 02:23:43 -05:00
|
|
|
#include <cassert>
|
2017-11-24 08:17:20 -06:00
|
|
|
#include <iostream>
|
2016-04-12 04:32:28 -05:00
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
///
|
2016-04-12 04:32:28 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
void RifEclipseSummaryTools::findSummaryHeaderFile( const QString& inputFile, QString* headerFile, bool* isFormatted )
|
2016-04-12 04:32:28 -05:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
findSummaryHeaderFileInfo( inputFile, headerFile, nullptr, nullptr, isFormatted );
|
2016-04-12 04:32:28 -05:00
|
|
|
}
|
|
|
|
|
2016-05-31 06:42:27 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
///
|
2016-05-31 06:42:27 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
void RifEclipseSummaryTools::findSummaryFiles( const QString& inputFile, QString* headerFile, QStringList* dataFiles )
|
2016-05-31 06:42:27 -05:00
|
|
|
{
|
|
|
|
dataFiles->clear();
|
|
|
|
headerFile->clear();
|
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
char* myPath = nullptr;
|
|
|
|
char* myBase = nullptr;
|
2020-06-03 15:31:58 -05:00
|
|
|
char* myExtension = nullptr;
|
2016-05-31 06:42:27 -05:00
|
|
|
|
2020-06-03 15:31:58 -05:00
|
|
|
util_alloc_file_components( RiaStringEncodingTools::toNativeEncoded( inputFile ).data(), &myPath, &myBase, &myExtension );
|
2016-05-31 06:42:27 -05:00
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
QString path;
|
|
|
|
if ( myPath ) path = RiaStringEncodingTools::fromNativeEncoded( myPath );
|
|
|
|
QString base;
|
|
|
|
if ( myBase ) base = RiaStringEncodingTools::fromNativeEncoded( myBase );
|
2020-06-03 15:31:58 -05:00
|
|
|
std::string extension;
|
|
|
|
if ( myExtension ) extension = myExtension;
|
2016-05-31 06:42:27 -05:00
|
|
|
|
2020-06-03 15:31:58 -05:00
|
|
|
free( myExtension );
|
2019-11-21 00:10:07 -06:00
|
|
|
free( myBase );
|
|
|
|
free( myPath );
|
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( path.isEmpty() || base.isEmpty() ) return;
|
2016-05-31 06:42:27 -05:00
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
char* myHeaderFile = nullptr;
|
2016-05-31 06:42:27 -05:00
|
|
|
stringlist_type* summary_file_list = stringlist_alloc_new();
|
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
ecl_util_alloc_summary_files( RiaStringEncodingTools::toNativeEncoded( path ).data(),
|
|
|
|
RiaStringEncodingTools::toNativeEncoded( base ).data(),
|
2020-06-03 15:31:58 -05:00
|
|
|
extension.data(),
|
2019-09-06 03:40:57 -05:00
|
|
|
&myHeaderFile,
|
|
|
|
summary_file_list );
|
|
|
|
if ( myHeaderFile )
|
2016-06-29 03:43:36 -05:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
( *headerFile ) = RiaStringEncodingTools::fromNativeEncoded( myHeaderFile );
|
|
|
|
free( myHeaderFile );
|
2016-06-29 03:43:36 -05:00
|
|
|
}
|
2016-05-31 06:42:27 -05:00
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( stringlist_get_size( summary_file_list ) > 0 )
|
2016-05-31 06:42:27 -05:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
for ( int i = 0; i < stringlist_get_size( summary_file_list ); i++ )
|
2016-05-31 06:42:27 -05:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
dataFiles->push_back( RiaStringEncodingTools::fromNativeEncoded( stringlist_iget( summary_file_list, i ) ) );
|
2016-05-31 06:42:27 -05:00
|
|
|
}
|
|
|
|
}
|
2019-09-06 03:40:57 -05:00
|
|
|
stringlist_free( summary_file_list );
|
2016-05-31 06:42:27 -05:00
|
|
|
}
|
|
|
|
|
2018-04-13 04:11:05 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
///
|
2018-04-13 04:11:05 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
QString RifEclipseSummaryTools::findGridCaseFileFromSummaryHeaderFile( const QString& summaryHeaderFile )
|
2018-04-13 04:11:05 -05:00
|
|
|
{
|
|
|
|
char* myPath = nullptr;
|
|
|
|
char* myBase = nullptr;
|
|
|
|
|
2020-02-12 04:43:15 -06:00
|
|
|
util_alloc_file_components( RiaStringEncodingTools::toNativeEncoded( QDir::toNativeSeparators( summaryHeaderFile ) ).data(),
|
2019-09-06 03:40:57 -05:00
|
|
|
&myPath,
|
|
|
|
&myBase,
|
|
|
|
nullptr );
|
2018-04-13 04:11:05 -05:00
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
char* caseFile = ecl_util_alloc_exfilename( myPath, myBase, ECL_EGRID_FILE, true, -1 );
|
|
|
|
if ( !caseFile )
|
2018-04-13 04:11:05 -05:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
caseFile = ecl_util_alloc_exfilename( myPath, myBase, ECL_EGRID_FILE, false, -1 );
|
2018-04-13 04:11:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
QString gridCaseFile;
|
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( caseFile ) gridCaseFile = caseFile;
|
2018-04-13 04:11:05 -05:00
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
free( caseFile );
|
|
|
|
free( myBase );
|
|
|
|
free( myPath );
|
2018-04-13 04:11:05 -05:00
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
return RiaFilePathTools::toInternalSeparator( gridCaseFile );
|
2018-04-13 04:11:05 -05:00
|
|
|
}
|
|
|
|
|
2016-04-12 04:32:28 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
///
|
2016-04-12 04:32:28 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
void RifEclipseSummaryTools::dumpMetaData( RifSummaryReaderInterface* readerEclipseSummary )
|
2016-04-12 04:32:28 -05:00
|
|
|
{
|
2023-08-21 00:12:08 -05:00
|
|
|
const auto addresses = readerEclipseSummary->allResultAddresses();
|
2016-04-12 04:32:28 -05:00
|
|
|
|
2023-08-21 00:12:08 -05:00
|
|
|
for ( const auto& catAddresse : addresses )
|
2016-04-12 04:32:28 -05:00
|
|
|
{
|
2023-08-21 00:12:08 -05:00
|
|
|
std::cout << catAddresse.vectorName() << " " << catAddresse.regionNumber() << " " << catAddresse.regionNumber2() << " "
|
|
|
|
<< catAddresse.groupName() << " " << catAddresse.wellName() << " " << catAddresse.wellSegmentNumber() << " "
|
|
|
|
<< catAddresse.lgrName() << " " << catAddresse.cellI() << " " << catAddresse.cellJ() << " " << catAddresse.cellK()
|
|
|
|
<< std::endl;
|
2016-04-12 04:32:28 -05:00
|
|
|
}
|
2023-08-21 00:12:08 -05:00
|
|
|
|
|
|
|
std::cout << std::endl;
|
2016-04-12 04:32:28 -05:00
|
|
|
}
|
|
|
|
|
2021-04-27 08:08:48 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2024-11-14 04:55:02 -06:00
|
|
|
std::vector<QString> RifEclipseSummaryTools::getRestartFileNames( const QString& headerFileName, std::vector<QString>& warnings )
|
2021-04-27 08:08:48 -05:00
|
|
|
{
|
2024-11-14 04:55:02 -06:00
|
|
|
return getRestartFileNames( headerFileName, false, warnings );
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
std::vector<QString>
|
|
|
|
RifEclipseSummaryTools::getRestartFileNames( const QString& headerFileName, bool useOpmReader, std::vector<QString>& warnings )
|
|
|
|
{
|
|
|
|
std::vector<QString> restartFiles;
|
2021-04-27 08:08:48 -05:00
|
|
|
|
|
|
|
std::set<QString> restartFilesOpened;
|
|
|
|
|
2024-11-14 04:55:02 -06:00
|
|
|
QString currentFileName = headerFileName;
|
|
|
|
while ( !currentFileName.isEmpty() )
|
2021-04-27 08:08:48 -05:00
|
|
|
{
|
2024-04-22 12:56:10 -05:00
|
|
|
// Due to a weakness in resdata regarding restart summary header file selection,
|
2021-04-27 08:08:48 -05:00
|
|
|
// do some extra checking
|
|
|
|
{
|
|
|
|
QString formattedHeaderExtension = ".FSMSPEC";
|
|
|
|
QString nonformattedHeaderExtension = ".SMSPEC";
|
|
|
|
QString formattedDataFileExtension = ".FUNSMRY";
|
|
|
|
|
2024-11-14 04:55:02 -06:00
|
|
|
if ( currentFileName.endsWith( nonformattedHeaderExtension, Qt::CaseInsensitive ) )
|
2021-04-27 08:08:48 -05:00
|
|
|
{
|
2024-11-14 04:55:02 -06:00
|
|
|
QString formattedHeaderFile = currentFileName;
|
2021-04-27 08:08:48 -05:00
|
|
|
formattedHeaderFile.replace( nonformattedHeaderExtension, formattedHeaderExtension, Qt::CaseInsensitive );
|
2024-11-14 04:55:02 -06:00
|
|
|
QString formattedDateFile = currentFileName;
|
2021-04-27 08:08:48 -05:00
|
|
|
formattedDateFile.replace( nonformattedHeaderExtension, formattedDataFileExtension, Qt::CaseInsensitive );
|
|
|
|
|
2024-11-14 04:55:02 -06:00
|
|
|
QFileInfo nonformattedHeaderFileInfo = QFileInfo( currentFileName );
|
2021-04-27 08:08:48 -05:00
|
|
|
QFileInfo formattedHeaderFileInfo = QFileInfo( formattedHeaderFile );
|
|
|
|
QFileInfo formattedDateFileInfo = QFileInfo( formattedDateFile );
|
|
|
|
if ( formattedHeaderFileInfo.lastModified() < nonformattedHeaderFileInfo.lastModified() &&
|
|
|
|
formattedHeaderFileInfo.exists() && !formattedDateFileInfo.exists() )
|
|
|
|
{
|
2023-02-26 03:48:40 -06:00
|
|
|
warnings.push_back( QString( "RifReaderEclipseSummary: Formatted summary header file without an\n" ) +
|
|
|
|
QString( "associated data file detected.\n" ) +
|
|
|
|
QString( "This may cause a failure reading summary origin data.\n" ) +
|
|
|
|
QString( "To avoid this problem, please delete or rename the.FSMSPEC file." ) );
|
2021-04-27 08:08:48 -05:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2024-11-14 04:55:02 -06:00
|
|
|
QString prevFileName = currentFileName;
|
|
|
|
|
|
|
|
if ( useOpmReader )
|
|
|
|
{
|
|
|
|
currentFileName = getRestartFileNameOpm( currentFileName );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
currentFileName = getRestartFileName( currentFileName );
|
|
|
|
}
|
2021-04-27 08:08:48 -05:00
|
|
|
|
|
|
|
// Fix to stop potential infinite loop
|
2024-11-14 04:55:02 -06:00
|
|
|
if ( currentFileName == prevFileName )
|
2021-04-27 08:08:48 -05:00
|
|
|
{
|
|
|
|
warnings.push_back( "RifReaderEclipseSummary: Restart file reference loop detected" );
|
|
|
|
break;
|
|
|
|
}
|
2024-11-14 04:55:02 -06:00
|
|
|
if ( restartFilesOpened.count( currentFileName ) != 0u )
|
2021-04-27 08:08:48 -05:00
|
|
|
{
|
|
|
|
warnings.push_back( "RifReaderEclipseSummary: Same restart file being opened multiple times" );
|
|
|
|
}
|
2024-11-14 04:55:02 -06:00
|
|
|
restartFilesOpened.insert( currentFileName );
|
2021-04-27 08:08:48 -05:00
|
|
|
}
|
|
|
|
|
2024-11-14 04:55:02 -06:00
|
|
|
if ( !currentFileName.isEmpty() ) restartFiles.push_back( currentFileName );
|
2021-04-27 08:08:48 -05:00
|
|
|
}
|
|
|
|
return restartFiles;
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2024-11-14 04:55:02 -06:00
|
|
|
RifRestartFileInfo RifEclipseSummaryTools::getFileInfoAndTimeSteps( const QString& headerFileName )
|
2021-04-27 08:08:48 -05:00
|
|
|
{
|
|
|
|
RifRestartFileInfo fileInfo;
|
|
|
|
ecl_sum_type* ecl_sum = openEclSum( headerFileName, false );
|
|
|
|
std::vector<time_t> timeSteps = getTimeSteps( ecl_sum );
|
|
|
|
if ( !timeSteps.empty() )
|
|
|
|
{
|
|
|
|
fileInfo.fileName = headerFileName;
|
|
|
|
fileInfo.startDate = timeSteps.front();
|
|
|
|
fileInfo.endDate = timeSteps.back();
|
|
|
|
}
|
|
|
|
closeEclSum( ecl_sum );
|
|
|
|
|
|
|
|
return fileInfo;
|
|
|
|
}
|
|
|
|
|
2024-11-14 04:55:02 -06:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
std::vector<QString> RifEclipseSummaryTools::getRestartFileNamesOpm( const QString& headerFileName, std::vector<QString>& warnings )
|
|
|
|
{
|
|
|
|
return getRestartFileNames( headerFileName, true, warnings );
|
|
|
|
}
|
|
|
|
|
2016-04-12 04:32:28 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
///
|
2016-04-12 04:32:28 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2023-02-26 03:48:40 -06:00
|
|
|
void RifEclipseSummaryTools::findSummaryHeaderFileInfo( const QString& inputFile, QString* headerFile, QString* path, QString* base, bool* isFormatted )
|
2016-04-12 04:32:28 -05:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
char* myPath = nullptr;
|
|
|
|
char* myBase = nullptr;
|
|
|
|
bool formattedFile = true;
|
2016-04-12 04:32:28 -05:00
|
|
|
|
2023-02-26 03:48:40 -06:00
|
|
|
util_alloc_file_components( RiaStringEncodingTools::toNativeEncoded( QDir::toNativeSeparators( inputFile ) ).data(), &myPath, &myBase, nullptr );
|
2016-04-12 04:32:28 -05:00
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
char* myHeaderFile = ecl_util_alloc_exfilename( myPath, myBase, ECL_SUMMARY_HEADER_FILE, true, -1 );
|
|
|
|
if ( !myHeaderFile )
|
2016-04-12 04:32:28 -05:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
myHeaderFile = ecl_util_alloc_exfilename( myPath, myBase, ECL_SUMMARY_HEADER_FILE, false, -1 );
|
|
|
|
if ( myHeaderFile )
|
2016-04-12 04:32:28 -05:00
|
|
|
{
|
|
|
|
formattedFile = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( myHeaderFile && headerFile ) *headerFile = RiaFilePathTools::toInternalSeparator( myHeaderFile );
|
|
|
|
if ( myPath && path ) *path = RiaFilePathTools::toInternalSeparator( myPath );
|
|
|
|
if ( myBase && base ) *base = RiaFilePathTools::toInternalSeparator( myBase );
|
|
|
|
if ( isFormatted ) *isFormatted = formattedFile;
|
2016-04-12 04:32:28 -05:00
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
free( myHeaderFile );
|
|
|
|
free( myBase );
|
|
|
|
free( myPath );
|
2016-04-12 04:32:28 -05:00
|
|
|
}
|
2021-04-27 08:08:48 -05:00
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2024-11-14 04:55:02 -06:00
|
|
|
QString RifEclipseSummaryTools::getRestartFileName( const QString& headerFileName )
|
2021-04-27 08:08:48 -05:00
|
|
|
{
|
|
|
|
ecl_sum_type* ecl_sum = openEclSum( headerFileName, true );
|
|
|
|
|
|
|
|
const ecl_smspec_type* smspec = ecl_sum ? ecl_sum_get_smspec( ecl_sum ) : nullptr;
|
|
|
|
const char* rstCase = smspec ? ecl_smspec_get_restart_case( smspec ) : nullptr;
|
2023-02-26 03:48:40 -06:00
|
|
|
QString restartCase = rstCase ? RiaFilePathTools::canonicalPath( RiaStringEncodingTools::fromNativeEncoded( rstCase ) ) : "";
|
2021-04-27 08:08:48 -05:00
|
|
|
closeEclSum( ecl_sum );
|
|
|
|
|
|
|
|
if ( !restartCase.isEmpty() )
|
|
|
|
{
|
|
|
|
QString path = QFileInfo( restartCase ).dir().path();
|
|
|
|
QString restartBase = QDir( restartCase ).dirName();
|
|
|
|
|
2023-02-26 03:48:40 -06:00
|
|
|
char* smspec_header = ecl_util_alloc_exfilename( path.toStdString().data(),
|
2021-04-27 08:08:48 -05:00
|
|
|
restartBase.toStdString().data(),
|
|
|
|
ECL_SUMMARY_HEADER_FILE,
|
|
|
|
false /*unformatted*/,
|
|
|
|
0 );
|
2023-02-26 03:48:40 -06:00
|
|
|
QString restartFileName = RiaFilePathTools::toInternalSeparator( RiaStringEncodingTools::fromNativeEncoded( smspec_header ) );
|
2021-04-27 08:08:48 -05:00
|
|
|
free( smspec_header );
|
|
|
|
|
2024-11-14 04:55:02 -06:00
|
|
|
return restartFileName;
|
|
|
|
}
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
QString RifEclipseSummaryTools::getRestartFileNameOpm( const QString& headerFileName )
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
Opm::EclIO::EclFile eclFile( headerFileName.toStdString() );
|
|
|
|
eclFile.loadData( "RESTART" );
|
|
|
|
|
|
|
|
std::string fullRestartFileName;
|
|
|
|
|
|
|
|
auto restartData = eclFile.get<std::string>( "RESTART" );
|
|
|
|
for ( const auto& string : restartData )
|
|
|
|
{
|
|
|
|
fullRestartFileName += string;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( fullRestartFileName.empty() ) return {};
|
|
|
|
|
|
|
|
QFileInfo sourceFileInfo( headerFileName );
|
|
|
|
QString suffix = sourceFileInfo.suffix();
|
|
|
|
|
|
|
|
QString filePath = sourceFileInfo.absolutePath() + RiaFilePathTools::separator() + QString::fromStdString( fullRestartFileName ) +
|
|
|
|
"." + suffix;
|
|
|
|
|
|
|
|
QFileInfo restartFileInfo( filePath );
|
|
|
|
QString restartFileName = RiaFilePathTools::toInternalSeparator( restartFileInfo.absoluteFilePath() );
|
|
|
|
|
|
|
|
return restartFileName;
|
|
|
|
}
|
|
|
|
catch ( ... )
|
|
|
|
{
|
2021-04-27 08:08:48 -05:00
|
|
|
}
|
2024-11-14 04:55:02 -06:00
|
|
|
|
|
|
|
return {};
|
2021-04-27 08:08:48 -05:00
|
|
|
}
|
|
|
|
|
2024-11-14 04:55:02 -06:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2021-04-27 08:08:48 -05:00
|
|
|
std::vector<time_t> RifEclipseSummaryTools::getTimeSteps( ecl_sum_type* ecl_sum )
|
|
|
|
{
|
|
|
|
std::vector<time_t> timeSteps;
|
|
|
|
|
|
|
|
if ( ecl_sum )
|
|
|
|
{
|
|
|
|
time_t_vector_type* steps = ecl_sum_alloc_time_vector( ecl_sum, false );
|
|
|
|
|
|
|
|
if ( steps )
|
|
|
|
{
|
|
|
|
for ( int i = 0; i < time_t_vector_size( steps ); i++ )
|
|
|
|
{
|
|
|
|
timeSteps.push_back( time_t_vector_iget( steps, i ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
time_t_vector_free( steps );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return timeSteps;
|
|
|
|
}
|
|
|
|
|
2024-11-14 04:55:02 -06:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2021-04-27 08:08:48 -05:00
|
|
|
RiaDefines::EclipseUnitSystem RifEclipseSummaryTools::readUnitSystem( ecl_sum_type* ecl_sum )
|
|
|
|
{
|
|
|
|
ert_ecl_unit_enum eclUnitEnum = ecl_sum_get_unit_system( ecl_sum );
|
|
|
|
switch ( eclUnitEnum )
|
|
|
|
{
|
|
|
|
case ECL_METRIC_UNITS:
|
|
|
|
return RiaDefines::EclipseUnitSystem::UNITS_METRIC;
|
|
|
|
case ECL_FIELD_UNITS:
|
|
|
|
return RiaDefines::EclipseUnitSystem::UNITS_FIELD;
|
|
|
|
case ECL_LAB_UNITS:
|
|
|
|
return RiaDefines::EclipseUnitSystem::UNITS_LAB;
|
|
|
|
default:
|
|
|
|
return RiaDefines::EclipseUnitSystem::UNITS_UNKNOWN;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
ecl_sum_type* RifEclipseSummaryTools::openEclSum( const QString& inHeaderFileName, bool includeRestartFiles )
|
|
|
|
{
|
|
|
|
QString headerFileName;
|
|
|
|
QStringList dataFileNames;
|
|
|
|
QString nativeHeaderFileName = QDir::toNativeSeparators( inHeaderFileName );
|
|
|
|
RifEclipseSummaryTools::findSummaryFiles( nativeHeaderFileName, &headerFileName, &dataFileNames );
|
|
|
|
|
|
|
|
if ( headerFileName.isEmpty() || dataFileNames.isEmpty() ) return nullptr;
|
|
|
|
|
|
|
|
stringlist_type* dataFiles = stringlist_alloc_new();
|
|
|
|
for ( int i = 0; i < dataFileNames.size(); i++ )
|
|
|
|
{
|
|
|
|
stringlist_append_copy( dataFiles, RiaStringEncodingTools::toNativeEncoded( dataFileNames[i] ).data() );
|
|
|
|
}
|
|
|
|
|
|
|
|
bool lazyLoad = true;
|
|
|
|
std::string itemSeparatorInVariableNames = ":";
|
|
|
|
|
|
|
|
ecl_sum_type* ecl_sum = nullptr;
|
|
|
|
try
|
|
|
|
{
|
|
|
|
ecl_sum = ecl_sum_fread_alloc( RiaStringEncodingTools::toNativeEncoded( headerFileName ).data(),
|
|
|
|
dataFiles,
|
|
|
|
itemSeparatorInVariableNames.data(),
|
|
|
|
includeRestartFiles,
|
|
|
|
lazyLoad,
|
|
|
|
ECL_FILE_CLOSE_STREAM );
|
|
|
|
}
|
|
|
|
catch ( ... )
|
|
|
|
{
|
|
|
|
ecl_sum = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
stringlist_free( dataFiles );
|
|
|
|
|
|
|
|
return ecl_sum;
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
void RifEclipseSummaryTools::closeEclSum( ecl_sum_type* ecl_sum )
|
|
|
|
{
|
|
|
|
if ( ecl_sum ) ecl_sum_free( ecl_sum );
|
|
|
|
}
|