; SCLIM
;---------------------------------------------------------------
;! operates on an image with a choice of mathematical functions
;# Task Analysis Plot
;-----------------------------------------------------------------------
;;  Copyright (C) 2003
;;  Associated Universities, Inc. Washington DC, USA.
;;
;;  This program is free software; you can redistribute it and/or
;;  modify it under the terms of the GNU General Public License as
;;  published by the Free Software Foundation; either version 2 of
;;  the License, or (at your option) any later version.
;;
;;  This program is distributed in the hope that it will be useful,
;;  but WITHOUT ANY WARRANTY; without even the implied warranty of
;;  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;;  GNU General Public License for more details.
;;
;;  You should have received a copy of the GNU General Public
;;  License along with this program; if not, write to the Free
;;  Software Foundation, Inc., 675 Massachusetts Ave, Cambridge,
;;  MA 02139, USA.
;;
;;  Correspondence concerning AIPS should be addressed as follows:
;;         Internet email: aipsmail@nrao.edu.
;;         Postal address: AIPS Project Office
;;                         National Radio Astronomy Observatory
;;                         520 Edgemont Road
;;                         Charlottesville, VA 22903-2475 USA
;-----------------------------------------------------------------------
SCLIM     LLLLLLLLLLLLUUUUUUUUUUUU CCCCCCCCCCCCCCCCCCCCCCCCCCCCC
SCLIM: Task to operate on an image with mathematical functions
INNAME                             Input image name
INCLASS                            Input image class
INSEQ           0.0      9999.0    Input image seq. no.
INDISK          0.0         9.0    Input image disk no.
OUTNAME                            Output image name
OUTCLASS                           Output image class
OUTSEQ          0.0      9999.0    Output image seq. #
OUTDISK         0.0         9.0    Output image disk drive
BLC                                BLC of input image
TRC                                TRC of input image
PIXRANGE                           Allowed range input values
OPCODE                             Operator code:
                                   LOG, ALOG, LOGN, EXP,
                                   POWR
CPARM                              CPARM(1:5):
                                   Output map is formed from
                                   C1+C2*OP[C3*IN+C4]
                                   except for 'POWR' when its
                                   C1+C2*[C3*IN+C4]**C5
---------------------------------------------------------------
SCLIM
Type: Task
Use:  SCLIM is similar to MATHS but is really designed to produce
      images scaled from 0 to 1 with blanked pixels set to zero and
      clipped pixels set either to 1 or 0.  It operates on an image,
      pixel by pixel, with a mathematical function.  Current choices
      are LOG, LOGN, ALOG, EXP, and POWR.  The output images are
      mostly used as inputs to LAYER.
Adverbs:
INNAME........Input image name
INCLASS.......Input image class
INSEQ.........Input image seq. #
INDISK........Input image disk drive #
OUTNAME.......Output image name
OUTCLASS......Output image class, blank = OPCODE
OUTSEQ........Output image seq. #
OUTDISK.......Output image disk drive #
BLC...........BLC of input image
TRC...........TRC of input image
PIXRANGE......Clip image below PIXRANGE(1) and above PIXRANGE(2).  The
              former end up 0.0 and the latter end up either 1.0 or
              0.0 depending on CPARM(6).  If PIXR(2) <= PIXR(1), the
              full range of the input image is used.
OPCODE........LOG and LOGN:
                These take the base 10 and base e (natural)
                logarithm of the input image.  If the input
                pixel is <= 0.0, then the output pixel is
                blanked.
                OUT = C(1) + C(2) * OP [C(3) * (IN + C(4))]

              ALOG and EXP:
                These take the base 10 and base e (natural)
                anti-logarithm of the input image.
                OUT = C(1) + C(2) * OP [C(3) * (IN + C(4))]

              POWR:
                Each OUTput pixel is formed from the INput
                pixel according to:
                OUT = C(1) + C(2)*[C(3) * (IN+C(4))]**C(5)
                Let X = C(3)*(IN+C(4))   The output pixel is
                blanked when X is negative, or when X and C(5)
                are both zero.  The special case of X < 0 and
                C(5) = 2.0 is trapped and blanked output pixel
                that would usually occur is avoided.

              OUT is then scaled linearly from 0 to 1.0.

              Special OPCODEs to match FUNCTYPEs in TVLOD are also
              allowed.  They are 'LN', 'NE', 'SQ', 'NQ', 'LG', NG'.
              See EXPLAIN.  CPARM(1)-CPARM(5) are ignored with these
              OPCODEs.

CPARM.........C(1:5):  Additive and multiplicative factors for
              the input image.  The defaults depend on the
              operator

              For OP = LOG, ALOG, LOGN, EXP, POWR

              C(2) = 0   ->   C(2) = 1
              C(3) = 0   ->   C(3) = 1

              C(6) <= 0 -> values above PIXRANGE(2) end up 1
              C(6) >  0 -> values above PIXRANGE(2) end up 0
----------------------------------------------------------------

The normal transfer functions used in TV loading are 'LN', 'NE', 'SQ',
'NQ', 'LG', NG'.  The translations of these into the terms of SCLIM
are as follows with PIXRANGE(1) called P1 and PIXRANGE(2) called P2.

Linear 'LN' :
   OPCODE = 'POWR'      but    OPCODE = 'POWR'   also works
   CPARM(1) = 0                CPARM(1) = 0
   CPARM(2) = 1                CPARM(2) = 1
   CPARM(3) = 1/(P2-P1)        CPARM(3) = 1
   CPARM(4) = -P1/(P2-P1)      CPARM(4) = 0
   CPARM(5) = 1                CPARM(5) = 1

Negative linear 'NE' :
   OPCODE = 'POWR'
   CPARM(1) = 0
   CPARM(2) = 1
   CPARM(3) = -1/(P2-P1)
   CPARM(4) = P2/(P2-P1)
   CPARM(5) = 1

Square root 'SQ' :
   OPCODE = 'POWR'
   CPARM(1) = 0
   CPARM(2) = 1
   CPARM(3) = 1/(P2-P1)
   CPARM(4) = -P1/(P2-P1)
   CPARM(5) = 0.5

Negative square root 'NQ' :
   OPCODE = 'POWER'
   CPARM(1) = 0
   CPARM(2) = 1
   CPARM(3) = -1/(P2-P1)
   CPARM(4) = P2/(P2-P1)
   CPARM(5) = 0.5

Logarithmic 'LG' :
   OPCODE = 'LOGN'
   CPARM(1) = 0.0
   CPARM(2) = 1.0/ln(6501.0)
   CPARM(3) = 6500.0/(P2-P1)
   CPARM(4) = 1.0 - 6500.0 P1/(P2-P1)
   CPARM(5) = 0.0

Negative logarithmic 'NG' :
   OPCODE = 'LOGN'
   CPARM(1) = 0.0
   CPARM(2) = 1.0/ln(6501.0)
   CPARM(3) = -6500.0/(P2-P1)
   CPARM(4) = 1.0 + 6500.0 P2/(P2-P1)
   CPARM(5) = 0.0
