; VLBACPOL
;---------------------------------------------------------------
;# PROCEDURE VLBI
;! Procedure to calibrate cross-polarization delays
;-----------------------------------------------------------------------
;;  Copyright (C) 2001
;;  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
;-----------------------------------------------------------------------
VLBACPOL  LLLLLLLLLLLLUUUUUUUUUUUU CCCCCCCCCCCCCCCCCCCCCCCCCCCCC
VLBACPOL: Procedure to calibrate cross polarization delays
INNAME                             UV file name (name)
INCLASS                            UV file name (class)
INSEQ              0.0      9999.0 UV file name (seq. #)
INDISK             0.0         9.0 UV file disk drive #
OUTDISK                            Disk for temporary files
FLAGVER                            Flagging table
GAINUSE                            Prior calibration CL
                                   NO DEFAULT
SUBARRAY          0.0       99.0   Selected subarray
BASELINE                           List of antennas; MUST
                                   CONTAIN REFANT
REFANT                             Reference antenna; MUST BE
                                   HIGHEST OR LOWEST NUMBERED
                                   ANTENNA IN BASELINE LIST
CALSOUR                            Calibrator source to use
TIMERANG                           select time range with good
                                   SNR for RL and LR corr.
SOLINT                             Solution interval (min)
                                     0=> 10 minutes
DPARM                              for strong sources, it is
                                   only necessary to set
                                   DPARM(4)=the int. time (sec).
                                   DPARM(1) and (8) are
                                   automatically set by
                                   procedure.
                                   for rest see HELP VLBACPOL
OPCODE                             'AVIF' => avg SB delays
BADDISK                            Disk drive #'s to avoid
----------------------------------------------------------------
VLBACPOL
Procedure:  This procedure uses a selected subset of a uv data set to
   determine cross polarized multi- and single-band delays.  The
   average single-band and multi-band delays will be written into an
   SN and CL table.  See EXPLAIN VLBACPOL for details.

   Before attempting to use VLBACPOL the RUN file VLBAUTIL must be run
   to define the procedure.  This is done by:
       >RUN VLBAUTIL
   and only needs be done once.

   VLBACPOL creates several temporary files which it will destroy if
   able.  The names of these files are fixed and must be destroyed if
   a previous attempt at VLBACPOL failed.  Also the output files must
   not exist before running VLBACPOL.  To execute the procedure simply
   type:
       >VLBACPOL

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.
  OUTDISK....Disk for temporary files 0=>INDISK.
  FLAGVER....Flag table version to apply
  GAINUSE....CL table from prior calibration to apply before
             determining solutions.  There is no default.
  SUBARRAY...Subarray to use.
  BASELINE...List of antennas, normally the reference antenna
             and the others to be used, see EXPLAIN VLBACPOL.
             NOTE: the reference antenna should have a number
             either above or below ALL other antenna numbers.
  REFANT.....Reference antenna.  MUST BE HIGHEST OR LOWEST NUMBERED
             ANTENNA LISTED IN BASELINE
  CALSOUR....Calibrator source(s) to use.
  TIMERANG...Time range of the data subset.
  SOLINT.....The FRING solution interval (min), 0=> 10 minutes
  DPARM......Delay rate parameters.
  DPARM(1)...Number of baseline combinations to use in the initial,
             coarse fringe search (1-3).  Larger values increase the
             point source sensitivity but reduce the sensitivity to
             extended sources when an accurate model is not available.
             0=>3.  THIS PARAMETER IS AUTOMATICALLY SET TO 1 IN THIS
             PROCEDURE!!!
  DPARM(2)...The delay window to search (nsec) centered on 0 delay.
             0 => full Nyquist range defined by the frequency spacing.
             If DPARM(2) < 0.0 no delay search will be performed.
  DPARM(3)...The rate window to search (mHz) centered on 0 rate.
             0 => full Nyquist range defined by the integration time.
  DPARM(4)...The minimum integration time of the data (sec);
             0 => search the data to find the minimum integration
                  time.
             The correct minimum of all baselines should be supplied.
  DPARM(5)...If > 0 then don't do the least squares solution. If the
             least squares solution is not done then only the coarse
             search is done and much less accurate solutions are
             obtained.
  DPARM(6)...If > 0 then the output data will not be averaged in
             frequency else, all frequencies in each IF will be
             averaged.  Affects single source files only.
  DPARM(7)...If > 0 then the phase, rate and delays will not be
             re-referenced to a common antenna.  This option is only
             desirable for VLBI polarization data.
  DPARM(8)...DPARM(8)>0 allows zero'ing of RATE, DELAY, and/or PHASE
             solutions.  ** Note that the ZEROing is done _AFTER_ the
             FRING solution is found,  this is not the mechanism for
             turning off the DELAY, RATE, or PHASE search,  see
             DPARM(2-3) for that capability. **
             DPARM(8) value   zero RATES?  zero DELAYs?  zero PHASEs?
                  0              No           No              No
                  1             Yes           No              No
                  2              No          Yes              No
                  3             Yes          Yes              No
                  4              No           No             Yes
                  5             Yes           No             Yes
                  6              No          Yes             Yes
                  7             Yes          Yes             Yes
             THIS PARAMENTER IS AUTOMATICALLY SET TO 1 IN THIS
             PROCEDURE!!!
  OPCODE.....'AVIF' means average single band delays
             corrections in IF, else do each IF independently.
             The best value depends on the SNR.
  BADDISK...Disk drive #'s to avoid for scratch files
----------------------------------------------------------------
VLBACPOL:  Make an SN for the calibration of cross polarized
          delays.
Documentor: W. D. Cotton
Related Programs: SWPOL, FRING, POLSN, CLCAL

      Calibration of cross polarized delays

   This procedure will take a selected subset of a uv data set
and determine the corrections needed to remove differences in
single and multiband delays for the right and left handed
systems.  The output is an SN and CL. The output SN and CL tables
will be written to the input data set and on successful completion of
VLBACPOL will be the highest version SN/CL table.  Cross polarized
rate errors are assumed to be zero.

This should run after correcting the instrumental delays (VLBAPCOR)
and before or after fringe fitting.

  The basic steps of this procedure are the following:

1) Run UVCOP to select a short section of data for one or more
antennas and the reference antenna.  This time/source/baseline
combination should have a reasonable SNR for the RL and LR
correlations.

2) Run FRING on this segment of data to obtain corrections for
the parallel fringes.  Use APARM=2,0; DOCAL=1; SNVER=1. Other
FRING parameters are as passed to the procedure either
explicitly in the inputs file or implicitly by the appropriate
adverb values.

3) Use CLCAL to apply this SN table to the CL table used to
calibrate the input to FRING.

4) Use SWPOL to swap the polarizations of the reference antenna.
Set ANTENNAS = ref. antenna; DOCALIB = 1

5) Run FRING as before but on the output of SWPOL.  Do this once for
each antenna in the BASELINE array with the reference antenna.

6) Run POLSN on the SN table produced by FRING.

7) Use TACOP to copy the SN table produced by POLSN to the
original data set.

8) Run CLCAL to apply this SN table to the CL table given in
   GAINUSE.  There are 2 lines at the end which will state
   which SN and CL tables contain the corrections.

   This procedure will create a number of temporary files on
OUTDISK.   These temporary files will have name 'CROSSPOL TMP'
and should be deleted by the procedure on successful completion.
As the names are fixed any residual files from a previous run of
CROSSPOL should be deleted before executing the procedure.
