* file.
*
* Such registry is traversed upon invocation of the single function
- * ParameterAcceptor::initialize(file.prm) which in turn calls the method
+ * ParameterAcceptor::initialize("file.prm") which in turn calls the method
* ParameterAcceptor::declare_parameters() for each of the registered classes,
* reads the file `file.prm` and subsequently calls the method
* ParameterAcceptor::parse_parameters(), again for each of the registered
* default values, and don't want to read external files to use a class
* derived from ParameterAcceptor.
*
- * If outfilename is not the empty string, then write the content that was
- * read in to the outfilename. The format of both input and output files are
- * selected using the extensions of the files themselves. This can be either
- * `prm` or `xml` for input, and `prm`, `xml`, or `tex/latex` for output. If
- * the output format is `prm`, then `output_style_for_prm_format` is used to
- * decide whether we write the full documentation as well, or only the
- * parameters.
+ * If @p output_filename is not the empty string, then we write the content
+ * that was read into the @p output_filename file, using the style specified
+ * in @p output_style_for_output_filename. The format of both input and output
+ * files are selected using the extensions of the files themselves. This can
+ * be either `prm`, `xml`, or `json` for the @p filename, and any of the
+ * supported formats for the @p output_filename.
*
* If the input file does not exist, a default one with the same name is
- * created for you, and an exception is thrown.
+ * created for you following the style specified in
+ * @p output_style_for_filename, and an exception is thrown.
+ *
+ * By default, the file format used to write the files is deduced from
+ * the extension of the file names. If the corresponding
+ * ParameterHandler::OutputStyle specifies a format specification, this must
+ * be compatible with the file extension, or an exception will be thrown.
+ *
+ * If the extension is not recognized, and you do not specify a format in the
+ * corresponding ParameterHandler::OutputStyle, an assertion is thrown.
*
* @param filename Input file name
* @param output_filename Output file name
- * @param output_style_for_prm_format How to write the output file if format
- * is `prm`
+ * @param output_style_for_output_filename How to write the output file
* @param prm The ParameterHandler to use
+ * @param output_style_for_filename How to write the default input file if it
+ * does not exist
*/
static void
- initialize(const std::string & filename = "",
- const std::string & output_filename = "",
- const ParameterHandler::OutputStyle output_style_for_prm_format =
- ParameterHandler::ShortText,
- ParameterHandler &prm = ParameterAcceptor::prm);
+ initialize(const std::string &filename = "",
+ const std::string &output_filename = "",
+ const ParameterHandler::OutputStyle
+ output_style_for_output_filename = ParameterHandler::Short,
+ ParameterHandler & prm = ParameterAcceptor::prm,
+ const ParameterHandler::OutputStyle output_style_for_filename =
+ ParameterHandler::DefaultStyle);
/**
* Call declare_all_parameters(), read the parameters from the `input_stream`
ParameterAcceptor::initialize(
const std::string & filename,
const std::string & output_filename,
- const ParameterHandler::OutputStyle output_style_for_prm_format,
- ParameterHandler & prm)
+ const ParameterHandler::OutputStyle output_style_for_output_filename,
+ ParameterHandler & prm,
+ const ParameterHandler::OutputStyle output_style_for_filename)
{
declare_all_parameters(prm);
if (!filename.empty())
{
- // check the extension of input file
- if (filename.substr(filename.find_last_of('.') + 1) == "prm")
+ try
{
- try
- {
- prm.parse_input(filename);
- }
- catch (const dealii::PathSearch::ExcFileNotFound &)
- {
- std::ofstream out(filename);
- Assert(out, ExcIO());
- prm.print_parameters(out, ParameterHandler::Text);
- out.close();
- AssertThrow(false,
- ExcMessage("You specified <" + filename +
- "> as input " +
- "parameter file, but it does not exist. " +
- "We created it for you."));
- }
+ prm.parse_input(filename);
}
- else if (filename.substr(filename.find_last_of('.') + 1) == "xml")
+ catch (const dealii::PathSearch::ExcFileNotFound &)
{
- std::ifstream is(filename);
- if (!is)
- {
- std::ofstream out(filename);
- Assert(out, ExcIO());
- prm.print_parameters(out, ParameterHandler::XML);
- out.close();
- AssertThrow(false,
- ExcMessage("You specified <" + filename +
- "> as input " +
- "parameter file, but it does not exist. " +
- "We created it for you."));
- }
- prm.parse_input_from_xml(is);
+ prm.print_parameters(filename, output_style_for_filename);
+ AssertThrow(false,
+ ExcMessage("You specified <" + filename + "> as input " +
+ "parameter file, but it does not exist. " +
+ "We created it for you."));
}
- else
- AssertThrow(
- false,
- ExcMessage(
- "Invalid extension of parameter file. Please use .prm or .xml"));
}
if (!output_filename.empty())
- {
- std::ofstream outfile(output_filename.c_str());
- Assert(outfile, ExcIO());
- std::string extension =
- output_filename.substr(output_filename.find_last_of('.') + 1);
-
- if (extension == "prm")
- {
- outfile << "# Parameter file generated with " << std::endl
- << "# DEAL_II_PACKAGE_VERSION = " << DEAL_II_PACKAGE_VERSION
- << std::endl;
- Assert(
- output_style_for_prm_format == ParameterHandler::Text ||
- output_style_for_prm_format == ParameterHandler::ShortText,
- ExcMessage(
- "Only Text or ShortText can be specified in output_style_for_prm_format."))
- prm.print_parameters(outfile, output_style_for_prm_format);
- }
- else if (extension == "xml")
- prm.print_parameters(outfile, ParameterHandler::XML);
- else if (extension == "latex" || extension == "tex")
- prm.print_parameters(outfile, ParameterHandler::LaTeX);
- else
- AssertThrow(false, ExcNotImplemented());
- }
+ prm.print_parameters(output_filename, output_style_for_output_filename);
// Finally do the parsing.
parse_all_parameters(prm);