Contents - Index
$DOLAST and $ENDDOLAST
Equations that are placed between the $DOLAST and $ENDDOLAST directives are compiled and executed after all of the other calculations are completed. The capability to control the order in which equations are executed is seldom needed since EES automatically orders the equations to provide the most efficient calculation. However, EES attempts to compile all equations before the calculations begin. Some equations, such as those involving a Duplicate statement cannot be compiled unless the limits are known apriori. In some cases, information such as the limits can be calculated and then used in further calculations. The $DOLAST directive is useful in these situations. Another application of the $DOLAST directive would be to set the limits of an Integral function.
$DOLAST directives can only be used within the main program, i.e., not within Modules or Subprograms. Note that each $DOLAST directive must be matched with a $ENDDOLAST directive. More than one set of these directives can be used but they cannot be nested within each other. However, there is no order for multiple $DOLAST statement. All equations within the combined $DOLAST - $ENDDOLAST directives are solved simultaneously.
When used with a Parametric Table initiated by the Solve Table command, the equations within the $DOLAST - $ENDDOLAST are executed after ALL rows in the Parametric Table have been calculated. The $DOLAST clause is useful in this case to provide information about the completed table, as illustrated in Example 2.
If the $DOLAST directive is used with the Uncertainty Propagation calculation, the uncertainty calculations are initiated after solving the equations that are outside of the $DOLAST - $ENDDOLAST directives, as shown in Example 3.
After the calculations are completed, the values of all variables (those outside and within the $DOLAST - $ENDDOLAST block) are displayed in the Solution window. The equations within the $DOLAST - $ENDDOLAST block are identified with 'Last' in the block number field of the Residuals window. The tree node representing the $DOLAST - $ENDDOLAST equations in the Computational Flow window is displayed as DoLast.
In the following EES program, the NRows function determines the actual number of values in each column of the Lookup table using the built-in function LookupCellEmpty. In this case, only the first 3 rows are in use. Without the $DOLAST directive, EES will attempt to compile the Duplicate statements before N1, N2, and N3 are known, which leads to a compilation error. With the $DOLAST directive in place, the compilation is not attempted until the values of N1, N2, and N3 are determined..
n = n+1
i = lookupcellempty('data',n,Column$)
NRows= n - 1
Duplicate i=1, N1
X[i] = lookup('data',i,'X')
Duplicate i=1, N2
Y[i] = lookup('data',i,'Y')
Duplicate i=1, N3
Z[i] = lookup('data',i,'Z')
$TabStops 0.25 0.5 in
The program below is run with the Solve Table (F3) command. The equations in the $DOLAST clause determine the sum of the values in z column after all of the rows in the table have been calculated. This problem would also work without the $DOLAST clause, but the sum would be computed for each row in the table and thereby require more computing effort.