; FXALIAS
;---------------------------------------------------------------
;! least squares fit aliasing function and remove
;# PROCEDURE UV SPECTRAL VLA
;-----------------------------------------------------------------------
;;  Copyright (C) 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
;-----------------------------------------------------------------------
FXALIAS   LLLLLLLLLLLLUUUUUUUUUUUU CCCCCCCCCCCCCCCCCCCCCCCCCCCCC
FXALIAS     process data set to remove EVLA-EVLA aliasing issue
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
NCOUNT            1.0       30.0   Use 1st NCOUNT CALSOUR for BP
TIMERANG                           Time range to use
FLAGVER          -1.0              Flag table version
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
----------------------------------------------------------------
FXALIAS
Procedure:      EXPERIMENTAL PROCEDURE
       This procedure does a special spectral fit designed to correct
       for aliasing of the continuum into the observing band found
       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 writing out
          amplitude-only bandpass functions
       3. Undo the EVLA-EVLA baseline flagging in the FG table
       4. Run SPLAT to apply the BP table
       5. Run UVCOP on one or more calibrator scans to make a data set
          for the alias "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.
       This procedure has been written to help implement this
       process.  Note that it does these operations in the simplest
       way.  If you want BPASS (step 2) run in special ways, SPLAT run
       with, for example, DOBAND > 1, etc. you may have to run the
       steps yourself.  The DPARM parameter allows you to experiment
       with different aliasing functions.  By default all baselines,
       polarizations, IFs, and times are averaged together and the
       imaginary part of the aliasing function is zeroed.  You can
       remove some or all of this averaging and can select Hanning
       smoothing of the aliasing function for improved S/N.

       If you have a data set consisting of only EVLA-EVLA baselines
       from a frequency unavailable to VKA antennas, things are more
       difficult.  You will need a data set at a nearby frequency that
       includes the VLA antennas.  Run FXALIAS on this data set.  Take
       the FXALIAS.UVCOP data set and run FIXAL on the bandpass cals
       of your main data.  Specify only channels which are not
       affected too badly by the bandpass and by the alias.  Then run
       BPASS on these cals.  Apply the bandpass to the main data with
       SPLAT.  Then run FIXAL on the SPLAT output with the
       FXALIAS.UVCOP file as the second input.  NOTE, THIS IS NOT
       GUARANTEED TO WORK.
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.  CALSOUR(1) is the primary
             bandpass and aliasing calibrator.
  TIMERANG...Time range of the primary aliasing calibrator to be used.
             In order: Start day, hour, min. sec, end day, hour, min.
             sec. Days relative to ref. date.
  FLAGVER....Version of flag table to be used.
  BDROP......Begin channel for alias calibrator unaffected by aliasing
             NO DEFAULT
  EDROP......End channel for alias calibrator 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
----------------------------------------------------------------
