; DELZN
;---------------------------------------------------------------
;! Determines residual atmosphere depth at zenith and clock errors
;# Task Calibration
;----------------------------------------------------------------
;;  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
;-----------------------------------------------------------------------
;---------------------------------------------------------------
DELZN     LLLLLLLLLLLLUUUUUUUUUUUU CCCCCCCCCCCCCCCCCCCCCCCCCCCCC
DELZN     Determines residual atmosphere depth at zenith
INNAME                             Input UV file name (name)
INCLASS                            Input UV file name (class)
INSEQ             0.0     9999.0   Input UV file name (seq. #)
INDISK                             Input UV file disk unit #
SNVER                              Input SN table version
                                   0 => last
GAINVER                            Input CL table to copy to
                                   CL#=high+1 and then correct
                                   0=>high
APARM                              control parameters:
                                   1: what data to plot
                                      0=>zenith atmos. delay
                                      1=>clock error
                                      2=>Reference antenna
                                   2: Number of terms at
                                      polynomial for zen. atm.
                                      0 => 3
                                   3: Number of terms at
                                      polynomial for clock
                                      0 => 2
                                   4: Create CL table?
                                      0 => not create
                                      1 => create
                                   5: What correction to make
                                      in CL table?
                                      0 => only atmosphere
                                      1 => atmosphere + clocks
                                   6: Number of iterations at
                                      editing the SN table
                                      0 => no editing
                                   7: Cutoff at the editing
                                      in r.m.s
                                      0 => 3
SOURCES                            Source list ' '=>all.
CALSOUR                            Calibrator list ' ' => all
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. 0=>all
ANTENNAS                           Antennas to select. 0=>all
SUBARRAY          0.0     9999.0   Subarray; 0 => 1.
NPLOTS                             Number of plots per page
                                     0=>5, -1=> Don't make plots
XINC              0.0     5000.0   Plot every XINC'th point
OPTYPE                             What data to read from the
                                   SN table:
                                   'DELA' => multi band delay
                                   '    ' => 'DELA'
                                   'PHAS' => phase
OUTFILE                            Table of zenith delays for
                                   selected set of antennas
                                   in format suitable for CLCOR
                                   option 'ATMO'.
PRTLEV                             0=> no printout.
                                   1 => print coefficients
                                   2 => print coefficients
                                        and their errors
                                        and rms of residual
DOHIST                             >0 => put coefficients in
                                         history file.
DOTV             -1.0       1.0    > 0 Do plot on the TV, else
                                   make a plot file
GRCHAN            0.0       8.0    Graphics channel 0 => 1.
BADDISK           0.0     9999.0   Disks to avoid for scratch
----------------------------------------------------------------
DELZN
Task:  This task estimates the zenith atmosphere delay dependence
       and clock error on time based on the SN table output for the
       selected calibrators.
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.
  SNVER......Input SN table version. If SNVER is equal zero or
             greater than the total number of the SN tables
             then SNVER is equal to the last existing SN table
  GAINVER....Input CL table version. If GAINVER is equal zero or
             greater than the total number of the CL tables
             then GAINVER is equal to the last existing CL table.
             The input CL table version (GAINVER) is copied to
             the output CL table version=(the last one+1), and then
             the output CL table is corrected.
  APARM......control parameters:
             1: what data to plot?
                0=> zenith atmosphere delay
                1=> clock error
                2=> reference antenna, if the reference antenna
                    is constant for the whole experiment
             2: Number of terms at the polynomial for zenith atmosphere
                presentation: linear =>2; quadratic => 3
                0 => 3
             3: Number of terms at the polynomial for clock
                presentation: linear =>2;
                0 => 2
             4: Create CL table?
                0 => not create
                1 => create
             5: What correction to make in CL table?
                0 => only atmosphere
                1 => atmosphere and clocks
             6: Number of iterations at editing the SN table
                0 => no editing
             7: Cutoff at the editing in r.m.s
                0 => 3
                At each iteration of the input data (SN table), the
                residual of each data point relatively solution is found.
                If the residual exceeds given number of R.M.S such a data
                are blanked and are not used in the following iteration.
  SOURCES....list of sources to process.
             ' ' = all; a "-" before any source name
             means ALL listed sources will be skipped.
  CALSOUR....list of calibrators to use.
             ' ' = all; a "-" before any calibrator name
             means ALL listed calibrators will be skipped.
  STOKES.....The desired Stokes type of the output data:
             'R', 'L', '  '=> all available.
  SELBAN.....Bandwidth to select (kHz)
  SELFREQ....Frequency to select (MHz)
  FREQID.....Frequency ID to select. 0=>all
  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. 0=>all
  ANTENNAS...A list of the antennas to be calibrated, plotted and
             corrected.  If any number is negative then all
             antennas listed are ignored.
             All 0 => use all antennas.
  SUBARRAY...The subarray to calibrate. Does only one at a time.
  NPLOTS.....Number of plots per page; 0=>5.
             If NPLOTS < 0, then no plots are made.
  XINC.......Plot every XINC'th point
  OPTYPE.....What data to read from the SN table:
             'DELA' => multi band delay
             '    ' => 'DELA'
             'PHAS' => phase. This option has not been tested yet
  OUTFILE....Table of zenith delays for selected set of antennas
             in format suitable for CLCOR option 'ATMO'.
  PRTLEV.....0 => Don't print the coefficients.
             1 => print the fitted coefficients for each antenna.
             2 => print coefficients and their errors and
                  rms of residual for each antenna.
  DOHIST.....if DOHIST > 0, the gain coefficients are written
	     into the history file.
  DOTV.......> 0 Do plot on the TV, else make a plot file
  GRCHAN.....Graphics channel 0 => 1.
  BADDISK....A list of disks on which scratch files are not to
             be placed.  This will not affect the output file.
----------------------------------------------------------------
DELZN:  Task to estimate the zenith delay and clock error dependence
        on time based on the CALIB output SN table for the selected
        calibrators.
Documenters: L.R. Kogan
Related Programs: CLCAL, ELINT

                            PURPOSE

   Model of the atmosphere delay and the clock error implemented into a
correlator never coincides with the actual values.
The task restores the residual atmosphere delay at the given elevation
observing calibrators at wide range of elevations. The task reads the
SN table, taking the information about the delays at given antenna
observing given calibrator. This delay is contributed by delay at the
atmosphere and delay due to the clock error.
   The task separates the atmosphere and clock delays using the
least square method to fit polynomial of the chosen degree to the clock
error and polynomial of the chosen degree for the zenith atmosphere delay.
   Having known these polynomials the task calculates the zenith
atmosphere delay and records it to the output file ready for use
as input file for the task CLCOR (option 'atmov').
   The  fitted zenith atmosphere delay and clock error is used to
correct the delay for target sources putting the correction to
the output CL table  by the same way CLCOR does at option 'atmov'.











