; CL2HF
;---------------------------------------------------------------
;! Convert CL table to HF table
;# Task VLBI Utility
;-----------------------------------------------------------------------
;;  Copyright (C) 1997-1999, 2005
;;  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
;-----------------------------------------------------------------------
;---------------------------------------------------------------
CL2HF     LLLLLLLLLLLLUUUUUUUUUUUU CCCCCCCCCCCCCCCCCCCCCCCCCCCCC
CL2HF:    Convert CL table to HF table for Calc/Solve Use
USERID                             User number.
INNAME                             Main input file (name).
INCLASS                            Main input file (class).
INSEQ             0.0    9999.0    Main input file (seq. #).
                                      0 => highest
INDISK            0.0       9.0    Disk unit #.       0 => any
INVERS                             Input CL  file version no.
IN2VERS                            CL table for phase cal.
SNVER                              SN table used
SUBARRAY                           Subarray number 0 -> 1
OUTVERS                            Output HF file version.
TIMERANG                           Time Range
BADDISK           -1.0      1000.0 Disks to avoid for scratch.
INFILE                             Schedule/time tag file name.
APARM                              General parameters:
                                   1=Time tag computation:
                                      0 => CL table time,
                                       rounded to integer sec.
                                      1 => SN table time,
                                       integer sec.
                                      2 => use input table
                                       of time tags.
                                      3 => use input Mark III
                                       schedule file.
                                      4 => use LISTR listing.
                                   2=Elev. angle cutoff.
                                       Permitted values 1.0
                                       to 10.0 degrees.
                                   3=Integration time, integer
                                     seconds. Default (0)
                                     implies 4 seconds.
                                   5=Where to get phases:
                                      =0 => from UV data
                                      >0 => from SN table
                                      (Use APARM(5)>0 always!)
DPARM                              More parameters:
                                   1 = # of channels used by
                                       FRING; usually 14 if
                                       end channels dropped;
                                       0 implies all
                                   2 = total number of channels;
                                       default (0) 16 channels;
                                       must be specified if not
                                       16 and DPARM(1) > 0.
----------------------------------------------------------------
CL2HF
Type:  Task
Use:   CL2HF translates AIPS calibration (CL) and solution (SN) tables
       to Haystack FRNGE (HF) tables.  This task is intended to
       transfer AIPS VLBI fringe fitting results to the Goddard
       CALC/SOLVE package.
Adverbs:
  USERID......The user ID of the owner of the image.  0 =>
              current user, 32000 => any user.
  INNAME......Main file name (name).       Standard defaults.
  INCLASS.....Main file name (class).      Standard defaults.
  INSEQ.......Main file name (seq. #).     0 => highest
  INDISK......Disk drive # of image.       0 => any
  INVERS......Input CL table version # containing the
              residual solutions. Residual solutions are now
              actually taken from the SN table.
  IN2VERS.....Input CL table version # to use for the phase
              cals.
  SNVER.......Input SN table version # containing the residual
              solutions from FRING/MBDLY.
  OUTVERS.....Output HF extension file version #. 0=>make new
  TIMERANG....The time range to work on.  0-> all
  BADDISK.....This array contains the numbers of disks on which
              it is desired that scratch files not be located.
              BADDISK has no effect on input and output files.
  INFILE......Name of the schedule file or time tag file to use
              for determining the observation UTC time tags.
              Only used if APARM(1) = 2, 3, or 4.
  APARM.......General control parameters:
  APARM(1)....Controls the time tag computation method
              = 0, (default), use CL table time, rounded to
                the nearest second.
              = 1, use SN table time, rounded to the nearest
                second.
              = 2, use an input table of time tags, must
                specify file name using INFILE adverb.
              = 3, use input Mark III schedule file
                and compute time tag ala Haystack
                formula, must specify file name using
                INFILE adverb.
              = 4, use start/stop times from LISTR listing,
                file name specified with INFILE.
  APARM(2)....Sets the elevation angle cutoff, in degrees.
              Source elevations less than APARM(2) will not
              be processed.   Minimum value is 1.0 degree.
  APARM(3)....Correlator integration period, in correlator
              (integer) seconds. Default (0) is 4 correlator
              seconds. Will be multiplied by .983 to get
              actual integration period. If the wrong value
              is used here, the group delay SNR's will not
              be correct.
  APARM(5)....Determines where the residual phase should be
              obtained.
              = 0, Get phases from UV data set. This no longer
                   gives correct phases.
              > 0, Get phases from the SN table. Use this
                   option always.
  DPARM.......More general control parameters:
              DPARM(1)/DPARM(2) - Parameters used to correct
              the SNR's if channels were dropped in FRING'ing.
              Enter 0, 0 if no channels were dropped. DPARM(1)
              is the number of channels used by FRING. DPARM(2)
              is the total number of channels. Use 14 16, for
              example, if the end channels were dropped.
              Defaults: DPARM(2) = 16, DPARM(1) = DPARM(2); i.e.
              no effect on SNR's.

----------------------------------------------------------------
PROGRAM:  CL2HF
DOCUMENTOR:  Ed Fomalont, D. Gordon
MAINTINER:  D. Gordon <dgg@leo.gsfc.nasa.gov>
RELATED PROGRAMS:  FRING, MBDLY, CLCAL, HF2SV

                   PURPOSE

Program CL2HF converts station-based, center-of-earth referenced
quantities (single band (narrow band) delays, group (multi-band or
wide band) delays, phase delay rates, and fringe phases) to
baseline-based, Haystack frame quantities. The primary inputs to
CL2HF are a solution SN table (from FRING/MBDLY), a solution CL
calibration table (from FRING/MBDLY/CLCAL), a phase cal CL table,
and (optionally) an Ascii file from which to determine the UTC
reference time tags of each observation. The output is an HF table.
Each baseline for a source scan produces one row in the HF table.
The HF table can then be written in files outside of AIPS
with the correct directory tree format using the task HF2SV.
These can be further processed using the GSFC/USNO Mark IV
Calc/Solve analysis package and used for geodetic and/or
astrometric studies.

See the 'HELP ASTROMET' help file for a very detailed description
of the AIPS processing of astrometric and geodetic experiments
correlated on the VLBA Correlator.

INVERS: This must be the CL table which contains the solutions
from Fring fitting.

IN2VERS: This must be the CL table which contains the apriori
phase calibration information. This information is needed in
determing some CL2HF parameters.

SNVER: The SN table which contains the fringe fit solutions and which
was used to update the CL table now in INVERS. This is the SN table
created by MBDLY. CL2HF now gets the residual delays and rates from
this table.

APARM(1)/INFILE: These two are used together to control how the
reference UTC time tags are determined for each observation.
 => 0  The time tags will be the CL table times rounded to the
       nearest second. INFILE is not used.
 => 1  The time tags will be the SN table times rounded to the
       nearest second. INFILE is not used.
 => 2  The time tags will be taken from a user supplied Ascii
       file, specified by INFILE. This file should contain the
       year, month, day, hour, minute, second, and source name
       for each scan in the experiment [ (6(I2,1X),A8) format].
       The source name is optional, if given it MUST match the
       observation (first 8 characters).
 => 3  The time tags will be computed using the Mark IV schedule file,
       which must be specified by INFILE. Do not edit the schedule
       file.  Time tags will be at the scheduled midpoint of the
       shortest duration on the particular scan.
 => 4  The time tags will be computed using the file produced with
       task 'LISTR' with OPTYPE = 'SCAN'. INFILE gives the file
       name. You MUST edit this file first and delete all lines
       that do not have a source and timerange. Do not edit the
       source/timerange lines though.

APARM(2): The elevation angle cutoff, in degrees. Lowest value
       permitted is 1.0 degrees. Default is 1.0 degrees.

APARM(3): The correlator integration period, in correlator
       (integer) seconds. The default (0) is 4 correlator
       seconds. It will be multiplied by .983 to get the actual
       integration period. If the wrong value is used here, the
       group delay SNR's will not be correct. Look in the CQ
       table if you don't know this value.

APARM(5): Determines where the residual phase will be obtained from.
       Should match the use of APARM(5) in FRING or APARM(6) in
       MBDLY, more or less (and until those defaults are changed
       if ever).
 => 0  Get phases from the UV data set. Use when FRING was run
       with APARM(5)=0, or when MBDLY run with APARM(6)=0.
 => >0 Get phases from the SN table. Use when FRING run with
       APARM(5)>1.5, or when MBDLY run with APARM(6)=1.

       USE APARM(5)=1 ALWAYS; value 0 no longer gets the correct
       answers.

DPARM(1)/DPARM(2): Parameters used to correct the SNR's if channels
        were dropped in FRING'ing. Enter 0  0 if no channels were
        dropped. DPARM(1) should be the number of channels used by
        FRING. DPARM(2) should be the total number of channels. Use
        14 16, for example, if the end channels were dropped.
        Defaults: DPARM(2) = 16, DPARM(1) = DPARM(2); i.e. no
        effect on SNR's.


VERSION HISTORY:
19980811: GSFC version merged into system version
19980814: Correctly processes 4 digit dates
19990714: DPARM added to drop pixels from SNR computation
20040228: Get phases from the SN table.
20050427: Update and correct, drop FLAGVER.
