Skip to content

Commit

Permalink
Avoid hardcoded requirements for headers of RFT pressure files
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
magnesj committed Mar 19, 2024
1 parent d1d987f commit d4f97d8
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 22 deletions.
36 changes: 17 additions & 19 deletions ApplicationLibCode/FileInterface/RifPressureDepthTextFileReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>

//--------------------------------------------------------------------------------------------------
Expand All @@ -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();
Expand All @@ -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.
}
Expand Down Expand Up @@ -105,19 +114,10 @@ bool RifPressureDepthTextFileReader::isDateLine( const QString& line )
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RifPressureDepthTextFileReader::isPropertiesLine( const QString& line )
{
// TODO: this might be to strict..
return line.startsWith( "PRESSURE DEPTH" );
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RifPressureDepthTextFileReader::isUnitsLine( const QString& line )
bool RifPressureDepthTextFileReader::containsLetters( const QString& line )
{
// TODO: this might be to strict..
return line.startsWith( "BARSA METRES" );
QRegularExpression regex( "[a-zA-Z]" );
return regex.match( line ).hasMatch();
}

//--------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -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 {};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
#include <QDateTime>
#include <QString>

#include <memory>
#include <optional>
#include <vector>

Expand All @@ -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 );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}

0 comments on commit d4f97d8

Please sign in to comment.