2018-03-26 13:11:36 +02:00
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
//
|
|
|
|
|
// Copyright (C) Statoil ASA
|
2019-09-06 10:40:57 +02:00
|
|
|
//
|
2018-03-26 13:11:36 +02: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 10:40:57 +02:00
|
|
|
//
|
2018-03-26 13:11:36 +02: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 10:40:57 +02:00
|
|
|
//
|
|
|
|
|
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
|
2018-03-26 13:11:36 +02:00
|
|
|
// for more details.
|
|
|
|
|
//
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
#include "RifCaseRealizationParametersReader.h"
|
|
|
|
|
#include "RifFileParseTools.h"
|
|
|
|
|
|
|
|
|
|
#include "RiaLogging.h"
|
|
|
|
|
#include "RiaStdStringTools.h"
|
2024-09-30 11:21:17 +02:00
|
|
|
#include "RiaTextStringTools.h"
|
2018-03-26 13:11:36 +02:00
|
|
|
|
2019-09-06 10:40:57 +02:00
|
|
|
#include <QDir>
|
2018-03-26 13:11:36 +02:00
|
|
|
#include <QString>
|
|
|
|
|
#include <QStringList>
|
|
|
|
|
|
2018-06-25 15:14:47 +02:00
|
|
|
#include <functional>
|
2024-09-02 11:35:00 +00:00
|
|
|
#include <memory>
|
2018-03-26 13:11:36 +02:00
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 10:40:57 +02:00
|
|
|
///
|
2018-03-26 13:11:36 +02:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 10:40:57 +02:00
|
|
|
RifCaseRealizationReader::RifCaseRealizationReader( const QString& fileName )
|
2018-03-26 13:11:36 +02:00
|
|
|
{
|
2024-09-02 11:35:00 +00:00
|
|
|
m_parameters = std::make_shared<RigCaseRealizationParameters>();
|
2019-09-06 10:40:57 +02:00
|
|
|
m_fileName = fileName;
|
2018-03-26 13:11:36 +02:00
|
|
|
}
|
|
|
|
|
|
2018-04-06 15:52:16 +02:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 10:40:57 +02:00
|
|
|
///
|
2018-04-06 15:52:16 +02:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2018-06-29 09:27:03 +02:00
|
|
|
RifCaseRealizationReader::~RifCaseRealizationReader()
|
2018-04-06 15:52:16 +02:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2018-03-26 13:11:36 +02:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 10:40:57 +02:00
|
|
|
///
|
2018-03-26 13:11:36 +02:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2018-06-29 09:27:03 +02:00
|
|
|
const std::shared_ptr<RigCaseRealizationParameters> RifCaseRealizationReader::parameters() const
|
2018-03-26 13:11:36 +02:00
|
|
|
{
|
2018-06-29 09:27:03 +02:00
|
|
|
return m_parameters;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 10:40:57 +02:00
|
|
|
///
|
2018-06-29 09:27:03 +02:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 10:40:57 +02:00
|
|
|
std::shared_ptr<RifCaseRealizationReader> RifCaseRealizationReader::createReaderFromFileName( const QString& fileName )
|
2018-06-29 09:27:03 +02:00
|
|
|
{
|
|
|
|
|
std::shared_ptr<RifCaseRealizationReader> reader;
|
|
|
|
|
|
2020-01-30 13:27:49 +01:00
|
|
|
if ( fileName.endsWith( parametersFileName() ) )
|
2018-03-26 13:11:36 +02:00
|
|
|
{
|
2019-09-06 10:40:57 +02:00
|
|
|
reader.reset( new RifCaseRealizationParametersReader( fileName ) );
|
2018-03-26 13:11:36 +02:00
|
|
|
}
|
2020-01-30 13:27:49 +01:00
|
|
|
else if ( fileName.endsWith( runSpecificationFileName() ) )
|
2018-06-29 09:27:03 +02:00
|
|
|
{
|
2019-09-06 10:40:57 +02:00
|
|
|
reader.reset( new RifCaseRealizationRunspecificationReader( fileName ) );
|
2018-06-29 09:27:03 +02:00
|
|
|
}
|
|
|
|
|
return reader;
|
2018-03-26 13:11:36 +02:00
|
|
|
}
|
|
|
|
|
|
2020-01-30 13:27:49 +01:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
QString RifCaseRealizationReader::parametersFileName()
|
|
|
|
|
{
|
|
|
|
|
return "parameters.txt";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
QString RifCaseRealizationReader::runSpecificationFileName()
|
|
|
|
|
{
|
|
|
|
|
return "runspecification.xml";
|
|
|
|
|
}
|
|
|
|
|
|
2018-06-29 09:27:03 +02:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 10:40:57 +02:00
|
|
|
///
|
2018-06-29 09:27:03 +02:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 10:40:57 +02:00
|
|
|
RifCaseRealizationParametersReader::RifCaseRealizationParametersReader( const QString& fileName )
|
|
|
|
|
: RifCaseRealizationReader( fileName )
|
2018-06-29 09:27:03 +02:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 10:40:57 +02:00
|
|
|
///
|
2018-06-29 09:27:03 +02:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
RifCaseRealizationParametersReader::~RifCaseRealizationParametersReader()
|
|
|
|
|
{
|
2018-04-06 15:52:16 +02:00
|
|
|
}
|
|
|
|
|
|
2018-03-26 13:11:36 +02:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 10:40:57 +02:00
|
|
|
///
|
2018-03-26 13:11:36 +02:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
void RifCaseRealizationParametersReader::parse()
|
|
|
|
|
{
|
2020-03-06 13:54:02 +01:00
|
|
|
QFile file( m_fileName );
|
|
|
|
|
if ( !file.open( QIODevice::ReadOnly | QIODevice::Text ) ) return;
|
|
|
|
|
|
|
|
|
|
QTextStream dataStream( &file );
|
2018-03-26 13:11:36 +02:00
|
|
|
|
2020-03-06 13:54:02 +01:00
|
|
|
int lineNo = 0;
|
2020-01-30 13:27:49 +01:00
|
|
|
QStringList errors;
|
|
|
|
|
|
2020-03-06 13:54:02 +01:00
|
|
|
while ( !dataStream.atEnd() )
|
2018-03-26 13:11:36 +02:00
|
|
|
{
|
2020-03-06 13:54:02 +01:00
|
|
|
QString line = dataStream.readLine();
|
2018-03-26 13:11:36 +02:00
|
|
|
|
2020-03-06 13:54:02 +01:00
|
|
|
lineNo++;
|
2024-10-28 13:09:18 +01:00
|
|
|
QStringList cols = RifFileParseTools::splitLineAndTrim( line, QRegularExpression( "[ \t]" ), true );
|
2018-03-26 13:11:36 +02:00
|
|
|
|
2020-03-06 13:54:02 +01:00
|
|
|
if ( cols.size() != 2 )
|
|
|
|
|
{
|
|
|
|
|
errors << QString( "RifEnsembleParametersReader: Invalid file format in line %1" ).arg( lineNo );
|
2020-01-30 13:27:49 +01:00
|
|
|
|
2020-03-06 13:54:02 +01:00
|
|
|
continue;
|
|
|
|
|
}
|
2018-03-26 13:11:36 +02:00
|
|
|
|
2020-03-06 13:54:02 +01:00
|
|
|
QString& name = cols[0];
|
|
|
|
|
QString& strValue = cols[1];
|
2018-03-26 13:11:36 +02:00
|
|
|
|
2024-09-30 11:21:17 +02:00
|
|
|
if ( RiaTextStringTools::isNumber( strValue, QLocale::c().decimalPoint() ) )
|
2020-03-06 13:54:02 +01:00
|
|
|
{
|
|
|
|
|
bool parseOk = true;
|
|
|
|
|
double value = QLocale::c().toDouble( strValue, &parseOk );
|
|
|
|
|
if ( parseOk )
|
2018-03-26 13:11:36 +02:00
|
|
|
{
|
2020-03-06 13:54:02 +01:00
|
|
|
m_parameters->addParameter( name, value );
|
2020-01-30 13:27:49 +01:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2020-03-06 13:54:02 +01:00
|
|
|
errors << QString( "RifEnsembleParametersReader: Invalid number format in line %1" ).arg( lineNo );
|
2018-03-26 13:11:36 +02:00
|
|
|
}
|
|
|
|
|
}
|
2020-03-06 13:54:02 +01:00
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
m_parameters->addParameter( name, strValue );
|
|
|
|
|
}
|
2018-03-26 13:11:36 +02:00
|
|
|
}
|
2020-01-30 13:27:49 +01:00
|
|
|
|
|
|
|
|
for ( const auto& s : errors )
|
|
|
|
|
{
|
|
|
|
|
RiaLogging::warning( s );
|
|
|
|
|
}
|
2018-03-26 13:11:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 10:40:57 +02:00
|
|
|
///
|
2018-03-26 13:11:36 +02:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 10:40:57 +02:00
|
|
|
RifCaseRealizationRunspecificationReader::RifCaseRealizationRunspecificationReader( const QString& fileName )
|
|
|
|
|
: RifCaseRealizationReader( fileName )
|
2018-03-26 13:11:36 +02:00
|
|
|
{
|
2018-06-29 09:27:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 10:40:57 +02:00
|
|
|
///
|
2018-06-29 09:27:03 +02:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2020-02-12 11:13:38 +01:00
|
|
|
RifCaseRealizationRunspecificationReader::~RifCaseRealizationRunspecificationReader()
|
|
|
|
|
{
|
|
|
|
|
}
|
2018-03-26 13:11:36 +02:00
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 10:40:57 +02:00
|
|
|
///
|
2018-03-26 13:11:36 +02:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2018-06-29 09:27:03 +02:00
|
|
|
void RifCaseRealizationRunspecificationReader::parse()
|
2018-03-26 13:11:36 +02:00
|
|
|
{
|
2020-03-06 13:54:02 +01:00
|
|
|
QFile file( m_fileName );
|
|
|
|
|
if ( !file.open( QIODevice::ReadOnly | QIODevice::Text ) ) return;
|
|
|
|
|
|
|
|
|
|
QXmlStreamReader xml( &file );
|
2019-11-03 08:37:03 +01:00
|
|
|
|
2020-01-30 13:37:59 +01:00
|
|
|
QStringList errors;
|
|
|
|
|
|
2018-06-29 09:27:03 +02:00
|
|
|
QString paramName;
|
|
|
|
|
|
2019-11-03 08:37:03 +01:00
|
|
|
while ( !xml.atEnd() )
|
2018-03-26 13:11:36 +02:00
|
|
|
{
|
2019-11-03 08:37:03 +01:00
|
|
|
xml.readNext();
|
2018-06-29 09:27:03 +02:00
|
|
|
|
2019-11-03 08:37:03 +01:00
|
|
|
if ( xml.isStartElement() )
|
2018-06-29 09:27:03 +02:00
|
|
|
{
|
2024-09-30 11:21:17 +02:00
|
|
|
if ( RiaTextStringTools::isTextEqual( xml.name(), QString( "modifier" ) ) )
|
2018-06-29 09:27:03 +02:00
|
|
|
{
|
|
|
|
|
paramName = "";
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-30 11:21:17 +02:00
|
|
|
if ( RiaTextStringTools::isTextEqual( xml.name(), QString( "id" ) ) )
|
2018-06-29 09:27:03 +02:00
|
|
|
{
|
2019-11-03 08:37:03 +01:00
|
|
|
paramName = xml.readElementText();
|
2018-06-29 09:27:03 +02:00
|
|
|
}
|
|
|
|
|
|
2024-09-30 11:21:17 +02:00
|
|
|
if ( RiaTextStringTools::isTextEqual( xml.name(), QString( "value" ) ) )
|
2018-06-29 09:27:03 +02:00
|
|
|
{
|
2019-11-03 08:37:03 +01:00
|
|
|
QString paramStrValue = xml.readElementText();
|
2018-06-29 09:27:03 +02:00
|
|
|
|
2019-09-06 10:40:57 +02:00
|
|
|
if ( paramName.isEmpty() ) continue;
|
2018-06-29 09:27:03 +02:00
|
|
|
|
2024-09-30 11:21:17 +02:00
|
|
|
if ( RiaTextStringTools::isNumber( paramStrValue, QLocale::c().decimalPoint() ) )
|
2018-06-29 09:27:03 +02:00
|
|
|
{
|
2019-09-06 10:40:57 +02:00
|
|
|
bool parseOk = true;
|
|
|
|
|
double value = QLocale::c().toDouble( paramStrValue, &parseOk );
|
2020-01-30 13:37:59 +01:00
|
|
|
if ( parseOk )
|
2018-06-29 09:27:03 +02:00
|
|
|
{
|
2020-01-30 13:37:59 +01:00
|
|
|
m_parameters->addParameter( paramName, value );
|
2018-06-29 09:27:03 +02:00
|
|
|
}
|
2020-01-30 13:37:59 +01:00
|
|
|
else
|
|
|
|
|
{
|
2020-02-12 11:43:15 +01:00
|
|
|
errors
|
2023-02-26 10:48:40 +01:00
|
|
|
<< QString( "RifCaseRealizationRunspecificationReader: Invalid number format in line %1" ).arg( xml.lineNumber() );
|
2020-01-30 13:37:59 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
m_parameters->addParameter( paramName, paramStrValue );
|
2018-06-29 09:27:03 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-11-03 08:37:03 +01:00
|
|
|
else if ( xml.isEndElement() )
|
2018-06-29 09:27:03 +02:00
|
|
|
{
|
2024-09-30 11:21:17 +02:00
|
|
|
if ( RiaTextStringTools::isTextEqual( xml.name(), QString( "modifier" ) ) )
|
2018-06-29 09:27:03 +02:00
|
|
|
{
|
|
|
|
|
paramName = "";
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-03-26 13:11:36 +02:00
|
|
|
}
|
2018-06-29 09:27:03 +02:00
|
|
|
|
2020-01-30 13:37:59 +01:00
|
|
|
for ( const auto& s : errors )
|
|
|
|
|
{
|
|
|
|
|
RiaLogging::warning( s );
|
|
|
|
|
}
|
2018-03-26 13:11:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 10:40:57 +02:00
|
|
|
///
|
2018-03-26 13:11:36 +02:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 10:40:57 +02:00
|
|
|
QString RifCaseRealizationParametersFileLocator::locate( const QString& modelPath )
|
2018-03-26 13:11:36 +02:00
|
|
|
{
|
2023-04-20 10:16:43 +02:00
|
|
|
// Chosen to find parameters file for StimPlan ensembles.
|
|
|
|
|
int MAX_LEVELS_UP = 5;
|
2019-09-06 10:40:57 +02:00
|
|
|
int dirLevel = 0;
|
2018-03-26 13:11:36 +02:00
|
|
|
|
2019-09-06 10:40:57 +02:00
|
|
|
QDir qdir( modelPath );
|
2018-03-26 13:11:36 +02:00
|
|
|
|
2019-09-06 10:40:57 +02:00
|
|
|
const QFileInfo dir( modelPath );
|
|
|
|
|
if ( dir.isFile() )
|
|
|
|
|
qdir.cdUp();
|
|
|
|
|
else if ( !dir.isDir() )
|
|
|
|
|
return "";
|
2018-03-26 13:11:36 +02:00
|
|
|
|
|
|
|
|
do
|
|
|
|
|
{
|
2019-09-06 10:40:57 +02:00
|
|
|
QStringList files = qdir.entryList( QDir::Files | QDir::NoDotAndDotDot );
|
|
|
|
|
for ( const QString& file : files )
|
2018-03-26 13:11:36 +02:00
|
|
|
{
|
2020-01-30 13:27:49 +01:00
|
|
|
if ( QString::compare( file, RifCaseRealizationReader::parametersFileName(), Qt::CaseInsensitive ) == 0 ||
|
|
|
|
|
QString::compare( file, RifCaseRealizationReader::runSpecificationFileName(), Qt::CaseInsensitive ) == 0 )
|
2018-03-26 13:11:36 +02:00
|
|
|
{
|
2019-09-06 10:40:57 +02:00
|
|
|
return qdir.absoluteFilePath( file );
|
2018-03-26 13:11:36 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
qdir.cdUp();
|
|
|
|
|
|
2019-09-06 10:40:57 +02:00
|
|
|
} while ( dirLevel++ < MAX_LEVELS_UP );
|
2018-03-26 13:11:36 +02:00
|
|
|
|
|
|
|
|
return "";
|
|
|
|
|
}
|
2020-03-06 15:00:55 +01:00
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
int RifCaseRealizationParametersFileLocator::realizationNumber( const QString& modelPath )
|
|
|
|
|
{
|
|
|
|
|
QDir dir( modelPath );
|
|
|
|
|
QString absolutePath = dir.absolutePath();
|
|
|
|
|
|
2024-10-28 13:09:18 +01:00
|
|
|
return realizationNumberFromFullPath( absolutePath );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
int RifCaseRealizationParametersFileLocator::realizationNumberFromFullPath( const QString& path )
|
|
|
|
|
{
|
2020-03-06 15:00:55 +01:00
|
|
|
int resultIndex = -1;
|
|
|
|
|
|
2024-10-28 13:09:18 +01:00
|
|
|
QRegularExpression pattern( "realization-(\\d+)", QRegularExpression::CaseInsensitiveOption );
|
|
|
|
|
QRegularExpressionMatch match = pattern.match( path );
|
2020-03-06 15:00:55 +01:00
|
|
|
|
2024-10-28 13:09:18 +01:00
|
|
|
if ( match.hasMatch() )
|
2020-03-06 15:00:55 +01:00
|
|
|
{
|
2024-10-28 13:09:18 +01:00
|
|
|
resultIndex = match.captured( 1 ).toInt();
|
2020-03-06 15:00:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return resultIndex;
|
|
|
|
|
}
|