View on GitHub

IRAF Community Distribution

IRAF maintained by the community

Home | Installation | Packages | X11IRAF | PyRAF | Forum

Wildcards and if statements

H.J. van Heerden wrote on May 10, 2007

Hi

I compiled scripts for different tasks. When I run the tasks, I want to check if the specific file is accessible. Thus created a list of image names, and then add different extentions to them, to see if they are there?

Thus.

imagenames -> imglist

fscanf (imglist, img)

if (access (img // "fit") || access (img // "mag"))
do something

The question that I would like to ask is how would I implement a wildcard?

i.e.
if (access(img // "fit*"))
or
if (access(img // "fit" // *))

Thanx
Pat

Mike Fitzpatrick wrote on May 10, 2007

Hi Pat,

The imaccess() function is what you should be using to check whether an image can be opened (doesn't require the extension), be neither the access() or imaccess() function can accept a file list or wildcard. To implement that you would need to probably use SECTIONS or FILES to expand the wildcard, pipe it to the COUNT task and then scan into a variable to look for a non-zero value, e.g.


sections ("img*.fits") | count STDIN | scan (nimages)
if (nimages > 0) {
    .....
}

or

sections ("img*.fits", >& "dev$null)
if (sections.nimages > 0) {
    ....
}


You can likewise just check the list of a file list. Note also that for images, the SECTIONS task has a 'nimages' parameter you can check directly.

Cheers,
-Mike

Last post on May 10, 2007