; VLACLCAL
;---------------------------------------------------------------
;! Runs CLCAL and prints the results with LISTR
;# PROCEDURE CALIBRATION
;-----------------------------------------------------------------------
;;  Copyright (C) 1995, 2001, 2005-2006
;;  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
;-----------------------------------------------------------------------
;---------------------------------------------------------------
VLACLCAL  LLLLLLLLLLLLUUUUUUUUUUUU CCCCCCCCCCCCCCCCCCCCCCCCCCCCC
VLACLCAL  Procedure to run CLCAL and LISTR for VLA data.
                                   Use RUN VLAPROCS first
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 to calibrate
SOUCODE                            Source "Cal codes"
CALSOUR                            Cal sources for calibration
QUAL            -10.0              Source qualifier -1=>all
CALCODE                            Calibrator code '    '=>all
FREQID                             Unique frequency code
TIMERANG                           Time range to calibrate
SUBARRAY          0.0     1000.0   Subarray, 0=>all
INTERPOL                           Interpolation function
SAMPTYPE                           Smoothing function
DOBLANK                            Blanked value interpolation
DOBTWEEN        -1.0         1.0   > 0 -> smooth all sources
                                   together; else separate them
SMOTYPE                            Data to smooth
BPARM                              Smoothing parameters
ICUT              0.0              Cutoff for functional forms
GAINVER                            Input Cal table 0=>1
GAINUSE                            Output CAL table 0=>2
REFANT                             Reference antenna 0=>pick.
DOPRINT                            >0 Print messages to a file
                                   or to the printer.
OUTPRINT                           Printer disk file to save
BADDISK           0.0     9999.0   Disks to avoid for scratch
----------------------------------------------------------------
VLACLCAL
Type: Procedure
Use:  Runs CLCAL and prints the results with LISTR:
          CLCAL: Manages SN and CL tables.
      For OPCODE='CALI' the merge operation
      will be done,if necessary, and SN table will be optionally
      smoothed and applied to the specified entries in CL table
      GAINVER and written to CL table GAINUSE.

          LISTR: after CLCAL successfully finishes LISTR is run
      to print the results from the output CL table.  Only
      SOURCES specified for CLCAL will be listed.

          Before attempting to use VLACLCAL the RUN file
      VLAPROCS must be run to defing the adverbs used and to
      read in the procedure.  This is done by:
      >RUN VLAPROCS
      and only needs be done once.
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 whose CL table entries are to be
             updated.  '*' = all; a "-" before a source name
             means all except ANY source named.
  SOUCODE....Sources may be selected on the basis of the
             calibrator code given in the SU table.
                  '    ' => any calibrator code selected
                  '*   ' => any non blank code (cal. only)
                  '-CAL' => blank codes only (no calibrators)
                  anything else = calibrator code to select.
             NB: The SOUCODE test is applied in addition to the
             other tests, i.e. SOURCES and QUAL, in the
             selection of sources to process.
  CALSOUR....List of calibrators to use for updating the CL
             table.  '*' = all; a "-" before a calibrator name
             means all except ANY calibrator named.
  QUAL.......Only sources with a source qualifier number in the
             SU table matching QUAL will be used if QUAL is not
             -1.  QUAL affects the selection of both the list of
             sources and the list of calibrators.
  CALCODE....Calibrators may be selected on the basis of the
             calibrator code given in the SU table.
                  '    ' => any calibrator code selected
                  '*   ' => any non blank code (cal. only)
                  '-CAL' => blank codes only (no calibrators)
                  anything else = calibrator code to select.
             NB: The CALCODE test is applied in addition to the
             other tests, i.e. SOURCS and QUAL, in the
             selection of sources to process.
             CALCODE affects only the selection of calibrators.
  FREQID.....Frequency selection. Defaults to 1.  This is what
             is required in most continuum cases.
  TIMERANG...Time range of the data to be calibrated. In order:
             Start day, hour, min. sec,
             end day, hour, min. sec. Days relative to ref.
             date.
  SUBARRAY...Subarray number to copy. 0=>all.
  INTERPOL...The type of interpolation to be applied to the
             SN table:
             '    ' = linear interpolation but no smoothing,
             '2PT ' = linear interpolation but no smoothing,
             'SELF' = do 2PT but only using SN entries from the same
                      source.  (New mode starting 20 April 2004.)
             'SELN' = Use only SN solution from same source which
                      is closest in time.  (This mode was called SELF
                      before 20 April.)
             'SIMP' = Simple linear phase connection between SN phase
                      entries, assumes phase difference less than 180
                      degrees.
             'AMBG' = Linear phase connection using rates to resolve
                      phase ambiguities.
             'CUBE' = As AMBG but fit third order polynomial to phases
                      and rates.
             'POLY' = Fit a polynomial to the SN rates and delays.
                      Use the integral of the rate polynomial for the
                      phases.  (CUTOFF sets the degree.)
  SAMPTYPE...The type of smoothing: ' ' => none
                '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"
  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.
             Note that DOBLANK >= 0 requires a SMOTYPE that smooths
             both phase and amplitude, namely BOTH or FULL
             NOTE: >=0 Forces SMOTYPE = 'FULL' unless BOTH is
             specified.
  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.
  SMOTYPE....Specified the data to be smoothed. '    '=>'FULL'
            'AMPL' = amplitude smoothing only,
            'PHAS' = phase smoothing only,
            'BOTH' = Sine and cosine (amplitude and phase),
            'VLBI' = Delay and rate,
            'FULL' = sine, cosine, delay and rate.
  BPARM......Parameters for smoothing function.
             Function support full width in hours.
               (1) => support time for amplitudes,
               (2) => support time for phase,
               (3) => support time for rates
               (4) => support time for singleband delay
               (5) => support time for multiband delay
             Added parameter (FWHM) for GAUS, EXP, LINE in hours
               (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
              (10) => smoothing FWHM time for multiband delay
             In all cases, the substitution for blanked and good
             solutions is governed by DOBLANK (see below)
  ICUT.......Cutoff for GAUS, EXP, LINE.  The sum of the weighting
             function in the support region must exceed ICUT 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.
  GAINVER....specifies the input version of the Cal (CL) table
             to which the SN tables will be applied.
              0 => 1
  GAINUSE....version number of the Cal. table to use after the
             application of the SN tables and is applied to the
             data.  This table will be updated  with the SN
             tables.  0 => 2.
             Note: modifying version 1 is disallowed.
  REFANT.....Reference antenna to use.  All phase-like values
             in the combined SN table will be referenced to
             this antenna. 0=> use the one used in the most
             solutions.
  DOPRINT....If > 0 print inputs to VLACLCAL and performs a LISTR (see
             EXPLAIN VLACLCAL) to either the printer or to a
             file specified in OUTPRINT.  Note that if this value is
             positive you may have to hit return for the procedure
             to continue running after it does the INPUTS command.
  OUTPRINT...Disk file name in which to save output.  ' ' => print
             to printer - When OUTPRINT is not blank, outputs are
             printed to a file.  Multiple uses of the same file
             are concatenated.
  BADDISK....A list of disks on which scratch files are not to
             be placed.  This will not affect the output file.
----------------------------------------------------------------
VLACLCAL:           Procedure to run CLCAL with fewer inputs and
                    possibly print the results with PRTMSG and LISTR.
Documenter:         Amy Mioduszewski
Related Programs:   CLCAL, LISTR, PRTMSG

STEPS in VLACLCAL:

Note that if DOPRINT<=0 then only step 1 is performed.

1.  RUN CLCAL, with VLACLCAL inputs and:
      OPCODE 'CALI'
      CUTOFF= 0

2.  If DOPRINT>0 then run LISTR with VLACLCAL inputs and:
       OPTYPE 'gain'
       INEXT 'CL'
       BIF 1; EIF 2
       STOKES 'HALF'
       DPARM 5, 1, 0

If you would like to run with DOPRINT=1 but would still like to
keep your old CLCAL messages.  Start AIPS in another window to
create another POPS number (when you run AIPS and see an "AIPS 2",
2 is the POPS number) and run VLACLCAL in that window.  Only the
messages from that POPS number will be deleted.
