diff inst/import_meshfunction_type.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
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/inst/import_meshfunction_type.m	Wed Aug 06 19:52:03 2014 +0200
@@ -0,0 +1,62 @@
+## Copyright (C) 2014 Eugenio Gianniti <eugenio.gianniti@mail.polimi.it>
+##
+## This program is free software; you can redistribute it and/or modify it under
+## the terms of the GNU General Public License as published by the Free Software
+## Foundation; either version 3 of the License, or (at your option) any later
+## version.
+##
+## This program is distributed in the hope that it will be useful, but WITHOUT
+## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+## details.
+##
+## You should have received a copy of the GNU General Public License along with
+## this program; if not, see <http://www.gnu.org/licenses/>.
+
+## -*- texinfo -*-
+## @deftypefn {Function File} {} import_meshfunction_type (@var{typename})
+## Add a wrapper for dolfin::MeshFunction <@var{typename}>
+## @end deftypefn
+
+function import_meshfunction_type (typename)
+
+  if (is_master_node ())
+    if (nargin != 1)
+      error ("import_meshfunction_type: wrong number of input parameters.");
+    elseif (! ischar (typename))
+      error ("import_meshfunction_type: first argument is not a valid string");
+    endif
+
+    # Ensure that the typename does not contain whitespace
+    typename = strtrim (typename);
+    typename = strjoin (strsplit (typename), "");
+
+    if (! check_mf_files (typename))
+      n = length (mfilename ("fullpath")) - length (mfilename());
+      path = strtrunc(mfilename ("fullpath"), n);
+
+      private = fullfile (path, "include/");
+      output = generate_mf_header (typename);
+      output += generate_mf_constructor (typename);
+      output += generate_mf_save (typename);
+      output += generate_mf_makefile (typename, private);
+      if (output != 0)
+        error ("compilation failed");
+      else
+        [output, textfile] = system (["make -f Makefile_", typename, " all"]);
+        if (output != 0)
+          display (text);
+          error ("compilation failed");
+        endif
+        [output, textfile] = system (["make -f Makefile_", typename, " clean"]);
+        if (output != 0)
+          display (text);
+          error ("compilation failed");
+        endif
+      endif
+    endif
+  endif
+
+  barrier ();
+
+endfunction