Writing tasks that accept lists and wildcards
sirmarcos wrote on May 24, 2006
What is the trick to allow a task to accept wildcards like file*imh or @filelist?
I have written a very basic task that just passes arguments to another iraf task. I call it qcont and it just takes the file, does a continuum on it with a 1st order spline3 and makes the output file_norm. It works like a charm on one file, but it's unclear to me how I alter the task to accept a list of files... any help or pointers would be appreciated.
I have written a very basic task that just passes arguments to another iraf task. I call it qcont and it just takes the file, does a continuum on it with a 1st order spline3 and makes the output file_norm. It works like a charm on one file, but it's unclear to me how I alter the task to accept a list of files... any help or pointers would be appreciated.
Mike Fitzpatrick wrote on May 24, 2006
Hi Marcos,
I assume we're talking about a CL script? If so the trick is to use something like the SECTIONS (or FILES if it isn't an image) task to expand the template, e.g.
Note some tasks already take image lists and you can just pass it through, other tasks (or pure sccript code) however don't and you need to loop like this.
Cheers,
-Mike
I assume we're talking about a CL script? If so the trick is to use something like the SECTIONS (or FILES if it isn't an image) task to expand the template, e.g.
procedure qcont (images)
string images { prompt = "Image list" }
begin
string imgfile, img
# Exapnd image template
imgfile = mktemp ("tmp$qcont") # get temp file
sections (images, opt="full", > imgfile)
list = imgfile
while (fscan (list, img) != EOF) {
.....stuff
}
end
Note some tasks already take image lists and you can just pass it through, other tasks (or pure sccript code) however don't and you need to loop like this.
Cheers,
-Mike
sirmarcos wrote on May 24, 2006
Thanks. That's pretty much what I was asking ... I just wanted to be able to add the @list functionality that most tasks have. And yes, it was a cl script I had written, so the input was just a string, the file name.
I've written cl scripts that accept lists using the fscan loop like you mentioned, but then the input has to be a list, so I'm guessing the "is it a list or is it a file" determination based on whether the @ is there or not is just a matter of parsing the string and using if statements to handle the file as either an image or a list?
I've written cl scripts that accept lists using the fscan loop like you mentioned, but then the input has to be a list, so I'm guessing the "is it a list or is it a file" determination based on whether the @ is there or not is just a matter of parsing the string and using if statements to handle the file as either an image or a list?
Mike Fitzpatrick wrote on May 24, 2006
The SECTIONS task will expand file templates and @files automatically, i.e.
sections foo.fits
sections @flist
sections foo*.fits
will expand the single file name, the contents of the @file, or the wildcard template. Note however that
section flist
will return just 'flist' and not the expanded contents as if you'd used '@flist'.
-Mike
sections foo.fits
sections @flist
sections foo*.fits
will expand the single file name, the contents of the @file, or the wildcard template. Note however that
section flist
will return just 'flist' and not the expanded contents as if you'd used '@flist'.
-Mike
Last post on May 24, 2006