2017-11-22 04:59:50 -06:00
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// Copyright (C) 2017- Statoil ASA
|
2017-11-24 02:42:07 -06:00
|
|
|
//
|
2017-11-22 04:59:50 -06: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 02:42:07 -06:00
|
|
|
//
|
2017-11-22 04:59:50 -06: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 02:42:07 -06:00
|
|
|
//
|
|
|
|
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
|
2017-11-22 04:59:50 -06:00
|
|
|
// for more details.
|
|
|
|
//
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2017-11-24 02:42:07 -06:00
|
|
|
#include "RifWellPathFormationReader.h"
|
2017-11-22 04:59:50 -06:00
|
|
|
|
2017-12-05 01:58:51 -06:00
|
|
|
#include "RiaLogging.h"
|
2017-12-07 01:34:12 -06:00
|
|
|
#include "RiuMainWindow.h"
|
2017-12-05 01:58:51 -06:00
|
|
|
|
2017-11-22 04:59:50 -06:00
|
|
|
#include <QFile>
|
2017-12-07 01:34:12 -06:00
|
|
|
#include <QMessageBox>
|
2017-11-24 02:42:07 -06:00
|
|
|
#include <QStringList>
|
2017-11-22 04:59:50 -06:00
|
|
|
|
2017-12-05 09:27:21 -06:00
|
|
|
#include <algorithm>
|
|
|
|
#include <cctype>
|
2017-12-06 01:33:27 -06:00
|
|
|
#include <string>
|
2017-12-05 09:27:21 -06:00
|
|
|
|
2017-11-22 04:59:50 -06:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2017-11-24 02:42:07 -06:00
|
|
|
///
|
2017-11-22 04:59:50 -06:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2017-11-27 03:33:41 -06:00
|
|
|
std::map<QString, cvf::ref<RigWellPathFormations>>
|
|
|
|
RifWellPathFormationReader::readWellFormationsToGeometry(const QString& filePath)
|
2017-11-22 04:59:50 -06:00
|
|
|
{
|
2017-11-24 02:42:07 -06:00
|
|
|
std::map<QString, cvf::ref<RigWellPathFormations>> result;
|
|
|
|
|
2017-12-08 02:27:30 -06:00
|
|
|
std::vector<QString> wellNames;
|
|
|
|
std::vector<QString> formationNames;
|
|
|
|
std::vector<double> mdTop;
|
|
|
|
std::vector<double> mdBase;
|
2017-11-22 04:59:50 -06:00
|
|
|
|
2017-12-08 02:27:30 -06:00
|
|
|
readFile(filePath, &wellNames, &formationNames, &mdTop, &mdBase);
|
|
|
|
if (wellNames.empty() || formationNames.empty() || mdTop.empty() || mdBase.empty())
|
2017-12-05 01:58:51 -06:00
|
|
|
{
|
2017-12-07 01:34:12 -06:00
|
|
|
QMessageBox::warning(RiuMainWindow::instance(), "Import failure",
|
2017-12-08 02:27:30 -06:00
|
|
|
QString("Failed to parse %1 as a well pick file").arg(filePath));
|
|
|
|
RiaLogging::error(QString("Failed to parse %1 as a well pick file").arg(filePath));
|
|
|
|
|
|
|
|
return result;
|
2017-12-05 01:58:51 -06:00
|
|
|
}
|
2017-11-22 04:59:50 -06:00
|
|
|
|
2017-12-08 02:27:30 -06:00
|
|
|
CVF_ASSERT(wellNames.size() == formationNames.size());
|
|
|
|
CVF_ASSERT(mdTop.size() == formationNames.size());
|
|
|
|
CVF_ASSERT(mdBase.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];
|
|
|
|
formation.mdTop = mdTop[i];
|
|
|
|
formation.mdBase = mdBase[i];
|
|
|
|
|
|
|
|
if (!formations.count(wellNames[i]))
|
|
|
|
{
|
|
|
|
formations[wellNames[i]] = std::vector<RigWellPathFormation>();
|
|
|
|
}
|
|
|
|
|
|
|
|
formations[wellNames[i]].push_back(formation);
|
|
|
|
}
|
2017-11-24 02:42:07 -06:00
|
|
|
|
2017-12-08 02:27:30 -06:00
|
|
|
for (auto it = formations.begin(); it != formations.end(); it++)
|
2017-11-24 02:42:07 -06:00
|
|
|
{
|
2017-11-27 03:33:41 -06:00
|
|
|
cvf::ref<RigWellPathFormations> wellPathFormations = new RigWellPathFormations(it->second, filePath, it->first);
|
2017-12-08 02:27:30 -06:00
|
|
|
result[it->first] = wellPathFormations;
|
2017-11-24 02:42:07 -06:00
|
|
|
}
|
2017-11-27 03:33:41 -06:00
|
|
|
|
2017-11-24 02:42:07 -06:00
|
|
|
return result;
|
2017-11-22 04:59:50 -06:00
|
|
|
}
|
|
|
|
|
2017-12-05 09:27:21 -06:00
|
|
|
void removeWhiteSpaces(QString* word)
|
|
|
|
{
|
|
|
|
std::string wordStd = word->toStdString();
|
2017-12-06 01:33:27 -06:00
|
|
|
wordStd.erase(std::remove_if(wordStd.begin(), wordStd.end(), [](unsigned char x) { return std::isspace(x); }), wordStd.end());
|
2017-12-05 09:27:21 -06:00
|
|
|
|
|
|
|
(*word) = QString(wordStd.c_str());
|
|
|
|
}
|
|
|
|
|
2017-11-22 04:59:50 -06:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2017-11-24 02:42:07 -06:00
|
|
|
///
|
2017-11-22 04:59:50 -06:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2017-12-08 02:27:30 -06:00
|
|
|
void RifWellPathFormationReader::readFile(const QString& filePath, std::vector<QString>* wellNames,
|
|
|
|
std::vector<QString>* formationNames, std::vector<double>* mdTop,
|
|
|
|
std::vector<double>* mdBase)
|
2017-11-22 04:59:50 -06:00
|
|
|
{
|
|
|
|
QFile data(filePath);
|
|
|
|
|
|
|
|
if (!data.open(QFile::ReadOnly))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
QStringList header;
|
|
|
|
|
|
|
|
while (header.size() < 3)
|
|
|
|
{
|
2017-12-07 01:28:20 -06:00
|
|
|
if (data.atEnd()) return;
|
|
|
|
|
2017-12-05 09:27:21 -06:00
|
|
|
QString line = data.readLine().toLower();
|
|
|
|
removeWhiteSpaces(&line);
|
2017-11-24 02:42:07 -06:00
|
|
|
|
2017-12-05 09:27:21 -06:00
|
|
|
header = line.split(';', QString::KeepEmptyParts);
|
2017-11-22 04:59:50 -06:00
|
|
|
}
|
|
|
|
|
2017-12-08 02:27:30 -06:00
|
|
|
static const QString wellNameText = "wellname";
|
|
|
|
static const QString surfaceNameText = "surfacename";
|
2017-12-07 01:28:20 -06:00
|
|
|
static const QString measuredDepthText = "md";
|
2017-11-22 04:59:50 -06:00
|
|
|
|
2017-12-08 02:27:30 -06:00
|
|
|
int wellNameIndex = header.indexOf(wellNameText);
|
|
|
|
int surfaceNameIndex = header.indexOf(surfaceNameText);
|
2017-11-22 04:59:50 -06:00
|
|
|
int measuredDepthIndex = header.indexOf(measuredDepthText);
|
|
|
|
|
2017-12-07 01:28:20 -06:00
|
|
|
if (wellNameIndex != -1 && surfaceNameIndex != -1 && measuredDepthIndex != -1)
|
2017-11-22 04:59:50 -06:00
|
|
|
{
|
2017-12-07 01:28:20 -06:00
|
|
|
do
|
|
|
|
{
|
|
|
|
QString line = data.readLine();
|
|
|
|
|
|
|
|
QStringList dataLine = line.split(';', QString::KeepEmptyParts);
|
|
|
|
if (dataLine.size() != header.size()) continue;
|
|
|
|
|
|
|
|
bool conversionOk;
|
|
|
|
double measuredDepth = dataLine[measuredDepthIndex].toDouble(&conversionOk);
|
|
|
|
if (!conversionOk) continue;
|
|
|
|
|
2017-12-08 02:27:30 -06:00
|
|
|
QString wellName = dataLine[wellNameIndex];
|
2017-12-07 01:28:20 -06:00
|
|
|
QString surfaceName = dataLine[surfaceNameIndex];
|
|
|
|
|
2017-12-08 02:27:30 -06:00
|
|
|
wellNames->push_back(wellName);
|
|
|
|
formationNames->push_back(surfaceName);
|
|
|
|
mdTop->push_back(measuredDepth);
|
2017-12-07 01:28:20 -06:00
|
|
|
|
|
|
|
} while (!data.atEnd());
|
|
|
|
|
|
|
|
return;
|
2017-11-22 04:59:50 -06:00
|
|
|
}
|
|
|
|
|
2017-12-08 02:27:30 -06:00
|
|
|
static const QString unitNameText = "unitname";
|
|
|
|
static const QString measuredDepthToptext = "topmd";
|
2017-12-07 01:28:20 -06:00
|
|
|
static const QString measuredDepthBasetext = "basemd";
|
2017-11-22 04:59:50 -06:00
|
|
|
|
2017-12-08 02:27:30 -06:00
|
|
|
int unitNameIndex = header.indexOf(unitNameText);
|
|
|
|
int measuredDepthTopIndex = header.indexOf(measuredDepthToptext);
|
2017-12-07 01:28:20 -06:00
|
|
|
int measuredDepthBaseIndex = header.indexOf(measuredDepthBasetext);
|
2017-12-06 01:40:43 -06:00
|
|
|
|
2017-12-07 01:28:20 -06:00
|
|
|
if (unitNameIndex != -1 && measuredDepthTopIndex != -1 && measuredDepthBaseIndex != -1)
|
|
|
|
{
|
|
|
|
do
|
|
|
|
{
|
|
|
|
QString line = data.readLine();
|
|
|
|
|
|
|
|
QStringList dataLine = line.split(';', QString::KeepEmptyParts);
|
|
|
|
if (dataLine.size() != header.size()) continue;
|
2017-11-22 04:59:50 -06:00
|
|
|
|
2017-12-08 02:27:30 -06:00
|
|
|
QString wellName = dataLine[wellNameIndex];
|
|
|
|
QString unitName = dataLine[unitNameIndex];
|
|
|
|
unitName = unitName.trimmed();
|
|
|
|
double measuredDepthTop = dataLine[measuredDepthTopIndex].toDouble();
|
2017-12-07 01:28:20 -06:00
|
|
|
double measuredDepthBase = dataLine[measuredDepthBaseIndex].toDouble();
|
2017-11-22 04:59:50 -06:00
|
|
|
|
2017-12-08 02:27:30 -06:00
|
|
|
wellNames->push_back(wellName);
|
|
|
|
formationNames->push_back(unitName);
|
|
|
|
mdTop->push_back(measuredDepthTop);
|
|
|
|
mdBase->push_back(measuredDepthBase);
|
2017-11-22 04:59:50 -06:00
|
|
|
|
2017-12-07 01:28:20 -06:00
|
|
|
} while (!data.atEnd());
|
|
|
|
}
|
2017-11-22 04:59:50 -06:00
|
|
|
}
|