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

After all input or output to a unit has been completed and the unit is no longer required, the link<br />

between the <strong>SIMSCRIPT</strong> <strong>II.5</strong> logical unit and the physical device, as controlled by the operating<br />

system, may be removed by closing the unit. This is achieved by a statement of the form:<br />

close unit device<br />

If the device is the current input or output unit, then that unit (read.v or write.v) is reset to its<br />

default value. Note that at the completion of a <strong>SIMSCRIPT</strong> <strong>II.5</strong> program, all files used or opened<br />

during the course of the program run will be closed automatically by <strong>SIMSCRIPT</strong> <strong>II.5</strong>.<br />

3.5.2 End-of-File Conditions<br />

Whenever a read statement is executed, there is the possibility of reading data from an "empty"<br />

file or reaching the end of the data file, which is referred to as an end-of-file condition. The freeform<br />

read statement, as previously noted, provides a check for an end-of-file condition through the<br />

statement if data is ended. A similar check is needed for formatted I/O.<br />

A <strong>SIMSCRIPT</strong> <strong>II.5</strong> system-defined variable, eof.v, is maintained for each logical input unit. A<br />

reference to eof.v applies always to the value of the current logical unit, set by use. This variable<br />

is initialized to zero when a unit is first referenced. When an end-of-file condition is encountered<br />

by a read statement, the <strong>SIMSCRIPT</strong> <strong>II.5</strong> system refers to the eof.v variable for direction. If<br />

eof.v is still equal to zero, encountering the end-of-file condition is considered an error, and the<br />

program terminates with an error message. If, however, under program control, the eof.v variable<br />

has previously been assigned the value 1, the variables in the read list are assigned values of<br />

zero, the eof.v variable is set to 2, and control returns to the statement following the read. In<br />

other words, setting the value of eof.v to 1 is considered a message to the <strong>SIMSCRIPT</strong> <strong>II.5</strong> system<br />

to the effect, "Do not terminate the program; return zero values and indicate that the end-of-file<br />

marker has been encountered." By testing eof.v after a read statement, the program logic can<br />

determine whether the statement read true data or encountered an end-of-file marker. This facility<br />

can be used in the following ways:<br />

1. As an end of data signal:<br />

use unit 1 for input<br />

let eof.v = 1<br />

.<br />

while eof.v ne 2,<br />

do<br />

read Z as I 2<br />

add Z to SUM<br />

add 1 to COUNTER<br />

loop<br />

write COUNTER, SUM/COUNTER as "The Average of", I 4,<br />

"Items Processed Is", D(6,2)<br />

stop<br />

end<br />

120

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

Saved successfully!

Ooh no, something went wrong!