; LISTR
;---------------------------------------------------------------
;! prints contents of UV data sets and assoc. calibration tables
;# Task UV Calibration
;-----------------------------------------------------------------------
;;  Copyright (C) 1995-1997, 1999-2001, 2003-2010
;;  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
;-----------------------------------------------------------------------
LISTR     LLLLLLLLLLLLUUUUUUUUUUUU CCCCCCCCCCCCCCCCCCCCCCCCCCCCC
LISTR:  Task to print UV data and calibration tables.
INNAME                             UV data (name).
INCLASS                            UV data (class).
INSEQ             0.0    9999.0    UV data (seq. #).  0 => high
INDISK                             Disk unit #.       0 => any
OPTYPE                             List type:
                                    'MATX','LIST','GAIN','SCAN'
                                    'EFST','SEFD' special GAINs
INEXT                              CL, SN or TY table for 'GAIN'
INVER            -1.0   46655.0    CL, Sn or TY table version
SOURCES                            Source list
CALCODE                            Calibrator code '    '=>all
TIMERANG                           Time range to list
STOKES                             Stokes type to list.
SELBAND                            Bandwidth to select (kHz)
SELFREQ                            Frequency to select (MHz)
FREQID                             Freq. ID to select.
                                   None selected => 1.
BIF               0.0      100.0   Lowest IF number 0=1
EIF               0.0      100.0   Highest IF number
BCHAN             0.0     2048.0   Low channel number 0=>1
ECHAN             0.0     2048.0   High channel number
ANTENNAS                           Antennas to list
BASELINE                           Baselines with ANTENNAS
UVRANGE           0.0              UV range in kilolambda
SUBARRAY         -1.0     1000.0   Subarray, 0=>1
                                   Cal. info for input:
DOCALIB          -1.0      101.0   > 0 calibrate data & weights
                                   > 99 do NOT calibrate weights
GAINUSE                            CAL (CL or SN) table to apply
DOPOL            -1.0       10.0   If >0 correct polarization.
PDVER                              PD table to apply (DOPOL>0)
BLVER                              BL table to apply.
FLAGVER                            Flag table version
DOBAND           -1.0       10.0   If >0 apply bandpass cal.
                                   Method used depends on value
                                   of DOBAND (see HELP file).
BPVER                              Bandpass table version
SMOOTH                             Smoothing function. See
                                   HELP SMOOTH for details.
DPARM                              Control info:
                                   (1) 0=amp, 1=phase, 2=rms
                                       3=amp+rms, 4=phase+rms
                                       5=amp+phase, 6=delay,
                                       7=rate, 8=SNR, 9=par. ang
                                       10 = Tsys, 11=elev,
                                       12 = multiband delay
                                       13 = Tant  14 = weights
                                       N.B. Options 3 and 4 only
                                       valid for OPTYPE = 'MATX'
                                   (2) 0=vec avg, 1=scalar
                                   (3) No. col (4-10) def=4.
                                   (4) avg. time min (MATX,LIST)
                                       *** significant
                                   (5) Type of gain listings:
                                       0 => all with same scale
                                       like DEC-10 listings;
                                       1 => scan/source info at
                                       source/scan boundaries.
                                   (6) Matrix scaling control:
                                       0 => plot amp & rms
                                       matrices with same scale;
                                       1 => self-scale each
                                       separately.
                                   (7) > 0 self-scale phase
                                       displays, else degrees.
                                   (8) > 0 display 1-2 and 2-1
                                       in LIST
DOACOR           -1.0       1.0    > 0 include autocorrelations
FACTOR            0.0              When DPARM(5)=0 Multiply
                                   gain listings by FACTOR,
                                   0=> use scale factor from
                                   first record printed.
DOCRT            -3.0     132.0    > 0 -> use the terminal,
                                   else use the line printer
                                   > 72 => terminal width
OUTPRINT
                                   Printer disk file to save
BADDISK                            Disk to avoid for scratch.
----------------------------------------------------------------
LISTR
Type:  Task
Use:   Prints information in a uv data base in a variety of possible
       forms.  Numerous selection criteria are available and
       calibration and flagging may optionally be applied.
           LISTR will work on multi-source, indexed files or TB sorted
       single-source files in some modes.
            Not all adverbs apply to all types of listing; the
       following notes when an adverb is used for only some listing
       types or its useage depends on the type.
            Note that all listings can scale both phases and
       amplitudes - check the scaling shown at the beginning of each
       data section carefully.
            Two special GAIN listing forms have been added: EFST and
       SEFD.  For these to appear as claimed, the visibility data must
       have been loaded as correlation coefficients, the calibrator
       sources must be unresolved, and the flux densities of the
       calibrator sources must be known.  See EVLA Memo 119.
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.
  OPTYPE.....Type of listing desired:
             'SCAN'=scan and source summary,
             'MATX'=scan averaged (or shorter) maxtix listing,
             '    ' or unrecognized => 'MATX'
             'LIST'=column listing of selected baselines,
             'GAIN'=column listing of gains from SN, CL or TY table
             'EFST'=column listing of SN or CL table converted to
                    Tsys/efficiency in degrees K.  Is amplitude gain
                    squared and then multiplied by 36.8.
             'SEFD'=column listing of SN or CL table converted to the
                    flux density which doubles the system temperature
                    in Jy.  Is amplitude gain squared and then
                    multiplied by 206.
              For EFST and SEFD to be what is desired, the visibility
              data must have been loaded as correlation coefficients,
              the calibrator sources must be unresolved, and the flux
              densities of the calibrator sources must be known.  See
              EVLA Memo 119.  Note that these are scaled for the VLA
              (25m antennas) only.
  INEXT......SN, CL or TY table type to list, '  '=> SN. 'GAIN'
  INVER......SN, CL or TY table version number 0=highest.'GAIN'
  SOURCES....List of sources to be listed. '  '=> all; if any
             starts with a '-' then all except ANY source named.
             For OPTYPE='GAIN' this controls the sources in the
             SN, CL or TY table to be listed.
  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 selection tests
  TIMERANG...Time range of the data to be listed. In order:
             Start day, hour, min. sec,
             end day, hour, min. sec. Days relative to ref.
             date.
  STOKES.....The desired Stokes type of the listed data:
             OPTYPE='MATX':
               'HALF' (=RR,LL) or I  are currently supported.
               '    ' => leave the data in its original form,
                         or RR and LL if both exist.
               'POL ' => RL, LR
               'POLC' => RL, Conjugate(LR); this is useful for
                   finding the Faraday rotation from known
                   polarization calibrators.
             OPTYPE='LIST': 'I','Q','U','V','RR','LL','RL', or
                            'RL'; anything else=>'I'
             OPTYPE='GAIN':
               'R','L', 'I', 'HALF'=(R,L)
               'POLD' => R/L (for phase differences and ampl.
                              ratios only)
               anything else => 'HALF'
  SELBAND....Bandwidth of data to be selected. If more than one IF is
             present SELBAND is the width of the IF required. Units =
             kHz, 0=> all
  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, 0=> all
  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.  If neither
             SELBAND, SELFREQ nor FREQID are specified then the first
             FQ id in the FQ table (usually 1) will be used.  FREQID
             applies to GAIN listings, but if all 3 freq-id adverbs
             are <= 0, then all freq-ids are listed.
  BIF........Lowest IF to list.  All operations will list the IFs one
             at a time.   0 => 1.
             **************************************************
             NOTE to VLA users: IF=1 corresponds to the VLA
             AC ifpairs and IF=2 corresponds to the BD ifpairs.
             **************************************************
  EIF........Highest IF to list. 0 => Highest
  BCHAN......First channel to average.  LIST and MATX will average
             channels BCHAN through ECHAN.  0 => 1.
  ECHAN......Last channel to average.  0 => highest.
  ANTENNAS...A list of the antennas to  list.  If any number is
             negative then all antenna numbers in ANTENNAS are NOT
             desired and all others are.  All 0 => list all.
             Note that antenna numbers that do not appear in the
             relevant antenna file(s) or which appear with a name
             containing the string 'OUT' are not displayed.
  BASELINE...Baselines are specified for the LIST option using
             BASELINE. Eg. baselines 1-6,1-8, 2-6 and 2-8 use
             ANTENNAS=1,2; BASELINE=6,8.
  UVRANGE....Range of projected spacings to be listed in 1000's
             of wavelengths.  0  =>  1, 1.E10
  SUBARRAY...Subarray number to list. <1 => 1 for all OPTYPEs except
             GAIN; < 1 => all subarrays for GAIN listings only.
  DOCALIB....If true (>0), calibrate the data using information in the
             specified Cal (CL) table for multi-source or SN table for
             single-source data.  Also calibrate the weights unless
             DOCALIB > 99 (use this for old non-physical weights).
  GAINUSE....Version number of the Cal. table to apply to the
             data if DOCALIB=1.  Refers to a CL table for
             multisource data of an SN table for single source.
             0 => highest.  Used for OPTYPE='MATX','LIST'.
  DOPOL......If > 0 then correct data for instrumental polarization as
             represented in the AN or PD table.  This correction is
             only useful if PCAL has been run or feed polarization
             parameters have been otherwise obtained.  See HELP DOPOL
             for available correction modes: 1 is normal, 2 and 3 are
             for VLBI.  1-3 use a PD table if available; 6, 7, 8 are
             the same but use the AN (continuum solution) even if a PD
             table is present.
  PDVER......PD table to apply if PCAL was run with SPECTRAL true and
             0 < DOPOL < 6.  <= 0 => highest.
  BLVER......Version number of the baseline based calibration
             (BL) table to appply. <0 => apply no BL table,
             0 => highest.
  FLAGVER....Specifies the version of the flagging table to be
             applied.  0 => highest numbered table.  <0 => no flagging
             to be applied.
  DOBAND.....If true (>0) then correct the data for the shape of the
             antenna bandpasses using the BP table specified by BPVER.
             The correction has five modes:
             (a) if DOBAND=1 all entries for an antenna in the table
             are averaged together before correcting the data.
             (b) if DOBAND=2 the entry nearest in time (including
             solution weights) is used to correct the data.
             (c) if DOBAND=3 the table entries are interpolated in
             time (using solution weights) and the data are then
             corrected.
             (d) if DOBAND=4 the entry nearest in time (ignoring
             solution weights) is used to correct the data.
             (e) if DOBAND=5 the table entries are interpolated in
             time (ignoring solution weights) and the data are then
             corrected.
  BPVER......Specifies the version of the BP table to be applied.
             <0 => no bandpass correction done.
  SMOOTH.....Specifies the type of spectral smoothing to be applied to
             a uv database . The default is not to apply any smoothing.
             The elements of SMOOTH are as follows:
             SMOOTH(1) = type of smoothing to apply: 0 => no smoothing
               To smooth before applying bandpass calibration
                 1 => Hanning, 2 => Gaussian, 3 => Boxcar, 4 => Sinc
               To smooth after applying bandpass calibration
                 5 => Hanning, 6 => Gaussian, 7 => Boxcar, 8 => Sinc
             SMOOTH(2) = the "diameter" of the function, i.e. width
               between first nulls of Hanning triangle and sinc
               function, FWHM of Gaussian, width of Boxcar. Defaults
               (if < 0.1) are 4, 2, 2 and 3 channels for SMOOTH(1) =
               1 - 4 and 5 - 8, resp.
             SMOOTH(3) = the diameter over which the convolving
               function has value - in channels.  Defaults: 1,3,1,4
               times SMOOTH(2) used when input SMOOTH(3) < net
               SMOOTH(2).
  DPARM......Control info:
             1) controls the type of information to be printed:
                0 => amplitude,
                1 => phase,
                2 => RMS of amplitude,
                3 => amplitude + amplitude rms  (MATX)
                4 = phase + phase rms (MATX)
                5 =  amplitude and phase (MATX)
                6 = delay (GAIN)
                7 = rate (GAIN)
                8 = SNR (i.e. weight) (GAIN)
                9 = parallactic angle (GAIN)
                10 = System temperature (GAIN)
                     (for VLA nominal sensitivity)
                11 = source elevation (GAIN)
                12 = multiband delay (GAIN)
                13 = Antenna temperature (GAIN)
                     (for VLA back-end or front-end syste, temperature
                     depending on FILLM settings)
                14 = Data weight (MATX)
             2) controls the type of averaging:
                0 => vector average,
                1 => amp scalar averaging. Amplitudes and phases
                     averaged separately.
             3) The number of digits per column for column
                based listings. The allowed range is 4 to 10;
                4 will be used if the value is outside of the
                allowed range.
             4) Averaging time in min. to be used for MATX or
             LIST option.
                0=> scan average (MATX multi source files)
                0=> 10 min. (MATX single source files)
                0=> 0 in LIST - times that are only subtly different
                    are taken as different and displayed on separate
                    lines.  On-line and later averaging can cause such
                    subtle time differences.  SET THIS ADVERB for LIST.
                large=>scan average. (MATX, LIST)
             5) Type of listings for OPTYE='GAIN':
                0=> list gain solutions in the style of the
                    DEC-10/ISIS packages, i.e long lists of
                    numbers with a constant scale for all.
                1=> Scale each scan/source separately and
                    provide a scan summary between each
                    scan.
                Default = 0
             6) Matrix scaling control:
                0=> when plotting amplitude matrix followed
                by rms, use the scale factor from the amplitude
                matrix to scale the rms.
                1=> self-scale each matrix separately.
                Default = 0
             7) > 0 => self-scale phases, otherwise they are in
                integer degrees
             8) > 0 on 'LIST' => list each baseline twice so that e.g.
                baseline 3-23 will appear with all the other 3-*
                baselines and with all other *-23 baselines.  By
                default 3-23 appears with the 3's but at the 23's only
                23-24, 23-25, etc. are displayed.
  DOACOR.....> 0 => include autocorrelation data.
  FACTOR.....The default for gain listings is to take the scale
             derived from the first record printed and apply
             it to all subsequent records. However this is
             obviously not a good idea in all cases. If you are
             not satisfied with this default value, you can use
             FACTOR to multiply the scale factor derived and
             then rerun LISTR printing the rescaled values.
  DOCRT......False (<= 0) use the line printer if OUTPRINT = ' '
                   else write named OUTPRINT file only.
                   When OUTPRINT is not blank, DOCRT=-2 suppresses the
                   page-feed character on page headers and DOCRT=-3
                   suppresses page headers and most other header
                   information.
             True  (> 0) use the terminal interactively.  The task will
                   use the actual terminal width as a display limit
                   unless 72 < DOCRT < width.  In that case, the display
                   limit will be DOCRT characters.
  OUTPRINT...Disk file name in which to save the line printer output.
             ' ' => use scratch and print immediately for interactive
             jobs - batch jobs use OUTPRINT = 'PRTFIL:BATCHjjj.nnn'
             (jjj= job #, nnn = user #).  When OUTPRINT is not blank,
             multiple outputs are concatenated, and the file is not
             actually printed.
  BADDISK....Disk numbers to avoid for scratch files.  Scratch
             files may be created by the sorting routines if
             calibration or flagging is applied.
----------------------------------------------------------------
LISTR: Task to list uv data.
DOCUMENTOR: Bill Cotton NRAO/CV
RELATED PROGRAMS: UVFLG

                             PURPOSE

     LISTR is designed to display uv data in line printer
listing form as an aid in evaluating and editing data; several
methods of displaying the data are provided.  LISTR should work
in at least some form on both single and multi-source data
files.
     The standard adverbs for calibration and editing e.g.
applying CL, BL and FG tables to the data etc.) are provided.

                           COMMENTS

OPTYPE:
     OPTYPE='MATX' requests a scan averaged matrix listing.  Pairs of
polarizations can be listed simultaneously:
     RR, LL if both exist and STOKES= 'HALF' or STOKES= '   ';
     RL, LR if both exist and STOKES= 'POL '
     RL, conjugate(LR) if both exist and STOKES= 'POLC'
Or one polarisation can be listed:
     RR if it exists and STOKES = 'RR  ' or
        RR is the only one and STOKES = '    '.
     LL if it exists and STOKES = 'LL  ' or
        LL is the only one and STOKES = '    '.
Two (one) lines under matrix correspond to auto correlation.
Only a single IF or frequency channel may be specified.
An averaging time shorter than a scan may be requested using DPARM(4).
Note: scans are not defined for single source data.

     OPTYPE='LIST' requests column listings of selected baselines.
The time will be averaged as specified by DPARM(4).  Only a single
polarization can be listed but all frequencies and IF selected will be
averaged.  A scan heading is given each time a new scan is
encountered.

     OPTYPE='GAIN' requests column listings of selected contents of
the CL, SN or TY table specified by INEXT and version number INVER.
The type of data (amplitude, phase, delay, rate) listed is controlled
by DPARM(1).  Multiple IFs and/or polarizations may be listed in a
single execution. STOKES='POLD' will tabulate R-L phase differences or
R/L amplitude gain ratios, if amplitude or phase is selected as
DPARM(1). This polarization option is ignored for other quantities.

     OPTYPE='SCAN' requests scan and source summaries.

ANTENNAS and BASELINE:
     The matrix option allows selection of data by antenna
only.  All baselines between the antennas given in ANTENNAS
will be displayed.
     The column listing option allows selection of data by
baseline; this involves both ANTENNAS and BASELINE.  The
baselines selected are those between antenna listed in ANTENNAS
and those in BASELINE.  All zeroes in either of these arrays
imply all altennas.
For example:
     ANTENNAS=1,0; BASELINE=10,0
specifies baseline 1-10 ( the zeroes are necessary to prevent
specifying the same baseline a large number of times).
Another example:
   ANTENNAS=1,2,3,4; BASELINE=3,4,5,6
specifies baselines
1-3,1-4,1-5,1-6,1-3,2-4,2-5,2-6,3-4,3-5,3-6,4-5 and 4-6.
     Listings of antenna gain solutions (GAIN) will only
contain antennas specified by ANTENNAS.


DPARM:
     Control Information.
(1) specifies the type of information to be listed:
    0 => amplitude of the visibility,
    1 => phase of the visibility,
    2 => RMS of the amplitude of the visibility (enough time
         samples must be included to compute an RMS),
    3 => Amplitude + RMS (OPTYPE=MATX),
    4 => phase + RMS (of amplitude) (OPTYPE=MATX),
    5 => amplitude and phase (OPTYPE=MATX),
    6 => delay (OPTYPE=GAIN),
    7 => rate (OPTYPE=GAIN),
    8 => SNR, actually the solution "WEIGHT" (OPTYPE=GAIN).
    9 => Parallactic angle of the antenna at the time of the
         gain record (OPTYPE=GAIN)
    10 => System temperature of the antenna (OPTYPE=GAIN)
    11 => Source elevation (OPTYPE='GAIN')
    12 => Multiband delay (OPTYPE='GAIN')
(2) specifies the type of averaging:
    0 => vector averaging of the selected visibilities before
         conversion to amplitude or phase.
    1 => "amp-scalar" averaging; amplitudes and phases are
         computed for the individual visibilities and averaged.
(3) specifies the number of digits per column in the output to
    be used for each value listed.  The allowed range is 4 to 10;
    if a number outside of this range is given, 4 is used.  A
    smaller number of columns per value allows more values to
    be listed but with lower precision.
(4) specifies the averaging time to be used for the MATX or
    LIST options.  Visibilities are averaged by the specified
    method for DPARM(4) min.  Zero implies the integration time
    of the input data (LIST) or scan averages (MATX) and a
    large time will be truncated at the end of each scan.
(5) Type of listings for OPTYE='GAIN':
    There are two formats of listing available when listing
    gain solutions: one (the default) applies a constant
    gain factor to all values (this is under user control),
    and the output is similar to that produced by the old
    Dec-10 programs. The other scales each scan separately
    when producing the output.
    0=> list gain solutions in the style of the
        DEC-10/ISIS packages, i.e long lists of
        numbers with a constant scale for all.
    1=> Scale each scan/source separately and
        provide a scan summary between each scan.
    Default = 0
(6) Matrix scaling control:
    0=> when plotting amplitude matrix followed
         by rms, use the scale factor from the amplitude
         matrix to scale the rms.
    1=> self-scale each matrix seperately.
    Default = 0
