Files
ResInsight/ApplicationLibCode/FileInterface/RifWellPathFormationReader.cpp
T

255 lines
8.4 KiB
C++
Raw Normal View History

2017-11-22 11:59:50 +01:00
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2017- Statoil ASA
//
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-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.
//
// 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.
//
/////////////////////////////////////////////////////////////////////////////////
#include "RifWellPathFormationReader.h"
2017-11-22 11:59:50 +01:00
#include "RiaGuiApplication.h"
#include "RiaLogging.h"
#include "RiaRegressionTestRunner.h"
#include "Riu3DMainWindowTools.h"
2017-11-22 11:59:50 +01:00
#include <QFile>
#include <QStringList>
2017-11-22 11:59:50 +01:00
#include <algorithm>
#include <cctype>
#include <string>
2017-11-22 11:59:50 +01:00
//--------------------------------------------------------------------------------------------------
///
2017-11-22 11:59:50 +01:00
//--------------------------------------------------------------------------------------------------
2023-02-26 10:48:40 +01:00
std::map<QString, cvf::ref<RigWellPathFormations>> RifWellPathFormationReader::readWellFormationsToGeometry( const QString& filePath )
2017-11-22 11:59:50 +01:00
{
std::map<QString, cvf::ref<RigWellPathFormations>> result;
std::vector<QString> wellNames;
std::vector<QString> formationNames;
std::vector<double> mdTop;
std::vector<double> mdBase;
2017-11-22 11:59:50 +01:00
std::vector<double> tvdTop;
std::vector<double> tvdBase;
readFile( filePath, &wellNames, &formationNames, &mdTop, &mdBase, &tvdTop, &tvdBase );
bool mdIsPresent = true;
bool tvdIsPresent = true;
if ( mdTop.empty() || mdBase.empty() )
{
mdIsPresent = false;
}
if ( tvdTop.empty() || tvdBase.empty() )
{
tvdIsPresent = false;
}
if ( wellNames.empty() || formationNames.empty() )
{
RiaLogging::errorInMessageBox( Riu3DMainWindowTools::mainWindowWidget(),
"Import failure",
QString( "Failed to parse %1 as a well pick file" ).arg( filePath ) );
return result;
}
else if ( !( mdIsPresent || tvdIsPresent ) )
{
RiaLogging::errorInMessageBox( Riu3DMainWindowTools::mainWindowWidget(),
"Import failure",
2023-02-26 10:48:40 +01:00
QString( "Failed to parse %1 as a well pick file. Neither MD or TVD is present." ).arg( filePath ) );
return result;
}
2017-11-22 11:59:50 +01:00
CVF_ASSERT( wellNames.size() == formationNames.size() );
std::map<QString, std::vector<RigWellPathFormation>> formations;
for ( size_t i = 0; i < wellNames.size(); i++ )
{
RigWellPathFormation formation;
formation.formationName = formationNames[i];
if ( mdIsPresent )
{
formation.mdTop = mdTop[i];
formation.mdBase = mdBase[i];
}
if ( tvdIsPresent )
{
formation.tvdTop = tvdTop[i];
formation.tvdBase = tvdBase[i];
}
if ( !formations.count( wellNames[i] ) )
{
formations[wellNames[i]] = std::vector<RigWellPathFormation>();
}
formations[wellNames[i]].push_back( formation );
}
for ( const std::pair<const QString, std::vector<RigWellPathFormation>>& formation : formations )
{
2023-02-26 10:48:40 +01:00
cvf::ref<RigWellPathFormations> wellPathFormations = new RigWellPathFormations( formation.second, filePath, formation.first );
result[formation.first] = wellPathFormations;
}
return result;
2017-11-22 11:59:50 +01:00
}
void removeWhiteSpaces( QString* word )
{
std::string wordStd = word->toStdString();
2023-02-26 10:48:40 +01:00
wordStd.erase( std::remove_if( wordStd.begin(), wordStd.end(), []( unsigned char x ) { return std::isspace( x ); } ), wordStd.end() );
( *word ) = QString( wordStd.c_str() );
}
2017-11-22 11:59:50 +01:00
//--------------------------------------------------------------------------------------------------
///
2017-11-22 11:59:50 +01:00
//--------------------------------------------------------------------------------------------------
void RifWellPathFormationReader::readFile( const QString& filePath,
std::vector<QString>* wellNames,
std::vector<QString>* formationNames,
std::vector<double>* mdTop,
std::vector<double>* mdBase,
std::vector<double>* tvdTop,
std::vector<double>* tvdBase )
2017-11-22 11:59:50 +01:00
{
QFile data( filePath );
2017-11-22 11:59:50 +01:00
if ( !data.open( QFile::ReadOnly ) )
2017-11-22 11:59:50 +01:00
{
return;
}
QStringList header;
while ( header.size() < 3 )
2017-11-22 11:59:50 +01:00
{
if ( data.atEnd() ) return;
2017-12-07 08:28:20 +01:00
QString line = data.readLine().toLower();
removeWhiteSpaces( &line );
2022-03-11 13:24:01 +01:00
header = line.split( ';' );
2017-11-22 11:59:50 +01:00
}
static const QString wellNameText = "wellname";
static const QString surfaceNameText = "surfacename";
2017-12-07 08:28:20 +01:00
static const QString measuredDepthText = "md";
2017-11-22 11:59:50 +01:00
int wellNameIndex = header.indexOf( wellNameText );
int surfaceNameIndex = header.indexOf( surfaceNameText );
int measuredDepthIndex = header.indexOf( measuredDepthText );
2017-11-22 11:59:50 +01:00
if ( wellNameIndex != -1 && surfaceNameIndex != -1 && measuredDepthIndex != -1 )
2017-11-22 11:59:50 +01:00
{
2017-12-07 08:28:20 +01:00
do
{
QString line = data.readLine();
2022-03-11 13:24:01 +01:00
QStringList dataLine = line.split( ';' );
if ( dataLine.size() != header.size() ) continue;
2017-12-07 08:28:20 +01:00
bool conversionOk;
double measuredDepth = dataLine[measuredDepthIndex].toDouble( &conversionOk );
if ( !conversionOk ) continue;
2017-12-07 08:28:20 +01:00
QString wellName = dataLine[wellNameIndex];
2017-12-07 08:28:20 +01:00
QString surfaceName = dataLine[surfaceNameIndex];
wellNames->push_back( wellName );
formationNames->push_back( surfaceName );
mdTop->push_back( measuredDepth );
2017-12-07 08:28:20 +01:00
} while ( !data.atEnd() );
2017-12-07 08:28:20 +01:00
return;
2017-11-22 11:59:50 +01:00
}
static const QString unitNameText = "unitname";
static const QString measuredDepthToptext = "topmd";
static const QString measuredDepthBasetext = "basemd";
static const QString trueVerticalDepthToptext = "toptvdss";
static const QString trueVerticalDepthBasetext = "basetvdss";
2017-11-22 11:59:50 +01:00
int unitNameIndex = header.indexOf( unitNameText );
int measuredDepthTopIndex = header.indexOf( measuredDepthToptext );
int measuredDepthBaseIndex = header.indexOf( measuredDepthBasetext );
int trueVerticalDepthTopIndex = header.indexOf( trueVerticalDepthToptext );
int trueVerticalDepthBaseIndex = header.indexOf( trueVerticalDepthBasetext );
bool mdIsPresent = true;
bool tvdIsPresent = true;
if ( measuredDepthTopIndex == -1 || measuredDepthBaseIndex == -1 )
{
mdIsPresent = false;
}
if ( trueVerticalDepthTopIndex == -1 || trueVerticalDepthBaseIndex == -1 )
{
tvdIsPresent = false;
}
if ( unitNameIndex != -1 && ( mdIsPresent || tvdIsPresent ) )
2017-12-07 08:28:20 +01:00
{
do
{
QString line = data.readLine();
2022-03-11 13:24:01 +01:00
QStringList dataLine = line.split( ';' );
if ( dataLine.size() != header.size() ) continue;
2017-11-22 11:59:50 +01:00
QString wellName = dataLine[wellNameIndex];
QString unitName = dataLine[unitNameIndex];
unitName = unitName.trimmed();
2020-12-10 10:44:23 +01:00
if ( wellName.trimmed().isEmpty() && unitName.isEmpty() ) continue;
if ( mdIsPresent )
{
double mdTopValue = dataLine[measuredDepthTopIndex].toDouble();
double mdBaseValue = dataLine[measuredDepthBaseIndex].toDouble();
mdTop->push_back( mdTopValue );
mdBase->push_back( mdBaseValue );
}
if ( tvdIsPresent )
{
double tvdTopValue = dataLine[trueVerticalDepthTopIndex].toDouble();
double tvdBaseValue = dataLine[trueVerticalDepthBaseIndex].toDouble();
tvdTop->push_back( -tvdTopValue );
tvdBase->push_back( -tvdBaseValue );
}
2017-11-22 11:59:50 +01:00
wellNames->push_back( wellName );
formationNames->push_back( unitName );
2017-11-22 11:59:50 +01:00
} while ( !data.atEnd() );
2017-12-07 08:28:20 +01:00
}
2017-11-22 11:59:50 +01:00
}