; VLBAFRNG
;---------------------------------------------------------------
;! fringe fit data to determine antenna calibration, delay, rate
;# TASK CALIBRATION AP VLBI
;-----------------------------------------------------------------------
;;  Copyright (C) 1995-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
;-----------------------------------------------------------------------
VLBAFRNG  LLLLLLLLLLLLUUUUUUUUUUUU CCCCCCCCCCCCCCCCCCCCCCCCCCCCC
VLBAFRNG: Procedure to fringe fit and calibrate data
                                   Input uv data.
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 #
CALSOUR                            Source list to fringe fit
TIMERANG                           Time range to use.
BCHAN             0.0     2048.0   Lowest channel number 0=>all
                                   FOR SPEC. LINE EXP. ONLY
ECHAN             0.0     2048.0   Highest channel number
                                   FOR SPEC. LINE EXP. ONLY
GAINUSE                            CL table to apply.
REFANT                             Reference antenna
SUBARRAY          0.0     1000.0   Subarray, 0=>all
SEARCH            0.0     1000.0   Prioritized reference antenna
                                   list - supplements REFANT
SOLINT                             Solution interval (min)
                                   0 => 10 min
DPARM                              for strong sources, it is
                                   only necessary to set
                                   DPARM(4), DPARM(7) and for
                                   spec line exp DPARM(8).
                                      4=int. time (sec)
                                       0 => min. found in data
                                      7 >0 => don't rereference
                                        phase; this should be 1
                                        for polarization exp
                                      8 > 0 => activate zero'ing
                                                options
                                   for rest see HELP VLBAFRNG
SOURCES                            Source list to calibrate: If
                                   sources are listed they are
                                   each calibrated with separate
                                   runs of CLCAL
INTERPOL                           Interpolation function:
                                   '2PT','SIMP','AMBG','CUBE',
                                   'SELF'
BADDISK            0.0        15.0 Disk no. not to use for
                                      scratch files.
----------------------------------------------------------------
VLBAFRNG
Type: Procedure
Use:  This procedure does antenna based fringe fitting using FRING
      and then applies those corrections using CLCAL.  For more
      information on FRING and CLCAL see their respective HELP/EXPLAIN
      files.  If you are doing a phase reference experiment use
      VLBAFRGP.
      Type RUN VLBAUTIL to make the VLBAFRNG procedure
      available.
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.

  CALSOUR....List of sources for which calibration constants are to be
             determined, i.e. the calibrator sources  All ' ' = all
             sources; a "-" before a source name. means all except ANY
             source named.  Note: solutions for multiple sources can
             only be made if the sources are point sources at their
             assumed phase center and with the flux densities given in
             the source (SU) table.
  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.
  BCHAN......First channel to use. 0=>all.
  ECHAN......Highest channel to use. 0=>all higher than BCHAN
  GAINUSE....(multisource) version number of the CL table to apply to
             the data.   0 => highest.
  REFANT.....The desired reference antenna for phases.
  SUBARRAY...Subarray number to use. 0=>all.
  SEARCH.....List of Prioritized antennas to be used when APARM(9)>0.
             This adverb supplements REFANT.  It is recommended that
             SEARCH be filled with a list of antennas whose order
             reflects the user's notion of which baselines will be
             easiest to find fringes on.  All baselines to each antenna
             in SEARCH will be searched in order looking for fringes.
             All remaining baselines will then be searched.  Choosing
             SEARCH wisely will speed the FFT portion of FRING.  The
             antenna chosen in REFANT is treated as SEARCH(0), ie all
             baselines to it are searched first.
  SOLINT.....The solution interval (min.)  You really should set this;
             longer values are allowed beginning with 15OCT96.
             0 => 10 minutes for all inputs
             If SOLINT > Scan/2 (in Multisource) SOLINT = Scan.
  Delay-rate control parameters:
  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.
  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
  SOURCES....Sources to calibrate.  If this is left blank then all
             the sources are calibrated at once using the INTERPOL
             (i.e. CLCAL is only run once).  If sources are listed
             then CLCAL is run once for each source using the
             interpolation method stated in INTERPOL.  This
             second option is recommended, see EXPLAIN file.
  INTERPOL...The type of interpolation to be applied to the SN table:

             '    ' = linear vector interpolation with no SN smoothing.
             '2PT ' = linear vector interpolation with no SN smoothing.
             'SELF' = Use only SN solution from same source which
                      is closest in time.
             '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.
  BADDISK....A list of disk numbers to be avoided when creating scratch
             files.
----------------------------------------------------------------
VLBAFRNG:           Procedure to perform antenna based fringe fitting
                    using FRING and then apply these corrections using
                    CLCAL.  If you are doing phase referencing use
                    VLBAFRGP.
Documenter:         Amy Mioduszewski
Related Programs:   VLBAUTIL, FRING, CLCAL, VLBAKRNG, VLBAFRGP

This should be done after solving for the instrumental phase
corrections (VLBAPCOR) and before applying all the calibration
and averaging (SPLIT/SPLAT).  After VLBAFRNG is run it is ESSENTIAL
to check the solutions in POSSM setting GAINUSE to the CL table
output by VLBAFRNG.  VLBAFRNG will produce the highest SN and
CL table.  For details on FRING and CLCAL see their HELP/EXPLAIN
files.

VLBAFRNG assumes:

1. there is only one FREQID

2. that all IFs should be calibrated

3. that all antennas should be calibrated

4. that the entire uv range should be calibrated

5. that the highest FG table is the one that should be applied

6. that this is a multisource file

Steps in VLBAFRNG:

1. Runs FRING, which will do antenna based fringe fits.  This
   will produce the highest SN table.

2. Runs CLCAL, with OPCODE 'CALI', SNVER output SN table from
   FRING; GAINVER input GAINUSE and GAINUSE = highest CL table +1.
   Output should be highest CL table.  If SOURCES is blank then
   CLCAL is run only once.  If SOURCES is not blank then CLCAL
   will be run for each SOURCE individually setting both CALSOUR
   and SOURCES to the same single source in the SOURCES list.
   This is recommended because of CLCAL is run for all the sources
   at once with any INTERPOL except 'SELF' then incorrect
   solutions may be applied for a few minutes before and after a
   source change.  CLCAL will output the highest CL table.

After VLBAFRNG is run and the solutions are checked in POSSM  SPLIT
or SPLAT should be run with GAINUSE set to the CL output from VLBAFRNG
and DOCAL=2.
