Defining a Process > Defining Model Elements and Advanced Elements > Subroutines > Defining Subroutines

Defining Subroutines

The Model Elements dialog box is used to define the subroutines that are used in a model and to record a set of properties for each defined subroutine. The Model Elements dialog box is accessed from the Advanced Elements button in the Model Elements portion of Process Simulator ribbon.

 

 

In the image of the Model Elements dialog box above, three subroutines are defined. Subroutine1 does not return any value and does not have any parameters. Subroutine2 returns an integer value when it has completed its logic, and it does not have any parameters. Subroutine3 returns a real value when it has completed its logic, and it is defined to have two parameters (Param1 and Param2) that will receive values from two corresponding arguments that are passed to the subroutine when it is called.

 

Below are descriptions of the fields in the dialog box that pertain to defining subroutines.

 

Name — the name of the subroutine. You can double-click on the name of an existing subroutine if you want to rename it. A subroutine may be named any unique, valid name. This is the name that will be used in the logic to call the subroutine.

 

Return Type — the type of numeric value returned by the subroutine can be real, integer, or none. Select Real if the subroutine will return a real-valued number and Integer if the subroutine will return an integer. Select None when no return value is expected, as is often the case with initialization or termination logic.

 

Parameters — the values of arguments that are passed to the subroutine get assigned to local variables within the subroutine logic. These local variables are called parameters. Parameters can be defined as real or integer values. The first parameter receives the first argument, the second parameter receives the second argument, and so on. Click the heading button, then double-click in this field (or click the ellipsis icon) to open the Parameters dialog box, with which you can type the name and select the data type (Integer or Real) of the parameters that you want for the subroutine.

Logic — one or more statements to be executed whenever the subroutine is called. Statements in subroutines must be valid in the logic that calls the subroutine. Subroutine logic may contain a RETURN statement with a value to be returned from the subroutine. Refer to the topic Return for the correct syntax of this statement. Select Builder if you want to use the Logic Builder to establish the logic that the subroutine is to execute. Select Free Form if you want to use the Free Form Logic window to enter logic for the subroutine without the support for syntax construction that is available in the Logic Builder.

 

Note: the ability to type logic in free form and without use of the Logic Builder is a feature available only in the Professional edition of Process Simulator.

 

Developing Subroutine Logic

 

The crucial step in defining the subroutine is to develop the logic to be executed when the subroutine is called. Click the Logic heading button in the Model Elements dialog box, then double-click in this field (or click the ellipsis icon) to select the means by which you want to develop the logic for the subroutine. Select Logic Builder if you want to use the Logic Builder to produce the logic for the subroutine, or select Free Form if you want to open a window in which you can write the logic manually. If you are adept at writing logic, using the Free Form Logic window can be quicker than selecting options from the Logic Builder, and it enables quicker copying and pasting of logic statements for more rapid building of models.

 

Notes — allows you to type general notes for descriptive information about the subroutine. Click the heading button, then double-click in this field (or click the ellipsis icon) to open a larger window for typing the notes.


© 2014 ProModel Corporation • 556 East Technology Avenue • Orem, UT 84097 • Support: 888-776-6633 • www.promodel.com