next up previous
Next: In-line do-loops
Up: Writing Your Own Command Files
Previous: Repetitive Operations

Automatic Repetitive Operations

 In the example above, say I want to make a list of the scans to be read in so that I can change the list when I want and go out for doughnuts while SPECX does all the work. One could combine a number of calls to the command file rlb.spx in a simple-minded way in a new command file e.g.
@RLB 101
@RLB 102


@RLB 119
@RLB 120

Saving this command with some name (say, 1to20.spx) and running it by typing

$\gt\!\gt$ @1to20

processes each of the scans 101 through 120, placing the results in my output file. SPECX will start running 1to20.spx; the first command it gets is to run rlb.spx, and while running rlb it sees the ? and looks for a value, it finds the value in 1to20.spx and continues to run happily along until it gets to the end of 1to20.spx.

This is still a bit silly. Since SPECX allows the use of loops and counters, one can achieve the same result a lot more elegantly. That is, if one creates a command file (call it, say, doit.spx):

do n 101 120
r-g-d\n\ 
r-l-b\-40 -20\20 40\ 
wr-sp\1\ 
enddo

then typing

$\gt\!\gt$ @doit

will achieve the same result. The counter n will step from 101 to 120.

As you might guess doit.spx could look like this also:

do n 101 120
@rlb\n\
enddo

Taking this still one step further allows the input of parameters from outside:

declare fscan i4
declare lscan i4
ask 'First scan?',fscan,?
ask 'Last scan?',lscan,?
do n fscan,lscan
@rlb\n\
enddo

In this case running this procedure will prompt you for the first and last scans to be processed by rlb.spx. Note that (a) the declaration of the type of variable (I4) required by SPECX for input, and (b) the use of the ask command. The latter gives a prompt (e.g. First scan?) and puts your answer in e.g. the variable fscan.



next up previous
Next: In-line do-loops
Up: Writing Your Own Command Files
Previous: Repetitive Operations

Specx Cookbook Reduction of millimetre wave data
Starlink Cookbook 8
Henry Matthews, Tim Jenness
1st March 1997
E-mail:ussc@star.rl.ac.uk

Copyright © 2005 Council for the Central Laboratory of the Research Councils