Skip to content

Commit

Permalink
Improve robustness when parsing PFLOTRAN files
Browse files Browse the repository at this point in the history
The include statements can optionally have a / at the end of the line. Make sure the parsing handles this correctly.
  • Loading branch information
magnesj committed Sep 6, 2024
1 parent 7ba4329 commit 5dd5f75
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
10 changes: 6 additions & 4 deletions ApplicationLibCode/FileInterface/RifEclipseInputFileTools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1065,6 +1065,7 @@ void RifEclipseInputFileTools::parsePflotranInputFile( const QString& fileName,

{
// Find all referenced grdecl files in a pflotran input file, in the GRID section, example
// The line can optionally contain a '/' at the end, which is ignored
/*
GRID
TYPE grdecl ../include/ccs_3df_kh.grdecl
Expand All @@ -1090,12 +1091,12 @@ void RifEclipseInputFileTools::parsePflotranInputFile( const QString& fileName,
if ( line.startsWith( "TYPE" ) )
{
auto words = RiaTextStringTools::splitSkipEmptyParts( line, " " );
if ( words.size() == 3 && words[1].startsWith( "grdecl", Qt::CaseInsensitive ) )
if ( words.size() > 2 && words[1].startsWith( "grdecl", Qt::CaseInsensitive ) )
{
QFileInfo fi( fileName );
QDir currentFileFolder = fi.absoluteDir();

QString absoluteFilePath = currentFileFolder.absoluteFilePath( words.back() );
QString absoluteFilePath = currentFileFolder.absoluteFilePath( words[2] );
gridSectionFilenames.push_back( absoluteFilePath );
}
}
Expand All @@ -1113,6 +1114,7 @@ void RifEclipseInputFileTools::parsePflotranInputFile( const QString& fileName,

// Find all grdecl files defined by the external_file keyword
// For all these files, search for the FAULTS keyword and create fault objects
// The line can optionally contain a '/' at the end, which is ignored
/*
external_file ccs_3df_kh.grdecl
external_file ccs_3df_other.grdecl
Expand All @@ -1131,12 +1133,12 @@ void RifEclipseInputFileTools::parsePflotranInputFile( const QString& fileName,
if ( line.startsWith( "external_file", Qt::CaseInsensitive ) )
{
auto words = RiaTextStringTools::splitSkipEmptyParts( line, " " );
if ( words.size() == 2 )
if ( words.size() > 1 )
{
QFileInfo fi( gridSectionFilename );
QDir currentFileFolder = fi.absoluteDir();

QString absoluteFilePath = currentFileFolder.absoluteFilePath( words.back() );
QString absoluteFilePath = currentFileFolder.absoluteFilePath( words[1] );
QFile grdeclFilename( absoluteFilePath );
if ( !grdeclFilename.open( QFile::ReadOnly ) ) continue;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ external_file ccs_3df_geom_kh.grdecl

external_file ccs_3df_prop.grdecl

external_file Faults_test_KH.grdecl
external_file Faults_test_KH.grdecl /

external_file multflt_test_KH.grdecl

Expand Down

0 comments on commit 5dd5f75

Please sign in to comment.