; CLPLT
;---------------------------------------------------------------
;! plots closure phase and model from CC file
;# TASK UV VLBI PLOT
;-----------------------------------------------------------------------
;;  Copyright (C) 1995-2003
;;  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
;-----------------------------------------------------------------------
CLPLT     LLLLLLLLLLLLUUUUUUUUUUUU CCCCCCCCCCCCCCCCCCCCCCCCCCCCC
CLPLT     Plots data from a u,v data base, model from a CC file
USERID       -32000.0    32000.0   Data base owner number
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             0.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.
                                   If BCHAN and ECHAN are
                                   different, then data will be
                                   averaged across given channel
                                   range before plotting.
BCHAN             0.0     4096.0   Lowest channel number 0=>all
ECHAN             0.0     4096.0   Highest channel number 0=>all
                                   If BIF and EIF are different,
                                   then data will be averaged
                                   across given IF range before
                                   plotting.
BIF               0.0      100.0   Lowest IF number 0=>all
EIF               0.0      100.0   Highest IF number 0=>all
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 triangles to plot.
                                   See HELP.
DOCALIB          -1.0        2.0   If >0 calibrate data
                                   = 2 calibrate weights
GAINUSE                            CL (or SN) table to apply
DOPOL            -1.0       10.0   If >0 correct polarization.
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 phase (mins).
                                   See HELP for hints on how
                                   to use this.
OPCODE                             If OPCODE = 'INDE' will plot
                                   all independent closure
                                   phases.
                                   IF OPCODE = ' ' will plot all
                                   closure phases, or all
                                   closure phases specified by
                                   the TRIANGLE adverb.
                                   See HELP for more info.
PHSLIMIT            0.0    180.0   Plot only those triangles
                                   exceeding plus/minus 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: Array type : 0 = VLBI
                                       1 = VLA and ATCA;
                                       2 = MERLIN; 3 = WSRT
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        10.0    Symbol to use when plotting.
                                   0 => '+' signs
                                   1 => '|' (i.e. vert. lines).
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.
----------------------------------------------------------------
CLPLT
Type: Task
Use:  Plots closure phase 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 triangle 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.

      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 triangle.  Otherwise, samples at slightly different times
      will be combined but the phases 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.
Adverbs:
  USERID.....Input file user number.  0 => logon user,
             32000 => any user.
  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.
  FLUX.......Only components > FLUX in absolute value are used in the
             model.
  NMAPS......Number of image files to use for model.  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.
  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 => ECHAN
             If BCHAN and ECHAN are set specificially then the
             data will be spectrally averaged across the range
             BCHAN -> ECHAN before being plotted.
  BIF........Start IF number to plot. 0 => 1
  EIF........End IF number to plot. 0 => BIF
             If BIF and EIF are set specificially then the
             data will be spectrally averaged across the range
             BIF -> EIF before being plotted.
  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 traingles to be plotted.
             (a) If TRIANGLE = 0, CLPLT will plot all available closure
                 phases.
             (b) If TRIANGLE(1) < 0, then CLPLT will plot all available
                 closure phases, EXLUDING those triangles involving
                 antennas listed in the TRIANGLE array (with either
                 sign)
             (c) If you wish to plot specified triangles you should
                 specify them as triplets within the TRIANGLE array.
                 E.g. TRIANGLE=1,2,4,2,5,6 will cause CLPLT to plot
                 triangles 1-2-4 and 2-5-6. You may specify up to 16
                 triangles in this manner.
             IF OPCODE = 'INDE' and TRIANGLE = 0 then CLPLT will plot
             all independent closure triangles, 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.  If > 1.5, also calibrate the weights
             (new for VLA, normal for VLBI).
  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 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.
  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
               1 => Hanning
               2 => Gaussian
               3 => Boxcar
               4 => Sinc (i.e. sin(x)/x)
             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.
             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 phase vs.
             time obeying the TRIANGLE adverb. If OPCODE =
             'INDE' then all independent triangles are plotted.
  PHSLIMIT...Plot only those triangles having closure phases
             greater in absolute value than PHASE degrees.
  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 = Type of array: 0 = VLBI, 1 = VLA and ATCA,
                        2 = MERLIN, 3 = WSRT
         Only VLBI, VLA and ATCA implemented.

    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 phase. 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 phase. If
             this is not necessary with your data, set
                  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 triangle.  Otherwise, samples at slightly different
             times will be combined but the phases 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.
  SYMBOL.....Symbol to use when plotting.
             0 => '+' signs
             1 => '|' (i.e. vertical lines).
  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.
----------------------------------------------------------------
