; TAMRG
;---------------------------------------------------------------
;! Task to merge table rows under specified conditions
;# TASK TABLE
;-----------------------------------------------------------------------
;;  Copyright (C) 1995, 2009
;;  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
;-----------------------------------------------------------------------
TAMRG     LLLLLLLLLLLLUUUUUUUUUUUU CCCCCCCCCCCCCCCCCCCCCCCCCCCCC
TAMRG:  Task to merge table rows under specified conditions
INNAME                             Main input file (name).
INCLASS                            Main input file (class).
INSEQ             0.0    9999.0    Main input file (seq. #).
                                      0 => high
INDISK                             Disk unit #.       0 => any
INEXT                              Input table extension type
INVERS                             Input table file version no.
OUTVERS                            Output table file version.
APARM                              Initial sort: Keys & weights
                                   1,2=> col. & wt pri. key 1.
                                   3,4=> col. & wt sec. key 1.
                                   5,6=> col. & wt pri. key 2.
                                   7,8=> col. & wt sec. key 2.
                                   APARM(1) = 0 => no sort.
BPARM                              Columns which must be equal
                                   to merge two rows.
CPARM             0.0              Allowed error in the equality
                                   test by column.
DPARM                              Columns to sum. 0 => none.
BADDISK                            Disks to avoid for scratch
----------------------------------------------------------------
TAMRG
Type:  Task
Use:   TAMRG sorts the contents of a given AIPS table extension
       file to bring all rows with the "same" control values
       together.  It then sums some of the columns and resorts
       the file into the original sort order.  The user
       specifies all of these operations via the adverbs.  He
       should use PRTAB first to make sure he knows the column
       numbers associated with each of the parameters.
Adverbs:
  INNAME......Main file name (name).       Standard defaults.
  INCLASS.....Main file name (class).      Standard defaults.
  INSEQ.......Main file name (seq. #)      0 => highest.
  INDISK......Disk drive # of image.       0 => any.
  INEXT.......Input extension file type    ' ' => 'TA'
  INVERS......Input extension file version #     0 => highest.
  OUTVERS.....Output extension file version #    0 => highest+1.
  APARM.......Table columns and factors for the initial sort:
              APARM(1) = 0 means no initial sort.  The numerical
              values on which the sort is performed, the "keys",
              are computed using APARM to specify which column
              values are used and how these values are scaled.
              The first (more slowly varying) key is:
                 KEY_VALUE1 = COL_VALUE(APARM(1)) * APARM(2) +
                              COL_VALUE(APARM(3)) * APARM(4)
              The faster changing key value is:
                 KEY_VALUE2 = COL_VALUE(APARM(5)) * APARM(6) +
                              COL_VALUE(APARM(7)) * APARM(8)
              In the case of bit or character strings, only one
              column is used to  generate the key values.  In
              this case, APARM(2) is the first character and
              APARM(4) is the number of characters to use for
              the first key; APARM(6) is the first character
              and APARM(8) is the number of characters to use
              for the second key.
                 Sorting is normally in ascending order of the
              keys, for decending order use a negative factor
              for the relevant key.  Factors of 0 => 1.0.  To
              sort using the ABSOLUTE value of the column, set
              the column number to negative.
                 For a single key sort use APARM(5)=0.  To use
              a single column as the sort key set APARM(3)=0
              and/or APARM(7)=0 as appropriate.
                 Example: sort by col. 1 (slowest varying) and
              col. 6 (fastest) in decending order:
                      APARM = 1,1,0,0, 6,-1,0,0
              To sort by ascending absolute value col. 2 and,
              secondarily, by descending value of col. 1:
                      APARM = -2, 1.0, 0, 0, 1, -1., 0, 0
  BPARM.......List of columns for which the values in two rows
              must be "equal" in order for the two rows to be
              merged.  A value of 0.0 terminates the list and
              there must be at least 1 column in the list.
  CPARM.......For numeric columns, the tolerance allowed to
              regard the column values as equal.  CPARM(j)
              applies to column BPARM(j).  Character- and bit-
              string columns and logical columns are required to
              be exactly equal if they appear in the BPARM list.
  DPARM.......Columns to be summed when two rows are merged.  A
              value of 0.0 terminates the list and the list may
              be empty.  When two rows are merged, the values
              in the first row are taken except for the columns
              listed in DPARM, which are summed.
              CC file example: column 1 is flux, column 2 is
              DeltaX, and column 3 is DeltaY.  Columns 4-7
              apply to extended source models.  CCMRG then is
              equivalent to TAMRG with values:
                 APARM = 2,-1, 0,0,  3,1, 0,0
                 BPARM = 2,   3,  4,  5,  6,  7, 0
                 CPARM = d1, d2, d0, d0,  1., 0.
                 DPARM = 1, 0
              where dn = abs(axis incr) / 20.
  BADDISK.....Disk drive numbers to avoid for scratch files.
----------------------------------------------------------------
