; CLVLB
;---------------------------------------------------------------
;! Corrects CL table gains for pointing offsets in VLBI data
;# Task Calibration VLBI
;-----------------------------------------------------------------------
;;  Copyright (C) 2013
;;  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
;-----------------------------------------------------------------------
CLVLB     LLLLLLLLLLLLUUUUUUUUUUUU CCCCCCCCCCCCCCCCCCCCCCCCCCCCC
CLVLB  Corrects CL table gains for pointing offsets in VLBI data
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 #
FREQID            0.0              Frequency ID number:  0 -> 1
SUBARRAY          0.0              Subarray: 0 -> 1
GAINVER                            Input CL table version
GAINUSE                            Output CL table version
CUTOFF           -1.0              Minimum allowed beam
CALIN
                                   Text file containing antenna
                                   beam parameters
TT               -1.0        1.0   > 0, use alternative geometry
                                   computation (Enno), else use
                                   Eric's method
BIF                                DEBUG: print BIF when > 0
ANTENNA                            DEBUG: print ANTENNA(1) if >0
----------------------------------------------------------------
TYAPL
Task: DiFX correlators are capable of correlating the same input data
      at multiple phase stopping positions, each separated from the
      direction in which the antennas of array were pointed.  For the
      tiny fields of view surrounding the antenna pointing position,
      the single-dish beam is essentially constant (spatially)
      although it will vary in time due to beam squint and other
      causes.  This task reads an input CL table, computes the
      corrections in amplitude for the separate polarizations and IFs,
      and applies them to the CL data as a function of time.

      Single-dish beam patterns are notoriously hard to compute.  This
      task assumes a simple model of them.  The R polarization and L
      polarization beams are assumed to be each circularly symmetric
      and separated by equal distances in opposite directions from the
      pointing center.

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.
  FREQID.....Frequency ID number to do       0 => 1
  SUBARRY....Subarray to do                  0 => 1
  GAINVER....Input version number of the CL table to be used.
  GAINUSE....Output version number of the CL table to be written.
  CUTOFF.....beam values < CUTOFF cause the solutions to be blanked.
  CALIN......Text file giving in order:
                1. antenna number (0 -> a default to use for those not
                      specified in some other way)
                2. Azimuth squint (arc min (R - L)
                3. Elevation squint (arc min (R - L)
                4. Frequency at which 2 and 3 were measured (MHz)
                5. Antenna effective diameter (meters)
                6. Frequency at which 5 measured (MHz)
                7. Change of effective diameter with frequency
                      (meters/MHz)
             Some of these can be recorded in the ANtenna file, but
             usually are not.  The values for VLBA antennas at L band
             are known by the task.
             In application,
                Azimuth squint = V(2) * V(4) / Freq(IF)
                Elevation squint = V(3) * V(4) / Freq(IF)
                D_effective = V(5) * (Freq(IF)-V(6)) * V(7)
             and the beam pattern is a J1(x) / x function where
             x = pi * D_effective / lambda * sin(offset)

             Some of these must be given to have the task work.
DEBUG option
  TT.........In order to find the primary beam level, Eric's algorithm
             adds the squints to the pointing position (linearly) and
             then computes the separation of the 2 squinted positions
             and the target (fully non-linearly).  TT <= 0.0
             Enno's finds the separation and angle from the pointing
             position to the target (fully non-linearly) and then adds
             the squint parameters (linearly) before finding the
             separation (also linearly).    TT > 0.0
  BIF........If > 0, then do debug print out with IF = BIF
  ANTENNA....If ANTENNA(1) > 0, then do debug print out with
             ANTENNA(1) and BIF only.

  The debug print out shows antenna #, polarization, time number,
  elevation (degrees), azimuth (degrees), separation (degrees), and
  beam power factor.
----------------------------------------------------------------
