From 5fc26a420a538b826f540e29e478cfd6b27e3d3f Mon Sep 17 00:00:00 2001 From: guido Date: Wed, 2 Feb 2000 01:59:00 +0000 Subject: [PATCH] write file automatically git-svn-id: https://svn.dealii.org/trunk@2315 0785d39b-7218-0410-832d-ea1e28bc413d --- deal.II/base/include/base/parameter_handler.h | 4 ++++ deal.II/base/source/parameter_handler.cc | 18 ++++++++++++++---- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/deal.II/base/include/base/parameter_handler.h b/deal.II/base/include/base/parameter_handler.h index a90ce0b4db..1f6f0be22e 100644 --- a/deal.II/base/include/base/parameter_handler.h +++ b/deal.II/base/include/base/parameter_handler.h @@ -643,6 +643,10 @@ class ParameterHandler * is given. * * Return whether the read was successful. + * + * This function will automatically generate + * the requested file with default values if + * the file did not exist. */ virtual bool read_input (const string &filename); diff --git a/deal.II/base/source/parameter_handler.cc b/deal.II/base/source/parameter_handler.cc index e851a40fd6..f2f5ee5452 100644 --- a/deal.II/base/source/parameter_handler.cc +++ b/deal.II/base/source/parameter_handler.cc @@ -239,17 +239,27 @@ bool ParameterHandler::read_input (istream &input) { }; -bool ParameterHandler::read_input (const string &filename) { +bool ParameterHandler::read_input (const string &filename) +{ ifstream input (filename.c_str()); if (!input) { cerr << "ParameterHandler::read_input: could not open file <" - << filename << ">. Aborting." << endl; + << filename << "> for reading." << endl + << "Trying to make file ;<" + << filename << "> with default values for you." << endl; + + ofstream output (filename.c_str()); + if (output) + { + print_parameters (output, Text); + } + return false; - }; + } return read_input (input); -}; +} -- 2.39.5