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>Programming</strong> <strong>Language</strong> Concepts<br />

Table 2-5. Values for System Variables When Data Are Ended<br />

_______________________________________________________________________________<br />

Name<br />

data<br />

sfield.f 0<br />

efield.f 0<br />

mode<br />

Value<br />

ENDED<br />

ALPHA<br />

card<br />

NEW<br />

_______________________________________________________________________________<br />

2.27 More Sample <strong>SIMSCRIPT</strong> <strong>II.5</strong> Level 1 Programs<br />

2.27.1 A Data Analysis Program: 1<br />

This example illustrates a use of subscripted variables, with reserve and read statements, and the<br />

use of for loops to control the indexing of subscripted variables.<br />

The program reads a list of N data items into an array. It then goes through the list, computing for<br />

each index value the averages of successive overlapping sequences of values, with sequence lengths<br />

varying from 2 to a maximum of N-1. These moving averages are compared with an arbitrary tolerance<br />

value. If they are less than this value, the values of the index, the sequence length, and the<br />

average are printed.<br />

Program 2-2.<br />

_______________________________________________________________________________<br />

main<br />

define LIST as a 1-dimensional array<br />

define I, J, SEQ.LEN and N as integer variables<br />

define TOLERANCE.VALUE, SUM and AVERAGE as real variables<br />

read N<br />

reserve LIST(*) as N<br />

read LIST, TOLERANCE.VALUE<br />

for SEQ.LEN = 1 to N-1<br />

for I = 1 to N-SEQ.LEN<br />

do<br />

let SUM = 0<br />

for J = 0 to SEQ.LEN<br />

add LIST(I+J) to SUM<br />

let AVERAGE = SUM/(SEQ.LEN+1)<br />

if AVERAGE is less than TOLERANCE.VALUE<br />

print 1 line with I, I + SEQ.LEN and AVERAGE thus<br />

ITEMS *** THROUGH *** HAVE AN AVERAGE OF **.***<br />

always<br />

loop<br />

release LIST(*)<br />

stop<br />

end<br />

_______________________________________________________________________________<br />

89

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

Saved successfully!

Ooh no, something went wrong!