Skip to content
Snippets Groups Projects
Commit c64b0573 authored by Timo Koch's avatar Timo Koch
Browse files

[params] Improve handling of parameter files

If no parameter file is given look for

* executbale.input
* params.intput

If none are found, try it without parameter file.
If a parameter file is given, let Dune do the error handling,
and check if the file exists.
parent 79d51872
No related branches found
No related tags found
1 merge request!1359[params] Improve handling of parameter files
...@@ -120,39 +120,50 @@ public: ...@@ -120,39 +120,50 @@ public:
// otherwise use the default name (executable name + .input) // otherwise use the default name (executable name + .input)
if (parameterFileName == "") if (parameterFileName == "")
{ {
if (mpiHelper.size() > 1) parameterFileName = [&](){
std::cout << "Rank " << mpiHelper.rank() << ": "; std::string defaultName = std::string(argv[0]) + ".input";
std::cout << "No parameter file given. " std::ifstream pFile(defaultName.c_str());
<< "Defaulting to '" if (pFile.is_open())
<< argv[0] return defaultName;
<< ".input' for input file.\n";
defaultName = "params.input";
parameterFileName = std::string(argv[0]) + ".input"; pFile = std::ifstream(defaultName.c_str());
} if (pFile.is_open())
return defaultName;
else
return std::string("");
}();
// if no parameter file was given and also no default names where found, continue without
if (parameterFileName == "")
{
if (mpiHelper.size() > 1)
std::cout << "Rank " << mpiHelper.rank() << ": ";
std::cout << "No parameter file found. Continuing without parameter file.\n";
// open and check whether the parameter file exists. return;
std::ifstream parameterFile(parameterFileName.c_str()); }
if (!parameterFile.is_open()) else
{ {
if (mpiHelper.size() > 1) if (mpiHelper.size() > 1)
std::cout << "Rank " << mpiHelper.rank() << ": "; std::cout << "Rank " << mpiHelper.rank() << ": ";
std::cout << " -> Could not open file '" std::cout << "No parameter file given. "
<< parameterFileName << "Defaulting to '"
<< "'. <- \n\n"; << parameterFileName
<< "' for input file.\n";
}
}
usage(argv[0], defaultUsageMessage(argv[0])); if (mpiHelper.size() > 1)
std::cout << "Rank " << mpiHelper.rank() << ": ";
std::cout << "Reading parameters from file " << parameterFileName << ".\n";
DUNE_THROW(ParameterException, "Error opening input file " << parameterFileName << "."); // read parameters from the file without overwriting the command line params
} // because the command line arguments have precedence
else // let Dune do the error checking if the file exists
{ Dune::ParameterTreeParser::readINITree(parameterFileName,
// read parameters from the file without overwriting the command line params paramTree(),
// because the command line arguments have precedence /*overwrite=*/false);
Dune::ParameterTreeParser::readINITree(parameterFileName,
paramTree(),
/*overwrite=*/false);
}
parameterFile.close();
} }
/*! /*!
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment