## Chapter 5ICL — Interactive Command Language

5.1 Introduction

5.3 Modes
5.4 Statements

5.6 Expressions

### 5.1 Introduction

ICL is the most commonly used ADAM command language. It is designed to provide a programmable user interface to an astronomical data-reduction or data-acquisition system. In some ways, ICL is similar to a high level programming language such as Fortran or Pascal, but it has some important differences:

• It is an interactive language — It provides a complete environment for entering, editing and debugging programs in much the same way that Basic does, rather than relying on external editors, compilers and so on.
• It is a command language — One of its main uses is to enable you to type commands with few format restrictions. For example, it can be used to run the FIGARO data reduction system and it is possible to type FIGARO commands in almost exactly the same format as was previously used from DCL.
• It is a programming language — However it is intended only for writing relatively simple and straightforward programs. Its requirements differ from those of most modern programming languages which are designed for the needs of big software projects. ICL is designed to make simple programs easy to write.

The definitive reference manual and user’s guide is SG/5. The language is summarised in Chapter 19. ICL also has an on-line Help system — simply type HELP.

### 5.2 Starting and stopping ICL

ICL is started by typing:

\$ ICL

ICL is stopped by issuing the EXIT command:

ICL> EXIT

If things are hopeless you can, of course, abandon ship by typing Ctrl/Y.

### 5.3 Modes

ICL can be used in two different modes:

• Direct Mode
• Procedure Mode

In Direct Mode, statements are executed immediately after they are typed in. In Procedure Mode, statements are first entered into a procedure, and subsequently executed by running that procedure. Another difference between the modes is that Control Statements (see below) can only be executed in Procedure Mode.

### 5.4 Statements

The statements of the language can be grouped into two sets:

• Direct Statements
• Control Statements

Direct statements are executed immediately and can be entered in either mode. Control statements affect the order in which statements are executed and can only be executed in Procedure mode. You can also enter Comments which are lines whose first non-blank character is ‘{’. Comments are ignored by the language interpreter. If desired, they can be terminated by ‘}’, but this isn’t necessary and is a matter of taste. Here is an example of a comment:

{ This is a comment

Although comments can be entered in Direct mode, their real purpose is to document procedures written in Procedure mode.

When entering statements in ICL, all the normal command line editing facilities available in DCL may be used. The Up arrow or ctrl/B keys may be used to recall previous commands, and the Down arrow key will step to the next command. Any command back to the start of the ICL session may be recalled.

A command may take more than one line. A tilde (~) symbol at the end of a line is used to indicate that the command continues on the next line.

### 5.5 Direct statements

There are three types of direct statements:

Immediate Statement:

This is used to make ICL do simple calculations. It consists of an equals sign (=) followed by an expression, and causes the value of the expression to be printed on the terminal. For example:

ICL> =1+2+3
6
ICL> =SQRT(2)
1.414214
ICL>

Assignment Statement:

This is exactly the same as the Fortran assignment statement and is used to assign a value to an ICL variable. For example:

ICL> PI=3.1415926
ICL> =2*pi
6.283185
ICL>

Note that the case of letters doesn’t matter. ‘PI’ and ‘pi’ are the same variable. In practice, names like ‘PI’ are the names of HDS objects which store the constant values.

Command:

A command consists of a command name followed (optionally) by one or more parameter specifications:

command_name [parameter_specification] …

The parameter specifications may be separated by commas, or by one or more spaces. The forms that parameters can take are described in Chapter 8. Here are some examples of commands:

PRINT Single Root is (-C/B)
TESTR 5.8

Commands are a very important part of ICL and several types exist. You can’t tell which type a command is just by looking at it; you have to know how it is defined. Commands are described in more detail in Chapter 6.

All three types of direct statement make use of expressions. These are described next.

### 5.6 Expressions

One of the basic syntactical units of the ICL language is the Expression. Expressions are built up by operating on values using operators:

VALUE operator VALUE operator VALUE …

Here are some examples of expressions:

2
X
X+5
Y*SIN(THETA)

The value of an expression belongs to one of the following four types:

• Real — same as Fortran DOUBLE PRECISION type.
• Integer — same as Fortran INTEGER type.
• Logical — same as Fortran LOGICAL type.
• String — strings of characters, similar to Fortran CHARACTER*n type.

The two constituents of expressions — value and operator — will now be considered in more detail:

Value
— A value can be represented in three ways:
Constant:

Real and Integer constants are represented by numbers written in the same formats that are accepted in Fortran. Integer constants may also be entered in binary, octal, or hexadecimal format by preceeding the value with %B, %O, or %X respectively.

Logical constants are written as TRUE or FALSE. Note that they are not delimited by decimal points as in Fortran.

String constants consist of any sequence of characters enclosed in either single or double quotes. Two consecutive quote symbols in a string are used to represent a single quote. String constants are the one place in ICL where the case of letters is significant.

Here are some examples of constants:

Real:          1.234E-5              3.14159
Integer:       123      %B100110     %O377      %Xffff
Logical:       TRUE     FALSE
String:        ’This is a string’    "So is this"      ’’

The last example defines a string of zero length (valid in ICL, but not in Fortran).

Variable:

Variables are represented by names composed of characters which may be letters, digits, or the underscore character (_). The first character must be a letter. The first 15 characters of a variable name are significant.

An important difference between ICL and Fortran is in the handling of variable types. In Fortran, each variable name has a unique type associated with it, and this type is either derived implicitly from the first letter of the name, or is explicitly specified in a declaration. In ICL, variable names do not have types — only values have types. A variable gains a type when it is assigned a value. This type can change when a new value is assigned to it. Thus we can have the following series of assignments making the variable X an integer, real, logical, and string in sequence:

ICL> X = 123
ICL> X = 123.456
ICL> X = TRUE
ICL> X = ’String’

This approach to variable types means that we do not have to declare the variable names we use, which helps to keep programs simple1.

Function:

ICL provides a variety of standard functions. They are written as in Fortran, and all the standard Fortran 77 generic functions which are relevant to the ICL data types are provided with the same names. Thus SIN, COS, TAN, ASIN, ACOS, ATAN, ATAN2, LOG, LOG10, EXP, SQRT and ABS are all valid functions. A complete list of functions is given in Chapter 19.

Operator

The operators which are used to build up expressions are listed in the following table in order of priority:

1 (highest)              **
2                        *   /
3                        +   -
4                        =   >   <   >=  <=  <>  :
5 (lowest)               NOT   AND   OR   &

The order of evaluation of expressions is determined by the priority of the operators. The rules are the same as those in Fortran2, with arithmetic operators having the highest priority and logical operators the lowest. This means that a condition such as $0 can be expressed in ICL as follows:

X+Y > 0  AND  X+Y <= 1

without requiring any parentheses. However, in general it is good practice to use parentheses to clarify any situation in which the order of evaluation is unclear.

The ‘&’ operator performs string concatenation. If one of its operands is a numeric value, it will be converted to a string. The ‘:’ operator is used for formatting numbers into character strings as described in Section 6.4

In evaluating expressions, ICL will freely apply type conversion to its operands in order to make sense of them. This means not only that integers will be converted to reals when required, but also that strings will be converted to numbers when possible. A string can be converted to a number if the value of the string is itself a valid ICL expression; for example, the string ’1.2345’ has a numeric value. The string ’X+1’ has a numeric value if X is currently a numeric variable (or if X is a string which has a numeric value).

1The disadvantage is that ICL cannot usually spot cases where we accidentally mistype a variable name, as can languages which enforce declaration of variables (such as Fortran with the IMPLICIT NONE directive). This is not thought to be a serious problem for the relatively simple programs for which ICL is intended.

2But different from those in Pascal.