From 9df3b2fda974a3d7bf3c3ef787e73a62df8a75b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rgen=20Kvalsvik?= Date: Wed, 16 Mar 2016 14:40:54 +0100 Subject: [PATCH] Flow accepts base name for input Deck Enables flow to accept a basename for a case by appending a .DATA suffix should it not be provided. It already supported reading the basename from a .DATA extension file, but not opening said file by handing it to the parser. --- opm/autodiff/FlowMain.hpp | 35 ++++++++++++++++++++++++++++++----- 1 file changed, 30 insertions(+), 5 deletions(-) diff --git a/opm/autodiff/FlowMain.hpp b/opm/autodiff/FlowMain.hpp index b3095fd2b..1c39c5c28 100644 --- a/opm/autodiff/FlowMain.hpp +++ b/opm/autodiff/FlowMain.hpp @@ -94,6 +94,7 @@ #include #include #include +#include @@ -101,6 +102,33 @@ namespace Opm { + boost::filesystem::path simulationCaseName( const std::string& casename ) { + namespace fs = boost::filesystem; + + const auto exists = []( const fs::path& f ) -> bool { + if( !fs::exists( f ) ) return false; + + if( fs::is_regular_file( f ) ) return true; + + return fs::is_symlink( f ) + && fs::is_regular_file( fs::read_symlink( f ) ); + }; + + auto simcase = fs::path( casename ); + + if( exists( simcase ) ) { + return simcase; + } + + for( const auto& ext : { std::string("data"), std::string("DATA") } ) { + if( exists( simcase.replace_extension( ext ) ) ) { + return simcase; + } + } + + throw std::invalid_argument( "Cannot find input case " + casename ); + } + /// This class encapsulates the setup and running of /// a simulator based on an input deck. template @@ -258,10 +286,6 @@ namespace Opm } } - - - - // Read parameters, see if a deck was specified on the command line, and if // it was, insert it into parameters. // Writes to: @@ -281,7 +305,8 @@ namespace Opm std::cerr << "You can only specify a single input deck on the command line.\n"; return false; } else { - param_.insertParameter("deck_filename", param_.unhandledArguments()[0]); + const auto casename = simulationCaseName( param_.unhandledArguments()[ 0 ] ); + param_.insertParameter("deck_filename", casename.string() ); } }