Speeding up repetitive task
The Big H wrote on Dec 16, 2009
I have to perform a large number of repetitive tasks on a large number of files. Basically I have to do the following:
imcopy DataFile[0][*,XX].fits SingleXX.fits
program1 SingleXX.fits
{inputs that program1 will prompt me for}
program2 SingleXX.fits
The commands, including the inputs to program1, will be the same every time except that XX will change (it's a different 2 or 3 digit number each time).
Is there a way I can store all these commands, including the inputs to program 1, in a single file that I can then call repeatedly. Basically I want to be able to enter something like "do 68", and it will copy column 68 out of the data file into the file Single68.fits and then run program1 on Single68.fits, enter all the inputs for program1, and then run program2 on Single68.fits. Is this possible?
imcopy DataFile[0][*,XX].fits SingleXX.fits
program1 SingleXX.fits
{inputs that program1 will prompt me for}
program2 SingleXX.fits
The commands, including the inputs to program1, will be the same every time except that XX will change (it's a different 2 or 3 digit number each time).
Is there a way I can store all these commands, including the inputs to program 1, in a single file that I can then call repeatedly. Basically I want to be able to enter something like "do 68", and it will copy column 68 out of the data file into the file Single68.fits and then run program1 on Single68.fits, enter all the inputs for program1, and then run program2 on Single68.fits. Is this possible?
Mike Fitzpatrick wrote on Dec 16, 2009
This is exactly what scripting is for, see the Script Guide to get started (http://iraf.net/irafdocs/script/).
Some details will depend on exactly what 'program1' is and how it takes input, let's assume a simple redirected text file would do: The 'do' script (called 'do.cl') would then look something like
At the CL prompt you would then declare the task as
and then execute using "do 68" as you suggest. Note that if you add or change parameters (any variable declared before the 'begin') you'll need to unlearn the parameters (i.e. "cl> unlearn do") to pick up the change.
-Mike
Some details will depend on exactly what 'program1' is and how it takes input, let's assume a simple redirected text file would do: The 'do' script (called 'do.cl') would then look something like
procedure do (num)
int num { prompt = "column number" }
begin
string data, single
int lnum
lnum = num # make local copy to avoid prompts
data = "DataFile[0][*," // lnum // ".fits"
single = "Single" // lnum // ".fits"
imcopy (data, single)
program1 (single, << "p1.txt")
program2 (single)
end
At the CL prompt you would then declare the task as
cl> task do = /path/do.cland then execute using "do 68" as you suggest. Note that if you add or change parameters (any variable declared before the 'begin') you'll need to unlearn the parameters (i.e. "cl> unlearn do") to pick up the change.
-Mike
Last post on Dec 16, 2009