[Gmsh] Extracting / Printing variable values from a .geo file
Geordie McBain
gdmcbain at freeshell.org
Thu Jul 28 13:04:39 CEST 2011
2011/7/28 Neilen Marais <nmarais at gmail.com>:
> Hi,
>
> I would like to read some of the variable values that I set in my .geo
> file into another (python) program. My program needs certain
> coordinates (such as where the source is located) that depends on
> variables defined in the .geo file. Is there a simple way of
> extracting the values of those variables from gmsh? I'd be happy to
> run gmsh and read values from stdout if neccesary.
There's the Printf command with the syntax
Printf ( char-expression , expression-list ) > char-expression;
http://geuz.org/gmsh/doc/texinfo/gmsh.html#General-commands
So calling the attached lc.geo from the shell with
gmsh - lc.geo
you get the attached lc.py which I think is valid Python.
Another approach to this kind of problem (i.e. sharing parameter
values between Gmsh and other programs) is to generate the .geo input
file from a template by macro substitution. That is, have a file
lc.geo.in with placeholders in it, run that through a macro-processor
like m4 <http://www.gnu.org/s/m4>, PYM
<http://ray.cg.tuwien.ac.at/rft/Papers/PYM/pym.html>, or use the
template string substitution from Python's standard library
<http://docs.python.org/library/string.html?highlight=template#string.Template.substitute>.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: lc.geo
Type: application/octet-stream
Size: 44 bytes
Desc: not available
URL: <http://www.geuz.org/pipermail/gmsh/attachments/20110728/931cffdc/attachment.geo>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: lc.py
Type: text/x-python
Size: 9 bytes
Desc: not available
URL: <http://www.geuz.org/pipermail/gmsh/attachments/20110728/931cffdc/attachment.py>