; TAFLG
;---------------------------------------------------------------
;! Flags data in a Table extension file
;# TASK TABLE EDITING
;-----------------------------------------------------------------------
;;  Copyright (C) 1995, 2008
;;  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
;-----------------------------------------------------------------------
TAFLG     LLLLLLLLLLLLUUUUUUUUUUUU CCCCCCCCCCCCCCCCCCCCCCCCCCCCC
TAFLG     Flags data in a Table extension file
USERID       -32000.0    32000.0   Data base owner number
INNAME                             Input file name (name)
INCLASS                            Input file name (class)
INSEQ             0.0     9999.0   Input file name (seq. #)
INDISK            0.0        9.0   Input file disk unit #
INEXT                              Input table type.
INVERS            0.0    46655.0   Input table version #.
OUTVERS           0.0    46655.0   Output table version #.
BCOUNT            0.0    99999.0   Beginning row to flag
ECOUNT            0.0    99999.0   Last row to flag: 0 => end
OPTYPE                             Type of comparison:'>','>='
                                   '=','<>','<=','<'
APARM                              Column selection parameters:
                                   1: L-side col A, no default
                                   2: L-side col A subscript
                                   3: L-side col B, no default
                                   4: L-side col B subscript
                                   5: L-side function type
                                          SEE the HELP !
                                   6: R-side col A, no default
                                   7: R-side col A subscript
                                   8: R-side col B, no default
                                   9: R-side col B subscript
                                   10: R-side function type
BPARM                              Control parameters:
                                   1: > 0 => use constant for
                                      R-side
                                   2: This constant
                                   3: Okay uncertainty in = and
                                      <> tests.
                                   4: > 0 => remove previous
                                      flagging
                                   9: Exponent for L-side
                                   10: Exponent for R-side
CPARM                              1: L-side col A factor
                                   2: L-side col A offset
                                   3: L-side col B factor
                                   4: L-side col B offset
                                   5: R-side col A factor
                                   6: R-side col A offset
                                   7: R-side col B factor
                                   8: R-side col B offset
                                   9: L-side overall factor
                                   10: L-side overall offset
----------------------------------------------------------------
TAFLG
Type: Task
Use:  Copies data from an AIPS table-format extension file to a new
      table extension file flagging rows having specified parameters.
      It can write over the input table file.  The decision about
      flagging is made in rows BCOUNT - ECOUNT by computing a function
      of one or two columns (the "L-side") and comparing the result
      with an OPTYPE comparison to a constant (BPARM(1) > 0) or to a
      2nd function of one or two more columns (the "R-side").  If the
      result of the comparison is true, then the row is flagged or
      unflagged (BPARM(4) > 0).

      If all you want to do is flag rows BCOUNT through ECOUNT, set
      OPTYPE='>'; APARM=0; BPARM=1,0 and decide what you want with
      INVERS and OUTVERS.
Adverbs:
  USERID.....Input file user number.  0 => logon user,
             32000 => any user.
  INNAME.....Input file name (name)    Standard defaults.
  INCLASS....Input file name (class)   Standard defaults.
  INSEQ......Input file name (seq. #)  0 => highest.
  INDISK.....Disk drive # of input file.  0 => any.
  INEXT......Type of input table extension.  '  ' = 'CC'
  INVERS.....Version number of input table extension.
             0 => highest.
  OUTVERS....Version number of output table extension.
             0 => highest + 1.
  BCOUNT.....Beginning row number to be included in flagging.
  ECOUNT.....Last row number included in flagging.  0 = highest.
             All rows are copied however.
  OPTYPE.....The logical result of <L-side value> OPTYPE <R-side
             value> determines whether a row is flagged.  OPTYPE
             may be '>    ', '>=  ', '=   ', '<>  ' (not equal),
             '<=  ', or '<   '.
  APARM......Column selection parameters:
     1 = L-side logical column number A:  0 => row number.
         < 0 => use absolute value of col. abs(APARM(1))
     2 = L-side subscript of column A data to use if the
         column is an array.  0 => 1.
     3 = L-side logical column number B:  0 => row number.
         < 0 => use absolute value of col. abs(APARM(1))
     4 = L-side subscript of column B data to use if the
         column is an array.  0 => 1.
     5 = L-side function number: Various functions may be
         performed on column A only or on a pair of columns A
         and B before comparison.  Functions which use column A
         only are 0 = no function, 1 = sum, 2 = asin, 3 = Log10,
         4 = ln, 5 = exp, 6 = sin, 7 = cos, 8 = tan, 9 = atan.
         In these cases, APARM(3) and (4) are ignored.  Sum
         includes those rows which are not flagged due to
         BCOUNT.  Functions which use both columns are
         10 = +, 11 = -, 12 = *, 13 = /, 14 = **, 15 = mod,
         16 = Modulus, 17 = atan2, 18 = max, and 19 = min.
     6 = R-side logical column number A:  as for L-side.
     7 = The subscript of the R-side column A data to use if the
         column is an array.  0 => 1.
     8 = R-side logical column number B:  as for L-side.
     9 = The subscript of the R-side column B data to use if the
         column is an array.  0 => 1.
     10 = R-side function number: as for L-side.  The R-side
         parms 6-10 are ignored if BPARM(1) > 0.
  BPARM......Control parameters:
     1 = Flag to set R-side to a constant: > 0 use BPARM(2) as a
         constant R-side; <= 0 compute the function specified in
         APARM(6) - APARM(10) as the R-side.
     2 = The constant comparison value for the R-side (used only
         if (BPARM(1) > 0).
     3 = For '=' and '<>' tests on floating-point columns or
         floating-point function results, the allowed difference
         between the L-side value and the R-side value to be
         regarded as "equal", i.e. if ABS(L-side - R-side) <
         BPARM(3) then L-side and R-side are considered equal.
     4 = <= 0 implies flag the row having the specified parms.
         > = implies remove flagging from those rows previously
         flagged which have the specified parms.
     9 = The exponent to which to take the L-side result value
         before final scaling and comparison.   0 => 1.
     10 = The exponent to which to take the R-side result value
         before comparison.   0 => 1.
  CPARM......After the value or absolute value of a column is
          found, it may be scaled and offset before other
          functions are applied to it.  Similarly, the result
          on the L side (only) may also be scaled and offset
          before comparison with the R-side.
     1 = L-side logical column number A scale factor: 0 -> 1.
     2 = L-side logical column number A offset.
     3 = L-side logical column number B scale factor: 0 -> 1.
     4 = L-side logical column number B offset.
     5 = R-side logical column number A scale factor: 0 -> 1.
     6 = R-side logical column number A offset.
     7 = R-side logical column number B scale factor: 0 -> 1.
     8 = R-side logical column number B offset.
     9 = L-side OVERALL result scale factor.  0 -> 1.
     10 = L-side OVERALL result offset.  0 -> 1.
----------------------------------------------------------------
TAFLG

                        FUNCTION

     TAFLG applies some function to one or two columns of an
input table extension file and compares the results to some
constant given in BPARM(2) or to the result of some other
function of one or two more rows.  Those rows for which the
comparison is true in the desired way (OPTYPE) are flagged in
the output file written by the task.

     For example: we wish to flag all rows in a CC (clean
components) table which have negative flux:
     GETN nnn
     INEXT = 'CC'; INVERS = 1; OUTVERS = 2
     APARM = 1, 1, 0, 0, 0 ; OPTYPE = '<'
     BPARM = 1, 0, 0, -1 ; CPARM = 0
     GO TAFLG
To reverse the process for components less than -1 mJy:
     INEXT = 'CC'; INVERS = 2; OUTVERS = 3
     APARM = 1, 1, 0, 0, 0; OPTYPE = '<'
     BPARM = 1, -0.001, 0, 1 ; CPARM = 0
     GO TAFLG

To give an unrealistic example to illustrate the possibilities,
Let us flag all rows for which the component radius converted
to arc seconds is greater than or equal twice the square root
of the product of the row number minus one and the absolute
component flux:
     GETN nnn
     INEXT = 'CC'; INVERS = 1; OUTVERS = 2
     OPTYPE = '>='
     APARM = 2, 1, 3, 1, 16, 0, 1, -1, 1, 12
     BPARM = -1, 0, 0, -1;     BPARM(10) = 0.5
     CPARM = 3600, 0, 3600, 0, 1, -1, 1, 0, 2, 0
     GO TAFLG
