mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
Make opm summary reader work with mixed casing (#7593)
* #7592 opm-common : Add case insensitive file search * #7592 opm-common : Find file based on case insensitive search * #7592 opm-common : Improve error messages
This commit is contained in:
parent
b2d475dde2
commit
a6277c0ddc
@ -197,17 +197,16 @@ bool RifReaderEclipseSummary::open( const QString& headerFileName,
|
|||||||
bool useLodsmryFiles = prefSummary->useOptimizedSummaryDataFiles();
|
bool useLodsmryFiles = prefSummary->useOptimizedSummaryDataFiles();
|
||||||
if ( useLodsmryFiles && includeRestartFiles )
|
if ( useLodsmryFiles && includeRestartFiles )
|
||||||
{
|
{
|
||||||
QString txt = "LODSMRY file loading for summary restart files is not supported. Disable one of the options";
|
QString txt =
|
||||||
if ( threadSafeLogger ) threadSafeLogger->error( txt );
|
"LODSMRY file loading for summary restart files is not supported. Restart history might be incomplete.";
|
||||||
|
if ( threadSafeLogger ) threadSafeLogger->warning( txt );
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
m_opmCommonReader = std::make_unique<RifOpmCommonEclipseSummary>();
|
m_opmCommonReader = std::make_unique<RifOpmCommonEclipseSummary>();
|
||||||
|
|
||||||
m_opmCommonReader->useLodsmaryFiles( prefSummary->useOptimizedSummaryDataFiles() );
|
m_opmCommonReader->useLodsmaryFiles( prefSummary->useOptimizedSummaryDataFiles() );
|
||||||
m_opmCommonReader->createLodsmaryFiles( prefSummary->createOptimizedSummaryDataFiles() );
|
m_opmCommonReader->createLodsmaryFiles( prefSummary->createOptimizedSummaryDataFiles() );
|
||||||
isValid = m_opmCommonReader->open( headerFileName, includeRestartFiles, threadSafeLogger );
|
isValid = m_opmCommonReader->open( headerFileName, false, threadSafeLogger );
|
||||||
if ( !isValid ) m_opmCommonReader.reset();
|
if ( !isValid ) m_opmCommonReader.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -100,9 +100,16 @@ void RimFileSummaryCase::createSummaryReaderInterfaceThreadSafe( RiaThreadSafeLo
|
|||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
void RimFileSummaryCase::createSummaryReaderInterface()
|
void RimFileSummaryCase::createSummaryReaderInterface()
|
||||||
{
|
{
|
||||||
|
RiaThreadSafeLogger threadSafeLogger;
|
||||||
m_summaryFileReader = RimFileSummaryCase::findRelatedFilesAndCreateReader( this->summaryHeaderFilename(),
|
m_summaryFileReader = RimFileSummaryCase::findRelatedFilesAndCreateReader( this->summaryHeaderFilename(),
|
||||||
m_includeRestartFiles,
|
m_includeRestartFiles,
|
||||||
nullptr );
|
&threadSafeLogger );
|
||||||
|
|
||||||
|
auto messages = threadSafeLogger.messages();
|
||||||
|
for ( const auto& m : messages )
|
||||||
|
{
|
||||||
|
RiaLogging::info( m );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
#define OPM_IO_ECLUTIL_HPP
|
#define OPM_IO_ECLUTIL_HPP
|
||||||
|
|
||||||
#include <opm/io/eclipse/EclIOdata.hpp>
|
#include <opm/io/eclipse/EclIOdata.hpp>
|
||||||
|
#include <opm/common/utility/FileSystem.hpp>
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <tuple>
|
#include <tuple>
|
||||||
@ -37,6 +38,9 @@ namespace Opm { namespace EclIO {
|
|||||||
bool isFormatted(const std::string& filename);
|
bool isFormatted(const std::string& filename);
|
||||||
bool is_number(const std::string& numstr);
|
bool is_number(const std::string& numstr);
|
||||||
|
|
||||||
|
bool isEqualCaseInsensitive(const std::string& string1, const std::string& string2);
|
||||||
|
Opm::filesystem::path findFileCaseInsensitive(const std::filesystem::path& folder, const std::string& filename);
|
||||||
|
|
||||||
std::tuple<int, int> block_size_data_binary(eclArrType arrType);
|
std::tuple<int, int> block_size_data_binary(eclArrType arrType);
|
||||||
std::tuple<int, int, int> block_size_data_formatted(eclArrType arrType);
|
std::tuple<int, int, int> block_size_data_formatted(eclArrType arrType);
|
||||||
|
|
||||||
|
@ -109,10 +109,19 @@ ESmry::ESmry(const std::string &filename, bool loadBaseRunData , bool uselodsmry
|
|||||||
if (inputFileName.extension()=="")
|
if (inputFileName.extension()=="")
|
||||||
inputFileName+=".SMSPEC";
|
inputFileName+=".SMSPEC";
|
||||||
|
|
||||||
if ((inputFileName.extension()!=".SMSPEC") && (inputFileName.extension()!=".FSMSPEC"))
|
if (!isEqualCaseInsensitive(inputFileName.extension().string(), ".SMSPEC") &&
|
||||||
|
!isEqualCaseInsensitive(inputFileName.extension().string(), ".FSMSPEC"))
|
||||||
throw std::invalid_argument("Input file should have extension .SMSPEC or .FSMSPEC");
|
throw std::invalid_argument("Input file should have extension .SMSPEC or .FSMSPEC");
|
||||||
|
|
||||||
const bool formatted = inputFileName.extension()==".SMSPEC" ? false : true;
|
{
|
||||||
|
auto candidatePath = findFileCaseInsensitive(inputFileName.parent_path(), inputFileName.filename().string());
|
||||||
|
if (!Opm::filesystem::exists(candidatePath))
|
||||||
|
throw std::invalid_argument("Not able to find summary SMSPEC file");
|
||||||
|
|
||||||
|
inputFileName = candidatePath;
|
||||||
|
}
|
||||||
|
|
||||||
|
const bool formatted = isEqualCaseInsensitive(inputFileName.extension().string(), ".SMSPEC") ? false : true;
|
||||||
formattedFiles.push_back(formatted);
|
formattedFiles.push_back(formatted);
|
||||||
|
|
||||||
if (formatted)
|
if (formatted)
|
||||||
@ -120,6 +129,12 @@ ESmry::ESmry(const std::string &filename, bool loadBaseRunData , bool uselodsmry
|
|||||||
else
|
else
|
||||||
lodFileName = rootName += ".LODSMRY";
|
lodFileName = rootName += ".LODSMRY";
|
||||||
|
|
||||||
|
{
|
||||||
|
auto candidatePath = findFileCaseInsensitive(lodFileName.parent_path(), lodFileName.filename().string());
|
||||||
|
if (Opm::filesystem::exists(candidatePath)) lodFileName = candidatePath;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
if ((!loadBaseRunData) && (Opm::filesystem::exists(lodFileName)))
|
if ((!loadBaseRunData) && (Opm::filesystem::exists(lodFileName)))
|
||||||
lodEnabeled = true;
|
lodEnabeled = true;
|
||||||
else
|
else
|
||||||
@ -132,6 +147,14 @@ ESmry::ESmry(const std::string &filename, bool loadBaseRunData , bool uselodsmry
|
|||||||
Opm::filesystem::path smspec_file = path / rootName;
|
Opm::filesystem::path smspec_file = path / rootName;
|
||||||
smspec_file += inputFileName.extension();
|
smspec_file += inputFileName.extension();
|
||||||
|
|
||||||
|
{
|
||||||
|
auto candidatePath = findFileCaseInsensitive(smspec_file.parent_path(), smspec_file.filename().string());
|
||||||
|
if (!Opm::filesystem::exists(candidatePath))
|
||||||
|
throw std::invalid_argument("Not able to find summary SMSPEC file");
|
||||||
|
|
||||||
|
smspec_file = candidatePath;
|
||||||
|
}
|
||||||
|
|
||||||
Opm::filesystem::path rstRootN;
|
Opm::filesystem::path rstRootN;
|
||||||
Opm::filesystem::path pathRstFile = path;
|
Opm::filesystem::path pathRstFile = path;
|
||||||
|
|
||||||
@ -217,12 +240,29 @@ ESmry::ESmry(const std::string &filename, bool loadBaseRunData , bool uselodsmry
|
|||||||
Opm::filesystem::path rstFile = pathRstFile / rstRootN;
|
Opm::filesystem::path rstFile = pathRstFile / rstRootN;
|
||||||
rstFile += ".SMSPEC";
|
rstFile += ".SMSPEC";
|
||||||
|
|
||||||
|
{
|
||||||
|
auto candidatePath = findFileCaseInsensitive(rstFile.parent_path(), rstFile.filename().string());
|
||||||
|
if (!Opm::filesystem::exists(candidatePath))
|
||||||
|
throw std::invalid_argument("Not able to find summary restart file");
|
||||||
|
|
||||||
|
rstFile = candidatePath;
|
||||||
|
}
|
||||||
|
|
||||||
bool baseRunFmt = false;
|
bool baseRunFmt = false;
|
||||||
|
|
||||||
// if unformatted file not exists, check for formatted file
|
// if unformatted file not exists, check for formatted file
|
||||||
if (!Opm::filesystem::exists(rstFile)){
|
if (!Opm::filesystem::exists(rstFile)){
|
||||||
rstFile = pathRstFile / rstRootN;
|
rstFile = pathRstFile / rstRootN;
|
||||||
rstFile += ".FSMSPEC";
|
rstFile += ".FSMSPEC";
|
||||||
|
|
||||||
|
{
|
||||||
|
auto candidatePath = findFileCaseInsensitive(rstFile.parent_path(), rstFile.filename().string());
|
||||||
|
if (!Opm::filesystem::exists(candidatePath))
|
||||||
|
throw std::invalid_argument("Not able to find summary restart file");
|
||||||
|
|
||||||
|
rstFile = candidatePath;
|
||||||
|
}
|
||||||
|
|
||||||
baseRunFmt = true;
|
baseRunFmt = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -384,6 +424,14 @@ ESmry::ESmry(const std::string &filename, bool loadBaseRunData , bool uselodsmry
|
|||||||
Opm::filesystem::path unsmryFile = rootName;
|
Opm::filesystem::path unsmryFile = rootName;
|
||||||
|
|
||||||
unsmryFile += formattedFiles[specInd] ? ".FUNSMRY" : ".UNSMRY";
|
unsmryFile += formattedFiles[specInd] ? ".FUNSMRY" : ".UNSMRY";
|
||||||
|
{
|
||||||
|
auto candidatePath = findFileCaseInsensitive(unsmryFile.parent_path(), unsmryFile.filename().string());
|
||||||
|
if (!Opm::filesystem::exists(candidatePath))
|
||||||
|
throw std::invalid_argument("Not able to find summary SMSPEC file");
|
||||||
|
|
||||||
|
unsmryFile = candidatePath;
|
||||||
|
}
|
||||||
|
|
||||||
const bool use_unified = Opm::filesystem::exists(unsmryFile.string());
|
const bool use_unified = Opm::filesystem::exists(unsmryFile.string());
|
||||||
|
|
||||||
const std::vector<std::string> multFileList = checkForMultipleResultFiles(rootName, formattedFiles[specInd]);
|
const std::vector<std::string> multFileList = checkForMultipleResultFiles(rootName, formattedFiles[specInd]);
|
||||||
|
@ -83,6 +83,28 @@ bool Opm::EclIO::is_number(const std::string& numstr)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool Opm::EclIO::isEqualCaseInsensitive(const std::string& string1, const std::string& string2)
|
||||||
|
{
|
||||||
|
std::string string1LowerCase(string1);
|
||||||
|
std::string string2LowerCase(string2);
|
||||||
|
|
||||||
|
std::transform(string1.begin(), string1.end(), string1LowerCase.begin(), ::tolower);
|
||||||
|
std::transform(string2.begin(), string2.end(), string2LowerCase.begin(), ::tolower);
|
||||||
|
|
||||||
|
return string1LowerCase == string2LowerCase;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::filesystem::path Opm::EclIO::findFileCaseInsensitive(const std::filesystem::path& folder, const std::string& filename)
|
||||||
|
{
|
||||||
|
for (auto& p : std::filesystem::directory_iterator(folder)) {
|
||||||
|
std::string candidate = p.path().filename().string();
|
||||||
|
|
||||||
|
if (isEqualCaseInsensitive(filename, candidate)) return p.path();
|
||||||
|
}
|
||||||
|
|
||||||
|
return { };
|
||||||
|
}
|
||||||
|
|
||||||
bool Opm::EclIO::isFormatted(const std::string& filename)
|
bool Opm::EclIO::isFormatted(const std::string& filename)
|
||||||
{
|
{
|
||||||
const auto p = filename.find_last_of(".");
|
const auto p = filename.find_last_of(".");
|
||||||
|
Loading…
Reference in New Issue
Block a user