mirror of
https://github.com/OPM/ResInsight.git
synced 2024-12-29 10:21:54 -06:00
Avoid hardcoded requirements for headers of RFT pressure files
Parsing "PSIA FEET" did not work, as "BARSA METRES" was the only supported unit. Keep special handling of header and date, and skip all other lines containing text or comment.
This commit is contained in:
parent
d1d987f522
commit
d4f97d8415
@ -19,15 +19,13 @@
|
||||
#include "RifPressureDepthTextFileReader.h"
|
||||
|
||||
#include "RiaDateStringParser.h"
|
||||
#include "RiaDefines.h"
|
||||
|
||||
#include "RigPressureDepthData.h"
|
||||
|
||||
#include "RifFileParseTools.h"
|
||||
|
||||
#include "cafAssert.h"
|
||||
|
||||
#include <QFile>
|
||||
#include <QRegularExpression>
|
||||
#include <QTextStream>
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@ -43,9 +41,20 @@ std::pair<std::vector<RigPressureDepthData>, QString> RifPressureDepthTextFileRe
|
||||
return std::make_pair( items, QString( "Unable to open file: %1" ).arg( filePath ) );
|
||||
}
|
||||
|
||||
return parse( file.readAll() );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
std::pair<std::vector<RigPressureDepthData>, QString> RifPressureDepthTextFileReader::parse( const QString& content )
|
||||
{
|
||||
std::vector<RigPressureDepthData> items;
|
||||
|
||||
QString separator = " ";
|
||||
|
||||
QTextStream in( &file );
|
||||
QString streamContent( content );
|
||||
QTextStream in( &streamContent );
|
||||
while ( !in.atEnd() )
|
||||
{
|
||||
QString line = in.readLine();
|
||||
@ -64,7 +73,7 @@ std::pair<std::vector<RigPressureDepthData>, QString> RifPressureDepthTextFileRe
|
||||
items.back().setTimeStep( date.value() );
|
||||
}
|
||||
}
|
||||
else if ( isPropertiesLine( line ) || isUnitsLine( line ) || isCommentLine( line ) )
|
||||
else if ( containsLetters( line ) || isCommentLine( line ) )
|
||||
{
|
||||
// Ignored.
|
||||
}
|
||||
@ -105,19 +114,10 @@ bool RifPressureDepthTextFileReader::isDateLine( const QString& line )
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RifPressureDepthTextFileReader::isPropertiesLine( const QString& line )
|
||||
bool RifPressureDepthTextFileReader::containsLetters( const QString& line )
|
||||
{
|
||||
// TODO: this might be to strict..
|
||||
return line.startsWith( "PRESSURE DEPTH" );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RifPressureDepthTextFileReader::isUnitsLine( const QString& line )
|
||||
{
|
||||
// TODO: this might be to strict..
|
||||
return line.startsWith( "BARSA METRES" );
|
||||
QRegularExpression regex( "[a-zA-Z]" );
|
||||
return regex.match( line ).hasMatch();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@ -152,8 +152,6 @@ std::optional<QDateTime> RifPressureDepthTextFileReader::parseDateLine( const QS
|
||||
QStringList values = RifFileParseTools::splitLineAndTrim( line, " ", skipEmptyParts );
|
||||
if ( values.size() != 2 ) return {};
|
||||
|
||||
CAF_ASSERT( values[0] == "DATE" );
|
||||
|
||||
// Second value is depth
|
||||
QDateTime dateTime = RiaDateStringParser::parseDateString( values[1], RiaDateStringParser::OrderPreference::DAY_FIRST );
|
||||
if ( !dateTime.isValid() ) return {};
|
||||
|
@ -21,7 +21,6 @@
|
||||
#include <QDateTime>
|
||||
#include <QString>
|
||||
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <vector>
|
||||
|
||||
@ -34,13 +33,13 @@ class RifPressureDepthTextFileReader
|
||||
{
|
||||
public:
|
||||
static std::pair<std::vector<RigPressureDepthData>, QString> readFile( const QString& fileName );
|
||||
static std::pair<std::vector<RigPressureDepthData>, QString> parse( const QString& content );
|
||||
|
||||
private:
|
||||
static bool isHeaderLine( const QString& line );
|
||||
static bool isCommentLine( const QString& line );
|
||||
static bool isDateLine( const QString& line );
|
||||
static bool isPropertiesLine( const QString& line );
|
||||
static bool isUnitsLine( const QString& line );
|
||||
static bool containsLetters( const QString& line );
|
||||
|
||||
static std::optional<std::pair<double, double>> parseDataLine( const QString& line );
|
||||
static std::optional<QDateTime> parseDateLine( const QString& line );
|
||||
|
@ -62,3 +62,33 @@ TEST( RifPressureDepthTextFileReaderTest, LoadFileNonExistingFiles )
|
||||
EXPECT_FALSE( errorMessage.isEmpty() );
|
||||
EXPECT_EQ( 0u, items.size() );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST( RifPressureDepthTextFileReaderTest, FieldUnitData )
|
||||
{
|
||||
auto content = R"(
|
||||
--TVDMSL
|
||||
RFT
|
||||
--
|
||||
WELLNAME 'A1'
|
||||
DATE 18-NOV-2018
|
||||
PRESSURE DEPTH
|
||||
PSIA FEET
|
||||
12008.00 22640.66
|
||||
12020.40 22674.44
|
||||
\n)";
|
||||
|
||||
auto [items, errorMessage] = RifPressureDepthTextFileReader::parse( content );
|
||||
|
||||
EXPECT_TRUE( errorMessage.isEmpty() );
|
||||
ASSERT_EQ( 1u, items.size() );
|
||||
|
||||
EXPECT_EQ( "A1", items[0].wellName().toStdString() );
|
||||
std::vector<std::pair<double, double>> values0 = items[0].getPressureDepthValues();
|
||||
EXPECT_EQ( 2u, values0.size() );
|
||||
double delta = 0.001;
|
||||
EXPECT_NEAR( 12008.0, values0[0].first, delta );
|
||||
EXPECT_NEAR( 22640.66, values0[0].second, delta );
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user