; ANBPL
;---------------------------------------------------------------
;! plots and prints uv data converted to antenna based values
;# TASK UV VLBI PLOT
;-----------------------------------------------------------------------
;;  Copyright (C) 2006, 2009-2010, 2014, 2016, 2018-2020
;;  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
;-----------------------------------------------------------------------
ANBPL     LLLLLLLLLLLLUUUUUUUUUUUU CCCCCCCCCCCCCCCCCCCCCCCCCCCCC
ANBPL     Plots/prints u,v data as antenna-based values
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 #
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   Lowest channel number 0=>1
ECHAN             0.0     4096.0   Highest channel number
                                                        0=>BCHAN
                                   If BCHAN and ECHAN are
                                   different, then data will be
                                   averaged across specified
                                   channel range before plotting
BIF               0.0      100.0   Lowest IF number 0=>1
EIF               0.0      100.0   Highest IF number 0=>high
AVGIF            -1.0        1.0   > 0 => average IFs
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
ANTENNAS                           Antennas to be plotted
BASELINE                           Baselines with ANTENNAS
                                   See explanation.
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
                                   See explanation.
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=>1.
                                   -1 => all, but beware!
SOLINT                             Time over which to average
                                   data before plotting (mins)
                                   =0 => no averaging
                                   >0 SOLINT=MIN(SOLINT, SCAN)
                                   <0 SOLINT=ABS(SOLINT)
                                      average through scans
DO3COLOR         -1.0        1.0   Plot separate IFs and/or
                                   Stokes in separate colors.
OPCODE                             Type of plot:
                                   'ALIF' => combine all IFs
                                   'ALST' => combine all Stokes
                                   'ALSI' => all IFs & Stokes
BPARM                              Control parameters
                                   1 : X-axis type code 0 -> 2
                                       1 = time (IAT)
                                       2 = time (IAT hms),
                                       3 = source number,
                                       4 = hour angle (hours)
                                       5 = elevation (degrees)
                                       6 = azimuth (degrees)
                                       7 = parallactic ang (deg)
                                   2 : Y-axis type code 0 -> 12
                                       if <0 => AMP & PHASE
                                       plotted together
                                       11 = ant-based amplitude
                                       12 = ant-based cmplx amp
                                       13 = ant-based cmplx phas
                                       14 = ant-based normalized
                                            cmplx phase
                                       15 = ant=based cmplx real
                                       16 = ant-based cmplx imag
                                       17 = weight
                                   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 : Ymin (phase plot)
                                   9 : Ymax (phase plot)
                                   10: > 0 scalar average
                                       = 0 vector average
NPLOTS                             Max number of plots per page.
                                   0 => 3; If bparm(2)<0 =>
                                   Max number of pairs of plots.
SYMBOL          0.0        24.0    Symbol to use when plotting.
                                   0 => Vertical line
                                   1 - 23, standard types
FACTOR          0.0        50.0    Scale the plotted symbol
LTYPE        -410.0       410.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 no plot
                                   > 0 Do plot on the TV
                                   < 0 make a plot file
GRCHAN          0.0         8.0    TV Graphics channel 0 => 1
XYRATIO         0.0                X/Y ratio 0 -> fit TV or 1 PL
DOCRT            -3.0     132.0    0 -> do no printer display,
                                   > 0 -> use the terminal,
                                   else use the line printer
                                   > 72 => terminal width
OUTPRINT                           Printer disk file to save
NDIG                        8.0    Number of digits in display
BADDISK                            Disks to avoid for scratch
----------------------------------------------------------------
ANBPL
Type: Task
Use:  Plots and or prints data from a u,v data base making a plot file
      or TV plot and/or a printer output.  The data are converted to
      antenna-based form before plotting or printing.  Plotting is
      done one antenna per plot with the number of plots per page
      specified by NPLOTS.  The plots are written one page per plot
      file so in general several plot files will be created (if DOTV
      is false).
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.
  SOURCES....Source list.  If the data is a multi-source file
             ANBPL 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 => BCHAN
             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 => highest
  AVGIF......> 0 => IFs BIF through EIF will be averaged before
             plotting, otherwise they will be plotted separately.
  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.
     Note that multi-subarray data are separated by 5 days for each
     subsequent subarray if the data are DBCON's output.
     ANBPL does not remove this time shift starting May 1, 2001.
     So pay attention on this fact selecting the TIMERANG.
  STOKES.....Specifies the stokes type(s) to be plotted:
             Recognized values are 'I', 'Q', 'U', 'V', 'IV', 'IQU',
             'IQUV' 'RR', 'LL', 'LR', 'RL', 'RRLL', 'HALF', 'FULL'
             ' ' => 'HALF' = 'RRLL'
  ANTENNAS...A list of the antennas to be plotted.
  BASELINE...Baselines between antennas named in ANTENNAS and those
             named in BASELINE are selected..  There are four possible
             combinations of ANTENNAS and BASELINE:
             1. ANTENNAS = 0; BASELINE = 0.
                All possible baselines are selected.
             2. ANTENNAS <>0; BASELINE = 0.
                a)All ANTENNAS > 0
                  Baselines including an antenna in the ANTENNAS list
                  are selected;
                b)Some ANTENNAS < 0
                  All baselines NOT including an antenna in the ANTENNAS
                  list are selected;
             3. ANTENNAS = 0; BASELINE <> 0.
                a)All BASELINE > 0
                  Baselines including an antenna in the BASELINE list
                  are selected;
                b)Some BASELINE < 0
                  All baselines NOT including an antenna in the BASELINE
                  list are selected;
             4. ANTENNAS <> 0; BASELINE <> 0.
                a)All ANTENNAS>0 and all BASELINE>0
                  Baselines between antennas named in ANTENNAS and those
                  named in BASELINE are selected.
                b)Some ANTENNAS<0 .OR. some BASELINE<0
                  Baselines between antennas named in ANTENNAS  and
                  those named in BASELINE are DE-selected, all others
                  are selected.
  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.
             If APARM(1)>0 then
                if FLAGVER>0 => the specified table is copied to
                   the next highest version and recognized bad points
                   are added to this table
                if FLAGVER=0 => the highest numbered table is copied
                   to the next highest version and recognized bad
                   points are added to this table
                if FLAGVER<0 => Recognized bad points
                   are recorded in a new FG table
  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 => 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=> 1.
             To have all subarrays plotted, give -1.  Be aware that the
             station names and model plotted will be for subarray 1
             only.
  SOLINT.....Time over which to pre-average data before
             plotting (mins). =0 => no pre-averaging.
             If SOLINT<0 then SOLINT = ABS(SOLINT) and averaging does
             not pay attention on scans
             If SOLINT>0 then averaging pays attention on scans.
             SOLINT = MIN(SOLINT, SCAN)
             If ABS(SOLINT)>0 then
             X can be only time;
             Y can be only amp, phas, real, imag, weight or rms
  DO3COLOR...> 0 => plot the separate IFs and/or polarizations  in
                    different colors if they occur in the same panel.
             <=0 => otherwise they are done in the same color.
             The color scheme is
                COLOR = 0
                DO IF = 1,Nif
                   DO POL = 1,Npol
                      set and use COLOR
                      COLOR = COLOR + DeltaColor
                      END DO POL
                   END DO IF
             where COLOR=0 is pure RED, DeltaColor is set so that the
             last value of COLOR is 1 which is pure BLUE.  Npol is the
             number of requested polarizations (1 unless OPCODE is
             ALSI or ALST) and Nif is the number of IFs plotted in the
             panel (1 unless OPCODE is ALIF or ALSI, then BIF to EIF)
             Thus, if there are 4 IFs and one polarization, the plot
             will be of red, yellow, cyan, and blue for IFs 1 through
             4, resp. If there are 2 IFs and 2 polarizations (RR and
             LL say), then red is RR in IF 1, yellow is LL in IF 1,
             cyan is RR in IF 2, and blue is LL in IF 2.  Note that
             the blue is plotted after the red and so may overlap and
             obscure the red.
  OPCODE.....Type of plot:
             'ALIF' => will plot data for all IFs (BIF through EIF) on
                    a single plot (antennas and polarizations are
                    plotted separately).
             'ALST' => will plot data for both polarizations (RR and
                    LL) on a single plot (antennas and IFs are plotted
                    separately).
             'ALSI' => will plot data for both polarizations (RR and
                    LL) and all IFs (BIF through EIF) on a single plot
                    (antennas are plotted separately).
             other  => will plot each request polarization, each
                    requested IF and each each requested antennas
                    individually looping in that order.
  BPARM......Control parameters:
     1 = type of X-axis (                other => 2
         1 = time (IAT)
         2 = time (IAT hms),
         3 = source number,
         4 = hour angle (hours)
         5 = elevation (degrees)
         6 = azimuth (degrees)
         7 = parallactic angle (deg)
              Moving sources are supported for types 4-7 if there is a
              PO table
     2 = type of Y-axis (as above).       other => 12
         11 = amplitude (antenna based amplitude)
         12 = amplitude (antenna based complex, amplitude value)
         13 = phase,    (antenna based complex)
         14 = phase     (antenna-based complex normalized)
         15 = real part (antenna based complex)
         16 = imaginary part (antenna based complex)
         17 = weight
         If <0 => Both Amplitude and phase are plotted.
     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 = Minimum of phase (amp+phase).  See note below on units.
     9 = Maximum of phase (amp+phase)  (if = BPARM(8) do self-scale in
                                        phase).
    10 : > 0 scalar average
         = 0 vector average 	
    Units to use in BPARM(4) - BPARM(9):
        axis type = 11, 12, 15, 16     Jy
                    13, 14, 5, 6, 7    Degrees
                    2                  Days from start of observation
                    1, 4               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).
  NPLOTS......Max number of plots per page. 0 => 3.  If AMP and
              PHASE are plotted together (BPARM(2) < 0), NPLOTS
              equals max. number of pairs of plots per page.
  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 (X) with gap
              0 => '|' (i.e. vertical lines).
  FACTOR......Scale the plotted symbol.  0 -> 1
  LTYPE.......Labelling type, see HELP LTYPE for details:
              1 = border, 2 = no ticks, 3 or 7 = standard, 4 or 8 =
              relative to ref. pixel, 5 or 9 = relative to subimage
              (BLC, TRC) center, 6 or 10 = pixels.  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.
              Add n * 100 to alter the metric scaling.
  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.
  DOCRT.......0 -> Do no printer display
              BPARM(1) must be 1 or 2 as well to get printer output.
              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.
                 When OUTPRINT is blank, the line printer will be
                 used.  ANBPL now counts the lines to be printed
                 before printing any and asks for permission to
                 continue if the count > 500.
              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.
  NDIG........Number of digits in the display: 3 to 8.
  BADDISK....The disk numbers to avoid for scratch files (sorting
             tables mostly).
----------------------------------------------------------------
