comparison inst/private/generate_mf_save.m @ 260:1e2a9be8083a

Support template dolfin::MeshFunction
author Eugenio Gianniti <eugenio.gianniti@mail.polimi.it>
date Wed, 06 Aug 2014 19:52:03 +0200
parents
children f22588ae37af
comparison
equal deleted inserted replaced
259:598c5e9e0a9e 260:1e2a9be8083a
1 ## Copyright (C) 2014 Eugenio Gianniti <eugenio.gianniti@mail.polimi.it>
2 ##
3 ## This program is free software; you can redistribute it and/or modify it under
4 ## the terms of the GNU General Public License as published by the Free Software
5 ## Foundation; either version 3 of the License, or (at your option) any later
6 ## version.
7 ##
8 ## This program is distributed in the hope that it will be useful, but WITHOUT
9 ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
11 ## details.
12 ##
13 ## You should have received a copy of the GNU General Public License along with
14 ## this program; if not, see <http://www.gnu.org/licenses/>.
15
16
17 ## -*- texinfo -*-
18 ## function for internal usage only
19 ## @end deftypefn
20
21 function output = generate_mf_save (typename)
22
23 STRING ="\n\
24 #include ""meshfunction_@@TYPENAME@@.h""\n\
25 \n\
26 DEFUN_DLD (save, args, nargout, ""save (MESHFUNCTION, FILENAME)"")\n\
27 {\n\
28 int nargin = args.length ();\n\
29 octave_value retval;\n\
30 \n\
31 if (nargin < 2 || nargin > 2 || nargout > 1)\n\
32 print_usage ();\n\
33 else\n\
34 {\n\
35 if (! meshfunction_@@TYPENAME@@_type_loaded)\n\
36 {\n\
37 meshfunction_@@TYPENAME@@::register_type ();\n\
38 meshfunction_@@TYPENAME@@_type_loaded = true;\n\
39 mlock ();\n\
40 }\n\
41 \n\
42 if (args(0).type_id () == meshfunction_@@TYPENAME@@::static_type_id ()\n\
43 && args(1).is_string ())\n\
44 {\n\
45 meshfunction_@@TYPENAME@@ const & mf_arg =\n\
46 static_cast<meshfunction_@@TYPENAME@@ const &>\n\
47 (args(0).get_rep ());\n\
48 std::string str = args(1).string_value ();\n\
49 \n\
50 if (!error_state)\n\
51 {\n\
52 dolfin::MeshFunction <@@TYPENAME@@> const &\n\
53 mf = mf_arg.get_mf ();\n\
54 str += "".xdmf"";\n\
55 try\n\
56 {\n\
57 dolfin::File file (str);\n\
58 file << mf;\n\
59 }\n\
60 catch (std::runtime_error &)\n\
61 { error (""error saving meshfunction@@TYPENAME@@""); }\n\
62 retval = 0;\n\
63 }\n\
64 }\n\
65 else\n\
66 error (""invalid input arguments"");\n\
67 }\n\
68 \n\
69 return retval;\n\
70 }";
71
72 STRING = strrep (STRING, "@@TYPENAME@@", typename);
73
74 fid = fopen (["save_", typename, ".cc"], "w");
75 if (is_valid_file_id (fid))
76 fputs (fid, STRING);
77 output = fclose (fid);
78 else
79 error ("cannot open file");
80 output = 1;
81 endif
82
83 endfunction