; GETJY
;---------------------------------------------------------------
;! determines calibrator flux densities
;# Task Calibration
;-----------------------------------------------------------------------
;;  Copyright (C) 1995, 2008-2009, 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
;-----------------------------------------------------------------------
GETJY     LLLLLLLLLLLLUUUUUUUUUUUU CCCCCCCCCCCCCCCCCCCCCCCCCCCCC
GETJY     Task to determine source flux densities.
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 find fluxes
SOUCODE                            Source "Cal codes"
CALSOUR                            Cal sources for calibration
QUAL            -10.0              Source qualifier -1=>all
CALCODE                            Calibrator code '    '=>all
BIF               0.0      100.0   Lowest IF number 0=1
EIF               0.0      100.0   Highest IF number
TIMERANG                           Time range of solutions.
ANTENNAS                           Antennas to use
SUBARRAY          0.0     1000.0   Subarray, 0=>all
SELBAND                            Bandwidth to select (kHz)
SELFREQ                            Frequency to select (MHz)
FREQID                             Freq. ID to select.
SNVER                              Input SN table, 0=>all.
----------------------------------------------------------------
GETJY
Task:  Determines flux densities from CALIB solution (SN) tables,
       enters the results in the source (SU) table, and corrects the
       amplitudes of the solutions in the SN tables.  There is a limit
       of 500 sources including the calibration sources.  Before
       running GETJY:
       1) SETJY should be run to insert the flux densities of the
          primary flux density calibrators into the SU table.
       2) SETJY should also be run to set some flux (1.0 will do) for
          any secondary calibrator for which you intend to use a model.
       3) CALIB should be run on all primary and secondary flux
          density calibrators.  Separate runs may be needed for
          different sources if UVRANGE and/or ANTENNAS need to be
          different or if some sources have models.
       After running GETJY:
       4) If you have numerous IFs (spectral windows), run SOUSP to
          see if the solutions are reasonable and perhaps to
          substitute the fitted flux and spectral index for the
          individual, per-IF fluxes.
       5) Run CLCAL to apply the SN tables to a specified CL table.

NOTE: GETJY may be run multiple times without adversely affecting
either the SN or SU tables.  Some users have models for sources other
than those provided with AIPS.  To use such a model, it is recommended
that you first run SETJY to set some total flux in the SU table.  Then
the model will be scaled to that flux and GETJY may be used to adjust
that scale after CALIB.  If you do not set a non-zero flux for such
calibrators, CALIB will use the flux contained in the model but GETJY
will assume 1.0 and the result after GETJY will be erroneous.  You can
use SETJY after CALIB to put the total flux of your model as reported
in CALIB into the SU table before GETJY.  That should work.

The averaging methods were changed on October 12, 2009:
(1) First the antenna gains for the calibration sources are averaged
    separately for each antenna, polarization, and IF.  The averaging
    is now done by robust methods in which outliers do not contribute
    to the average or rms.  The number of gain samples contributing to
    these averages (summed over antenna, polarization, and IF) is
    reported along with the total number of calibration source
    samples.  Any samples more than six times the rms from the mean
    are counted over antenna, polarization, and IF and are then
    reported.
(2) Then, one source at a time, the antenna gains are averaged
    robustly separately for each antenna, polarization, and IF.  The
    total number of such samples, the number contributing to the
    averages, and the number more than six rms away from the mean are
    counted over all antennas, polarizations, and IFs.
(3) The ratio of the source gain to the average calibrator gain in
    each antenna and polarization is averaged separately for each IF
    using robust methods.  The number of samples possible in each
    average, the number used, and the number more than six rms away
    from the mean are counted over all IFs.  The apparent flux in each
    IF is reported along with the formal error using both the robust
    rms and an rms computed over all samples.  The formal error is the
    rms of the average over antennas and polarizations divided by the
    square root of the number of samples used in the robust mean minus
    one.
(4) Following all source fluxes, the counts in the second and third
    averages are reported separately for each source.

Adverbs:
  INNAME.....Input UV file name (name).      Standard defaults.
             Multisource files only.
  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 flux densities are to be
             determined.  '*' or '' => 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 to determine source
             flux densities.  The flux densities of these
             sources should have been entered into the SU table
             using SETJY before running CALIB.  '*' or '' = 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. CALSOUR and QUAL, in the
             selection of calibrators.
             CALCODE affects only the selection of calibrators.
  BIF........Lowest IF number to process, 0=>1.
  EIF........Highest IF number to process, 0=>all.
  TIMERANG...Time range of the data to be considered. In order:
             Start day, hour, min. sec,
             end day, hour, min. sec. Days relative to ref.
             date.  TIMERANG is only used in the determination
             of the source flux densities.  Solutions at all
             times are corrected by the determined flux
             densities.
  SUBARRAY...Subarray number to use. 0=>all.
             Only data in subarray SUBARRAY are used to
             determine flux densities and only solutions in this
             subarray are corrected.
  ANTENNAS...A list of the antennas to use.  If any number
             is negative then all antennas listed  are NOT
             desired and all others are. All 0 => use all.
             ANTENNAS is only used to determine the source flux
             densities; solutions for all antennas are
             corrected.
  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. For data which
             contain multiple bandwidths/frequencies the task
             will insist that some form of selection be made
             by frequency or bandwidth.
  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 override that of FREQID.
             However, setting SELBAND and SELFREQ may
             occasionally result in an ambiguity.  In that
             case, the task will request that you use FREQID.
  SNVER......Selected SN table(s).  If SNVER > 0 then only SN
             version SNVER is used.  If SNVER <= 0 then all SN
             tables are selected.
----------------------------------------------------------------
