mirror of
https://github.com/OPM/ResInsight.git
synced 2026-10-27 15:41:00 -05:00
#12425 Use Qt file operations to establish absolute path to restart case
This commit is contained in:
1 parent
d0375378da
commit
ec191f32e3
2 files changed
+59
-41
No files matched your search
@@ -156,7 +156,8 @@ void RifEclipseSummaryTools::dumpMetaData( RifSummaryReaderInterface* readerEcli
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
std::vector<QString> RifEclipseSummaryTools::getRestartFileNames( const QString& headerFileName, std::vector<QString>& warnings )
|
||||
{
|
||||
return getRestartFileNames( headerFileName, false, warnings );
|
||||
const bool useOpmReader = false;
|
||||
return getRestartFileNames( headerFileName, useOpmReader, warnings );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@@ -199,15 +200,25 @@ std::vector<QString>
|
||||
break;
|
||||
}
|
||||
}
|
||||
QString prevFileName = currentFileName;
|
||||
|
||||
QString relativeFilePathFromFile;
|
||||
if ( useOpmReader )
|
||||
{
|
||||
currentFileName = getRestartFileNameOpm( currentFileName );
|
||||
relativeFilePathFromFile = getRestartRelativeFilePathOpm( currentFileName );
|
||||
}
|
||||
else
|
||||
{
|
||||
currentFileName = getRestartFileName( currentFileName );
|
||||
relativeFilePathFromFile = getRestartRelativeFilePathResdata( currentFileName );
|
||||
}
|
||||
|
||||
QString prevFileName = currentFileName;
|
||||
if ( !relativeFilePathFromFile.isEmpty() )
|
||||
{
|
||||
currentFileName = getRestartFilePath( currentFileName, relativeFilePathFromFile );
|
||||
}
|
||||
else
|
||||
{
|
||||
currentFileName.clear();
|
||||
}
|
||||
|
||||
// Fix to stop potential infinite loop
|
||||
@@ -228,6 +239,22 @@ std::vector<QString>
|
||||
return restartFiles;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RifEclipseSummaryTools::getRestartFilePath( const QString& headerFileName, const QString& restartCaseNameFromFile )
|
||||
{
|
||||
QFileInfo sourceFileInfo( headerFileName );
|
||||
QString suffix = sourceFileInfo.suffix();
|
||||
|
||||
QString filePath = sourceFileInfo.absolutePath() + RiaFilePathTools::separator() + restartCaseNameFromFile + "." + suffix;
|
||||
|
||||
QFileInfo restartFileInfo( filePath );
|
||||
QString restartFileName = RiaFilePathTools::toInternalSeparator( restartFileInfo.absoluteFilePath() );
|
||||
|
||||
return restartFileName;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@@ -289,63 +316,53 @@ void RifEclipseSummaryTools::findSummaryHeaderFileInfo( const QString& inputFile
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RifEclipseSummaryTools::getRestartFileName( const QString& headerFileName )
|
||||
QString RifEclipseSummaryTools::getRestartRelativeFilePathResdata( const QString& headerFileName )
|
||||
{
|
||||
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;
|
||||
QString restartCase = rstCase ? RiaFilePathTools::canonicalPath( RiaStringEncodingTools::fromNativeEncoded( rstCase ) ) : "";
|
||||
closeEclSum( ecl_sum );
|
||||
|
||||
if ( !restartCase.isEmpty() )
|
||||
QString restartCaseNameFromFile;
|
||||
if ( ecl_file_type* header = ecl_file_open( headerFileName.toStdString().data(), 0 ) )
|
||||
{
|
||||
QString path = QFileInfo( restartCase ).dir().path();
|
||||
QString restartBase = QDir( restartCase ).dirName();
|
||||
// Code taken from ecl_smspec_load_restart() in ecl_smspec.cpp
|
||||
if ( ecl_file_has_kw( header, RESTART_KW ) )
|
||||
{
|
||||
if ( const ecl_kw_type* restart_kw = ecl_file_iget_named_kw( header, RESTART_KW, 0 ) )
|
||||
{
|
||||
char tmp_base[137];
|
||||
|
||||
char* smspec_header = ecl_util_alloc_exfilename( path.toStdString().data(),
|
||||
restartBase.toStdString().data(),
|
||||
ECL_SUMMARY_HEADER_FILE,
|
||||
false /*unformatted*/,
|
||||
0 );
|
||||
QString restartFileName = RiaFilePathTools::toInternalSeparator( RiaStringEncodingTools::fromNativeEncoded( smspec_header ) );
|
||||
free( smspec_header );
|
||||
tmp_base[0] = '\0';
|
||||
for ( int i = 0; i < ecl_kw_get_size( restart_kw ); i++ )
|
||||
strcat( tmp_base, (const char*)ecl_kw_iget_ptr( restart_kw, i ) );
|
||||
|
||||
return restartFileName;
|
||||
// The case name is a relative path without the .SMSPEC extension
|
||||
restartCaseNameFromFile = tmp_base;
|
||||
restartCaseNameFromFile = restartCaseNameFromFile.trimmed();
|
||||
}
|
||||
}
|
||||
|
||||
ecl_file_close( header );
|
||||
}
|
||||
return {};
|
||||
|
||||
return restartCaseNameFromFile;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RifEclipseSummaryTools::getRestartFileNameOpm( const QString& headerFileName )
|
||||
QString RifEclipseSummaryTools::getRestartRelativeFilePathOpm( const QString& headerFileName )
|
||||
{
|
||||
try
|
||||
{
|
||||
Opm::EclIO::EclFile eclFile( headerFileName.toStdString() );
|
||||
eclFile.loadData( "RESTART" );
|
||||
|
||||
std::string fullRestartFileName;
|
||||
std::string restartCaseNameFromFile;
|
||||
|
||||
auto restartData = eclFile.get<std::string>( "RESTART" );
|
||||
for ( const auto& string : restartData )
|
||||
{
|
||||
fullRestartFileName += string;
|
||||
restartCaseNameFromFile += 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;
|
||||
return QString::fromStdString( restartCaseNameFromFile );
|
||||
}
|
||||
catch ( ... )
|
||||
{
|
||||
|
||||
@@ -83,9 +83,10 @@ public:
|
||||
|
||||
private:
|
||||
static void findSummaryFiles( const QString& inputFile, QString* headerFile, QStringList* dataFiles );
|
||||
static QString getRestartFileName( const QString& headerFileName );
|
||||
static QString getRestartFileNameOpm( const QString& headerFileName );
|
||||
static QString getRestartRelativeFilePathResdata( const QString& headerFileName );
|
||||
static QString getRestartRelativeFilePathOpm( const QString& headerFileName );
|
||||
static std::vector<QString> getRestartFileNames( const QString& headerFileName, bool useOpmReader, std::vector<QString>& warnings );
|
||||
static QString getRestartFilePath( const QString& headerFileName, const QString& restartCaseNameFromFile );
|
||||
|
||||
static void findSummaryHeaderFileInfo( const QString& inputFile, QString* headerFile, QString* path, QString* base, bool* isFormatted );
|
||||
};
|
||||
Reference in new issue
Block a user