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>SIMSCRIPT</strong> <strong>II.5</strong> <strong>Programming</strong> <strong>Language</strong><br />

3.4.2 The Formatted I/O Statements READ and Write<br />

As described in Chapter 1, input and output data streams consist of a sequence of records, corresponding<br />

to lines of printed output or lines of data accepted from a terminal. Each record, in turn,<br />

is composed of a sequence of fields. A field is a logically defined group of consecutive symbols.<br />

In free-form data, a field is delimited by blank characters. In print output statements, an output<br />

field position within a printed line may be defined by asterisks. This latter facility may be extended<br />

to provide greater program-directed control over the structuring of both input and output records.<br />

A read statement that accepts formatted data has the form:<br />

read variable list as format list<br />

in which each variable value to be read has its input data format field described by a corresponding<br />

field descriptor character in a format list. These formats, which are codes describing how the fields<br />

in the input data stream are composed, are described in the next subsection.<br />

The write statement transfers values from within the computer to specified external media. Every<br />

write statement is formatted. With the sole exception of the list statement, the programmer is<br />

always required to indicate the arrangement of output data. The write statement looks like the<br />

read statement. Its form is:<br />

write expression list as format list<br />

The indicated expressions, which may simply be variables, are evaluated and printed in the form<br />

described by their matching format descriptors. Before illustrating these read and write statements<br />

with examples, the format descriptors are defined.<br />

3.4.2.1 I (Integer) Descriptor<br />

A descriptor of the form n I w is used for converting numbers from their internal integer computer<br />

storage representation to an external format, and vice versa. The character I is always followed by<br />

an expression (w), specifying the maximum number of digits in the integer field, including the sign.<br />

The I can be preceded by a number (n), declaring that the descriptor defines n consecutive identical<br />

data fields. Such formats as 2 I 6 and 14 I 3 define 2 fields of 6 positions and 14 fields of 3<br />

positions, respectively. There must be at least one blank between the fields n, I, w.<br />

When an I format is used for input, it specifies that the full contents of a field w digits wide are to<br />

be stored as the value of a corresponding variable in a read statement. Blank field positions —<br />

leading, embedded, or trailing — are treated as zeros. If a field is unsigned, it is interpreted as positive,<br />

although a plus sign can be typed. Except for the sign character, only numbers can be typed<br />

in a I data field. If w is larger than the maximum number of digits that can be stored in a computer<br />

word, only the rightmost, storable digits are used.<br />

On output, an I format places a right-justified integer value in a field of specified width. Numbers<br />

larger than the field width are converted to scientific notation (see paragraph 3.4.2.3). Positive<br />

106

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

Saved successfully!

Ooh no, something went wrong!