mirror of
https://github.com/OPM/ResInsight.git
synced 2026-10-25 06:38:13 -05:00
#13530 Fix RMS well path import with spaces in well names
The RMS well parser now correctly handles well names containing spaces. Previously, ReadNext<std::string>() stopped at the first whitespace, causing parsing failures. The fix reads line 3 as a whole and parses coordinates from the end, treating remaining tokens as the well name.
This commit is contained in:
1 parent
eebe856075
commit
116c3b83a5
3 files changed
+79
-11
No files matched your search
@@ -41,3 +41,21 @@ TEST( RifRmsWellPathReader, ReadFromFile )
|
||||
EXPECT_EQ( 4647u, wellPath->wellPathPoints().size() );
|
||||
EXPECT_EQ( 4647u, wellPath->measuredDepths().size() );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST( RifRmsWellPathReader, ReadFromFileWithSpaceInName )
|
||||
{
|
||||
QString filePath = TEST_DATA_DIRECTORY + "well_with_space.rmswell";
|
||||
auto wellData = RifRmsWellPathReader::readWellData( filePath );
|
||||
EXPECT_EQ( wellData.m_name, QString( "55 33-1" ) );
|
||||
|
||||
auto wellPath = wellData.m_wellPathGeometry;
|
||||
ASSERT_TRUE( wellPath.notNull() );
|
||||
|
||||
ASSERT_TRUE( wellPath->hasDatumElevation() );
|
||||
EXPECT_DOUBLE_EQ( 25.0, wellPath->datumElevation() );
|
||||
EXPECT_EQ( 2u, wellPath->wellPathPoints().size() );
|
||||
EXPECT_EQ( 2u, wellPath->measuredDepths().size() );
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
1.0
|
||||
Unknown
|
||||
55 33-1 462480.0 5934232.0 25.0
|
||||
1
|
||||
MDepth CONT linear
|
||||
462480.0 5934232.0 -25.0 0.0
|
||||
462480.0 5934232.0 -24.5 0.5
|
||||
+54
-11
@@ -22,6 +22,7 @@
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <iostream>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
@@ -45,18 +46,60 @@ RMSWell::RMSWell(const std::string& filename)
|
||||
getline(file,line2_);
|
||||
int line = 0;
|
||||
std::string token;
|
||||
std::string wellName = ReadNext<std::string>(file, line);
|
||||
SetWellName(wellName);
|
||||
xpos0_ = ReadNext<double>(file, line);
|
||||
ypos0_ = ReadNext<double>(file, line); // read wellname and positions
|
||||
try {
|
||||
rkb_ = ReadNext<double>(file, line);
|
||||
} catch (std::exception &) {
|
||||
// Ignore errors: not guaranteed to get rkb
|
||||
|
||||
// Read the entire line containing well name and coordinates
|
||||
// The well name may contain spaces, so we parse from the end to find coordinates first
|
||||
std::string line3;
|
||||
getline(file, line3);
|
||||
|
||||
// Tokenize the line
|
||||
std::istringstream iss(line3);
|
||||
std::vector<std::string> tokens;
|
||||
std::string t;
|
||||
while (iss >> t) {
|
||||
tokens.push_back(t);
|
||||
}
|
||||
// getline(file,dummy);// Line may contain a dummy number
|
||||
//-----line shift
|
||||
DiscardRestOfLine(file, line, false);
|
||||
|
||||
// Need at least 3 tokens: wellname (1+), x, y (rkb is optional)
|
||||
if (tokens.size() < 3) {
|
||||
throw FileFormatError("Invalid RMS well format: line 3 must contain well name, x, and y coordinates");
|
||||
}
|
||||
|
||||
// Parse from end to find where coordinates start
|
||||
// Work backwards: try to parse as many trailing numbers as possible (up to 3: x, y, rkb)
|
||||
size_t coordStart = tokens.size();
|
||||
int numCoords = 0;
|
||||
|
||||
for (size_t i = tokens.size(); i > 0 && numCoords < 3; --i) {
|
||||
try {
|
||||
ParseType<double>(tokens[i-1]);
|
||||
coordStart = i - 1;
|
||||
numCoords++;
|
||||
} catch (...) {
|
||||
break; // Stop when we hit a non-number (part of well name)
|
||||
}
|
||||
}
|
||||
|
||||
// Must have at least x and y coordinates
|
||||
if (numCoords < 2) {
|
||||
throw FileFormatError("Invalid RMS well format: could not parse x and y coordinates");
|
||||
}
|
||||
|
||||
// Well name is everything before the coordinates
|
||||
std::string wellName;
|
||||
for (size_t i = 0; i < coordStart; ++i) {
|
||||
if (i > 0) wellName += " ";
|
||||
wellName += tokens[i];
|
||||
}
|
||||
SetWellName(wellName);
|
||||
|
||||
// Parse coordinates (in order: x, y, [rkb])
|
||||
xpos0_ = ParseType<double>(tokens[coordStart]);
|
||||
ypos0_ = ParseType<double>(tokens[coordStart + 1]);
|
||||
if (coordStart + 2 < tokens.size()) {
|
||||
rkb_ = ParseType<double>(tokens[coordStart + 2]);
|
||||
}
|
||||
|
||||
nlog = ReadNext<int>(file, line); // read number of logs
|
||||
DiscardRestOfLine(file, line, false);
|
||||
lognames_.resize(nlog+3);
|
||||
|
||||
Reference in new issue
Block a user