Contents - Index

Internal Procedures


EES Procedures are very much like EES Functions, except that they allow multiple inputs and outputs.  The format of a Procedure is:




            Optional help text can be provided as a comment, as shown here}



   X :=...

   Y :=...



Procedures must be placed at the top of the Equations window, before any of the non-function and non-procedure equations. The Procedure name, TEST, in the example above, can be any valid EES variable name.  The argument list consists of a list of inputs and a list of outputs separated by a colon.  In the example above, A, B, and C are inputs and X and Y are outputs.  Each Procedure must have at least one input and one output.  Array range notation can be used for both inputs and outputs.  Variable values can also be passed to an internal Procedure using the $COMMON directive.  Each output variable must be defined by an equation with the output variable name on the left of the equal sign.  An END statement closes the Procedure.  Optional help can be provided as a comment starting with a $, just as for Internal Functions.


To use the Procedure, place a CALL statement anywhere within your equations.  The CALL statement appears as


CALL TEST(1,2,3:X,Y)


The number and order of inputs and output in the CALL statement argument list must exactly match the PROCEDURE declaration statement.  The arguments may be constants, variables, or algebraic expressions.  EES will evaluate the outputs using the input variables supplied in the argument list.  Functions and Procedures may also call other Procedures, provided that the Procedure is defined previously.   Arguments are separated by a comma (U.S. numerical format) or a semicolon (European numerical format).


Starting with version 9.513, it is possible to call an internal or external Procedure with fewer output variables than indicated in the Procedure statement.  For example, if it is desired to only evaluate variable Y by the procedure, the CALL statement can be entered as:


CALL TEST(1,2,3:{X},Y)     or      CALL TEST(1,2,3:,Y)


Note that {X} is commented out and need not be entered, but the list separator must be provided and the order of the outputs remains as indicated in the Procedure statement.


The equations within a Procedure differ from ordinary EES equations which are not in Functions or Procedures.  First, all variables except for the inputs and outputs are local to the Procedure.  Second, the equations are really assignment statements, rather than equalities, and to make this distinction clear, the assignment symbol (:=) is used in place of the equal sign.  You may override this convention by enabling the Allow = in Functions/Procedures control in the Preferences dialog window.  Third, IF - THEN - ELSE, REPEAT-UNTIL, GOTO statements, Return and other logic control statements and other control logic statements may be used.   Note the EES also provides Modules and Subprogram which are quite similar to Procedures except that Modules and Subprogram use equalities and do not allow logical statements, just as in the main body of EES. 


The local variables used within a Function or Procedure are normally not of interest. The values are not initialized and they do not remain in memory after the calculations are completed.  The local variables in a Function or Procedure are always real regardless of the Complex Numbers setting.  All variables used in the Procedure will display in Solution window.  Array variables that are defined and used in the Procedure can be displayed in the Arrays table window by placing a $ARRAYS ON directive in the function.


Procedures offer a number of advantages for the EES user.  Commonly used procedures may be saved separately in a .LIB fle.  If the .LIB file is located in the USERLIB directory, it will be automatically loaded when EES is started.  Alternatively, *.LIB files may be loaded with the Load Library command or with the $INCLUDE directive.  For example, the equations describing a turbine can be entered once and saved.  Each time a turbine calculation is needed, the CALL Turbine statement can be used to determine the turbine work and outlet state variables.  Modules and Subprograms provide similar capability.  An advantage of Procedures is that logic statements such as IF-THEN-ELSE, CASE, and REPEAT-UNTIL can be used.  The Print command can also be used for debugging or for output of results.  


EES supports both internal and external Procedures.  Internal Procedures are entered directly at the top of the Equations window, as described in this section.  External Procedures are written in a high-level language such as C, Pascal, or FORTRAN and called from EES.  The CALL statement for both types of Procedures is identical. 


Procedures can be called from the main program or a Subprogram that is configured to operate in complex mode.  However, only real equations are solved within a Procedure.  Note that Functions and Procedures cannot be used in complex mode.


Help can be provided as a comment in the file (shown in the example above) or in a separate Help file.