mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
#9614 Check last write time for ESMRY files and SMSPEC files
This commit is contained in:
parent
4c0e7b2979
commit
28b3f16db1
@ -25,6 +25,7 @@
|
||||
|
||||
#include <QDir>
|
||||
|
||||
#include <filesystem>
|
||||
#include <memory>
|
||||
#include <set>
|
||||
|
||||
@ -362,3 +363,16 @@ std::map<QString, QStringList> RiaFilePathTools::keyPathComponentsForEachFilePat
|
||||
|
||||
return keyComponents;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RiaFilePathTools::isFirstOlderThanSecond( const std::string& firstFileName, const std::string& secondFileName )
|
||||
{
|
||||
if ( !std::filesystem::exists( firstFileName ) || !std::filesystem::exists( secondFileName ) ) return false;
|
||||
|
||||
auto timeFirstFile = std::filesystem::last_write_time( firstFileName );
|
||||
auto timeSecondFile = std::filesystem::last_write_time( secondFileName );
|
||||
|
||||
return ( timeFirstFile < timeSecondFile );
|
||||
}
|
||||
|
@ -48,4 +48,6 @@ public:
|
||||
static QStringList splitPathIntoComponents( const QString& path, bool splitExtensionIntoSeparateEntry = false );
|
||||
|
||||
static std::map<QString, QStringList> keyPathComponentsForEachFilePath( const QStringList& filePaths );
|
||||
|
||||
static bool isFirstOlderThanSecond( const std::string& firstFileName, const std::string& secondFileName );
|
||||
};
|
||||
|
@ -18,6 +18,7 @@
|
||||
|
||||
#include "RifHdf5SummaryExporter.h"
|
||||
|
||||
#include "RiaFilePathTools.h"
|
||||
#include "RiaLogging.h"
|
||||
#include "RiaPreferencesSummary.h"
|
||||
#include "RiaStdStringTools.h"
|
||||
@ -98,7 +99,7 @@ bool RifHdf5SummaryExporter::ensureHdf5FileIsCreated( const std::string& smspecF
|
||||
{
|
||||
exportIsRequired = true;
|
||||
}
|
||||
else if ( RifHdf5SummaryExporter::isFirstOlderThanSecond( h5FileName, smspecFileName ) )
|
||||
else if ( RiaFilePathTools::isFirstOlderThanSecond( h5FileName, smspecFileName ) )
|
||||
{
|
||||
exportIsRequired = true;
|
||||
}
|
||||
@ -269,18 +270,3 @@ bool RifHdf5SummaryExporter::writeSummaryVectors( RifHdf5Exporter& exporter, Opm
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RifHdf5SummaryExporter::isFirstOlderThanSecond( const std::string& firstFileName, const std::string& secondFileName )
|
||||
{
|
||||
// Use Opm namespace to make sure the code compiles on older compilers
|
||||
|
||||
if ( !std::filesystem::exists( firstFileName ) || !std::filesystem::exists( secondFileName ) ) return false;
|
||||
|
||||
auto timeA = std::filesystem::last_write_time( firstFileName );
|
||||
auto timeB = std::filesystem::last_write_time( secondFileName );
|
||||
|
||||
return ( timeA < timeB );
|
||||
}
|
||||
|
@ -51,6 +51,4 @@ public:
|
||||
private:
|
||||
static bool writeGeneralSection( RifHdf5Exporter& exporter, Opm::EclIO::ESmry& sourceSummaryData );
|
||||
static bool writeSummaryVectors( RifHdf5Exporter& exporter, Opm::EclIO::ESmry& sourceSummaryData );
|
||||
|
||||
static bool isFirstOlderThanSecond( const std::string& firstFileName, const std::string& secondFileName );
|
||||
};
|
||||
|
@ -18,6 +18,7 @@
|
||||
|
||||
#include "RifOpmCommonSummary.h"
|
||||
|
||||
#include "RiaFilePathTools.h"
|
||||
#include "RiaLogging.h"
|
||||
#include "RiaStdStringTools.h"
|
||||
|
||||
@ -81,19 +82,37 @@ size_t RifOpmCommonEclipseSummary::numberOfEnhancedSummaryFileCreated()
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RifOpmCommonEclipseSummary::open( const QString& headerFileName,
|
||||
bool includeRestartFiles,
|
||||
RiaThreadSafeLogger* threadSafeLogger )
|
||||
bool RifOpmCommonEclipseSummary::open( const QString& fileName, bool includeRestartFiles, RiaThreadSafeLogger* threadSafeLogger )
|
||||
{
|
||||
if ( m_createEsmryFiles )
|
||||
{
|
||||
auto candidateFileName = enhancedSummaryFilename( headerFileName );
|
||||
if ( !QFileInfo::exists( candidateFileName ) )
|
||||
auto candidateEsmryFileName = enhancedSummaryFilename( fileName );
|
||||
|
||||
// Make sure to check the smspec file name, as it is supported to import ESMRY files without any SMSPEC data
|
||||
auto smspecFileName = smspecSummaryFilename( fileName );
|
||||
|
||||
if ( QFile::exists( candidateEsmryFileName ) && QFile::exists( smspecFileName ) &&
|
||||
RiaFilePathTools::isFirstOlderThanSecond( candidateEsmryFileName.toStdString(), smspecFileName.toStdString() ) )
|
||||
{
|
||||
QString root = QFileInfo( smspecFileName ).canonicalPath();
|
||||
|
||||
const QString smspecFileNameShort = QFileInfo( smspecFileName ).fileName();
|
||||
const QString esmryFileNameShort = QFileInfo( candidateEsmryFileName ).fileName();
|
||||
|
||||
RiaLogging::debug( QString( " %3 : %1 is older than %2, recreating %1." )
|
||||
.arg( esmryFileNameShort )
|
||||
.arg( smspecFileNameShort )
|
||||
.arg( root ) );
|
||||
|
||||
std::filesystem::remove( candidateEsmryFileName.toStdString() );
|
||||
}
|
||||
|
||||
if ( !QFile::exists( candidateEsmryFileName ) && QFile::exists( smspecFileName ) )
|
||||
{
|
||||
try
|
||||
{
|
||||
auto temporarySummaryFile =
|
||||
std::make_unique<Opm::EclIO::ESmry>( headerFileName.toStdString(), includeRestartFiles );
|
||||
std::make_unique<Opm::EclIO::ESmry>( smspecFileName.toStdString(), includeRestartFiles );
|
||||
|
||||
temporarySummaryFile->make_esmry_file();
|
||||
|
||||
@ -110,7 +129,7 @@ bool RifOpmCommonEclipseSummary::open( const QString& headerFileName,
|
||||
}
|
||||
}
|
||||
|
||||
if ( !openFileReader( headerFileName, includeRestartFiles, threadSafeLogger ) ) return false;
|
||||
if ( !openFileReader( fileName, includeRestartFiles, threadSafeLogger ) ) return false;
|
||||
|
||||
if ( !m_standardReader && !m_enhancedReader ) return false;
|
||||
|
||||
@ -218,19 +237,54 @@ void RifOpmCommonEclipseSummary::buildMetaData()
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RifOpmCommonEclipseSummary::openFileReader( const QString& headerFileName,
|
||||
bool RifOpmCommonEclipseSummary::openFileReader( const QString& fileName,
|
||||
bool includeRestartFiles,
|
||||
RiaThreadSafeLogger* threadSafeLogger )
|
||||
{
|
||||
// Make sure to check the SMSPEC file name, as it is supported to import ESMRY files without any SMSPEC data.
|
||||
auto smspecFileName = smspecSummaryFilename( fileName );
|
||||
|
||||
if ( m_useEsmryFiles )
|
||||
{
|
||||
try
|
||||
{
|
||||
auto candidateFileName = enhancedSummaryFilename( headerFileName );
|
||||
m_enhancedReader =
|
||||
std::make_unique<Opm::EclIO::ExtESmry>( candidateFileName.toStdString(), includeRestartFiles );
|
||||
auto candidateEsmryFileName = enhancedSummaryFilename( fileName );
|
||||
|
||||
return true;
|
||||
if ( QFile::exists( candidateEsmryFileName ) )
|
||||
{
|
||||
bool isValidEsmryFile = false;
|
||||
|
||||
if ( !QFile::exists( smspecFileName ) )
|
||||
{
|
||||
// No SMSPEC file present, OK to import ESMRY file
|
||||
isValidEsmryFile = true;
|
||||
}
|
||||
else if ( RiaFilePathTools::isFirstOlderThanSecond( smspecFileName.toStdString(),
|
||||
candidateEsmryFileName.toStdString() ) )
|
||||
{
|
||||
isValidEsmryFile = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
QString root = QFileInfo( smspecFileName ).canonicalPath();
|
||||
|
||||
const QString smspecFileNameShort = QFileInfo( smspecFileName ).fileName();
|
||||
const QString esmryFileNameShort = QFileInfo( candidateEsmryFileName ).fileName();
|
||||
|
||||
RiaLogging::warning( QString( " %3 : %1 is older than %2, importing data from newest file %2." )
|
||||
.arg( esmryFileNameShort )
|
||||
.arg( smspecFileNameShort )
|
||||
.arg( root ) );
|
||||
}
|
||||
|
||||
if ( isValidEsmryFile )
|
||||
{
|
||||
m_enhancedReader = std::make_unique<Opm::EclIO::ExtESmry>( candidateEsmryFileName.toStdString(),
|
||||
includeRestartFiles );
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch ( ... )
|
||||
{
|
||||
@ -240,7 +294,8 @@ bool RifOpmCommonEclipseSummary::openFileReader( const QString& headerFile
|
||||
|
||||
try
|
||||
{
|
||||
m_standardReader = std::make_unique<Opm::EclIO::ESmry>( headerFileName.toStdString(), includeRestartFiles );
|
||||
// The standard reader will import data from SMSPEC and UNSMRY files
|
||||
m_standardReader = std::make_unique<Opm::EclIO::ESmry>( smspecFileName.toStdString(), includeRestartFiles );
|
||||
}
|
||||
catch ( std::exception& e )
|
||||
{
|
||||
@ -267,12 +322,21 @@ void RifOpmCommonEclipseSummary::increaseEsmryFileCount()
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RifOpmCommonEclipseSummary::enhancedSummaryFilename( const QString& headerFileName )
|
||||
QString RifOpmCommonEclipseSummary::enhancedSummaryFilename( const QString& fileName )
|
||||
{
|
||||
QString s( headerFileName );
|
||||
QString s( fileName );
|
||||
return s.replace( ".SMSPEC", ".ESMRY" );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RifOpmCommonEclipseSummary::smspecSummaryFilename( const QString& fileName )
|
||||
{
|
||||
QString s( fileName );
|
||||
return s.replace( ".ESMRY", ".SMSPEC" );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
@ -72,7 +72,7 @@ public:
|
||||
static void resetEnhancedSummaryFileCount();
|
||||
static size_t numberOfEnhancedSummaryFileCreated();
|
||||
|
||||
bool open( const QString& headerFileName, bool includeRestartFiles, RiaThreadSafeLogger* threadSafeLogger );
|
||||
bool open( const QString& fileName, bool includeRestartFiles, RiaThreadSafeLogger* threadSafeLogger );
|
||||
|
||||
const std::vector<time_t>& timeSteps( const RifEclipseSummaryAddress& resultAddress ) const override;
|
||||
bool values( const RifEclipseSummaryAddress& resultAddress, std::vector<double>* values ) const override;
|
||||
@ -81,10 +81,11 @@ public:
|
||||
|
||||
private:
|
||||
void buildMetaData();
|
||||
bool openFileReader( const QString& headerFileName, bool includeRestartFiles, RiaThreadSafeLogger* threadSafeLogger );
|
||||
bool openFileReader( const QString& fileName, bool includeRestartFiles, RiaThreadSafeLogger* threadSafeLogger );
|
||||
|
||||
static void increaseEsmryFileCount();
|
||||
static QString enhancedSummaryFilename( const QString& headerFileName );
|
||||
static QString enhancedSummaryFilename( const QString& fileName );
|
||||
static QString smspecSummaryFilename( const QString& fileName );
|
||||
|
||||
private:
|
||||
std::unique_ptr<Opm::EclIO::ESmry> m_standardReader;
|
||||
|
Loading…
Reference in New Issue
Block a user