Saving Commands to Scripts
All the actions performed by the user, such as opening files, creating
plots, editing graphical objects, viewing transformations, etc. are casted
into commands and saved to a script file. In the case of the lite version
of ZFEM this file is called zfemLite_script while for the full version
it is called zfem_script, and it is saved in the working directory.
The saving of commands to the script file is done automatically, and
if a zfem_script file already exists in the working directory, it will
be overwritten. The saving of commands can be disabled when launching zfem
(or zfemLite): simply start zfem with the -n flag in the command line (-n
stands for "not saving").
Executing Scripts
Once a script file is created, it can be re-executed to reproduce the
visualization session. There are two possibilities to execute the commands
contained in a script file:
- From the command line: start zfem with the -e flag (zfem -e file) where
file is the name of the script. Note that if the script is still called
zfem_script it will be overwritten unless the -n flag is used as well.
- From the GUI: click on the "execute script" icon in the tools
window. A dialog window will popup:

Change the directory by double clicking on the entries of the dir list
or type the path in the path entry field. Select a file name from the file
list or type the name into the file entry field. Press the "OK"
icon when the desired script file is selected.
The execution of a script can be terminated by clicking on the "abort
script" icon in the tools window.
While a script is being executed the application remains fully interactive
and the user can perform any action. However this can cause interference
with the normal execution of the script and the final result may not be
as expected. Therefore, it is suggested that no user interaction with the
application occurrs until the script finishes its execution.
Do Loops
In order to use the scripting capabilities to produce movies automatically,
do-loops were implemented. The idea is as follows. Suppose we have a set
of files named file001...file100, representing the solution in time of
a certain problem. If we want to see the evolution of, say contour lines
of a given quantity, we would need to produce a contour plot for each of
the files mentioned above (and save the image to a file). This can be automated
in the following way:
- Read the first file (file001).
- Create the desired plot(s) (in this case the contour lines) and save
to an image file.
- Stop zfem to obtain a script file of the form:
proj new local
proj open file file001
proj workers plot contours [...]
viewers send 0 dump rgb image001.rgb
The first two lines open the file, the third creates the contour plot and
the last one saves the image of viewer number 0 to a file in RGB format.
- Edit the script to read:
script format 3
script do $i 1 100 1
proj new local
proj open file file$i
viewers bcast obj clean 1
proj workers plot contours [...]
viewers send 0 dump rgb image$i.rgb
proj close
script enddo
The first line specifies the number of digits
to use when formating numbers in the file names (e.g. if file001 is to
be used the format is 3, if file1 is to be used the format is 1). If this
command is omitted a value of 1 is assumed.
The second line starts a do-loop with a variable called $i (variable names
start with $ and can have any number of characters). The variable will
take the values from 1 to 100 in steps of 1. All the commands up to the
"script enddo" line will be repeated with the variable substituted
by the corresponding value, formatted as explained before.
A line to "clean" the scene (delete all the graphical objects in the scene)
was also added after opening the file.
Note also that a line "proj close" was added in order to close
the file before reading the next one, otherwise 100 files would be open
simultaneously.
- Re-run ZFEM with the new script file (-e option) and wait. Once the
script is completed a set of files named image001.rgb ... image100.rgb
will be obtained.
Script Variables
Beside do-loops it is also possible to define variables in a script, and
perform basic operations on them. All variable names start with $ and
variables starting with [ijklmn] are defined as integers while the rest
are real numbers. The operations performed on the variables must be written
in inverse polish notation between [] (integer operations) or between {}
(real operations). Examples:
script set $i 10
script set $j [$i 10 +]
script set $k [$i 10 -]
script set $m [$j 2 *]
script set $n [$j 2 /]
script set $a 1.0
script set $b 20.0
script set $c {$a $b +}
Whenever a [] or a {} is found, the expression inside is evaluated and
expanded before execution of the script command.
Limitations
Currently the maximum number of variables possible is 20 and the maximum
number of nested loops is 10. The maximum number of characters in the name
of a variable is 30.