Elements of the Language

 

The procedure statements follow the conventions of FORTRAN 77 along with the addition of the special Calculator Intrinsic Functions . Each statement contains a maximum of 80 characters. An ampersand (&) at the end of a line indicates continuation on the following line. All lines of code except the PROCEDURE statement may be preceded by a unique numeric label from 1 to 99999 (denoted by "nn" in the statement syntax).

 

A currency sign ("$" in United States) causes all following data on the remainder of the line to be interpreted as a comment rather than a code (Not "C" as in FORTRAN).

 

The statement RETURN signals the end of the procedure section. If there are two RETURN statements, only the lines prior to the first RETURN are compiled.

 

Note that you must not use statements such as "SUBROUTINE", "MODULE", or "FUNCTION" to begin the procedure section.

 

 

Calculator Supplied Arrays

 

All the data types in the FORTRAN-based statements in the procedure section of the calculator module must be calculator supplied arrays or numeric constants. Some of the arrays can be used only on the right hand side of the statements, while the others can be used on both sides. The C( ) (Constants ), P( ) (Parameters ) and the labels for Results have to be initialized in the View area by pushing the appropriate buttons. The following table lists all the supplied arrays and the form in which they can be used of in the procedure statements:

 

image\LINE01.gif

Array name and form

Default Range

Description and Comments

image\LINE01.gif

 

Cn or C(index)

1<= n<= 50

image\LINE01.gif

Pn or P(index)

index = expression

1<=n<= 50

Vn or V(index)

index = expression

1<=n<=200

A floating-point work array used on either the left of right hand side of assignment statements. They are initialized to a large negative value and are not available outside the calculator.

image\LINE01.gif

Rn or R(index)

n = Result number

index = expression

1<=n<=200

The array of calculator results, used on either side of assignment statements. This results vector is available to other flowsheet modules external to the calculator module. These elements are initialized to a large negative values and can be assigned a descriptive label using the Results Table.

image\LINE01.gif

IXn or IX(index)

n = IX array index

0<=n<=9

An array of integer values. It may be used on either side of assignment statements. The form IX(index) is invalid in a DO Statement, since FORTRAN does not permit subscripted variables as DO loop indices.

image\LINE01.gif

ISn

0<=n<=9

An array of elements used as indices of DO loops for stepping through a series of streams in the order defined in the Stream Sequence Table. It may also serve as the stream index in Calculator Intrinsic Functions.

image\LINE01.gif

 

 

Solution Flag

image\BMDMLINE.gif

 

You can use the variable ISOLVE to control the flowsheet calculations, based on the calculator results. It is initialized to zero upon each entry into the calculation procedure and you will have to assign all subsequent values using an Assignment Statement. The following table lists all the allowed values for the flags:

 

image\LINE02.gif

Flag Setting

 

Description

image\LINE02.gif

 

0

The calculator has not yet executed (default) or has solved successfully.

1

The calculator has solved.

2

The calculator did not solve but continue flowsheet calculations within a recycle loop.

3

The calculator did not solve. All calculations stop unconditionally.

4

The calculator solved but stop all subsequent flowsheet calculations. This sets the flowsheet solution flag to "SOLVED"

image\LINE02.gif

 

image\BMDMLINE.gif

 

Mathematical Operators

image\BMDMLINE.gif

The following table list the mathematical operations allowed in expressions of the procedure statements:

 

image\LINE03.gif

Symbol

Description

image\LINE03.gif

+

Addition 

-

Subtraction 

*

Multiplication 

/

Division 

**

Exponentiation (raise to a power) 

image\LINE03.gif

 

image\BMDMLINE.gif

 

User-defined Variables and Arrays

Standard FORTRAN variables may be used in CALCULATORS instead of, or in addition to, the supplied V and IX arrays. They may be up to 8 characters long and may not duplicate the names of any supplied variables; otherwise they follow the conventional FORTRAN rules.

 

DIMENSION variable (subscripts), variable (subscripts), ...

 

The DIMENSION statement is used to define one or two-dimensional arrays. Each subscript may be an integer constant, or two integer constants separated by a colon to specify both the lower and upper array bounds.

 

REAL variable {(subscript)}, variable {(subscript)}, ...

INTEGER variable {(subscript)}, variable {(subscript)}, ...

 

These statements are used to explicitly specify the type of a variable.

 

Examples:

DIMENSION A(20,20), B(20), X(20)

REAL MASS

INTEGER COUNT, TAB(100)

REAL REVENU(1990:1995), PROFIT(1990:1995), LOSS(1990:1995)

 

Note: A variable may only appear once on these statements. The following is valid in standard FORTRAN, but not in the CALCULATOR:

 

REAL MOLWT

DIMENSION MOLWT(50)

 

Both standard FORTRAN and the CALCULATOR accept this equivalent form:

 

REAL MOLWT(50)

 

Assignment Statements

image\BMDMLINE.gif

 

Syntax

 

nn V(i) = expression

nn R(i) = expression

nn IX(i) = expression

nn ISOLVE = expression

 

Operator Precedence

The operations on a given statement are executed in the following order:

 

image\KEY01.gif Expressions within parenthesis ( ) (evaluated innermost first)

image\KEY01.gif Functions (evaluated second)

image\KEY01.gif Exponential (**) (evaluated third)

image\KEY01.gif Multiplications and divisions (*, /) (evaluated fourth)

image\KEY01.gif Additions and subtractions (+, -) (evaluated fifth, left to right)

For calculations with the same precedence, expressions are evaluated from right to left for exponentials and left to right for all others.

 

 

Calculation Flow Control Statements

image\BMDMLINE.gif

 

The flow of control within the calculator procedure can be controlled using the following FORTRAN statements:

 

GOTO statement

CONTINUE statement

IF statement

DO statement

 

 

 

GOTO Statement

Syntax: nn GOTO mm

 

Branches to statement with label mm unconditionally. GO TO written as two words is also supported.

 

 

CONTINUE Statement

Syntax: nn CONTINUE

 

This statement serves as a branch destination or the end of a DO loop. It performs no calculations.

 

 

IF Statement

Syntax: nn IF (expression) conditional clause

 

This statement allows logical branching during calculations. If the parenthetic expression is true, it executes the conditional clause, which may be any procedure section statement except RETURN, IF or DO. The following table lists all the logical operators allowed in the expression:

 

image\LINE04.gif

Operator

Description

image\LINE04.gif

.EQ.

equal to

.NE.

not equal to 

.LT.

less than

.GT.

greater than

.GE.

greater than or equal to

.LE.

less than or equal to

.AND.

both true

.OR.

either true

.EQV.

equivalent

.NEQV.

not equivalent

.NOT.

true/false toggle

image\LINE04.gif

 

 

Block IF constructs

Syntax: nn  IF (expression) THEN

   ELSEIF (expression) THEN

   ELSE

   ENDIF

 

The standard FORTRAN block IF statements are supported. ELSE IF and END IF (written as two words) also are accepted. Block IF constructs may be nested.

 

 

DO Statement

 

Syntax: nn DO mm IXn = i,j,k (or)

nn DO mm ISn = sid1, sid2

 

This statement indicates the beginning of DO loops having a range extending through statement label mm. Specially designated indices must be used for DO loop counters. IXn (a Calculator Supplied Array) requires integer values for the initial and final indices "i" and "j". The incremental step index "k" is optional and defaults to 1.

 

It is also possible to loop on streams, with stream label sequence as defined by the order in the Stream Sequence Table . ISn requires stream sequence's initial and final indices sid1 and sid2. All the streams defined within this range are iterated through and therefore no incremental step index is allowed.

 

 

FORTRAN Intrinsic Functions

image\BMDMLINE.gif

 

All the FORTRAN intrinsic functions can be used in the calculator procedure statements. The following table lists all the available functions (all function parameters must be real numbers):

 

image\LINE05.gif

Function

Description 

Result Type

image\LINE05.gif

 

ABS(x)

Absolute Value

real

DIM(x)

Positive Difference

real

EXP(x)

Exponential e

real

INT(x)

Truncation

integer

LOG(x)

Natural Logarithm

real

LOG10(x)

Common Logarithm

real

MIN(x,y,...)

Minimum Value

real

MAX(x,y,...)

Maximum Value

real

MOD(x,y)

Remainder

real

NINT(x)

Nearest Integer

integer

SQRT(x)

Square Root

real

SIN(x)

Sine (radians)

real

COS(x)

Cosine (radians)

real

TAN(x)

Tangent (radians)

real

ASIN(x)

Arc Sine (radians)

radian

ACOS(x)

Arc Cosine (radians)

radian

ATAN(x)

Arc Tangent (radians)

real

SINH(x)

Hyperbolic Sine

real

COSH(x)

Hyperbolic Cosine

real

TANH(x)

Hyperbolic Tangent

real

image\LINE05.gif

 

 

Calculator Intrinsic Functions

image\BMDMLINE.gif

 

The Calculator module contains special intrinsic functions which allow you to retrieve component and stream properties directly. For these functions, the component identifying number and stream label are used as parameters. The streams identifier must have been selected in for the calculator Stream Sequence Table . Property values are retrieved in the dimensional units used for the simulation input. The total number of components and streams may also be retrieved and used as limits for loop calculations, etc.

 

The following table lists the available Calculator Intrinsic Functions:

 

cno : Integer component number which is either an actual integer or an IXn value.

sid : Stream identifier of ISn value.

 

image\LINE06.gif

Function

Description of Property 

CMW(cno)

Molecular Weight

CNBP(cno)

Normal boiling temperature

CSPGR(cno)

Specific gravity (60F/60F)

CTC(cno)

CPC(cno)

Critical pressure

CVC(cno)

Critical volume, cc/gm-mole

COMEGA(cno)

Acentric factor

Stream Component

Properties  

SCMF(cno, sid)

Molar fraction of component in stream

SCWF(cno, sid)

Weight fraction of component in stream

SCVF(cno, sid)

Standard liquid volume fraction

SCMR(cno, sid)

Molar rate of component in stream

SCWR(cno, sid)

Weight rate of component in stream

SCLVR(cno, sid)

Standard liquid volume rate of component

SCGVR(cno, sid)

Standard gas volume rate of component

image\LINE06.gif

Stream

Properties

SMR(sid)

Mole rate of stream

SWR(sid)

Weight rate of stream

SLVR(sid)

Standard liquid volume rate of stream

SGVR(sid)

Standard gas volume rate of stream

STEMP(sid)

Stream temperature

SPRES(sid)

Stream pressure

image\LINE06.gif

Miscellaneous

Properties

MAXC

MAXS

Maximum number of streams in the simulation

image\LINE06.gif

 

image\BMDMLINE.gif

 

Stream Property Storage Subroutines

 

PRO/II contains special subroutines which store a calculator supplied array element as a stream property or a stream component property. The values being stored must be computed in the dimensional units used for data input. The resulting stream is flashed at the new conditions to determine its thermodynamic state.

 

image\BMDMLINE.gif

 

SRXSTR subroutine

Syntax: nn CALL SRXSTR(type, value, sid)

 

This subroutine is used to store an overall stream property. The parameters for this subroutine are:

 

type: The stream property to store. The following table lists the available options:

 

image\LINE07.gif

type

Description

image\LINE07.gif

 

SMR

mole rate of stream

SWR

weight rate of stream

SLVR

standard liquid volume rate

SGVR

standard gas volume rate of stream

STEMP

stream temperature

SPRES

stream pressure

image\LINE07.gif

 

value: The value of the property to be stored in the stream. It can be a numeric value or a descriptor identifying a variable.

 

sid: The stream identifier in which the property has to be stored. The identifier can be one of the streams listed in the Stream Sequence Table , or it can be an element of array IS in the form ISn.

 

Example: CALL SRXSTR( SPRES, R(2), STRM004 )

 

The value element 2 from array R is stored as the pressure of stream STRM004.

 

image\BMDMLINE.gif

 

SRVSTR subroutine

Syntax: nn CALL SRVSTR (type, array, sid, i, j)

 

Use this call to store a range of values representing component stream properties from a calculator array into a stream. The parameters for the subroutine are:

 

type: The component property to be stored in the stream. The following table lists all the available options:

image\LINE08.gif

Type

Description 

image\LINE08.gif

SCMR

molar rate of component in stream

SCWR

weight rate of component in stream

SCLVR

component standard of liquid volume rate

SCGVR

component standard gas volume rate

image\LINE08.gif

 

array: Initial element of a calculator supplied array containing values to store as properties of components in a stream.

 

sid: Identifier of the stream in which the property has to be stored. It may be any stream identifier selected in the calculator Stream Sequence Table , or an element of IS in the form ISn

 

i, j: Component id numbers. They indicate the first and last components of the stream, respectively, for which property is stored.

 

Example: CALL SRVSTR( SCMR, V(3), STRM1, 2, 5 )

 

The values of elements V(3) - V(6) are stored as the molar flow rates of components 2 - 5 in stream STRM1.

 

Print Control Statements

 

image\BMDMLINE.gif

 

Display statement

Syntax: nn DISPLAY { R(i:j), P(i:j), C(i:j), V(i:j), IX(i:j), IS(i:j) }

 

This statement prints out array values during calculations. The position of DISPLAY statements in the procedure section determines when values are printed. Entries "i" and "j" refer to the first and last elements of the array to print. If they are absent, the entire array is printed.

 

image\BMDMLINE.gif

 

FORMAT Statement

Syntax: nn FORMAT ( item, item, … )

 

image\format2.gif

 

image\EDIT03.gif The following items are allowed:

 

image\format1.gif

 

image\EDIT03.gif Standard FORTRAN rules are used when:

 

The variable list in the WRITE statement is exhausted but there are still more FORMAT items.

The list of FORMAT items is exhausted but there are still variables in the WRITE statement.

 

 

Open statement

Syntax: nn OPEN ( FILE = FileID, ACCESS=OVERWRITE or APPEND )

 

This statement opens a file for calculator output (using an OUTPUT statement). It automatically closes any previously opened file. If neither access option is given, the default is OVERWRITE. Note that the OUTPUT statement performs the actual write to files.

 

The default output file is named current_FileID.CAL. The "current_FileID" is the name of the simulation file that is being run. A unique file name may be specified, if necessary; however, it still will have the .CAL extension.

 

 

Output statement

Syntax: nn OUTPUT { R(i:j), P(i:j), C(i:j), V(i:j), IX(i:j), IS(i:j) }

 

This statement prints out the array values to the currently open file (that has been opened using an OPEN statement). Multiple OUTPUT statements may be used. They may appear at any time following an OPEN statement.

 

Entries "i" and "j" refer to the first and the last elements of the array to print. If they are absent, the entire array is printed.

 

Trace statement

Syntax: nn TRACE option

 

This statement controls printing of an historical trace as calculations proceed. This facilitates debugging the code in the calculator procedure. The options available are:

 

ON Print the line number, statement number and (a) action taken, or (b) new variable value, as each statement executes.

BRANCH Print TRACE information only for branching statements such as IF, GOTO or DO.

OFF Turn off all TRACE options.

 

 

WRITE Statement

Syntax: WRITE (*, fmt) var, var, var, … )

 

 image\write1.gif

 

In standard FORTRAN, the first entry within the parentheses may be either a unit number or an asterisk to indicate that the standard output file is to be used. However, only the asterisk is allowed within the Calculator.

 

There are three ways to output arrays and array elements in standard FORTRAN:

 

 image\write2.gif

 

Calculation Termination Statements

 

STOP statement

Syntax: nn STOP

 

This statement stops all flowsheet calculations and proceeds directly to the output report. The Solution Flag for the entire flowsheet is set according to the user defined value of ISOLVE.

 

 

RETURN statement

Syntax: nn RETURN

 

This statement signals the end of the calculator procedure of the calculator and must appear as the last statement in the procedure section. Only one RETURN statement is allowed in the PROCEDURE, and it is required. The Solution Flag for the calculator is set according to the user-defined value of ISOLVE.

 

 

Related Topics

Calculator - General Information

Calculator Main Window

Calculator - Examples