mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
#4169 Saturation-Pressure plot : Read keyword data and add test files
This commit is contained in:
parent
ea9503d065
commit
42f93d3a5a
@ -785,6 +785,185 @@ bool RifEclipseInputFileTools::readFaultsAndParseIncludeStatementsRecursively(
|
||||
return true;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RifEclipseInputFileTools::readKeywordAndParseIncludeStatementsRecursively(
|
||||
const QString& keyword,
|
||||
const QString& keywordToStopParsing,
|
||||
QFile& file,
|
||||
qint64 startPos,
|
||||
const std::vector<std::pair<QString, QString>>& pathAliasDefinitions,
|
||||
QStringList* keywordDataContent,
|
||||
std::vector<QString>* filenamesContainingKeyword,
|
||||
bool* isStopParsingKeywordDetected,
|
||||
const QString& faultIncludeFileAbsolutePathPrefix /* rename to includeStatementAbsolutePathPrefix */)
|
||||
{
|
||||
QString line;
|
||||
|
||||
if (!file.seek(startPos))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool continueParsing = true;
|
||||
|
||||
do
|
||||
{
|
||||
line = file.readLine();
|
||||
line = line.trimmed();
|
||||
|
||||
if (line.startsWith("--", Qt::CaseInsensitive))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!keywordToStopParsing.isEmpty() && line.startsWith(keywordToStopParsing, Qt::CaseInsensitive))
|
||||
{
|
||||
if (isStopParsingKeywordDetected)
|
||||
{
|
||||
*isStopParsingKeywordDetected = true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if (line.startsWith(includeKeyword, Qt::CaseInsensitive))
|
||||
{
|
||||
line = file.readLine();
|
||||
line = line.trimmed();
|
||||
|
||||
while (line.startsWith("--", Qt::CaseInsensitive))
|
||||
{
|
||||
line = file.readLine();
|
||||
line = line.trimmed();
|
||||
}
|
||||
|
||||
int firstQuote = line.indexOf("'");
|
||||
int lastQuote = line.lastIndexOf("'");
|
||||
|
||||
if (!(firstQuote < 0 || lastQuote < 0 || firstQuote == lastQuote))
|
||||
{
|
||||
QDir currentFileFolder;
|
||||
{
|
||||
QFileInfo fi(file.fileName());
|
||||
currentFileFolder = fi.absoluteDir();
|
||||
}
|
||||
|
||||
// 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);
|
||||
}
|
||||
|
||||
#ifdef WIN32
|
||||
if (includeFilename.startsWith('/'))
|
||||
{
|
||||
// Absolute UNIX path, prefix on Windows
|
||||
includeFilename = faultIncludeFileAbsolutePathPrefix + includeFilename;
|
||||
}
|
||||
#endif
|
||||
|
||||
QFileInfo fi(currentFileFolder, includeFilename);
|
||||
if (fi.exists())
|
||||
{
|
||||
QString absoluteFilename = fi.canonicalFilePath();
|
||||
QFile includeFile(absoluteFilename);
|
||||
if (includeFile.open(QFile::ReadOnly))
|
||||
{
|
||||
// qDebug() << "Found include statement, and start parsing of\n " << absoluteFilename;
|
||||
|
||||
if (!readKeywordAndParseIncludeStatementsRecursively(keyword,
|
||||
keywordToStopParsing,
|
||||
includeFile,
|
||||
0,
|
||||
pathAliasDefinitions,
|
||||
keywordDataContent,
|
||||
filenamesContainingKeyword,
|
||||
isStopParsingKeywordDetected,
|
||||
faultIncludeFileAbsolutePathPrefix))
|
||||
{
|
||||
qDebug() << "Error when parsing include file : " << absoluteFilename;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (line.startsWith(keyword, Qt::CaseInsensitive))
|
||||
{
|
||||
if (!line.contains("/"))
|
||||
{
|
||||
readKeywordDataContent(file, file.pos(), keywordDataContent, isStopParsingKeywordDetected);
|
||||
filenamesContainingKeyword->push_back(file.fileName());
|
||||
}
|
||||
}
|
||||
|
||||
if (isStopParsingKeywordDetected && *isStopParsingKeywordDetected)
|
||||
{
|
||||
continueParsing = false;
|
||||
}
|
||||
|
||||
if (file.atEnd())
|
||||
{
|
||||
continueParsing = false;
|
||||
}
|
||||
|
||||
} while (continueParsing);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RifEclipseInputFileTools::readKeywordDataContent(QFile& data,
|
||||
qint64 filePos,
|
||||
QStringList* textContent,
|
||||
bool* isEditKeywordDetected)
|
||||
{
|
||||
if (!data.seek(filePos))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// This function assumes the keyword is read from file, and the file pointer is pointing to the first line containing data for
|
||||
// the keyword
|
||||
|
||||
do
|
||||
{
|
||||
QString line = data.readLine();
|
||||
line = line.trimmed();
|
||||
|
||||
if (line.startsWith("--", Qt::CaseInsensitive))
|
||||
{
|
||||
// Skip comment lines
|
||||
continue;
|
||||
}
|
||||
else if (line.startsWith("/", Qt::CaseInsensitive))
|
||||
{
|
||||
// Detected end of keyword data section
|
||||
return;
|
||||
}
|
||||
else if (line.startsWith(editKeyword, Qt::CaseInsensitive))
|
||||
{
|
||||
// End parsing when edit keyword is detected
|
||||
|
||||
if (isEditKeywordDetected)
|
||||
{
|
||||
*isEditKeywordDetected = true;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
textContent->push_back(line);
|
||||
|
||||
} while (!data.atEnd());
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
@ -82,6 +82,22 @@ public:
|
||||
bool* isEditKeywordDetected,
|
||||
const QString& faultIncludeFileAbsolutePathPrefix);
|
||||
|
||||
|
||||
|
||||
static bool readKeywordAndParseIncludeStatementsRecursively(const QString& keyword,
|
||||
const QString& keywordToStopParsing,
|
||||
QFile& file,
|
||||
qint64 startPos,
|
||||
const std::vector< std::pair<QString, QString> >& pathAliasDefinitions,
|
||||
QStringList* keywordDataContent,
|
||||
std::vector<QString>* filenamesContainingKeyword,
|
||||
bool* isEditKeywordDetected,
|
||||
const QString& faultIncludeFileAbsolutePathPrefix // rename to includeStatementAbsolutePathPrefix
|
||||
);
|
||||
|
||||
static void readKeywordDataContent(QFile &data, qint64 filePos, QStringList* textContent, bool* isEditKeywordDetected);
|
||||
|
||||
|
||||
static cvf::StructGridInterface::FaceEnum faceEnumFromText(const QString& faceString);
|
||||
|
||||
private:
|
||||
|
@ -1,10 +1,11 @@
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
#include "RiaTestDataDirectory.h"
|
||||
#include "RifEclipseInputFileTools.h"
|
||||
#include "RigEclipseCaseData.h"
|
||||
|
||||
#include "RifEclipseInputFileTools.h"
|
||||
|
||||
#include <QDebug>
|
||||
#include <QFile>
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
@ -149,3 +150,90 @@ TEST(RifEclipseInputFileToolsTest, FaultFaces)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(RifEclipseInputFileToolsTest, EquilData)
|
||||
{
|
||||
static const QString testDataRootFolder = QString("%1/ParsingOfDataKeywords/").arg(TEST_DATA_DIR);
|
||||
|
||||
{
|
||||
QString fileName = testDataRootFolder + "simulation/MY_CASE.DATA";
|
||||
|
||||
QFile data(fileName);
|
||||
if (!data.open(QFile::ReadOnly))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
std::vector<std::pair<QString, QString>> pathAliasDefinitions;
|
||||
RifEclipseInputFileTools::parseAndReadPathAliasKeyword(fileName, &pathAliasDefinitions);
|
||||
|
||||
const QString keyword("EQUIL");
|
||||
const QString keywordToStopParsing;
|
||||
const qint64 startPositionInFile = 0;
|
||||
QStringList keywordContent;
|
||||
std::vector<QString> fileNamesContainingKeyword;
|
||||
bool isEditKeywordDetected = false;
|
||||
const QString includeStatementAbsolutePathPrefix;
|
||||
|
||||
RifEclipseInputFileTools::readKeywordAndParseIncludeStatementsRecursively(keyword,
|
||||
keywordToStopParsing,
|
||||
data,
|
||||
startPositionInFile,
|
||||
pathAliasDefinitions,
|
||||
&keywordContent,
|
||||
&fileNamesContainingKeyword,
|
||||
&isEditKeywordDetected,
|
||||
includeStatementAbsolutePathPrefix);
|
||||
|
||||
for (const auto& s : keywordContent)
|
||||
{
|
||||
qDebug() << s;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(RifEclipseInputFileToolsTest, FaultData)
|
||||
{
|
||||
static const QString testDataRootFolder = QString("%1/ParsingOfDataKeywords/").arg(TEST_DATA_DIR);
|
||||
|
||||
{
|
||||
QString fileName = testDataRootFolder + "simulation/MY_CASE.DATA";
|
||||
|
||||
QFile data(fileName);
|
||||
if (!data.open(QFile::ReadOnly))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
std::vector<std::pair<QString, QString>> pathAliasDefinitions;
|
||||
RifEclipseInputFileTools::parseAndReadPathAliasKeyword(fileName, &pathAliasDefinitions);
|
||||
|
||||
const QString keyword("FAULTS");
|
||||
const QString keywordToStopParsing;
|
||||
const qint64 startPositionInFile = 0;
|
||||
QStringList keywordContent;
|
||||
std::vector<QString> fileNamesContainingKeyword;
|
||||
bool isEditKeywordDetected = false;
|
||||
const QString includeStatementAbsolutePathPrefix;
|
||||
|
||||
RifEclipseInputFileTools::readKeywordAndParseIncludeStatementsRecursively(keyword,
|
||||
keywordToStopParsing,
|
||||
data,
|
||||
startPositionInFile,
|
||||
pathAliasDefinitions,
|
||||
&keywordContent,
|
||||
&fileNamesContainingKeyword,
|
||||
&isEditKeywordDetected,
|
||||
includeStatementAbsolutePathPrefix);
|
||||
for (const auto& s : keywordContent)
|
||||
{
|
||||
qDebug() << s;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,13 @@
|
||||
EQUIL
|
||||
-- Datum P-datum WOC Pcwoc GOC Pcgoc RSVD RSVD
|
||||
1950 634.8 1940 0.00 3904 0.00 1 1 / asdf
|
||||
1950 634.8 1944 0.00 3904 0.00 2 2 / asdf
|
||||
1950 634.8 1898.5 0.00 3898.5 0.00 3 3 / sdfsdfsdf
|
||||
1950 634 2020 0.00 4020 0.00 4 4 / ssss
|
||||
1821.94 629.35 1883 0.00 3000 0.00 5 5 20/ sdfsdf
|
||||
1821.94 629.35 1877 0.00 3000 0.00 6 6 / abab
|
||||
1950 634.8 1944 0.00 3650 0.00 7 7 / aaa
|
||||
1950 634.8 1944 0.00 3650 0.00 8 8 / bbb
|
||||
1950 634.8 1820.5 0.00 3811 0.00 9 9 / ddd
|
||||
1950 634.8 1892 0.00 3821 0.00 10 10 / sdf
|
||||
-- 1950 634.8 1913 0.00 3871 0.00 11 11 / sdf
|
@ -0,0 +1,6 @@
|
||||
INCLUDE
|
||||
'../include/solution/equilibiration.inc' /
|
||||
|
||||
INCLUDE
|
||||
'../include/grid/FAULT_JUN_05.INC'/
|
||||
|
Loading…
Reference in New Issue
Block a user