mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-09 23:16:00 -06:00
#157 Parse and use PATHS alias when reading faults
This commit is contained in:
parent
c869492de2
commit
60b2788374
@ -45,6 +45,7 @@ QString includeKeyword("INCLUDE");
|
||||
QString faultsKeyword("FAULTS");
|
||||
QString editKeyword("EDIT");
|
||||
QString gridKeyword("GRID");
|
||||
QString pathsKeyword("PATHS");
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@ -364,6 +365,72 @@ void RifEclipseInputFileTools::findKeywordsOnFile(const QString &fileName, std::
|
||||
while (lineLength != -1);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RifEclipseInputFileTools::parseAndReadPathAliasKeyword(const QString &fileName, std::vector< std::pair<QString, QString> >* pathAliasDefinitions)
|
||||
{
|
||||
char buf[1024];
|
||||
|
||||
QFile data(fileName);
|
||||
data.open(QFile::ReadOnly);
|
||||
|
||||
QString line;
|
||||
qint64 lineLength = -1;
|
||||
|
||||
bool foundPathsKeyword = false;
|
||||
|
||||
do
|
||||
{
|
||||
lineLength = data.readLine(buf, sizeof(buf));
|
||||
if (lineLength > 0)
|
||||
{
|
||||
line = QString::fromAscii(buf);
|
||||
if (line.size() && (line[0].isLetter() || foundPathsKeyword))
|
||||
{
|
||||
line = line.trimmed();
|
||||
|
||||
if (line == gridKeyword)
|
||||
{
|
||||
return;
|
||||
}
|
||||
else if (line == pathsKeyword)
|
||||
{
|
||||
foundPathsKeyword = true;
|
||||
}
|
||||
else if (foundPathsKeyword)
|
||||
{
|
||||
if (line.startsWith("/", Qt::CaseInsensitive))
|
||||
{
|
||||
// Detected end of keyword data section
|
||||
return;
|
||||
}
|
||||
else if (line.startsWith("--", Qt::CaseInsensitive))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Replace tab with space to be able to split the string using space as splitter
|
||||
line.replace("\t", " ");
|
||||
|
||||
// Remove character ' used to mark start and end of fault name, possibly also around face definition; 'I+'
|
||||
line.remove("'");
|
||||
|
||||
QStringList entries = line.split(" ", QString::SkipEmptyParts);
|
||||
if (entries.size() < 2)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
pathAliasDefinitions->push_back(std::make_pair(entries[0], entries[1]));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} while (!data.atEnd());
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Reads the property data requested into the \a reservoir, overwriting any previous
|
||||
/// properties with the same name.
|
||||
@ -688,10 +755,7 @@ void RifEclipseInputFileTools::readFaultsInGridSection(const QString& fileName,
|
||||
return;
|
||||
}
|
||||
|
||||
QString gridKeyword("GRID");
|
||||
|
||||
// Search for keyword grid
|
||||
|
||||
qint64 gridPos = findKeyword(gridKeyword, data, 0);
|
||||
if (gridPos < 0)
|
||||
{
|
||||
@ -700,7 +764,10 @@ void RifEclipseInputFileTools::readFaultsInGridSection(const QString& fileName,
|
||||
|
||||
bool isEditKeywordDetected = false;
|
||||
|
||||
readFaultsAndParseIncludeStatementsRecursively(data, gridPos, faults, filenamesWithFaults, &isEditKeywordDetected);
|
||||
std::vector< std::pair<QString, QString> > pathAliasDefinitions;
|
||||
parseAndReadPathAliasKeyword(fileName, &pathAliasDefinitions);
|
||||
|
||||
readFaultsAndParseIncludeStatementsRecursively(data, gridPos, pathAliasDefinitions, faults, filenamesWithFaults, &isEditKeywordDetected);
|
||||
}
|
||||
|
||||
|
||||
@ -753,7 +820,12 @@ qint64 RifEclipseInputFileTools::findKeyword(const QString& keyword, QFile& file
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RifEclipseInputFileTools::readFaultsAndParseIncludeStatementsRecursively(QFile& file, qint64 startPos, cvf::Collection<RigFault>* faults, std::vector<QString>* filenamesWithFaults, bool* isEditKeywordDetected)
|
||||
bool RifEclipseInputFileTools::readFaultsAndParseIncludeStatementsRecursively( QFile& file,
|
||||
qint64 startPos,
|
||||
const std::vector< std::pair<QString, QString> >& pathAliasDefinitions,
|
||||
cvf::Collection<RigFault>* faults,
|
||||
std::vector<QString>* filenamesWithFaults,
|
||||
bool* isEditKeywordDetected)
|
||||
{
|
||||
QString line;
|
||||
|
||||
@ -807,6 +879,13 @@ bool RifEclipseInputFileTools::readFaultsAndParseIncludeStatementsRecursively(QF
|
||||
|
||||
// Read include file name, and both relative and absolute path is supported
|
||||
QString includeFilename = line.mid(firstQuote + 1, lastQuote - firstQuote - 1);
|
||||
|
||||
for (auto entry : pathAliasDefinitions)
|
||||
{
|
||||
QString textToReplace = "$" + entry.first;
|
||||
includeFilename.replace(textToReplace, entry.second);
|
||||
}
|
||||
|
||||
QFileInfo fi(currentFileFolder, includeFilename);
|
||||
if (fi.exists())
|
||||
{
|
||||
@ -816,7 +895,7 @@ bool RifEclipseInputFileTools::readFaultsAndParseIncludeStatementsRecursively(QF
|
||||
{
|
||||
//qDebug() << "Found include statement, and start parsing of\n " << absoluteFilename;
|
||||
|
||||
if (!readFaultsAndParseIncludeStatementsRecursively(includeFile, 0, faults, filenamesWithFaults, isEditKeywordDetected))
|
||||
if (!readFaultsAndParseIncludeStatementsRecursively(includeFile, 0, pathAliasDefinitions, faults, filenamesWithFaults, isEditKeywordDetected))
|
||||
{
|
||||
qDebug() << "Error when parsing include file : " << absoluteFilename;
|
||||
}
|
||||
|
@ -69,12 +69,19 @@ public:
|
||||
static void readFaults(QFile &data, qint64 filePos, cvf::Collection<RigFault>* faults, bool* isEditKeywordDetected);
|
||||
static void findKeywordsOnFile(const QString &fileName, std::vector< RifKeywordAndFilePos >* keywords);
|
||||
|
||||
static void parseAndReadPathAliasKeyword(const QString &fileName, std::vector< std::pair<QString, QString> >* pathAliasDefinitions);
|
||||
|
||||
static const std::vector<QString>& knownPropertyKeywords();
|
||||
|
||||
static bool writePropertyToTextFile(const QString& fileName, RigCaseData* eclipseCase, size_t timeStep, const QString& resultName, const QString& eclipseKeyWord);
|
||||
static bool writeBinaryResultToTextFile(const QString& fileName, RigCaseData* eclipseCase, RifReaderInterface::PorosityModelResultType porosityModel, size_t timeStep, const QString& resultName, const QString& eclipseKeyWord, const double undefinedValue);
|
||||
|
||||
static bool readFaultsAndParseIncludeStatementsRecursively(QFile& file, qint64 startPos, cvf::Collection<RigFault>* faults, std::vector<QString>* filenamesWithFaults, bool* isEditKeywordDetected);
|
||||
static bool readFaultsAndParseIncludeStatementsRecursively( QFile& file,
|
||||
qint64 startPos,
|
||||
const std::vector< std::pair<QString, QString> >& pathAliasDefinitions,
|
||||
cvf::Collection<RigFault>* faults,
|
||||
std::vector<QString>* filenamesWithFaults,
|
||||
bool* isEditKeywordDetected);
|
||||
|
||||
static cvf::StructGridInterface::FaceEnum faceEnumFromText(const QString& faceString);
|
||||
|
||||
|
@ -4,7 +4,32 @@
|
||||
|
||||
#include "RifEclipseInputFileTools.h"
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/*
|
||||
TEST(RifEclipseInputFileToolsTest, PathsKeyword)
|
||||
{
|
||||
QString filename = "d:/Models/Statoil/troll_Ref2014/T07-4A-W2014-06.DATA";
|
||||
//QString filename = "d:/Models/Statoil/!myTestWithWellLog/TEST10K_FLT_LGR_NNC.DATA";
|
||||
|
||||
std::vector<std::pair<QString, QString>> pathEntries;
|
||||
|
||||
RifEclipseInputFileTools::parseAndReadPathAliasKeyword(filename, &pathEntries);
|
||||
|
||||
for (auto entry : pathEntries)
|
||||
{
|
||||
qDebug() << entry.first << " " << entry.second;
|
||||
}
|
||||
|
||||
std::vector<QString> filenamesWithFaults;
|
||||
cvf::Collection<RigFault> faults;
|
||||
RifEclipseInputFileTools::readFaultsInGridSection(filename, &faults, &filenamesWithFaults);
|
||||
|
||||
}
|
||||
*/
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
|
Loading…
Reference in New Issue
Block a user