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:
// otherwise use the default name (executable name + .input)
if (parameterFileName == "")
{
if (mpiHelper.size() > 1)
std::cout << "Rank " << mpiHelper.rank() << ": ";
std::cout << "No parameter file given. "
<< "Defaulting to '"
<< argv[0]
<< ".input' for input file.\n";
parameterFileName = std::string(argv[0]) + ".input";
}
parameterFileName = [&](){
std::string defaultName = std::string(argv[0]) + ".input";
std::ifstream pFile(defaultName.c_str());
if (pFile.is_open())
return defaultName;
defaultName = "params.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.
std::ifstream parameterFile(parameterFileName.c_str());
if (!parameterFile.is_open())
{
if (mpiHelper.size() > 1)
std::cout << "Rank " << mpiHelper.rank() << ": ";
std::cout << " -> Could not open file '"
<< parameterFileName
<< "'. <- \n\n";
return;
}
else
{
if (mpiHelper.size() > 1)
std::cout << "Rank " << mpiHelper.rank() << ": ";
std::cout << "No parameter file given. "
<< "Defaulting to '"
<< 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 << ".");
}
else
{
// read parameters from the file without overwriting the command line params
// because the command line arguments have precedence
Dune::ParameterTreeParser::readINITree(parameterFileName,
paramTree(),
/*overwrite=*/false);
}
parameterFile.close();
// read parameters from the file without overwriting the command line params
// because the command line arguments have precedence
// let Dune do the error checking if the file exists
Dune::ParameterTreeParser::readINITree(parameterFileName,
paramTree(),
/*overwrite=*/false);
}
/*!
......
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