18.10.2014 Views

SIMSCRIPT II.5 Programming Language

SIMSCRIPT II.5 Programming Language

SIMSCRIPT II.5 Programming Language

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Advanced Topics<br />

The task of a right-handed function routine is to return a data value to a calling program. A typical<br />

right-handed function (not performing a monitoring task) is:<br />

function EXAMPLE(I,J)<br />

.<br />

.<br />

statements using I and J<br />

.<br />

.<br />

return with expression<br />

end<br />

The function name (EXAMPLE) represents a subprogram name. The argument list transmits initial<br />

values for I and J from a calling program to EXAMPLE, and the return with statement returns a<br />

computed value to the calling program.<br />

If EXAMPLE is declared as a monitored variable, its name refers to both data and a monitoring routine.<br />

EXAMPLE(K,5) is both a legitimate subscripted variable reference and a call on a routine with<br />

arguments K and 5. The additional statement needed to convert a normal right-handed routine to a<br />

right-handed monitoring routine fetches the data value associated with the monitored variable<br />

name, and makes it accessible to a named variable within the routine. The statement is:<br />

move to variable<br />

The program:<br />

function EXAMPLE(I,J)<br />

move to Q<br />

.<br />

.<br />

statements using I,J, and Q<br />

.<br />

.<br />

return with expression<br />

end<br />

starts out by assigning the value of EXAMPLE(I,J) to Q, which then can be used freely in the routine.<br />

The move statement variable can be local or global, unsubscripted or subscripted, an attribute,<br />

or even a left-handed function.<br />

Except for defining EXAMPLE as being monitored, no other change is made in the rest of the<br />

program. EXAMPLE is reserved and used in the normal way; all data references are to<br />

EXAMPLE(I,J), as though it were a simple subscripted variable.<br />

Used for left-handed monitoring, the move statement must assign a value to the data cell associated<br />

with a monitored variable. The statement that does this is of the form:<br />

283

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!