mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
(#596) Refactored name matching for Ascii well path files (dev-files)
Supported well names are Well name in quotes name myWellName WELLNAME: myWellName
This commit is contained in:
@@ -0,0 +1,70 @@
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
#include "RimWellPathCollection.h"
|
||||
#include "RigWellPath.h"
|
||||
|
||||
#include <QTemporaryFile>
|
||||
#include <QTextStream>
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(RimWellPathAsciiFileReaderTest, TestWellNameNoColon)
|
||||
{
|
||||
QTemporaryFile file;
|
||||
if (file.open())
|
||||
{
|
||||
QString wellName = "My test Wellname";
|
||||
{
|
||||
QTextStream out(&file);
|
||||
out << "name " << wellName << "\n";
|
||||
out << "1 2 3";
|
||||
}
|
||||
|
||||
RimWellPathAsciiFileReader reader;
|
||||
RimWellPathAsciiFileReader::WellData wpData = reader.readWellData(file.fileName(), 0);
|
||||
EXPECT_TRUE(wpData.m_name == wellName);
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(RimWellPathAsciiFileReaderTest, TestWellNameWithColon)
|
||||
{
|
||||
QTemporaryFile file;
|
||||
if (file.open())
|
||||
{
|
||||
QString wellName = "My test Wellname";
|
||||
{
|
||||
QTextStream out(&file);
|
||||
out << "WELLNAME:" << wellName << "\n";
|
||||
out << "1 2 3";
|
||||
}
|
||||
|
||||
RimWellPathAsciiFileReader reader;
|
||||
RimWellPathAsciiFileReader::WellData wpData = reader.readWellData(file.fileName(), 0);
|
||||
EXPECT_TRUE(wpData.m_name == wellName);
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(RimWellPathAsciiFileReaderTest, TestWellNameWithColonAndSpace)
|
||||
{
|
||||
QTemporaryFile file;
|
||||
if (file.open())
|
||||
{
|
||||
QString wellName = "My test Wellname";
|
||||
{
|
||||
QTextStream out(&file);
|
||||
out << "WELLNAME : " << wellName << "\n";
|
||||
out << "1 2 3";
|
||||
}
|
||||
|
||||
RimWellPathAsciiFileReader reader;
|
||||
RimWellPathAsciiFileReader::WellData wpData = reader.readWellData(file.fileName(), 0);
|
||||
EXPECT_TRUE(wpData.m_name == wellName);
|
||||
}
|
||||
}
|
||||
@@ -420,15 +420,26 @@ void RimWellPathAsciiFileReader::readAllWellData(QString filePath)
|
||||
else if (quoteStartIdx > line.length() && quoteEndIdx > line.length())
|
||||
{
|
||||
// Did not find any quotes
|
||||
// Look for keyword Name
|
||||
// Supported alternatives are
|
||||
// name WellNameA
|
||||
// wellname: WellNameA
|
||||
std::string lineLowerCase = line;
|
||||
transform(lineLowerCase.begin(), lineLowerCase.end(), lineLowerCase.begin(), ::tolower );
|
||||
|
||||
std::string token = "name ";
|
||||
size_t firstNameIdx = lineLowerCase.find_first_of(token);
|
||||
if (firstNameIdx < lineLowerCase.length())
|
||||
std::string tokenName = "name";
|
||||
std::size_t foundNameIdx = lineLowerCase.find(tokenName);
|
||||
if (foundNameIdx != std::string::npos)
|
||||
{
|
||||
wellName = line.substr(firstNameIdx + token.length());
|
||||
std::string tokenColon = ":";
|
||||
std::size_t foundColonIdx = lineLowerCase.find(tokenColon, foundNameIdx);
|
||||
if (foundColonIdx != std::string::npos)
|
||||
{
|
||||
wellName = line.substr(foundColonIdx + tokenColon.length());
|
||||
}
|
||||
else
|
||||
{
|
||||
wellName = line.substr(foundNameIdx + tokenName.length());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user