18 Writing ICL command files and procedures

Like DCL, ICL has a set of commands, functions and control structures which can be used to write powerful command files and procedures, both of which have the default extension ‘.ICL’. An important difference between command files and procedures is that command files run when loaded, whereas loading a procedure simply makes it available to run.

ICL syntax.

ICL syntax will generally appear familiar to the Fortran user although there are several important distinctions. Perhaps the most striking difference involves variable type; this is not fixed but depends on the current value of a variable. The example session below illustrates some of ICL’s capabilities. The open bracket ‘{’ on an ICL command line begins a comment. Explanations of the ICL commands below are shown enclosed in brackets {} but the closing bracket is included only for appearance.

  $ ICL
  ICL> x=3              {Assign 3 to variable x}
  ICL> =x               {Print the value of x}
         3
  ICL> x=’Hi there’     {Assign string to x - ICL variables have no intrinsic type}
  ICL> =x               {Print the value of x}
  Hi there
  ICL> x=x&x            {String concatenation achieved using ‘&’}
  ICL> =x               {Print the value of x}
  Hi thereHi there
  ICL> =sqrt(4)         {ICL has many Fortran-like intrinsic functions}
  2
  ICL> x=upcase(x)      {And other functions too.}
  ICL> =x
  HI THEREHI THERE

ICL commands.

A selection of ICL commands were introduced in Section 17, i.e. LOAD, TASKS, DEFINE, KILL and DEFAULT. A full list of the commands and their specifications can be examined by typing HELP in ICL.

ICL functions.

Several ICL functions (SQRT, UPCASE) are shown in the example session above. SNAME is a very useful ICL function which concatenates a string with an integer (it is described here as it is used in the procedure PLOTS later in this section). SNAME has two or three arguments, the first and second being a string and an integer. The optional third argument gives the number of characters which the integer part of the resultant string should occupy, for example: SNAME(’FIBRE’,2) returns FIBRE2 whereas SNAME(’FIBRE’,2,3) returns FIBRE002. A complete up-to-date list of functions can be viewed by typing HELP FUNCTIONS in ICL.

ICL control structures.

Two types of control structures are available within ICL; the loop structure, which can be compared to the Fortran DO loop, and the IF or conditional structure, which also resembles its Fortran equivalent. Three variants of the loop structure exist; an example of each is shown below. A BREAK statement can be used to pass control to the end of a LOOP; normally such a statement would be inside an IF structure. Also shown is an example IF structure.

  LOOP          LOOP WHILE (I<5)     LOOP FOR I=1 TO 7      IF A=0
  ...           ...                  ...                    ...
  END LOOP      END LOOP             END LOOP               ELSE IF NOT DONE
                                                            ...
                                                            END IF

ICL control structures can only be used in procedures. Both a LOOP and an IF control structure are used in the procedure PLOTS shown later in this section.

ICL command files.

ICL command files contain a set of ICL command lines and are activated by typing LOAD filename in ICL. For example, rather than typing the commands to define ADDNEW and REPDIM2 in each ICL session, the appropriate commands (as shown below) might be written to a file called MYCOM.ICL.

  DEFINE ADDNEW  ADAM_EXAMPLES:ADDNEW
  DEFINE REPDIM2 ADAM_EXAMPLES:REPDIM2

On entering ICL, loading this command file is analogous to activating a DCL command file.

  ICL> LOAD MYCOM         {Defines ADDNEW and REPDIM2}

Just as you probably have a LOGIN.COM file which executes every time you begin a VAX session, an ICL login file can be set up which will execute each time you enter ICL. This is done by defining the appropriate file as ICL_LOGIN. For example, you might include the following line in your LOGIN.COM:

  $ DEFINE ICL_LOGIN ADAM_EXAMPLES:LOGIN.ICL

ICL procedures.

ICL procedures are ideal for programming data-reduction sequences. An ICL procedure can use any ICL commands (including user-defined commands) control structures, functions etc. As mentioned above, loading a procedure does not cause it to run; it is simply made available for running whenever the procedure name is typed. A procedure begins with the declaration PROC procedurename and ends with END PROC. For example, the command file MYCOM.ICL above can be converted into a procedure named MYPROC.ICL by inserting an initial line PROC MYPROC and a final line END PROC. Running this procedure requires two steps: it is first loaded, after which it is run by typing the procedure name as shown below. Subsequent runs do not require the procedure to be loaded again.

  ICL> LOAD MYPROC
  ICL> MYPROC

Unlike command files, ICL procedures can have arguments as shown in the example below:

  PROC MULT X Y
    Z=X*Y
    =Z
  END PROC

This is loaded and run as shown below:

  ICL> LOAD MULT
  ICL> MULT 15 2
     30

The procedure below was written to produce CANON plots from seven data files each containing a spectrum. These spectra had been extracted from a CCD image and named FIBRE01.SDF, …FIBRE08.SDF. One file, FIBRE06.SDF is missing from the sequence, as this corresponded to a dud fibre. The procedure uses KAPPA’s LINPLOT to produce and print the graphs on a CANON laser printer (see SUN/95); it is therefore necessary to define the command LINPLOT (by typing KAPPA) before running the procedure. Additional explanation is provided in the on-line file ADAM_EXAMPLES:PLOTS.ICL.

  PROC PLOTS
  LOOP FOR I = 1 TO 8
    IF NOT (I = 6)
       FILENAME = (SNAME(’FIBRE’,I,2))
       LINPLOT INPIC=(’@’&FILENAME) DEVICE=CANON_L PLTITL=(FILENAME) \
       $ PRINT/PASSALL/QUE=SYS_LASER CANON.DAT
    ENDIF
  END LOOP
  END PROC