Files
ResInsight/ApplicationCode/FileInterface/RifWellPathFormationReader.cpp
T

109 lines
3.9 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 <QFile>
#include <QStringList>
2017-11-22 11:59:50 +01:00
//--------------------------------------------------------------------------------------------------
///
2017-11-22 11:59:50 +01:00
//--------------------------------------------------------------------------------------------------
std::map<QString, std::vector<std::pair<double, QString>>> RifWellPathFormationReader::readWellFormations(const QString& filePath)
2017-11-22 11:59:50 +01:00
{
std::map<QString, std::vector<std::pair<double, QString>>> formations;
2017-11-22 11:59:50 +01:00
readFileIntoMap(filePath, &formations);
2017-11-22 11:59:50 +01:00
return formations;
}
//--------------------------------------------------------------------------------------------------
///
2017-11-22 11:59:50 +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::map<QString, std::vector<std::pair<double, QString>>> formations;
2017-11-22 11:59:50 +01:00
readFileIntoMap(filePath, &formations);
std::map<QString, std::vector<std::pair<double, QString>>>::iterator it;
for (it = formations.begin(); it != formations.end(); it++)
{
cvf::ref<RigWellPathFormations> wellPathFormations = new RigWellPathFormations(it->second, filePath, it->first);
result[it->first] = wellPathFormations;
}
return result;
2017-11-22 11:59:50 +01:00
}
//--------------------------------------------------------------------------------------------------
///
2017-11-22 11:59:50 +01:00
//--------------------------------------------------------------------------------------------------
void RifWellPathFormationReader::readFileIntoMap(const QString& filePath,
std::map<QString, std::vector<std::pair<double, QString>>>* formations)
2017-11-22 11:59:50 +01:00
{
QFile data(filePath);
if (!data.open(QFile::ReadOnly))
{
return;
}
QStringList header;
while (header.size() < 3)
{
QString line = data.readLine().toLower();
2017-11-22 11:59:50 +01:00
QString lineWithoutSpaces = line.remove(' ');
2017-11-22 11:59:50 +01:00
header = lineWithoutSpaces.split(';', QString::KeepEmptyParts);
}
const QString wellNameText = "wellname";
const QString surfaceNameText = "surfacename";
2017-11-22 11:59:50 +01:00
const QString measuredDepthText = "md";
int wellNameIndex = header.indexOf(wellNameText);
int surfaceNameIndex = header.indexOf(surfaceNameText);
2017-11-22 11:59:50 +01:00
int measuredDepthIndex = header.indexOf(measuredDepthText);
if (wellNameIndex == -1 || surfaceNameIndex == -1 || measuredDepthIndex == -1)
{
return;
}
do
{
2017-11-22 11:59:50 +01:00
QString line = data.readLine();
QStringList dataLine = line.split(';', QString::KeepEmptyParts);
if (dataLine.size() != header.size())
continue;
2017-11-22 11:59:50 +01:00
QString wellName = dataLine[wellNameIndex];
QString surfaceName = dataLine[surfaceNameIndex];
double measuredDepth = dataLine[measuredDepthIndex].toDouble();
2017-11-22 11:59:50 +01:00
(*formations)[wellName].push_back(std::make_pair(measuredDepth, surfaceName));
2017-11-22 11:59:50 +01:00
} while (!data.atEnd());
}