changeset 220:9adf76893ce4

Added ufl.m
author Eugenio Gianniti <eugenio.gianniti@mail.polimi.it>
date Mon, 19 May 2014 12:14:44 +0200
parents a13b7d744b86
children 470586565dc7
files INDEX inst/ufl.m
diffstat 2 files changed, 69 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/INDEX	Sat May 17 17:16:58 2014 +0200
+++ b/INDEX	Mon May 19 12:14:44 2014 +0200
@@ -5,6 +5,7 @@
   import_ufl_Functional
   import_ufl_FunctionSpace
   import_ufl_Problem
+  ufl
 Problem geometry and FE space
   Mesh
   FunctionSpace
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/inst/ufl.m	Mon May 19 12:14:44 2014 +0200
@@ -0,0 +1,68 @@
+## 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} ufl [command] line
+##
+## Writes the given line to a ufl file. Optional commands are:
+## @itemize @bullet
+## @item start: opens an ufl file. It is possible to specify a name for it,
+## otherwise 'default.ufl' will be used.
+## @item end: closes an ufl file.
+## @end itemize
+##
+## @end deftypefn
+
+function ufl (varargin)
+
+  persistent fid = -1;
+  filename = "default.ufl";
+
+  if (numel (varargin) < 1)
+    if (fid < 0)
+      print_usage ();
+    endif
+  elseif (! all (cellfun ("ischar", varargin)))
+    error ("ufl: all arguments should be strings");
+  elseif (strcmpi (varargin{1}, "start"))
+    if (fid >= 0)
+      error ("ufl: a file is already open");
+    else
+      if (numel (varargin) > 1)
+        filename = varargin{2};
+        if (isempty (regexpi (filename, ".ufl$", "match")))
+          filename = [filename, ".ufl"];
+        endif
+      endif
+      fid = fopen (filename, "w");
+    endif
+    if (fid < 0)
+      error (["ufl: could not open file ", filename]);
+    endif
+  elseif (strcmpi (varargin{1}, "end"))
+    if (fid < 0)
+      error ("ufl: no open file");
+    else
+      fclose (fid);
+      fid = -1;
+    endif
+  elseif (fid < 0)
+    error ("ufl: no open file");
+  else
+    fprintf (fid, "%s ", varargin{:});
+    fprintf (fid, "\n");
+  endif
+
+endfunction