Mercurial > fem-fenics-eugenio
comparison inst/private/generate_mf_save.m @ 261:f22588ae37af
Improve template meshfunction implementation
* inst/import_meshfunction_type.m: provide to the auxiliary functions a type name and
a valid identifier
* inst/private/generate_mf_*.m: add space before closing angle bracket to avoid parse
errors
author | Eugenio Gianniti <eugenio.gianniti@mail.polimi.it> |
---|---|
date | Thu, 07 Aug 2014 11:13:54 +0200 |
parents | 1e2a9be8083a |
children |
comparison
equal
deleted
inserted
replaced
260:1e2a9be8083a | 261:f22588ae37af |
---|---|
16 | 16 |
17 ## -*- texinfo -*- | 17 ## -*- texinfo -*- |
18 ## function for internal usage only | 18 ## function for internal usage only |
19 ## @end deftypefn | 19 ## @end deftypefn |
20 | 20 |
21 function output = generate_mf_save (typename) | 21 function output = generate_mf_save (typename, label) |
22 | 22 |
23 STRING ="\n\ | 23 STRING ="\n\ |
24 #include ""meshfunction_@@TYPENAME@@.h""\n\ | 24 #include ""meshfunction_@@LABEL@@.h""\n\ |
25 \n\ | 25 \n\ |
26 DEFUN_DLD (save, args, nargout, ""save (MESHFUNCTION, FILENAME)"")\n\ | 26 DEFUN_DLD (save, args, nargout, ""save (MESHFUNCTION, FILENAME)"")\n\ |
27 {\n\ | 27 {\n\ |
28 int nargin = args.length ();\n\ | 28 int nargin = args.length ();\n\ |
29 octave_value retval;\n\ | 29 octave_value retval;\n\ |
30 \n\ | 30 \n\ |
31 if (nargin < 2 || nargin > 2 || nargout > 1)\n\ | 31 if (nargin < 2 || nargin > 2 || nargout > 1)\n\ |
32 print_usage ();\n\ | 32 print_usage ();\n\ |
33 else\n\ | 33 else\n\ |
34 {\n\ | 34 {\n\ |
35 if (! meshfunction_@@TYPENAME@@_type_loaded)\n\ | 35 if (! meshfunction_@@LABEL@@_type_loaded)\n\ |
36 {\n\ | 36 {\n\ |
37 meshfunction_@@TYPENAME@@::register_type ();\n\ | 37 meshfunction_@@LABEL@@::register_type ();\n\ |
38 meshfunction_@@TYPENAME@@_type_loaded = true;\n\ | 38 meshfunction_@@LABEL@@_type_loaded = true;\n\ |
39 mlock ();\n\ | 39 mlock ();\n\ |
40 }\n\ | 40 }\n\ |
41 \n\ | 41 \n\ |
42 if (args(0).type_id () == meshfunction_@@TYPENAME@@::static_type_id ()\n\ | 42 if (args(0).type_id () == meshfunction_@@LABEL@@::static_type_id ()\n\ |
43 && args(1).is_string ())\n\ | 43 && args(1).is_string ())\n\ |
44 {\n\ | 44 {\n\ |
45 meshfunction_@@TYPENAME@@ const & mf_arg =\n\ | 45 meshfunction_@@LABEL@@ const & mf_arg =\n\ |
46 static_cast<meshfunction_@@TYPENAME@@ const &>\n\ | 46 static_cast<meshfunction_@@LABEL@@ const &>\n\ |
47 (args(0).get_rep ());\n\ | 47 (args(0).get_rep ());\n\ |
48 std::string str = args(1).string_value ();\n\ | 48 std::string str = args(1).string_value ();\n\ |
49 \n\ | 49 \n\ |
50 if (!error_state)\n\ | 50 if (!error_state)\n\ |
51 {\n\ | 51 {\n\ |
52 dolfin::MeshFunction <@@TYPENAME@@> const &\n\ | 52 dolfin::MeshFunction <@@TYPENAME@@ > const &\n\ |
53 mf = mf_arg.get_mf ();\n\ | 53 mf = mf_arg.get_mf ();\n\ |
54 str += "".xdmf"";\n\ | 54 str += "".xdmf"";\n\ |
55 try\n\ | 55 try\n\ |
56 {\n\ | 56 {\n\ |
57 dolfin::File file (str);\n\ | 57 dolfin::File file (str);\n\ |
58 file << mf;\n\ | 58 file << mf;\n\ |
59 }\n\ | 59 }\n\ |
60 catch (std::runtime_error &)\n\ | 60 catch (std::runtime_error &)\n\ |
61 { error (""error saving meshfunction@@TYPENAME@@""); }\n\ | 61 { error (""error saving meshfunction@@LABEL@@""); }\n\ |
62 retval = 0;\n\ | 62 retval = 0;\n\ |
63 }\n\ | 63 }\n\ |
64 }\n\ | 64 }\n\ |
65 else\n\ | 65 else\n\ |
66 error (""invalid input arguments"");\n\ | 66 error (""invalid input arguments"");\n\ |
67 }\n\ | 67 }\n\ |
68 \n\ | 68 \n\ |
69 return retval;\n\ | 69 return retval;\n\ |
70 }"; | 70 }"; |
71 | 71 |
72 STRING = strrep (STRING, "@@TYPENAME@@", typename); | 72 STRING = strrep (STRING, "@@TYPENAME@@", typename); |
73 STRING = strrep (STRING, "@@LABEL@@", label); | |
73 | 74 |
74 fid = fopen (["save_", typename, ".cc"], "w"); | 75 fid = fopen (["save_", label, ".cc"], "w"); |
75 if (is_valid_file_id (fid)) | 76 if (is_valid_file_id (fid)) |
76 fputs (fid, STRING); | 77 fputs (fid, STRING); |
77 output = fclose (fid); | 78 output = fclose (fid); |
78 else | 79 else |
79 error ("cannot open file"); | 80 error ("cannot open file"); |