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.

<strong>Programming</strong> <strong>Language</strong> Concepts<br />

for I = 1 to N, read A(I)<br />

Here, a free-form read reads a sequence of values across the current input record. If the values are<br />

packed, however, with no blanks between them, the individual data fields cannot be identified by<br />

the free-form read. An alternative might be to write:<br />

for I = 1 to N, read A(I) as I 4<br />

This form may be used if the values of A(I) are spaced across entire records. If, however, the data<br />

are arranged so that values are contained only in columns 1 through 60 of successive 80-byte data<br />

records, the above statement will read through column 60 and attempt to take values from columns<br />

61 through 80. The read must be directed to skip to a new input record upon reaching column 61.<br />

An expression enclosed in parentheses, placed before a format list, repeats that format list the indicated<br />

number of times and then skips to a new record. The statement above should be written as:<br />

for I = 1 to N, read A(I) as (15)I 4<br />

If N = 12 and four numbers are to be read per record from columns 1 through 24, the following<br />

statements read 12 values from 3 records:<br />

start new record<br />

for I = 1 to N, read A(I) as (4)I 6<br />

This form may also be used if groups of variables with different formats are in a record. The following<br />

statement reads four pairs of data fields in the format I 6,D(6,2) from each data record<br />

until 2*N values have been read:<br />

for I = 1 to N, read A(I), B(I) as (4) I 6, D(6,2)<br />

Such a repetition facility can be used with both read and write statements, but it can only be<br />

used in statements controlled by for phrases. This particular form of the read statement assumes<br />

that input starts at the beginning of a data (record), which explains the start new record statement<br />

in the foregoing example. The statement can terminate, of course, with the current input pointer<br />

positioned in the middle of a record, depending on the format used.<br />

Similar rules apply to the print and list statements, as well as to all input/output operations performed<br />

by the <strong>SIMSCRIPT</strong> <strong>II.5</strong> system. Output is printed wherever the current pointer points, assuming<br />

it is at the head of a record. After output, the system positions the pointer at the head of the<br />

next record.<br />

3.4.5 Variable Formats<br />

The use of format descriptors containing expressions as well as constants is one feature available in<br />

read and write statements that has not been discussed. Arithmetic expressions can be used to<br />

control field widths in formats for data-layout purposes. For instance, a curve of the natural log<br />

function, using * as a graphical character, is generated by the statement:<br />

117

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

Saved successfully!

Ooh no, something went wrong!