(#345) Well name alone on a line is now accepted. "#" and "--" at start of a line tags the line as comment

Several lines of text between wells are handled. Last none-empty line is used as well name.
This commit is contained in:
Jacob Støren 2015-12-01 16:07:42 +01:00
parent 1150b12213
commit 219fdc6603

View File

@ -406,10 +406,13 @@ void RifWellPathAsciiFileReader::readAllWellData(QString filePath)
std::ifstream stream(filePath.toLatin1().data()); std::ifstream stream(filePath.toLatin1().data());
double x(HUGE_VAL), y(HUGE_VAL), tvd(HUGE_VAL), md(HUGE_VAL); double x(HUGE_VAL), y(HUGE_VAL), tvd(HUGE_VAL), md(HUGE_VAL);
bool hasReadWellPointInCurrentWell = false;
while (stream.good()) while (stream.good())
{ {
// First check if we can read a number
stream >> x; stream >> x;
if (stream.good()) if (stream.good()) // If we can, assume this line is a well point entry
{ {
stream >> y >> tvd >> md; stream >> y >> tvd >> md;
if (!stream.good()) if (!stream.good())
@ -438,6 +441,8 @@ void RifWellPathAsciiFileReader::readAllWellData(QString filePath)
y = HUGE_VAL; y = HUGE_VAL;
tvd = HUGE_VAL; tvd = HUGE_VAL;
md = HUGE_VAL; md = HUGE_VAL;
hasReadWellPointInCurrentWell = true;
} }
} }
else else
@ -448,22 +453,34 @@ void RifWellPathAsciiFileReader::readAllWellData(QString filePath)
std::string line; std::string line;
std::getline(stream, line, '\n'); std::getline(stream, line, '\n');
// Skip possible comment lines (-- is used in eclipse, so Haakon Høgstøl considered it smart to skip these here as well)
// The first "-" is eaten by the stream >> x above
if (line.find("-") == 0 || line.find("#") == 0)
{
// Comment line, just ignore
}
else
{
// Find the first and the last position of any quotes (and do not care to match quotes)
size_t quoteStartIdx = line.find_first_of("'`´"); size_t quoteStartIdx = line.find_first_of("'`´");
size_t quoteEndIdx = line.find_last_of("'`´"); size_t quoteEndIdx = line.find_last_of("'`´");
std::string wellName; std::string wellName;
bool haveAPossibleWellStart = false;
if (quoteStartIdx < line.size() -1) if (quoteStartIdx < line.size() -1)
{ {
// Extract the text between the quotes // Extract the text between the quotes
wellName = line.substr(quoteStartIdx + 1, quoteEndIdx - 1 - quoteStartIdx); wellName = line.substr(quoteStartIdx + 1, quoteEndIdx - 1 - quoteStartIdx);
haveAPossibleWellStart = true;
} }
else if (quoteStartIdx > line.length() && quoteEndIdx > line.length()) else if (quoteStartIdx > line.length())
{ {
// Did not find any quotes // We did not find any quotes
// Supported alternatives are // Supported alternatives are
// name WellNameA // name <WellNameA>
// wellname: WellNameA // wellname: <WellNameA>
std::string lineLowerCase = line; std::string lineLowerCase = line;
transform(lineLowerCase.begin(), lineLowerCase.end(), lineLowerCase.begin(), ::tolower); transform(lineLowerCase.begin(), lineLowerCase.end(), lineLowerCase.begin(), ::tolower);
@ -481,18 +498,41 @@ void RifWellPathAsciiFileReader::readAllWellData(QString filePath)
{ {
wellName = line.substr(foundNameIdx + tokenName.length()); wellName = line.substr(foundNameIdx + tokenName.length());
} }
haveAPossibleWellStart = true;
}
else
{
// Interpret the whole line as the well name.
QString name = line.c_str();
if (!name.trimmed().isEmpty())
{
wellName = name.trimmed().toStdString();
haveAPossibleWellStart = true;
}
} }
} }
if (wellName.size() > 0) if (haveAPossibleWellStart)
{
// Create a new Well data if we have read some data into the previous one.
// if not, just overwrite the name
if (hasReadWellPointInCurrentWell || fileWellDataArray.size() == 0)
{ {
// Create a new Well data
fileWellDataArray.push_back(WellData()); fileWellDataArray.push_back(WellData());
fileWellDataArray.back().m_wellPathGeometry = new RigWellPath(); fileWellDataArray.back().m_wellPathGeometry = new RigWellPath();
}
QString name = wellName.c_str(); QString name = wellName.c_str();
if (!name.trimmed().isEmpty())
{
// Do not overwrite the name aquired from a line above, if this line is empty
fileWellDataArray.back().m_name = name.trimmed(); fileWellDataArray.back().m_name = name.trimmed();
} }
hasReadWellPointInCurrentWell = false;
}
}
} }
} }
} }