SIMSCRIPT II.5 Programming Language
SIMSCRIPT II.5 Programming Language
SIMSCRIPT II.5 Programming Language
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
<strong>Programming</strong> <strong>Language</strong> Concepts<br />
2.6 Reading Subscripted Variables<br />
Subscripted variable values can be assigned from input data by including each element of an array<br />
in the variable name list of a read statement. In the following examples, let LIST be a singly subscripted<br />
variable allocated by the statement reserve LIST(*) as 10.<br />
Individual elements of the array are read by listing their names (the array identifier followed by the<br />
appropriate subscript expression(s) enclosed in parentheses) in the list of a read statement. Values<br />
of LIST(1), LIST(5), and LIST(9) are read by the statement:<br />
read LIST(1), LIST(5), LIST(9)<br />
A variable name list can contain array elements whose subscript designators are expressions, such<br />
as LIST(N*M+2/J) or LIST(I), as long as the variables appearing in these expressions have had<br />
values assigned to them. Note that, as the variables named in a read statement are processed from<br />
left to right, variables to be used as subscripts may be assigned if they appear in a read statement<br />
before their subsequent use in the same statement as subscripts, as in:<br />
read N, M, LIST(N), LIST(LIST(N) + M)<br />
This example shows that both unsubscripted and subscripted variables can appear in the same read<br />
statement list.<br />
This procedure is obviously tedious for large arrays, and so provision is also made for reading all<br />
the values of a subscripted array, in order, by including the unsubscripted array name in the list.<br />
Read LIST reads the 10 elements of LIST, as defined by the reserve statement. Numbers are<br />
read and assigned to the elements of LIST in increasing subscript order: the first data item is<br />
assigned to LIST(1), the next to LIST(2), and so on. If LIST were a multidimensional array, the<br />
data would be assigned to successive elements whose subscripts change in increasing order, with<br />
the last subscript position varying most rapidly. A two-dimensional array is read in row-by-row, as<br />
in TABLE(1,1), TABLE(1,2), TABLE(1,3), ..., TABLE(1,N), TABLE (2,1),<br />
TABLE(2,2), ..., TABLE(2,N), etc.<br />
Mixtures of unsubscripted variables, elements of arrays, and entire arrays can be read in one read<br />
statement. In the following example, if LIST and VECTOR are one-dimensional arrays and X and Y<br />
unsubscripted variables, the statement:<br />
read X, LIST(Y), VECTOR<br />
reads a data item and assigns its value to X, reads another data item and assigns its value to<br />
LIST(Y), and then reads as many values as there are elements reserved in VECTOR.<br />
Clearly, the repetition provided by the use of a control phrase is useful when processing the elements<br />
of subscripted variables. Such a control phrase may be used to govern the reading of array<br />
values. The following statement reads N data values, assigning them to the first N elements of the<br />
array LIST:<br />
49