Scripts


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:

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:

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.