18.10.2014 Views

SIMSCRIPT II.5 Programming Language

SIMSCRIPT II.5 Programming Language

SIMSCRIPT II.5 Programming Language

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>SIMSCRIPT</strong> <strong>II.5</strong> <strong>Programming</strong> <strong>Language</strong><br />

often be reduced by structuring it so that not all arrays need be reserved concurrently. The release<br />

statement has the general form:<br />

release array-pointer list<br />

Examples are:<br />

release A(*)<br />

release COEFF (*,*), WIDTH (*), DIMENSIONS (J,*)<br />

No access should be attempted to any element of a released array. The array cannot be distinguished<br />

from one that has not been reserved, and an error will result. The array may, of course, be re-reserved<br />

with the same dimensionality.<br />

2.18 Array Pointers as Routine Arguments<br />

Thus far, routine arguments have represented the values of variables, or, in the case of given arguments,<br />

the values of arithmetic expressions. These values are copied between the calling and called<br />

routine, as indicated by the ordering in the argument lists. Such arguments are said to be passed<br />

between routines by value. The value of a subscripted variable may be used in the same way as an<br />

unsubscripted variable. The transmission of an array of values is handled differently. To reserve<br />

and copy entire arrays of values would involve significant inefficiencies. For this reason, when arrays<br />

appear as routine arguments they are passed by reference, that is, a pointer value is passed.<br />

When an array name appears in an argument list, the value of the array base pointer is transmitted,<br />

rather than the array element values. By using this pointer, the receiving routine can access the element<br />

values within the array structure. For an array pointer transmitted as an argument to be recognized<br />

as such, and to enable the correct accessing of its element values, both the mode and<br />

dimensionality of the array represented must be defined to the receiving routine. The following<br />

function routine illustrates the use of an array name as an argument. The function computes the<br />

trace of a square matrix, defined as the sum of the diagonal elements. As the matrix must be square,<br />

it is sufficient to pass one value indicating the number of rows and columns. For example:<br />

function TRACE(MATRIX, SIZE)<br />

define MATRIX as a real, 1-dimensional array<br />

define SIZE as an integer variable<br />

define SUM as a real variable<br />

define I as an integer variable<br />

for I = 1 to SIZE<br />

add MATRIX(I,I) to SUM<br />

return with SUM<br />

end<br />

In this function routine, the argument MATRIX is locally defined as an array. A pointer value is assigned<br />

to it, not by a reserve statement, but by copying the transmitted value of the array base<br />

pointers passed from the calling routine. In this way, the function works with the actual element<br />

66

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

Saved successfully!

Ooh no, something went wrong!