view inst/generate_fs.m @ 82:5a4371f45fc4

Create the corresponding function following new naming convention.
author gedeone-octave <marcovass89@hotmail.it>
date Sat, 03 Aug 2013 14:45:57 +0200
parents 4ef8dbafcdfc
children 2191111a1cad
line wrap: on
line source


function output = generate_fs (ufl_name)

STRING ="\n\
#include ""functionspace.h""\n\
#include ""mesh.h""\n\
#include ""@@UFL_NAME@@.h""\n\
\n\
DEFUN_DLD (@@UFL_NAME@@_FunctionSpace, args, , ""initialize a fs from a mesh declared with fem_init_mesh"")\n\
{\n\
  int nargin = args.length ();\n\
  octave_value retval;\n\
\n\
  if (nargin < 1 || nargin > 1)\n\
    print_usage ();\n\
  else\n\
    {\n\
\n\
      if (! mesh_type_loaded)\n\
        {\n\
          mesh::register_type ();\n\
          mesh_type_loaded = true;\n\
          mlock ();\n\
        }\n\
\n\
      if (args(0).type_id () == mesh::static_type_id ())\n\
        {\n\
          const mesh & msho = static_cast<const mesh&> (args(0).get_rep ());\n\
          const dolfin::Mesh & mshd = msho.get_msh ();\n\
          boost::shared_ptr <const dolfin::FunctionSpace> g (new @@UFL_NAME@@::FunctionSpace (mshd));\n\
\n\
          if (! functionspace_type_loaded)\n\
            {\n\
              functionspace::register_type ();\n\
              functionspace_type_loaded = true;\n\
              mlock ();\n\
            }\n\
\n\
          retval = new functionspace(g);\n\
        }\n\
    }\n\
  return retval;\n\
}";

STRING =  strrep (STRING, "@@UFL_NAME@@", ufl_name);

fid = fopen (sprintf ("%s_FunctionSpace.cc", ufl_name), 'w');
if (fid >= 0)
  fputs (fid, STRING);
  output = fclose (fid);
else
  error ("cannot open file");
  output = 1;
endif

endfunction