; QUACK
;---------------------------------------------------------------
;! Flags beginning or end portions of UV-data scans
;# Task UV
;-----------------------------------------------------------------------
;;  Copyright (C) 1995, 1999, 2002, 2006-2007, 2011-2012, 2018
;;  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
;-----------------------------------------------------------------------
QUACK     LLLLLLLLLLLLUUUUUUUUUUUU CCCCCCCCCCCCCCCCCCCCCCCCCCCCC
QUACK     Flags specified portion of scans of UV data
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 #
STOKES                             Limit flagging by Stokes
BIF               0.0       90.0   Limit flagging to BIF-EIF
EIF               0.0       90.0   Limit flagging
SOURCES                            Sources selected/deselected
SUBARRAY                           Subarray number 0=>all.
SELBAND                            Bandwidth to flag (kHz)
SELFREQ                            Frequency to flag (MHz)
FREQID                             Freq. ID to flag. -1=>all.
                                   0=> first Freq. ID.
TIMERANG                           Time: start day,hr,min,sec
                                         stop day,hr,min,sec.
ANTENNAS                           Antennas to flag
BASELINE                           Baselines with ANTENNAS
FLAGVER                            Flag table version number
                                   0 => highest
OPCODE                             'END ', 'BEG ', 'ENDB'
                                   'TAIL';   ' ' => 'BEG '
REASON                             Reason (24 char.)
APARM                              (1) => Cutting time (min)
                                   from end (ENDG) 0 => 2
                                   (2) => Cutting time (min)
                                   from beg/end (BEGB/ENDB)
                                   0 => 0.1
                                   (3) Back start of flagging
                                    <0 => no padding (0 seconds)
                                     0 => 0.5 seconds [default]
                                    >0 => APARM(3) seconds
BADDISK                            Disks to avoid for scratch
----------------------------------------------------------------
QUACK
Task:  This task will flag selected portions of scans in a
       multi-source UV data set.  All data EXCEPT the last APARM(1)
       minutes can be flagged using OPCODE='END ' for a selected
       set of scans.  Alternately the first/last APARM(2) minutes in
       each selected scan may be flagged using OPCODE='BEG '/'ENDB'.
       One can also delete APARM(2) minutes of data following the end
       of each scan, for those systems that may not get the word to
       all telescopes at the same time, using OPCODE='TAIL'.

       Flagging info is entered in the specified FG table and is based
       on the scans defined in the NX table.  If no NX table is
       present, one can be created using task INDXR.
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.
  STOKES.....Limit flags to specified Stokes value.  ' ' = '1111'
             Allowed values for RR/LL..  are 'FULL', 'HALF', 'RR',
             'LL', 'RL', 'LR', 'RRLL', 'RLLR', and any combination of
             4 1s and 0s (e.g. '1011' to delete all R polarizations).
  BIF........Limit flag to IF beginning with BIF;  0 -> 1.
  EIF........Limit flag to range BIF through EIF.  0, < BIF -> max.
  SOURCES....List of sources in the data file to be flagged.
             If any names begins with a '-' all sources listed
             are deselected (i.e. all others are).
  SUBARRAY...The subarray desired for the operation. 0=> all.
  SELBAND....Bandwidth of data to be flagged. 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 flagged. If more than
	     one IF is present SELFREQ is the frequency of the
	     first IF required. Units = MHz, 0=> all
  FREQID.....Frequency identifier to flag (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. 0=> program will
             select the first in the FQ table, -1=> flag all
             FREQID values. Note this useage is slightly
             different from that in other tasks.
  TIMERANG...The specified time range; scans whose central time
             is in this range will be affected.
             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 = start IAT = 0 =>, all times
  ANTENNAS...A list of the antennas to be flagged.  If any number is
             negative then all antennas listed are NOT to be flagged
             and all others are.
  BASELINE...If any elements of BASELINE are non zero then all
             baselines between antennas named in ANTENNAS and those
             named in BASELINE are specified.  If ANTENNAS contains a
             negative value then all baselines NOT specified are
             selected.
             Examples:
             If ANTENNAS = 1,2,3 and BASELINE = 4,5 then baselines
             1-4, 2-4, 3-4, 1-5, 2-5 and 3-5 are selected.

             If ANTENNAS = -1,2,3 and BASELINE = 4,5 then ALL baselines
             EXCEPT 1-4, 2-4, 3-4, 1-5, 2-5 and 3-5 are selected.

  FLAGVER....The version of the flagging (FG) table in which to
             make the entries.
             0 => highest, or 1 if no FG table exists
  OPCODE.....Tells type of flagging:
             'END ' => flag all but APARM(1) min from end of
                       scan.
             'BEG ' => flag first APARM(2) min of each scan
             'ENDB' => flag last APARM(2) min of each scan
             'TAIL' => flag APARM(2) min after each scan
             '    ' => 'BEG '
  REASON.....Reason for flagging the data, up to 24 characters.  This
             string will be inserted in the FG table and may be used
             by UVFLG to unflag this data if you later decide to do
             so.  ' ' => 'QUACK dd-mmm-yy hh:mm:ss' where the date and
             time is filled in.
  APARM......(1) => Cutting time (min) from end (ENDG) of each
                    scan to keep, the rest is flaged. 0 => 2
             (2) => Cutting time (min) from beginning or end of each
                    scan to flag. 0 => 0.1
             (3) Back start (forward stop) of flagging to include
                 the scan edge.
                    <0 => no padding (0 seconds)
                     0 => 0.5 seconds [default]
                    >0 => APARM(3) seconds
                 A value about a fourth of the integration time of the
                 integration time will protect from inaccuracies in
                 the times due to floating-point formats.
             See EXPLAIN for details of the actual flag times used.
  BADDISK....The disk numbers to avoid for scratch files (sorting
             tables mostly).
----------------------------------------------------------------

A note on the exact times used.  Assume that a particular scan is said
in the NX table to run from T0 to T1 (T0 = TIME - 0.5* DTIME,
T1 = TIME + 0.5*DTIME where TIME and DTIME are in the NX table).  Also
define
      TB = APARM(1)
      TE = APARM(2)
      CC = APARM(3)

Then

OPCODE 'END ' flags from   T0 - CC     through   T1 - TB
       'BEG '              T0 - CC               T0 + TE
       'ENDB'              T1 - TE               T1 + CC
       'TAIL'              T1 + CC               T1 + TE

The first three do just the specific source, the last does all
sources.
----------------------------------------------------------------
