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 />

ements in the prereserved array space. Responsibility for reserving this space rests with the<br />

calling routine.<br />

Routine definition:<br />

routine ADD.MATRICES given A, B, and C<br />

define A, B, and C as real 2-dimensional arrays<br />

normally mode is integer<br />

for I = 1 to dim.f(A(*,*))<br />

for J = 1 to dim.f(A(I,*))<br />

let C(I,J) = A(I,J) + B(I,J)<br />

return<br />

end<br />

Routine called within a program:<br />

define COST1, COST2, TOTAL.COST as 2-dimensional real arrays<br />

.<br />

.<br />

reserve A(*,*), B(*,*) and C(*,*) as N by M<br />

.<br />

.<br />

call ADD.MATRICES given COST1(*,*), COST2(*,*)<br />

and TOTAL.COST(*,*)<br />

2. As an alternative to the above example, the result array could have been reserved by the<br />

called routine and its pointer value returned as a yielded argument. This yielded argument<br />

must be defined at the calling program level to be an array. Note that each call to the routine<br />

reserves space for a new copy of the array. The calling program, therefore, is responsible<br />

for managing the release of these multiple space allocations.<br />

Routine definition:<br />

routine ADD.MATRICES given A and B yielding C<br />

define A, B, and C as 2-dimensional real arrays<br />

normally mode is integer<br />

let NROWS = dim.f(A(*,*))<br />

let NCOLS = dim.f(A(1,*))<br />

reserve C as NROWS by NCOLS<br />

for I = 1 to NROWS<br />

for J = 1 to NCOLS<br />

let C(I,J) = A(I,J) + B(I,J)<br />

return<br />

end<br />

Routine called within a program:<br />

define COST1, COST2, TOTAL.COST<br />

as 2-dimensional real arrays<br />

reserve COST1, COST2 as N by M<br />

68

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

Saved successfully!

Ooh no, something went wrong!