; TYSMO
;---------------------------------------------------------------
;! smooths and filters a calibration TY or SY table
;# Task Calibration VLA
;-----------------------------------------------------------------------
;;  Copyright (C) 2007, 2010
;;  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
;-----------------------------------------------------------------------
TYSMO     LLLLLLLLLLLLUUUUUUUUUUUU CCCCCCCCCCCCCCCCCCCCCCCCCCCCC
TYSMO     Task which smooths/filters system temperature 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
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 => all.
INEXT                              'TY' or 'SY' or choose
INVERS                             Input ?Y table; 0=>highest
OUTVERS                            Output ?Y table; 0=>new
APARM                              Range of allowed T's or P's
CPARM                              Clip wrt median filter
SAMPTYPE                           Smoothing function
BPARM                              Smoothing parameters
CUTOFF            0.0              Cutoff for functional forms
DOBLANK                            Blanked value interpolation
BADDISK           0.0     9999.0   Disks to avoid for scratch
----------------------------------------------------------------
TYSMO
Task: This task edits and smooths a TY or SY table.  For TY tables,
      the antenna and system temperatures are clipped to be in
      reasonable ranges.  For SY tables, the Pdif (noise tube on -
      noise tube off) and Psum (Pon+Poff) columns and their ratio
      (Psum/Pdif/2*Tcal = Tsys) are clipped to be in reasonable
      ranges.  Then they are time smoothed.  Blanked values will be
      interpolated or not under control of DOBLANK.   In TY tables.
      for some telescopes, Tsys and Tant are what they are labled to
      be.  For the VLA, Tsys is the nominal sensitivity and Tant is
      some form of system temperature.  The SY table is an EVLA
      concept and contains Pdif, Psum, and PostGain columns.  At the
      synchronous detector, the measured power is Pon with the noise
      tube on and Poff with the noise tube off and PostGain is any
      gain that follows this detector.  Then Pdif = PostGain * (Pon -
      Poff) and Psum = PostGain * (Pon + poff).  The ratio, Psum/Pdif
      is twice the Tsys divided by the noise tube Tcal.

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 TY/SY values regardless of source.
             <= 0 => smooth only TY/SY values from the same source.
             Well-separated calibrators may have different spill-over
             and background temperatures, 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.
  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 reference 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.  0 -> all.
  INEXT......'SY' or 'TY' else select whichever is present and die if
             both are present.
  INVERS.....input version number of the TY/SY table to smooth.
             0 => Highest.
  OUTVERS....output version of TY/SY table to write.
             0 => create new table (recommended)
  APARM......Data can first be clipped on the actual values:
               (1) => min Tsys or Pdif            0 => zero
               (2) => min Tant or Psum            0 => zero
               (3) => min Psum/Pdif/2*Tcal = Tsys 0 => zero
               (6) => max Tsys or Pdif            0 => very large
               (7) => max Tant or Psum            0 => very large
               (8) => max Psum/Pdif/2*Tcal = Tsys 0 => very large
  CPARM......Data can then be clipped by comparison with a median
             window filter.  The width of the Median window is
             specified in CPARM(1-2 or 3).  The maximum allowed
             deviation is given in CPARM(6-7 or 8).
             0 => all values are OK.
               (1) => smoothing time for Tsys or Pdif (minutes),
               (2) => smoothing time for Tant or Psum (minutes),
               (3) => smoothing time for Psum/Pdif/2*Tcal = Tsys (min)
               (6) => max deviation for Tsys or Pdif
               (7) => max deviation for Tant or Psum
               (8) => max deviation for Psum/Pdif/2*Tcal = Tsys
  SAMPTYPE...The type of smoothing to follow clipping (if any)
                'BOX ' = boxcar smoothing (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: note that we cannot
             smooth Tsys in SY tables since that is the ratio of the
             two measured quantities.
             Function support full-width width in minutes
               (1) => support time for Tsys or Pdif,  (0 -> skip)
               (2) => support time for Tant or Psum,  (0 -> skip)
             Added parameter (FWHM) for GAUS, EXP, LINE in minutes
               (6) => smoothing FWHM time for Tsys or Pdif,
               (7) => smoothing FWHM time for Tant or Psum,
             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.
  BADDISK....A list of disks on which scratch files are not to be
             placed.  This will not affect the output file.
----------------------------------------------------------------
