diff --git a/opm/models/utils/parametersystem.cpp b/opm/models/utils/parametersystem.cpp index c7712118c..1c791cd2f 100644 --- a/opm/models/utils/parametersystem.cpp +++ b/opm/models/utils/parametersystem.cpp @@ -559,10 +559,14 @@ void printUsage(const std::string& helpPreamble, } } -void parseParameterFile(const std::string& fileName, bool overwrite) +bool parseParameterFile(const std::string& fileName, bool overwrite) { std::set seenKeys; std::ifstream ifs(fileName); + if (!ifs.is_open()) { + return false; + } + unsigned curLineNum = 0; while (ifs) { // string and file processing in c++ is quite blunt! @@ -624,6 +628,8 @@ void parseParameterFile(const std::string& fileName, bool overwrite) MetaData::tree()[canonicalKey] = value; } } + + return true; } std::string parseCommandLineOptions(int argc, diff --git a/opm/models/utils/parametersystem.hpp b/opm/models/utils/parametersystem.hpp index abdcf8f1b..4c57ce3f9 100644 --- a/opm/models/utils/parametersystem.hpp +++ b/opm/models/utils/parametersystem.hpp @@ -146,7 +146,7 @@ parseCommandLineOptions(int argc, * * This function does some basic syntax checks. */ -void parseParameterFile(const std::string& fileName, bool overwrite = true); +bool parseParameterFile(const std::string& fileName, bool overwrite = true); /*! * \ingroup Parameter diff --git a/opm/models/utils/start.hh b/opm/models/utils/start.hh index e81cd06e8..5da8d1bd6 100644 --- a/opm/models/utils/start.hh +++ b/opm/models/utils/start.hh @@ -44,7 +44,6 @@ #include #endif -#include #include #include #include @@ -145,9 +144,7 @@ static inline int setupParameters_(int argc, //////////////////////////////////////////////////////////// // check whether the parameter file is readable. - std::ifstream tmp; - tmp.open(paramFileName.c_str()); - if (!tmp.is_open()) { + if (!Parameters::parseParameterFile(paramFileName, /*overwrite=*/false)) { std::ostringstream oss; if (myRank == 0) { oss << "Parameter file \"" << paramFileName @@ -156,9 +153,6 @@ static inline int setupParameters_(int argc, } return /*status=*/1; } - - // read the parameter file. - Parameters::parseParameterFile(paramFileName, /*overwrite=*/false); } // make sure that no unknown parameters are encountered