View on GitHub

IRAF Community Distribution

IRAF maintained by the community

Home | Installation | Packages | X11IRAF | PyRAF | Forum

Problem with apparently simple CL script

Stephen Walton wrote on Feb 07, 2006

Hello. I ran the apparently simple script which follows:

minmax('tmp_image', verbose=no, update=no, force=yes)
=minmax.minval
if (real(minmax.minval) < 0) {
imarith('tmp_image', '+', real(minmax.minval), 'tmp_image')
}

by putting these lines into a file called 't.cl' and doing

cl> cl < t.cl

The "=minmax.minval" prints out -295. but the IF is not taken. What am I doing wrong? I have tried adding and removing the real() function call around minmax.minval, and adding 'cache minmax' to the top of the script, but these changes make no difference.

pyrafuser wrote on Feb 07, 2006

It's a hack, but if you add a print statement (ie print "") at the end of your script, it should work.

Mike Fitzpatrick wrote on Feb 07, 2006

Think of the cl redirection as just a way of redirecting your keyboard input, then try simply typing your script in at the CL prompt to see what's going on. You'll notice that after you get to the closing brace of the 'if' the CL prompts again with the ">>>" indicating it is expecting more input. When redirecting it sees the EOF and so doesn't compile the block, what it is actually expecting is some token to tell it that the 'if' is complete or is part of an 'if-else' block. The hack print stmt from pyrafuser terminates the if block, the more common trick people have learned over the years is to terminate an if with a ';'.

Note you can accomplish the same thing with IMEXPR, e.g.

minmax ('tmp1', update+, force+)
imexpr ("(a<0)?(a+b):a", 'tmp2', a='tmp1', b=a.i_minpixval)

This costs an extra temp image and is somtimes a no-op but I mention it FYI.
Also, if you are simply trying to shift all the values to be ositive then I think you want "abs(minpix)" in the expression, otherwise you're effectively subtracting the negative min value from everything.

-Mike

Last post on Feb 07, 2006