Ascii Well path import: Works for one path in one file

p4#: 21966
This commit is contained in:
Jacob Støren 2013-06-21 15:59:04 +02:00
parent 139c80dfa0
commit cd6d60d896
2 changed files with 52 additions and 18 deletions

View File

@ -41,6 +41,7 @@
#include "RimOilField.h"
#include "RimAnalysisModels.h"
#include <fstream>
#include <limits>
CAF_PDM_SOURCE_INIT(RimWellPath, "WellPath");
@ -221,35 +222,64 @@ void RimWellPath::readJsonWellPathFile()
}
//--------------------------------------------------------------------------------------------------
///
/// Read a well path ascii file in the format specified by Lars Hustoft
/// Except that we here only handle one well path in one file.
//--------------------------------------------------------------------------------------------------
void RimWellPath::readAsciiWellPathFile()
{
RigWellPath* wellPathGeom = new RigWellPath();
std::ifstream stream(filepath().toLatin1().data());
double x, y, tvd, md;
double x(HUGE_VAL), y(HUGE_VAL), tvd(HUGE_VAL), md(HUGE_VAL);
bool foundWellName = false;
while(stream.good())
{
std::string wellNameKw;
stream >> wellNameKw;
while (stream.good())
{
stream >> x >> y >> tvd >> md;
stream >> x;
if (stream.good())
{
stream >> y >> tvd >> md;
if (!stream.good())
{
// -999 or otherwise to few numbers before some word
if (x != -999)
{
// Error in file: missing numbers at this line
}
stream.clear();
}
else
{
cvf::Vec3d wellPoint(x, y, -tvd);
wellPathGeom->m_wellPathPoints.push_back(wellPoint);
x = HUGE_VAL;
y = HUGE_VAL;
tvd = HUGE_VAL;
md = HUGE_VAL;
}
}
if (stream.eof()) break;
else
{
// Could not read one double.
// we assume there is a comment line or a well path description
stream.clear();
std::string line;
std::getline(stream, line, '\n');
size_t quoteStartIdx = line.find_first_of("'`´");
size_t quoteEndIdx = line.find_last_of("'`´");
if (quoteStartIdx < line.size() -1 )
{
// If we have already read a well name stop parsing the file,
// as the rest is a new well which we cant handle right now.
if (foundWellName) break;
// Extract the text between the quotes
std::string wellName = line.substr(quoteStartIdx + 1, quoteEndIdx - 1 - quoteStartIdx);
this->name = wellName.c_str();
foundWellName = true;
}
}
}
setWellPathGeometry(wellPathGeom);
}

View File

@ -52,6 +52,8 @@ public:
caf::PdmField<QString> name;
caf::PdmField<QString> filepath;
//caf::PdmField<int> wellPathIndexInFile; // -1 means all, but is not to be used when saving.
caf::PdmField<bool> showWellPathLabel;
caf::PdmField<bool> showWellPath;
@ -72,6 +74,8 @@ private:
QString surveyType() { return m_surveyType; }
void setSurveyType(QString surveyType);
//RimWellPath* generateRimWellPathForFilePart(int wellPathNumberOnFile);
caf::PdmField<QString> id;
caf::PdmField<QString> sourceSystem;
caf::PdmField<QString> utmZone;