June 18, 2019

Grinder - IRAF CL scripts

What I would like to do is to have a cron job run every night, maybe at 1 AM and run wfits on the current set of 8 data files from the night before. It sounds easy enough, and it would be on a modern system with any kind of civilized scripting language -- even an uncivilized language like tcl.

There are hints that this can be done with the IRAF CL, although the only clue I have found is this nearly 20 year old page that warns that this is "still a primitive feature of the OpenIRAF project in development". They claim it is functional, but I have not yet been able to make it work.

So far, I always end up with the "cl" prompt rather than having it execute the script in the file.

The forum discussion says that this should appear on the shebang line:

#!/iraf/iraf/bin.linux/ecl.e -f
And indeed this works, the recipe in the first link is embryonic and out of date.

Another option is to just run the desired IRAF task directly. The following excerpt tells how to do this from the csh:

There are three ways to run an IRAF task outside of the CL, either invoke the executable directly with the correct command line arguments, run the CL with the input redirected to execute the task, or use the host CL scripting capability.

In the first case you must know in which executable the task resides, core IRAF system tasks (e.g. things in the PLOT and IMAGES packages) have their executables in the main $iraf/bin. directory, NOAO package tasks have the executables in the $iraf/noao/bin. directory. There is usually a separate executable for each package and you can probably figure out which one goes for each package otherwise just look at the package cl file to find out, for example the PLOT package defines the task in the $iraf/pkg/plot/plot.cl file, if you look in their you'll see that is defines the tasks as (part of the file reads)

task    contour,
        surface,
        hafton,
        velvect         = "plot$x_ncar.e"
which means that the CONTOUR, SURFACE, etc tasks are in the "x_ncar.e" executable.

Once you find the correct binary, you need to create a file with the task parameters: usually it's easiest to set the parameters and then dump the parameter file with 'dpar', e.g.

        cl> dpar listpix > listpix.par
Then to run the task you would do something like:
        % $iraf/bin.sparc/x_images.e listpix @listpix.par
In this case you must be careful that ALL of the task parameters are defined, this is done by 'dpar' but empty string parameters will be prompted for.

In the second case you create a command file and input it to the cl, for example

        % cl < cl.input >& some_logfile
where cl.input contains CL commands such as
        wfits.scale=no                  # set a parameter
        wfits image*.imh mta            # call a task
        logout                          # logout of the CL
You must be careful about making sure you are in the right directory and that parameters are given explicitly if they're like to change, but with this approach you can call any iraf task.

In both cases you need to be careful about redirecting any input or output that is required, both text and graphics. You can redirect graphics output either by setting the "device" parameter to e.g. 'stdvdm' or using the '>G' syntax as in

        cl> surface dev$pix >G surf.plot
        cl> surface dev$pix dev="stdplot"       # to print it out
        cl> surface dev$pix dev="stdvdm"        # save metacode to uparm dir
The host CL scripting capability is covered in another part of this FAQ. Which of these approaches works best for depends depends on the tasks you need and the complexity of the script. Note that by using OS escapes in IRAF scripts it may be simpler to write an IRAF script to do the same thing.


Have any comments? Questions? Drop me a line!

Tom's home page / tom@mmto.org