next up previous contents index
Next: Functions Up: Expression evaluator Previous: Expression evaluator   Contents   Index


Variables

Variables are defined when they are assigned for the first time, except two predefined variables, e and pi. If a numerical expression contains a non defined variable, the result is set to 0. Uppercase and lowercase characters are distinguished.

Each thread has its particular sets of variables (cf. chapter 10). The same names of variables may be used in several threads, except for the variables whose name begins with a _ (underscore character), which are global variables. For instance the variable num1 may have distinct values in two threads, but _num1 will be the same in all threads. Global variables can be used by threads to communicate with each other.

Each thread has also a particular set of variables : the quick access variables. These variables begin with the character @ followed by a single letter. So there are only 52 quick access variables available for each thread. These variables are treated more quickly by the expression evaluator than the ordinary ones.

It is possible to know which variables are defined and their values by using the command varlist.


Example :

- interpcom -> varlist
                 a=2.000000
                 b=3.000000
                 @x=2.250000

Only variables defined in the running thread or global variables will be shown. It is possible to undefine variables by using the command undef.


Example :

- interpcom -> undef a
- interpcom -> varlist
                 b=3.000000
                 @x=2.250000

The instruction

undef *

will destroy all the variables defined in the running thread, and

undef **

will destroy also the global variables.


The command interpreter uses hidden variables, for the names of the dimensions of objects and for members of structures (cf. 6). These variables are not thread-specific, i.e. they are global variables. A hidden variable is simply a variable whith a name whose first character is not printable. So it is not possible to access directly these variables. Inside a program one may use the functions S_convert_int or S_convert_float. Their unique argument is a string of characters. These functions add a non printable character at the beginning of the string, send this new string to the expression evaluator and returns the evaluation of the string. For instance

S_convert_float("sq_root_of_2=sqrt(2)", flow_interp);

will create the hidden variable sq_root_of_2 (if it did not exist) and assign the square root of 2 to this variable. It is possible to define and fix hidden variables in the !var section of the initialization file. With the command initvar it is possible to use the values of hidden variables. This command will create (or modify) local variables which have the same names as the hidden ones (except of course for the first character that is omitted) and give them the values of the corresponding hidden variables. Subsequent modifications of the visible variables will not affect the values of the hidden ones.

The maximal number of variables that can be defined is 500. It is fixed in the source file interp.h :

#define MAXXVARS 500 /* Max user-defined variables */


next up previous contents index
Next: Functions Up: Expression evaluator Previous: Expression evaluator   Contents   Index
2009-11-12