View on GitHub

IRAF Community Distribution

IRAF maintained by the community

Home | Installation | Packages | X11IRAF | PyRAF | Forum

Iraf if statements

Thomas Amby Ottosen wrote on Aug 29, 2009

Hi there,

I'm relatively new with IRAF and I have taken on the task of making an automatic pipeline for an imaging instrument. Therefore I encountered a problem with the IF-statement. Since I want to constrain my data selection with more than one parameter. I managed to do what I wanted with two IF-statements. i.e.

tmpl = mktemp("tmp$idedither")
  sections(ini,option="fullname", > tmpl)
  list1 = tmpl
  while( fscan(list1, fname) != EOF) {
        # --> Read from header...
        if (header == yes) {
                imgets(fname//"[1]",keyword1)
                exptime = real(imgets.value)
                imgets(fname//"[1]",keyword2)
                stfltpos = int(imgets.value)
                if (stfltpos == 4) {
                        if (exptime > 11) {
                        print((fname), >> "Rflat.lst")
                        }
                }
        }
  }

Where as in any other programing language I know of it is possible to do the same thing in the following way:

tmpl = mktemp("tmp$idedither")
  sections(ini,option="fullname", > tmpl)
  list1 = tmpl
  while( fscan(list1, fname) != EOF) {
        # --> Read from header...
        if (header == yes) {
                imgets(fname//"[1]",keyword1)
                exptime = real(imgets.value)
                imgets(fname//"[1]",keyword2)
                stfltpos = int(imgets.value)
                if (stfltpos == 4 && exptime > 11) {
                        print((fname), >> "Rflat.lst")
                }
        }
  }


So my question is very simple is this at all possible in IRAF, I looked up the if syntax ~ http://iraf.net/irafhelp.php?val=if&help=Help+Page from that I could not determine if it was possible or not.

James Turner wrote on Aug 29, 2009

You should be able to use "&&" in a CL if statement.

I can't immediately spot anything wrong in your second example. What happens when you run it?

James.

Thomas Amby Ottosen wrote on Aug 29, 2009

When I run the second example I get no images printed to my list, but when I'm doing it in two if-statements I get exactly the images I want, which I find a bit peculiar.

- Thomas

Francisco Valdes wrote on Aug 29, 2009

Hi,

There is a peculiarity (or I would agree a bug) that if statements when executed from the command line or a script which consists of command lines (as opposed to a "procedure" script) they must end with an else or a semi-colon. For example,


tmpl = mktemp("tmp$idedither")
  sections(ini,option="fullname", > tmpl)
  list1 = tmpl
  while( fscan(list1, fname) != EOF) {
        # --> Read from header...
        if (header == yes) {
                imgets(fname//"[1]",keyword1)
                exptime = real(imgets.value)
                imgets(fname//"[1]",keyword2)
                stfltpos = int(imgets.value)
                if (stfltpos == 4 && exptime > 11) {
                        print((fname), >> "Rflat.lst")
                }
                ;
        }
        ;
  }


If this is not done things may behave mysteriously. This is my guess at the problem.

Yours,
Frank Valdes

Last post on Aug 29, 2009