Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow field units when importing RFT pressures #11302

Merged
merged 1 commit into from
Mar 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 );
}