If you want other arguments, or a UNIX-like set of options for specifying arguments with defaults, you’ll need to use switch and shift statements, rather than the simple while loop.
Suppose that we want to obtain photometric details of a galaxy, known to be the brightest object in a series of NDFs. Before that’s possible we must first measure the background in each image. To reduce contamination that could bias the determination of the sky we mask the region containing the galaxy. Here we obtain the values for the shape, orientation, and the names of the NDFs, and assign them to shell variables. There are also default values.
-o
orientation-value on the command line when
invoking the script.
The switch looks for specific arguments. If the first argument matches one of the allowed cases: -a
, -b
,
-o
, or any string (*
) in that order, the script jumps to that case, and follows the commands there until it
encounters the breaksw, and then the script moves to the endsw statement. You may be wondering
why only the first element of the arguments is tested against the cases. This is where the shift
statement comes in. This decrements the element indices of an array by one, so that $argv[1] is lost,
$argv[2]
becomes $argv[1]
, $argv[3] becomes $argv[2]
and so on. If we look at the -a
case. The
arguments are shifted, so that the first argument is now the value of the semi-major axis. This in turn
is shifted out of the arguments. The *
case does the equivalent of the earlier while loop (see
Section 7.6) as it appends the NDF filenames. The [1-]
means the first element until the
last.
To actually perform the masking we could write an ARD ellipse shape using the variables, and pipe it
into a file, in this case biggal.ard
.
On the command line we could enter
if the script was calledgalmask
. This would set the semi-major axis to 78.4 pixels, the orientation to
145° , leaving the semi-minor axis at its default of 44 pixels. It would operate on the NDF called myndf
and those whose names began with ccd
and ended with o
.
There is a related example in Section 17.1 where the ellipse axis lengths and orientation are fixed for two galaxies. The above options code could replace that recipe’s first two lines, if we wanted to alter the spatial parameters for the brighter galaxy to see which gives best results.
In $KAPPA_DIR/multiplot.csh
you can find a complete example. For a series of NDFs, this produces a
grid of displayed images with axes and titles, prints them to a nominated device, once
each page is full. You can modify it for other operations, where a single page of graphics
output is produced by running several tasks, and joining them together with PSMERGE
(SUN/164).