; VLACALIB
;---------------------------------------------------------------
;! Runs CALIB and LISTR for VLA observation
;# PROCEDURE CALIBRATION
;-----------------------------------------------------------------------
;;  Copyright (C) 1995-1997; 2001
;;  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
;-----------------------------------------------------------------------
;---------------------------------------------------------------
VLACALIB  LLLLLLLLLLLLUUUUUUUUUUUU CCCCCCCCCCCCCCCCCCCCCCCCCCCCC
VLACALIB:  Procedure to run CALIB and LISTR for VLA calibration.
                                   Use RUN VLAPROCS first!!!
INNAME                                UV file name (name)
INCLASS                               UV file name (class)
INSEQ              0.0      9999.0    UV file name (seq. #)
INDISK             0.0         9.0    UV file disk drive #
                                   Data selection (multisource):
CALSOUR                            Calibrator sources
CALCODE                            Calibrator code '*'=>all cal.
QUAL            -10.0              Calibrator qualifier -1=>all
TIMERANG                           Time range to use.
ANTENNAS                           Antennas to solve for. 0=all
UVRANGE                            Range of uv distance for full
                                   weight, 0 outside.
REFANT                             Reference antenna
DOCALIB          -1.0        2.0   If >0 calibrate data
                                   = 2 calibrate weights
GAINUSE                            CL table to apply, 0=> latest
FLAGVER                            Flag table version 0=> 1
DOBAND           -1.0       10.0   If >0 apply bandpass cal.
                                   Method used depends on value
                                   of DOBAND (see HELP file).
BPVER                              Bandpass table version
SNVER                              SN table to write, 0=> create
                                    new table
MINAMPER                           Min. amplitude closure error
MINPHSER                           Min. phase closure error
FREQID                             Unique frequency code
DOPRINT                            >0 Print messages to a file
                                   or to the printer.
OUTPRINT                           Printer disk file to save
----------------------------------------------------------------
VLACALIB
Procedure:  This procedure is designed to simplify determining
       antenna based calibration for calibrating VLA data from
       external calibrator sources. It accepts a subset of the
       input adverbs for CALIB and uses the default values for
       the rest.  After running CALIB the solution table (SN)
       produced is printed by LISTR, if DOPRINT>=0.  Note that
       if DOPRINT>=0 then depending on your window size you may
       have to press return a second time for the procedure to
       continue.
          Before attempting to use VLACALIB the RUN file
       VLAPROCS must be run to define the adverbs used and to
       read in the procedure.  This is done by:
       >RUN VLAPROCS
       and only needs be done once.
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 calibration constants
             are to be determined, i.e. the calibrator sources
             All ' ' = all sources; a "-" before a source name.
             means all except ANY source named.
             Note: solutions for multiple sources can only be
             made if the sources are point sources at their
             assumed phase center and with the flux densities
             given in the source (SU) table.
  CALCODE....Calibrators may be selected on the basis of the
             calibrator code:
                  '    ' => any calibrator code selected
                            including non-calibrators.
                  '*   ' => 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.
  QUAL.......Only sources with a source qualifier number in the
             SU table matching QUAL will be used if QUAL is not
             -1.
  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  have solutions
             determined. If any number is negative then all
             antennas listed  are NOT to be used to determine
             solutions and all others are. All 0 => use all.
  UVRANGE....The range of uv distance from the origin in
             kilowavelengths over  which the data will have
             full weight; outside of this annulus in the uv
             plane the data will be given a weight of 0.
  REFANT.....The desired reference antenna for phases.
  DOCALIB....If true (>0), calibrate the data using information in the
             specified Cal (CL) table for multi-source or SN table for
             single-source data.  If > 1.5, also calibrate the weights
             (new for VLA, normal for VLBI).  Applied before
             determining new solutions.  The calibration data in
             the CL table version specified by GAINUSE will be used.
  GAINUSE....version number of the CL table to apply to the data.
             0 => highest.
  FLAGVER....specifies the version of the flagging table to be applied.
             0 => 1; <0 => no flagging to be applied.
  SNVER......The version of the SN table to write the solutions
             to.  If =0, a new SN table is generated.  Prior
             to 15OCT95, SNVER was fixed =1 so that solutions
             were always written to SN #1.  If 0 is selected and
             VLACALIB is run multiple times, be careful to
             remove those SN tables which contain unacceptable
             solutions before applying calibration (vis CLCAL..)
  MINAMPER...If > 0 then the values of any amplitude closure errors
             whose abs. percentage value exceeds MINAMPER will be
             printed.  Any whose average over all baselines exceeds
             MINAMPER/10 will be printed (1 per cal time).
  MINPHSER...If >0 then the values of any phase closure errors whose
             value exceeds MINPHSER degrees will be printed.  Any whose
             average over all baselines exceeds MINPHSER/10 will be
             printed (1 per cal time).
  FREQID.....Frequency selection. Defaults to 1.  This is what
             is required in most continuum cases.
  DOPRINT....If > 0 print inputs to VLACALIB and performs a LISTR (see
             EXPLAIN VLACALIB) to either the printer or to a
             file specified in OUTPRINT.  Note that if this value is
             positive you may have to hit return for the procedure
             to continue running after it does the INPUTS command.
  OUTPRINT...Disk file name in which to save output.  ' ' => print
             to printer - When OUTPRINT is not blank, outputs are
             printed to a file.  Multiple uses of the same
             are concatenated.
----------------------------------------------------------------
VLACALIB:           Procedure to run CALIB with fewer inputs and
                    possibly print the results with PRTMSG and LISTR.
Documenter:         Amy Mioduszewski
Related Programs:   CALIB, LISTR, PRTMSG

STEPS in VLACALIB:

Note that if DOPRINT<=0 then only step 2 is performed.

1.  If DOPRINT>0 then
       a. clear AIPS messages using CLRMSG
       b. put inputs of VLACALIB into AIPS messages
          (using INPUT VLACALIB)
       c. clear CALIB messages using CLRMSG

2.  RUN CALIB, with VLACALIB inputs and:
      APARM 4, 0, 0, 0, 0, 2;
      SOLMODE 'A&P';
      CPARM 0, 0, MINAMPER/10, MINPHSER/10, 1, 0

3.  If DOPRINT>0 then print AIPS and CALIB messages
    using PRTMSG to the selected printer or to the file
    stated in OUTPRINT.

4.  If DOPRINT>0 then run LISTR with VLACALIB inputs and:
       OPTYPE 'gain'
       INEXT 'SN'
       BIF 1; EIF 2
       STOKES 'HALF'
       DPARM 5, 1, 0

If you would like to run with DOPRINT=1 but would still like to
keep your AIPS and CALIB messages.  Start AIPS in another window
to create another POPS number (when you run AIPS and see an
"AIPS 2" or "IMAGR2"; 2 is the POPS number) and run VLACALIB in
that window.  Only the messages from that POPS number will be
deleted.
