The Simscript Programming Language: P. Kivict. R. Villanueva Ant, H. M. Markowitz
The Simscript Programming Language: P. Kivict. R. Villanueva Ant, H. M. Markowitz
October 1968
R-460-PR
A REPORT PREPARED FO ..
PREFACE
DISTRIBUTION STATE.MENT
Thi. diurmrt hjI. le)ppro•ed for pullic rel•eacs drl ,ale:
it, d trilutii i '. irullinited.
A IW
"-.'.m• w
S*•MMARY
Except for some basic knowledge concerning what a computer is end what
a programing language translator (compiler) does, no prior computer
education or programing knowledge on the reader's part has been
"*used. As a result, the Report will not have equal appeal to all
readers. Professional programers vill find it slow reading at first;
novices may wish it read more slowly. To reduce the discomfort of
either too slow or too rapid a pace through all of SIMSCRIPT I1,wV
suggest a selective path through the Report. Stctions that a,- un-.
usually difficult or contain features of powerful but limited use a-,e
-vi-
i
-vii-
ACXNOWLED04ENTS
face routines for the IBM 360 compiler, influenced our language de-
sign.
SISCRIPT II having turned out to be more than just an extended
SIMSCRIPT, wv want to acknovledge the contributions of many friends --
compiler writers, language designers, and programers -- who have in-
teracted with us over the y'_•rs. Some of their suggestions are re-
flected in the simulation-oriented sections of the language. Much
of their influence is seen in the part of SIMSCRIPT II that can be
called a "general programing language." We would like to thank
Bob Balser, John Buxton, John Laski, Howard Krasnov, John McNelsy,
Kristen Nygaard, and Paula Oldfather for their suggestions and crit-
icisms. Should they, or any others, perceive glints of their own
ideas in SIMSCILIFT II. they should not be surprised.
Lastly. wa wish to thank X. J. Shukisr for the many helpful sug-
gestions he made whila reviewing the manuscript and using early vor-
sions of the compiler. Sally Anderson labored over the Index, for
which we are truly Mrateful.
-ix-
CONTENTS
Chr.pter 1
SIM CRIPT II: Level 1 ......................................
1-00 Introduc tion .................................. .... 1
1-01 Vara Zb#e ............... .......... ......... . .... ... .
1-02 Const ts ................................... .... 2
1-03 Arithmetic Expreseions ............................. 2
1-04 Logical Expressions ................................ 5
1-05 Readinq Data from Punched Carde .................... 6
1-06 Skipping Lu.wantcd Data ............................. 7
1-07 Computing Variable Values .......................... 9
1-08 Specialized Cof:,tation Statementa ................. 9
1-09 A Pgra on cards and the F" of Comprtatian ... 10
1-10 Clarifying C'omir- .'n a Pmq*r ................... 12
i-il Chaning the Flow of Computation y Direct Oier 13
1-12 Chwiging the FZot of Computation by
Loqia! Expresion ............................ 13
2-13 Displaying the Results of Cc•utation ............... 17
1-14 The Logical Endof aProlrG I ....................... ?
1-15 The Phyuical End of a Progr ...................... 2'
1-16 Some '72pTe SI.CCRIPT II, Lev 1 PAogrxm ......... 21
Chapter 2
SIMSCRIPT II: Level 2 .................................... 28
2-00 Variab'* and L&*•Z YVtw, Peesee.................. 28
r- :ab,U .4o d e ..................................... 29
"2, icbl
va" ... ............... 31
- SCbe'ipe: . ,rr ................................. 33
-::•4 S e'r • ............................. 40
a
?_1.... ; witpe................................ 4
-A.Y~i '~tdjtra ee 11!-.8
-,,.. Te................................ 48
":-: p, . ,f , ;............................... 76
-:4 3:e:e~'-2 Lab*:*.• .............................. 78
-I--
Chapter 3
SI[SCRIPT II: Level 3
3-00 A Statement for SimpZiffyiin Nes el7 Statiments .... 131
3-01 A Statement for SimpLifying NVested DO Loops ......... 132
3-02 Cp 'fying Complex Logical Expr•asione............... 134
3-03 Logical Control Prase .............................. 137
3-04 Returning Routines to Free Store ................. 1 40
.- 05 External Srorze vid Retrieval of Routines .......... 142
3-06 A Sea-rc Statem nr .................................. 145
3-0' A Statmnt for Camuting Sow. StandarI
Y%*tctionB of vari-blea .......................... 147
3-08 Alpha--A Ye wMode ................................... 150
3-09 A Formwtte'd Inout/Output Statement .................. 153
3-121 MiEcezza-.o'•u fnput/9•utut Staterwnts
and Fa-.Zt CiO8 .... .............................. 173
3_7- 1 F.j 'ýing
1rtrz .~fIo'ai'......................176
3-1
- WritrYnc Fo t:e .Reprts ................................ 179
1
SChapter 4
Chapter 5
SIMSCRIPT I: Level 5 ............................. ....... 281
5-00 Introducticn ....................................... 281
5-01 Decribing System Dyncrics ........................ 282
5-02 Controlling System Dynamics ........................ 293
5-03 Modeling Statistical Phenomena ..................... 312
5-04 Model Debugging and Analysis ....................... 322
5-05 A Simulation Exmple ................ ... ............ 336
5-06 Miscellaneous Simulation Topics .................... 357
5-07 Reocap .............................................. 366
Chapter 1
i-00 INTRODUCTION
READ X, Y AND Z
ADD X + Y TO Z
PRINT I LINE WITH Z AS FOLLOWS
X+ Y+ z =
STOP
1-01 VARIABLES
1-02 CONSTANTS
a. Exponentiation
b. Multiplication and division * and /
c. Addition and subtraction + and -
equal
÷ not equal
< less than
< less than or equal
> greater than
> greater than or equal
X - Y is false
X> Y is true
X< Y is false
X+ Y - X * Y is false
a. Y 0
b. AGE LESS THAN RETIREMENT
c. CODE NOT EQUAL TO ZIP
d. LEVEL LT THRESHOLD
e. (FIXED * *JER " UNITS) GREATER THAN L0ID
f. A G1 (8 # X 2 * 3.57/C)
g. (X 2 + Y 2) GREATER THAN *'Z
h. X 2 + Y 2 1 Z "" 2
-6-
Table 1-1
RELATIONAL OPERATORS
Permitted Permitted
Hathemacical Keypunch English "Literary English"
Symbol Symbol Abbreviation Equivalent
- EQ EQUAL TO
EQUALS
"NE NOT EQUAL TO
< LS LESS THAN
LT
GR GREATER THAN
GT
< < LE NO GREATER THAN
NOT GREATER THAN
G> NO LESS THAN
-_ _NOT LESS THAN
I. Y. and QUANTITY are variable nas. They are used in this state-
ment in a LvmiablZ %.ww list.
ia general a SISCRIPT II 4'it consisto of a string of quantities
separated by either a co, or the vord AND. or a coma followed by
the word AAD. Sesi examples of lists &a they sight appear in READ
etatats are:
SKIP e FIELDS
SKIP 2 FIELDS
skips the next two data fields, and
SKIP 1 CARD
An equivalent statement
in which case the current Jata card and the following e - 1 cards are
bypassed. If the expression (e) in zero, no cards are skipped; if it
is negative, the program terminates with an error message. Example:
SKIP 3 CARDS
ejects the current data card and skips over the next two data cards.
as in the statements
LET X- 0
LET X - (Y + 1)/15
LET PRICE - QUANTITY * SALESPRICE
LET BALANCE - STOCK - PURCHASE
LET UNITCOST = TOTALCOST/NUMBEROFUNITS
LET E - I*R
LET X - Y*2
LET X - X + l
The ADO and SUSTTRoACT stateents are used to &Ad or su!.tract t-he
-10-
ADO 1 TO COUNTER
ADO IT7LCOST TO BILL
SUBTRACT 3*X + 6*Y FROM Z
SUBTRACT COST 9ROM CASH
'HERE' LET A = 0
GO TO HERE
GO TO THERE
'THERE' LiT A = 0
GO TO 'label' or GO TO label
'READ' READ X, Y, Z
ADD X + Y TO Z
PRINT 1 LINE CONTAINING Z AS FOLLOWS
X + Y + Z =
GO TO READ
The program returns to the statement labeled 'READ' after it has
finished printing, and continues to do so until all the data cards
are read, since an attempt to READ a card when there are no data auto-
matically terminates a program.1
t S
See ec.-10 proramtermnaton
o en-of-ile
-14-
IF statement is
as in
(b) To read a set of 200 numbers and sum all those numbers
greater than or equal to 5 in one group, and all the
numbers less than 5 in a second group.
-15-
Faalse
Fl
X<LO GO TO L
ADD X TO SUM
-16-
IF X IS LESS THAN A
IF Y IS LESS THAN B
LET Z - A + B
REGARDLESS
GO TO 'Al'
OTHERWISE
GO TO 'A2'
X<A
Star YesY<B es =A+B
or
PRINT i LINES WITH arithmetic expression Zist AS FOLLOWS
The i lines, called format lines, that follow the PRINT state-
ment can contain as many as 80 columns of textual infor-nation and
formats for arithmetic expressions whose values are to be printed.
There can be either text, or formats, or both in any format line.
The length of a format line is measured as the number of columns from
column 1 to the last nonblank column in the line.
Textual information appearing in format lines is printed exactly
as it appears; thus, the statement
prints two lines of output as they appear on the format cards. Any
character except an asterisk (*) or a parallel (I) can appear in a
format card as a textual message; blanks are "printed" as empty columns.
When PRINT statements are used to display the value of arithmetic
expressions, the expressions are listed in the PRINT statement, and
descriptive formats are provided for their values. The expressions
are first evaluated, and then printed in the display formats in left-
to-right order. The statement
evaluates the expressions X, Y, X/Y and N**2 and displays their values
according to the format rules shown in Table 1-2.
The variables PRICE and ITEMS appearing in the folloving PRINT
statements are assumed to have the values 100.899 and 27, respectively.
(a) PRINT 1 LINE WITH PRICE/ITEMS THUS
PRICE/ITEM -
is printed as
PRICE/ITEM - $3.737
is printed as
PRICE/ITEM - $3.74
is printed as
PRICE - $100.9
ITEMS - 27
PRICE/ITEM - 53.737
Table 1-2
FODEAT COWMfIOIP USED 1N P IDE STATDENOT
Ill'11.
Blank lines can be inserted between PRINT statements by the SKIP
statemnt, or blank format lines can be used. if e is any aritnmetic
expression, then the statement
The PRINT, SKIP. and START NEW PAGE statements can be used to-
gether to produce attractively labeled output reports.
As a final caution, note that whereas a PRINT statement can appear
on a card with previous stateme-'-, each of its following format lines
must appear on a separate card. This is illustrated in the following
program:
1-14
.•'.' • -, ..4, .; P - ;F.•
"1Y?4 -*. AV
these numbers. and determines their minimum and maximum. When all
tht numbers have been processed, N, their average value, and their
winimum and mai-'inun values, are printed.
Notice that since the range of the numbers is unk:no•, t'•e varn-
able PX is initialized tc a large negative namber and MIN tn s large
FpwLtive nuuber to ensurv that tSe largest and saallest data values
arc retsaind.
-22-
"THIS PROGRAM COMPUTES THE AVERAGE AND THE MINIIM AND MAXIMUM OF
"A SET OF NUMBERS ON PUNCHED CARDS
LET HAX- 99999.99999 LET MIN--PAX
READ N " THE NUMBER OF DATA OBSERVATIONS
'R' READ X A'DATA OBSERVATION
ADD X TO SLIM
IF X IS GREATER ThAN MAX. LET MAX-X REGARDLESS
IF X IS LESS THAN MIN, LET MIN-X REGARDLESS
ADD 1 TO COUNTER
IF COUNTER IS LESS THAN N, GO TO R ELSE
START NEW PAGE
PRINT 3 LINES WITH N.SLM/N,MAX.MIN AS FOLLOWS
THE AVERAGE VALUE OF ** NUMBERS IS ..
THE MAXIMUM VALUE IS ' "
THE MINIMUM VALUE IS . . -
STOP END
STOP END
I
7
scientific co •tattons. The follor.wi preXrau use* am "Irnfnite,
I
-24-
I i 1 111
3 5 7 9* *
The program starts by initializing the variables SIGN and DIVISOR
to their starting value of 1. The variable PI is automatically initia-
lized to 0 at the start of the program.
At the label TERM the value of the next term (1/DIVISOR) is com-
puted. At the label TEST, a test is made to determine if enough terms
have been computed to give sufficient accuracy, using the fact that
any term with value less than 0.00025 will add, or subtract, less than
0.001 to, or from, the sum of the series when it is multiplied by 4
to evaluate 7r.
If the term is greater than or equal to 0.00025, the sign of the
term, which alternates between +1 and -1, is computed and the value
of the term is added to the variable PI. The program then returns to
the label TERM to continue the summation of the series.
When the term is less than 0.00025, the program transfers to the
label FINISHED, where the expression PI*4 is printed.
GO TO 'READ'
END
t y1 a
-27-
Nx
N!i N N
iyi" ! x il Yl
a'I N 2 N
N ix x-
i-li i-i 1
N N
I Iyi aliii xi
ao
= N
where
N
ijxi represents the sum of all the xi
i-i
N 2
x represents the sum of all the x2
etc.
Chapter 2
PART.NUMBER LABEL
NUMBER.OF.PARTS SECTION.1
TOTAL .... I
SECTION ..... 1 12345
.PAGE 12.345
3.7.6 PART.4
. 6 ERROR
-29-
t The one exception is the word AND, which should not be used
as
a name.
±%fhese words are listed in the Appendix.
t
tParticular implementations of SIMSCRIPT II on different com-
puters will of necessity impose restrict~ons due to characteristics
of the computer hardware used in the implementation. Thus you might
be able to express some numbers (very large or very small) on some
computers, but not on others. These limitations are seen by a pro-
grammer in the magnitude and precision of the numbers he can express,
and in the results of his computations.
-30-f
Table 2-1
Data Variable
Punched as Defined as Action
_I__
A/B + C is REAL
A + B + C is INTEGER
A**B + C is REAL
I
data collection that has n reference indices, as a position in a list,
or a row and column location in a table, can be described by an
c
'-.:;.L-wznzi array.
1
-'4-
Row
Row 2
RIt• 3
F T(
11 UST( UST( 1) ST( J UST(di USrl1) LIST($ ULT (,I)
Column Number
1 2 3 4 ,
REAL valued. All elements of an array must have the same mode. If
their mode differs from that of the compiler's background conditions
it can be declared in a DEFINE statement in the same way as unwub-
scripted variables. For instance. if the assumed mode of all as vor
undeclared variables has been set to REAL, then we might write the
statement
The words VARIABLE. VARIABLES, ARRAY, and ARRAYS can be used irter-
changvably to improve the readability of declarations.
as in the ztatements
PREAMBLE
NORMALLY, MUDE IS INTEGER, DIMENSION = 2
DEFINE X, Y, Z AND Q AS REAL VARIABLES
DEFINE VECTOR AS A 1-DIMENSIONAL ARRAY
END
-37-
A variable must not, however, be used in more than one DEFINE state-
ment. It is permissible to write
It is
DEFINE X AS AN INTEGER,
is compiled as
RESERVE MATRIX(*,*) AS 5 BY 7
variables:
(1) To read a number from a data card, and add together those
subscripted variables in a list that are greater than the number.
-41-
PREAMBLE
DEFINE NUMBER AS A 1-DIMENSIONAL ARRAY
DEFINE INDEX AS AN INTEGER VARIABLE
END
RESERVE NUMBER(*) AS 500
f program statements assign values to
the elements of the array NUMBER
READ N LET INDEX=1
'LOOP' IF NUMBER(INDEX) IS GREATER THAN N, ADD NUMBER(INDEX) TO SUM
REGARDLESS ADD 1 TO INDEX
IF INDEX IS LESS THAN 500, GO TO LOOP ELSE
PRINT 1 LINE WITH SUM AS FOLLOWS
SUM = * **
STOP END
" NOTE THAT INDEX MUST BE INITIALIZED TO 1 JN THE PROGRAM
" SUM IS AUTOMATICALLY SET TO 0 AT THE START OF EXECUTION
" NUMBER AND N ARE BOTH REAL BY IMPLICATION
(2) To search through a list .f numbers for all those that lie
between a lover and an upper bound; to print such numbers.
PREAMBLE
NORMALLY, MODE IS INTEGER
DEFINE LIST AS A 1-DIMENSIONAL ARRAY
END
READ N ''NUMBER IN LIST'', X "-LOWER BOUND" AND Y ''UPPER BOUND
RESERVE LIST(*) AS N LET INDEX=1
: { somewhere in here program statements
assign values to each element of LIST
'LOOP' IF LIST(INDEX) IS GREATER THAN X, "'AND"
IF LIST(INDEX) IS LESS THAN Y,
PRINT 1 LINE WITH INDEX AND LIST(INDEX) LIKE THIS
NUMBER *** = *w*.*
OTHERWISE
REGARDLESS
IF INDEX IS LESS THAN N, ADD I TO INDEX GO TO LOOP
ELSE STOP E14D
II
-42-
PREAMBLE
DEF!NE MATRIX AS A 2-DIMENSIONAL ARRAY
DEFINE I, J AND N AS INTEGER VARIABLES
END
READ N ''THE DIMENSIONS OF THE ARRAY
RESERVE MATRIX AS N BY N READ ',IATRI,(t
'READ.LABEL' READ I,J ''THE SUBSCRIPT PAIR
PRINT 2 LINES WITH I,J,MATRIX(I,J) AND MATRIX(J,I) THUS
I=* J=* MATRIX(IJ) =
MATRIX(J,I) =
GO TO READ.LABEL END
Note that there is no test to terminate the program; it continues read-
ing cards and printing until there are no more data cards to be read.
(4) To illustrate the ,parentheses rule" as it Ppplies to the
evaluation of expressions containing subscripted variables.
PREAMBLE
NORMALLY, MODE IS INTEGER
DEFINE STOCK AS A 2-DIMENSIONAL ARRAY
DEFINE STORE AND ITEM AS 1-DIMENSIONAL ARRAYS
DEFINE PRICE, ITEM.INVENTORY AND STORE.INVENTORY AS
REAL, 1-DIMENSIONAL ARRAYS
END
'SUMMARY' LET I = 0
'LOOP' LET J = 0 ADD 1 TO I. IF I = 11, GO TO PRINI ELSE
'AGAIN' ADD 1 Tb J IF J = 101, GO TO LOOP ELSE
ADD STOCK(J,I; TO STORE() ''STORE SALES''
ADD STOCK(J,I) TO ITEM(J) ''ITEM SALES"
ADD STOCK(J,I)*PRICE(J) TO STORE. INVENTORY(1)
''SALES DOLLARS''
GO TO AGAIN
'PRINT' L`T J = 0
'NEXT' ADD 1 TO J. IF J = 101, GO TO OUTPUT ELSE
LET ITEM.INVENTORY(J) = ITEM(J)*PRICE(J)
" ITEM DOLL ARS''
GO TO NEXT
'OUTPUT' START NEW PAGE
PRINT 1 LINE AS FOLLOWS
SUMMARY REPORT AT END OF CURRENT PERIOD
SKIP 2 OUTPUT LINES
LIST STORE, STORE.INVENTORY, I1M, ITEM.INVENTORY
AND STOCK
STOP
END ''OF PROGRAM
LET N - LOW
'LOOP' ADD INCKEMENT*N TO SUM
ADD INCREMENT TO N IF N<HIGH, GO TO LOOP ELSE...
Poesible Subscript _
Control Phrases Successive Values of v
FOR I - I TO 5. 1-2.3.4.5
FOR ! - -5 TO 5, -5,-4,-3,-2.-l,0.l,2,3,4,5,
FOR I - 0.0 TO 2.0 BY 0.5 0.0,0.5,1.0.1.5,2.0
! a 0 TO N BYM,
FOR I if Nis less than 10 the cn-
trolled statement will not be
executed
if N is at least equal to 10,
the controlled statement will
be executed with 1-10, 10+M,
l0+2*1, ... , lo+n*M until I
exceeds N
Used this way, the control phrase on the left in said to be an outer
phrase, and the phrase on the right an inner phrase. In cvaputing
successive values of I and J, the inner phrase is stepped Th•rough its
entire range of values for each value of the outer conz.rol phrase
variable. The controlled stateent is executeJ each time . Thus, It
N - 3 and M - 4. the above stactý=nt vould be executed in the sequence
-47-
3 Z LET i(3,'} -
3 3 LET ix3,3) 0
rablo contaitns & list of the 51teCIIrt '4 sitest nts sc:'
thus far that are ::rtra7.asl. sn'V otc':o. Ciban~tr,:
ph ras s.
-43-
Table 2-2
SUBSCRIPT STATEMENTS
Controllable Uncontrollable
Statement Types Statement Types
LET IF
ADD GO TO
SUBTRACT STOP
READ NORFALLY
PRINT DEFINE
START NEW PREAMBLE
SKIP END
RESERVEa
For example:
(a) FOR I = 1 TO MAX, READ X(I)
reads the successive values X(1), X(2), ... , X(MAX)
(b) FOR X = 1 TO N, ADD X**2 TO SiM
N 2
computes I X N*X**2
X=1
(c) FOR I = 1 TO N, ADD X(I)**2 TO SUM
N
computes i I
I=1
(d) PRINT 1 LINE AS FOLLOWS
INDEX VALUE
FOR IN•DEX = 5 TO 10, PRINT 1 LINE WITH INDEX AND
VALUE(INDEX)
**
LIKE THIS
** **
reads a data item and assigns its value to X; reads another data item
and assigns its value to LIST(7); read& as many data items as there
are elements in the array VECTOR ind assigns them to the elements of
VECTOR; reads as many data items as there aro in the array TABLE and
assigns them to the elements of TABLE; reads a data item and assigns
it to Y; and reads a data item and assigns it to thi element of LIST
indexed by the subscript Y.
A subscript control phase can also be used to control the selec-
tion of array elements in a READ statement. The statement
r-ads N data items and assigns their successive values to the elements
LIST(L), ... , LIST(N).
Some examples illustrate a few of the many forms a READ statement
can take. X, Y, and Z are subscripted variables defined by the state-
ment
The above examples show that a control phrase does not control
the index of a variable within a READ statement, but controls the
entiz-e READ statement. Thus, each variable that appears in a con-
trolled READ statement should contain the control variable as a sub-
script; if it does not, successive data values are assigned to this
variable as the control phrase iterates over the range of the control
phrase variable. This is seen in the statement below, which reads
and assigns six successive values to the unsubscripted variable A and
the subscripted variables X(I). Naturally, all but the last value of
A is lost,
PREAMBLE
NORMALLY, MODE IS INTEGER DEFINE X AND TEST.NUMBER AS REAL VARIABLES
DEFINE CODE AS A 1-DIMENSIONAL ARRAY
END
READ NUMBER.OF.SAMPLES AND TEST.NUMBER
RESERVE CODE AS NUMBER.OF.SAMPLES
FOR I = 1 TO NUMBEROF.SAMPLES,
DO
READ
X
IF X IS LESS THAN TEST.NUMBER, LET CODE(I) - 1
TO SUM
LOOP REGARDLESS ADD CODE(1)
PRINT I LINE WITH 100*(SUM/NUMBER.OF.SAMPLES) THUS
PER CENT ITEMS LESS THAN TEST NUMBER = **.**
STOP END
In the foregoing example the statements READ, IF, LET, REGARDLESS,
and ADD appear between the statements DO and LOOP. The logic of
-52-
organization of the FOR phrase mechanism and does not expect more
from the compiler than it is able to do. Each FOR phrase is compi'ed
into a series of program steps that work, roughly, as follows (the
word rozughly is used since variations of the FOR statement require
different treatments, e.3., the direction of the inequality will
change in the IF test when a BACK FROM phrase is used):
The program
FOR V=e 1 TO e 2 BY e
3
DO
Statement group
LOOP
LET V=e,
GO TO L.2
'L.1' ADD e t0 V
'L.2' IF V ý e 2 ', GO TO L.3
OTHERWISE
Statement group
GO TO L.1
'L.3: continue with program
L.1, L.2, and L.3 are local labels that the compiler constructs; they
cannot be used by a SIMSCRIPT II programmer.
DO loops can be nested within one another for control over sub-
scripted variables with two or more subscripts. Recall that subscript
indexing takes place within the bounds of the DO and LOOP or REPEAT
statements. To print a matrix of numbers, we might write:
FOR I = 1 TO N, DO
FOR J = 1 TO M, DO
PRINT 1 LINE WITH I, J, MATRIX(I,J) AS FOLLOWS
MATRIX(*,*) = *.***
LOOP "ON J, THE SECOND SUBSCRIPTt
REPEAT ''ON I, THE FIRSr SUBSCRIPT
tThe careful reader will note that this statement is not required,
as the preceding FOR only controls one statement. In fact, neither
the preceding DO nor the following REPEAT is required.
-4.' ~ -
-54-
FOR I - 1 TO N, DO
FOR J - I TO M, DO
PRINT 1 LINE WITH I, J, MATRIX(I,J) AS FOLLOWS
MATRIX(*,*) .
LOOP ''J''
REPEAT 'I''
MATRIX(1,1) - -----
MATRIX(1,2 - ....
MATRIX(1,3 - ....
MATRIX(2,1 ------
MATRIX (2.2 - ....
MATRIX (2,31 =
has been declared. The base pointer, whose value is a computer loca-
tion, is always in INTEGER mode. A one-dimensu"onal array X, allocated
storage by the statement
RESERVE X(*) AS 10
is stored as:
ELEMENTS
X(1)
X(2)
X(3)
BASE POINTER X(4)
X(5)
X(*)
X(6)
X( 6)
X(9)
X(lO)
RESERVE X('*') AS 5 BY 3
is stored as:
-56-
ELEMENTS
X(1' 1)
ROW POINTERSX(12)
'((1 .3)
X(1P ,)
( 1X(3,)
XX(5..
X('5 1)
X(5, 31
RESERVE X(*.,') AS 5 BY 3 BY 2
is stored as:
-57-
X(l, 2. 1, 2,_I)j
X(l, 3,
LX( 3, 2)
X(2, 1, 1)
X(2, 1, X(2.1,2)
1
11
r X(2, 2, Y)l
X(2, 2,
ROW PO',NTER
NTER X(2, 3, 1)
X(2.
X(l. . . X(2. 3. X(2, 3, 2)
X(3, 1. tj X(3,1,2)
BASE PO!NTER
X(4, 1. X(4, 1. 1)
X(5- 0. 0)
E4., 1.2)
XG 2)
f I X(4, 27,71)
X(4.2,
X(4. 3,
x(s, 1,
4 ý1,
EX(5, 2)l
X(5. 2.
wl
X(5, 3, 1)
5 3. ý2)
kXk
-58-
RESERVE TABLE(*,*) AS 5 BY *
ROW POINTERS
STABLE('. ")TABLE(3.)
The base pointer points to the array of row pointers; the row pointers
do not point to anything since arrays have not yet been assigned to them.
(b) Set up a loop to assign data arrays to each of the row
pointers. Since a dimension must be given for each row, read a value
FOR I=1 TO 5,
DO READ ")
RELERVE TABLE(I,*) 'PS D
L3OP
DATA ELEMENTS
TABLE(1, 1)
TABLE(], 2)
TABLE(1, 3)
ROW POINTERS
I. ABLE(3, 2)
BASE POiNTER
'IABLE(3,4)
3)
TABLE(- s) lop; TABLE(3,*) [3 TABLE(.1,
TABLE(3.4)
1
TIBLE(3 5)
TABLE (4, TABLE(3,6)
TABUi:(4, 1)
TABLE (5 ")•w,•{ rABLE(5. 1)
I'ABLECS.2
-60-
The ragged table TABLE(I,J) can be used the same as any rectangular
array, The only care a programmer must exercise is to ensure that
he does not ask for a nonexistent array element, as, for example,
TABLE(4,3) in the above illustration.
(2)
Section 2-03 indicates that once an array has been reserved
it cannot be reserved again. To prevent this from happening, the
SIMSCRIPT II system ignorps instructions to reserve an array when the
pointer to the array has a value in it. When a program is first ini-
tialized, all array pointeýz. are zero, makS-g the first RESERVE pos-
sible. After this, the presence of a nonzero value in a pointer
variable dictates whether or not a reserve w-l' ?e exdcuted.
At timas ft is useful to be able to perform multiple ai•ray zeser-
vations, kev.ping track of array pointers as they are _eplaced, This
can be done by stcring a pointer, setting -.L to zero, an: executing
a new RESERVE statement. Althou:'b the pointer variable will point
to the latest array that is rese.-vfd, it is possihie a.: any tiue to
restore it to a previous ,alue (which sti. )_ ptnts t; an array of
values in memory) and use those previously computed values. The
example below illus.ratfG how such a mechanism ca- be employed:
A pLogram is to De developed that aiores gcaea!ogical informa-
tion in the form of a family tree. Sidc a tree hdq an individual at
its apex, his parents at the next level, his parents' parents below
that, and so on. Figurc 2.5 Llluatratee a family tree containing
INDIVIDUAL ................... .. .. . .
PARENT ................. - r2 3
GRANDPAI~NTs.. 4 5 7
GPEAT- lF,
GRANDPARENTS 8 9 lu 12 F, 1
2 3
4 5 6 7
8 9 10 11 12 13 14 15
2 3
4 5 6 7
8 912 1 13 14 151
Assume that we are given the number of levels in the tree and the names
(co 4 ed as integer numbers) of the family members arranged in proper
order on punched cards. We first construct a tree with the family
data suitably arranged. The following program does this:
LEVEL TREE
IZIZ
3 -1,15 17 ,7F
4 8 1 9 10 111 12 13 14 is
READ K
LET TREE(*)-LEVEL(K)
LIST TREEt
To pick out specific ancest)rs, one can search through the tree until
the correct code is found using the following program:
1This
statemnt displays an entire array; set Sec. 2-11.
-63-
READ CODE
FOR I-I TO N,
DO LET
TREE(*)=LEVEL(I)
FOR J-1 TO 2**(I-l).
DO
IF TREE(J) EQUALS CODE, GO TO PRINT
OTHERWISE
LOOP
LOOP
PRINT 1 LINE WITH CODE AS FOLLO'S
UNABLE TO FIND AN ANCESTOR WITH THE CODE **
STOP
'PRINT' PRINT 1 LINE WITH CODE, J AND I AS FOLLOWS
ANCESTOR ** FOUND IN POSITION * OF LEVEL *
STOP
END
RESERVE TABLE(*,*) AS 10 BY 10
(c) Read INTEGER values into the fourth row of the array
by using the statements
LET WHOLE(*)-TABLE(4.*)
READ WHOLE
"The first statement sets the base pointer of the one-dimensional array
WHOLE equal to the row pointer of the fourth row of TABLE. This has
the effect of assigning the 10 data element values of thp fourth row
of TABLE to WHOLE -- both TABLE(4,*) ard WHOLE(*) point to the 9~
memori locations. The second staLement reads 10 data values into
the array WHOLE, vhich is also a row of TABLE. They are read as
-64-
integers, since WHOLE has been declared an INTEGER array. The READ
statement knows ho.. :y elements to read, since every pointer word -
LET DECIMAL(*)=TABLE(7,*)
READ DECIMAL
or the statement
FOR I=1 TO 10, READ TABLE(7,I)
Both statements can be used, since TABLE has been defined as a REAL
array.
(4) The pointer mechanism can be used to make the processing of
a three-dimensional array more efficient by eliminating the necessity
of recomputing two subscripts each time an element is accessed in a
FOR loop. The program segment described in (a) can be made more
efficient by rewriting it as shown in (b).
The revised statement eliminates the need for recomputing the sub-
scripts of CUBE -:t are not affected by the FOR loop every time a
new element is accessed. Little additional memory space is taken,
for the array DUMMY never has more words allocated than are needed
for its base pointer.
The use of pointer words thus greatly enhances a programmer's
ability to construct and use data structures, and its applications
are manifold; for inrtance, rows of mat,-ices can be interchanged by
simply changing pointer values, and large -natrices with many identi-
cal rows can be compressed by having several pointers point to the
same array.
The most genersl form of the RESERVE statement illhusrating the
-65-
Two features are provided that make the uce of pointers easier.
The first concerns the physical act of writing programs and the second,
the task of operating with arrays of unknown size.
(1) A base pointer can be written as X(*) regardless of the num-
ber of its dimensions. For instance, if X is defined as three-dimen-
sional, X(*) is interpreted as X(*,*,*). While this makes the use of
pointers convenient, one should be aware that, to a person unfamiliar
with the structure of a program's data, it obscures the actual opera-
tions that are taking place, e.g., example (5) above.
(2) The function DIM.F, when given a pointer as an argument,
returus as its value the number of words pointed to. This is extremely
useful !n programs that compute the values of array dimensions, as it
"sakes it unnecessary to save such values for later use. For example,
the folloving FOR loop uses the DIM.F function to determine its bounds:
t-..- - -.. - .
III
-67-
IIi
direct transfer of program control to a particular statement, or to
select, according to the truth or falsity of a logical axrression,
either of tvo alternaLo program branches.
Theme statements a:e frequently inadequate, however. For example,
there may be more than two alternative program paths to choose from,
or a program may have to be written to accommodate transfers to state-
ments that have not yet been written. Two new GO TO statements cir-
cumvent these problems.
If ve let LABELI, LABEL2, LABEL3, ... , LABELN represent statement
labels, and e represent an arithmetic expression, then a statement of
the form
In this last example note that the mame label name can appear in
more than one position in a label olit, and that label names can be
written without alphabetic characters.
When two distinct label names are used to identify the san
program statement, they are called equivalent labels. In the follo*-
ing examples the labels ADD and PLUS are used as distinct labels in
(I), and as equivalent labels in (2):
GO TO READ
READ I GO TO A(I)
rather than list all the possible label names in an ordinary computed
GO TO statement. The subscripted label GO TO statement form can be
used whenever this seems desirable. It is particularly useful in
programe containing GO TO statements that direct control to various
parts of a program when the program is frequently updated or augmerted.
Subscripted labels allow labels to be added or deleted witnout changing
scripted labels:
-70-
STOP END
t
Called "debugging" in the programming vernacular.
INTEGER variables
N-5 MA--245 MOTORCAR-O KEY=1S6733578
NUMER.OF.JOBS. IN.QUEUE-45
REAL variables
TIM-345.87 LONGITUDE-37.37 PRICE-lO0.O0
TEMP.FAHRENHEIT-267.66 RATE-545.6667
RATIO-O.0
+
In this statement corrections are not made for missing stubscripts
(see Sec. 3-2'); X is treated as an array name and not as an improperly
specified element X(1).
-73-
Program statement
LIST N/MAN,MOTORCARTIMELONGITUDE,NLNBER.OF.JOBS.IN.QUEUE,
TEM. FAHRENHEIT,PRICE+RATE,KEY,RATIO
Program output
N/MAN MOTORCAR TII. LONGITUDE
0.024081 0 345.870000 37.370000
NUMBER.OF.JOBS TEMP.FAHRENHEI PRICE+RA'E KEY
45 267.660000 -445.666700 156733578
RATIO
0.000000
These values, of course, are printed out differently on a printer with
a wider width of paper.
Singly-aubscripted variab•e• are printed in colums following the
same heading and spacing conventions as expressions. The length of
each column is determined by the number of elements in the array, the
longest array determining the maximum number of rows printed. Vari-
ables with fewer elements than the maximum show blanks in the positions
where no elements appear. For example, if a RESERVE statement reads
the following columns are printed (note that the left-hand margin is
numbered to identify the element values):
first column of element values; the spacing conventions are the same.
If more than one array is mentioned in a LIST statement, they are
printed successively in the order in which they are listed. For
example, if TABLE is an array defined by the statement
RESERVE TABLE AS 5 BY 4
TABLE
1 2 3 4
1 0 556 90 78
2 24 88 8 5555
3 5 0 777 89
4 337 7 0 98
5 0 55 54 0
or as follows if it is REAL:
TABLE
1 2 3 4
1 0.000CO0 556.000000 90.000000 78.000000
2 24.000000 88.000000 8.000000 5555.000000
3 5.000000 0.000000 777.000000 89.000000
4 337.000000 1.000000 0.000000 98.000000
5 0.000000 55.000000 54.000000 0.000000
Arrays with more columns than a page can contain are continued
on successive pAges. For example, if TABLE had been reserved as
5 BY 7, an additional page would be printed as follows:
TABLE
5 6 7
1 12 28 1000
2 301 -100 27
3 0 0 0
4 16 0 -16
5 -3 3 4
X MAN AVERAGE
23.111100 1.370000E+10 9,252525
number between zero and ten scaled by a power of ten; 10.6 is printed
"a 1.06(10#'+1). 0.00123 as 1.23(10"-3). 546372.3 as 5.4637?3(10O.5),
etc. The power of ten, e.g., +1. -3, +5, indicates the direction and
distance in which the decimal point must be moved to convert the
fraction to the true number.
-76-
expression is
The words POSITIVE, NEGATIVE, and ZERO are recognized in their correct
context as property names when they follow the word IS or words IS NOT
in a logical expression. Therefore, they can be used without reserva-
tion as variable names or labels. In fact, if POSITIVE is declared
as a variable, the SIMSCRIPT II compiler has no difficulty with the
statement
Name Value
PREAMBLE
DEFINE COUNT AS AN INTEGER, I-DIMENSIONAL ARRAY
END
RESERVE COUNT(*) AS 10
FOR I -01 TO N. DO THE FOLLOWING
ADO I COUNT(EFIELD.F-SFIELD.F+I) SKIP 1 FIELD " TO THE
" NEXT NLMBER
REPEAT
cards and add together all the integers (n,. whole numbers, hut num-
bere without deciral points).
'READ' READ X
When there are no data, e.g., all data have been read and look-
ahead is impossible, tha system variables have these values:
Nane value
SFIELD.F 0
EFIELD.F 0
MODE ALPHA
CARD NEW
DATA ENDED
Table 2-3
SYSTEM-DEFINED CONSTANTS
Standard
Name Symbol VWlue Units Mode
MAIN PROGRAM
o
0
0
o0 = 1
o I.
toL iGR11
0
MAIN PROGRAM
SUBPROGRAM 1
0
O
SUBPROGRAM 2
o0
O _______ SUBPROGRAM 1
END
MAIN PROGRAM
0
SUBPROGRAM I1UBPROGRAM,
0
0-
0 SUPRORAMSUBPROGRAMTI
0 _____ UBRGA 2
.3__
0
END
MAIN
although this is not always necessary. Since all other sections of
a program deck must have a heading, It is possible to make MAIN
optional and assume a program is a main program if it is not other-
wise labeled. Nevertheiess, it ic good programming practice to label
programs fully. From now on, we shall do so.
A subprogrcm definition statement precedes each subprogram and
(1) declares that the statements following are part of a subprogram;
-83-
ROUTINE rxne
The optional words TO and FOR are allowed after the word ROUTINE to
make statements more grammatical. Thus, a program that extracts
square roots might be called SQUARE.ROOT and could be defined by the
statement
ROUTINE SQUARE.ROOT
ROUTINE TO TAKE.SQUARE.ROOT
As the words TO and FOR are optional, care must be exerzised to avoid
using the short form of the statement when defining a subprogram
named FOR or TO. If this is done, the compiler will continue to look
for a subprogram name after it sees the words TO or FOR, and mistakenly
use the next word it sees. For example, if a subprogram named FOR
is defined by the statements
ROUTINE FOR
LET X = 1
END
I-
-84-
A local variable, on the other hand, has its value defined only
within a particular routine. The same name can be used for a local
variable in many routines; when it is so used it refers to a different
quantity in each routine, as if a different variable name were being
used in each place. Local vs lables can be used mnemonicaliy in dif-
ferent routines without the various applications interfering with one
another. When a name is defined within a routine, it is unique to
that routine and does not conflict with other uses of the same name.
Thus, it Is possible to have many different elements with the same
t
" See p. 90.
-85-
?REAMBLE
NORMALLY, MODE IS INTEGER, DIMENSION=2
DEFINE GHOST AND SPECTER AS REAL ARRAYS • Program Preamble
DEFINE VALUE AS A REAL, I-DIMENSIONAL ARRAY )
NORMALLY, DIMENSION= 0
END
MAIN
This section is the main routine. It can contain
references to both global and local variables.
END
ROUTINE RTNI
IThis section contains statements that use the
variables X and Y.
END
ROUTINE RTN2
This section contains statements that use the
variables X and Y_
END
PREAMBLE
NORMALLY, MODE IS INTEGER
DEFINE VI AND V2 AS REAL, 1-DIMENSIONAL ARRAYS Program
DEFINE V3, V4 AND V5 AS 2-DIMENSIONAL ARRAYS Preamble
NORMALLY. MODE- REAL
END
ROUTINE TO PROCESS.DATA
NORMALLY, DIMENSION- 1, MODE IS REAL
DEFINE Z AS AN INTEGER ARRAY
DEFINE L. M AND N AS INTEGER VARIABLES
RESERVE Z AS 10
'START'
GO TO START
and other statements that make up a routine
Expreasion: SQRT.F((X(I+1)**2+Y(J)**2)+(5.5*Z(2*I+J)-I)).
Evaluation: (1) Application of the parentheses and overator pre-
cedence rules evaluate, in turn, the sub-expressions:
(a) 1+1 - a (b) J - d (c) b**2 - c
X(a) - b Y(d) - • e**2 - f
c+f - g
(d) 2*1 - h (e) g+- - n (f) SQRT,.F(n) * p
h4+J - i
Z(i) jj
5.5*j - k
k-l m
Table 2-4
_ I I_ I
tDenotes a function compiled in-line rather than called esa routine.
and REAL
-92-
Statement 11 Action
ROUTINE ALLOCATE
ROUTINE TO ADD(X AND Yi
ROUTINE FOR ADDING GIVEN X ANU Y
ROUTINE LOG(X,Y)
ROUTINE FOR ALLOCATING THIS MAN
name (ar-z-tnet~c e
where the words AN INTEGER or A REAL are optional and can be substi-
tuted for the mode when appropriate. More than one function can be
declared in a single DEFINE statement, as, for example, in the statement
are returned in the same mode, of course. The program shown below
illustrates the use of arguments and the ROUTINE and RETURN state-
meats. The routine computes the 2n-th root of an input value, where
n can take on the values 1, 2, or 3.
In the program preamble:
END
and
(a) If fewer arguments are listed than are correct, the missing
arguments are assumed to be zero and a warning message issued. Thus,
a routine that has been defined as
PREAMBLE
DEFINE SUM AS A REAL FUNCTION WITH 1 ARGUMENT
END
ROUTINE TO SUM(N)
DEFINE N AS AN INTEGER VARIABLE
FOR I = 1 TO N, ADD 1/I TO X
RETURN(X)
END
LET ANSWER=COUNT+TOTAL+SUM
LET ANSWER=COUNT+TOTAL+SUM(O)
LET ANSWER=COUNT+TOTAL+SUM(N,M)
LET ANSWER=COUNT+TOTAL+SUM(N)
The routine has two arguments: the number of terms in the series
that are to be summed, and the value to be substituted for x.
In the program preamble:
Routine definition:
10
.. L+L
+' I +0.999
.2 2 7 3+ 10
i- 2 72 2 2 2
I 40
i-1 sin(O)i
Routine definition:
tSince VALUE has REAL arguments. 2.0 and 10.0 rather than 2 and
10 must be used.
-99-
ROUTINE TO EVALUATE(N,Q,R)
DEFINE XYLNQR AS REAL VARIABLES
LET X-N**2*Q**2 LET Y-X+Q LET ZuX+R
RETURN WITH VALUE(N,YtZ+SQRT.F(N**2))
END
If argument lists are used, they are written after the routine name.
Various forms of argument list structures can be used. The statements
below are equivalent:
the same rules that apply to functions are observed. Missing argu-
ments in input lists having les than the "standard" number of argu-
ments are assumed to be zero and additional arguments are ignored.
Additional arguments in output lists are ignored, and missing argu-
muets, because they are needed to receive output variables, are created
by the compiler. The values transmitted to them are not accessible
to the calling program. Warning messages are issued.
If a routine Is defined vwth only GIVING arguments, it is assumd
to have no YIELDING values; if it is defined vith only YIELDING values,
it is assumed to have no GIVING argumecns.
Routine definition:
Routine used:
Notice the added input araumwnt that determines how the routine is
used so that a proper return is affected. A code mway be provided
sithe: this way or as a global variable.
In the above routine X and Y are local arrays. When the routine
is called, pointer value arv given to them. If the ro'utine is called
as VECTOR.PRODUCT(COST(*),L#MIT(*)), the statement FOR I - 1 TO
DIM.F(X'*)), ADO X(I)*Y() TO SLIM is intorpreted as FOR I - I TO
DIM.F(COST(*)), ADv COST(I)'UNIT(I) TO SUM.
-104-
If a program has the arrays LIST and VECTOR defined and the
folloving values:
LIST(1) a 2 VECTOR(1) a 4
LISTh2) • 3 VECTOR (2) - 6
LIST(3) - 7 VECTOR(3) - 0
LISTi'4) a - VECTOi,(4) aI1
LIST(5) • 0 VECTOR(5) -5
Routine definition:
-105-
ROUTINE TRACE(N.MATRIX)
DEFINE SUM AS A REAL VARIABLE
DEFINE MATRIX AS A REAL, 2-DINENSIONAL ARRAY DEFINE I AND N AS
INTEGER VARIABLES
FOR I - 1 TO N, ADO MATRIX(TI) TO SUM
RETURN WITH 3U1 END
Routine definition:
Routine definition:
ROUTINE QUANTITY GIVEN N AND MATRIX
DEFINE MATRIX AND TEMP AS REAL, 2-DIMENSIONAL ARRAYS
DEcINE N AS AN INTEGER VARIABLE
RESERVE TEMP(*,*) AS N BY N
FOR I - 1 TO N, FOR J 1 TO N,
LET TEMP(I,J)uMATRIX(I,J)**2
RETURN WITH TPACE(NTEMP(*,*)) END
The local variables I, J, and TEMP are "created" when the routine
is :alled, as wheat a callipg program contains the statement
Routine definition:
__.
-108-
PREAMBLE
NORMALLY, MODE IS INTEGER
DEFINE COSTS AS A 2-DIMENSIONAL ARRAY
DEFINE MODE.FACTORS AND CLASS.FACTORS AS I-DIMENSIONAL ARRAYS
DEFINE CAPACITY AS A 4-DIMENSIONAL ARRAY
DEFINE FROM, TO,MODE AND CLASS AS ''GLOBAL'' VARIABLES
END
MAIN
READ NFROM, NTO, NMODE,NCLASS ''READ MAXIMUM DIMENSIONS
RESERVE COSTS(*,*) AS NFROM BY NTO, MODE.FACTORS(*) AS NMODE,
CLASS.FACTORS(*) AS NCLASS,CAPACITY(*,*,*,*) AS NFROM
BY NTO BY NCLASS BY NMODE
READ COSTS, CLASS.FACTORSMODE.FACTORS ''READ INITIAL DATA
'REQUEST' REAO FROMTOMODE,CLASS
'INQUIRE' CALL RESERVATION YIELDING ANSWER
IF ANSWER EQUALS 1
NOW FIND.COST YIELDING PRICE
PRINT 1 LINE WITH MODE,CLASSFROM,TO,PRICE THUS
MODE * CLASS * RESERVATION FROM ** TO ** IS AVAILABLE FOR *** DOLLARS
GO TO ''NEXT CUSTOMER" REQUEST
OTHERWISE ''FIND OTHER SPACE
SUBTRACT 1 FROM CLASS
IF CLASS IS GREATER THAN 0 GO TO INQUIRE
OTHERWISE LET CLASS=NCLASS
SUBTRACT 1 FROM MODF
IF MODE IS GREATER THAN 0 GO TO INQUIRE
OTHERWISE PRINT 1 LINE WITH FROM AND TO LIKE THIS
THERE IS NO TRANSPORTATION AVAILABLE FROM ** TO ** TODAY
GO TO REQUEST
END ''OF MAIN ROUTINE''
are vacated.
The points to note in this program are:
A
-110-
been given the same name as a local variable in the main routine to
show that this can be done without conflict. A corresponding variable
in the routine FIND.COST has been given a different name to show that
the actual name is of no importance; only its location in the argument
list is important. It also illustrates that the value computed as
SUM in the routine FIND.COST is stored in the local variable PRICE in
the main routine when FIND.COST returns to that program.
(g) FIND.COST can also be defined as a function. This is done
by modifying the routine to:
ROUTINE TO FIND.COST
RETURN WITH COSTS( FROMTO)*CLASS. FACTORS(CLASS)*MODE. FACTORS(MODE)
END
and using the routine name in place of the variable PRICE in the PRINT
statement:
RESERVE TABLE(*,*) AS 10 BY 50
RELEASE TABLE(*.*)
ROUTINE VALUE(X)
LET A=SQRT.F(X)
RETURN WITH 4*A+A**3
END
statement and the ones shown below look alike on the surface but pro-
duce different results in the context of the program.
In the main program:
Use of the local variable V also makes the program more efficient,
as it eliminates the evaluation of FN(K) before each iteration of the
loop.
LI
-114-
FACTORIAL(4)-4*FACTORIAL(3)
-4* (3*FACTORIAL(2))
P*3* 2*FACTORIAL(l)))
-4"(3"(2*(1)))
-24
RECURSIVE local variable has an initial vr]ue of zero each time the
routive in which it appears is called. Recursive variables are often
used for this property alone. A SAVED local variable retains the
value left in 1'.s storage location when the routine was last used.
Thus, routines can use SAVED variables to pass messages from call to
call concerning their operations. The first time a routine is called,
all its local variables, both SAVED and RECURSIVE, are zero.
Recursion can best be understood by shoving an example. The
program below uses Horner's method for evaluation of polynomials.
This method has the computational advantage of requiring only 2(K-1)
arithmetic operations to evaluate a polynomial, fewer than are re-
quired by straightforward evaluation, and it expresses a polynomial
of form A(K)=A(K-I)*X+...+A(1)*X**(K-1) as the recursive form
A(K)+X*(A(K-1)+...+A(1)*X.*(K-2)). The following brief SIMSCRIFT II
routine demonstrates a program for evaluating this form:
In the program preamble:
Routine detinition:
END
TREE
-NOD
e(1) NODE
E (c)t
ROUTINE DESTROY(NODE)
NORMALLY MODE IS INTEGER
DEFINE NODE AS A 1-DIM ARRAY
IF NODE(*) IS NOT ZERO,
FOR 1=1 TO 2 CALL DESTROY(NODE(I))
RELEASE NODE(*)
REGARDLESS
RETURN END
This ro.uLne, when called by a statement such as NOW DESTROY(TREE),
calls upon itself as each node destroys the nodes below it. Since
each node either points to a successor node or is zero, the routine
can tell whether it has to follow a downward path to destroy successor
aodes, or whether it can destroy the ncde it is working on by releas-
ing it. Perhaps the e~siest way to understand this routine is to
construct a typical tree, such as that shown in Fig. 2-9, and follow
the logic through.
F 2-9 Ab tree
ROUTINE TO OESTROY(NODE)
NORMALLY MODE IS INTEGER
DEFINE NODE AS A 1-DIMENSIONAL ARRAY
IF NODE(*) IS NOT ZERO,
FOR I1-TO DIM.F(NODE(*)), CALL DESTROY(NODE(I))
RELEASE NODE(*)
REGARDLESS
RETURN END
The DIM.F function allows each node to have several branches, rather
than only two. Such a tree might look like Fig. 2-10.
Fig 210 A 0
DEFINE X TO MEAN Z
SUPPRESS SUBSTITUTION
DEFINE X TO MEAN X
RESUME SUBSTITUTION
PROCEDURE TO FIND.MAX(X)
DEFINE X AS A 1-DIMENSIONAL INTEGER ARRAY
SET MAX=X(1) ADD 1 TO SET
FOR I - 2 TO DIM.F(X(*)), SET MAX-MAX.F(MAX,X(I))
RETURN WITH MAY
FINISH
when submitted for compilation preceded by the three DEFINE TO MEAN
statements will be compiled as
ROUTINE TO FIND.MAX(X)
DEFINE X AS A I-DIMENSIONAL INTEGER ARRAY
LET MAX-X(1) ADD 1 TO LET
FOR I - 2 TO DIM.F(X(*)), LET MAX-MAX.F(MAXX(I))
RETURN WITH MAX
END
Notice the use of the word LET as both a variable and a key word.
(c) Use of the statement to define macro-instructions. A macro-
instruction is a compound instruction that N generated from one key
word. The statement
-123-
ROUTINE EXAMPLE(X)
LOCAL
DEFINE X AS A REAL VARIABLE
END
ROUTINE EXAMPLE(X)
DEFINE I,J,K,L AND M AS INTEGER VARIABLES
DEFINE X AS A REAL VARIABLE
END
In the first statement, the contents of the line following the state-
ment is substituted for the key word wherever it appears; in the
second statement, the contents of the following I lines are substi-
tuted. As with the DEFINE TO MEAN statement, totally blank cards and
comments cannot be substituted.
DEFINE TO MEAN and SUBSTITUTE statements can be used freely in
a program with few restri-tions. They can "call on" one another at
different levels of substitution. The following statements show how
a series of DEFINE TO MEAN and SUBSTITUTE statements can be applied
to a program statement and used to translate the words of the state-
ment into legal SIMSCRIPT II code:
-124-
the READ statement with a subscripted variable, and the use of FOR
loops to control the indexing of subscripted variables: A
PREAMBLE DEFINE LIST AS A 1-DIMENSIONAL ARRAY
DEFINE I,J,M AND N AS INTEGER VARIABLES
END
MAIN READ N
RESERVE LIST(*) AS N READ LIST
READ TOLERANCE. VALUE
FOR M-1 TO N-i
FOR 1-1 TO N-M
DO
LET SUM-O
FOR J-O TO M, ADD LIST(I+J) TO SUM
LET AVERAGE=SUM/(M+l)
IF AVERAGE IS LESS THAN TOLERANCE.VALUE
PRINT I LINE WITH I, I+M AND AVERAGE AS FOLLOWS
ITEMS *** THROUGH *** HAVE AN AVERAGE OF *****
REGARDLESS
LOOP
STOP END
M
c(I.X) - (1.J),3(J.K)
MAIN
DEFINE I,J,K,MN,R AND S AS INTEGER VARIABLES
READ N, M, R AND S IF M IS NOT EQUAL TO R, PRINT I LINE THUS
MATRIX DIMENSIONS ARE NOT EQUAL, MULTIPLICAI TO.N IMPOSSIBLE
STOP ELSE RESERVE A(*,*) AS N BY M,B(',) AS R BY SC(*.*) AS N BY S
READ A FOR J-1 TO S, rOR 1.1 TO R, READ B(I,J)
FOR II TO N. FOR K-1 TO S, FOR J-l TO M
ADD A(IoJ)*B(J,K) TO C(IK)
LIST A, B AND C
STOP END
For values d-62.4, L-10, and x- 4 the routine is used to compute and
print the quantities
Qi - H- (M-I)2
12
0 if M<m
Q2 - 1 if M , m
2 if M> m
2 2 2 2
Q3 iT (1-q) 2 A3 (l-a)(3.080
2an .- 0.7100 sin 2a
A6(1~)3A 0 -A -0*An
3n2
---- )
+ 0.349 sin
A
MAIN
LET VALUE=M(62.4,10.O,4.0)
PRINT 1 LINE WITH SQRT.F(VALUE**2 - (VALUE-I)**2) LIKE THIS
THE VALUE OF Q1 IS *
LET Q2-O READ SMALL.EM
IF VALUE EQUALS SMALL.EM, LET Q2=1 ELSE
IF VALUE IS GREATER THAN SMALL.EM, LET Q2=2 REGARDLESS
PRINT 1 LINE WITH Q2 AS FOLLOWS
THE VALUE OF Q2 IS *
READ QA AND LITTLE.EH
PRINT 1 LINE WITH M((1-Q)**2,A, LITTLE.EH**2) THUS
THE VALUE OF Q3 IS *
STOP END
the variables VALUE, SMALL.EM, Q1, 02, Q,A and LIVTLE.EH are local to
the main routine, and the variable TEMP is local to the routine M.
END
PREAMBLE
LAWT LULUMN IS 72
END
This specifies that in all succeeding cards only columns 1 through 72
contain program statements. Columns 73 through 80 are listed but
ignored during compilation.
-131-
iI
Chapter 3
I- ~ .
-132-
STrue IF False
STrue THNI
False
The following sequence of FOR and ALSO FOR loops illustrates how DOs
and LOOPs are matched when these phrases are interspersed:
FOR
00
FOR
00
ALSO MRo
00
ALSO MRe
00
LOOP
AL SO FOe
00
ALso F"
00
LOOP
-1.34-
The IS FALSE phtase serves a wider purpose than the mere improvement
of readability - it can be used to state a desired condition without
forcing an unnatural transposition nf logiz. For example, a test can
be written as
4h.,*
-135-
Form Example
eRe I<X
e Re Re R <X<N
e ReReR e 1
< X <N aSUM
e R e R e R e R eI1 < X < N - SUM IS GREATER THAN 5
Compound logical expressions can contain more than two simple logical
expressions, as in the logical expression
e1 AND e2 OR e 3 AND e4
for a selected set of control variable values. The phrase i.s useful
for screening values before they pass itto FOR-phrase-controlled state-
ments. An example of the use of a WITH phrase in
In this example the WITH phrase screens out those values of I hetween
I and N for which the logical expression X(I) < CUT.OFF is false. The
program perform as if it had been written as
FOR I - I TO M, DO
IF X(T) > CUT.OFF GO TO LOOP
ELSE L"Et BID(i) - PRICE + PROPORTION (PRICE)
ADD 1 TO NUMBER.OF.BIDS
'LOOP' LOOP
The word WHEN can be used as a synonym for WITH. The word UNLESS
and the phrase EXCEPT WHEN can be used to show that the items papuing
the indicated tast are screened from the loop, rather than accepted.
as iu the program
The outer FOR phrases step the variables DELTA and Q through a sequence
of values as long as the logical expression in the WHILE phrase ts
true. A false condition ends the FOR phraso control by transferzing
to 'NEXT'. Each time the variables ,ro stepped and the logi,-al expres-
sion is troe. the .nne. FOR steps the variable V through a sequence
of values. Only those values In the sequence, however, for which the
logical expression in the WITH phrase is true are passed on to the
statements in the DO loop.
Stotences of WITH. UNLESS, WHILE, ad UNTIL phrases car be attechod
to FOR phrases in any combination. %lore than on* of each trpe c-fphrase
is permitted.
UNTIL and WHILE stacewmnts can also be useý! independently. -henn
used this way, the variables appearint within their Inlical express!ms
de not cose from a FOR phrase iteration, but from compmtations perfcr-ue
-140.
This loop is not teriiinal, as the values of I and J are not affected
by the loop.
PREAMBLE
DEFINE START AS A RELEASABLE ROUTINE
program NORMALLY, MODE IS REAL
preamble et cetera
END
MAIN
main PERFORM START RELEASE START
routine RESERVE MATRIX(*,*) AS N BY N
other computations
END
ROUTINE START
computations
other RETURN END
routines *
The easier of the two program storage and retrieval schoeme pre-
sented involves the partitioning of a program into overlay sections,
with each section containing one or more routines. If the partitioning
is done well (and if a program permits it to be done well), a program
can be executed by sequentially bringing overlay sections into core
on top of one another. If routines within particular sections only
call on routines in the same section or on routines permanently located
in coze, this method is efficient. On the other hand, if routines call
upon routines in other sections, time is spent replacing these sections
in core so that the routines may be loaded and executed. Overlay is
an efficient technique for sequentially designed programs; its effi-
ciency decreases as the inLeraction between overlay sections ;ncreases.
There are several ways in which overlay can be implemented. All
involve keeping a copy of each overlay section on an external medium
and loading it into a fixed overlay area when the section is needed.
Since the same copy is loadod each time a section is overlayed, it is
impossible to transmit values of SAVED local variables between overlays.
-143-
LOAD routin-e na
can then be used to load the routine into core so that it can be
executed.
If dynamic program relocation facilities are available, they
greatly enhance a programmr's capabilities by providing unlimited
memory capacity for program storage. As vith program overlay, SIN-
SCRIPT II implmntation manuals must be examined to see what particu-
lar features specific computer implementations provide.
-145-
FOR I - 1 TO N,
DO
IF X(1)*Y(I) IS GREATER THAN LIMITLET FIRST.PAIR-I GO OUT
OTHERWI SE
LOOP
GO TO NO.PAIRS
'OUT'
are equivalent and illustrate alternate forms of the basic FIND statement
FIND variable - arithmetio xpresaeion
More than one FOR phrase can be used to control a FIND statement.
When this iL done. the FIND statement is usually written vith a list
of Lw-iable - ritiwatic exressionl phrases, as ina
(a) FOR I-1 TO MAX, WITH V(I)cQQ(I) FIND THE FIRST CASE
(b) FOR 1-1 TO MAX, WITH V(I)QQ(I)I FIND I-THE FIRST I
n -
-148-
form "variable sstatistic none." The optional word THE can be put
before each statistic name, and tb-. word AS can be used in lieu of
the equal sign. A COMPUTE statement can be controlled by more than
FOR I - I TO N. DO
statement 1
FOR J - 1 TO M, DO
statement2
COMPUTE MEANX AS THE MEAN OF X(J)
statement 3
LOOP
statement 4
LOOP
FOR I - 1 TO N, DO
statement 1
ALSO FOR J - 1 TO M, DO
stat#Aent,
COMPUTE SLJMX AS THE SUM AND "AXX AS THE IAXIPNUM OF X(I.J)
statement 3
LOOP
-149-
Table 3-1
Alternative or 1
Statistic Abbreviation Computation
NUMBER NUM Number of items selected in the
NUM
iteration
SUM Sum of the selected values of the
expression
MEAN AVERAGE. AVG SUM/NUMBER
SUM.OF.SQUARES SSQ Sum of squares of the selected values
of the expression
MEAN.SQUARE MSQ SUM.OF.SQUARES/NUMBER
VARIANCE VAR MEAN.SQUARE - MEAN
STD.DEV STD SQRT.F(VARIANCE)
MAXIMUM MAX Maximum value of the selected values
of the expression
MINIMUM MIN Minimum value of the selected values
of the expression
MAXIMUM(e) MAY(e) Value of computed e using the control
variable values that produce the
expression with the MAXIMUM value
MINIMUM(e) MIN(e, Same as MAX(e) but for minimum
N- 5
X(1)- 4.0 X(2) - 7.3 X(3) 12.9 X(4) - 0.5 XC5) - 2.2 X(6)- 7.3
The dbove statement iterates the control variable I over the values
1,2,3,4,5, and 6, and selects only those values foe inclusion in the
COMPUTE statement computations for which I < S and X(I) < X(I+1). or
for vhich I=5; thus, it selects X(1). X(2). and X(4) under condition
1 and X(5) under condition 2. For these index numbers, the statis-
tical quantities are computed for the expression X(I). The computed
statistics are:
Coputed
Variable1 Statistic j Computation
NX NUMBER 4
SUMX SUM 4.0 + 7.3 + 0.5 + 2.2 -14.0
MI MEAN 14.0/4 - 3.5
SSQX SUM.OF.SQUARES (4.0)2 +(7.3)2 +(0.5)2 + (2.2)2 74.38
MSQX MEAN.SQUARE 74.38/4- 18.595
VARX VARIANCE 18.595- 3.5 - 15.095
SOVX STD.DEV SQRT.F(15.095) - 3.89
MINX MINIMIM 0.5
PAXX MAX IKM 7.3
MINI MIN(I) 4
40.
-15 1-
reads the first four contiguous xnonblank characters into X(1), the
second four into X(2), and the third four into X(3), and then reads
into I however many digits follow to the first blank. If the free-
form "look ahead" feature is used (see Sec. 2-13), the wode of the
next value to be read can be ascertained by the statement
IF MODE IS ALPHA
If this value is an integer uumber, it is reported as INTEGER, even
though a string of digits is a legitimate character string. Since
the system does not know how characters are to be used but only their
form, ti-e value has to be reported as INTEGER.
In a LIST statement of the form LIST V, where V has been declared
as ALPHA, the contents of V are displayed similarly to INTEGER values
except that character strings are left-adjusted. Additionally, lead-
ing zeroes are not suppressed, as they are legal alphanumeric charac-
ters. In ALPHA mode, zero and blank are distinct symbols.
In a PRINT statement where the format of an item must be described
by a "picture" of asterisks, single parallels, and decimal point.s, each
ALPHA character must be pictured. Unlike INTEGERS, where only the
position of the rightmost digit must be shown, all characters of an
ALPHA variable must be indicated either by * or 1. If more characters
than are stored in an ALPHA word are indicated, only the leftmos-:
positions are used. This choice of rules, quite different from the
rules for INTEGER printing, is made to allow the greatest flexibility
in displaying alphanumeric information.
The READ, PRINT, and LIST statements permit programs to (1) read
data in free-form from punched cards, (2) display computational results
in picture-like formats, and (3) generate labeled data displays without
consideration of specific formats or data arrangements. There is much
more to computer I/0 than these facilities, however. For example,
there are other types of input/output units, such as magnetic tapes,
disks, and drums. In addition, there are recognized needs for facil-
ities to read and write formatted data and to transmit information in
internal machine representation as well as decimal format.
This section presents a set of statements for performing input/
output functions with many types of I/O devices. Unfortunately, these
statements can only serve as guidelines for SIMSCRIPT II compiler
implementations, and cannot be taken as strict language specifica-
tions due to the variance in input/output device designs among co'-
puter systems, as well as to the special relationship between input/
output operations and computer operating systems. Specifications
that appear in single statements in our proposal may have to appear
-154-
a device cannot be used for both input and output at the same time,
this ensures that error messages will be properly displayed and in-
magneaic tape units if they are designated as the current input unit,
whereas output can be written onto magnetic tape, as well as being
displayed on printers.
Input/Output Devices
The devices people are most familiar with and that are found in the
majority of installations are punched card readers and punches, line
Table 3-2
MaIF m f
!/O Device Field Width Record
The READ statement used thus far has only been able to read free-
form data. A READ statement that accepts formatted data has the form
in which each variable value to be read has its input data format
described by a corresponding descriptor in a format list. These for-
mats, which are codes telling how the input data are placec on data
cards, are described in the next subsecti..n.
The WRITE statement transfers values frov vit•in the computer to
specified external media, such as line printers or magnetic tapes.
Every WRITE statement is formatted. With the sole exception of the
LIST stetment, it is always the programmr's obligation to indicate
the arrangement of output data. The WRITE statemnt looks like the
READ @tatement; Its form is
-158-
I (Integr) Descriptor
D (Decimal) Descriptor
See p. 161.
+I
I
-160-
E (Scientific) Descriptor
txxx.xxxE±xx
2 sign of nwbber E +E
3 sign of nwuber E sign of exponent +E+
4 sign of nwuber E sign of exponent d +E÷2
d- digit if 0 < exponent < 9
a * if exponent > 10
rI
-162-
A %.Aphanumeri ) Descriptor
If ye asiume that data are on punched cards, and the above statement --
the first in a program - starts reading at column one, the value
punched in columis 1-3 is sasitned to X , the value pur-hed in columns
4-5 is assigned to ANSWER. and the value punched in columns 6-7 is
assigned to Y. The data card might appear as
column number
00000ocI1,11...
12345678901234
160 3 8
column number
0000000001111.
12345678901234
-336-9
in which case X'-3, ANSWER36. and Y--9. The data aro read saque-
tially. Tht information needed to locale a number and detorwirc6 its
form is contained in the foruat descriptors.
Here, the fornat list is the amea (a) except that the second and
third format descriptors have been combined.
-164-
column number
00000000011111...
12345678901234
9-3 0
Notice that leading zeroes are left blank, but that the rightmost
zero in a zero-valued integer is printed.
column number
000000000111111111122222222223333...
123456789012345678901234567890123...
126.345 -18.62 768954346
The first data field is assigned to X and the decimal point is where
it is expected, in column 7. The second data field is assigned to Y;
here the decimal point is not where it is expected, in column 17.
Therefore, the punched number overrides the stated format, and the
value -18.62 is assigned to Y. A characteristic of the D format is
that it allows itself to be overridden if a decimal point is punched
within a field. If no decimal point is punched, as occurs in the
third data field, its location is determined by the format. In this
call, the value 768954.346 is assigned to Z.
column number
00000000011111...
12345678901234
16.5E 2
The punched decimal point overrides the format. The scale factor
multiplies the resulting number by 10**2 so that the value 1650 is
assigned to X. The flexibility of the decimal format is shown in the
column number
0000000000000000000Z222222222333333333344444444445...
12345678901234567890123456789012345678901234567890...
41.25 19.22E-03 4537992 -167.1
column number
00000000011111111112222222222333333333344444444445...
1234567890123456789012345678901234567890123456'7890..
Thn output of E illustrates the action taken when a value is too large
significance.
-166-
If we assume that the array A has been defined as ALPHA, and that each
computer word holds four characters, the following data will be read
and stored in A(1), A(2), and A(3):
column number
000000000111111111
123456789012345678
INPUT DATA
A(1) contains the characters INPU, A(2) the characters T DA, and A(3)
the characters TA . The charanter denotes a blank.
column number
00000000011,11
1234567890123
INPUT DATA
column number
000000000111
123456789012
INPUT
Thus far, the examples have pretended that each new READ or WRITE
statement starts at the beginning nf a new data card, line, or record.
This does not always occur. It has been a convenient fiction for the
exposition of format descriptors.
All READ and WRITE statements operate on a continuous string of
characters and only skip to a new data card or output line when so
instructed. Thus, the two statements
read successive fields from the same data card (record). Often, of
course, data are split between data cards, or must be read from dif-
ferent, noncontiguous parts of the same data card. A method of posi-
tioning the current input pointer or current output pointer is needed
to do this. Such pointers are variables that point to the last
referenced columns in the various input and output data streams.
They can be advanceO by the statements START NEW INPUT CARD, START
NEW OUTPUT CARD, and START NEW PAGE, which we have already seen, and
by five nonnumerical formas. These formats can be interspersed
among numerical formats, or they can appear alone in READ and WRITE
statements. Examples of the use of these formats are given following
their description.
-169-
(e) WRITE N AND AVERAGE AS "OF",I 3," TO DATE, THE AVERAGE IS ",0(6,2)
Two values embedded in character strings are written from the
above statement. If writing occurs on a line printer and the current
output pointer is at the beginning of a line, the output looks as
follows for N=97 and AVERAGE-53.287:
11
-170-
The above statement starts a new output page and skips four lines.
No output values are transmitted.
Here, the free-form READ reads a sequence of values across the current
input record. If, however, values are packed in a format with no
blanks between them, the free-form READ cannot be used. One is
tempted to write
as this reads one value per input record. A new convention is needed.
An expresslon enclosed in parentheses placed before a format list
repeats that format list the indicated number of times and then skips
to a new record. If N-12 and four numbers are to be read per card
from columns 1 through 24, the following statements read 12 values
from 3 cards:
This form may also be used if groups of vartabilu with different for-
mats are in a record. The folioving statewent reads 4 groups of data
in the format I 6,D(6,2) from each data card until 2N values have
been read.
Variable Formats
Table 3-3
Integer field I I e
Decimal field i D(e,e)
Scientific field i E(e,e)
Starting column B e
Space skip S e
Alpha field i Ae
Computer rep-field i C e
READ 1, A, B AS B C1 , I C2 , S C3 ,2 D(C4,C5)
column number
00000000000000000022222222223333333333...
123456 7890123456 78901234567890123456 78...
6 4 10 5 2
342 16.25 1.5
-10 0.5 73.4
This phrase sets the current input or output unit to the indicated
unit dur'Ang the statement's execution, and returns it to its previous
value on its completion. The optional words TAPE or UNIT can be
written before the unit number, if desired, as in the last example.
A Final Remark
move the current input or output unite forvard or backward the indi-
cated n-mbtr of files, i.e., past a end-of-file markers. The statement
are available.
The CLOSE. ADVANCE, and BACKSPACE statements clso allow an optional
word before the device specification, as in
CLOSE TAPE K
ADVANCE 2 INPUT FILES USING NMIT 7
REWIND d
The words TAPE and UNIT are optional aftei REWIND. After a unit has
been rewound, it muat be "used" before it can be read from or vritten
on again. A REWIND comand before a unit has been "used" is ignored.
tape, or disk, and for reading them back when they are needed. Binary
and formatted data can.not be written together on the same device. The
foliowlng program shows how to save a computed array, release it for
other use, and, at a later time, reuse the array values:
MAIN
READ N "FREE-FOPM READl
RESERVE ARRAY(*,*) AS N BY N
RESERVE ARRAY(*,*'* AS N BY N
USE TAPE 1 FOR iHPUT
FOR I=1 TO N, FOR J=1 TO 0, READ ARRAY(I,J) AS BINARY
STOP END
used (cards, tape, printer). All reading and writing occurs through
these bufters. Both the curient input pointer (RCOLUMN.V) and current
output pointer (WCOLUMN.V) travel along the buffers, point to the last
accessed character, and read or write physically when a / format is
encountered or the end of a buffer Is reached.
The current output buffer is called OUT.F, and can be accessed
as an ALPHA function. OUT.F(1) refers to the first character in the
buffer, OUT.F(1O) to the tenth characterp OUT.F(132) to ,-: last
character. tAs a computer word contains more than one alphanumeric
character and the OUT.F function returns only one character, the value
of OUT.F is a left-adjusted ALPHA word; e.g., if the first buffer
position contains the letter A and each word can hold four ALPHA
characters, the value of OUT.F(1) is A._..tt It is possible to edit
output information by inserting alphanumeric or numeric data directly
into the buffer. When a new record is begun, by either a START NEW
statement or a / format descriptor, the buffer is emptied and filled
as the ensuing formats dictate. Thus, the statement
-178-
Note that / clears THE BUFFER and sets the current output pointer to
its first position. The statement
-179-
The PRINT statement that we have been using since Sec. 1-12 has
functioned as both a simple mechanism for displaying short error mes-
sages and as a more complex report layout statement (Sec. 1-16-2).
This section adds two phrases to the PRINT statement and introduces
two control statements to provide a full-fledged report generator
capability.
These new features permit a programner to specify the layout of
printed results, to control the printing of headings and titles, to
eject pages between various report sections, and to arrange "wide
reports" on standard-width paper. Figure 3-1 illustrates the kind of
complex report that can be generated.
The statement BEGIN REPORT marks the start of a report section
within which various kinds of control can be exercised. A report
section, like a routine, is terminated by an END statement. The
statements
BEGIN REPORT
FOR 1=1 TO N, PRINT 1 LINE WITH I,X(1) THUS
END
I-I
Szz
xX x Ih x Cm
Vi
4J
o0000000000000
* XX 000 0000000000000 0 0 000000000 -*S
0000000000000000
C, "I O.. 1
4-)
C
* ..
a.-
°S-
.40 Pdif
-. 4 44
- a w
*
aOo oO XX K *i XX
OOOOOOOOOO000K
0 0 4 *l XX
0000000a000000 XX]• 0- r
5-I.- C-
0- ul
4.. .. .0 ow J- y.. .0 0d g . . .0c49
0.4 I-- a0
BEGIN REPORT
PRINT I '.INE AS FOLLOWS
I X(I
FOR 1=1 TO N, PRINT 1 LINE WITH IX(I) THUS I
END
This prints a heading above the N lines of output that identify the
displayed values. If N is large and the output continues on more
than one page, only the results on the first page are labeled. All
other pages are untitled.
A heading section may be defined within a report section so that
titles are printed and any necessary computation performed whenever
a page is ejected. A heading section is started by the statement
BEGIN HEADING and ended by the statetient END. All statements between
a BEGIN HEADING and its matching END are executed whenever a page is
ejected by an output statement within an enclosing report section,
but after the heading section itself.
To title all pages of output in the foregoing example, the program
can be written as
BEGIN REPORT
DEGIN HEADING
PRINT 1 LINE AS FOLLOWS
I X(1)
END " HEADING SECTION
FOR 1=1 TO N, PRINT I LINE WITH I, X(T) THUS
END
IF PAGE IS FIRST
may be used to select atatements to be executed only on the first page
of a report section's output. The following program illustrates one
way of using the report facilities described thus far:
PREAMBLE
NORMALLY, MODE IS INTEGER
END
The above program (1) in its MAIN routine reads in control infor-
mation and (2) in its DISPLAY routine uses a report section to prepare
a labeled output display. The variable LINES.V is used both to control
the number of lines prinead per page in successive reports and to
terminate the program.
Within the routine DISPLAY, an output unit is selected outside
the report section &nd PAGE.V is set to 1. This enables each report
to be printed on a separate device, if desired, and sets the number
of the first page of each report to 1. Within the report section
SKIP statements are used to separate heading information.
If the data read by this program are the sequence of values 50,
100, 5, 20, 40, 6, 0, 0, 0, two reports vll be printed. The first
will display the values of J, vj, j2, and log(j) for J-1,2,...,100 on
three pages of output unit 5. If we assume that printing starts at
the top of the first page, it vll contain the heading TABULATION OF
MATHEMATICAL FUNCTIONS, the page number, the heading I SQRT(I) I SQ
LOG(I) and values for J-1,2,...,41. The second page wvii contain the
page number, the heading I SQRT(1) I SQ LOG(I) and values for j- 42,
44, ... , 86. The third page will resemble the second, except that it
will contain values for j - 87,89, ... , 100.
The second report will be similar to the first, except that it
will display values for j - 1, 2. ... , 40 on pages that contain only
20 lines. The heading TABULATION OF MATHEMATICAL FUNCTIONS will be
printed on the current page, renumbered 1, of output unit 6.
Whenever it is necessary to begin each report section on a new
page, as might be done in this example, the BEGIN REPORT statement
can be written as
which ejects a page on the current output device unless the current
page has not been written on (LINE.V- 1, WCOLUMN.V- 0). This prevents
blauk pages from being ejected between renorts.
The form of a "typical" report using the statements described
thus far is
-184-
program statements
BEGIN HEADING
SKIP N LINES
END"HEADING
program sto.tements
END"REPORT
wit! the variables LINE.V and PAGE.V being used in computational,
decisionmaking, and output statements. PRINT statements appear in
heading and report sections, and usually are controlled by FOR or
WHILE statements in the part of the report section labeled "program
statementa." The flow of control in a report section such as appears
on this page is as follows:
specifies that 2i, rather than i, format lines follow that are to be
read in pairs and interpreted as one format line 160 columns long.
To fill an entire line on a printer 132 columns wide, one would write
a statement as
specifies that five sets of column indices will be used for five ex-
ecutions of a report section. The report soction vill be executed
-186-
PA Gi PA CE3
PAGE 2 PAGC 4
END REPORT
This program generates four pages of ourput. Page 1 uses the first
five values of J. A headilug displays the values of J. and a row
repetition statement prints the values of X(IJ) for those values of
J and 1- 1,2,3,4,5,6. Fii.:re 3-3 illustrates how such a page might
appear.
1 2 3 4 5
Pg 3. 4.andia.
ae 0 p-u
Fage
2. Fig. 3-4~ir.lok eatlly.' !iko
kt page I nfrm i
SFig.
3-3 -- Columnw repetltlofl,
i ~ Fage 2, tig. 3-4, looks exactly .like page 1 in form, but jeots
This program generates four pages of output. Page 1 uses the first
five values of J. A heading displays the values of J, and a row
repetition statement prints the values of X(I,J) for those values of
J and 1- 1,2,3,4,5,6. Figure 3-3 illustrates how such a page might
appear,
1 2 3 4 5
** ** ** ** **k
Page 2, Fig. 3-4, looks exactly like page 1 in fo.-m, but uses
the second fi';e values of J to select values for display.
Pages 3, 4, and 5 are similar, with page 3 using J1ll,...,15,
and page 4 using Jz 16,...,20, etc.
The phrase A GROUP OF FIELDS in a PRINT statement notifies the
compiler that a sequence of index values generated for the enclosing
-189-
All repeated formats need not be identical, e.g., and but they
must be of the same mode.
If it is not necessary that each set of column repetition groups
start on a new page, the PER PAGE clause may be omitted from the
BEGIN REPORT statement. The following report section uses this fea-
ture to display a matrix containing more columns than can be put on
one line:
FOR I=1 TO N, DO
PRINT 1 LINE WITH I AS FOLLOWS
ROW ** i
BEGIN REPORT PRINTING FOR J= I TO M IN GROUPS OF 24
PRINT I LINE WITH A GROUP OF X(IJ) FIELDS THUS
END''REPORT
SKIP 2 LINES
LOOP
Such a program produces a report that, for M= 50, looks like Fig. 3-5.
ROW 1
* ** ** ** * * * *** ** * ** * *
*** * * * ** * * * * *
Note that the total number of column indices generated need not be an
even multiple of the group size, e.g., 50 and 24 above.
A final feature makes it possible to generate attractively labeled
reports that have row, as well as column, sunmarizations, even if the
reports use column repetition. This is done by adding a clause to
tLe PRINT statement that suppresses some output until all column
-190-
Page 1
Page 2
Page 3
I,
-192-
Card Column
OOOOOOOOljllllllll2222222222333333333344444444445555555555666666666677777777778
12345678901234567890123456789012345678901234567890123456789012345678901234567890
LET PAGE.V=1
BEGIN REPORT ON A NEW PAGE PRINTING FOR DEPOT=1 TO 60 IN GROUPS OF 24 PER PAGE
BEGIN HEADING
PRINT 1 DOUBLE LINE WITH PAGE.V AS FOLLOWS
PAGE *
PRINT 1 LINE AS FOLLOWS
DEPOT TO BASE SHIPMENTS
SKIP 1 OUTPUT LINE
PRINT I DOUBLE LINE WITH A GROUP OF DEPOT FIELDS SUPPRESSING FROM COLUMN 91 THUS
DEPOT ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **
TOTAL
PRINT 1 LINE AS FOLLOWS
BASE
END '"HEADING
FOR BASE=1 TO 120, PRINT 1 DOUBLE LINE WITH BASE, A GROUP OF SHIP(BASE,DEPOT)
FIELDS, TOT(BASE) SUPPRESSING FROM COLUMN 92 AS FOLLOWS
•** * * * * * * * * * * * * * * * * * * * * * * * *
END
Chapter 4
4-00 INTRODUCTION
RESERVE MAN AS 3 BY 10
with the understanding that MAN(I,4) represents the age of the fourth
man, MAN(3,b) the social security number of the sixth man, etc.,
according to the layout:
1 2 3 4 5 6 7 8 9 10
AGE 1
DEPENDENTS 2
SOC.SEC 3
MAN
value of AGE
value of DEPENDENTS
value of SOCIAL.SECURITY.NUMBER
and the form AGE(MAN) can be translated into "the value found in the
first word of the record indexed by the value MAN." Since attribute
names specify relative Zocations of values in entity records, no two
entities can have an attribute with the asme name placed in different
words within the two entity records. The statesents
do not. Sections 4-03 and 4-04 discuss entity types and entity declara-
tions more fully, and clarify the notion of an "entity index" referred
to above.
-196-
4-02 SETS
The first statement declares that each entity of the class COMMUNITY
awns a set called MASONS, a set called ELKS. and a set called
BOY.SCOUTS. Fach of these sets corresponds to a logical grouping
of man in the counity. This statement doas not specify which men
belong to the particular sets; rather, it establishes a system of
set pointezr and set attywibutes for the onr entities that enable
#at membereship to be constructed. Each COMMUNITY is given a logical
entity record with the following attributes automatically defined:
COMM(ITY
F.MASONS
L.MASONS
F.ELKS
L.ELKS
F.BOY. SCOUTS
L. BOY. SCOUTS
The attributes etartin w-ith F. are set pointers thait point to the
first member of the respective sets. The attributes starting with L.
are set pointers that point to the last member of the respective sets.
The set ,membeos, as we shall see, point to one another, defining their
interrelationships and making the connection between the set owner and
the set members complete.
The second statement declares that each entity of the class OAN
may belong co sets called MASONS, ELKS and BOY.SCOUTS. It is impor-
tunt to note that membership is declared am possible in this statement
and not mAde mandatory. As might 1-e expected, this statement auto-
matically defines set attributes for member ent.ties:
MAN
P. MASONYS
S.MASONS
S.ELKS
P.BOY. SCOUTS
OUJT 5
S.90Y. -SC'
entity COMMUNITY owns one set called MASONS. The members of the set
are entittas of the class MAN. The entity-set relationships are
defined by the statements:
COMMUNITY
F. MASONSMA
L. MASONS P. MASONS
Th. set ower, the entity namd COMM4UNITY, has tw7o attribute.
Z~ogioalZz/ first and last
that point Lothe member entities that arehere called MANM1 , MAN2,
member entitie,
r1MA
in the set MASONS. The
.....
4 , have two attributas
MAN that point to the members of the
3 , and
MAN
F.MASONS in
set that logicaZty precede and succeed the.. Thus,
~MAN indicating that it is
COMMUNITY points to the entity record of MANl 1,
.4-u
COMMUNITY
P.MASONS 0 "
S.MASONS O 0
F.CHILDREN S0 0 0 i
L. CHILDREN 0 O /0
P. CHILDREN 0 0 /
S. CHILDREN 0
(a) COMMUNLIY owns the set MASONS wbose members are MAN 1 , MAN 3,
MAN 4 , and MAm5,
(b) MAN, ownu a set CHILDREN whose members are MAN 2 . MAN 6 - and
MAN 5.
(c) MAN 2 owns a set CHILOREN whose single member is MAN 4 .
MANI UA-- /
V-------
MAK CNXItDRI
2
•--
MAN
....-.....
4
TEMPORARY ENTITIES
TEMPORARY ENTITIES
EVERY SHIP HAS A NAME AND A TONNAGE
CREATE statements in a program:
NAME
VESSEL TONNAGE
NAME
TONNAGE
PREAMBLE
NORMALLY.MODE IS INTEGER
TEMPORARY ENT!TIES
EVERY SHIP HAS AN AGE AND A TONNAGE
DEFINE V AS 1-DIMENSIONAL ARRAY
END
MAIN
READ N RESERVE V AS N
FOR I- TO NDO
CREATE A SHIP (ALLED V(I)
READ AGE(V(I)) AND TONNAGE (V(I))
LOOP
'READ' READ OLD
FOR I-1 TO N,WITH AGE(V(I)) < OLD,
ADD TONNAGE(V(I)) TO SUM.TON$
PRINT 1 LINE WITH OLD,SUM.TONS THUS
TOTAL TONNAGE OF SHIPS LESS THAN ** YEARS OLDu******
LET SUM.TONS-O
IF DATA IS ENDEDSTOP
ELSE GO TO READ
END
In this program N temporary entities of the class SHIP are
created and their identification numbers stored in the subscripted
variables V(1),V(2)....,V(N). The attributes of these entities are
accessed in READ, WITH. and ADD statements.
As temporary entities are created, entity records are fetched
from a pool of unused memory vords. The assignment of entity records
to entities is similar to the assignment of pointer and data words
to
-204-
is treated as
DESTROY entity name CALLED entity name
The statement
DESTROY THE SHIP
is interpreted as
PERMANENT ENTITIES
PERMANENT ENTITIES
EVERY HOME HAS AN ADDRESS AND AN AREA
When the second form is used, N.entity is set to the value of the
parenthesized expression.
Entities so created are referred to, not by an identification
number that is a computer location, but by an index. Thus we speak
of ..S attributes of each HOME as ADDRESS(1),ADDRESS(2),...,ADDRESS(5),
AREA(1),AREA(2),...,AREA(5). The layout of these attributes is shovn
in Fig. 4-4.
I
- -~--
-206-
ADDRESS AREA
2 2
3 _ 3
44
PREAMBLE
NORMALLYMODE IS INTEGER
PERMANENT ENTITIES
EVERY SHIP HAS AN AGE AND A TONNAGE
END
MAIN
READ N.SHIP CREATE EVERY SHIP
FOR 1-1 TO N.SHIP,
READ AGE(I)oTONNAGE(I)
'READ'READ OLD
FOR I1- TO N.SHIP WITH AGE(I) < OLD.
ADD TONNAGE(I) TO SUM.TONS
PRINT 1 LINE WITH OLDSUM.TONS THUS
TOTAL TONNAGE OF SHIPS LESS THAN * YEARS OLD-*****
LET SUK.TONS-O
IF DATA IS ENDEDlSTOP
ELSE GO TO READ
END
EVERY enti.t,
-207-
NORMALLY, DIMENSION IS 2
THE SYSTEM HAS AN X
PREAMBLE
NORMALLY.MODE IS INTEGER
THE SYSTEM OWNS A SCHOOL
PERMANENT ENTITIES
EVERY STREET HAS A SIGN AND OWNS HOUSES
EVERY HOUSE HAS A NUMBER, OWNS A FAMILY AND
BELONGS TO SOME HOUSES
TEMPORARY ENTITIES
EVERY PERSON HAS A NAMEAN AGEA SEX.BELONGS
TO A FAMILY AND MAY BELONG TO A SCHOOL
EVERY FAMILY OWNS SOM.E PERSON
END
Subscripted system-owned sets are defined by setting a dimensionality
background condition that makes the set pointers arrays, rather than
unsubscripted variables, a in
NORMALLY. DIMENSION - 2
THE SYSTEM OWNS A TABLE AND HAS A MATRIX
must be executed.
PREAMBLE
NORMALLY DIMFNSION IS 2
THE SYSTEM HAS AN EXCESS
DEFINE EXCESS AS AN INTEGE1 ARRAY
NORMALLY DIMENSION - 0,
MODE IS REAL
THE SYSTEM HAS A VALUE AND
OW14S A COLLECTION
PERMANENT ENTITIES
EVERY SAMPLE BELONGS TO T1Er COLLECTION
AND HAS A PRICE ANC A SAME
TEWPORARY ENTITIES
EVERY POINT HAS AN IDENTITY AND A
TIME.OF.COLLECTION
DEFINE NAME AND ID[NTITY AS ALPHA VARIABLES
END
SAMPLE
base pointers 1 2 . N. SAMPLE
P. COLLECTION -"
.N. SOLECTIO
NAME
IDENTITY
VALUEE
Row pointers
EXCESS (base pointer)
F. COLLECTION
L.COLLECTION L iI ]L
Thus far, all discussions of data have assumed that data values
exist whereby more than one data value must be placed in a single
computer word. The vost commonly encountered reason for doing this
is to "squeeze" programs with large data requirements into limited
memory space.
When more than one data value is placed in a computer word, the
values are said to be packed in the word. When a data value is given
different names the names are said to be equivalent. SIK'CRIPT II
are avPiiable: field, bit, and intra. Field and bit packing apply
to all subscripted attributes; intrapacking applies only to sub3cripted
system attributes and to attributes of permanent entities.
The SIMSCRIPT II system uses programmer-specified packing factors
t, store and retrieve data values. The fact that data are packed is
reflected in a program's preamble but not in its executable state-
ments. A programmer operates at all times on a logical level., e.g.,
AGE(MAN); the SIMSCRIPT II system determines where AGE(MAN) is phys-
ically located.
Using field and bit packing, data fields can be laid out within
computer words. The field packing notation (1/2) specifies that the
attribute value to which it is attached is to be put in the first
half of a computer word. The bit packing notation (1-16) specifies
that bits 1 through 16 are to be used to store an attribute value.
Since computers differ in word size and in instructions available to
access parts of words, it is impossible to specify all the possible
field and bit packing factors available in different SIMSCRIPT II
implementations. Table 4-1 shows the packing factors available in
an IBM 360 implementation; readers using other implementations will
have to consult their implementation manuals for the packing factors
av&ilable to them.
Attrl'ute names are processed as they appear in EVERY statements,
and are assigned their indicated positions within successive computer
words. Attribute equivalence is specified bv placing parentheses
around a list of attributes. All attributes within parentheses are
assigned to the same computer word; if two attributes have the same
packing factors, their names are synonyms. Overlapping packing fac-
tors can be specified. Attributes enclosed in equivalencing parenthe-
ses appear in a list, without the words A, AN, or THE before them.
The parenthesized list must, however, be preceded by one of these
words. The following examples illustrate the use of field and bit
packing fa-tors for attributes of temporary entities:
Table 4-1
TEMPORARY ENTITIES
(a) Declaration:
Entity record:
word I AGE
wvrd 2
(b) Declaration;
Fntitv record:
(c) Declaration;
word 2 NAME
word 3 SEX
(d) Declaration:
Entity record: 1 9 32
word 1 AGE INAME I
(e) Declaration:
Entity record:
word 1 AGE A WGHT
word 2 F.FAMiLY
vord 3 L.FAMILY
(g) Declaration:
PERMANENT ENTITIES
EVERY HOUSE HAS AN (ADDRESS(1/2).AND ZIP(?/2))
placea similarly indexed values of ADDRESS arl ZIP in the same com-
puter word. This declaration, followed by the statement CREATE EVERY
HOUSE (5) allocates storage as follows:
This rtatent pairs the attributes TONNAGE and CAPACITY and the
attributes DESTINATION and HOWE.PORT in adjacent parts of attribute
arrays. Some additional *xamples follow.
PERMANENT ENTITIES
(a) Declaration:
Attribute arrays:
word N.HORSE
(b) Declaration:
word 1
word 2
word N.HORSE
(c) Declaration:
Att:ibute arrays:
word 1
word 2
word N.HORSE
NAME ig stored in the left half, and OWNER in the right half of
a data array.
SYSTEM ATTRLIUTES
(a) Declaration:
NOPALLY, DIMENSION - 0
THE SYSTEM HAS A HIGH AND A LOW
Attribute&:
HI GH LOIW.
-217-
(b) Declaration:
NORMALLY, DIMENSION 1
THE SYSTEM HAS A HIGH AND A LOW
Attributes:
word 11
word2 2
0 .
wordNNM
(c) Declaration:
NORMALLY, DIMENSION - I
THE SYSTEM HAS A (HIGHLOW)
Attributes: HIGH
LOW
word 1
word 2
word N
(d) Declaration:
NORMALLY, DIMENSION 1
I
THE SYSTEM HAS A (HIGH(1/4), LCO(2/2))
Attributes: WYiGH7
LLordOW
word 1
word 21
word N _
NORMALLY, DIMENSION - 1
THE SYSTEM HAS A LIST(*/2)
NORMALLY. DIMENSION * 2
THE SYSTEM HAS A LIST(*/2) and
RESERVE LIST(*,*) AS 3 BY 4
Table 4-2
(a) Declaration:
Entity record:
word I AGE
vord 2 F.FAMILY
word 3 L.FAMILY
vord 4 NAM
-220-
(b) Declaration:
word 2 DEBT
MAN WOMAN
word 1 AGE INAME AGE NAME
word 2 F. FAMILY unuaed
word 3 L.FAMILY unused
word 4 P.FAMILY P.FAMILY
word 5 S.FAMILY S.FAMILY
Table 4-3
ATTRIBUTE SPECIFICATIONS
Specification Assignment
Declaration:
Declaration:
Program statement:
I IF CREDIT.RATING(CUSTOMER)=O,GO
ELSE CALL ACCEPT.CREDIT
REFUSE.CREDIT
f
tI'
-224-
like arrays in that they are composed of elements that can be identi-
fied and manipulated, but are unlike arrays in their method of organi-
zation and their dynamic and changeable, rather than static and fixed,
nature.
As described in previous sections, sets are declared in EVERY
statements when their owner and member antities are defined. Every
set must have an owner, either an entity or the system, and can have
either permanent or temporary entities as members. When more than
one type of temporary entity belongs to a set, the predecessor and
successor attributes of the entities must be located in the same
words in the entity records.
Sets named in EVERY statements have the following properties:
(a) Owner entities have first and last pointers named F.set
and L.set;
(b) Member entities have predecessor and successor pointers
named P.set and S.set;
(c) Set members are ranked on a first-in, first-out basis when
they are put in a set. This ranking gives the highest
priority to the first entity put in a set;
(d) A request to remove an unspecified entity from a set removes
the entity with the highest current priority;
(e) Each member entity has a memberohip attribute named M.set
that is "yes" if an entity is in the set and "no" if it is not;
(f) Each owner entity has a counter attribute names N.set whose
value is the number of member entities currently in the set.
All set owner and member attributes are INTEGER valued and have names
t
formed by prefixing a letter and a period to the set name.
The declarations
PERMANENT ENTITIES
EVERY CITY OWNS A CLUB
TEMPORARY ENTITIES
EVERY MAN MAY BELONG TO THE CLUB
define three attributes for the owner entity of CLUB and three attri-
butes for its member entities. Since CITY is a permanent entity, its
owner attributes are stored as arrays:
vord 1
word 2
word N.CITY
MAN
word I P.CLUB
word 2 S.CLUB
word 3 M.CLUB
The words FIPC•T or LAST are optional. When both are omitted, FILE
LAST is implied; the statements
FILE arithmetic #xpv*.;cn. LAST IN set and
FILE mr-ithmtio exprission IN Pet
are equivalent.
In each of the forus, the words THE or THIS are optional before
the expression or the set name, as in
-226-
TEMPORARY ENTITIES
EVERY FAR4 OWNS A KENNEL
EVERY DOG HAS A NAME AND BELONGS TO SOME KENNEL
DE&INE NAME AS AN ALPHA VARIABLE
The two illustrations are included in the program segment shown below.
We first consider the situation before and after the first dog is
filed in a kannel; later we examine a subsequent situation. Assume
a FARM has been created whose identification number is stored in the
global variable FARM. This could have been done by the statement
CREATE A FARM.
Program Segment
READ NLUER.OF.DOGS
FOR 1-1 TO NUMBER.OF.DOGS.DO
CREATE A DOG
READ NAW (DOG)
FILE DOG FIRST IN KENNEL(FARM)
LOOP
The entity record of FARM looks like:
FARM
word 1 F.KENNEL
word 2 L.KENNEL
word 3 N.KENNEL
-227-
After the first dog is created, its entity record looks like:
DOG
NAME
P.ENNEL
SKENNEL
The ovner entity FARM points to the uemer entity DOG: DOG, being
the only entity in KENNEL(FAR4). is both first and last. Since DOG
is alone in KENNEL(FARM) it has no predecessor or successor entities.
After the second DOG is crasted and tiled, the entity records
look like:
FARIM
F.KENNEL 0 NAME RO-VER •
L:EN E P.AENNEL • -
N.KENNELL.KENNEL NNL
S .KENNEL 0
P.KENNEL I•/
IDO
NAMFE FIDe
P.KENNEL
M. ENNEL I
With tvo members in the set, the first and last pointers lead to dif-
ferent entity records. The first entity, poi,:t.~: to rY F.KENNEL(FAR4),
-228-
pointe ahead to the second entity with its successor pointer. The
second entity pointa back at the first entity with its predecessor
pointer. Both the predecessor pointer of the f,&rst entity and the
successor pointer of the last entity are zero, indicating their re-
spective roles.
An important point to note is that the global variable DOG now
points to the second DOG (the second DOG created, not necessarily the
second in the set). The entity record of the first DOG created can
only be accessed through the pointers to it. L.KENNEL(FARM) and
S.KENNEL(DOG). These pointers illustrate the general form of an
attribute reference.
S.KENNEL(F.KENNEL(FARM) )1'
S.KE 4NEL
P.KENNEL
KEINEL
S.
M.KENNEL -1
F.KENNEL eER N
L. KENNEL 3.N
N.KENNEL
NAME FIDO
P. KENNEL
S.KENt4EL
M.KENNEL 1
NAME REX
P.KENN EL
S.KENNEL 0
M.KENNEL I
The statements
CREATE A DOG
FILE THE DOG AFTER FIDO IN KENNEL(FARM)
insert the entity record for the newly created DOG after the entity
record pointed to by the variable FIDO. The resultinS entity record
organization in shown in Fig. 4-9.
-230-
F.KENNEL NM
I *KENNEL PKNE
N. KENNELE
NAME
P. KENNEL 0
S. KENNEL
M.KENNELI
F.KENNEL NM
1. KENNEL PKNI
N. KENNELL
Fig.A se
-9 wit
- threm Ier
The word THE is optional after REMOVE, "s is either of the words THE
and THIS before the set nae. In addition, either of the words THIS
or ABOVE cdn be used before the expression in form (b).
A "REMOVE FIRST" or "REMOVE LAST" statement removes from a set
the entity pointed to by the first or last pointer attribute of the
set ow r. The identification nmber of the removed entity is "ssigned
to the variable in the REMOVE statement. For instance, in the situa-
tion shown in Fig. 4-9. the statement
removes the first entity (FIDO) from KEIP4EL(FAR4), makes the second
entity first, and puts a pointer to FIDO in HOUND. The attribute
values of FIDO, which now can also be called HOUND, are unchanged
except for M.KENNEL. Although FIDO is no longer in KENNEL(FAIR), its
attribute S.KENNEL still points to DOG. In most instances, pointer
values are meaningless once in entity is removed from a set. If the
name FIDO were replaced by DOG in Fig. 4-8, this figure would show
the organization of KENNEL(FARN) after FIDO had been removed irom
1"-&. 4-9.
If an attempt is made to remove the first or last member from an
empty set. the program terminates with a message and an error halt.
A "REMOVE specific entity" statement (form (b)) extracts a par-
ticular entity from a set; the entity identification number is given
by the arithmetic expression. Referring again to Fig. 4-9, the state-
sent
REMOVE THIS DOG FROM KENNEL(FARM)
converts the set show• in that figure to the set shown in fil. '--8.
If the arithmetic expression is not an identification number of an
entity currently in the set (signaled by a "yes" in its membership
attribute), the progrma terminates with a message and an error halt.
The presence of a membership attribute in an entity paermits both
-232-
ditional on set membership. As options, the vords THE and THIS can
precede the arithmtic expression, and the vords A, AN, THE, or SOME
the set nine. One can write
are available. As vith the preceding expressions, the words THE and
THIS are alloyed before the set name to improve readabillty. Using
the "IS NOT EMPTY" and "IS EMPTY" logical expressions. ine can write
statements such as
All tho s*atesmnts described thus far &Asumi that every set has
a full complement of owwership and emboerehip attributes, i.e., that
both first and last, predecessor sad successor poibters, asd c..nter
sad meamwership attributes are defiued. To perform all of the available
-233-
set manipulatitons, they must all be present. When set needs are moie
modest, sets with fever pointers can be designed, with a gain in
efficiency in set manipulations at the expense of some manipulative
power.
The sets pictured in all preceding illustrations contain all
possible pointers. Additionally, they rank on a fitst-in, first-out,
priority scheme, i.e., FILE LAST is the default condition. Other
rankings are possible. For examole, in a set defined by the declarations
we might want the various men in the army sets to be ranked by weight
or height, rather than by set et, rsnce time. Furthermore, we might
want this ranking to be in ascending or descending ordei. This can
be done by including a set definition atutement after the EVERY state-
ments that first mention a set, and after any attribute definition
statements that might be associated with the EVERY stateraer'. A set
definition statement, like an attribute definition atatemetnt, begini
with DEFINE. The following statements define the set ARMY as being,
respectively: (1) ranked in descending order by the HEIGHT attribute
of the fntities in it; (2) ranked in ascending order by tCese same
att.-ibutes; (3) ranked in descending order by the WEIGHT attribute
of the entities in it; (4) ranked in descending order by the HEIGHT
attributes, and, fcr those entities whose HEIGHT attributes have equal
value, ranked in ascending order by their WEIGHT attrlbut'!s.
Exasple ()' shovs that omission of the vords HIGH o:r LCW iar•,e,
HIGH. Example (4) shows how ranaings can be ascetdca, ,nc after
another, by THEN BY clauses to ,*solve ties vhen ranking %ttrP-!1tV%
are equal. As many THEN BY clawes car. So used as are .,eded 'n Any
given applicatior. A cosms must precede each THEN BY ,-!ause.
-234-
F. F.
L.
S S.
S. S.
REMOVE takes
from this end
S. 0 S. 0
IJ
-236-
The astute reader will note that while it is possible to delete all
attribuces, doing so completell destroys the concept of a set. The
programmer is cautioned against deleting set attributes without care-
fully considering the consequences (see Table 4-5, page 241).
When required, two or mcre sets having the same properties can
be declared in the same DEFINE statement. A list of set names can
appear after the word DEFINE, and the word SETS used instead of SET.
PERMANENT ENTITIES
EVERY MAN HAS A NAME, AND AN AGE
Main Program:
READ N.MAN
CREATE EVERY MAN
LOOP
Experience has shown that some people would rather write FOR EACH
JOB, rather than FOR I = 1 TO N.JOB even if JOB has not been defined
as a permanent entity. That is, they prefer not to make up a local
variable name (I in this instance) just to step through a sequence of
values from 1 to N (N.JOB in this instance), but would rather use a
name that is easy to remember and has some meaning. To facilitate
this, the phrase
Program Preamble:
Main Program:
READ N.ELEMENT
RESERVE LIST(*) AS N.ELEMENT
FOR EACH ELEMENT, LET LIST(ELEMENT)- 1
In forms (a) the words EVERY and ALL can be used instead
and (b),
of EACH, and the words IN, ON, and AT used as synonyms for OF.
To step backward through a jet, the phrase
IN REVERSE ORDER
is placed after the set name. Set control can range from simple state-
ments such as
Table 4-4
Identification
Control Statement Number Sequence
LET V = F.set
GO TO L.2
'L.1° LET V= L.4
'L.2' IF V- 0 GO TO L.3
ELSE LET L.4- S.set(V)
statement grouv
GO TO L.1
'L.3'
A comparison of this program with that of Sec. P,-O7 reveals that the
two are analogous. The first LET statement picks up the initial item
in the iteration sequence; the statement labeled 'L.2' checks to see
if the sequence has ended; and the statement labeled 'L.1' sets the
control variable to a new vflue for the next iteration. Variations
of the FOR phrase produce variations in this prototype; for example,
writing FOR EACH V FROM W OF set changes the first statement to
LET V- S.8et(W). Adding an IN REVERSE ORDER clause changes the LET
statement following the ELSE statement to LET LA4 - P.aet(V), etc.
The consequences of particular statements within a FOR phrase control
loop can always be determined by constructing the program generated
by the specific FOR phrase and analyzing its relation to the state-
ments involved.
Table 4-5 lists the set attributes that are required for the
different set operations described.
Table 4.-5
±
Following sections dtscribe automatic set diagnostics
performed only when a membership attribute is included.
-242-
PERMANENT ENTITIES
(1) EVERY MAN AND WOMAN OWNS A FAMILY AND HAS
A BANK.ACCOUNT
(2) EVERY CITY,COUNTY,STATE HAS A CENSUS
(3) EVERY MODELCOLORYEAR,MFG HAS A SALES.VOLUME
define compound entities composes of 2, 3, and 4 permanent entities,
respectively. The first defines three two-dimensional arrays:
F.FAMILY, L.FAMILY, and BANK.ACCOUNT, e&ch dimensioned as N.MAN BY
N.WOMAN. The second defines a three-dimensional array CENSUS dimen-
sioned as N.CirY BY N.COUNTRY BY N.STATE. The fourth defines a four-
dimensional array dimensioned in a similar way. Compound entities
are defined by statements of the form
EVERY compound entity name list HAS attribute name list AND OWNS
set plow list.
TEMPORARY ENTITIES
EVERY CHILD BELONGS TO A FAMILY AND HAS AN AGE
DEFINE FAMILY AS A SET RANKED BY AGE WITHOUT N AND M ATTRIBUTES
the variables I and MAU can range from 1 to N.MAN, and the variables
J and WOMAN can range from I to N.WOMAN.
Arrays are allocated to "permanent" compound entities when their
individual entities are created. While it is usual, it is not ncces-
-'y that they be created together. Given the declarations
PERMANENT ENTITIES
EVERY MAN HAS A JOB AND A SALARY
EVERY WOMAN OWNS SOME JEWELRY
EVERY MAN AND WOMAN OWNS A FAMILY AND HAS A
BANK.ACCOUNT
the statement
reserves arrays for the attributes of MAN and WOMAN, and the compound
entity MAN,WOMAN. The CREATE statement is in fact translated into
several RESERVE statements:
RELEASE 8ANK.ACCOUNT
-244-
They cannot be created or destroyed, s& can (and indeed must) the
entities of which they are composed. A routine must be written for
each compound at.tribute (including set pointers) of this type that
accepts the attribite indices as argumants and re:urns a single value --
defined, as in
An i
01 0Y 1dentft-AtIMn rr or atrib:,-. of -omc",r.
-245-
CREATE A SHIP
READ NAME(SHIP), TONNAGE(SHIP),...,SPEED(SHIP)
(1) Declaration:
PERMANENT ENTITIES
EVERY MAN HAS AN AGE
Use:
TEMPORARY ENTITIES
EVERY PROGRAM COWS SCf# LABEL•
EVERY LABEL BEL-OGS To SOWE LABELS
-246-
Use:
CREATE A PROGRAM
PERMANFNT ENTItIES
EVERY CITYSTATE HAS A DOPULATION
Use:
PERMANENT ENTITIES
EVERY BOOK HAS A PAGE.COUNT, A SUBJECT AND AN AUTHOR
-247-
LIST attribute
PERMANENT ENTITIES
EVERY COUNTRY OWNS A FLEET
EVERY SHIP HAS A NAME , BELONGS TO A FLEET
AND OWNS A CREW
TEMPORARY ENTITIES
EVERY MAN HAS A SERIAL.NO, A RATING, A SKILL
AND BELONGS TO A CREW
Use of LIST statements:
PREAMBLE
TEMPORARY ENTITIES
EVERY JOB HAS A LABOR.COST, A MATERIAL.COST,
AN OVERHEAD, A PROFIT, A RANKING FUNCTION
AND BELONGS TO A QUEUE
PERMANENT ENTITIES
EVERY MACHINE OWNS A QUEUE
DEFINE QUEUE AS A SET RANKED BY HIGH RANKING
END
MAIN
READ N.MACHINE CREATE EVERY MACHINE
'NEW.JOB' CREATE A JOB
READ LABOR.COST, MATERIAL.COST, OVERHEAD
AND PROFIT ''INITIAL VALUES''
READ MACHINE ''TO DO THIS JOB
FILE JOB IN QUEUE (MACHINE)
GO TO NEW.JOB
END
LI
-251-
set owned by an entity as the ranking value for that entity's filing
in another set.
PREAMBLE
TEMPORARY ENTITIES
EVERY JOB OWNS A ROUTING, BELONGS TO A QUEUE AND HAS A VALUE
EVERY PATH HAS AN ORIGIN, A DESTINATION, A RANKING FUNCTION
AND A DISTANCE AND BELONGS TO A ROUTING
PERMANENT ENTITIES
EVERY MACHINE OWNS A QUEUE
DEFINE QUEUE AS A SET RANKED BY HIGH RANKING
DEFINE ROUTING AS A SET RANKED BY LOW DISTANCE
DEFINE RANKING AS AN INTEGER FUNCTION
END
STOP
END
This program reads data on auto sales and prices for different
population units, and computes regression coefficients that allow the
following graphs to be drawn:
F-
0ý / .
.LJ
,a.
S 6 NOTE: Fach point
B represents a county
LOCAL.GNP.PERCAPITIA
V I
-253-
w 0
PRICE
MAIN READ N
FOR 1= 2 TO N. DO ''CREATE PRIME NUMBERS''
FOR EACH PRIME IN PRIMES WITH MOD. F(I,VALUE) 0,
FIND THE FIRST CASE
IF NONE, CREATE A PRIME LET VALUE = I
FILE PRIME IN PRIMES
REGARDLESS
LOOP
FOR EACH I OF PRIMES WITH S.PRIMES(1) NE 0,
COMPUTE MAX= THE MAX(1) OF VALUE(S.PRIMES(I))-VALUE(1)
PRINT 2 LINES WITH N,VALUE(MAX),VALUE(S.PRIMES(MAX)) THUS
MAXIMUM GAP AMONG THE FIRST **** PRIMES
OCCURS BETWEEN **** AND ****
STOP
END
-254-
Declaration:
PREAMBLE
TEMPORARY E1TITIES
EVERY ENTITY HAS AN ARRAY
DEFINE ARRAY AS AN INTEGER VARIABLE
DEFINE DUMMY AS A 2-DIMENSIONAL ARRAY
END
Creation:
CREATE AN ENTITY
RESERVE DUMMY(*,*) AS 3 BY N
LET ARRAY(ENTITY) = DUMMY(*,*)
LET DUMMY(W,*) = 0
Use:
U
-255-
Declarations:
PREAMBLE
TEMPORARY ENTITIES
EVERY CITY OWNS SOME OPTIONS. HAS A NAME,
A POPULATION, A STATE AND AN OPTIONAL
FUNCTION
EVERY OPTION HAS A VALUE AND A CODE AND
BELONGS TO SOME OPTIONS
DEFINE NAME AND STATE AS ALPHA VARIABLES
DEFINE WHICH AS A "GLOBAL'' VARIABLE
DEFINE DEFAULT AS A I-DIMENSIONAL ARRAY
END
MAIN
CREATE A CITY
UNTIL MODE IS ALPHA,
CREATE AN OPTION
READ CODE AND VALUE
FILE OPTION IN OPTIONS
LOOP
END
LET X - OPTIONAL(CITY)
if an entity CITY has an entity filed in
its OPTIONS set with CODE - 1, X is set
to the VALUE of the entity
if an entity CITY has no such entity filed
in OPTIONS, X ia set to DEFAULT(1)
I
-257-
CITY
2 0.
97 200
98 10
99 4510
100 -1
Table 4-6
thus has seven routines, A.QUEUE, B.QUEUE, ... , Z.QUEUE generated for
it.
Ranked sets, by their definition, do not permit filing first,
last, or before or after a specific entity without attention to the
specified set ranking. Hence, ranked sets generate four routines,
there being only one file routine.
In addition, certain set operations are impossible if specific
set attributes are not present. For instance, filing before is
impossible in a LIFO set if the predecessor attribute has been deleted.
Tablc 4-7 shows the set attributes that must be present for the
indicated set operations to be performed.
Since all set attributes are not required for all set operations,
Table 4-7 can be used to determinte which attributes to delete in
ord a save memory space. For example, if a program only files
an( oves first, the set attributes L and P can be deleted without
pe t. If they are not deleted, the generated programs keep track
of update them anyway.
pecific set routines can also be deleted to conserve nmemory
s when their associated operations are not used in a program.
S
-259-
Table 4-7
statements. They are used for computing values, rather than for
storing them.
One example of a right-handed SIMSCRIPT II function is OUT.F,
which is used to access characterr in the current output buffer (see
Sec. 3-11). The statement LET A = OUT.F(1), where A is an ALPHA
variable, extracts the first character from the current output buffer
and assigns its value to A. The single character is left-adjusted
within A and followed by blanks.
Defining a function as "left-handed" indicates that it receives
values, rather than that it computes them. SIMSCRIPT II allows the
function OUT.F to be used in both a right-handed and left-handed manner.
LET OUT.F(1)=A takes the leftmost character from the ALPHA variable A
and stores it in the first position in the current output buffer.
Any function can be defined to be used in both a right- ane left-
handed manner, i.e., to compute a value, the right-handed version of
the routine is called; when a reference is made in a left-handed manner,
i.e., to store a value, the left-handed version is called.
No Pew concepts or statements are invclved in the definition of
right-handed routines, for all the functions dealt with thus far have
been right-handed. All of the by now familiar declarative forms
ROUTINE name
ROUTINE name GIVEN argument
ROUTINE name (argument Zist)
indicate that the statements that follow, up to the statement END,
define a computational process, hence, a right-handed function. In
programs that use both right- and left-handed functions, the word
RIGHT may be put before ROUTINE, bt-t this is optional.
A left-handed function is headed by one of the forms of the
ROUTINE statement shown above, preceded by the word LEFT, as in
PREAMBLE
THE SYSTEM OWNS SOME DATA
TEMPORARY ENTITIES
EVERY SAMPLE HAS A VALUE AND BELONGS TO SOME DATA
DEFINE X AS A REAL FUNCTION
DEFINE VALUE AS A REAL VARIABLE
END
MAIN
READ N FOR I=1 TO N, READ X(I)
FOR 1- 1 TO N-1, WITH X(I) <2*X(1+1)
COMPUTE M= AVG, V= VARIANCE, K= NUMBER OF XtO)**2
LIST K,M,V
STOP
END
RIGHT ROUTINE X(I)
DEFINE I,J,S AS INTEGER VARIABLES
IF I > N.DATA.
PRINT 1 LINE WITh I THUS
MEMBER *** OF COLLECTION AX DOES NOT EXIST
STOP
ELSE
IF 1=1, RETURN WITH VALUE(F.DATA)
ELSE LET S=S.DATA(F.DATA)
FOR J= 1 TO 1-2, LET S-S.DATA(S)
RETURN WITH VALUE(S)
END
-262-
Thus far, program names representiag data values have had either
memory locations or programs associated with them. Names defined as
variables referred to values stored in computer words; names defined
as functions referred to values computed or stored by associated
programs.
A new data type, a monitored variable, has both a storage loca-
tion and a program associated with it. The statements required to
define and use monitored variables parallel the statements required
to define variables and functions and to implement left-handed functions.
A variable (or array or attribute) is defined as monitored by a
statement of the form:
ROUTINE EAPLE(I,J)
MOVE TO wuiable
Th? program
ROUTINE EXAMPLE(I.J)
MOVE TO Q
only one preambie card and throwing away two routines; the operational
program is unchanged. However, the program must be recompiled.
PREA14BLE
DEFINE DATA AS A REAL,2-DIMENS.OIWAL ARRAY
MONITORED ON THE RIGHT AND THE LEFT
NORMALLYMODE IS INTEGER
DEFINE MAND N AS VARIABLES
END
MAIN
READ NM RESERVE DATA AS N BY M
UNTIL MODE IS ALPWA,
READ I,J, DATA(IJ)
FOR 1-1 TO N. FOR J-1 TO M, DO
IF DATA(IJ)-O
IF J > I, LEI DATA (IJ) 1
GO TO L
ELSE LET DATA(1,J) . -1
ELSE
'L' LOOP
SKIP 1 FIELD ''THE ALPHA FLAG''
UNTIL MODE IS ALPHA. DO
READ I,J
PRINT 1 LINE WITH IJ, DATA(I,J) LIKE THIS
THE VALUE OF DATA(**,**) IS ******
LOOP
srop
END
ROUTINE FOR DATA(LK)
DEFINE VALUE AS A REAL VARIABLE
" THE FETCHING OF DACA(L,K) IS
"INHIBITED UNTIL THE SUBSCRIPTS ARE
" VERIFIED
IF L < 0 OR L > N OR K < 0 OR K > M, STOP
OTHERW'ISE...
MOVE TO VALUE ''THE VALUE OF DATA(L,K) IS FETCHED
RETURN WITH VALUE
END
PREAMBLE
TEiPORARY ENTT!IIES
EVERY SAMPLE HAS AN XVAL AND A YVAL AND
BELONGS TO A GRAPH
PERMANENT ENTITIES
EVERY SERIES OWNS A GRAPH
DEFINE XVAL AND YVAI AS REAL VARIABLES
MONITORED ON rHE RIGHT
DEFINE GRAPH AS A SET RANKED BY HIGH YVAL WITHOUT
N ATTRIBUTE, WITHOUT FB.FAFL AND RS ROUTINES
NORMALLY. MOVE IS INTEGER
END
MAIN
READ N.SERIES CREATE EVERY SERIES
FOR EACH SERIES, DO
READ N
ALSO FOR I, 1 TO N.DO
CREA-E A SAMPLE
READ XVAL AND YVAL
FILE SAMPLE IN GRAPH
LOOP
FOR EACH SERIES, NOW PLOT.GRAPH
STOP
END
ROUTINE TO PLOT.GRAPH
" ASSUME XVAL BETWEEN 0 AND 132
" ASSUME YVAL BETWEEN 0 AND LINES.V-4
START NEW PAGE
PRINT i LINE WITH SERIES AS FOLLOWS
PLOT OF SERIES NUMBER **
FOR EACH I IN GRAPH, COMPUTE X AS THE MAXIMUM OF XVAL(I)
PRINT 2 LINES WITH XYVAL(F.GRAPH) THUS
X RANGE IS 0 TO '".
Y RANGE IS 0 TO "
SKIP 1 OUTPUT LINE
FOR EACH I IN GRAPH, DO
IF I - F.GRAPH. GO TO 'W' ELSE
SKIP TRUNC.F(YVAL(I)) - TRUNC.F(YVAL(P.GRAPH(1))) OUTPJT LINES
'W' WRITE AS B TRUNC.F(XVAL(I)) + ',I
LOOP
RETURN
END
-267-
LET A = 'SIN.J'
the statement
(b) RELEASE X
releases the routine whose name is stored in X(7). When all the ele-
ments of X are referred to, as in (a) and (b), X itself is the object
of a statement. When a particular element of X is mentioned, as in
(c), an indirect routine reference is implied.
-269-
the clauses
PREAMBLE
DEFINE FUNCTION AS A REAL, SUBPROGRAM VARIABLE
DEFINE K AS AN INTEGER VARIABLE
DEFINE X AS A 1-DIMENSIONAL ARRAY
END
MAIN
READ N RESERVE X(*) AS N
READ X
LET FUNCTION -'EXP.F1
'COMPUTE' FOR I= 1 TC N, COMPUTE S AS THE SLIM,
M AS THE MEAN AND V AS THE VARIANCE
OF iFUNCTION(X(I))
PR!NT 2 LINES WITH S, M AND V THUS
SUM- **.* MEAN= *.*
VARIANCE= *.**
IF FUNCTION: 'EXP.F',
LET FUNCTION- 'SQRT.F'
GO COMPUTE
ELSE
IF FUNCTION- 'SQRT.F'.
LET FUNCT:ON= 'LCG.2G.'
GO COMPUTE
ELSE
STOP END
PREAMBLE
DEFINE FUNCTION AS A REAL, SUJBPROGRAM VARIABLE
DEFINE N AS AN INTEGER VARIABLE
DEFINE X AS A 1-biMENSIONAL ARRAY
END
MAIN
READ N RESERVE X(*) AS N
READ X
CAlL PPOCFSS DATA GIVEN 'EXP.-'
CALL PROCESS.DATA GIVEN 'SQRT.F'
CALL PROCESS.DPTA GIVEN 'LOM.,O.F'
STOP
END
-271-
ROUTINE TO PROCESS.DATA(J)
DEFINE J AS A SUBPROGRAM VARIABLE
DEFINE I AS AN INTEGER VARIABLE
FOR I - 1 TO N. COMPUTE S AS THE SUM,
MAS THE MEAN AND V AS THE VARIANCE
OF $J(x(1))
PRINT 2 LINES WITH S, MAND V THUS
SUM- **.* MEAN- **
VARIANCE- *.*
RETURN
END
(3) SUBPROGRAM mode variable used for program c-"itrol.
PREAMBLE
DEFINE ROUTER AS A SUBPROGRAM VARIABLE
DEFINE DATA AS A REAL, 1-DIMENSIONAL ARRAY
DEFINE STOCK AND BORROW.BIN AS VARIABLES
END
MAIN
RESERVE DATA(*) AS 3
LET ROUTER- 'INPUT'
'A' CALL ROUTER
LIST DATA, STOCK, BORROW.BIN
IF ROUTER = 0, STOP
ELSE GO TO A
END
ROUTINE INPUT
READ DATA
iF DATA(1) = 0 LET ROUTER= 'RECEIPT'
ELSE LET ROUTER= 'SHIPMENT'
RETURN
END
ROUTINE RECEIPT
ADD DATA(2)-1 TO STOCK
ADD 1 TO BORROW.BIN
LET ROUTER= 'INPUT'
kLTURN
END
ROUTINE SHIPMENT
IF DATA(2) < STOCK,
SUBTRACT-hATA(2) FROM STOCK
PERFORM SHIPPING.NOTICE
LET ROUTER- 'INPUT'
RETURN
ELSE LET ROUTER. 'BORROW'
RETURN
END
-272-
ROUTINE SHIPPING.NOTICE
PRINT 1 LINE WITH DATA(2), DATA(3) THUS
SHIP *** UNITS TO CUSTOMER ****
RETURN
END
ROUTINE TO BORROW
LET DIFF = DATA(2) - STOCK
IF DIFF < BORROW.BIN,
ADD DTFF TO STOCK
SUBTRACT DIFF FROM BORROW.BiN
LET ROUTER= 'SHIPMENT'
RETURN
ELSE PRINT I LINE WITH DATA(3) THUS
CAN NOT FILL ORDER FOR CUSTOMER *
IF DATA(3) > 10,0
LET ROUTER= 0
RETURN
OTHERWISE
LET ROUTER= 'INPUT'
RETURN
END
column number
00000000011111111112222222222333
12345678901234567890123456789012
ANTIDISESTABLISHMENTARIANISM IS
READ variable AS T e
Since more than one TEXT variable can point to the same text data,
the ERASE statement must be used with care. The following few state-
ments show why care is necessary.
ERASE NAME
can be used like any other FOR phrase to control a program's operat~o~s.
Each TEXT variable has an INTEGER attribute whose value is Zhe
number of characters contained in the variable. Each declaration
WRITE variable AS T e
write output on the current output unit, starting at the column ptinted
to by the current output pointer. More than one line is printed if
the expression e requires it.
Statements of the form
Table 4-8
TEXT TTOA.F
MAIN
READ N RESERVE SENTENCE(*) AS N
LET LET MARK.V= "."
FOR I= I TO N, INPUT SENTENCE(I)
'ANOTHER' FOR EACH I IN THE DICTIONARY,
COMPUTE MAX= THE MAXIMUM(1) OF LENGTH.A(1)
IF MAX= OSTOP
OTHERWISE
OUTPUT, SENTENCE (MAX)
ERASE SENTENCE (MAX)
GO TO ANOTHER
END
(2) This program reads a deck of name cards, in which names are
punched in the form first name bian.k last cine, and counts the number
of cccurrences of different names:
PREAMBLE
DEFINE FIRST AND LAST AS TEXT VARIABLES
NORMALLYMODE IS INTEGER
END
MAIN
'READ' IF DATA IS ENDED,
PRINT 1 LINE WITH JOHNGREGSMITH,HH THUS
COUNTS ARE *** *** *** **
STOP ELSE
READ FIRST AND LAST
IF FIRST EQUALS IJOHNI, ADD I TO JOHN
ELSE
IF FIRST EQUALS I GREGORY!. ADD I TO GREG
ELSE
IF LAST EQUALS 1SMITHj, ADD 1 TO SMITH
ELSE
IF CONCAT.F(FIRSTLAST)- 1 HORATIOHORNBLOWER!
ADO 1 TO HH
ELSE GO READ
END
PREAMBLE
TEMPORARY ENTITIES
EVERY JOB HAS A DESCRIPTION, A PRIORITY, A
DUE.CDATE AND MAY BELONG TO A QUEUE
-278-
END
MAIN
END
I is 4n INTEGER variable
T is a TEXT variable
koutine definition:
PREAMBLE
TEMPOPARY ENTITIES
EVERY MAN HAS A NAME,AN AGE AND A SALARY AND BELONGS
TO A GROUP
DEFINE NAME MND N AS TEXT VARIABLES
THE SYSTEM OWNS A GROUP•
END
MAIN
LET MARK.V-"
'BACK' READ N
IF N NE I DATA GROUP ENDED ,
CREATE A MAN
LET NAME - N
READ AGE AND SALARY
FILE THIS MAN IN GROUP
GO BACK
ELSE
START ,EW PAGE
PRINT 2 LINES WITH N.GROUP AS FOLLOWS
THIS GROUP CONTAINS "** PEOPLE
NAME AGE SALARY
FOR EACH MAN IN GROUPDO
REMOVE THE MAN FROM THE GROUP
WRITE NA.EAGE AND SALARY AS 9 15, T 25, 2 I 10
ERASE NAME
DESTROY MAN
LOOP
IF DATA IS ENDED, STOP
ELSE GO BACK
END
I
-280-
Table 4-9
Chapter 5
SIMSCRIPT I: LEVEL 5
5-00 INTRODUCTION
Unlike Levels 1 through 4, which present a rather general pro-
gramming language, Level 5 provides concepts and programming features
for a specific applications area, discrete-event simulation. Readers
unfamiliar with this subject are advised to read any one of a number
of current texts or P. J. Kiviat, Digital Computer Simulation:
Modeling Concepts, The RAND Corporation, RM-5378-PR, August 1967.
While some methodological comments are made in this section, it is
not intended as a text, and will most likely prove unsatisfactory to
persons unfamiliar with the subject. Readers who have done simula-
tions, and particularly those who have used a simulation programming
language, should haie no difficulty following the section without
additional preparation.
Simulation as we deal with it is the use of a numerical model
of a system to study its behavior as it operates over time. Dis rete-
event simulation deals with models whose entities interact with one
another at discrete points in time, rather than continuously. This
section presents concepts and statements designed to aid in modeling
systems and in programming them so that they can be simulated. Its
organization reflects subject areas that are Important to this task:
Typical activities
-283-
activity
event
timing routine
simulation clock
event scheduling in simulated time
instantaneous charges of system state
In Fig. 5-1 two jobs are started and ended at different times
to illustrate the concepts of event occurrence and event scheduling.
Job, activity
-Job2 activit4
Simulated
time
START.JOB 1 END.JOB 1
START.JOB 2 END.JOB 2
Job, activity
Job., activity
START'JOB 2 END'4008 2
I .. I ,._
Simulated time
I II
START.JOB1 END.JOB1
START.JOB 2 END.JOB2
Table 5-1
while EXTERNAL events are fed to a model from a data source (a mag-
netic tape or disk, or punched cards). Generally, EXTERNAL events
provide stimuli to a model and INTERNAL events react to them.
Event Declaration
EVENT IS ?,•r:i or
EVENT IS NOT 'rt
as in the statements
-288-
Internal Events
EVENT NOTICES
PREAMBLE
EVENT NOTICES INCLUDE ARRIVAL, WEEKLY.REPORr AND END.SIm
EVERY JOB.OVER HAS A NEXT.JOB AND OWNS SOME RESOURCES
When created, records for these event notices look like
Section 5-0-2 describes how event notices are created and ,•sed.
It is sufficient at this poiit that the reader understand rt at they
are created and destroyed like temporary entities, and uied by the
SISCRIPT II timing routine to organize the execution of events in
proper time sequence.
The reader bhould also understand at this point that it it pos-
sible to have many e¢ents of the saga kind scheduled to occur at thm
saw* or different times in the future. 'or esmpl*, a machine-shop
,imulation having an zvvnt END.J0" that signals th,ý completion of a
machining operation and cdarges the state of the simulated systct
vhf.a job is completed, can have many EN4.JOB events sche'uled and
held in abeyance by the timing routine. Thnese events are usually
scheduled to take plac- at differe-r times, and the ttiing routine
-290-
gives priority to the event with the high (low) attribute value when
two or more event notices of the same type have the sae event time.
The attcibutes are, of course, ones that have been defined in EVERY
statements for the event named. In cases where more than one set of
tie-breaking attributes are needed, clauses of the form
EVENT NOTICES
EVERY ARRIVAL HAS A VALUE, A DUE.DATE AND A PRIORITY
at the samw simulated time and having identicalc PRIORITY values, the
notice with the smallest DUE.DATE vill occur first. And similarly
for (c) and other variations.
Conflicts between different kinds of events are of similar impor-
tance. It often happens that several different events are scheduled
for the same time, as for example, the arrival of a job, the comple-
tion of a task, and the preparation of a management report. Resolviag
these conflicts is Important in situations where events compete for
the same resources or have som effect upon one another. A statement
of the form
places an cidering upon the events named so that in cases where event
notices of different kinds have the same event time, the event notice
of the higher-priority event type is selected first. Priority in
this case corresponds to position in the PRIORITY statement; the first
event named is given the highest priority. If no PRIORITY statement
appears in a program, events are given priority in the order in which
they appear in the preamble, in either INCLUDE or EVERY statements.
If only a subset of the events of a program are listed in a PRIORITY
statement, the remaining events are given lower priority than the
ones listed, and are ranked among themselves in the order in wh!ch
they appear.
The folloving preamble illustrates the use of BREAK TIES and
PRIORITY statements in a typical simulation program:
PREAMBLE
EVENT NOTICES INCLUDE END.OF.JOS AND SHIFT.CHANGES
EVERY CAR.ARRIVAL HAS A VALUE AND AN IDENTITY
EVERY TRUCK.ARRIVAL HAS A LOAD.WEIGHT AND A DENSITY
EVERY START.J06 HAS A VEHICLE AND A CREWSIZE
BREAK CAR.ARRIVAL TIES BY HIGH VALUE
BREAK TRUCK.ARRIVAL TIES BY LOW DENSITY, THEN BY HIGH LOAD.WEIGHT
BREAK START.JOB TIES BY LOi CREWSIZE
PRIORITY ORDER IS TRUCK.ARRIVAL, CAR.ARRIVAL, START.JOB, END.OF.JOP,
SH I FT. CHANGE S
DEFINE IDENTITY. LOAD.W[EGHT, AND CREWSIZE AS INTEGER VARIABLES
DEFINE VEHICLE AS AN ALPHA YARIABLE
END
-292-.
External Events
word 1 TIME.A
word 2 EUNIr.A
word 3 P.EV.S
word 4 S.EV.S
word 5 M.EV.S
The first, third, fourth, and fifth attributes have the same
meaning as in the preceding subsection; the second attribute contains
the numuer of the input unit on which information about the event is
contained. External event input units are c'lfined in a statement of
the form:
priorities.
Events that occur both internally and externally can be give"
priority over other kinds of events but cannot be ranked among them-
selves by a BREAK TIES statement. As only the internally generated
event notices have ranking attributes, the externally triggered event
notices compete with them on a first-come, first-served basis.
START SIMULATION
MAIN
Iocal declarations
initialization of entities, attributes
and sets
initialization of events
specification of external event units
START SIMULATION
control statements
END
events with BREAK TIES conditions are put into their proper sets by
routines named C.event; internal events not named in BREAK TIES state-
ments, and external events, are put into their sets by a routine named
A.EV.S, which is the standard FILE routine for the set EV.S.
Each event has a global variable I.event associated with it that
denotes the subscript value of the event class in the subscripted
events set. In a program without a PRIORITY statement, values are
assigned to these variables in ascending order as event names appear.
When a PRIORITY statement is used, values are assigned in the order
in which events appear in the statement. An example illustrates these
points:
Preamble:
Ir._ _
-296-
and remove the first event or a specific event from a set, The routine
C.START.JOB is generated to file event notices in EV.S (I.START.JOB)
according to the rankings specified in the BREAK TIES statement.
Simulation event control is maintained in the following way:
(a) Every time an internal or external event is scheduled it is
filed in its proper set. Events are filed in their set* in the order
in which they are to be executed, i.e., the event with the smallest
event time is filed first.
(b) When control returns to the timing mechanism from an event,
or from the main progr.am, the next event to be performed is selected
by taking the event with the smallest event time "rom its set. This
is done by searching the event sets in the order specified by their
I.event variables, and keeping the identification of the event notice
with the smallest event time. By doing this, two events of the same
class will have their tie resolved by the ranking within the set, and
two events of different classes with the same event time will have
their tie resolved by keeping the identification of the first one
found.
Figure 5-2 pictures the way the events of the above preamble are
organized. Normally, a programmer does not deal with the set EV.S
directly, or with the variables F.EV.S, P.EV.S, S.FV.S, M.EV.S. TIME.A,
and EUNIT.A. He inserts events into the event sets with soecial state-
ments and data inputs, and has them removed from the sets automatic-
ally. When an event is removed, its event time TIME.A is transferred
to the simulation clock TIME.v, becoming the updatet simulation time,
and control is transferred to the event routine.
We have shc,%n how an event notice is taken fro? its event set by
0 0
t.
--------- 4
7 It
where event is the global variable associated with the entity class.
One can just as easily write a SCHEWLE statement with a different
variable nme, as in
If an event notice already exists (it may have been created pre-
viously), one can specify that it be used in a SCHEDULE statement by
using the word THIS rather than AN. as in
EVENT NOTICES....
EVERY START.JOB HAS A VALUE. A DUE.DATE AND A PROCESS.TIME
AND BELONGS TO A ROUTING.SET
word 1 TIME.A
word 2 EUNIT.A
word 3 P.EV.S
word 4 S.EV.S
word 5 M.EV.S
word 6 VALUE
word 7 DUE.DATE
word 8 PROCESS.TIME
word 9 P.ROUTING.SET
word 10 S.ROUTING.SET
word 11 M.ROUTING.SET
AT 0.00
AT TIME.V + 1.5
IN C'S33 DAYS
IN iri:z,,e:, • e-rta y' MINUTES
IN u-k:,. so': HOURS
wants to know, not what absolute tiiw it is, i.e.. the vialue of
TIME.V. but what day of the week. hcur of the current aimulated iar.
or minute of the current si1~ilated hour it Is. T1hree svst. fuunct Ionse
described in Tabl-e 5- prov4,! thiq ,apabilitv.
-302-
Table 5-2
Function
Name Argument Mode Function Values Examples
In the preamble:
RESERVE WEEKDAY(*) AS 7
READ WEEKDMY
Daca card:
MONDAY TUESDAY WEDNESDAY THURSDAY FRIDAY SATURDAY
SUNDAY
NOW or
NEXT
in statements such as
model. The reader should reviev this section to make sure he under-
stands the concepts of:
?rwa!ýn ým event ,t'-
Events are triggered externally by event data cards that are read
in chronological order from external event input devices. An event
card contains the name of an event, the time at which it is to occur,
and optional data, which can be continued on subsequent cards. The
cards are read one at a time, their information recognized and deci-
phered, and event notices created for the events they represent. This
section deals with two issues: the operations performed by SIMSCRIPT II
when external event cards are read, and the format of external event
data cards.
Whean a START SIMULATION statement is recognized, one of the first
tasks performed is reading information about the first event named on
each external event device. The system schedules the first event on
each device and initializes the reading mechanism for subsequent ex-
ternal event triggers. When an external event data card is read, the
event class is recognized and the event time computed from data on
the card. An event notice named event is created, and the event time
and number of the unit from which the event card was read are stored
in the TIME.A and EUNIT.A attributes of the notice.
If the event is of a class that can only be triggered externally,
the event notice contains the five standard event attributes. If it
can also be triggered internally, the notice conforms to the preamble
declaration for the event class, i.e., it might have five words, or
six, or eleven.
After TIME.A and EUNIT.A are specified, the event notice is filed
in the set that corresponds to the event class. Internally and
I.
-305-
externally generated evcnt notices are filed together. They are dis-
tinguished by the coding of EUNIT.A. If EUNIT.A has a special code
value, usually zero, an event notice represents an internally generated
event. Otherwise it represents an externally triggered event and
EUNIT.A is the number of the device from which the external event card
was read.
The format of an external event card is:
The event name and event times are read in free-form by the SIM-
SCRIPT II system. Event data are punched in whatever format a pro-
grammer finds convenient. The MARK.V symbol is used by the system to
advance properly from one set cf external event data to another. As
data for an event can be on many cards, and a program can leave some
data unread, the SIMSCRIPT II system must have a way of advancing to
the start of a new set of event data when it receives a signal to
read in the next external event trigger.
The three formats in which event time can be stated are:
Dac-Hour-Minute format
ARRIVAL 1/15/69 05 35 *
ARRIVAL 14 05 35 *
ARRIVAL 476.2 *
ARRIVAL 4/17/1960 00 00 *
END.OF.SIMULATION 1000.0 *
SALE 5/10/66 12 00 YOYO 15 2.3 1 1 2 *
SALE 5/11/66 12 30 TOP 22 19.6 2 2 4 *
PURCHASE 500.00 MAGNETIC SOLENOID* 22.50 *
PURCHASE 750.00 RESISTOR* 1.50 *
PURCHASE 750.00 CATHODE RAY TUBE DISPLAY DEVICE* 600.00 *
Before the calendar format can be used, the calendar date of the j
start of simulation must be set to provide an origin against which
calendar time specifications can be compared. This must be done before
the START SIMULATION statement is executed. The origin is set by
executing a statement of the form
CALL ORIGIN.R(INTEGER month expression,INTEGER day expression,
INTEGER year expression)
as in the statements:
Four functions are provided to convert year, month, and day ex-
pressions into cumulative simulation times and vice versa. These
functions are described in Table 5-3. As they all depend on a simu-
lation time origin, ORIGIN.R must be called before they can be used.
Table 5-3
Function
Name Arguments Mode Function Values Example
EVENT ARRIVAL
DEFINE X AND Y AS INTEGER VARIABLES
READ X AND Y AS B 20, 2 I 5
RETURN
END
External event data card
00000000011111111112222222222333333333344444444445
12345678901234567890123456789012345678901234567890
ARRIVAL 525.30 1234512345
PREAMBLE
EXTERNAL EVENTS ARE ARRIVAL AND COMPLETION
EXTERNAL EVENT UNITS ARE 5 AND 7
DEFINE X AS AN ALPHA VARIABLE
END
MAIN
READ N '' THE NUMBER OF EXTERNAL EVENTS TO SKIP
FOR 1=1 TO N, DO UNTIL X="*", READ X USING 5 LOOP
START SIMULATION
END
PREAMBLE
EVENT NOTICES INCLUDE Al, A2,..., AN
END
MAiN
USE UNIT 6 FOR INPUT
CAVL EXTERNAL
START SIMULATION
STOP
END
ROUTINE EXTERNAL
DEFINE V AS AN INTEGER VARIABLE
UNTIL V="*, READ V AS BINARY
READ EVENT.CODE AND TIME AS BINARY
GO TO L(EVENT.CODE)
'L(1)' CAUSE AN Al AT TIME
RETURN
'L(2)' CAUSE AN A2 AT TIME
RETURN
EVENT Al
READ event data Ziet AS BINARY
CALL EXTERNAL
RETURN
END
EVENT AkRIVAL
CREATE A PERSON
READ NAME(PERSON) AND DESTINATION(PERSON)
LET ARRIVAL.TIME(PERSON) - TIME.V
FILE PERSON IN INTRANSIT(DESTINATION(PERSON))
RETURN
END
EVENT ARRIVAL GIVEN NAME AND DESTINATION SAVING THE EVENT NOTICE
EVENT ARRIVAL(NAME,DESTINATION)
DEFINE NAME AND DESTINATION AS INTEGER VARIABLES
!F EVENT IS INTERNAL, GO AROUND
OTHERWISE READ NAME AND DESTINATION AS B 20, 2 I 10
'AROUND' rest of event program
RETURN
END
MA IN
RELEASE SEED.V(*)
READ N RESLRVE SEED.V(*) AS N
READ SEED.V
START SIMULATION
END
RANDOM.F can be used in IF and WITH statements for decisionmaking,
as in these examples:
Table 5-4
Function
Name Arguments Mode Function Value
EVENT ARRIVAL
statements to process an arrival
SCHEDULE MN ARRIVAL AT TIME.V + EXPONENTIAL.F(MEANp1)
RETURN
END
(b)
Same as (a) but the number of units that arrive is assumed
to have a Foisson distribution with mean 5.
r
r
r r
i2 + - r ; that is, any point (ij) with i < r and j !.r and
i
2 ++ J < r 2 lies inside a circle of radius r. The area of the circle
2
not. in fact, the proportion of those falling within the circle will
be approximately iT/4 of all the points. If M is the total number of
those that fall within the circle, then M/N is approximately equal to
7r/4. We can estimate the value of w as 4M/N. The accuracy of this
estimate aitproves as N ii.creases, and is proportional to Y9.
This program uses the function UNIFORM.F to generate points (i,j)
that are rarndnmly distributed within a square of side R. It does this
by generging random numbers between 0 and R and assigning them to
i and j. lhc, point (i,j) is somewhere inside the square.
If 2 + j 2 < r 2 then the puint also lies within the circle and 1
is added to M to tabulate this fact. This procedure is repeated N
times. Each time, a different i Pnd j are generated and used to
determine if the point (ij) lies within the circle.
At the end of N point generations, the approximation to w is
printed.
ROUTINE nmne(index)
RETURN WITH function(F.na'ne(index), stream number)
END
ROUTINE SAMPLE(JOB)
DEFINE JOB AS AN INTEGER VARIABLE
RETURN WITH LIN.F(F.SAMPLE(JOB),6)
END
RANDOM variables can only be read and sampled; assignments cannot
be made tc them.
Sampling is alwsys done automatically; from a programmer's point
of view a RANDOM variable acts like a right-handed functica.
Because of the special storage assigned to RANDOM variable sample
-320-
(A) Definition
Input statement:
READ WORDS
Input data:
4____
-321-
•[ 10 25_40
S0.8 1.0
150 200
0
Use of WORDS:
(B) Definition:
READ WORDS
Input data:
Debugging
Table 5-5
BE FORE AFTER
tNot allowed.
i•In FILE BEFORE and FILE AFTER statements, the second
entity identification nuzbtr is not GIVEN.
itttBy definition, the entity identifica:lon GIVEN for a
REMOVE FIRST or REMOVE LAST is zero.
Preamble:
Routine:
-324-
Analysis
fied. Table 5-6 states the cases in which additional routines and
attributes are generated.
Table 5-6
TALLY ACTIONS
Some examples illustrate the usa of the TALLY statement and the
attributes and functions generated by it:
Preamble:
PREAMBLE
DEFINE X AS A REAL VARIABLE
TALLY M AS THE MEAN AND V AS THE VARIANCE OF X
END
Preamble generates:
Preamble:
PREAMBLE
PERMANENT ENTITIES....
EVERY MAN HAS SOME CASH. IN.POCKET AND OWNS A FAMILY
END
Preamble genermates:
-327-
PRFA.BLE
TEMPORARY ENTITIES
EVERY JOB HAS A NUMBER.OF.OPERATIONS
ENC
In progiam:
Preamble genterates:
Table 5-7
Statistic Counters
MEAN xi, N
2
MEAN.SQUARE x2, N
VARIANCE x, x2 N
2
STD.DEV x x,, N
defined:
Symbol Meaning
TL The simulated time an ACCUMULATED
variable was set ta its current value
T0 The simulated time at which
ACCUMULATION starts
Table 5-8
TALLY ACCUMULATE
NUMBER N N
SUM [ X [ X*(TIME.V - TL)
SUM.OF.SQUARES [ X X2 *(TIME.V - TL)
MEAN SUM/NUMBER SUM/(TIME.V - T0 )
MEAN.SQUARE SUM.OF.SQUARES/ SUM.OF.SQUARES/(TIME.V - T0 )
NUMBER
VARIANCE MEAN.SQUARE - MEAN.SQUARE - MEAN
MEAN
STD.DEV SQRT.F(VARIANCE) SQRT.F(VARIANCE)
MAXIMUM Largest X Largest X
MINIMUM Smallest X Smallest X
"PREAMBLE
PERMANENT ENTITIES....
EVERY MACHINE HAS A STATUS, A PROCESSING.SPEED
AND OWNS A QUEUE
TEMPORARY ENTITIES....
EVERY JOB HAS A VALUE AND BELONGS TO A QUEUE
ACCUMULATE AVG.QUEUE AS THE MEAN AND MAX.QUEUE AS
THE MAXIMUM OF N.QUEUE
ACCUMULATE MACHINE.STATE AS THE MEAN OF STATUS
END
L 4 -- 1
3 -
042 - a
0 DD
0 2 4 6 8 10 12 14 16 18
Simulated time in decimal days
Table 5-9
ACCUMULATE COMPUTATIONS
0 0 1.2 1.2 0 0
1 1.2 3.0 1.8 1.8 1.8
3 3.0 4.6 1.6 4.8 6.6
2 4.6 6.1 1.5 3.0 9.6
3 6.1 8.0 1.9 5.7 15.3
4 8.0 8.3 0.3 1.2 16.5
5 8.3 11.2 2.9 14.5 31.0
2 11.2 12.4 1.2 2.4 33.4
1 12.4 14.1 1.7 1.7 35.1
0 14.1 17.1 3.0 0 35.1
1 17.1 18.0 0.9 0.9 40.0
added to none 2 (2), etc. To get the average value of a variable over
the life of a program and the distribution of values it has at dif-
ferent times, one writes:
PREAMBLE
DEFINE VAL AS A REAL VARIABLE
TALLY AVERAGE AS THE MEAN AND FREQ(O TO 100 BY 5) AS THE HISTOGRAM OF VAL
END
Whenever VAL changes, observations are summed to provide data for com-
puting AVERAGE, and counts are made in 21 interval counters that indi-
cate the number of times VAL is between 0 and 5-, 5 and 10-, 10 and
15, etc. If a value is less than rI it is counted in the first cell;
if equal to or greater than r 2 it is counted in the last cell.
Compilation of histograms for global variables, system attributes.
and attributes of permanent entities generate histogram arrays of one
more dimension than the variables themselves. This dimension is for
the histogram array, which is reserved by the system automatically
in the following places:
PREAMBLE
PERMANENT ENTITIES....
EVERY MACHINE HAS A PROCESSING.SPEED AND A STATUS AND
OWNS A QUEUE
TEMPORARY ENTITIES ....
EVERY JOB HAS A VALUE AND BELONGS TO A QUEUE
ACCUMULATE MEANQ AS THE MEAN OF N.QUEUE
ACCUMULATE STATE.PROBS(O TO 2 BY 1) AS THE HISTOGRAM OF
STATUS
" POSSIBLE VALUES OF STATUS ARE"
"STATUS=O MACHINE IDLE''
"STATUS-I MACHINE DLE BUT COMMITTED"
" STATUS=2 MACHINE ENGAGED''
END
Periodic events would then print the relevant statistics daily and
weekly, and reset the appropriate counters by the statements:
PREAMBLE
DEFINE V'R AS A REAL, 1-DIMENSIONAL ARRAY
rALLY MAS THE MEAN OF VAR
FND
MAIN
READ N RESERVE VAR(*) AS N
FOR 1-1 TO N, RESET TOTALS OF VAR(1)
READ VAR
CALL MANIPULATE GIVING VAR
LIST VAR,M
STOP
END
ROUTINE TO MANIPULATE GIVEN ARRAY
DEFINE ARRAY AS A REAL, 1-DIMENSIONAL ARRAY
DEFINE I AS AN INTEGER VARIABLE
FOR 1-1 TO DIM.F(ARRAY(*)), WITH ARRAY(1)1-O,
LET ARRAY(I) = ARRAY (1)**2
RETURN
END
The values of VAR are changed within MANIPULATE ',jt under the
name ARRAY. Tallying cannot take place.
A final note on analysis has to do with minimizing storage require-
ments for computations of statistica! qu;ntjl.es. The reasons for
wanting to do so are brought out In the following example:
PREAMBLE
PERMANENT ENTITIES.
EVERY MACHINE OWNS A QUEUE
TEMPORARY ENTITIES..
EVERY JOB BELONGS TO SOME QUEUE. AND HAS A VALUE,
A DUE.DATE AND A LATENESS
EVENT NOTICES INCLUDE ARRIVAL AND STOP.SIMULATION
EVERY END.JOB HAS A JOB AND A NEXT.JOB
TALLY AVG.LATE AS THE MEAN OF LATENESS
-3I5-
END
The System
Production
Center,
Production
Center2 Center3
1
Center4 " Lcenter.,
Production Production
machines, and a finished goods inventory storage area. The shop pro-
duces P standard prod&cts for local sale avd distribution, and varia-
tions of t'.te standard products for local and export distributors. Each
product ordered goes through the shop, undergoing processing at produc-
tion centers according to standard routings, production times, and p'-
duct expediting procedures.
Each production center has an in-process inventory area where pro-
ducts in process are stored if they cannot be processed when they arrive
at the center. The production rules of the shop, iai order to minimize
the -value of in-process inventory, always remove partially completed
products from production center queues according to their value.
Table 5-10 shows the entity-attribute-set model of the shop and
its product line.
Aside from the attributes required to accumulate system performance
data, table 5-10 shows the entities, attributes, and sets needed to de-
scribe the static structure of the shop. Permanent e-ntities are used
for production centers and product descriptions, which are fixed in num-
ber. Tcmporary entities are used for jobs and for job processing speci-
fications, which are variable in number. Before going on, the reader
should make sure he understands this characterization of the system.
-338-
Table 5-10
PREAMBLE
NORMALLY NOPE 16 INTEGER AND DIMENSION IS 0
PERMANENT ENTITIES..i..
EVERY PRODUCT PAS A SALIES.FREQUIENCY AND A, NANE AND OWNS A STRUCTURE
WRINE SALES.FREGUENCV AS A REAL RANDOM LINEAR VARIABLE
OEFfINE NAMIE AS AN ALPHA VARIABLE
EVERY PRODUICT.PRODUCT HAS A PROOMCT.SALEStSO/Z
EVERY PRODUCT 1ON.CENTER HAS A (MAX* IN.QUEUIE 4 1121AXe QUEUE 121211 IN ARRAY Is
A (IWNUNI41/21, NNU2I2l) IN ARRAY 29 A WhiM. I MS*JMv A NUNBER.IDLE
A0D OWNS A QUEUE
DEFINE NUNBER.IDLE AS A VARIABLE MOMIT'!R&O ON THE LEFT
TEMPORARY ENTITHiS..o...
EVERY JOG HAS A VALUE IN WORD 2, A OUE.DATE. AN AIRIVAL.TINEt
AN EXPEOITE.FACTOR FUNCT:ON@ MAYBELONG TO A C'EUE. OWNS A RO6tING
AND NAY BELONG TO THE WA9TING.SET
DEFINE EXPEDITE.FACTOR AS A REAL FUNCTION
DEFINE VALUE* OUE.DATI AND ARRIVAL.TINEI AS %*AL VARIABLES
DEFINE ROUTING AS A FIFO SET WITHOUT P ANC N ATTRIBUTES
DEFINE QUEUE AS A SET RANKED BY HIGH VALUE
EVERY OPEIIATION HAS A I CODEIL/2) AND NACHINE.OESTINGDI2/2) I INtWORD I
AND A PROCESS#TXNE AND BELONGS TO A STRUCTURE AND A ROUTING
DEFINE STRUCTURE AS A SET RANKED BY LOW COPE WITHOUT N ATTRIBUTE
AND WITHOUT R ROUTINES
DEFINE PROCESS.TINE AS A REAL VARIABLE
MAIN
OINIT1ALIZIo PERFORM INITIALIZATION
LIET OrElTUEEN..VoTRAC1o START SIMULATION
60 IN1IIALIlE
STOP IWO0
RADi N.PROSUCTION.CENTER
CREATE EVERY PRDOuCTIONACINTIR
FOR EACH PROOUCTIO11.CENTER.t READ NUNSELIOLE01.1
READ N.PROOUCT
CRERvu EVERY PRODUCT
RESERVE PRIMRITY.PREOUENCYloo*l AS NI.PROh)UCT IITS
FOR GACO PRODUCT. DO
READ NAPE
READ SALES.FRIOUEUCY
RESERVE FR EON ITY.FREUOENCVIPROIIUCT94I AS PRODUCT
FOR li' TO PRODUCT. READ PRIlORITYbFPPfU2UNCYIPftDUCTvII
UNTIL 140SE IS ALPHA. 00OTHIS.....
CREATE All OPERATION
FILE THE OPERATION IN STRUCTURE
READ COOlo XACHINE.OCSTINED AND FIOCESS.TIME
LOIP
SKIP & FIELD
CAUSE A SALE IN SF "OURS
LET PFOOUCT.TVPlsPROOUCT
LET PRICEsPROOUCTORAINWO.FiII
LET PNIORIT~sPFUPARDUUCT. TRUNC.PFIPI""Ill
LOOP
II
ALE RETURN
OTHERWISE.....
SCHEEWLE THE M#LIFsODUCT. PpIRADMFI.PAIDWIIY.FREooENCYIPROCIUCT.
REUR 0"C
ROUTINEl To [email protected]
ROUTINE EEPED1IT.PACIom
IP TINA.V IS GRIAVE! IthAN DUE.OATE RETURN WITH 0.5 ELME
RETURN WITH NINJPIF.,-i:,)POCSSTNE1
IF NVew IS EMPTY,
ADD I TO NUINSER10.IO RVTURN
LSE REMOVE THE PIRST JEPOOP SUIEUE
PERPORM ALLOCATION RETURN
INC
ROUTINE TO TRACE
LOCAL
It PINIS4119*001S.INVENTORV IS EMPTYp. SO AROUIND
ELSE FOR EACH dOE MNPNSE.OO.NET UNTIL DUE.OATE 31 TINE.Vo 00
me"OVE To Joe PROM FlatsMES.GO0oSIN"""TORY SESTROY THE JOG
LOOP
SO VS E01.0.PSKIESS9 SAL@* UEINGY.REFPORV AND 101NS.5P.ILATION PER 1V1NV.V
I,*ENOFW.PRocisso WRITP ITEM PRODUCER* TINE.V AS 61IP~oo I So 'STOPPEO.
'PROCESSING, ONMNACHINE*# I S. 0 AT TINE".OIIO.31s I
RETURN
'SALE0 UNITI TSNE.Ve PWOOC.TVPE. PRICE AMWPRIO&ITY AS OSALE OF TYPE', I So a
0 MROOUT AT VINE.'. 0490.3). a FOR lot DIG 1),* aPRIORITYO"s I so
I RETURN
'WEERLYdREFUTO
&I TV" .3~ VNN
-345-
ROUTINE To REPORT
LOCAL
IF TIXEoVmOv
START NE0 PAGE 90AND0 OUTPUT TITLE
SKIP 2 OUTPUT LINES
PRINT 3 LINES AS FOLLOWS
FPA 0D '1C 1 D AT A
"HAME SALES FREQUENCY PRODUCTION SEQUENCE
PORS. VALUE CODE CTRm TINE
FOR EACM PRODUCT. Do
LET I.F.SALEIVFREQUENCY
LET J.F.SWRIJCTURE
PRINT I LINE WITN NANE. PROS.AIII, RVALUIa.AIII, CODEIJI.
NACHINEODESTINED(JI AND PROCESSOTINIIJ3 THUS
5,05 0.00 0 *04 **
IF 1-00t LET IoS.SALF~afR6GENCV4I1 ELSE
IF J-%449 LET JOS.STRUCTUR4IJ MELS
If Ioll AND JwO. GO TO OLOOPQ ELSE
If Ift.O AND JwOp PRINT I LINE WITH PROS.AgII AND RVALUE.AiII THUS
ELSE IF IoG ANM J..D. PRINT t LIONE WITH CIDEIJI. PACNINE.DEDSTINEDIJit
AND MMICSSTNel'IJI,1 THUS
"0 0.00
00
ELSE If [email protected] PRINT I LINE WITH PROS.AIII. RVALUI.AIII. CODEIJ1,
NACNINEMOSTINEDIJI AND PROCISS.TINEIJI THUS
06*0 0.00 00 00 0.00
OLOSP LOOP
SKIP 2 OUIPUT LINES
PRINT 2 LINEIS AS FOLLOWS
PROD 0U CTIO0N CEIN TER D AT A
CENTER 0110ER OF NAHINES
FOR EACH PROOUCTION.CENTIR9 PRINT I LINE WITH PROCUCTIMNCERTER Am)
NUNSER1. IDLE1 THUS
00 00
SKIP 2 OUT`PUT LINES
PRINT I LINES AS FOLLOWS
1 06 T I A L E VEINT S
EVENT TYPE TINE
FOR 1.1 To EVENTS.V. Foot EACM J IN #V.sM@t
PRINT I LINE WITH I AND TINI.AIIS THUS
REGRDLSS....0 00,00
START NEw PAGU
PRINT I LINE AS FOLLOWS
PRINT 3 LINES LIKE THIS*....
W IEEKL Y REIPORaT
I
116GIN REPORT
SKHIN HEADING
PRINT I LINES AS FOLLOWS
PRISUCION CENTER VJEUEING REPOT
CNTS Avg. stEoE MAX. OUEUE
ENo *'HEAOING
PONREACH PAGOUCTION.CENTER,9 PRINT I LINE WITH$ PROOKTION.CENTIA,
AVI.UEUEl AND FAK.&UIW Tus
000.00 0
ENG 4:001RT
'o
-346-
LOOP
IP @OO.PIWNHIOCOVUNTERto$-%Oa RETURN
OTHERWItMeoo STOAT NOWPAME
PRINT I LINt AS FOLLOWS
SAPli 0D1ATP0* SEVERAL JO. SOW 101tI1tUVS DUSIUP 1wC LEVEL So SECTION S.09
.0V11666W SIULI,01 CAN 1|1060 OVER SEVERAL CMOS
PROG1lso.....lITLIS. AS SIN1151H
W AME INOGO III A NA OeVCHMAACTEI
THIS 'i A VEILS CARD POR THE SICOWt SIONA4110 llPIlANINT OF TOO SERIaS
(+8T6 CMIs FOD THIS IIPIEIN11T VILL HAVE 9OU SAN POSIkm AS THOSE OF THE
PARVIOUS lXPEllNINW am0 WILL viv o1WI all w*me CARDO
lTt POI•IOWIW CMOS mi SamiPS OF TOU DATA ,lMOS PUOC..w FOR ON OF ITo TWO
IXTl41mL v*
yIgiS TAPES .. ..... +... THIS s
Ji A Salome rum 1,14 rot6
I
-348-
PEAMBLE
I,
-349-
MAIN FIOC1AI(
m
-351-
Add to preamble:
MAIN
PERFORM INITIALIZATION
RELEASE INITIALIZATION
START SIMULATION
STOP END
PROGRAM INITIALIZATION
the number of simulated weeks that have gone by, resets counters that
are used for collecting periodic statistical information, calls on a
report routine, and reschedules itself. The feature of interest in
this routirne is the use of the word WEEK in the RESCHEDULE statement.
This word was defined to mean *HOIJRS.V*7 HOURS in the program preamble;
the RESCHEDULE statement is therefore compiled as RESCHEDULE THIS
WEEKLY.REPORT IN 1*HOURS.V*7 HOURS. When declarations such as this
are made, care must be taken that the defined word is not used inad-
vertently in another context; e.g., there can be no variable, routine,
label, or set named WEEK in this program.
The event END.OF.SIMULATION is triggered externally. Its only
purpose is to terminate a simulation run, which it does by emptying
the events sets so control will iass to the statement after START
SIMULATION when END.Ov.SIMULATION returns control. In addition to
stopping the simulation, END.OF.SIWILATION calls REPORT and lists an
array.
The next two routines, QUEUE.CHECK and STAY.TIME, are associated
with the BEFORE statements of the preamble. QUEUE.CHECK is called
before filing or removing is done in any QUEUE; STAI.TIME is called
before any JOB is destroyed. The sole purpose of QUEUE.CHECK in
error checking; its code is straightforward. STAY.TIME has a dif-
ferent purpose. It computes the time a JOB spends in the shop,
"assigning this time to a variable for which a TALLY operation has
been specified. Note that STAY is used to compute statistics through
its TALLY computations, but as it is not used anywhere else in the
program, is declared DUMMY and given no storage location.
TRACE is more complicated. Triggered by a call from BETWEEN.V
before every event, it i4 used for event tracing and for releesing
Jobs from finished goods inventory when the simulation clocK reaches
their due date. The first part of the routine deals with this task.
The code sakes use of the fact that Jobs are ranked in FINISHED.GOODS.
INVENTORY in order of their DUE.DATE to make the search more efficient.
The trace section of the program :-as EVENT.V to branch to a
different output statement according to the type of event that has
been selected to occur next. These output statem.nts print different
-357-
PREAMBLE
EVENT NOTICES.... INCLUDE ARRIVAL AND SALE
EVERY END.OF.PROCESS HAS A TIME AND A WHO.COWPLETED
EVERY SHIFT.CHANGE HAS A PERIOD.NUMBER
PRIORITY ORDER IS SALE, SHIFT.CHANGE AND ARRIVAL
etc.
END
MAIN
NOW INITIALIZE
LET BETWEEN.V-'TRACE'
START SIMULATION
STOP END
ROUTINE TO TRACE
GO TO SALE, SHIFT.CHANGE, ARRIVAL OR END.OF.PROCESS
PER EVENT.V
'SALE' WRITE TIME.V AS "SALE OCCURRED AT ",D(10,4),/
RETURN
'SHIFT.CHANGE' WRITE TIME.V PERIOD.NUMBER AS "SHIFT CHA?'GE OCCURRED',
"AT ",D(10,4)," FOR PERIOD ", I 4,/
RETUR14
'ARRIVAL: WRITE TIME.V AS "ARRIVAL OCCURRED AT ",D(10,4),/
RETURN
'END.OF.PROCESS' WRITE TIME.V, TIME AND WHO.COMPLETED AS -END OF%,
"PROCESS OCCURRED AT ",D(1O,4),"JOB TOOK ",D(5.1'1
"TIME UNITS A*:; WAS COMPLETED BY MAN NO. ",I 4,/
RETURN
END
A global variable having the same name as the eveat type selected
contains the identification number of the selected event notice.
This permits implied subscripts to be used in the trace routine.
variables. a in:
-360-
ROUTINE TO TRACE
IF EVENT.V a I.ARRIVAL,
WRITE TIME.V AS "ARRIVAL AT ",D(10,4),/
ELSE
RETURN END
PREAMBLE
TEMPORARY ENTITIES...
EVERY DOG BELONGS TO SOME KENNEL
PER:.,IENmr ENTITIES...
EVERY FARM OWNS A KENNEL
EVENT NOTICES...
EVERY SALE HAS A PRICE AND A DOG.NUMBER
EXTERNAL EVENTS ARE SIGNAL AND END.OF.SIMULATION
DEFINE PROGRAM AS A SUBPROGRAM VARIABLE
BEFORE FILING IN KENNEL, CALL PROGRAM
END
EVENT SIGNAL
READ CODE IF CODE - 1. LFT PROGRAM - 0 RETURN ELSE
IF BETWEEN.V - 0, LET BETNEEN.V - 'TRACE'
RETURN
ELSE LET BETWEEN.V - 0 RETURN
END
ROUTINE TO TRACE
PRINT 1 LINE WITH EYENT.V AND TIME.V THUS
EVENT TYPE *'* EXECUTED AT TIME *''*
RETURN
END
provides a dynamic map of the function and procedure call3 that are
in effect when it is executed. The output of TRACE looks like:
AT LOCATION ******
CALLED FROM ******
CALLED FROM ******
The AT LOCATION line displays the memory location of the objeýr pro-
gram statement that called TRACE. The first CALLED FROM line displays
the memory location of the object program statement that called the
routine that called TRACE. knd so on. If TRACE is executed in a main
routine, no CALLED FROM lines appear.
A programer cAn identify the source program statements that
correspond to displayed memory locations from the memory map and
assembly listings that are part of the normal SIMSrRIPT IT compiler
output. Since computer systems generate maps and listings in dif-
ferent formats, it is impossible to dipcuss how one does this here.
The following program uses symbolic names raLher than memory locations
to illustrate TRACE; SI.SCRIPT II implementation manuals give more
explicit infoimation.
Example of the use of TRACE:
PREAMBLE
NORMALLY MODE IS REAL
DEFINE COMPUTE AS A REAL FUNCTION
END
MAIN
READ X, Y AND Z AS 3 D(10.3) USING UNIT 6
"1 CALL CALCULATE GIVING X, v AND Z YIELDING Q
LIST X. Y. &IAND Q
STOP END
ROUTINE TO COMPUTE(E, F, G)
IF G IS NEGATIVE,
13 TRACE
WRITE E, F, G AS /, B 10, "AN ERROR WAS FOUND, THE",
"DATA IS", 3 D(5,1).
STOP
ELSE RETURN WITH SQRT.F(E**2+F**2+G**2)
END
Given as data the numbers -10, 10, and -5, this program produces
the display
AT LOCATION r13
CALLED FROM w2
CALLED FROM w11
AN ERROR K"AS FOUND, THE DATA IS -10.0 10.0 -5.0
By tracing through the memory locations, a programmer can ace
that the error was found at 13 -" in routine COMPUTE, called from w2 --
TRACE USING 3
When the system calls TRACE, it automatically sets the szandard out-
put device as the current output unit and restores the unit that was
current when the trace is completed.
-363-
Synchronous Variables
PREAMBLE
THE SYSTEM OWNS A SYNCH.SET
TEMPORARY ENTITIES...
EVERY MEMO HAS A VALUE AND A SUB AND BELONGS
TO THE SYNCH.SET
DEFINE SUB AS AN INTEGER VARIABLE
DEFINE X AS A REAL, I-DIMENSIONAL ARRAY MONITORED
ON THE LEFT
END
1MAIN
LET BETWEEN.V='SYNCH'
START SIMULATION
STOP END
----------------
------------------------------- -- -- -- -- -- ----
ROUTINE SYNCH
j DEFINE TAS AREAL, SAVED VARIABLE
IF T = TIME.V, RETURN
OTHERWISE
LET T = TIME.V
FOR EACH MEMO IN SYNCH.SET, DO
REMOVE MEMO FROM SYNCH.SET
LET X(SUB) = VALUE
DESTROY MEMO
LOOP
RETURN END
---------------
------ --- ------ --------------
-- -- -- -- ---- --
-364-
Activity Scanning
PREAMBLE -6
PERMANENT ENTITIES....
EVERY MACHINE HAS A STATUS, A CLOCK AND A PROCESSING.TIME
EVERY MAN HAS A CONDITION. A WATCH AND A WORK.TIME
THE SYSTEM OWNS A QUEUE
EVENT NOTICES INCLUDE STATE.CHANGE
EVERY SALE HAS A CODE AND MAY BELONG TO THE QUEUE
DEFINE CODE, STATUS AND CONCITION, AS INTEGER VARIABLES
PRIORITY ORDER IS STATE.CHANGE AND SALE
END
MAIN
READ N.MACHINE AND N.MAN
CREATE EVERY MACHINE AND MAN "INITIAL CONDITIONS ALL ZERO
SCHEDULE A SALE AT 0.0
LET CODE - UNIFORM.F(1.0,3.0,1)
LET BETWEEN.V-'ACTIVITY.SCAN'
START SIMULATION
STOP END
EVENT STATE.CHANGE
RETURN END
'BOTH' FOR EACH MAN WITH CONDITIONOD, FIND THE FIRST CASE
IF NONE,
GO AHEAD
ELSE FOR EACH MACHINE WITH STATUS=O, FIND THE FIRST CASE
IF NONE,
'AHEAD' LET BOTH.CODE-1 GO TO FAILURE
ELSE LET CONDITION,,1 LET STATUS,1
LET T-MAX.F(PRGCESSING.TIME, WORK.TIME)
LET CLOCK-T LET WATCH-T GO TO DONE
'LOOP' LOOP
FOR EACH MAN, COMPUTE T AS THE MINIMUM OF WATCH
FOR EACH MACHINE, COMPUTE S AS THE MINIMUM OF CLOCK
SCHEDULE A STATE.CHANGE AT MIN.F(T,S)
RETURN
END
The reader wll notice that this program has no output statements
5-07 RECAP
Table 5-11
PREAMBLE STATEMENTS
Statement
Type Statement Rules
I
to declare local background conditions, variables, and substitution*.
I
-369-
Appendix
SFIELO.
SIGII.F
SIN.F
SQRT.F
TANJ
TRUNC.F
TTOA.F
L0R4 IFORM. F
a ~WEE'MAY:F
YEAR. F
-369-
Appendix
TIME. A LOG.NORMAL.F
LOG. 1O.Ft
ROUTINES MIN.F
ORIGIN.R P4INIJTE.F
MOM.
MONT H .F
NOWKL.FI
POISSON.F
RA.NDOM.F
RE AL. F
RSTEP.F
SFUELD. F
SIGNJ.
SIN.F
SORT. F
TAX.F
TRUJNC.F
TTOA.F
LR41FSR.F
WEEKA. F
WE BULL. F
YEAR.
-371-
INDEX
a,
-377-
I format, 158
Tnput (continued):
I.entity system variable, 295f., 358 free-form READ:
Identifiration number, 202
ALPHA,
array, 152
4Sf.
IF FOUND phrase, 145
controlled, 170
IF NONEphrase. 145 defined, of.
random, ?20
IF statement:
defined, 13 TEXT, 272
modified by THEN phizae, 131 INPUT, 2/3
INPUT statement, 273
nesting, 16, 131
optional coma, 16
Tnput/output:
*eaaleo IS phrases
devicei, 155
12p11od, unit characteristics, 157t
pointer aeterisks, 66
INT.F function, 91t, 276t, 369t
subscripts:
for attributes, 244 INTEGER, 2
example, 353 defined, 30
format descriptor (1), 158
in output se tatements, 246f. input conversion, 32t
for sets, 245 mode conversion, 91t, 276
IN phrases:
print conventions, 19t
ARRAY 1, 221
Internal:
DA YS , 30 1 r , 17
bnfe
THE DICTIONARY, 274
GROUPS, 185f. HOURS buffer, 178
HOURS, 301
301event, editing,28Sf.
176
definad, 286
MINUTES, 301
REVERSE ORDER, 239 example, 349
set, 232
WORD1, 219 Interpolation formula, 318
Intra packing, 212
Imbedded:
parentheses, 3 defined, 218f.
periods, 28 example, 348
IS:
INCLUDE statement:
for event notices, 289 optional use, 14
phrases:
for permanent entities, 237
ALPHA, 152
EMPTY, 232
Incremental time expression, 301
ENDED, 77
Independence of random numbers, 312
ENDOGENOUS, 286f.
Index: EXOGZNOUS, 286f.
entity, 195, 205 EXTERNAL,
of MAXIMUM, 149t FALSE, 134 287
of MINIMW4, 149t FIRST, 182
INTEGER, 77
Individual probabilities: INTERNAL, 287
for sampling, 320 LOADED, 144
INF.C constant, 79t, 369t NEW,77
Initialization: POSITIVE, is
of array, 39 REAL, 77
example, 351
of random numbers, 312 IN set, 232
by READ statement, 7 TRUE, 134
by RESET statement. 351 ZERO, 75
ISTEP.F function, 319t, 369t
routine, 351
of system activities, 294
of system state, 294 ITOA.F function, 276, 369t
IVALUE.A attribute, 320, 369t
of variables, 2
In-line function:
defined, 91n
Label:
restrictions, 141n, 267n
defined, 12
'nput:
binary, 175 local property, 87
name, 28
date conversions, 32t subscripted, 68
properties, 76, 77t
Labeled statement, 12
to a routine, b.
statements: LAST COLUMN IS statement, 129f.
formatted READ:
controlled, Last-in-set pointer, 197. 224
defined, 170 15ýff.
Leading zero supprvesioij:
TEXT, 272
in D
in I format, 159
format, 158
K
-378-
tatDE satnet,,3
204 defpultsrl, 27919
numer.
atobuf 369dtit) effeior
tyo: v~i oss 5
refteraleente
, 2 92 beithin anffevent classes: *vns
inatemnleent, 204 PRIARITYE statement, 290.29
packng ule,299default rule, 290
Random: RECURSIVE:
number: routines, 113f.
defined, 312 global variable, 114
function (RANDOM.F), 312 local variable, 114
argument, 312 variables, 114f.
sed, 312 declared, 115
stream, 312 initialized, lisf.
samples from atatisticil distributions, 313 Reference:
generating functions, 313, 314t array, 34
argument, 313 attribute:
example,nested, 22
used to generate activity times, 313 of perranent entity, 205
variables: of temporary entity, 203
construction of set, 322
declared, 316f. REGARDLESS statemcnt, 14; aee atoo ELSE statement
RANDOM LINEAR VARIABLE, 318 Relational operator, 5, 6t
RANDOM STEP VARIABLE, 317f.
defined, 316 Relative time specification, 301
example, 348, 352 Relative location of attribute, 195
free-form READ, 320, 322
input format, 320 RELEASE statement:
prohibited use, 319 for arrays, 110
sampling routines, 319t for attributes of permanent entities, 206
generation, 319 compound, 243
inhibition, 319 for routines, 140
set, 320 REMOVE statement, 225
stored, 320 FIRST, 231
RANDOM.E entity, 320, 369t LAST, 231
specific, 231
RANDOM.F function, 312f., 369t THIS, 231
Range of FOR statement, 44-45, 52 ABOVE, 231
used in BEFORE and AFTER statements, 323t
Ranked set, 233 REPEAT rtatement, 52
Ranking function example, 250 Report:
RCOLUMN.V system variable, 369t generator, 179
defined, 177 column repetition, 185
set by external event, 310 DOUBLE LINES, 184f.
Read binary, 175 roy repetition, 179-181
SUPPRESSING clause, 190
READ statement: section, 179
formatted: headings:
controlled, 170f. printing on each page, l6
defined, 157 printing on first page only, 182
descriptors, 158-168 NEW PAGE, 183
TEXT, 273
unit specification, 172 Required set attributes, 2It
variable formats, 171 RESCHEDULE statement, 298; cee alco Scheduling
free-form: RESERVE statement:
ALPHA, 152 defined, 37-40
for arrays, 48ff. general form, 64f.
defined, 6f. multiple form, 60
card format, 7 pointer words only, 65
controlled, 50
look-ahead properties, 76, 77t RESET statement, 332f.
RANDOM variables, 320 RESUME SUBSTITUTION statement, 121
TEXT, 272
unit specification, 172 RETURN statement:
READV system variable, 369t in an event routine, 308
ReAVsem,vai e used in a function, 93
defined, 155usdn preue,9
set by external event, 310f. used in a procedure, 99