; VLOG
;---------------------------------------------------------------
;! Pre-process external VLBA calibration files
;# Task Calibration VLBI
;----------------------------------------------------------------------
;;  Copyright (C) 1997-1998, 2007-2009, 2014-2016
;;  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
;----------------------------------------------------------------------
VLOG      LLLLLLLLLLLLUUUUUUUUUUUU CCCCCCCCCCCCCCCCCCCCCCCCCCCCC
VLOG      Task to pre-process external VLBA calibration files
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 #
SUBARRAY          0.0     9999.0   Subarray (0=> 1)
CALIN                              Name of ext. cal. file
OUTFILE                            Prefix for output files
FQTOL                              Freq. tol. for IF match (kHz)
PRTLEV                             Print level (0=>none;
                                   1=> inform when gain curves
                                       passed into .TSYS file
                                   2=> echo cal. file)
----------------------------------------------------------------
VLOG
Task: !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
      ! WARNING: If you are using the *cal.vlba* file for data    !
      ! observed with the RDBE/MARK5C system (all data from the   !
      ! VLBA  Jan 31, 2014 and occasional data before this        !
      ! date), please be aware that *cal.vlba files from between  !
      ! the dates of Jan 31, 2014 and October 19, 2015 are from   !
      ! the VLBA LEGACY system. The LEGACY system signal path is  !
      ! very different from the RDBE/MARK5C system.  Do not use   !
      ! *cal.vlba* file from BETWEEN THE ABOVE DATES unless you   !
      ! understand what you are doing.                            !
      !                                                           !
      ! The pulse-cal data will be wrong and the Tsys data should !
      ! be used with caution.                                     !
      !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

       This task segments and re-formats the TSM calibration file
       produced for each VLBA experiment (eg. bk08cal.vlba) into
       separate files that can be read directly by tasks ANTAB, APCAL,
       UVFLG and PCLOD. This task is highly VLBA specific and relies
       on a known, fixed input format for the TSM calibration file.
       Nonetheless it should be useful in automating a priori
       calibration for a broad range of VLBA projects.
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.
  SUBARRAY...The subarray to calibrate. Run VLOG separately
             for each subarray in the uv-data file.
  CALIN.....TSM calibration file eg. FITS:bk08cal.vlba.
             Note: To use lower-case characters in the file
                   name, omit the closing quote.
  OUTFILE....Prefix for the output files produced by VLOG
             eg. FITS:BK08. The resulting files will be
             named BK08.TSYS, BK08.FLAG, BK08.WX, and
             BK08.PCAL. Null files, BK08.SCAN and BK08.MKIII,
             will also be produced but contain the scan
             scan summary and MKIII information, which is
             not presently used within AIPS.
  FQTOL......Frequency tolerance to use in matching IF
             frequencies (kHz). This is used in compiling
             the INDEX line in the .TSYS file from the
             BBC frequencies recorded in the TSM comment
             lines. A value of one frequency channel width
             is recommended.  Default is 1.0e-4 (or a 0.1 Hz).
  PRTLEV.....Print level. A value >2 will echo each line
             in the calibration file to the message console,
             which is useful for locating errors in the format
             of the calibration information.  A value equal to
             1 will print a message each time a gain curve is
             passed on to the TSYS file fyi.
----------------------------------------------------------------
VLOG: Task to pre-process external VLBI calibration files
Documentor: A. J. Kemball, A. Mioduszewski
Related programs: ANTAB, APCAL, UVLFG, PCLOD

  This task can be used once the VLBA uv-data have been loaded
to disk using FITLD, and takes as input the unedited TSM
calibration text file made available for each VLBA project on
the server aspen.aoc.nrao.edu. The task can also process the
standard VLBA gain curve file vlba_gains.key as retrieved
from ftp.aoc.nrao.edu (dir: pub). This file can be concatenated
with the TSM file before running VLOG or processed separately.

  If your VLBI data contains modes that are different enough that
FITLD automatically creates multiple files (e.g., different numbers
of IFs or polarizations) then the cal file also contains mixed
modes.  Although VLOG can handle this the tasks that load the text
files (notably ANTAB) will die when the mode change is encountered.
Therefor you must create separate cal files for each mode from the
original cal file and run VLOG on them separately.

  The output files produced by VLOG are as follows:

 .TSYS   - Tsys calibration data, including gain curves, suitable
           for direct use by ANTAB. An INDEX record is constructed
           for each freq. id. if possible. If no match can be
           made to the FQ data a warning message is printed and
           the INDEX keyword is omitted. Gain curve entries for
           the frequencies and time range in the uv-data are
           copied to this output file.

 .FLAG   - Flag data, suitable for direct use by UVFLG. In the
           older format "antennas=vlba_xx" the appropriate
           antenna and day numbers are inserted.

 .WX     - Weather data, as used by APCAL if performing an
           opacity solution. This file is altered to conform
           with APCAL requirements (eg. WEATHER keyword) and
           lines with bad entries (*) are commented out.

 .PCAL   - Pulse-calibration data, for input to PCLOD.
           No editing is performed.

 .SCAN   - Scan summary information. Not used by AIPS.

 .MKIII  - MKIII information. Not used by AIPS.

**Note** The files produced by VLOG should be inspected before
         further processing. VLOG may not re-format calibration
         data for non-VLBA antennas correctly.
-----------------------------------------------------------------------

