next up previous 63
Next: Running a background job
Up: Worked Examples
Previous: Installing Starlink software in IRAF

IRAF Scripts and Background Jobs

A series of IRAF commands can be executed as a script by putting them in a file and then running the file. The IRAF command language, cl, is also a programming language and contains many features which allow you to write scripts to perform repetitive tasks automatically. It is also possible to run IRAF scripts as Unix background jobs. This facility is particularly useful if you want to run lengthy tasks at low priority without tying up your terminal. This example is a simple introduction to IRAF scripts and background jobs.

The scripts used in this example is available as files:


If you intend to work through the example you should copy these files to your IRAF directory. The IRAF OIF image ccdframe, which was used in the previous examples, should also be available.

File is a script of IRAF commands. It is shown in Figure [*]. It calculates the mean value of all the pixels in an image and then generates a new image in which the mean value is subtracted from every pixel.

Figure: Example IRAF script

As with any unfamiliar programming language, your first reaction is probably one of trepidation as you wonder what is going on. No variables were declared at the start of this script although variables are used throughout the program for parameter passing. The cl has some built-in variables which do not need to be declared. There are three string variables named s1 to s3, three real variables x, y and z, three integers i, j and k, three booleans and other more esoteric ones. Type `lpar cl' for a full list of the parameters available for immediate use. Other variables can be used but they need to be declared: see the cl manual[13] for information on how to do this. List-type parameters are useful, they are usually associated with files, and they allow you to use fscan and fprint for reading and writing to files. These functions are similar to the equivalent functions in the C language.

The command imstat is used to calculate the mean. Some IRAF tasks have output parameters which allow their results to be stored and subsequently accessed by another task. Unfortunately, imstat does not have any such output parameters. Instead, it is configured so that the only output that it generates is the mean value, without any annotation. This output is redirected to temporary file temp.file using the Unix-like output redirection capabilities of the IRAF cl.

The fscan function is used to read the value from the file and store it in variable x. The imarith task (from the images package) is then used to subtract the mean value from each pixel and create a new image newframe. Finally, imstat is reconfigured to display its default output and the statistics for image newframe displayed as a check that the script has worked correctly.

Quoted parameters are passed to the tasks as they are; the brackets around some of the parameter lists indicate that the cl language is meant to interpret these parameters as variables. Programming in cl can be tricky sometimes: putting `echo=yes' at the start of the script means that all commands are echoed to the terminal as they are executed, which can be useful for debugging. The file name `ccdframe' was of course hardwired into the script; a more typical application would operate on every file in a list, or loop until some condition is satisfied. The cl can support loops of various types. See A User's Introduction to the IRAF Command Language[13] for more information.

The procedure to run the script is as follows.

  1. First you must make the script known to IRAF. From the cl> prompt type:

    task $submean=home$

    `home' is specifying that the script file resides in your root IRAF directory.

  2. You can now simply run the script by typing:


    Output similar to the following should appear:

    #               IMAGE      NPIX      MEAN    STDDEV       MIN       MAX
                 newframe     98304  3.044E-5     308.3     -178.    31480.
    Subtracted 508.046 to create file newframe.

    You can check that image newframe has been created by typing dir and display it with SAOIMAGE by typing:

    display  newframe  1

  3. Finally you should tidy-up by deleting the new image:

    imdelete  newframe

    Note that the script will not work correctly if newframe already exists, so you must delete it before running the script again.


next up previous 63
Next: Running a background job
Up: Worked Examples
Previous: Installing Starlink software in IRAF

An Introduction to IRAF
Starlink Guide 12
R. Morris, G.J. Privett & A.C. Davenhall
2nd December 1999

Copyright © 2013 Science and Technology Facilities Council