; VLBABPSS
;---------------------------------------------------------------
;! computes spectral bandpass correction table
;# TASK CALIBRATION AP SPECTRAL
;-----------------------------------------------------------------------
;;  Copyright (C) 2015
;;  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
;-----------------------------------------------------------------------
VLBABPSS  LLLLLLLLLLLLUUUUUUUUUUUU CCCCCCCCCCCCCCCCCCCCCCCCCCCCC
VLBABPSS  Procedure to create BP table and correct auto-correlations
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 #

                                   Data Selection
CALSOUR                            Bandpass calibrator sources.
CALCODE                            Calibrator code '    '=>all
TIMERANG                           Time range to select
ANTENNAS                           Antennas to select

                                   CLEAN map (optional)
IN2NAME                            Cleaned map name (name)
IN2CLASS                           Cleaned map name (class)
IN2SEQ            0.0     9999.0   Cleaned map name (seq. #)
IN2DISK           0.0        9.0   Cleaned map disk unit #
INVERS           -1.0    46655.0   CC file version #.
NCOMP                              # comps to use for model.
                                   1 value per field
FLUX                               Lowest CC component used.
NMAPS             0.0     4096.0   No. Clean map files
CMODEL                             Model type: 'COMP','IMAG'
                                   'SUBI' (see HELP re images)
SMODEL                             Source model, 1=flux,2=x,3=y
                                   See HELP SMODEL for details.

                                   Control options
REFANT                             Reference antenna

          VLBABPSS is defined in the VLBAUTIL run file.
----------------------------------------------------------------
VLBABPSS
Type: Procedure
Use:  VLBABPSS run BPASS to VLBA data.  Then it runs ACSCL with
      all the previous calibration applied (sampler corrections,
      bandpass corrections) and produces additional corrections
      based on the autocorrelations in order to return them to
      unity.

      This is a new prodecure based on the recommendations laid out
      in VLBA Scientific Memo #37 (Craig Walker).

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.
  CALSOUR....List of sources for which bandpass response functions are
             to be determined.  All ' ' = all sources; a "-" before a
             source name means all except ANY source named. If the data
             file is a single-source file no source name need be
             specified.  If both IN2NAME and IN2CLASS are specified,
             but multiple sources are selected, BPASS will quit.
  CALCODE....Calibrators may be selected on the basis of the calibrator
             code:
                  '    ' => any calibrator code selected
                  '*   ' => any non blank code (cal. only)
                  '-CAL' => blank codes only (no calibrators)
                  anything else = calibrator code to select.
             NB: The CALCODE test is applied in addition to the other
             tests, i.e. CALSOUR and QUAL, in the selection of sources
             for which to determine solutions.
  TIMERANG...Time range of the data to be selected. In order: Start day,
             hour, min. sec, end day, hour, min. sec. Days relative to
             reference date.
  ANTENNAS...A list of the antennas for which bandpasses are to be
             determined.  If any number is negative then all antennas
             listed are NOT to be used and all others are.
The following specify a CLEAN model to be used if a single source was
specified in CALSOUR
  IN2NAME....Cleaned map name (name).      ' ' => no Clean model
             Note: a CLEAN image for only a single source may be given
             although the uv data may be in a multi-source file.
             If the source table contains a flux, then that flux will
             be used to scale the components model to obtain the
             stated total flux.  This is needed since initial Cleans
             may not obtain the full flux even though they represent
             all the essentials of the source structure.
  IN2CLASS...Cleaned map name (class).     ' ' => no Clean model
             If a Clean model is specified, then only one source may
             be selected (multi-source files) and no SMODEL may be
             specified (single-source files).
  IN2SEQ.....Cleaned map name (seq. #).    0 -> highest.
  IN2DISK....Disk drive # of cleaned map.  0 => any.
  INVERS.....CC file version #.  0=> highest numbered version
  NCOMP......Number of Clean components to use for the model, one
             value per field.  If all values are zero, then all
             components in all fields are used.  If any value is not
             zero, then abs(NCOMP(i)) (or fewer depending on FLUX and
             negativity) components are used for field i, even if
             NCOMP(i) is zero.  If any of the NCOMP is less than 0,
             then components are only used in each field i up to
             abs(NCOMP(i)), FLUX, or the first negative whichever
             comes first.  If abs(NCOMP(i)) is greater than the number
             of components in field i, the actual number is used.  For
             example
                   NCOMP = -1,0
             says to use one component from field one unless it is
             negative or < FLUX and no components from any other
             field.  This would usually not be desirable.
                   NCOMP = -1000000
             says to use all components from each field up to the
             first negative in that field.
                   NCOMP = -200 100 23 0 300 5
             says to use no more than 200 components from field 1, 100
             from field 2, 23 from field 3, 300 from field 5, 5 from
             field 6 and none from any other field.  Fewer are used if
             a negative is encountered or the components go below
             FLUX.
  FLUX.......Only components > FLUX in absolute value are used in the
             model.
  NMAPS......Number of image files to use for model.  For multi-scale
             models, set NMAPS = NFIELD * NGAUSS to include the Clean
             components of the extended resolutions.  If more than one
             file is to be used, the NAME, CLASS, DISK and SEQ of the
             subsequent image files will be the same as the first file
             except that the LAST 3 or 4 characters of the CLASS will
             be an increasing sequence above that in IN2CLASS.  Thus,
             if INCLASS='ICL005', classes 'ICL005' through 'ICLnnn'
             or 'ICnnnn', where nnn = 5 + NMAPS - 1 will be used.  Old
             names (in which the 4'th character is not a number) are
             also supported: the last two characters are '01' through
             'E7' for fields 2 through 512.  In old names, the highest
             field number allowed is 512; in new names it is 4096.
  CMETHOD....This determines the method used to compute the
             model visibility values.
             'DFT' uses the direct Fourier transform, this
             method is the most accurate.
             'GRID' does a gridded-FFT interpolation model
             computation.
             '    ' allows the program to use the fastest
             method.
             NOTE: when using a model derived from data with
             different uv sampling it is best to use 'DFT'
  CMODEL.....This indicates the type of input model; 'COMP' means that
             the input model consists of Clean components, 'IMAG'
             indicates that the input model consists of images.
             'SUBI' means that the model consists of a sub-image of
             the original IMAGR output.  If CMODEL is '   ' Clean
             components will be used if present and the image if not.
             SUBI should work for sub-images made with DO3DIM true and
             sib-images of the central facet made with DO3DIM false,
             but probably will not work well for shifted facets with
             DO3DIM false.  Use BLANK rather than SUBIM in such cases.
             CALIB will set a scaling factor to correct image units
             from JY/BEAM to JY/PIXEL for image models.  If the source
             table contains a flux, then that flux will be used to
             scale the components model to obtain the stated total
             flux.  This is needed since initial Cleans may not obtain
             the full flux even though they represent all the
             essentials of the source structure.
  SMODEL.....For single-source files only: a single component model to
             be used instead of a CLEAN components model; if SMODEL(1)
             > 0 then use of this model is requested.  Note that
             IN2NAME or IN2CLASS must be blank if SMODEL(1) > 0 and
             both must be specified if SMODEL(1) <= 0 for
             single-source files.
                SMODEL(1) = flux density (Jy)
                SMODEL(2) = X offset in sky (arcsec)
                SMODEL(3) = Y offset in sky (arcsec)
                SMODEL(4) = Model type:
                  0 => point model
                  1 => elliptical Gaussian and
                       SMODEL(5) = major axis size (arcsec)
                       SMODEL(6) = minor axis size (arcsec)
                       SMODEL(7) = P. A. of major axis (degrees)
                  2 => uniform sphere and
                       SMODEL(5) = radius (arcsec)
  REFANT.....The antenna to use as a reference in the least-squares
             solution.
----------------------------------------------------------------
VLBABPSS:  Procedure to determine antenna bandpass functions from
           calibrator data and do final scaling with the auto-
           correlations
Documentor:  Amy Mioduszewski
Related Programs: BPASS

This procedure is defined in VLBAUTIL.

VLBABPSS determines the bandpass calibration using BPASS.

VLBABPSS should be used along with VLBACCIR and VLBAAMP instead of
VLBACALA.  This redesign of the amplitude calibration path is based on
VLBA Scientific Memo #37 (Craig Walker).  The new recommended steps for
amplitude calibration are:
  1) Do preliminary calibration steps that are necessary (e.g., VLBAFIX,
      VLBAEOPS, VLBATECR...).
  2) VLBACCOR -- digital sampling corrections
  3) VLBAMPCL (or VLBAPCOR) -- remove instrumental delay
  4) VLBABPSS -- do bandpass
  5) VLBAAMP -- correct auto-correlations and a priori amplitude calibration
  6) Continue with calibration.

