; SNREF
;---------------------------------------------------------------
;! Chooses best reference antenna to minimize R-L differences
;# Task UV Calibration
;-----------------------------------------------------------------------
;;  Copyright (C) 2012
;;  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
;-----------------------------------------------------------------------
SNREF     LLLLLLLLLLLLUUUUUUUUUUUU CCCCCCCCCCCCCCCCCCCCCCCCCCCCC
SNREF:  Task to choose best reference for R-L phase difference
INNAME                             UV data (name).
INCLASS                            UV data (class).
INSEQ             0.0    9999.0    UV data (seq. #).  0 => high
INDISK            0.0       9.0    Disk unit #.  0 => any
INEXT                              Input 'SN','CL'
INVERS                             Input table file version no.
SELBAND                            Bandwidth to plot (kHz)
SELFREQ                            Frequency to plot (MHz)
FREQID                             Freq. ID to plot, -1=>all
SUBARRAY         -1.0              Limit to subarray; <=0 -> 1
DOKEEP           -1.0       1.0    > 0 => keep all "temporary"
                                   tables
----------------------------------------------------------------
SNREF
Type:  Task
Use:   Tries re-referencing an SN or CL table to see which reference
       antenna minimizes the R-L phase scatter.  The task loops over
       all possible reference antennas copying the requested SN or CL
       table to a new version and re-referencing it.  This
       re-referenced table is then read and the normalized gains in L
       are subracted from those in R and averaged in real and
       imaginary parts separately.  The two rmses for each IF are
       added in quadrature and saved.  After all possible reference
       antennas have been evaluated, the rmses are examined.  The
       antenna with the lowest rms (averaged in quadrature over all
       IFs) is reported as are the lowest antennas in each IF.  The
       rmses are then shown in detail.

       The output file will have 1 new SN or CL table if DOKEEP is
       false.  If DOKEEP is true, it will have one for each of the
       possible reference antennas for your examination (with e.g.
       SNPLT).
Adverbs:
  INNAME.....UV file name (name).       Standard defaults.
  INCLASS....UV file name (class).      Standard defaults.
  INSEQ......UV file name (seq. #).     0 => highest.
  INDISK.....Disk unit #.               0 => any.
  INEXT......'SN', or 'CL' table to be analyzed.
  INVERS.....Version number of table to analyze, 0=>highest no.
  SELBAND....Bandwidth of data to be selected.  If more than one IF is
             present SELBAND is the width of the first IF required.
             Units = kHz.
  SELFREQ....Frequency of data to be selected. If more than one IF is
             present SELFREQ is the frequency of the first IF required.
             Units = MHz.
  FREQID.....Frequency identifier to select (you may determine which is
             applicable from the OPTYPE='SCAN' listing produced by
             LISTR).  If either SELBAND or SELFREQ are set, their values
             overide that of FREQID.  However, setting SELBAND and
             SELFREQ may result in an ambiguity.  In that case, the task
             will request that you use FREQID.  -1 => all, 0 => first
  SUBARRAY...Limit display to specific subarray.  <= 0 -> 1.
  DOKEEP.....> 0 => keep all temporary SN/CL tables, else keep only
             the selected one.
----------------------------------------------------------------
