Programming

CL as a Programming Language


The IRAF CL contains a number of control constructs that enable you to build data processing scripts directly in the CL, allowing you to automate your processing or to build up your own programs. There are two ways to do this:

Writing Scripts

Even at the script-writing level there is a large variation in the complexity of operations that can be done. The use of wildcards in input file names is probably the simplest kind of procedure (doit input*), but if you look at the STSDAS software, you will find that some STSDAS tasks are actually CL procedures which call other more basic tasks elsewhere in the system.

The introduction to the CL in this manual can get you started in using the CL to construct data processing procedures, but you should refer to the documents A User's Introduction to the IRAF Command Language and An Introductory Guide to IRAF Scripts for help. Both documents are part of the standard IRAF documentation set. The STSDAS group can provide a CL Programmer's Quick Reference Card on request.

Using mkscript

The mkscript task in the system package creates a CL script so that you can run several commands together. While it's relatively easy to build simple scripts manually, mkscript does much of the tedious work to make sure that all of the parameters are present in the task calls. This becomes particularly useful for longer scripts involving tasks with many parameters.

Note that mkscript does not include any of the programming capabilities available in the CL such as loops or conditional execution. Nor does it produce a script task with parameters. However, any script produced by mkscript can be customized and enhanced by editing and adding to the script file. (See "An Introductory User's Guide to IRAF Scripts" by Ed Anderson for a much more complete description.)

In operation, mkscript prompts you for a task to add to the script. When you type the task name, mkscript runs eparam so that you can specify the task parameters. After exiting from the parameter editor, mkscript lets you add more tasks. At each point, mkscript prompts you to continue. When no more tasks are added, mkscript lets you submit the script as a background job.

The sequence of steps are:

  1. See if the script already exists. If the script exists and append = no the script file is deleted. (When verify = yes you will be prompted to confirm the deletion.)

  2. Provide a task name. If a task is not specified on the command line, you will be asked to specify one. The task must be in a loaded package. If the task can be loaded a message will be displayed.

  3. Set the task parameters using eparam.

  4. Confirm whether you want to add the task to the script. If verify = yes the command is displayed and you will be asked if the command is correct.

  5. Add additional commands. You will be asked if another command is to be added to the script. If you say "yes", steps 2 through 5 will be repeated.

  6. Save the script or start over. If verify = yes the script is displayed, page by page, and you will be asked if the script is correct. If it is not, the script will be deleted and steps 2 through 6 will be repeated.

  7. If the submit parameter is not specified on the command line, you will be asked if the script should be submitted as a background job.

The parameter hidden is important because hidden parameters are not explicitly included in the script commands, therefore the values of the hidden parameters will be taken from the parameter file at run time. Thus, changes in the hidden parameters with eparam or explicit assignments may produce unexpected results if you run the task again later. On the other hand, if the hidden parameters are never changed, then the commands are more readable when the hidden parameters are not included.


mkscript is implemented with a script which makes it seem somewhat slow. The most important limitation is that the command formatter is based on the output of lparam. If a task parameter name exceeds 12 characters it is truncated by lparam and is then also truncated by the command formatter. The script will then fail when executed! Also, the task name may not be abbreviated.


Psets and mkscript

Note that mkscript does not automatically
expand pset parameter tasks. If you wish to use pset parameters different from the current default values, you may include psets as task calls to be added to the script. You will be able to modify the parameters with eparam as for any task. However, when a pset task is executed by name, it invokes eparam for modifying the parameters. This means that any script containing a pset call will invoke the eparam parameter editor.

Alternately, you can edit the script created by mkscript and include the pset parameters in the argument list for the parent task, or set each parameter via an explicit assignment. For example, the following is the result of including the pltpar pset task and the sgraph task from the stplot package in a script using mkscript. (This would be the appropriate order since sgraph depends on values pltpar.)

pltpar (stack=no,
axis=1, pointmode=yes, marker="box", szmarker=0.005,
erraxis=0, errtype="bartck", pattern="solid",
crvstyle="straight", rejectlog=yes, barpat="hollow",
crvcolor=4, color=3, cycolor=no, version="20July1993")

sgraph ("dev$pix[*,100]",
errcolumn="E", dvpar="", pltpar="", axispar="",
version="20Jul93")
If you don't want to have eparam executed when you run the script, you could edit the script and include some or all of the pltpar parameters in the sgraph calling sequence:

sgraph ("dev$pix[*,100]",
errcolumn="E", dvpar="", pltpar="",axispar="", stack=no,
axis=1, pointmode=yes, marker="box", szmarker=0.005,
erraxis=0, errtype="bartck", pattern="solid",
crvstyle="straight", rejectlog=yes, barpat="hollow",
crvcolor=4, color=3, cycolor=no)

mkscript Task Parameters

Example

A common use of mkscript in data analysis is to create repeated commands with different input data or parameters. The following is an example of creating a script with mkscript to do this sort of operation:.

Creating a Script with mkscript

Writing Scripts
Using mkscript
Psets and mkscript
mkscript Task Parameters
Example

Generated with WebMaker