(#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:
Magne Sjaastad
2015-10-28 11:32:47 +01:00
parent 56e6fd1f6b
commit ad6e17a5d9
3 changed files with 87 additions and 5 deletions

View File

@@ -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);
}
}

View File

@@ -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());
}
}
}