From 412b478f5c208bcf493df339f9a51f60c3246176 Mon Sep 17 00:00:00 2001 From: Luca Heltai Date: Tue, 28 Apr 2020 23:05:07 +0200 Subject: [PATCH] Added print_parameters with string and style. --- include/deal.II/base/parameter_handler.h | 26 +++++++++++++++++++++++ source/base/parameter_handler.cc | 27 ++++++++++++++++++++++++ 2 files changed, 53 insertions(+) diff --git a/include/deal.II/base/parameter_handler.h b/include/deal.II/base/parameter_handler.h index 2699965e4f..e91a3517bc 100644 --- a/include/deal.II/base/parameter_handler.h +++ b/include/deal.II/base/parameter_handler.h @@ -1475,6 +1475,32 @@ public: std::ostream & print_parameters(std::ostream &out, const OutputStyle style) const; + + + /** + * Print all parameters with the given @p style to the file given by + * @p filename. + * + * This function deduces the output format from the extension of the specified + * filename. Supported extensions are `prm`, `xml`, `tex`, and `json`. + * If a different extensions is used, then an output style is deduced from the + * @p style argument. + * + * Notice that specifying a supported file extension is equivalent to + * specifying the corresponding ParameterHandler::OutputStyle format. In + * particular, any (optional) format specification specified in the @p style + * parameter must be compatible with the given extension. + * + * If the format is not supported, and @p output_style does not contain a + * format specification, an assertion is thrown. + * + * @param filename The output file name. + * @param style The style with which output is produced. + */ + void + print_parameters(const std::string &filename, + const OutputStyle style = DefaultStyle) const; + /** * Print parameters to a logstream. This function allows to print all * parameters into a log-file. Sections will be indented in the usual log- diff --git a/source/base/parameter_handler.cc b/source/base/parameter_handler.cc index 2f3f157607..07716b8826 100644 --- a/source/base/parameter_handler.cc +++ b/source/base/parameter_handler.cc @@ -1339,6 +1339,33 @@ ParameterHandler::print_parameters(std::ostream & out, return out; } + + +void +ParameterHandler::print_parameters( + const std::string & filename, + const ParameterHandler::OutputStyle style) const +{ + std::string extension = filename.substr(filename.find_last_of('.') + 1); + boost::algorithm::to_lower(extension); + + ParameterHandler::OutputStyle output_style = style; + if (extension == "prm") + output_style = style | PRM; + else if (extension == "xml") + output_style = style | XML; + else if (extension == "json") + output_style = style | JSON; + else if (extension == "tex") + output_style = style | LaTeX; + + std::ofstream out(filename); + AssertThrow(out, ExcIO()); + print_parameters(out, output_style); +} + + + void ParameterHandler::recursively_print_parameters( const boost::property_tree::ptree &tree, -- 2.39.5