The following is an example of a task with a parameter. This task calculates the square of a number and outputs its value on the terminal.
SUBROUTINE SQUARE(STATUS)
INTEGER STATUS
REAL R,RR
CALL PAR_GET0R('VALUE',R,STATUS)
RR = R*R
CALL MSG_SETR('RVAL',R)
CALL MSG_SETR('RSQUARED',RR)
CALL MSG_OUT(' ','The Square of ^RVAL is ^RSQUARED',STATUS)
END
This program uses the subroutine PAR_GET0R to get the value of the parameter
VALUE (there are similar routines for other types). Output of the numbers
is done using the routine MSG_SETR to give values to the tokens RVAL and
RSQUARED which are then inserted into the MSG_OUT output string using
the ^RVAL notation. The interface file for this example is given
below.
INTERFACE SQUARE
PARAMETER VALUE
TYPE _REAL
POSITION 1
VPATH PROMPT
PPATH CURRENT
PROMPT 'Number to be squared'
ENDPARAMETER
ENDINTERFACE
The interface file has an entry for the parameter VALUE. The TYPE field specifies the type of the parameter. The underscore prefix on '_REAL' identifies it as a primitive type (i.e. a simple number or string, rather than an HDS structure or Device name). The position field specifies the position that the parameter is expected in if it appears on the command line.
The VPATH entry specifies how the parameter value is to be obtained if it not found on the command line. In this case it is to be prompted for. The PPATH entry specifies how the default value that appears in the parameter prompt is to be obtained. In this case the CURRENT value (i.e. the value the parameter had at the end of the last execution of the command) is used. The PROMPT field gives the prompt string to be used.
Interface files are described in more detail in SUN/115.
To run this example we would compile and link it as described above and then use the following ICL commands:
ICL> DEFINE SQUARE SQUARE
ICL> SQUARE 12
Loading SQUARE into 03BCSQUARE
The Square of 12 is 144
ICL> SQUARE (SQRT(3))
The Square of 1.73205 is 3
ICL> SQUARE
VALUE - Number to be squared /0.173205E+01/ > 7
The Square of 7 is 49
ICL>
ICL The Interactive Command Language for ADAM