; CAPLT
;---------------------------------------------------------------
;! plots closure amplitude and model from CC file
;# TASK UV VLBI PLOT
;-----------------------------------------------------------------------
;;  Copyright (C) 2009-2011
;;  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
;-----------------------------------------------------------------------
CAPLT     LLLLLLLLLLLLUUUUUUUUUUUU CCCCCCCCCCCCCCCCCCCCCCCCCCCCC
CAPLT     Plots closure amplitides from uv data base and model
USERID       -32000.0    32000.0   File owner number - ignored
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        3.0   Input UV file disk unit #
IN2NAME                            Input CC file name (name)
                                   ' ' => no model
IN2CLASS                           Input CC file name (class)
                                   ' ' => no model
IN2SEQ            0.0     9999.0   Input CC file name (seq. #)
IN2DISK           0.0        3.0   Input CC file disk unit #
IN2VERS           0.0     46655.0  Input CC file version #
NCOMP                              # comps to use for model.
                                   1 value per field
FLUX                               Lowest CC component used.
NMAPS         -4096.0    4096.0    # clean maps (fields).
                                   0 => no model
                                   Data selection:
SOURCES                            Source list
QUAL            -10.0              Source qualifier -1=>all
CALCODE                            Calibrator code '    '=>all
SELBAND                            Bandwidth to select (kHz)
SELFREQ                            Frequency to select (MHz)
FREQID                             Freq. ID to select.
BCHAN             0.0     4096.0   Low channel # averaged 0=>1
ECHAN             0.0     4096.0   High channel # averaged
BIF               0.0      100.0   Low IF # averaged 0=>1
EIF               0.0      100.0   High IF # averaged 0=>max
XINC              0.0     9999.0   Plot every XINC'th visibility
                                   0 => 1
UVRANGE           0.0              Range of projected spacings
                                   (thousands of wavelengths)
TIMERANG                           Time: start day,hr,min,sec
                                         stop day,hr,min,sec.
STOKES                             Stokes' parameters
TRIANGLE                           Closure quadrangles to plot
                                   See HELP.
DOCALIB          -1.0      101.0   > 0 calibrate data & weights
                                   > 99 do NOT calibrate weights
GAINUSE                            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
SUBARRAY                           Subarray number 0=all.
DOEBAR                             If > 0, plot error bars,
                                   else don't
SOLINT                             Time interval over which to
                                   average data in order to
                                   form closure amplitude (mins)
                                   See HELP for hints on how
                                   to use this.
OPCODE                             If OPCODE = 'INDE' will plot
                                   all independent closure
                                   amplitudes.
                                   If OPCODE = ' ' will plot all
                                   closure amplitudes, or all
                                   closure amplitudes specified
                                   by the TRIANGLE adverb.
                                   See HELP for more info.
PHSLIMIT            0.0            Plot only those quadrangles
                                   exceeding PHSLIMIT
BPARM                              Control parameters
                                   1 : 1 => x-axis is UTC
                                       or IAT (depending on
                                       time system in data.)
                                     : 2 => x-axis is GST
                                       0 => 1
                                   2 : not used
                                   3 : >0.0 => fixed scale
                                       <0.0 => fixed range
                                        0.0 => sep. scales
                                   4 : Xmin (fixed scale)
                                   5 : Xmax (fixed scale)
                                   6 : Ymin (fixed scale)
                                   7 : Ymax (fixed scale)
                                   8 : Max no. plots/page.
                                   9  > 0 -> plot models for
                                       baselines with no data
                                   10: unused
POLPLOT                            Option to display various
                                   combinations of polzns to
                                   plot: 'RL/RR', 'RL/LL',
                                   'LR/RR', 'LR/LL', 'RR/LL'
                                   'LL/RR'; other = don't use
                                   this option.
SYMBOL          0.0        24.0    Symbol to use when plotting.
                                   0 => Vertical line
                                   1 - 24, standard types
FACTOR          0.0      1000.0    Scale symbol plotted
LTYPE         -10.0        10.0    Type of labeling: 1 border,
                                   2 no ticks, 3 - 6 standard,
                                   7 - 10 only tick labels
                                   <0 -> no date/time
DOTV           -1.0         1.0    > 0 Do plot on the TV, else
                                   make a plot file
GRCHAN          0.0         8.0    Graphics channel 0 => 1.
XYRATIO         0.0                X/Y ratio 0 -> fit TV or 1 PL
----------------------------------------------------------------
CLPLT
Type: Task
Use:  Plots closure amplitude from a u,v data base making a plot file
      or using the TV.  Also, if a valid CLEAN map is specified the
      model values will be plotted.  Plotting is done one quadrangle
      (4 antennas) per plot with the number of plots per page
      specified by BPARM(8).  The plots are written one page per plot
      file so in general several plot files will be created.  Model
      types recognized are: points, elliptical gaussians and uniform
      spheres.  The DO3DIMAG option of IMAGR is fully supported as are
      multi-scale images.

      If the fringe rate for the source is fairly rapid, then it is very
      important to have the sampling be the same on all baselines in
      each quadrangle.  Otherwise, samples at slightly different times
      will be combined but the amplitudes will not cancel properly.
      Use of a very small value of SOLINT (but > 0) will cause
      inadequately aligned data to be discarded in order to avoid
      misleadingly high closure amplitudes.

      Note that you might wish to divide your data by your model with
      OOSUB or UVSUB, and then plot the closure amplitudes from the
      resulting "gains".
Adverbs:
  USERID.....Input file user number.  Ignored
  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.
  IN2NAME....Name of desired CLEAN components to be used.  If this file
             is not found no model will be plotted   ' ' => no model.
  IN2CLASS...Class of CLEAN map.            ' ' => no model
  IN2SEQ.....Sequence number of CLEAN map.  0 => highest.
  IN2DISK....Disk number of CLEAN map.      0 => any.
  IN2VERS....CLEAN component file version (CC tables)   0 => highest.
             The same version number is used for the all selected
             image files. Use task TACOP to provide the same numbers
             for desired CC tables.
             For a multi-source file, the flux of the clean components
             selected for the model are summed and scaled to the source
             flux found in the SU table.  If that flux is zero, no
             scaling is done.
  NCOMP......Number of Clean components to use for the model, one
             value per field.  If all values are zero, then all
             components in all fields are used.  If any value is not
             zero, then abs(NCOMP(i)) (or fewer depending on FLUX and
             negativity) components are used for field i, even if
             NCOMP(i) is zero.  If any of the NCOMP is less than 0,
             then components are only used in each field i up to
             abs(NCOMP(i)), FLUX, or the first negative whichever
             comes first.  If abs(NCOMP(i)) is greater than the number
             of components in field i, the actual number is used.  For
             example
                   NCOMP = -1,0
             says to use one component from field one unless it is
             negative or < FLUX and no components from any other
             field.  This would usually not be desirable.
                   NCOMP = -1000000
             says to use all components from each field up to the
             first negative in that field.
                   NCOMP = -200 100 23 0 300 5
             says to use no more than 200 components from field 1, 100
             from field 2, 23 from field 3, 300 from field 5, 5 from
             field 6 and none from any other field.  Fewer are used if
             a negative is encountered or the components go below
             FLUX.   *** This option is limited to the first 200000
             Clean components encountered.  ***
  FLUX.......Only components > FLUX in absolute value are used in the
             model.
  NMAPS......Number of image files to use for model.  For multi-scale
             models, set NMAPS = NFIELD * NGAUSS to include the Clean
             components of the extended resolutions.  If more than one
             file is to be used, the NAME, CLASS, DISK and SEQ of the
             subsequent image files will be the same as the first file
             except that the LAST 3 or 4 characters of the CLASS will
             be an increasing sequence above that in IN2CLASS.  Thus,
             if INCLASS='ICL005', classes 'ICL005' through 'ICLnnn'
             or 'ICnnnn', where nnn = 5 + NMAPS - 1 will be used.  Old
             names (in which the 4'th character is not a number) are
             also supported: the last two characters are '01' through
             'E7' for fields 2 through 512.  In old names, the highest
             field number allowed is 512; in new names it is 4096.
             = 0 => do not plot a model
             > 0 => plot the model at each data sample.  In this mode,
                    the u,v,w are known from the data sample, but the
                    sampling for each baseline may be coarse and
                    irregular.
             < 0 => plot a model at 200 regularly sampled points for
                    each baseline.  In this mode, the u,v,w's are
                    computed from the times and antenna locations and
                    may have subtle (or not so subtle) complications
                    (with precession, u-v rotation, times) causing the
                    plotted model to fail to match the plotted data.
  SOURCES....Source list.  If the data is a multi-source file
             CLPLT will plot the visibility for the first
             source specified. If the data is a single
             source file no source name need be specified.
  QUAL.......Only sources with a source qualifier number in the
             SU table matching QUAL will be used if QUAL is not
             -1.
  CALCODE....Calibrators may be selected on the basis of the
             calibrator code:
                  '    ' => 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 sources for which to determine
             solutions.
  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, 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 occasionally
	     result in an ambiguity, in which case the task will
	     request that you use FREQID.
  BCHAN......Start channel. 0 => 1
  ECHAN......End channel. 0 => max   The data from BCHAN through ECHAN
             will be averaged before plotting.
  BIF........Start IF number to plot. 0 => 1
  EIF........End IF number to plot. 0 => max  The data from BIF
             through EIF will be averaged before plotting.
  XINC.......Plot every XINC'th visibility
             which might be plotted.  0 => 1
  UVRANGE....Range (min, max) of projected baselines to include
             0,0 => all baselines
  TIMERANG...The specified time range.
     1 = Start IAT day (day 0 = first day in data base)
     2 = Start IAT hour
     3 = Start IAT minute
     4 = Start IAT second
     5 = Stop IAT day (day 0 = first day in data base)
     6 = Stop IAT hour
     7 = Stop IAT minute
     8 = Stop IAT second
         stop IAT = 0 => beginning
         stop IAT = 0 => end.
                    of time.
  STOKES.....Specifies the stokes type to be plotted:
             Recognized values are 'I', 'Q', 'U', 'V',
             'RR', 'LL', 'LR', 'RL';    '    ' => 'I'.
  TRIANGLE...A list of the closure quadrangles to be plotted.
             (a) If TRIANGLE = 0, CLPLT will plot all available closure
                 amplitudes.
             (b) If TRIANGLE(1) < 0, then CLPLT will plot all available
                 closure amplitudes, EXLUDING those quadrangles
                 involving antennas listed in the TRIANGLE array (with
                 either sign)
             (c) If you wish to plot specified quadrangles you should
                 specify them as quadruplets within the TRIANGLE
                 array.  E.g. TRIANGLE=1,2,3,4,2,5,6,8 will cause
                 CLPLT to plot quadrangles 1-2-3-4 and 2-5-6-8. You may
                 specify up to 12 quadrangles in this manner.
             IF OPCODE = 'INDE' and TRIANGLE = 0 then CLPLT will plot
             all independent closure quadrangles, if TRIANGLE is
             non-zero the task will complain.
  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 CL table to apply to
             multisource files or the SN table for single
             source files.  0 => highest.
  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 either
             plotted (if APARM(8)=2) or applied (if DOBAND > 0
             and APARM(8) .NE. 2). 0 => highest numbered table.
             <0 => no bandpass correction to be applied.
             plotted (if APARM(8)=2) or applied (if DOBAND > 0
             and APARM(8) .NE. 2). 0 => highest numbered table.
             <0 => no bandpass correction to be applied.
  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).
  SUBARRAY...The subarray number desired. 0=> all.
  DOEBAR.....If = 0 => do not plot error bars on data
             if = 1 => do plot error bars
  OPCODE.....If OPCODE = ' ' then plot closure amplitude vs. time
             obeying the TRIANGLE adverb. If OPCODE = 'INDE' then all
             independent quadrangles are plotted.
  PHSLIMIT...Plot only those quadrangles having closure amplitudes
             greater than PHSLIMIT.
  BPARM......Control parameters:
     1 = limited types of x-axis values available.
         1 = time (UT or IAT, depending on timesystem in use)
         2 = GST
         0 - default => 1
     2 = not used
     3 = if greater than zero, use BPARM(4) - BPARM(8) as the
         ranges of the axes.  If less than zero, use the BPARMs
         to limit the range of the axes, but self-scale the axes
         within that range.  If 0.0, scale the Y axis separately
         for each baseline.
     4 = Minimum of X-axis.  See note below on units.
     5 = Maximum of X-axis (if = BPARM(4) do self-scale in X).
     6 = Minimum of Y-axis.  See note below on units.
     7 = Maximum of Y-axis (if = BPARM(6) do self-scale in Y).
     8 = Maximum number of plots per page: 0 => 3
     9 = Control of plotting for baselines with no data samples:
         > 0  => plot such baselines if a model is being plotted
         <= 0 => don't plot them - such baselines are never
         plotted if there is not a model being plotted.
    10 = No longer used

    Units to use in BPARM(4) - BPARM(7):
        axis type = 1, 9, 10     Jy
                    2, 4         Degrees
                    3, 6, 7, 8   Kilo wavelengths
                    5, 12        Days from start of observation
                   11            Hours
    The axes will be labeled in appropriately scaled units, with
    axis types 11 and 12 expressed in sexagesimal (hours,
    minutes, seconds as needed).
    NOTE: two models will be plotted if the x axis type is 3, 6,
    7, or 8 (uv distance, u, v, w) since the x axis value
    determines the baseline only with an ambiguity.  Models are
    plotted only if the y-axis type is 1, 2, 9, or 10 and the x-
    axis type is NOT 1, 2, 9, or 10 (and if NITER > 0 and there
    is an appropriate CC file).
  POLPLOT....An option to display the ratio of various
             correlated values. Allowed combinations are:
             'RL/RR', 'RL/LL', 'LR/RR', 'RL/LL', 'RR/LL',
             'LL/RR'; other => don't use this option.
  SOLINT.....The time interval (minutes) over which to average the data
             in order to form the closure amplitude. It is possible,
             especially on correlators which only correlate a subset of
             the available stations simultaneously that the time tags
             associated with visibility values on different baselines
             differ. Therefore one has to specify a time interval over
             which to average the data to form the closure amplitude.
             If this is not necessary with your data, set
                  0 < SOLINT <= 0.9 * data integration time.
             You should experiment a little with this parameter. If the
             fringe rate for the source is fairly rapid, then it is very
             important to have the sampling be the same on all baselines
             in each quadrangle.  Otherwise, samples at slightly
             different times will be combined but the amplitudes will
             not cancel properly.  Use of a very small value of SOLINT
             (but > 0) will cause inadequately aligned data to be
             discarded in order to avoid misleadingly high closure
             phases.
             If SOLINT < 0, the task will form a closure amplitude as
             soon as it has accumulated at least one sample for each
             of the four baselines in the quadrangle.  The closure
             amplitudes will then be averaged over SOLINT minutes.
             This averaging is a scalar averaging and may be
             particularly affected by Ricean noise bias.
  SYMBOL.....Symbol to use when plotting.
             1: Plus sign           12: Five pointed star
             2: Cross (X)           13: Star of David
             3: Circle              14: Seven-pointed star
             4: Box                 15: Eight-pointed star
             5: Triangle            16: Nine-pointed star
             6: Diamond             17: Ten-pointed star
             7: Pentagon            18: 11-pointed star
             8: Hexagon             19: 12-pointed star
             9: Septagon            20: 13-pointed star
             10: Octagon            21: 14-pointed star
             11: Nine-gon           22: Plus with gap
                                    23: Vertical line
                                    24: Cross with gap
             0 => 23 =  '|' (i.e. vertical lines).
             If error bars are plotted, SYMBOL = 23 is recommended.
  FACTOR......Scale plot symbol by FACTOR, 0 -> 1.  FACTOR is applied
              even when plotting error bars.
  LTYPE.......Labelling type: 1 = border, 2 = no ticks,
              3 - 10 = standard, with  7-10 all labels other
              than tick numbers and axis type are omitted.
              Less than 0 is the same except that the plot file
              version number and create time are omitted.
  DOTV........> 0 => plot directly on the TV device, otherwise
              make a plot file for later display on one or
              more devices (including the TV if desired).
  GRCHAN......Graphics channel (1 - 7) to use for line drawing.
              0 => 1.
  XYRATIO.....Scale the X axis longer than the Y by XYRATIO.
              If DOTV >  0, 0 -> fit to the TV window
              If DOTV <= 0, 0 -> 1.
----------------------------------------------------------------
