2017-11-22 11:59:50 +01:00
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
//
|
|
|
|
|
// Copyright (C) 2017- Statoil ASA
|
2017-11-24 09:42:07 +01:00
|
|
|
//
|
2017-11-22 11:59:50 +01: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.
|
2017-11-24 09:42:07 +01:00
|
|
|
//
|
2017-11-22 11:59:50 +01: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.
|
2017-11-24 09:42:07 +01:00
|
|
|
//
|
|
|
|
|
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
|
2017-11-22 11:59:50 +01:00
|
|
|
// for more details.
|
|
|
|
|
//
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
2017-11-24 09:42:07 +01:00
|
|
|
#include "RifWellPathFormationReader.h"
|
2017-11-22 11:59:50 +01:00
|
|
|
|
|
|
|
|
#include <QFile>
|
2017-11-24 09:42:07 +01:00
|
|
|
#include <QStringList>
|
2026-10-06 13:12:10 +02:00
|
|
|
#include <QTextStream>
|
2017-11-22 11:59:50 +01:00
|
|
|
|
2026-10-06 13:12:10 +02:00
|
|
|
#include <vector>
|
2017-12-05 16:27:21 +01:00
|
|
|
|
2026-10-06 13:12:10 +02:00
|
|
|
namespace
|
|
|
|
|
{
|
2017-11-22 11:59:50 +01:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2017-11-24 09:42:07 +01:00
|
|
|
///
|
2017-11-22 11:59:50 +01:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2026-10-06 13:12:10 +02:00
|
|
|
QStringList parseHeader( const QString& line )
|
2017-11-22 11:59:50 +01:00
|
|
|
{
|
2026-10-06 13:12:10 +02:00
|
|
|
QString header = line.toLower();
|
|
|
|
|
header.removeIf( []( QChar c ) { return c.isSpace(); } );
|
2017-11-27 10:33:41 +01:00
|
|
|
|
2026-10-06 13:12:10 +02:00
|
|
|
return header.split( ';' );
|
2017-11-22 11:59:50 +01:00
|
|
|
}
|
2026-10-06 13:12:10 +02:00
|
|
|
} // namespace
|
2017-11-22 11:59:50 +01:00
|
|
|
|
2026-10-06 13:12:10 +02:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
std::expected<RifWellPathFormationReader::WellFormations, QString> RifWellPathFormationReader::readWellFormations( const QString& filePath )
|
2017-12-05 16:27:21 +01:00
|
|
|
{
|
2026-10-06 13:12:10 +02:00
|
|
|
QFile file( filePath );
|
|
|
|
|
if ( !file.open( QFile::ReadOnly | QFile::Text ) )
|
|
|
|
|
{
|
|
|
|
|
return std::unexpected( QString( "Failed to open %1" ).arg( filePath ) );
|
|
|
|
|
}
|
2017-12-05 16:27:21 +01:00
|
|
|
|
2026-10-06 13:12:10 +02:00
|
|
|
return parseWellFormations( QString::fromUtf8( file.readAll() ), filePath );
|
2017-12-05 16:27:21 +01:00
|
|
|
}
|
|
|
|
|
|
2017-11-22 11:59:50 +01:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2017-11-24 09:42:07 +01:00
|
|
|
///
|
2017-11-22 11:59:50 +01:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2026-10-06 13:12:10 +02:00
|
|
|
std::expected<RifWellPathFormationReader::WellFormations, QString> RifWellPathFormationReader::parseWellFormations( const QString& content,
|
|
|
|
|
const QString& filePath )
|
2017-11-22 11:59:50 +01:00
|
|
|
{
|
2026-10-06 13:12:10 +02:00
|
|
|
const auto parseFailure = QString( "Failed to parse %1 as a well pick file" ).arg( filePath );
|
2017-11-22 11:59:50 +01:00
|
|
|
|
2026-10-06 13:12:10 +02:00
|
|
|
QString text = content;
|
|
|
|
|
QTextStream stream( &text );
|
2017-11-22 11:59:50 +01:00
|
|
|
|
2026-10-06 13:12:10 +02:00
|
|
|
QStringList header;
|
2019-09-06 10:40:57 +02:00
|
|
|
while ( header.size() < 3 )
|
2017-11-22 11:59:50 +01:00
|
|
|
{
|
2026-10-06 13:12:10 +02:00
|
|
|
if ( stream.atEnd() ) return std::unexpected( parseFailure );
|
2017-12-07 08:28:20 +01:00
|
|
|
|
2026-10-06 13:12:10 +02:00
|
|
|
header = parseHeader( stream.readLine() );
|
2017-11-22 11:59:50 +01:00
|
|
|
}
|
|
|
|
|
|
2026-10-06 13:12:10 +02:00
|
|
|
const int wellNameIndex = header.indexOf( "wellname" );
|
|
|
|
|
const int unitNameIndex = header.indexOf( "unitname" );
|
|
|
|
|
const int mdTopIndex = header.indexOf( "topmd" );
|
|
|
|
|
const int mdBaseIndex = header.indexOf( "basemd" );
|
|
|
|
|
const int tvdTopIndex = header.indexOf( "toptvdss" );
|
|
|
|
|
const int tvdBaseIndex = header.indexOf( "basetvdss" );
|
2017-11-22 11:59:50 +01:00
|
|
|
|
2026-10-06 13:12:10 +02:00
|
|
|
const bool hasMd = mdTopIndex != -1 && mdBaseIndex != -1;
|
|
|
|
|
const bool hasTvd = tvdTopIndex != -1 && tvdBaseIndex != -1;
|
2017-11-22 11:59:50 +01:00
|
|
|
|
2026-10-06 13:12:10 +02:00
|
|
|
if ( wellNameIndex == -1 || unitNameIndex == -1 )
|
2017-11-22 11:59:50 +01:00
|
|
|
{
|
2026-10-06 13:12:10 +02:00
|
|
|
return std::unexpected( parseFailure );
|
2017-11-22 11:59:50 +01:00
|
|
|
}
|
|
|
|
|
|
2026-10-06 13:12:10 +02:00
|
|
|
if ( !hasMd && !hasTvd )
|
2018-01-24 08:21:22 +01:00
|
|
|
{
|
2026-10-06 13:12:10 +02:00
|
|
|
return std::unexpected( parseFailure + ". Neither MD or TVD is present." );
|
2018-01-24 08:21:22 +01:00
|
|
|
}
|
|
|
|
|
|
2026-10-06 13:12:10 +02:00
|
|
|
std::map<QString, std::vector<RigWellPathFormation>> formationsPerWell;
|
2018-01-24 08:21:22 +01:00
|
|
|
|
2026-10-06 13:12:10 +02:00
|
|
|
while ( !stream.atEnd() )
|
2017-12-07 08:28:20 +01:00
|
|
|
{
|
2026-10-06 13:12:10 +02:00
|
|
|
const QStringList columns = stream.readLine().split( ';' );
|
|
|
|
|
if ( columns.size() != header.size() ) continue;
|
2018-01-24 08:21:22 +01:00
|
|
|
|
2026-10-06 13:12:10 +02:00
|
|
|
const QString wellName = columns[wellNameIndex];
|
|
|
|
|
const QString unitName = columns[unitNameIndex].trimmed();
|
|
|
|
|
if ( wellName.trimmed().isEmpty() && unitName.isEmpty() ) continue;
|
2020-12-10 10:44:23 +01:00
|
|
|
|
2026-10-06 13:12:10 +02:00
|
|
|
RigWellPathFormation formation;
|
|
|
|
|
formation.formationName = unitName;
|
2019-09-06 10:40:57 +02:00
|
|
|
|
2026-10-06 13:12:10 +02:00
|
|
|
if ( hasMd )
|
|
|
|
|
{
|
|
|
|
|
formation.mdTop = columns[mdTopIndex].toDouble();
|
|
|
|
|
formation.mdBase = columns[mdBaseIndex].toDouble();
|
|
|
|
|
}
|
2018-01-24 08:21:22 +01:00
|
|
|
|
2026-10-06 13:12:10 +02:00
|
|
|
if ( hasTvd )
|
|
|
|
|
{
|
|
|
|
|
formation.tvdTop = -columns[tvdTopIndex].toDouble();
|
|
|
|
|
formation.tvdBase = -columns[tvdBaseIndex].toDouble();
|
|
|
|
|
}
|
2018-01-24 08:21:22 +01:00
|
|
|
|
2026-10-06 13:12:10 +02:00
|
|
|
formationsPerWell[wellName].push_back( formation );
|
|
|
|
|
}
|
2017-11-22 11:59:50 +01:00
|
|
|
|
2026-10-06 13:12:10 +02:00
|
|
|
if ( formationsPerWell.empty() )
|
|
|
|
|
{
|
|
|
|
|
return std::unexpected( parseFailure );
|
|
|
|
|
}
|
2017-11-22 11:59:50 +01:00
|
|
|
|
2026-10-06 13:12:10 +02:00
|
|
|
WellFormations result;
|
|
|
|
|
for ( const auto& [wellName, formations] : formationsPerWell )
|
|
|
|
|
{
|
|
|
|
|
result.emplace( wellName, RigWellPathFormations( formations, filePath, wellName ) );
|
2017-12-07 08:28:20 +01:00
|
|
|
}
|
2026-10-06 13:12:10 +02:00
|
|
|
|
|
|
|
|
return result;
|
2017-11-22 11:59:50 +01:00
|
|
|
}
|