mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
#9773 Import data from Reveal and StimPlan as summary case.
This commit is contained in:
@@ -78,6 +78,10 @@ set(SOURCE_GROUP_HEADER_FILES
|
||||
${CMAKE_CURRENT_LIST_DIR}/RifPressureDepthTextFileReader.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RifReaderPressureDepthData.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RifOpmGridTools.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RifCsvSummaryReader.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RifRevealSummaryCsvReader.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RifRevealCsvSectionSummaryReader.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RifStimPlanCsvSummaryReader.h
|
||||
)
|
||||
|
||||
set(SOURCE_GROUP_SOURCE_FILES
|
||||
@@ -157,6 +161,10 @@ set(SOURCE_GROUP_SOURCE_FILES
|
||||
${CMAKE_CURRENT_LIST_DIR}/RifPressureDepthTextFileReader.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RifReaderPressureDepthData.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RifOpmGridTools.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RifCsvSummaryReader.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RifRevealCsvSummaryReader.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RifRevealCsvSectionSummaryReader.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RifStimPlanCsvSummaryReader.cpp
|
||||
)
|
||||
|
||||
list(APPEND CODE_HEADER_FILES ${SOURCE_GROUP_HEADER_FILES})
|
||||
|
||||
147
ApplicationLibCode/FileInterface/RifCsvSummaryReader.cpp
Normal file
147
ApplicationLibCode/FileInterface/RifCsvSummaryReader.cpp
Normal file
@@ -0,0 +1,147 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2023- 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 "RifCsvSummaryReader.h"
|
||||
|
||||
#include "RiaDateStringParser.h"
|
||||
#include "RiaLogging.h"
|
||||
#include "RiaQDateTimeTools.h"
|
||||
|
||||
#include "RifCsvUserDataParser.h"
|
||||
#include "RifEclipseUserDataKeywordTools.h"
|
||||
#include "RifEclipseUserDataParserTools.h"
|
||||
|
||||
#include "cafUtils.h"
|
||||
|
||||
#include <QDateTime>
|
||||
#include <QFile>
|
||||
#include <QTextStream>
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RifCsvSummaryReader::RifCsvSummaryReader()
|
||||
{
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RifCsvSummaryReader::~RifCsvSummaryReader()
|
||||
{
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RifCsvSummaryReader::values( const RifEclipseSummaryAddress& resultAddress, std::vector<double>* values ) const
|
||||
{
|
||||
auto search = m_mapFromAddressToResultIndex.find( resultAddress );
|
||||
if ( search != m_mapFromAddressToResultIndex.end() )
|
||||
{
|
||||
size_t columnIndex = search->second;
|
||||
|
||||
const Column* ci = m_parser->columnInfo( columnIndex );
|
||||
if ( !ci ) return false;
|
||||
|
||||
values->clear();
|
||||
values->reserve( ci->values.size() );
|
||||
for ( double val : ci->values )
|
||||
{
|
||||
values->push_back( val );
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
std::vector<time_t> RifCsvSummaryReader::timeSteps( const RifEclipseSummaryAddress& resultAddress ) const
|
||||
{
|
||||
// First, check whether date time values exist for the current address
|
||||
auto search = m_mapFromAddressToResultIndex.find( resultAddress );
|
||||
if ( search != m_mapFromAddressToResultIndex.end() )
|
||||
{
|
||||
size_t index = m_mapFromAddressToResultIndex.at( resultAddress );
|
||||
if ( !m_parser->tableData().columnInfos()[index].dateTimeValues.empty() )
|
||||
{
|
||||
return m_parser->tableData().columnInfos()[index].dateTimeValues;
|
||||
}
|
||||
}
|
||||
|
||||
// Then check for a separate date time column
|
||||
int index = m_parser->tableData().dateTimeColumnIndex();
|
||||
if ( index >= 0 )
|
||||
{
|
||||
return m_parser->tableData().columnInfos()[index].dateTimeValues;
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
std::string RifCsvSummaryReader::unitName( const RifEclipseSummaryAddress& resultAddress ) const
|
||||
{
|
||||
auto search = m_mapFromAddressToResultIndex.find( resultAddress );
|
||||
if ( search != m_mapFromAddressToResultIndex.end() )
|
||||
{
|
||||
size_t columnIndex = search->second;
|
||||
|
||||
const Column* ci = m_parser->columnInfo( columnIndex );
|
||||
if ( ci )
|
||||
{
|
||||
return ci->unitName;
|
||||
}
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RiaDefines::EclipseUnitSystem RifCsvSummaryReader::unitSystem() const
|
||||
{
|
||||
return RiaDefines::EclipseUnitSystem::UNITS_UNKNOWN;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RifCsvSummaryReader::buildTimeStepsAndMappings()
|
||||
{
|
||||
auto tableData = m_parser->tableData();
|
||||
|
||||
for ( size_t columnIndex = 0; columnIndex < tableData.columnInfos().size(); columnIndex++ )
|
||||
{
|
||||
const Column& ci = tableData.columnInfos()[columnIndex];
|
||||
if ( ci.dataType == Column::NUMERIC )
|
||||
{
|
||||
RifEclipseSummaryAddress sumAddress = ci.summaryAddress;
|
||||
|
||||
m_allResultAddresses.insert( sumAddress );
|
||||
if ( sumAddress.isErrorResult() ) m_allErrorAddresses.insert( sumAddress );
|
||||
|
||||
m_mapFromAddressToResultIndex[sumAddress] = columnIndex;
|
||||
}
|
||||
}
|
||||
}
|
||||
56
ApplicationLibCode/FileInterface/RifCsvSummaryReader.h
Normal file
56
ApplicationLibCode/FileInterface/RifCsvSummaryReader.h
Normal file
@@ -0,0 +1,56 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2023- 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.
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "RifSummaryReaderInterface.h"
|
||||
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
class QString;
|
||||
|
||||
class RifCsvUserDataParser;
|
||||
class RifEclipseSummaryAddress;
|
||||
|
||||
//==================================================================================================
|
||||
//
|
||||
//
|
||||
//==================================================================================================
|
||||
class RifCsvSummaryReader : public RifSummaryReaderInterface
|
||||
{
|
||||
public:
|
||||
RifCsvSummaryReader();
|
||||
~RifCsvSummaryReader() override;
|
||||
|
||||
std::vector<time_t> timeSteps( const RifEclipseSummaryAddress& resultAddress ) const override;
|
||||
|
||||
bool values( const RifEclipseSummaryAddress& resultAddress, std::vector<double>* values ) const override;
|
||||
|
||||
std::string unitName( const RifEclipseSummaryAddress& resultAddress ) const override;
|
||||
|
||||
RiaDefines::EclipseUnitSystem unitSystem() const override;
|
||||
|
||||
protected:
|
||||
void buildTimeStepsAndMappings();
|
||||
|
||||
std::unique_ptr<RifCsvUserDataParser> m_parser;
|
||||
|
||||
std::map<RifEclipseSummaryAddress, size_t> m_mapFromAddressToResultIndex;
|
||||
};
|
||||
@@ -18,6 +18,7 @@
|
||||
|
||||
#include "RifCsvUserDataParser.h"
|
||||
|
||||
#include "RifEclipseSummaryAddress.h"
|
||||
#include "RifEclipseUserDataKeywordTools.h"
|
||||
#include "RifEclipseUserDataParserTools.h"
|
||||
#include "RifFileParseTools.h"
|
||||
@@ -276,7 +277,9 @@ QStringList RifCsvUserDataParser::timeColumnPreviewData( int lineCount, const As
|
||||
RifCsvUserDataParser::CsvLayout RifCsvUserDataParser::determineCsvLayout()
|
||||
{
|
||||
QTextStream* dataStream = openDataStream();
|
||||
QString firstLine;
|
||||
if ( !dataStream ) return LineBased;
|
||||
|
||||
QString firstLine;
|
||||
|
||||
QStringList headers;
|
||||
while ( !dataStream->atEnd() )
|
||||
@@ -309,7 +312,19 @@ bool RifCsvUserDataParser::parseColumnInfo( QTextStream* dataStream, const Ascii
|
||||
while ( !headerFound )
|
||||
{
|
||||
QString line = dataStream->readLine();
|
||||
if ( line.trimmed().isEmpty() ) continue;
|
||||
if ( line.trimmed().isEmpty() )
|
||||
{
|
||||
if ( !headerFound && dataStream->atEnd() )
|
||||
{
|
||||
// Handle empty stream
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Empty lines are skipped.
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
QStringList columnHeaders = RifFileParseTools::splitLineAndTrim( line, parseOptions.cellSeparator );
|
||||
|
||||
@@ -317,8 +332,9 @@ bool RifCsvUserDataParser::parseColumnInfo( QTextStream* dataStream, const Ascii
|
||||
QStringList unitTexts;
|
||||
QStringList names;
|
||||
|
||||
auto startOfLineWithDataValues = dataStream->pos();
|
||||
bool hasDataValues = false;
|
||||
auto startOfLineWithDataValues = dataStream->pos();
|
||||
bool hasDataValues = false;
|
||||
QString nameFromData;
|
||||
while ( !hasDataValues )
|
||||
{
|
||||
QString candidateLine = dataStream->readLine();
|
||||
@@ -327,7 +343,14 @@ bool RifCsvUserDataParser::parseColumnInfo( QTextStream* dataStream, const Ascii
|
||||
for ( const auto& text : candidateColumnHeaders )
|
||||
{
|
||||
if ( RiaStdStringTools::isNumber( text.toStdString(), parseOptions.locale.decimalPoint().toLatin1() ) )
|
||||
{
|
||||
hasDataValues = true;
|
||||
}
|
||||
else if ( nameFromData.isEmpty() )
|
||||
{
|
||||
// Keep the first non-number data field as a possible name.
|
||||
nameFromData = text;
|
||||
}
|
||||
}
|
||||
|
||||
if ( !hasDataValues && candidateColumnHeaders.size() == columnHeaders.size() )
|
||||
@@ -353,6 +376,23 @@ bool RifCsvUserDataParser::parseColumnInfo( QTextStream* dataStream, const Ascii
|
||||
{
|
||||
QString colName = RiaTextStringTools::trimAndRemoveDoubleSpaces( columnHeaders[iCol] );
|
||||
|
||||
QString unit;
|
||||
|
||||
// Check if unit is part of the column name in parentheses, e.g. "VECTOR (unit)".
|
||||
QRegExp exp( "\\((.*)\\)" );
|
||||
if ( exp.indexIn( colName ) >= 0 )
|
||||
{
|
||||
// "VECTOR (unit)" ==> "(unit)"
|
||||
QString fullCapture = exp.cap( 0 );
|
||||
// "VECTOR (unit)" ==> "unit"
|
||||
QString unitCapture = exp.cap( 1 );
|
||||
|
||||
unit = unitCapture;
|
||||
|
||||
// Remove unit from name
|
||||
colName = RiaTextStringTools::trimAndRemoveDoubleSpaces( colName.remove( fullCapture ) );
|
||||
}
|
||||
|
||||
if ( iCol < names.size() )
|
||||
{
|
||||
QString name = RiaTextStringTools::trimAndRemoveDoubleSpaces( names[iCol] );
|
||||
@@ -363,12 +403,17 @@ bool RifCsvUserDataParser::parseColumnInfo( QTextStream* dataStream, const Ascii
|
||||
}
|
||||
}
|
||||
|
||||
QString unit;
|
||||
if ( iCol < unitTexts.size() ) unit = unitTexts[iCol];
|
||||
|
||||
RifEclipseSummaryAddress addr = RifEclipseSummaryAddress::fromEclipseTextAddressParseErrorTokens( colName.toStdString() );
|
||||
Column col = Column::createColumnInfoFromCsvData( addr, unit.toStdString() );
|
||||
|
||||
// Create address of a give category if provided
|
||||
if ( parseOptions.defaultCategory == RifEclipseSummaryAddress::SummaryVarCategory::SUMMARY_WELL )
|
||||
addr = RifEclipseSummaryAddress::wellAddress( colName.toStdString(), nameFromData.toStdString() );
|
||||
else if ( parseOptions.defaultCategory == RifEclipseSummaryAddress::SummaryVarCategory::SUMMARY_FIELD )
|
||||
addr = RifEclipseSummaryAddress::fieldAddress( colName.toStdString() );
|
||||
|
||||
Column col = Column::createColumnInfoFromCsvData( addr, unit.toStdString() );
|
||||
columnInfoList->push_back( col );
|
||||
}
|
||||
|
||||
@@ -484,20 +529,22 @@ bool RifCsvUserDataParser::parseColumnBasedData( const AsciiDataParseOptions& pa
|
||||
}
|
||||
else if ( col.dataType == Column::DATETIME )
|
||||
{
|
||||
QDateTime dt;
|
||||
dt = tryParseDateTime( colData.toStdString(), parseOptions.dateTimeFormat );
|
||||
QDateTime dt = tryParseDateTime( colData.toStdString(), parseOptions.dateTimeFormat );
|
||||
|
||||
if ( !dt.isValid() && !parseOptions.useCustomDateTimeFormat )
|
||||
// Try to match date format only
|
||||
if ( !dt.isValid() && parseOptions.dateFormat != parseOptions.dateTimeFormat )
|
||||
{
|
||||
// Try to match date format only
|
||||
if ( parseOptions.dateFormat != parseOptions.dateTimeFormat )
|
||||
{
|
||||
dt = tryParseDateTime( colData.toStdString(), parseOptions.dateFormat );
|
||||
}
|
||||
if ( !dt.isValid() && !parseOptions.fallbackDateTimeFormat.isEmpty() )
|
||||
{
|
||||
dt = tryParseDateTime( colData.toStdString(), parseOptions.fallbackDateTimeFormat );
|
||||
}
|
||||
dt = tryParseDateTime( colData.toStdString(), parseOptions.dateFormat );
|
||||
}
|
||||
if ( !dt.isValid() && !parseOptions.fallbackDateTimeFormat.isEmpty() )
|
||||
{
|
||||
dt = tryParseDateTime( colData.toStdString(), parseOptions.fallbackDateTimeFormat );
|
||||
}
|
||||
|
||||
if ( !dt.isValid() && parseOptions.startDateTime.isValid() )
|
||||
{
|
||||
double minutes = colData.toDouble();
|
||||
dt = parseOptions.startDateTime.addSecs( minutes * 60 );
|
||||
}
|
||||
|
||||
if ( !dt.isValid() )
|
||||
@@ -532,7 +579,12 @@ bool RifCsvUserDataParser::parseColumnBasedData( const AsciiDataParseOptions& pa
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RifCsvUserDataParser::parseLineBasedData()
|
||||
{
|
||||
QTextStream* dataStream = openDataStream();
|
||||
QTextStream* dataStream = openDataStream();
|
||||
if ( !dataStream )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
std::map<RifEclipseSummaryAddress, std::vector<std::pair<time_t, double>>> addressesAndData;
|
||||
std::vector<int> colIndexes;
|
||||
|
||||
|
||||
@@ -0,0 +1,78 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2023- 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 "RifRevealCsvSectionSummaryReader.h"
|
||||
|
||||
#include "RiaDateStringParser.h"
|
||||
#include "RiaLogging.h"
|
||||
#include "RiaQDateTimeTools.h"
|
||||
|
||||
#include "RifCsvUserDataParser.h"
|
||||
#include "RifEclipseUserDataKeywordTools.h"
|
||||
#include "RifEclipseUserDataParserTools.h"
|
||||
|
||||
#include "SummaryPlotCommands/RicPasteAsciiDataToSummaryPlotFeatureUi.h"
|
||||
|
||||
#include "cafUtils.h"
|
||||
|
||||
#include <QDateTime>
|
||||
#include <QFile>
|
||||
#include <QTextStream>
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RifRevealCsvSectionSummaryReader::RifRevealCsvSectionSummaryReader()
|
||||
{
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RifRevealCsvSectionSummaryReader::~RifRevealCsvSectionSummaryReader()
|
||||
{
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RifRevealCsvSectionSummaryReader::parse( const QString& text, RifEclipseSummaryAddress::SummaryVarCategory defaultCategory, QString* errorText )
|
||||
{
|
||||
m_allResultAddresses.clear();
|
||||
m_mapFromAddressToResultIndex.clear();
|
||||
|
||||
AsciiDataParseOptions parseOptions;
|
||||
parseOptions.useCustomDateTimeFormat = true;
|
||||
parseOptions.dateTimeFormat = "dd.MM.yyyy hh:mm:ss";
|
||||
parseOptions.fallbackDateTimeFormat = "dd.MM.yyyy";
|
||||
parseOptions.cellSeparator = ",";
|
||||
parseOptions.decimalSeparator = ".";
|
||||
parseOptions.timeSeriesColumnName = "Date";
|
||||
parseOptions.defaultCategory = defaultCategory;
|
||||
|
||||
m_parser = std::unique_ptr<RifCsvUserDataPastedTextParser>( new RifCsvUserDataPastedTextParser( text, errorText ) );
|
||||
if ( !m_parser->parse( parseOptions ) )
|
||||
{
|
||||
RiaLogging::error( QString( "Failed to parse file" ) );
|
||||
return false;
|
||||
}
|
||||
|
||||
buildTimeStepsAndMappings();
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2023- 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.
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "RifCsvSummaryReader.h"
|
||||
|
||||
class QString;
|
||||
|
||||
class RifCsvUserDataParser;
|
||||
class RifEclipseSummaryAddress;
|
||||
|
||||
//==================================================================================================
|
||||
//
|
||||
//
|
||||
//==================================================================================================
|
||||
class RifRevealCsvSectionSummaryReader : public RifCsvSummaryReader
|
||||
{
|
||||
public:
|
||||
RifRevealCsvSectionSummaryReader();
|
||||
~RifRevealCsvSectionSummaryReader() override;
|
||||
|
||||
bool parse( const QString& fileName, RifEclipseSummaryAddress::SummaryVarCategory defaultCategory, QString* errorText = nullptr );
|
||||
};
|
||||
@@ -0,0 +1,83 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2023- 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 "RifRevealCsvSummaryReader.h"
|
||||
|
||||
#include "RifCsvUserDataParser.h"
|
||||
#include "RifRevealCsvSectionSummaryReader.h"
|
||||
|
||||
#include <QFile>
|
||||
#include <QTextStream>
|
||||
#include <Qt>
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RifRevealCsvSummaryReader::RifRevealCsvSummaryReader()
|
||||
{
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RifRevealCsvSummaryReader::~RifRevealCsvSummaryReader()
|
||||
{
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
std::pair<bool, QString> RifRevealCsvSummaryReader::parse( const QString& fileName, QString* errorText )
|
||||
{
|
||||
QFile file( fileName );
|
||||
|
||||
if ( !file.open( QFile::ReadOnly | QFile::Text ) ) return std::make_pair( false, "" );
|
||||
|
||||
QTextStream in( &file );
|
||||
|
||||
// Skip first line
|
||||
QString caseName = in.readLine().trimmed();
|
||||
|
||||
// Split files on strange header line (starts with ",Date").
|
||||
QString fileContents = in.readAll();
|
||||
QStringList parts = fileContents.split( ",Date", QString::SkipEmptyParts );
|
||||
|
||||
// Parse each section separately
|
||||
bool isFirst = true;
|
||||
for ( auto p : parts )
|
||||
{
|
||||
p.prepend( "Name,Date" );
|
||||
cvf::ref<RifRevealCsvSectionSummaryReader> sectionReader = new RifRevealCsvSectionSummaryReader;
|
||||
|
||||
// The first part is field data, and the rest is well data
|
||||
auto defaultCategory = isFirst ? RifEclipseSummaryAddress::SummaryVarCategory::SUMMARY_FIELD
|
||||
: RifEclipseSummaryAddress::SummaryVarCategory::SUMMARY_WELL;
|
||||
|
||||
QString errorMessage;
|
||||
if ( !sectionReader->parse( p, defaultCategory, &errorMessage ) )
|
||||
{
|
||||
return std::make_pair( false, "" );
|
||||
}
|
||||
|
||||
addReader( sectionReader.p() );
|
||||
|
||||
isFirst = false;
|
||||
}
|
||||
|
||||
return std::make_pair( true, caseName );
|
||||
}
|
||||
36
ApplicationLibCode/FileInterface/RifRevealCsvSummaryReader.h
Normal file
36
ApplicationLibCode/FileInterface/RifRevealCsvSummaryReader.h
Normal file
@@ -0,0 +1,36 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2023- 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.
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "RifMultipleSummaryReaders.h"
|
||||
|
||||
class QString;
|
||||
|
||||
//==================================================================================================
|
||||
//
|
||||
//
|
||||
//==================================================================================================
|
||||
class RifRevealCsvSummaryReader : public RifMultipleSummaryReaders
|
||||
{
|
||||
public:
|
||||
RifRevealCsvSummaryReader();
|
||||
~RifRevealCsvSummaryReader() override;
|
||||
|
||||
std::pair<bool, QString> parse( const QString& fileName, QString* errorText = nullptr );
|
||||
};
|
||||
@@ -0,0 +1,90 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2023- 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 "RifStimPlanCsvSummaryReader.h"
|
||||
|
||||
#include "RiaDateStringParser.h"
|
||||
#include "RiaLogging.h"
|
||||
#include "RiaQDateTimeTools.h"
|
||||
|
||||
#include "RifCsvUserDataParser.h"
|
||||
#include "RifEclipseUserDataKeywordTools.h"
|
||||
#include "RifEclipseUserDataParserTools.h"
|
||||
|
||||
#include "SummaryPlotCommands/RicPasteAsciiDataToSummaryPlotFeatureUi.h"
|
||||
|
||||
#include "cafUtils.h"
|
||||
|
||||
#include <QDateTime>
|
||||
#include <QFile>
|
||||
#include <QTextStream>
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RifStimPlanCsvSummaryReader::RifStimPlanCsvSummaryReader()
|
||||
{
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RifStimPlanCsvSummaryReader::~RifStimPlanCsvSummaryReader()
|
||||
{
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
std::pair<bool, QString> RifStimPlanCsvSummaryReader::parse( const QString& fileName, const QDateTime& startDateTime, QString* errorText )
|
||||
{
|
||||
m_allResultAddresses.clear();
|
||||
m_mapFromAddressToResultIndex.clear();
|
||||
|
||||
QFile file( fileName );
|
||||
|
||||
if ( !file.open( QFile::ReadOnly | QFile::Text ) ) return std::make_pair( false, "" );
|
||||
|
||||
QTextStream in( &file );
|
||||
|
||||
// Read case name from first line
|
||||
QString caseName = in.readLine().trimmed();
|
||||
|
||||
// Split files on strange header line (starts with ",Date").
|
||||
QString fileContents = in.readAll();
|
||||
|
||||
AsciiDataParseOptions parseOptions;
|
||||
parseOptions.useCustomDateTimeFormat = true;
|
||||
parseOptions.dateTimeFormat = "m.zzz";
|
||||
parseOptions.cellSeparator = ",";
|
||||
parseOptions.decimalSeparator = ".";
|
||||
parseOptions.timeSeriesColumnName = "Time";
|
||||
parseOptions.startDateTime = startDateTime;
|
||||
|
||||
m_parser = std::unique_ptr<RifCsvUserDataPastedTextParser>( new RifCsvUserDataPastedTextParser( fileContents, errorText ) );
|
||||
|
||||
if ( !m_parser->parse( parseOptions ) )
|
||||
{
|
||||
RiaLogging::error( QString( "Failed to parse file" ) );
|
||||
return std::make_pair( false, "" );
|
||||
}
|
||||
|
||||
buildTimeStepsAndMappings();
|
||||
|
||||
return std::make_pair( true, caseName );
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2023- 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.
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "RifCsvSummaryReader.h"
|
||||
|
||||
class QString;
|
||||
|
||||
class RifCsvUserDataParser;
|
||||
class RifEclipseSummaryAddress;
|
||||
|
||||
//==================================================================================================
|
||||
//
|
||||
//
|
||||
//==================================================================================================
|
||||
class RifStimPlanCsvSummaryReader : public RifCsvSummaryReader
|
||||
{
|
||||
public:
|
||||
RifStimPlanCsvSummaryReader();
|
||||
~RifStimPlanCsvSummaryReader() override;
|
||||
|
||||
std::pair<bool, QString> parse( const QString& fileName, const QDateTime& startDateTime, QString* errorText = nullptr );
|
||||
};
|
||||
Reference in New Issue
Block a user