; BPCOR
;---------------------------------------------------------------
;! Correct BP table.
;# Task Calibration
;-----------------------------------------------------------------------
;;  Copyright (C) 1995-1996, 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
;-----------------------------------------------------------------------
BPCOR     LLLLLLLLLLLLUUUUUUUUUUUU CCCCCCCCCCCCCCCCCCCCCCCCCCCCC
BPCOR     Task to apply various corrections to BP spectra.
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 list ' '=>all.
STOKES                             Stokes type to process
FREQID           -1.0     9999.0   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.
BPVER             1.0     9999.0   Input BP table version
                                   (will append new table)
CODETYPE                           Components to smooth 'R&I',
                                   'A&P','A','P','  ' => 'R&I'









                                   Not used for OPCODE='SPEC'
OPCODE                             Correction mode:
                                   'FUNC' => scale by function
                                   'HANN' => Hanning smooth
                                   'BOXC' => Boxcar smooth
                                   'GAUS' => Guassian smooth
                                   'SINC' => Sinc smooth
                                   'BMED' => Broadened median
                                             filter
                                   'SPEC' => spectral index
                                             correction
                                   ' ' => pass BP table
                                          obeying BPARMS
APARM                              Parameters (see HELP BPCOR).
                                   For smoothing then:
                                   APARM(1) = smoothing function
                                       diameter (channels)
                                       HANN, BOXC - full diam
                                       GAUS - FWHM
                                       SINC - first nulls
                                       BMED - median window diam
                                   APARM(2) = smoothing support
                                       func diameter in chans.
                                   For spectral index (SPEC)
                                   APARM(1) = spectral index
                                   APARM(2) = start channel
                                   APARM(3) = end channel
                                   APARM(4) = channel about
                                       which spectrum will
                                       pivot
                                   For interpolation (POLY)
                                   APARM(1) = polyn. order to
                                       fit to amplitude
                                   APARM(2) = polyn. order to
                                       fit to phase
BPARM                              Parameters (see HELP BPCOR)
                                   (1) 1=> set phase to zero
                                   (2) 0=> normalise BP ampl
CPARM                              Channels to fit
                                   (OPCODE = 'POLY' only)
                                   Pairs of starting, ending
                                   channels to use in the fit
CALIN
                                   Text file for FUNC mode
BADDISK           0.0     9999.0   Disks to aviod for scratch
----------------------------------------------------------------
BPCOR
Task:  Task to correct bandpass correction tables.
Use:   BPCOR applies various smoothing and other correction methods to
       the selected data in the input BP table.  All other data in the
       table are copied to the output table unmodified.  The output BP
       table is always version number one higher than the previous
       highest number.

       FUNCTION:
           The calibration source may not have a frequency-independent
       flux because of, for example, absorption due to hydrogen in the
       Galaxy.  The FUNC mode may be used to correct the amplitude of
       the BP for an arbitrary spectral shape.  The user provides the
       shape, listing the channels to be corrected and their correction
       factors in a text file.

       SMOOTHING:
	   The principal correction mode is smoothing: several smoothing
       methods are available including Hanning, Gaussian, Boxcar and
       Sinc smoothing.  Broadened median window filtering is also
       possible.

       SPECTRAL INDEX CORRECTION:
           The BP spectra can also be corrected for the effects of a
       spectral index across the band.

       INTERPOLATION:
           The BP spectra can also be interpolated with a polynomial
       (OPCODE = 'POLY')  NOT IMPLEMENTED!!

       The corrected complex bandpasses can be normalised before output
       and the phase response can be set to zero if desired.
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 to select:
             '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 ref.
             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.
  BPVER......The input BP table version number. NOTE: There
             is NO default value. The output BP table will
             always be version 0 (i.e. appended after the
             last existing BP table).
  CODETYPE...Which components are to be smoothed.
             'R&I'=> real and imag; 'A&P'=> ampl and phase,
             '   '=> 'R&I'
             'A  ' or 'P   ' - used for opcode 'POLY' only
             This parameter is ignored for OPCODE = 'SPEC'
  OPCODE.....Type of correction to be performed:
             'FUNC' - input gain function
             'HANN' - Hanning smoothing
             'BOXC' - Boxcar smoothing
             'GAUS' - Gaussian smoothing
             'SINC' - Sin x/x smoothing.
             'BMED' - Broadened median window filtering.
             'SPEC' - Spectral index correction.
             'POLY' - polynomial interpolation - NOT IMPLEMENTED
  APARM......Smoothing parameters:
              APARM(1) = Smoothing function diameter (chan)
                         'HANN','BOXC' - full width.
                         'GAUS' - FWHM
                         'SINC' - width between first nulls.
                         'BMED' - median window diameter.

                         'SPEC' - spectral index present in
                                  the data, defined as
                                  S = So * freq ** alpha.
                                  This spectral index will be
                                  removed from the data.

                         'POLY' - order of polynomial to fit
                                  to amplitude
              APARM(2) = Smoothing function support (chan)
                         (not required for OPCODE='BMED').

                         'SPEC' - start channel for spectral
                                  index correction.

                         'POLY' - order of polynomial to fit
                                  to phase
              APARM(3)   'SPEC' - stop channel for spectral
                                  index correction.
              APARM(4)   'SPEC' - channel about which the
                                  the spectrum will pivot.
                                  If zero will be the central
                                  channel.
  BPARM......Options after correction is completed.
             BPARM(1): 0=> phase unchanged;
                       1=> set phase to zero across the band;
             BPARM(2): 0=> normalise the bandpass amplitude;
                       1=> bandpass amplitude unchanged;
  CPARM......Channel to use in the interpolation.
                (OPCODE = 'POLY' only)
             CPARM(1): starting channel for window 1
             CPARM(2): last channel for window 1
             etc. for a total of 5 windows
  CALIN......Name for input text file used in the FUNC mode. e.g.
             CALIN='MYAREA:MYFILE.TXT'.  Each line of the file is used
             to give the correction factor (actually divisor) for one
             channel.  Thus, a weak absorption feature would be
             corrected with
                 63  0.999
                 64  0.995
                 65  0.990
                 66  0.988
                 67  0.991
                 68  0.996
             where channels 1-62 and 69-n have no correction applied.
             Blank lines or ones beggining with a $ or an * are ignored.
             Others may cause problems.
  BADDISK....A list of disks on which scratch files are not to
             be placed.  This will not affect the output file.
----------------------------------------------------------------
