Program control


A GenStat program consists of a sequence of one or more jobs. The first job starts automatically at the start of the program. Subsequent jobs can be initialized by the JOB and ENDJOB directives:


JOB
starts a GenStat job (ending the previous one if necessary)

ENDJOB
ends a job


The whole program is terminated by a STOP directive:


STOP
ends a GenStat program


Statements within a program can be repeated using a FOR loop. The loop is introduced by a FOR statement. This is followed by the series of statements that is to repeated (that is, the contents of the loop), and the end of the loop is marked by an ENDFOR statement. Parameters of the FOR directive allow lists of data structures to be specified so that the statements in the loop operate on different structures each time that it is executed.


FOR
indicates the start of a loop

ENDFOR
marks the end of a loop


GenStat has two ways of choosing between sets of statements. The block-if structure consists of one or more alternative sets of statements. The first set is introduced by an IF statement. There may then be further sets introduced by ELSIF statements. Then there may be a final set introduced by an ELSE statement, and the whole structure is terminated by an ENDIF structure. The IF statement, and each ELSIF statement, contains a single-valued logical expression. GenStat evaluates each one in turn and executes the statements following the first TRUE logical found; if none of them is true, GenStat executes the statements following the ELSE statement (if any).

 

IF
                           introduces a block-if structure

ELSIF
introduces an alternative set of statements in a block-if structure

ELSE
introduces a default set of statements for a block-if structure

ENDIF
marks the end of a block-if structure


The multiple-selection structure consists of several sets of statements. The first is introduced by a CASE statement. Subsequent sets are introduced by OR statements. There can then be a final, default, set introduced by an ELSE statement, and the end of the structure is indicated by an ENDCASE statement. The parameter of the CASE statement is an expression which must produce a single number. GenStat rounds this to the nearest integer, n say, and then executes the nth set of statements. If there is no nth set, the statements following the ELSE statement are executed (if any).


CASE
introduces a multiple-selection structure

OR
                         introduces an alternative set of statements for a multiple-selection structure

ELSE
introduces a default set of statements for a multiple-selection structure

ENDCASE
marks the end of a multiple-selection structure


Sequences of statements can be formed into GenStat procedures for convenient future use. The use of a procedure looks just like one of the GenStat directives, with its own options and parameters, which transfer information to and from the procedure. Otherwise the procedure is completely self-contained. The start of a procedure is indicated by a PROCEDURE statement. Then OPTION and PARAMETER statements can be given to define the arguments of the procedure. These are followed by the statements to be executed when the procedure is called, terminated by an ENDPROCEDURE statement.


PROCEDURE
introduces a procedure, and defines its name

OPTION
defines the options of a procedure

PARAMETER
defines the parameters of a procedure

CALLS
lists library procedures called by a procedure

ENDPROCEDURE
indicates the end of a procedure

WORKSPACE
accesses "private" data structures for use in procedures


Any control structure (job, block-if structure, loop, multiple-selection structure or procedure) can be abandoned using an EXIT statement. Also, execution of any of these structures can be interrupted explicitly with a BREAK statement, or implicitly by using DEBUG. Once DEBUG has been entered, GenStat will produce breaks automatically at regular intervals, until it meets an ENDDEBUG statement.


EXIT
exits from a control structure

BREAK
suspends the execution of a control structure

ENDBREAK
continues execution of a control structure, following a break

DEBUG
can cause a break to take place after the current statement (and at specified intervals thereafter), or immediately after the next fault

ENDDEBUG
cancels DEBUG


Macros within a procedure are substituted as soon as they are met during the definition of the procedure. However, it is also possible to execute a set of statements (contained in a text) during execution of the procedure. This can also be useful within loops.


EXECUTE
executes the statements contained within a text


In some implementations of GenStat, it is possible to suspend the execution of GenStat and return to the operating system of the computer to execute commands, for example to list or edit files on the computer. Likewise, it may be possible to halt the execution of GenStat to execute some other computer program. The OWN directive provides another way of running a user's program from within GenStat. The OWN subroutine, within the Fortran code of GenStat, needs to be modified to call the program. The new code must then be recompiled and linked into a new version of GenStat.


SUSPEND
suspends the execution of GenStat to carry out operating-system commands

PASS
runs another computer program, taking data from GenStat and transferring results back

OWN
executes the user's own code linked into GenStat