; CLSMO
;---------------------------------------------------------------
;! smooths a calibration CL table
;# Task Calibration
;-----------------------------------------------------------------------
;;  Copyright (C) 1995, 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
;-----------------------------------------------------------------------
CLSMO     LLLLLLLLLLLLUUUUUUUUUUUU CCCCCCCCCCCCCCCCCCCCCCCCCCCCC
CLSMO     Task which smooths CL tables.
INNAME                             Input UV file name (name)
INCLASS                            Input UV file name (class)
INSEQ             0.0     9999.0   Input UV file name (seq. #)
INDISK            0.0        9.0   Input UV file disk unit #
SOURCES                            Source list ' '=>all.
DOBTWEEN        -1.0         1.0   > 0 -> smooth all sources
                                   together; else separate them
STOKES                             Stokes type to process
SELBAND                            Bandwidth to select (kHz)
SELFREQ                            Frequency to select (MHz)
FREQID                             Freq. ID to select, 0=>all
BIF               0.0      100.0   Lowest IF number 0=>all
EIF               0.0      100.0   Highest IF number 0=>all
TIMERANG                           Time range to use.
ANTENNAS                           Antennas to correct.
SUBARRAY          0.0     9999.0   Subarray; 0 => 1.
SAMPTYPE                           Interpolation function
BPARM                              Smoothing parameters
CUTOFF            0.0              Cutoff for functional forms
DOBLANK                            Blanked value interpolation
SMOTYPE                            Data to smooth
GAINVER           0.0              Input CL table to use
BADDISK           0.0     9999.0   Disks to avoid for scratch
----------------------------------------------------------------
CLSMO
Task:  This task smooths a CL table.  Blanked values can be
   interpolated.  Note that this task does relatively simple
   smoothing.  VLBI data with rates and delays should be smoothed with
   SNSMO rather than CLSMO and/or CLCAL.

   WARNING: THIS TASK WAS CHANGED 27 MARCH, 2003.  The smoothing no
   longer propagates good solutions indefinitely.  Instead the support
   size is strictly enforced.  Additional smoothing options are now
   available.  DOBLANK is now changed: if it is < 0, failed solutions
   are not fixed, if it is >= 0 they are fixed.  If it is <= 0, good
   solutions are smoothed, if it is > 0 good solutions are not
   altered.

Adverbs:
  INNAME.....Input UV file name (name).      Standard defaults.
  INCLASS....Input UV file name (class).     Standard defaults.
  INSEQ......Input UV file name (seq. #).    0 => highest.
  INDISK.....Disk drive # of input UV file.  0 => any.
  SOURCES....list of sources to process.
             '*' = all; a "-" before a source name
             means all except ANY source named.
  DOBTWEEN...> 0 => smooth all SN values regardless of source.
             <= 0 => smooth only SN values from the same source.
             Well-separated calibrators may have different phases just
             because of different atmosphere, so one would not want to
             smooth them together.  This can be achieved via doing one
             source at a time, but DOBTWEEN allows one to do all
             sources at once - at least if the choice is a simple one.
  STOKES.....The desired Stokes type of the output data:
             'R ', 'L ', 'RL', '  '=> 'RL'.
  FREQID.....Frequency identifier to select (you may determine
	     which is applicable from the OPTYPE='SCAN' listing
	     produced by LISTR).
  BIF........First IF to process. 0=>all.
  EIF........Highest IF to process. 0=>all higher than BIF
  TIMERANG...Time range of the data to be used. In order:
             Start day, hour, min. sec,
             end day, hour, min. sec. Days relative to ref.
             date.
  ANTENNAS...A list of the antennas to be modified.  If any
             number is negative then all antennas listed  are
             NOT to be modified.  All 0 => use all.
  SUBARRAY...The subarray to modify. Do only one at a time.
  SAMPTYPE...The type of smoothing.
                'BOX ' = boxcar smoothing - the default
                'MWF ' = Median window filter
                'GAUS' = Gaussian
                'EXP ' = Exponential
                'LINE' = Linear (1 - abs(t-t0)/sigma)
                '2PT ' = Two-point
                '2PTH' = Two-point + "Hanning"
  BPARM......Parameters for smoothing function.
             Function support full-width width in hours.
               (1) => support time for amplitudes,
               (2) => support time for phase,
               (3) => support time for rates
               (4) => support time for singleband delay
             Added parameter (FWHM) for GAUS, EXP, LINE
               (6) => smoothing FWHM time for amplitudes,
               (7) => smoothing FWHM time for phase,
               (8) => smoothing FWHM time for rates
               (9) => smoothing FWHM time for singleband delay
             In all cases, the substitution for blanked and good
             solutions is governed by DOBLANK (see below)
  CUTOFF.....Cutoff for GAUS, EXP, LINE.  The sum of the weighting
             function in the support region must exceed CUTOFF for the
             smoothed value to be regarded as valid.  Be careful, a
             value of 1.5 means that the sample itself must be good
             and the sum over other good samples in the support range
             must exceed 0.5.  < 1.e-6 => 1.e-6.
  DOBLANK....Blanked value interpolation:
             > 0: replace previously blanked values with smoothed
                  values, leave previously good values unchanged.
             = 0: replace previously blanked and previously good
                  values with smoothed values.
             < 0: replace previously good values with smoothed values,
                  leave previously blanked values blanked.
  SMOTYPE....Specified the data to be smoothed. '    '=>'AMPL'
            'AMPL' = amplitude smoothing only,
            'PHAS' = phase smoothing only,
            'BOTH' = amplitude and phase,
            'VLBI' = Delay and rate,
            'FULL' = sine, cosine, delay and rate.
  GAINVER....Version number of the input Cal. table to smooth.
             0 => Highest.  A new CL table is always written.
  BADDISK....A list of disks on which scratch files are not to
             be placed.  This will not affect the output file.
----------------------------------------------------------------


SAMPTYPE
    '2PT ' - interpolates in time between the two nearest neighbors of
             a flagged sample within the support time range
             This mode is really only for DOBLANK > 0.
    '2PTH' - interpolates in time between the two nearest neighbors of
             a sample within the support time range, then averages the
             sample (if good) with the interpolated value.  When there
             is only one good neighbor, the sample itself counts
             double if it is good.
