; IBLED
;---------------------------------------------------------------
;! Interactive BaseLine based visibility EDitor
;# TASK UV VLBI CALIBRATION EDITING TV-APPL INTERACTIVE
;-----------------------------------------------------------------------
;;  Copyright (C) 1995, 1997, 1999-2004, 2006-2010, 2016
;;  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
;-----------------------------------------------------------------------
IBLED     LLLLLLLLLLLLUUUUUUUUUUUU CCCCCCCCCCCCCCCCCCCCCCCCCCCCC
IBLED     Task to edit data baseline-by-baseline using the TV
INNAME                             Input UV file name (name)
INCLASS                            Input UV file name (class)
INSEQ             0.0     9999.0   Input UV file name (seq. #)
INDISK            0.0        9.0   Input UV file disk unit #
DOCAT            -1.0       2.0    Catalog work file ?
IN2SEQ            0.0              Sequence number of work file
IN2DISK           0.0       9.0    Disk on which to write work
                                   file, 0 => any
DOHIST           -3.0       1.0    Record flags in history file
SOURCES                            Source list
CALCODE                            Calibrator code '    '=>all
                                   Source model to plot:
IN3NAME                             CLEAN map name (name)
IN3CLASS                            CLEAN map name (class)
IN3SEQ            0.0    9999.0     CLEAN map name (seq. #)
IN3DISK           0.0       9.0     CLEAN map disk unit #
IN3VER           -1.0   46655.0    CC file version #
NMAPS             0.0    4096.0    No. CLEAN map files
NCOMP                              # comps to use for model.
                                   1 value per field
FLUX                               Lowest CC component used.
TIMERANG                           Time range to include
STOKES                             Stokes type to display
SELBAND                            Bandwidth to select (kHz)
SELFREQ                            Frequency to select (MHz)
FREQID                             Freq. ID to select.
BIF               0.0     1000.0   Lowest IF number 0=1
EIF               0.0     1000.0   Highest IF number
BCHAN             0.0     8192.0   Lowest channel number 0=>1
ECHAN             0.0     8192.0   Highest channel number
ANTENNAS                           Antennas to edit.
BASELINE                           Baselines with ANTENNAS
UVRANGE           0.0              UV range in kilolambda
SUBARRAY          0.0     1000.0   Subarray, 0 => all
                                   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 0 => high
                                      < 0 no flagging on input
                                      Used w single-source too
OUTFGVER          0.0              Output FG 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.
                                   Task enrichment parameters:
DPARM                              (1) 0 => display amplitude
                                       1 => display phase,
                                       can change interactively
                                   (2) if > 0, include
                                       autocorrelation data
                                   (3) if > 0 will average IFs
                                       selected with BIF to EIF
                                   (4) input data interval in
                                       secs.  <=0 -> 10
                                       PLEASE SET 4 & 5 !
                                   (5) data averaging time in
                                       secs:  <=0 => >= 10
                                   (6) If > 1, plot error bars,
                                       can change interactively
                                   (7) Min value to plot, can
                                       be changed interactively.
                                       0 => use min. in data
                                   (8) Max value to plot, can
                                       be changed interactively.
                                       0 => use max. in data
                                   (9) If > 1, don't plot whole
                                       visibility function along
                                       the top of the screen,
                                       can change interactively
BADDISK                            Disks to avoid for master and
                                   scratch files
----------------------------------------------------------------
IBLED
Type:  Task
Use:   To edit visibility data interactively. This task is complementary
       to TVFLG and will be mainly useful for editing data from
       interferometers with a relatively small number of baselines (e.g.
       VLBI experiments).  The visibility function for a single baseline
       is displayed on the TV device and the user has various editing
       options (all under a menu-like control interface) available to
       flag bad data.  There are also various display and data selection
       options available in the menu.  For multi-source data a flagging
       (FG) table is written;, for single-source data the flagging
       information is applied at the end of the editing sessions.

       IBLED is for editing continuum data from one or more IFs.
       Multiple spectral channels may be averaged in the master file
       used for display and editing, while multiple IFs may be averaged
       together or kept separate.  These averagings as well as an option
       time averaging may be used to find the ratio of the vector- to
       scalar-averaged amplitudes.  This will be 1.0 for stable data of
       high signal-to-noise and near 0 for signal-free data.  This ratio
       may be displayed and used in editing in addition to the displays
       and uses of the vector-averaged amplitude and phase.  If the IFs
       are kept separate, one may also display and edit the ratio in
       amplitude or difference in phase of one IF to a second.
Adverbs:
  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.
  DOCAT......True (>0) means to use a cataloged file for the "master
             file".  It creates a new one or uses an old one, depending
             on the value of IN2SEQ.  One can run IBLED a number of
             times using the same master file, before applying the final
             list of flag commands to the input data file.  (The master
             file is destroyed when the flag commands are applied or, if
             DOCAT <= 0, on EXIT.)  If DOCAT = 2 and IN2SEQ = 0, then
             the program returns to the user immediately, prepares the
             cataloged master file, and then exits.  The program must be
             rerun with an appropriate, non-zero value of IN2SEQ to flag
             the data.  This option allows the user to do other things
             while creating a large master grid file.
  IN2SEQ.....Sequence number of cataloged master grid file. 0 => create
             new one, else use existing one of seq number = IN2SEQ.
             NOTE: to use this option, all of the adverbs must have the
             same value as when the old grid file was created.
  IN2DISK....Disk on which to write the catalogued work file,
             0 => choose a disk, avoiding those in BADDISK.
  DOHIST.....> 0 => record task execution and flagging info in the
             history file (this can be a lot!).  <= 0.0 means to omit
             the flagging info and <= -9.5 means to omit the execution
             information as well.
  SOURCES....List of sources to be displayed. '  '=> all; if any starts
             with a '-' then all except ANY source named.
  CALCODE....Sources may be selected on the basis of calibrator code:
                '    '  =>  any calibrator code selected
                '*   '  =>  any non blank code (cal. only)
                '-CAL'  =>  blank codes only (no calibrators)
                anything else = calibrator code to select.
  IN3NAME....Source model file name. If selected, a plot of the model
             amplitude will appear as an overlay in the lower frame.
             This can be selected or de-selected using the "PLOT MODEL"
             option on the left-hand menu. The model will not be plotted
             for phase or de-correlation data.  Models made with either
             value of DO3DIMAG in IMAGR are supported.
  IN3CLASS...Source model file class
  IN3SEQ.....Source model file sequence number
  IN3DISK....Source model disk number
  IN3VER.....CC file version # for source model file
             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.
  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.
  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.
  TIMERANG...Time range of the data to be displayed. In order: Start
             day, hour, min., sec, end day, hour, min., sec. in days
             relative to reference date.
  STOKES.....The desired Stokes type of the data for display and
             editing.  It is probably a good idea to view the data
             without Stokes conversion, i.e., STOKES = ' '.  However,
             there may be times when conversion to, say, STOKES = 'IQUV'
             may make sense.  Note that a flag of Stokes I flags both RR
             and LL.  The value of STOKES controls the default set of
             polarizations (correlators) to be flagged.  However, you
             may enter interactively any desired and reasonable set.
  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 result in an ambiguity.  In that case, the task
             will request that you use FREQID.
  BIF........Lowest IF to grid. Note that unless you have requested the
             selected IF's to be averaged together (see DPARM(3)) then
             the first IF displayed on the TV will be BIF, other IF's
             can then be displayed interactively by selecting them from
             the menu.
             **************************************************
             NOTE to VLA users: IF=1 corresponds to the VLA AC ifpairs
             and IF=2 corresponds to the BD ifpairs.
             **************************************************
  EIF........Highest IF to grid.    0 => highest.
  BCHAN......First channel to AVERAGE together.   0 => 1.
  ECHAN......Last channel to AVERAGE.  0 => highest.
  ANTENNAS...A list of the antennas to edit.  If any number is negative
             then all antennas listed  are NOT desired and all others
             are.  All 0 => edit all.
  BASELINE...Baselines to be edited, use BASELINE and ANTENNAS.  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 gridded in 1000's of
             wavelengths.  0  =>  1, 1.E10
  SUBARRAY...Subarray number to grid.  0 => all.  If you have
             multi-source data with more than one source at a time, then
             you will need to specify the SUBARRAY and do one of them at
             a time.
  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 multi-source data or
             an SN table for single-source.   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 for reading the data.   FLAGVER = -n => no
             flagging on input.
  OUTFGVER...Flag table version to be used on output for both single-
             and multi-source data sets.  If OUTFGVER is <= 0 or
             greater than FGmax (the previously highest FG version
             number), then a new FG table will be created for the new
             flags with version FGmax+1.  This new table will also
             contain the flags applied on input (if any) from FG
             version FLAGVER.  If OUTFGVER specifies a pre-existing FG
             version, then the input flags are not copied even if
             OUTFGVER and FLAGVER are not equal.
  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......(multi-source) 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).
  DPARM......(1) = 0 => display amplitudes for editing
                 = 1 => display phases for editing
                 These can be interactively toggled within the task.
             (2) if > 0, autocorrelation data will be calibrated and
                 averaged into the master file
             (3) if > 0 will average IFs BIF through EIF.
             (4) Normal integration time found in the data.  PLEASE
                 PROVIDE THIS NUMBER.  0 => 10 seconds to the routine
                 that reads in the data averaging and calibrating them.
                 Then a new integration time will be used based on the
                 averaged data of the first baseline.
             (5) Data samples within DPARM(5) seconds are averaged after
                 calibration.  This averaging along with averaging over
                 IFs and/or spectral channels provides the estimate of
                 the decorrelation.  IT IS BEST TO SET THIS VALUE.
                 If DPARM(5) <= 0, the task will average the data to 10
                 seconds and then read through the averaged data of the
                 first baseline and set the sampling to the minimum
                 interval found (>= 10 seconds).
             (6) if > 1 then IBLED will assume that the weights
                 associated with the data are correctly scaled so as to
                 be easily related to true error bars and will plot them
                 as such. The default is not to plot error bars and to
                 represent each datum with the same size vector on the
                 TV.  This can be changed interactively.
             (7) Minimum amplitude (Jy) (or phase (degrees)) to be
                 displayed.
             (8) Maximum amplitude (Jy) (or phase (degrees)) to be
                 displayed. Both DPARM(6) and (7) can be set
                 interactively also.
             (9) If = 0 => plot the whole of the visibility function for
                 the particular baseline across the top of the TV.
                 Normally a baseline will have more data points than
                 there are pixels across the TV so IBLED will only plot
                 part of the data in the main editing frame, however it
                 is useful to be able to see the whole visibility
                 function while only editing part of it, this option
                 enables the user to do that. If DPARM(9) = 1 then the
                 whole visibility function will not be plotted. This can
                 be changed interactively.
            (10)
  BADDISK....List of disks to avoid for BOTH scratch files and the
                 master file (if OUTDISK = 0).
----------------------------------------------------------------
    IBLED has three main steps:
(1) The data are selected and calibrated using all of the usual
    calibration adverbs and options.  Then they are averaged over
    spectral channels BCHAN through ECHAN, over IFs BIF through EIF (if
    DPARM(3) > 0), and over DPARM(5) seconds of time.  The resultant
    visibilities are written to a "master file" which is cataloged
    temporarily or (semi) permanently on disk INDISK2 with class IBLEDR.
    Each visibility record in this file consists of a weight,
    vector-averaged amplitude, vector-averaged phase, and
    "decorrelation" index (ratio of vector-averaged to scalar-averaged
    amplitude).  For autocorrelation data, the amplitude is the real
    part (with sign) and the decorrelation is the rms in the real part.
    This master file can be used in one or, if DOCAT > 0, more than one
    session of step (2) below to prepare flag commands which are stored
    in an FC table attached to the master file.
(2) The session(s) in which the user interacts with his data arranging
    the TV display and then selecting which data are to be flagged.  The
    data are plotted with time along the X axis plotting one point per
    TV pixel and skipping 20 pixels between scans.  Therefore, the time
    axis is quite non-linear.  Tick marks are placed at integer hour
    points along the X axis and the end points labeled to provide you
    with some idea of the times.  All interactive editing operations
    provide detailed displays of the currently selected time and
    visibility.  The main editing area may not be large enough to
    contain all the data.  In this case, a smaller "frame" of data is
    selected and you may alter the selected frame to gain access to all
    of your data.  A small plot at the top of the screen shows all of
    the data, potentially with a fairly crowded X (time) axis.
(3) The actual flagging of the data and writing of the history file.  A
    flag table is written for multi-source files and the uv data
    themselves are flagged for single-source files. This should be done
    when exiting if you have not cataloged the master file (i.e. DOCAT
    <= 0) or when you are fully satisfied with your flag commands.  When
    the flags are applied to the input data set, the master file is
    deleted.

The interactive session is driven by a menu which is displayed on the
same screen as the data.  Move the cursor to the desired operation
(noting that the currently selected one is highlighted in a different
color on many TVs) and press button  A, B, or C to select the operation.
Press button D for a short explanation of the selected operation.  The
first column contains options to alter the display of the data and the
choice of which data are flagged ultimately.  The second column has 7
interactive modes for selecting data to be flagged, 2 operations on the
FC table itself, and 10 operations which cause the display to be
changed.

When the menu is displayed, one or more lines of status information are
displayed at the bottom of the screen.  The line that is always present
shows the type of data displayed and which Stokes and whether one or all
sources, IFs, and channels will be flagged by the next flag commands.
If all baselines to on or both of the displayed antennas will be flagged
and/or if the points are currently plotted with error bars, a second
line reflecting this fact will be displayed.  If the Stokes type, the
first or second IF, or the error bar type will change on the next LOAD,
then another line is displayed saying "NEXT LOAD SHOWS" these new
things.  Finally, if some data are omitted from the plot due to
user-selected plot scaling, then another line appears warning of this
fact.  The plot of the data is labeled along the vertical axis by normal
labeled tick marks and the units, while the horizontal axis has ticks at
integer hours and time strings at both ends of the plotted data.  The
line at the top of the plot identifies the data currently displayed.

The left-hand menu section begins with 3 operations to alter the TV
display zoom and color transfer functions.  The zoom is useful for
greater accuracy in selecting data to be flagged. Then there are 3
options to set the range of amplitude, phase, and decorrelations which
are actually plotted.  These default to the full range in the current
data, and can be set back to default by entering 0 0.  The next two
options ask you to enter the desired IF number and Stokes type for the
next display, but do not actually change the display.  Use any of the
redisplay options in the second menu (LOAD is simplest) to update the
display.  The next option allows you to specify a second IF number.
When that is not 0 and not the same as the first IF, IBLED plots the
amplitude ratio or phase difference of the first IF and the second IF.
The next 5 options switch the binary states of several flags: the first
controls the plotting of the full data set in the small plot at the top,
the second controls the vertical bars plotted about the data switching
betwen error estimates and a small constant, and the rest control
whether one or all spectral channels, IFs, and sources are flagged by
the following flag commands.  The next option allows you to set the
Stokes which will be flagged by the following flag commands (see below).
And the final 2 options allow you to switch between flagging only the
displayed baseline and flagging all antennas to one or both of those
displayed.  The last two menu items actually reflect the station names
for the two antennas and change as you change baselines.

The menu looks like:
-------------------
| OFF ZOOM        |   To turn off any zoom magnification
| OFF ENHANCEMENT |   To turn of black & white and pseudo-color
                      enhancements (usually top plot only)
| TVFIDDLE        |   To do interactive zoom, pseudo-color contours, or
                      black and white enhancement
| ENTER AMP RANGE |   To type in the intensity range to be used for
                      plotting amplitudes (Jy or ratio)
| ENTER PHS RANGE |   To type in the phase range to be used for plotting
                      phases (degrees)
| ENTER DCR RANGE |   To type in the decorrelation range to be used to
                      plot decorrelation (0-1 or ratio)
| ENTER IF        |   To enter on the terminal the desired IF to be
                      displayed next.
| ENTER STOKES    |   To enter on the terminal the STOKES type to be
                      displayed next.
| RATIO 2ND IF    |   To enter on the terminal the IF to divide into the
                      first IF to display ratios of data .  0 turns off
                      this option.
| SHOW TOP PLOT   |   To toggle switch to display complete data for
                      current baseline along top of screen
| PLOT MODEL      |   To toggle between displaying and not displaying
                      the model visibility (when selected by adverbs)
| PLOT ERROR BARS |   To toggle switch to plot error bars or a small
                      constant bar - works only with fully calibrated
                      data weights.
| SWTCH 1-CH FLAG |   To toggle between flagging all spectral channels
                      and only BCHAN-ECHAN.
| SWTCH 1-IF FLAG |   To toggle between flagging all IFs or only the one
                      shown (or BIF-EIF if averaged).
| SWTCH 1-SO FLAG |   To toggle between flagging all sources in any time
                      range and only those displayed.
| SET STOKES FLAG |   To enter on the terminal the 4-character string
                      which will control which correlators
                      (polarizations) are flagged.  Note: this parameter
                      applies only to flag commands prepared after it is
                      set.  It should be changed whenever a different
                      Stokes is displayed.  See also below.
| FLAG station1   |   To toggle switch between flagging all data to this
                      antenna and only station2.
| FLAG station2   |   To toggle switch between flagging all data to this
                      antenna and only station1.
-------------------
The all-channel flag remains true if the full range of channels in the
input data set are averaged in the data being flagged.  The all-IF flag
remains true if the full range of IFs in the input data set are averaged
in the data being flagged.


The right-hand menu section begins with 8 flagging operations: to flag
one time at a time, to flag a range of times, to flag an area in the
intensity-time plane, to flag all points above some intensity or below
some intensity, to flag all points more than x times the rms from the
mean, to flag all points above or below a user-drawn curve in the
intensity-time plane, and lastly, to flag all times in all frames for
the displayed data.  During the first 7 operations the current position
selected by the cursor is displayed in the upper left hand corner of the
TV with source name, time, flux, and (optionally) error.  Lines or boxes
are also drawn in the TV to indicate the area being selected for
flagging.  During interactive flagging, button A switches between
corners or end times except for FLAG TIME where it does the flagging and
FLAG INTERACTIV where it marks a point.  Button B does the flagging and
loops for more except for FLAG INTERACTIV where it marks another point
on the curve.  Button C also does the flagging, but the program then
returns to the main menu rather than prompting for more flagging
selections.  Button D exits back to the menu without doing any
additional flagging.  When a flagging command is generated, any flagged
data currently displayed are erased (only from the lower plot) and some
number of records are written into the FC table.  Note that one can flag
only those data in the current frame using the intensity type in the
current display (plus other IFs, Stokes, etc. as chosen by the flagging
control commands).  You must visit other frames in order to flag them.
The last flag operation, FLAG ALL TIME, is not interactive and simply
flags all data for the displayed baseline (or antenna) for all times
in all frames.

The next two operations in the right-hand menu allow you to list the
flag commands already in the FC table and to undo any of them.  The UNDO
FLAGS peration prompts you for a list of flags to be undone by number
(get these from LIST FLAGS) with 0 ending the list.  When a flag is
undone, all cells in the master file which were first flagged by that
command are restored to use, except for those also flagged by some later
command.  This is done automatically by IBLED without the special
commands required by TVFLG.  After an UNDO FLAGS operation, the TV is
reloaded, potentially with new plot scales.

The next 10 operations in the right-hand menu also cause the display to
be updated immediately if needed.  The first three select the type of
data to be displayed and used in flagging; the next four change the
current frame (portion of the current baseline) being displayed and
edited; the next two change the current baseline, and the last forces an
update of the screen including the top plot in case some of the changes
(e.g. flagged points, new IF or Stokes selection, etc.) have not been
fully reflected in the displays.  The SELECT FRAME uses the top plot to
select the desired frame interactively and can work only when the top
plot is displayed.  The last option in this menu selection is to EXIT,
optionally applying an flagging commands to the input data set.

The menu looks like:
-------------------
| FLAG TIME       |   To flag single visibility points
| FLAG TIME RANGE |   To flag all data in a range of times
| FLAG AREA       |   To flag a rectangular area in the flux-time plane
| FLAG ABOVE      |   To set a lower limit and flag all data above over
                      a selected range of times
| FLAG BELOW      |   To set an upper limit and flag all data below over
                      a selected range of times
| FLAG ABOUT MEAN |   To set a time range within which the mean and rms
                      are determined and then flag all data outside the
                      range MEAN +/- x * RMS, where the user is asked to
                      specify x and to confirm the flagging.
| FLAG INTERACTIV |   To define a piecewise-linear curve and then flag
                      all data above or below it
| FLAG ALL TIME   |   To flag all times in all frames at once
| LIST FLAGS      |   To list selected range of flag commands
| UNDO FLAGS      |   To remove flags by number from FC table and undo
                      that flagging in the data
| SHOW AMPLITUDE  |   To reload the TV displaying amplitudes
| SHOW PHASE      |   To reload the TV displaying phases
| SHOW DECORRELAT |   To reload the TV displaying decorrelation index
| SELECT FRAME    |   To select the visibility set to be displayed
                      interactively from the top plot
| FIRST FRAME     |   To display the first set of visibilities
| NEXT FRAME      |   To display the next set of visibilities
| PREVIOUS FRAME  |   To display the previous set of visibities
| SELECT BASELINE |   To display a new baseline by entering the desired
                      antenna pair on the terminal
| NEXT BASELINE   |   To display the first set of visibilties from the
                      next baseline
| PREV BASELINE   |   To display the first set of visibilties from the
                      previous baseline
| LOAD            |   To reload the TV with the current flags and
                      parameters, checking the scale
| EXIT            |   To resume AIPS and, optionally, enter the flags in
                      the data
-------------------


Before the flags are entered in the data, IBLED asks the user whether or
not he actually wishes to do this.  You must respond yes or no.  If the
master file is not cataloged (DOCAT <= 0), then your flags will be lost
if you do not say yes.  If the master file is cataloged and you intend
to do more flagging on this particualr set of data, then you should
answer no.  Then, you can resume later without having to compute a new
master file and will have the option to undo previous IBLED flag
commands.  Once the flags are applied to the input data set, they are
much harder to undo and the master file is destroyed since it no longer
accurately represents the input data.

The subject of Stokes flags deserves more discussion.  In their simplest
form, they are a string of four 1's and 0's with the 1's represeenting
the correlators to be flagged and the 0's those that are not altered.
These strings always represent correlators in their basic groupings and
orders - I/Q/U/V or RR/LL/RL/LR or XX/YY/XY/YX - even if the current
data set only has, say, LL data.  IBLED allows you to enter Stokes flags
in this form, but also allows more mnemonic forms as well.  If I, Q, U,
and/or V data are displayed, then the strings i, Q, U, V, IQU, IQUV, and
IV are also accepted.  If RR, LL, RL, and/or LR data are displayed, then
the strings RR, LL, RL, LR, HALF, NOLL, NORR, RRLL, and RLLR are
accepted (HALF = RRLL = 1100, NOLL = 1011, NORR = 0111).  If XX, YY, XY,
and/or YX data are displayed, then the strings XX, YY, XY, YX, HALF,
NOYY, NOXX, XXYY, and XYYX are accepted (HALF = XXYY = 1100, NOYY =
1011, NOXX = 0111).  FULL is always accepted as 1111.  Inside IBLED,
these strings apply to the Stokes form(s) chosen for editing and
display, which, because of the STOKES input adverb, are not necessarily
those of the input data set.  If they are of different forms then a
translation must take place.  The only such translation that is likely
to occur is when the user edits in I/Q/U/V a data set in RR/LL/RL/LR.
In this case, any flag of I and/or V flags both RR and LL and any flag
of Q and/or U flags both RL and LR.  IBLED attempts to support the other
translations as well.
----------------------------------------------------------------
