; MEDI
;---------------------------------------------------------------
;! combines four images by a variety of mathematical methods
;# TASK ANALYSIS POLARIZATION
;-----------------------------------------------------------------------
;;  Copyright (C) 1995, 1997, 1999, 2009
;;  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
;-----------------------------------------------------------------------
MEDI     LLLLLLLLLLLLUUUUUUUUUUUU CCCCCCCCCCCCCCCCCCCCCCCCCCCCC
MEDI: Task to combine four overlapping images
INNAME                             First image name
INCLASS                            First image class
INSEQ           0.0      9999.0    First image seq. #
INDISK          0.0         9.0    First image disk drive #
IN2NAME                            Second image name
IN2CLASS                           Second image class
IN2SEQ          0.0      9999.0    Second image seq. #
IN2DISK         0.0         9.0    Second image disk drive #
IN3NAME                            Third image name
IN3CLASS                           Third image class
IN3SEQ          0.0      9999.0    Third image seq. #
IN3DISK         0.0         9.0    Third image disk #
IN4NAME                            Fourth image name
IN4CLASS                           Fourth image class
IN4SEQ          0.0      9999.0    Fourth image seq. #
IN4DISK         0.0         9.0    Fourth image disk #
DOALIGN        -2.0         1.0    Should images be coincident?
                                   (See HELP.)
OUTNAME                            Output image name
OUTCLASS                           Output image class
OUTSEQ         -1.0      9999.0    Output image seq. #
OUTDISK         0.0         9.0    Output image disk drive #
BLC             0.0      4096.0    Bottom left corner
TRC             0.0      4096.0    Top right corner
APARM                              Parameters for algorithm:
                                     (1) - (4) scale and offset
                                     (8) > 0 => blank with 0.0
                                     (9)  Map1 clip level
                                     (10) Map2 clip level
                                     see HELP COMB
BPARM                              Noise/control parameters:
                                     (1)  Map noise level
                                          0 ignore noise
                                     (3)  > 0 => output
                                          deviation image
                                     (4)  < 0.5 => clip w inputs
                                          > 1.5 => clip w S/N
                                          else  => clip w noise
                                     (5)  minimum ok S/N   or
                                          maximum ok noise
                                     (6)  max output noise
                                          0 -> any
                                     see HELP MEDI
----------------------------------------------------------------
MEDI
Type: Task
      MEDI is a task in which four input images are combined on
      a pixel by pixel level to produce an output image and an
      optional deviation image.   The MEDIan, like the AVERAGE,
      is used to estimate the most likely (true) value of an
      observable.  The average is a more efficient estimator of a
      value when the noise of the measurement is gaussian
      distributed with zero mean.   However in the presence of
      out-lying data (noise), the MEDIAN is a more efficient
      estimator.
Adverbs:
  INNAME......First image name.     Standard defaults.
  INCLASS.....First image class.    Standard defaults.
  INSEQ.......First image seq. #.   0 => highest.
  INDISK......Disk drive # for the first image.  0 => any.
  IN2NAME.....Second image name.    Standard defaults.
  IN2CLASS....Second image class.   Standard defaults.
  IN2SEQ......Second image seq. #.  0 => highest.
  IN2DISK.....Disk drive # for the second image.  0 => any.
  IN3NAME.....Third image name.     Standard defaults.
  IN3CLASS....Third image class.    Standard defaults.
  IN3SEQ......Third image seq. #.   0 => highest.
  IN3DISK.....Disk # for Third image.  0 => any.
  IN4NAME.....Fourth image name.    Standard defaults.
  IN4CLASS....Fourth image class.   Standard defaults.
  IN4SEQ......Fourth image seq. #.  0 => highest.
  IN4DISK.....Disk # for Fourth image.  0 => any.
  DOALIGN.....Controls how the four images are to be aligned (see HELP
              DOALIGN).  True (>.1) means that the images must agree in
              their coordinates, though not necessarily in the reference
              pixel position.  Alignment is by coordinate values (if
              DOALIGN > -0.1) or by offsets from the reference pixel
              positions (if DOALIGN <= -0.1).  NOTE: all real axes (>1
              point) are aligned.  If DOALIGN = -2, the headers are
              ignored and the images are aligned at pixel (1,1,...).
  OUTNAME.....Output image name.    Standard defaults.
  OUTCLASS....Output image class.   Standard behavior with default =
              either the output STOKES in string form or the MEDI if
              the output STOKES is the same as the first input image.
              The noise image has the 6th character of class set to N.
  OUTSEQ......Output image seq. #.  0 => highest unique.
  OUTDISK.....Output disk number. 0 => highest with space.
  BLC.........Bottom left corner of the 1st input image. The other
              images are aligned by coordinates (see DOALIGN) on all
              axes having > 1 point.  The other images may have fewer
              real axes than the 1st.  The 4 windows must have the same
              dimension on the first 2 axes, but the task will select a
              smaller window than was specified if needed to overlap the
              4 images.
  TRC.........Top right corner of input images. (See BLC.)
  APARM.......Parameters needed for algorithm:
     APARM(1), APARM(2), APARM(3), APARM(4) used as above.
     APARM(8) >  0  => Use 0.0 for clipped & illegal values
              <= 0  => Use blanking for clipped & illegal values
     APARM(9) = Clip if Abs (MAP(1)) < APARM(9) - image units.
     APARM(10) = Clip if Abs(MAP(2)) < APARM(10) - image units.
          There are no defaults for APARM(9) and (10) and a zero
          value means no clipping.  Used only if BPARM(4) <= 0.5
  BPARM.......Parameters needed noise calculation and control:
     BPARM(1) = 1-sigma level on 1st input map.
     BPARM(3) = false (<= 0) => output normal image
              = true  (>  0) => output normal and sigma image
                Blanking is the same for both settings of B(3).
     BPARM(4) <= 0.5  => Blank output map using input map values
              else    => Blank output map using output map sigma
              >= 1.5  => Blank output map using output map S/N.
     BPARM(5) = Error on output map value above which output
                pixel is blanked (if BPARM(4) = 1) 0 -> ignore
              = S/N ratio of output map value below which output
                pixel is blanked (if BPARM(4) = 2) 0 -> ignore
     BPARM(6) = Maximum value of sigma to be output (used if > 0 and
                BPARM(3) > 0 only).

     NOTE: certain combinations of BPARM(3), BPARM(4) do not
     make much sense but all are allowed.  Output images
     which are constant will be written and a warning message will
     appear.

     Task MATHS is used to do mathematical operations on single images.
      MEDIAN Details:  In the case of one or two un-blanked pixel
      values, the MEDIAN is the average of the un-blanked values.
      The deviation image pixel is blanked.  In the case of 3
      un-blanked pixel values, the middle of the three values is
      the median, and the deviation image contains the average of
      the high and low pixels, minus the middle pixel.   In the
      case of 4 un-blanked input values, the median is the average
      of the middle two values and the deviation image is the
      average of the high and low values, minus the average of the
      middle two values.

      MEDI.FOR is a modified verison of COMB.FOR
      Created by Glen Langston  in 99 December
----------------------------------------------------------------
