From: wolf Date: Mon, 18 Apr 2005 22:43:38 +0000 (+0000) Subject: First version. X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6275444d3d525d42fb55972666fab7a98ffa08aa;p=dealii-svn.git First version. git-svn-id: https://svn.dealii.org/trunk@10520 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/deal.II/examples/step-19/step-19.cc b/deal.II/examples/step-19/step-19.cc new file mode 100644 index 0000000000..271202259e --- /dev/null +++ b/deal.II/examples/step-19/step-19.cc @@ -0,0 +1,221 @@ +//---------------------------- converter.cc --------------------------- +// +// Copyright (C) 2005 by Luca Heltai +// +// This file is subject to QPL and may not be distributed +// without copyright and license information. Please refer +// to the file deal.II/doc/license.html for the text and +// further information on this license. +// +//---------------------------- converter.cc --------------------------- + +// Base libraries +#include + +// C++ libraries +#include +#include + + + + +template +void do_convert (const std::vector &input_files, + const std::string &output_file, + const std::string &/*parameter_file*/, + const std::string &output_format_extension) +{ + std::ifstream intermediate_stream (input_files[0].c_str()); + AssertThrow (intermediate_stream, ExcIO()); + + DataOutReader intermediate_data; + intermediate_data.read (intermediate_stream); + + std::ofstream output_stream (output_file.c_str()); + AssertThrow (output_stream, ExcIO()); + + const typename DataOutInterface::OutputFormat + output_format + = intermediate_data.parse_output_format (output_format_extension); + + intermediate_data.write(output_stream, output_format); +} + + +void convert (const std::vector &input_files, + const std::string &output_file, + const std::string ¶meter_file, + const std::string &output_format_extension) +{ + std::ifstream input(input_files[0].c_str()); + AssertThrow (input, ExcIO()); + + const std::pair + dimensions = DataOutBase::determine_intermediate_format_dimensions (input); + + switch (dimensions.first) + { + case 1: + switch (dimensions.second) + { + case 1: + do_convert <1,1> (input_files, + output_file, + parameter_file, + output_format_extension); + return; + + case 2: + do_convert <1,2> (input_files, + output_file, + parameter_file, + output_format_extension); + return; + } + AssertThrow (false, ExcNotImplemented()); + + case 2: + switch (dimensions.second) + { + case 2: + do_convert <2,2> (input_files, + output_file, + parameter_file, + output_format_extension); + return; + + case 3: + do_convert <2,3> (input_files, + output_file, + parameter_file, + output_format_extension); + return; + } + AssertThrow (false, ExcNotImplemented()); + + case 3: + switch (dimensions.second) + { + case 3: + do_convert <3,3> (input_files, + output_file, + parameter_file, + output_format_extension); + return; + } + AssertThrow (false, ExcNotImplemented()); + } + + AssertThrow (false, ExcNotImplemented()); +} + + + +int main (int argc, char ** argv) +{ + try + { + if (argc == 0) + { + std::cout << "Converter from deal.II intermediate format to " + << "other graphics formats." + << std::endl << std::endl + << "Usage: ./step-19 [-p parameter_file] " + << "list_of_input_files -x output_format " + << "output_file" + << std::endl; + exit (1); + } + + std::string parameter_file; + std::string output_format_extension; + std::vector file_names; + + for (int i=1; i input_files (file_names.begin(), + file_names.end()-1); + const std::string output_file (file_names.back()); + + if (output_format_extension.size() == 0) + { + output_format_extension + = std::string(output_file.begin() + output_file.rfind ('.') + 1, + output_file.end()); + + if (output_format_extension.size() == 0) + { + std::cerr << "Error: could not determine output file format " + << "from name of last file name." + << std::endl; + exit (1); + } + } + + convert (input_files, + output_file, + parameter_file, + output_format_extension); + } + catch (std::exception &exc) + { + std::cerr << std::endl << std::endl + << "----------------------------------------------------" + << std::endl; + std::cerr << "Exception on processing: " << std::endl + << exc.what() << std::endl + << "Aborting!" << std::endl + << "----------------------------------------------------" + << std::endl; + + return 1; + } + catch (...) + { + std::cerr << std::endl << std::endl + << "----------------------------------------------------" + << std::endl; + std::cerr << "Unknown exception!" << std::endl + << "Aborting!" << std::endl + << "----------------------------------------------------" + << std::endl; + return 1; + }; + + return 0; +}