; FIXAL
;---------------------------------------------------------------
;! least squares fit aliasing function and remove
;# TASK UV SPECTRAL VLA
;-----------------------------------------------------------------------
;;  Copyright (C) 2008, 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
;-----------------------------------------------------------------------
FIXAL     LLLLLLLLLLLLUUUUUUUUUUUU CCCCCCCCCCCCCCCCCCCCCCCCCCCCC
FIXAL     Least squares fit aliasing function and remove
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 #
SOURCES                            Source names for line sources
                                      NO '-' usage
CALSOUR                            Continuum source names
FLAGVER                            Flag table version
IN2NAME                            Input cal file name (name)
IN2CLASS                           Input cal file name (class)
IN2SEQ            0.0     9999.0   Input cal file name (seq #)
IN2DISK           0.0        9.0   Input cal file disk unit #
BDROP             1.0      512.0   start chan in cal for cont
EDROP             1.0      512.0   end chan in cal for cont
OUTNAME                            Output UV file name (name)
OUTCLASS                           Output UV file name (class)
OUTSEQ           -1.0     9999.0   Output UV file name (seq. #)
OUTDISK           0.0        9.0   Output UV file disk unit #.
BCHAN                              Lowest channel for cals
ECHAN                              Highest channel for cals
ICHANSEL                           Select channels to fit: NOTE
                                   this is start,end,increment
                                   and IF for each region
DPARM             -1.0       1.0   <=0 => average polarizations,
                                   IFs, times, antennas
                                   (5) > 0 keep imaginary
                                   (6) > Hanning smooth
FLUX              0.0              Flag data if residual flux in
                                   any fit channel is > FLUX
                                   0 -> 10**20
CUTOFF            0.0              Flag data if RMS of residual
                                   in fit channels > CUTOFF
                                   0 -> 10**20
BADDISK                            Disks to avoid for scratch
----------------------------------------------------------------
FIXAL
Task:          EXPERIMENTAL TASK!
       This task does a special spectral fit designed to correct for
       aliasing of the continuum into the observing band caused only
       for EVLA-EVLA baselines when observed in the VLA-EVLA
       transition with the old correlator.

       The process which one must undertake to correct data affected
       by this problem is:
       1. Flag EVLA-EVLA baselines in the FG table
       2. Run BPASS on the VLA-VLA and VLA-EVLA baselines
       3. Undo the EVLA-EVLA baseline flagging in the FG table
       4. Run SPLAT to apply the BP table
       5. Run UVAVG on one or more calibrator scans to make scan
          average data for the "cal"
       6. Run FIXAL applying the cals of step 5.  It reads in the data
          averaging each baseline.pol/IF separately.  Sums up the cal
          channels BDROP through EDROP and divides the cal by this
          complex average.  Then it fits the normalized cal to the
          channels of the input data to get the continuum flux and
          subtracts the channel-dependent part of that from the data.
       A procedure, FXALIAS, has been written to help implement this
       process.
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....Sources to be baselined using the specified ICHANSEL.
             '  '=> all except those in CALSOUR.  The '-name' usage is
             not allowed here.
  CALSOUR....Sources to be baselined using BCHAN-ECHAN rather than
             ICHANSEL.  ' ' => none.
  FLAGVER....specifies the version of the flagging table to be applied.
              0 => highest numbered table.
             <0 => no flagging to be applied.
  IN2NAME....Input cal file name (name).      Standard defaults.
  IN2CLASS...Input cal file name (class).     Standard defaults.
  IN2SEQ.....Input cal file name (seq. #).    0 => highest.
  IN2DISK....Disk drive # of input cal file.  0 => any.
  BDROP......Begin channel for cal file unaffected by aliasing
             NO DEFAULT
  EDROP......End channel for cal file unaffected by aliasing
             NO DEFAULT
  OUTNAME....Output UV file name (name).     Standard defaults.
  OUTCLASS...Output UV file name (class).    Standard defaults.
  OUTSEQ.....Output UV file name (seq. #).   0 => highest unique
  OUTDISK....Disk drive # of output UV file. 0 => highest with
             space for the file.
  BCHAN......Lowest channel number in the input file to fit CALSOUR
             sources. 0=> Nchan/8
  ECHAN......Highest channel number in the input file to fit CALSOUR
             sources.  0=> Nchan - Nchan/8
  ICHANSEL...For sources named in SOURCES, selects up to 20 groups of
             channels/IF(s) to fit as sets  of (Start,end,inc,IF),
             i.e., ICHANSEL = 6,37,1,0, 92,123,1,0 for two regions
             applying to all IFs.  The first group for which
             ICHANSEL(2,i) <= 0 ends the list. Defaults: Any IF having
             no group assigned to it, gets a group including all
             channels.  ICHANSEL(1,j) defaults to 1,
             0 < ICHANSEL(2,j) < ICHANSEL(1,j) defaults to Nchan.
             ICHANSEL(3,j) < 1 or > ICHANSEL(2,j)-ICHANSEL(1,j)+1
             defaults to 1.
             ICHANSEL(4) <= 0 => this group applies to all IFs.
  DPARM......(1) > 0 => do NOT average polarizations in fitting the
                 aliasing function
             (2) > 0 => do NOT average IFs in fitting the aliasing
                 function
             (3) > 0 => do NOT average times in fitting the aliasing
                  function
             (4) > 0 => do NOT average antennas in fitting the
                  aliasing function
             (5) > 0 => do full complex aliasing function
                 < 0 => zero the imaginary part of aliasing function
             (6) > 0 => Hanning smooth the aliasing function
  FLUX.......If the residual flux in any channel used to fit the
             baseline exceeds FLUX, then the spectrum for that time, IF,
             and polarization is fully flagged.  <= 0 => 1.0E20
  CUTOFF.....If the RMS flux in the channels used to fit the baseline
             exceeds CUTOFF, then the spectrum for that time, IF, and
             polarization is fully flagged.      <= 0 => 1.0E20
  BADDISK....The disk numbers to avoid for scratch files (sorting
             tables mostly).
----------------------------------------------------------------
