Inline variables
Inline variables are indicated with the symbol @ in the input file. During runtime, these inline variables are replaced by values (numerical or alphanumerical) when a specific logical line is read by the program. Because lines are read line by line during execution and not all at once in the beginning, the corresponding values are adapted dynamically to their definitions during runtime. A logical line is different from a physical line when reading the input file: one physical line can contain more than one logical line when it contains the line separator ; - a logical line can be composed of several physical lines by the line continuation operator \. The alphanumerical values can not contain line separators, continuation operators, hard returns (which forms an extra physical line after a logical line has been identified), nor the comment character (#, after which characters are not included in the logical line).
When an integer is expected in the input file, an exponential format of the value may result in an error during execution. For example, 1.00100E3 will not be interpreted as the integer 1001 which may lead to an error message or even just an error in the calculation. Examples are e.g. when saving a result (SAVE) or when defining the solution numbers of the MIX statement. The format is indicated by text between %%, see below.
The inline variables can refer to single numerical or alphanumerical values or can indicate a simple expression. In its most simplest form, the inline variable is defined by a global variable using global_variable:
global_variable ExchangeSite 0.1 "Site of the exchange site"
EXHANGE 1
X @ExchangeSite
The values that will replace the inline variables are or can be defined in different ways:
- a global variable defined or adapted by global_variable
- a global variable defined or adapted by in a script using put_var()
- a counter variable defined by COUNTER with the option to change or reset values after replacing the inline variable
- a value from a datablock defined by DATABLOCK given each column has a heading name and a column acting as row indicator has been defined.
- a value that is returned form a script defined in calculate_values
- system-defined global variables (see System inline variables)
The first five methods are detailed below.
The symbol @ can be followed by a special character
- < and should be closed by >: indicates a mathematical expression.
- ! and should be closed by !: indicates the formation of the inline variable name.
- % and should be closed by %: indicates the format of numerical values.
The special functions are detailed below.
Inline variables
GLOBAL_VARIABLE
COUNTER
DATABLOCK
CALCULATE_VALUES
The inline variable consists simple of the name of the script defined in a calculate_value datablock:
@calculate_values_name
Note that this is limited to numerical values only. When a - sign precedes the name, the inline value is a single space (note that the script still needs a (dummy) return value). This option is useful if one needs to adapt the value of several global variables (via put_var()):
@-calculate_values_name
Functionalities
Mathematical expression
To define a mathematical expression as a inline value, the following sequences is used @<mathematical expression> where the mathematical expression following the syntax of the mathematical parser and interpreter muparserX :
global_variable ExchangeSiteDensity 0.01 "Site of the exchange site / g clay"
global_variable AmountClay 10 "gram of clay in the system"
EXHANGE 1
X @<@ExchangeSiteDensity*@AmountClay>
Mathematical expressions cannot be nested.
Formation of the inline variable name
For the expression @!expression!, only !expression! is replaced and the expression remains an inline variable. It allows for defining the inline variables based on global or datablock variables.
For example, assuming a datablock with pH values for different experiments (see Examples of inline definition and use)
GLOBAL_VARIABLE Experiment$ Exp01
solution
-pH @!@<"ExperimentalConditions:pH:"//@Experiment$>!
The expression !@<"ExperimentalConditions:pH:"//@Experiment$>! will first be evaluated resulting in this particular example in ExperimentalConditions:pH:Exp01. The line remains
@ExperimentalConditions:pH:Exp01
This inline variable will then be replaced. The value will taken from the datablock ExperimentalConditions, the column pH and the row with label Exp01.
For an inline variable of the typ @%format%name, the value of name is printed with the format format. This only applies for numerical values. format follows basically the C++ format specifier:
%[flags][width][.precision][length]specifier
with
specifier specifies the type of the output.
Most relevant specifiers are:
d or i integer
f floating point
e scientific notation (mantissa/exponent), lowercase
E scientific notation (mantissa/exponent), uppercase
g shorter notation of e or f
G shorter notation of E or F
width Minimum number of characters to be printed; if the value to be printed is smaller, blank spaces are added.
precision for f,e,E,g and G: number of digits to be printed after the decimal point
flags
- Left-justify within the given field width
+ Result will be preceded by a - or + sign. By default, only negative numbers are preceded by a - sign.
0 Left pads the number with zeroes instead of spaces
Note that the # symbol does not work as this will be interpreted as the comment character during reading
The default format is %12.4e.
The format symbol @%format% can be combined with the mathematical expression symbol (@%format%<mathematical expression>) or the formation symbol (@%format%!expression!).