Mercurial > fem-fenics-eugenio
changeset 40:df41c72f4da4
Example for the problem of how we could dinamically include an header
author | gedeone-octave <marco.vassallo@outlook.com> |
---|---|
date | Fri, 19 Jul 2013 10:15:34 +0200 |
parents | 7909b9af405c |
children | cedb2b5d6455 |
files | example/fem_func_space.m |
diffstat | 1 files changed, 75 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/example/fem_func_space.m Fri Jul 19 10:15:34 2013 +0200 @@ -0,0 +1,75 @@ +## Copyright (C) 2013 Marco Vassallo + +## 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 2 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} {} = fem_ffc (myproblem.ufl) +## This function take as input a .ufl file with a Variationa Problem +## @example +## +## @end example +## @seealso{} +## @end deftypefn + +function res = fem_func_space (mesh, name) + + if nargin != 2 + error ("fem_ffc: wrong number of input parameters."); + elseif ! isstr (name) + error ("fem_ffc: first argument is not a valid string"); + endif + + # fem_fs.cc is the file where I should include name.h + # I use name.h at line 35, where I call + # "new FunctionSpace (mshd);" + # because FunctionSpace is defined inside of name.h + # (correct call would be "name::FunctionSpace (mshd)" but + # I'm using the namespace "name") + command = "cp ../src/fem_fs.cc fem_fs.cc"; + [output, text] = system (command); + if output != 0 + display (text); + error ("Compilation failed"); + endif + + # add line to fem_fs.cc + filename = "fem_fs.cc"; + fid = fopen (filename, "r+"); + fseek (fid, 671, SEEK_SET ()); + fprintf (fid, "%c%s.h%c", 34, name, 34); + fseek (fid, 721, SEEK_SET ()); + fprintf (fid, "%s%c", name, 59); + fclose (fid); + + #now compile the program + command = "mkoctfile -c fem_fs.cc $(LDFLAGS) -o fem_fs.o -I../src/"; + [output, text] = system (command); + if output != 0 + display (text); + error ("Compilation failed"); + endif + + command = "mkoctfile -s ../src/mesh.o ../src/fem_init_env.o fem_fs.o -o fem_fs.oct $(LDFLAGS) -ldolfin"; + [output, text] = system (command); + if output != 0 + display (text); + error ("Compilation failed"); + endif + + #run the program and get the result + res = fem_fs (mesh); + +endfunction +