; SNCOR
;---------------------------------------------------------------
;! applies user-selected corrections to the calibration SN table
;# Task Calibration
;-----------------------------------------------------------------------
;;  Copyright (C) 1995-1996, 1999
;;  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
;-----------------------------------------------------------------------
;---------------------------------------------------------------
SNCOR     LLLLLLLLLLLLUUUUUUUUUUUU CCCCCCCCCCCCCCCCCCCCCCCCCCCCC
SNCOR     Task which applies various corrections to SN tables.
INNAME                             Input UV file name (name)
INCLASS                            Input UV file name (class)
INSEQ             0.0     9999.0   Input UV file name (seq. #)
INDISK                             Input UV file disk unit #
SOURCES                            Source list ' '=>all.
STOKES                             Stokes type to process
SELBAND                            Bandwidth to select (kHz)
SELFREQ                            Frequency to select (MHz)
FREQID                             Freq. ID to select, 0=>all
BIF               0.0      100.0   Lowest IF number 0=>all
EIF               0.0      100.0   Highest IF number 0=>all
TIMERANG                           Time range to use.
ANTENNAS                           Antennas to correct.
SUBARRAY          0.0     9999.0   Subarray; 0 => 1.
SNVER             1.0     9999.0   SN table version to update
OPCODE                             Operation code.See HELP
SNCORPRM                           Parameters (see HELP SNCOR).
PHASPRM                            Parameters for OPCODE=XFER
BADDISK           0.0     9999.0   Disks to aviod for scratch
----------------------------------------------------------------
SNCOR
Task:  This task makes a number of corrections to a SN table.
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.
  SOURCES....list of sources to process.
             '*' = all; a "-" before a source name
             means all except ANY source named.
  STOKES.....The desired Stokes type of the output data:
             'R ', 'L ', 'RL', '  '=> 'RL'.
  FREQID.....Frequency identifier to select (you may determine
             which is applicable from the OPTYPE='SCAN' listing
             produced by LISTR).
  BIF........First IF to process. 0=>all.
  EIF........Highest IF to process. 0=>all higher than BIF
  TIMERANG...Time range of the data to be used. In order:
             Start day, hour, min. sec, end day, hour, min. sec.
             Days relative to reference date.
  ANTENNAS...A list of the antennas to be modified.  If any
             number is negative then all antennas listed  are
             NOT to be modified.  All 0 => use all.
  SUBARRAY...The subarray to modify. Do only one at a time.
  SNVER......The SN table version number which is to be updated.
             NOTE: There is NO default value.
  OPCODE.....Operation code (see also EXPLAIN SNCOR):
             'AVRT' => average selected fringe rates in a
                       record.
             'CLPA' => Flag amplitudes outside of the range
                       SNCORPRM(1) (min) to SNCORPRM(2) (max).
             'CLPP' => Flag phases outside of the range
                       SNCORPRM(1) (min) to SNCORPRM(2) (max).
             'CLPD' => Flag delays outside of the range (nsec)
                       SNCORPRM(1) (min) to SNCORPRM(2) (max).
             'CLPR' => Flag rates outside of the range (mHz)
                       SNCORPRM(1) (min) to SNCORPRM(2) (max).
             'CLPW' => Flag amplitudes, phases, rates and delays
                       where the weight is outside the range
                       SNCORPRM(1) (min) to SNCORPRM(2) (max).
             'XFER' => Transfers phases between frequencies with
                       scaling to compensate for ionospheric delays.
                       Also allows instrumental phase offsets
                       and new antenna amplitudes to be introduced.
                       (See SNCORPRM, PHASPRM below)
             'ZPHS' => Zero phases of selected solutions
             'ZRAT' => Zero residual fringe-rates of selected
                       solutions.
             'ZDEL' => Zero residual delays of selected
                       solutions.
             'MULA' => Multiply gain amplitudes by SNCORPRM(1)
             'REFP' => Reference phases to IF SNCORPRM(1)
             'CPRT' => Copy the residual fringe rate from IF
                       denoted by SNCORPRM(1) to all specified
                       IFs.
             'CPSN' => Copy the whole solution from the IF
                       denoted by SNCORPRM(1) to all specified
                       IFs.
             'PCOP' => Copy the whole solution from one
                       polarization to the other (under
                       control of SNCORPRM(1))
             'PNEG' => Flip the sign of the gain phase for
                       all selected solutions.
             'NORM' => Normalize amplitudes to 1
  SNCORPRM...Parameters: see above and below.
  PHASPRM....More parameters: see above and below
  BADDISK....A list of disks on which scratch files are not to
             be placed.  This will not affect the output file.
----------------------------------------------------------------
SNCOR:  Task to apply corrections to an SN table in a variety of
        ways.
Documentor: W. D. Cotton, W. C. Erickson (for "XFER")
Related Programs: LISTR, SPLIT, TACOP, TABED

This task will compute various corrections and apply them
directly to a solution (SN) table.  The operation to be done
is determined by OPCODE.  Details and/or additional information
for the various models is given below.

OPCODE='AVRT'
     This option will cause all selected residual fringe rates
to be averaged.

OPCODE='CLPA'
    This option flags any gain entries with an amplitude outside
of the range given by SNCORPRM(1) (min) to SNCORPRM(2) (max).

OPCODE='CLPP'
    This option flags any gain entries with a phase outside
of the range given by SNCORPRM(1) (min) to SNCORPRM(2) (max).

OPCODE='CLPW'
    This option flags any gain entries whose weight lies outside
the range SNCORPRM(1) (min) to SNCORPRM(2) (max).

OPCODE='XFER'
    This option transfers phases between frequencies and also sets
antenna amplitudes.
Antenna amplitudes: SNCORPRM(30):
    If left blank, the antenna amplitude gains will be unchanged.
    To manually set the antenna amplitude gains, enter
    the desired amplitudes strictly in order 1 to 28 into
    SNCORPRM(1) to SNCORPRM(28) and set SNCORPRM(30) to -1.
    To set all antenna amplitude gains to 1.0 set SNCORPRM(30)
    to +1.
Phase transfer parameters: PHASPRM(30)
    PHASPRM(1) - PHASPRM(28) are the instrumental phase offsets
    at the two frequencies for Antennas 1 to 28 (in radians).
    [They must be strictly in order 1 to 28.]
    PHASPRM(29) = The higher frequency in MHz.
    PHASPRM(30) = The lower frequency in MHz.

OPCODE='CLPD'
    This option flags any  entries with a delay whose value in
nanoseconds is outside of the range given by SNCORPRM(1) (min) to
SNCORPRM(2) (max).

OPCODE='CLPR'
    This option flags any  entries with a fringe rate whose
value in milliHz is outside of the range given by SNCORPRM(1)
(min) to SNCORPRM(2) (max).  The given fringe rate in mHz is at
the reference frequency.

OPCODE='ZPHS'
    This option causes the phases of selected gaines to be set
to zero.  This is useful for the calibration of amplitudes only.

OPCODE='ZRAT'
    This option will cause the residual fringe-rates of the
selected solutions to be set to zero.

OPCODE='ZDEL'
    This option will cause the residual delays of the
selected solutions to be set to zero.

OPCODE='MULA'
    This option will cause the amplitudes of the selected
complex gains to be multiplied by SNCORPRM(1).

OPCODE='REFP'
    This option will reference all the phases to the IF
specified by SNCORPRM(1).  If the phase for this IF is flagged
all phases will be flagged. Default = IF 1.

OPCODE='CPRT'
    This option will copy the residual fringe-rate from the IF
denoted by SNCORPRM(1) to all specified IFs.  Obviously If the
rate for the reference IF is flagged all IFS will be flagged.
Default = IF 1.

OPCODE='CPSN'
    This option will copy the whole solution from the IF
denoted by SNCORPRM(1) to all specified IFs.  Obviously If the
solution for the reference IF is flagged all IFS will be flagged.
Default = IF 1.

OPCODE='PCOP'
    This option will copy the whole solution from one
polarization to the other, for all specified IF's. The copy
direction is specified by SNCORPRM(1):
    SNCORPRM(1) = 1   => Copy polzn. 1 (R) to 2 (L)
                = 2   => Copy polzn. 2 (L) to 1 (R)
No action is taken if there is only one polarization in the
SN table.

OPCODE='PNEG'
    This option will flip the sign of the gain phase for
all selected SN solutions.

OPCODE='NORM'
    This option normalizes amplitudes to 1.





