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.

Example 1

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..

function NRows(Column\$)

n=0

Repeat

n = n+1

i = lookupcellempty('data',n,Column\$)

until (i=0)

NRows= n - 1

End

N1=NRows('X')

N2=NRows('Y')

N3=NRows('Z')

\$DOLAST

Duplicate i=1, N1

X[i] = lookup('data',i,'X')

End

Duplicate i=1, N2

Y[i] = lookup('data',i,'Y')

End

Duplicate i=1, N3

Z[i] = lookup('data',i,'Z')

End

\$ENDDOLAST

\$TabStops 0.25 0.5 in

Example 2

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.

x^2+y^3=z

x/(y^2+1)=1.2345

\$DOLAST

SumZ=sumParametric('Table 1','z')

\$ENDDOLAST

Directives