mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
#5001 Add Well Measurement reader.
This commit is contained in:
@@ -35,6 +35,7 @@ ${CMAKE_CURRENT_LIST_DIR}/RifDataSourceForRftPltQMetaType.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RifEclipseUserDataKeywordTools.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RifCsvUserData.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RifCsvUserDataParser.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RifWellMeasurementReader.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RifWellPathFormationReader.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RifWellPathFormationsImporter.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RifElementPropertyTableReader.h
|
||||
@@ -88,6 +89,7 @@ ${CMAKE_CURRENT_LIST_DIR}/RifDataSourceForRftPlt.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RifEclipseUserDataKeywordTools.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RifCsvUserData.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RifCsvUserDataParser.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RifWellMeasurementReader.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RifWellPathFormationReader.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RifWellPathFormationsImporter.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RifElementPropertyTableReader.cpp
|
||||
|
||||
209
ApplicationCode/FileInterface/RifWellMeasurementReader.cpp
Normal file
209
ApplicationCode/FileInterface/RifWellMeasurementReader.cpp
Normal file
@@ -0,0 +1,209 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2019- Equinor ASA
|
||||
//
|
||||
// ResInsight is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
// FITNESS FOR A PARTICULAR PURPOSE.
|
||||
//
|
||||
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
|
||||
// for more details.
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "RifWellMeasurementReader.h"
|
||||
|
||||
#include "RifFileParseTools.h"
|
||||
|
||||
#include <QDate>
|
||||
#include <QFileInfo>
|
||||
#include <QTextStream>
|
||||
|
||||
//==================================================================================================
|
||||
///
|
||||
//==================================================================================================
|
||||
void RifWellMeasurementReader::readWellMeasurements( std::vector<RifWellMeasurement>& wellMeasurements,
|
||||
const QStringList& filePaths )
|
||||
{
|
||||
for ( const QString& filePath : filePaths )
|
||||
{
|
||||
try
|
||||
{
|
||||
readWellMeasurements( wellMeasurements, filePath );
|
||||
}
|
||||
catch ( FileParseException& )
|
||||
{
|
||||
// Delete all well measurements and rethrow exception
|
||||
wellMeasurements.clear();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//==================================================================================================
|
||||
///
|
||||
//==================================================================================================
|
||||
void RifWellMeasurementReader::readWellMeasurements( std::vector<RifWellMeasurement>& wellMeasurements,
|
||||
const QString& filePath )
|
||||
{
|
||||
QFile file( filePath );
|
||||
if ( !file.open( QIODevice::ReadOnly | QIODevice::Text ) )
|
||||
{
|
||||
throw FileParseException( QString( "Unable to open file: %1" ).arg( filePath ) );
|
||||
}
|
||||
|
||||
QTextStream in( &file );
|
||||
int lineNumber = 1;
|
||||
while ( !in.atEnd() )
|
||||
{
|
||||
QString line = in.readLine();
|
||||
if ( !isEmptyLine( line ) && !isCommentLine( line ) )
|
||||
{
|
||||
RifWellMeasurement wellMeasurement = parseWellMeasurement( line, lineNumber, filePath );
|
||||
wellMeasurements.push_back( wellMeasurement );
|
||||
}
|
||||
|
||||
lineNumber++;
|
||||
}
|
||||
}
|
||||
|
||||
//==================================================================================================
|
||||
///
|
||||
//==================================================================================================
|
||||
RifWellMeasurement
|
||||
RifWellMeasurementReader::parseWellMeasurement( const QString& line, int lineNumber, const QString& filePath )
|
||||
{
|
||||
QStringList tokens = tokenize( line, "," );
|
||||
|
||||
if ( tokens.size() != 7 )
|
||||
{
|
||||
throw FileParseException( QString( "Incomplete data on line %1: %2" ).arg( lineNumber ).arg( filePath ) );
|
||||
}
|
||||
|
||||
// Check for unexpected empty tokens
|
||||
QStringList nameOfNonEmptyTokens;
|
||||
nameOfNonEmptyTokens << "Well Name"
|
||||
<< "Measured Depth"
|
||||
<< "Date"
|
||||
<< "Value"
|
||||
<< "Kind";
|
||||
verifyNonEmptyTokens( tokens, nameOfNonEmptyTokens, lineNumber, filePath );
|
||||
|
||||
RifWellMeasurement wellMeasurement;
|
||||
wellMeasurement.wellName = tokens[0];
|
||||
wellMeasurement.MD = parseDouble( tokens[1], "Measured Depth", lineNumber, filePath );
|
||||
wellMeasurement.date = parseDate( tokens[2], "Date", lineNumber, filePath );
|
||||
wellMeasurement.value = parseDouble( tokens[3], "Value", lineNumber, filePath );
|
||||
wellMeasurement.kind = tokens[4];
|
||||
wellMeasurement.quality = parseInt( tokens[5], "Quality", lineNumber, filePath );
|
||||
wellMeasurement.remark = tokens[6];
|
||||
wellMeasurement.filePath = filePath;
|
||||
return wellMeasurement;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QStringList RifWellMeasurementReader::tokenize( const QString& line, const QString& separator )
|
||||
{
|
||||
return RifFileParseTools::splitLineAndTrim( line, separator );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QDate RifWellMeasurementReader::parseDate( const QString& token,
|
||||
const QString& propertyName,
|
||||
int lineNumber,
|
||||
const QString& filePath )
|
||||
{
|
||||
QDate date = QDate::fromString( token, Qt::ISODate );
|
||||
if ( !date.isValid() )
|
||||
{
|
||||
throw FileParseException( QString( "Invalid date format (must be ISO 8601) for '%1' on line %2: %3" )
|
||||
.arg( propertyName )
|
||||
.arg( lineNumber )
|
||||
.arg( filePath ) );
|
||||
}
|
||||
|
||||
return date;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
double RifWellMeasurementReader::parseDouble( const QString& token,
|
||||
const QString& propertyName,
|
||||
int lineNumber,
|
||||
const QString& filePath )
|
||||
{
|
||||
bool isOk = false;
|
||||
double value = token.toDouble( &isOk );
|
||||
if ( !isOk )
|
||||
{
|
||||
throw FileParseException(
|
||||
QString( "Invalid number for '%1' on line %2: %3" ).arg( propertyName ).arg( lineNumber ).arg( filePath ) );
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
int RifWellMeasurementReader::parseInt( const QString& token,
|
||||
const QString& propertyName,
|
||||
int lineNumber,
|
||||
const QString& filePath )
|
||||
{
|
||||
bool isOk = false;
|
||||
int value = token.toInt( &isOk );
|
||||
if ( !isOk )
|
||||
{
|
||||
throw FileParseException(
|
||||
QString( "Invalid number for '%1' on line %2: %3" ).arg( propertyName ).arg( lineNumber ).arg( filePath ) );
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RifWellMeasurementReader::isEmptyLine( const QString& line )
|
||||
{
|
||||
return line.trimmed().isEmpty();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RifWellMeasurementReader::isCommentLine( const QString& line )
|
||||
{
|
||||
return line.startsWith( "#" );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RifWellMeasurementReader::verifyNonEmptyTokens( const QStringList& tokens,
|
||||
const QStringList& nameOfNonEmptyTokens,
|
||||
int lineNumber,
|
||||
const QString& filePath )
|
||||
{
|
||||
for ( int i = 0; i < nameOfNonEmptyTokens.size(); ++i )
|
||||
{
|
||||
if ( tokens[i].isEmpty() )
|
||||
{
|
||||
throw FileParseException( QString( "Unexpected empty '%1' on line %2: %3" )
|
||||
.arg( nameOfNonEmptyTokens[i] )
|
||||
.arg( lineNumber )
|
||||
.arg( filePath ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
61
ApplicationCode/FileInterface/RifWellMeasurementReader.h
Normal file
61
ApplicationCode/FileInterface/RifWellMeasurementReader.h
Normal file
@@ -0,0 +1,61 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2017- Statoil ASA
|
||||
//
|
||||
// ResInsight is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
// FITNESS FOR A PARTICULAR PURPOSE.
|
||||
//
|
||||
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
|
||||
// for more details.
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include <QDate>
|
||||
#include <QString>
|
||||
|
||||
struct RifWellMeasurement
|
||||
{
|
||||
QString wellName;
|
||||
double MD;
|
||||
double value;
|
||||
QDate date;
|
||||
int quality;
|
||||
QString kind;
|
||||
QString remark;
|
||||
QString filePath;
|
||||
};
|
||||
|
||||
//==================================================================================================
|
||||
///
|
||||
//==================================================================================================
|
||||
class RifWellMeasurementReader
|
||||
{
|
||||
public:
|
||||
static void readWellMeasurements( std::vector<RifWellMeasurement>& wellMeasurements, const QStringList& filePaths );
|
||||
|
||||
private:
|
||||
static void readWellMeasurements( std::vector<RifWellMeasurement>& wellMeasurements, const QString& filePath );
|
||||
static RifWellMeasurement parseWellMeasurement( const QString& line, int lineNumber, const QString& filePath );
|
||||
static QStringList tokenize( const QString& line, const QString& separator );
|
||||
static void verifyNonEmptyTokens( const QStringList& tokens,
|
||||
const QStringList& nameOfNonEmptyTokens,
|
||||
int lineNumber,
|
||||
const QString& filePath );
|
||||
|
||||
static QDate parseDate( const QString& token, const QString& propertyName, int lineNumber, const QString& filePath );
|
||||
static double parseDouble( const QString& token, const QString& propertyName, int lineNumber, const QString& filePath );
|
||||
static int parseInt( const QString& token, const QString& propertyName, int lineNumber, const QString& filePath );
|
||||
|
||||
static bool isEmptyLine( const QString& line );
|
||||
static bool isCommentLine( const QString& line );
|
||||
};
|
||||
Reference in New Issue
Block a user