%-----------------------------------------------------------------------
%;  Copyright (C) 1995-1998
%;  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
%-----------------------------------------------------------------------
\input COOK82.MAC
\input psfig
\def\doFIG{T}
\def\titlea{15-Oct-1998 (revised 20-August-1998)}
\def\chapt{9}

% rework all indexing references!!!
% what about gain curves that do/do not include OPACITY!!!
% give additional resources for finding cal files for VLA, VSOP, and EVN!!!
% improve discussions of SNSMO, SHOUV, and GPHAS!!!
% improve explanations in polarization section!!!
% add plots to polarization sections!!!
% discuss merits of averaging RR and LL for determining solutions !!!
% reference a paper that uses a polarization calibrator !!!
% show inputs for CROSSPOL in 9.4.8.7.1 !!!
% add phase referencing to recipe structure !!!

\tsect{9.  REDUCING VLBI DATA IN \AIPS\ }

% other VLBI resources
This chapter describes the reduction of \Indx{VLBI} data in \AIPS\ .
A Step-by-step recipe is presented.  We also include some background
information concerning the structure of VLBI data sets, the data
reduction philosophy and a description of some of the effects for
which corrections must be determined and applied.  It is important to
understand these aspects if you wish to reduce your data reliably.
For more background information on VLBI data reduction consult {\it
VLBI and the VLBA}, Astronomical Society of the Pacific (ASP)
Conference Series No. 82, 1995.

% other AIPS resources
Programs of particular interest for VLBI may be found in Chapter 13 or
displayed from inside \AIPS\ by typing {\us ABOUT\qs VLBI\CR} or {\us
APROPOS\qs VLBI \hbox{\CR}}.  Remember, the best and most complete
information available on all \AIPS\ verbs and tasks may be found in
their {\tt EXPLAIN} files.  A {\tt 15APR97} or later version of \AIPS\
is required to support full Space VLBI data reduction.

% content note
Most types of VLBI data, once read into \AIPS, appear very similar in
structure as far as the user is concerned.  We shall concentrate on
describing the reduction path for \Indx{VLBA} correlator data, but
most operations also apply to MkIII and MkII data.  Where appropriate,
we shall draw the reader's attention to any differences.  In
particular, \Sec 9.2.2 deals with reading data from a MkIII correlator
into \AIPS\ and the steps necessary to prepare such data for
calibration.  In the near future, the procedures for processing
phase-referencing experiments will be incorporated into this chapter.

% reading in external files
Some of the VLBI-related tasks require the ability to read files
resident outside \AIPS\ .  To communicate to \AIPS\ the directory in
which these files exist it is necessary to define a logical pointer or
environment variable.  Please refer to \Sec 3.10 to see how this is
done.

While the majority of VLBI observations to date have been continuum
observations, more sophisticated data reduction techniques are
increasingly common.  Continuum VLBI observers sometimes also apply
spectral-line VLBI techniques to improve the dynamic range of their
data sets.  For these reasons, this chapter is now organised to make
the discussion of data reduction techniques more uniform.  The
overview in this section of the steps involved for several type of
VLBI data reduction is meant to guide the user through the rest of the
chapter.  Please read the overview carefully before proceeding.

The expected size of the output \uv\ data file can be an important
consideration in VLBI data reduction. The \indx{disk space} required
by \AIPS\ for a compressed dataset is given by the relation:
$${\rm Disk\ Space} = 4\ {\rm x}\ 10^{-6}\ N_{Stokes}\ N_{chan}\
N_{IF}\ {{N_{ant}\over2}(N_{ant}+1)}\ {{T_{expt}}\over{\triangle
T}}\ {\rm MBytes}$$
where $T_{expt}$ is the total observing time, $\triangle T$ the
correlator integration time, $N_{Stokes}$ the number of polarization
correlation pairs $(RR,LL,RL,LR)$, $N_{chan}$ the number of spectral
channels per IF, $N_{IF}$ the number of IF's, and $N_{ant}$ the number
of antennas in the network.  SVLBI data set sizes may be much larger
and can be computed using the formula given in \Sec 9.2.1.2.  In
uncompressed format the same data set will require three times the
disk space.  Be forewarned that some tasks [including {\tt FRING}]
attempt to create uncompressed scratch files which may not fit into
the available disk space.  The amount of available free disk space can
be determined using the {\tt AIPS} commands \hbox{{\tt FREE}}.  The
blocks referred to in the {\tt FREE} output are equal to 1024 bytes.

Note that certain operating systems are still subject to a
\indx{2-Gigabyte limit} for any individual file, as a result of their
32-bit file systems. Larger \AIPS\ files should be possible under
systems that support 64-bit file systems. This is presently supported
on DEC Alpha workstations and on SGI systems running XFS, amongst
others, and will be supported under Solaris (revision 2.6) in the near
future. The size of the output file can be reduced by IF selection or
limited concatenation in {\tt FITLD} or by time- or spectral-averaging
later using {\tt UVAVG} or \hbox{{\tt AVSPC}}.

Regardless of how the data are loaded onto disk, they must be written
to tape in uncompressed form and so it is possible to create \AIPS\
datasets on disk that are too large to fit onto a single output tape.
Be forewarned that there is not yet any mechanism for storing a single
dataset across multiple tapes.

One large point of divergence in the reduction of continuum
\indx{polarization} \Indx{VLBI} data is the question of whether or not
to determine separate LL and RR phase solutions.  The
polarization-specific portions of the recipe given below are based
upon the premise that L and R phase solutions should always be
determined separately on the grounds that it is safer and should work
with data from a wide variety of antennas.  If the L-R phase offsets
for antennas in your data set are small and constant in time, you may
consider modifying the recipe in \Sec 9.1 by determining averaged
LL,RR phase solutions everywhere except in step 7.

\subsect{9.1 VLBI data reduction recipe}

\enumerate{1}{{\bf LOAD THE DATA}
For data from the \Indx{VLBA} correlator, run {\tt \tndx{FITLD}} (\Sec
9.2.1.1); if needed, follow up with {\tt MSORT}, {\tt USUBA}, {\tt
INDXR}, and {\tt VBGLU} (\Secs 9.2.1.3-6).  For data from a MkIII
correlator, run {\tt MK3TX}, {\tt \tndx{MK3IN}}, {\tt MSORT}, {\tt
DBCON}, {\tt UVAVG}, {\tt TAMRG}, {\tt SBCOR}, and {\tt INDXR} as
needed (\Secs 9.2.2.1-6).  Data from the Penticton correlator should
be loaded using {\tt FITLD} (\Sec 9.2.3), sorted (\Sec 9.2.1.3), and
indexed (\Sec 9.2.1.5).  The loading of data from the Mitaka
correlator will be described in the \Cookbook\ at a later date.}

\hangnxtpar{POLARIZATION:
The VLBA correlator incorrectly labels polarizations for
single-polarization LL correlation and for dual parallel-hand
correlation (RR and LL only).  For these types of data, you must
additionally run {\tt FXPOL} (\Sec 9.2.1.7).}

\hangnxtpar{SVLBI:
See SVLBI-specific discussion of {\tt FITLD} in \Sec 9.2.1.2.  Also,
the {\tt OB} table and the time-corrections file should be prepared
for data from the VLBA correlator (\Secs 9.2.1.8-9).}

\enumrnext{{\bf EXAMINE THE DATA}
It is important to familiarize yourself with the data set before
proceeding further, especially if you have little experience with VLBI
data. There are many \AIPS\ tasks for the examination of your data
(see \Sec 9.3 for a fuller discussion).  Minimally, you should at
first run {\tt LISTR}, {\tt IMHEAD}, {\tt DTSUM}, {\tt POSSM}, {\tt
VPLOT}, and \hbox{{\tt PRTAN}}.  At later stages you will probably
find {\tt SNPLT}, {\tt PRTAB}, {\tt OBPLT}, and {\tt SHOUV} useful for
examining data and calibration tables.}

\hangnxtpar{SVLBI:
Task {\tt OBPLT} allows you to examine different aspects of the
spacecraft orbit.}

\enumrnext{{\bf PROCESS THE CALIBRATION FILES}
You will have either received calibration files, or instructions on
where to obtain them.  Some calibration files can be automatically
processed into a form suitable for use within \AIPS\ using {\tt VLOG}
(\Sec 9.4.2).}

\hangnxtpar{POLARIZATION:
Be careful to make sure that the polarization labeling of the
IFs in the calibration text files is the same as the labeling in the
data.}

\enumrnext{{\bf EDIT THE DATA}
Identifying and \indx{editing} bad data now can save you time later.
Data should first be editted using {\tt UVFLG} to apply editting
information supplied with your calibration files (\Sec 9.4.3).  Some
useful tasks for examining and editing data are {\tt IBLED}, {\tt
UVFLG}, {\tt TVFLG}, {\tt SPFLG}, {\tt EDITR}, {\tt EDITA}, {\tt
VPLOT}, and \hbox{{\tt QUACK}}.}


\hangnxtpar{POLARIZATION:
You may want to edit the data consistenly in all polarizations (select
{\tt STOKES='IQUV'} within {\tt TVFLG} or {\tt SPFLG}) --- this can
greatly simplify the imaging stage (see step 15).}

\enumrnext{{\bf APPLY {\it A PRIORI\/} CALIBRATION}
Use {\tt \tndx{ANTAB}} to load the measured system temperature
($T_{\rm sys}$) and gain curve information for each antenna and {\tt
APCAL} to complete the {\it a priori\/} amplitude \indx{calibration}
(\Sec 9.4.4.3) --- this is called the $T_{\rm sys}$ method of
amplitude calibration.  {\tt APCAL} can also be used to perform
opacity corrections.}
\eject

\hangnxtpar{POLARIZATION:
For alt-az mounted antennas, a parallactic angle correction for the
rotating orientation of the antenna feeds with respect to the observed
source must be performed as the first step in the phase
\indx{calibration} using {\tt CLCOR} (\Sec 9.4.4.4).  This step should
be performed no later than immediately after the $T_{\rm sys}$
calibration.}

\hangnxtpar{VLBA CORRELATOR DATA ONLY:
Corrections for sampler biases should be applied using {\tt ACCOR}
(\Sec 9.4.4.1) BEFORE the $T_{\rm sys}$ calibration. It is recommended
that this step be taken for both 1-bit and 2-bit data.}

\hangnxtpar{SPECTRAL-LINE:
Unless the line emission is very weak, you may wish to defer amplitude
calibration of your {\it line sources only} until step 12 below.  The
template method described there is much more accurate than the
$T_{\rm sys}$ method.}

\enumrnext{{\bf CALIBRATE THE SCALAR BANDPASS RESPONSE FUNCTION}
Run {\tt BPASS} or {\tt CPASS} to determine the \indx{bandpass}
response function using the total-power spectra (\Sec 9.4.5).  This
step is not necessary for most continuum observations unless very high
dynamic range is sought and even then may not significantly improve
the calibration.  You should probably skip this step initially and
return to it later if you suspect that your images are limited by
these effects.}

\hangnxtpar{SPECTRAL-LINE: The bandpass response function should be
determined using only the continuum calibrator sources.  This step
SHOULD NOT BE SKIPPED unless the continuum calibrator source is
sufficiently weak that a good bandpass response function cannot be
estimated.\indx{spectral-line}}

\enumrnext{{\bf CALIBRATE THE INSTRUMENTAL DELAYS}
`Phase-cals', or measured single band and multi-band instrumental
phase errors, should be applied using {\tt PCCOR} (\Sec 9.4.8.2).  You
can perform a `manual phase-cal' by running {\tt FRING} on a limited
subset of your data to account for missing phase-cal information or to
refine the reported phase-cal measurements (\Sec 9.4.8.2b).}

\hangnxtpar{\Indx{VLBA} CORRELATOR:
Phase-cal information must currently be loaded into a {\tt PC} table
using {\tt PCLOD} (\Sec 9.4.8.2); some time `real soon now', the {\tt
PC} table will be provided directly by the correlator.\Iodx{VLBI}}

\hangnxtpar{SPECTRAL-LINE:
Delay calibration should be carried out only on the continuum sources
at this stage.}

\hangnxtpar{POLARIZATION:
When running {\tt FRING}, be certain to solve for independent left-
and right-polarization delay solutions {\tt APARM(3) = 0}.  Run {\tt
CROSSPOL} after calibrating the instrumental delays, to determine a
single delay offset between left and right \indx{polarization} (\Sec
9.4.8.7).}

\enumrnext{{\bf FRINGE FIT THE DATA}
Estimate and remove residual delays, rates and phases using {\tt
\tndx{FRING}} or {\tt BLING} (\Sec 9.4.8.3-4).}

\hangnxtpar{SPECTRAL-LINE:
Only fringe-fit the calibrator source at this stage.  Check the
coherence of the target source using the resulting solutions to decide
whether or not to zero the rate solutions using the {\tt 'ZRAT'}
option in {\tt SNCOR} (\Sec 9.4.8.6).}

\hangnxtpar{SVLBI:
Under some circumstances, the `ground-phasing' task {\tt GPHAS} may
prove useful if {\tt FRING} or {\tt BLING} cannot successfully find
fringes to the space satellite (\Sec 9.4.8.5).}

\enumrnext{{\bf ESTIMATE THE INSTRUMENTAL POLARIZATION} (polarization
data only).
Correct for the instrumental polarization terms, commonly known as
`D-terms' using {\tt PCAL}, {\tt LPCAL}, or {\tt SPCAL} on the
polarization calibrator (\Sec 9.4.8.7.2).  This polarization
calibrator should first be fully calibrated and imaged before this
step can be performed.}

\enumrnext{{\bf CALIBRATE THE POLARIZATION POSITION ANGLE}
(polarization data only).
If a calibration source with known polarization orientation is
available, use {\tt CLCOR} to make a final correction to adjust the
polarization angles of the target source data (\Sec 9.4.8.7.3).}

\enumrnext{{\bf CALIBRATE THE COMPLEX BANDPASS RESPONSE FUNCTION}
Run {\tt BPASS} or {\tt CPASS} to determine a complex-valued
\indx{bandpass} response function.  As before, this step is usually
not necessary and should be skipped unless your final images are
thought to be limited by these effects (\Sec 9.4.5).}

\hangnxtpar{SPECTRAL-LINE or POLARIZATION:
The bandpass response function should be determined using only the
calibrator source.  Unlike step 6, this step CAN be skipped.}

\enumrnext{{\bf APPLY THE DOPPLER CORRECTION} (\indx{spectral-line}
data only).
Run {\tt CVEL} to compensate for the changing Doppler shifts of the
antennas with respect to the source during the observation (\Sec
9.4.6).}

\enumrnext{{\bf REFINE THE AMPLITUDE CALIBRATION} (spectral-line data
only).
Run {\tt ACFIT} to amplitude calibrate the program source using the
template spectra method (\Sec 9.4.7).  Note that the traditional
$T_{\rm sys}$ method (\Sec 9.4.4.3) can also be used if the line
emission is too weak for the template method to work successfully.}

\enumrnext{{\bf DETERMINE RESIDUAL RATES} (spectral-line data only).
Now estimate the residual rates ONLY by running {\tt FRING} or {\tt
BLING} on one or a few spectral points on the target source (\Sec
9.4.8.6).}

\enumrnext {{\bf APPLY CALIBRATION, AVERAGE, AND INSPECT THE FINAL
DATA}
Run {\tt SPLIT} to apply the calibration solutions (\Sec 9.5.1), {\tt
AVSPC} to frequency-average the data (\Sec 9.5.1), and {\tt UVAVG} to
frequency average the data (\Sec 9.5.2).  It is recommended that you
take the time to inspect the calibrated data to see if more editing is
needed, and to check that no gross calibration errors remain in the
data (\Sec 9.5.3).}

\hangnxtpar{SPECTRAL-LINE: You probably don't want to average in
frequency.}

\enumrnext {{\bf SELF-CALIBRATE/IMAGE OR SELF-CALIBRATE/MODEL-FIT THE
DATA}
The final complex gain corrections are determined by iterating
self-calibration with imaging of the resultant data set.  This is
called hybrid-mapping.  Alternatively, self-calibration can be
iterated while fitting models directly to the data --- the goal is to
self-calibrate using the best model possible.  The options are
outlined in \Sec 9.6.}

\hangnxtpar{SPECTRAL-LINE:
One final distinction remains between continuum and spectral-line
data.  Only one or a few spectral points are used to determine final
complex gain corrections which are then applied to all spectral points
in the line data.  After applying these gains, the line source data
can be imaged to form an image cube.}

\hangnxtpar{POLARIZATION:
While the Stokes I and Stokes V images formed using the {\tt RR} and
{\tt LL} visibilities will be real-valued, the Stokes Q and Stokes U
images formed using {\tt LR} and {\tt RL} visibilities can, in
principle, be complex-valued.  You must use a fully complex imaging
and deconvolution technique (see the {\tt HELP} files for {\tt CXPOL}
and {\tt CXCLN}) or you can simply edit the {\tt LR} and {\tt RL}
visibilities to enforce the condition that the whenever you have a
{\tt RL} visibility on a baseline, you also have the {\tt LR}
visibility on the same baseline; this ensures that the Stokes Q and U
images are real-valued and allows you to use the standard imaging
tasks.}

\Iodx{VLBI}\iodx{calibration}

\subsect{9.2. Loading and inspecting data }

\subsubsectt{9.2.1. Loading data from the VLBA correlator}

\subsubsectt{9.2.1.1. Running {\tt FITLD}}

Data generated by the \Indx{VLBA} correlator are loaded from DAT (or
Exabyte) tape into \AIPS\ using \hbox{{\tt FITLD}}.  First, physically
load your tape and {\tt \tndx{MOUNT}} it (\Sec 3.9), then run
\hbox{{\tt \Tndx{FITLD}}}.  Often the data on your tape will be
divided into a number of separate files (corresponding to separate
``correlator jobs'').  In this case, run {\tt FITLD} with {\tt NCOUNT}
set equal to the number of files on the tape (or a suitably large
number), as listed on the paper index which comes with the tape.  Also
set {\us DOCONCAT = 1 \CR} to ensure that all tape files with the same
structure are concatenated into a single \AIPS\ file.  Note that
standard tape handling tasks (\eg\ {\tt PRTTP} and {\tt TPHEAD}) can
be used to inspect the tape contents.

Typical inputs to {\tt FITLD} would be;
\dispt{TASK\qs 'FITLD' ; INP \CR}{to review the inputs.}
\dispt{INTAPE {\it n}\CR}{to specify the input tape number.}
\dispt{NFILES\qs 0 \CR}{to skip no files on tape.}
\dispt{INFILE\qs ' ' \CR}{to load from tape, not from disk.}
\dispt{OUTNAME\qs 'TEST' ; OUTCL\qs 'FITLD '\CR}{to specify the name
           of the output file.}
\dispt{OUTSEQ \qs 0; OUTDI \qs 1 \CR}{to specify the sequence number
           and disk of the output.}
\dispt{OPTY ' ' \CR}{to load any type of file found.}
\dispt{NCOUNT\qs 20 \CR }{to load 20 tape files.}
\dispt{DOUVCOMP\qs 1 \CR}{to save disk space by writing compressed
           data.}
\dispt{DOCONCAT\qs 1 \CR}{to concatenate files with same data
           structure into one disk file.}
\dispt{CLINT\qs $\triangle t$ \CR}{set CL table interval to $\triangle t$
           minutes [see discussion below].}
\dispt{DIGICOR\qs 1 \CR}{request digital corrections.}
\dispt{DELCORR\qs 1 \CR}{request delay decorrelation corrections.}
\dispt{WTTHRESH\qs 0 \CR}{do not flag incoming visibilities based upon
           correlator weights.}
\disptt{SOURCES\qs ''; QUAL\qs 0; CALCODE\qs ''\CR}{to accept all sources found.}
\dispt{TIMERANG\qs 0 \CR}{to accept data from all times.}
\disptt{BCHAN\qs 0; ECHAN\qs 0; BIF\qs 1; EIF\qs 1 \CR}{to accept all channels in all IFs.}
\dispt{SELBAND\qs 0 \CR}{bandwidth to select (kHz).}
\dispt{SELFREQ\qs 0; FQTOL\qs 0\CR}{frequency to select with tolerance of 10 kHz.}
\dispt{OPCODE\qs ''\CR}{to not copy the tape statistics table ('VT' table).}
\dispt{GO \CR}{to run the program.}
\dispe{Because the data files tend to be very large, you should
usually write compressed data ({\tt DOUVCOMP=1}). For most types of
observations, it is better to write `compressed' data sets.  These
take about 1/3 of the space of `uncompressed' data sets, but cause
information about the weights of individual spectral channels and IF
channels to be lost.  [See appendix Y for an expanded discussion of
when to and when not to write `compressed' data sets.]  If your
observation has more than one DAT or Exabyte tape, simply run {\tt
\Tndx{FITLD}} for each tape.  Setting {\tt DOCONCAT 1} and setting the
output file name completely will ensure that the data from separate
tapes with compatible observing band/data structure will be appended
to existing \AIPS\ files.  Generally, after loading all of your data,
you will have one file for each such observing band and/or observing
mode.  However, observations which require multiple passes through the
correlator (including \indx{MkIII} Modes A, B, and C observations)
will have one file per observing mode {\it per correlation pass}.
Data from separate correlator passes can be concatenated using task
\hbox{{\tt \tndx{VBGLU}}}.\Iodx{VLBI}\Iodx{VLBA}}

Adverb {\tt CLINT}, which specifies the {\tt CL} table time sampling
interval must be short compared to the anticipated coherence time;
{\tt CLINT} should be set such that the shortest anticipated
fringe-fit interval is spanned by a few {\tt CL} entries. Time
sampling in the {\tt CL} table that is too coarse can lead to
calibration interpolation errors when applying the fringe-fit
solutions at later stages of the data reduction.  If the interval is
made unnecessarily short the {\tt CL} table may become unmanageably
large (see Lecture XX in VLBI and the VLBA for guidelines on
estimating the coherence times expected at different frequencies).

It is recommended that corrections for correlator scaling and
quantization be performed in {\tt FITLD} by setting adverb {\tt
DIGICOR} to one.  However, in the special case of spectra with very
strong narrow features, the absence of correlator zero-padding may
limit the accuracy of the quantization corrections. See the {\tt
FITLD} help file for further information.

Adverb {\tt DELCORR} enables amplitude corrections for known delay
decorrelation losses in the VLBA correlator, as described in \AIPS\
Memo~90 (1995, ``Delay decorrelation corrections for VLBA data within
\AIPS'' by A. J. Kemball). Setting {\tt DELCORR=1} will create a
correlator parameter frequency ({\tt CQ}) table for each file written
by \hbox{{\tt \Tndx{FITLD}}}. The presence of this table enables the
delay decorrelation correction once the residual delays have been
determined in fringe-fitting. These corrections will not be applied if
the data were not correlated at the \Indx{VLBA} correlator or if the
{\tt CQ} table is missing.  For older {\tt FITLD} files the {\tt CQ}
table can be generated using task \hbox{{\tt \tndx{FXVLB}}} and this
must be done before any changes in the frequency structure of the file
are made.  The {\tt CQ} table is used for rate and delay amplitude
decorrelation corrections after residual delay and rate errors have
been determined by fringe-fitting, and are being applied to the data.
The {\tt CQ} table has no immediate effect on the data written by {\tt
FITLD} but is essential for later processing.\Iodx{VLBI}

The output files produced by {\tt FITLD} are in standard multi-source
format (as described in \Sec 4.1) and contain data from all the target
and calibrator observations in your observation.  {\tt FITLD} also
writes a large number of extension \indx{tables} including an index
({\tt NX}) table, and many tables containing calibration information.
A description of the VLBA correlator table types in given in \Sec 9.8.
With the exceptions of the {\tt OB} table which is specific to SVLBI
observations and the {\tt CORR-ID} random axis which will only appear
when a newer version of {\tt FITLD} is run ({\tt 15APR97} or later),
your catalog header should be similar to the one, obtained using verb
{\tt IMHEADER}, given below .
%\vskip 10pt

\vbox{
\vskip 5pt \verbatim{50pt}
 Image=MULTI     (UV)         Filename=329         .OVLB  .   1
 Telescope=VLBA               Receiver=VLBA
 Observer=TM008               User #=   44
 Observ. date=23-SEP-1996     Map date=06-JAN-1997
 # visibilities      6567     Sort order  **
 Rand axes: UU-L  VV-L  WW-L  TIME1  BASELINE  SOURCE  FREQSEL
            INTTIM  CORR-ID  WEIGHT  SCALE
 ----------------------------------------------------------------
 Type    Pixels   Coord value     at Pixel     Coord incr   Rotat
 COMPLEX      1   1.0000000E+00       1.00  1.0000000E+00     .00
 STOKES       1  -2.0000000E+00       1.00 -1.0000000E+00     .00
 FREQ        16   4.9714900E+09        .53  5.0000000E+05     .00
 IF           8   1.0000000E+00       1.00  1.0000000E+00     .00
 RA           1    00 00 0 .000       1.00        .000000     .00
 DEC          1    00 00 0 .000       1.00        .000000     .00
 ----------------------------------------------------------------
 Coordinate equinox 2000.00
 Maximum version number of extension files of type HI is   1
 Maximum version number of extension files of type CQ is   1
 Maximum version number of extension files of type AT is   1
 Maximum version number of extension files of type IM is   1
 Maximum version number of extension files of type CT is   1
 Maximum version number of extension files of type MC is   1
 Maximum version number of extension files of type OB is   1
 Maximum version number of extension files of type AN is   1
 Maximum version number of extension files of type FQ is   1
 Maximum version number of extension files of type SU is   1
 Keyword = 'OLDRFQ  '  value =  4.97149000D+09
|endverbatim
}
\eject

Note that the sort order of the output dataset in listed as {\tt **}
rather than {\tt TB} and that there are no attached {\tt CL} and {\tt
NX} tables.  This happens (sometimes erroneously) when {\tt
\Tndx{FITLD}} detects a subarray condition on reading the data or, as
in this case, detects the use of multiple integration times on
different baselines in the dataset (common for SVLBI data, see \Sec
9.2.1.2).  The message reported by {\tt FITLD} in this case takes the
form:
\verbatim{50pt}
**********************************************
FITLD5:  Subarray or multiple dump-rate condition found.
FITLD5:  NX/CL tables deleted.
FITLD5:  Use USUBA to set up subarrays.
FITLD5:  Rerun INDXR using CPARM(3) and (4)
FITLD5: *******************************************
|endverbatim

\dispe{Unless any of the following criteria are met, the data written
by {\tt FITLD} are immediately ready for further processing.}

* If the sort code has been blanked as in this example, you must sort
the data [use {\tt \tndx{UVSRT}} or {\tt MSORT}].

* If the subarray/multiple dump-rate condition is encountered, you may
need to run \hbox{{\tt \tndx{USUBA}}}.

* If you wish to join together data processed in multiple correlator
passes, you must run \hbox{{\tt \tndx{VBGLU}}}.

* If {\tt FITLD} does not leave behind {\tt CL} and {\tt NX} tables,
you must run {\tt \tndx{INDXR}} to create them.

{\tt FITLD} can also be used to load archived \AIPS\ data previously
written to tape using {\tt FITTP}, as described in \Sec 5.1.2. In this
case the \indx{VLBA} correlator-specific adverbs, such as those
enabling digital and delay corrections, are not active. \Iodx{VLBI}

\subsubsect{9.2.1.2. Running FITLD for SVLBI data}

For a compressed \Indx{SVLBI} dataset with integration times on the
ground and space baselines of $\triangle T_g$ and $\triangle T_s$
respectively, the total \indx{disk space} requirement is larger than
that given in \Sec 9.1 :
$${\rm Disk\ Space} = 4\ {\rm x}\ 10^{-6}\ N_{Stokes}\ N_{chan}\ N_{if}\
\left[{1\over2}N_{ant}(N_{ant} - 1){T_{expt}\over \triangle T_g} +
N_{ant}{T_{expt}\over\triangle T_s}\right]\ {\rm MBytes}$$
The problem of large dataset sizes will be significantly reduced in
impact if the time filters (see below) are used to increase the
integration times of the space baselines.

Space VLBI data need to be loaded with a version of {\tt FITLD} that
has a revision level of at least 9.0 (as shipped with the {\tt
15APR97} version of \AIPS). This version supports the loading of
spacecraft orbit ({\tt OB}) tables and the use of time filters. The
{\tt OB} tables contain accurate orbit ephemeris data describing the
reconstructed orbit used by the VLBA correlator. This version of {\tt
FITLD} will also create output \uv\ data files containing a
correlation id. random parameter, identified by the abbreviation {\tt
CORR-ID} in the catalog header. This random parameter, which is also
attached to ground-only VLBI datasets by this revision of {\tt FITLD},
allows time-variable changes in the time filtering used by the VLBA
correlator for SVLBI data. Apart from unweighted boxcar averaging, the
filters supported at present include the 32- and 64-tap filters with
decimation factors of 4 and 8 respectively (32-4 and 64-8 in what
follows). For further details on the time filters see VLBA Memo. XXXXX
by B. Clark. The importance of these filters for SVLBI data in \AIPS\
is that they may allow longer accumulation times on baselines to the
spacecraft, with an improved signal-to-noise ratio for the larger
expected fringe rates, than might be obtained with unweighted
averaging. They also significantly reduce the size of the resulting
output \uv\ data set.

The sample catalog header shown in \Sec 9.2.1.1 is for a \Indx{SVLBI}
data set.  Note that these data contain an {\tt OB} table and a {\tt
CORR-ID} random parameter as discussed above. The use of a time filter
can be confirmed by examining the {\tt CQ} table using task \hbox{{\tt
PRTAB}}. The filter type is encoded in column 11 of the table, with
column header {\tt FILTER}, with {\it filter\_type} = {\tt FILTER}
{\it modulo} 256, where {\it filter\_type} values of (0,3,4) represent
the boxcar and 32-4 and 64-8 filters respectively.  Although {\tt
FXVLB} can be used to re-generate a missing {\tt CQ} table, this
should not be done if time filters were used since the resulting {\tt
CQ} table cannot be properly reconstructed; when time filters are
used, only {\tt FITLD} can properly generate {\tt CQ} tables.

Use of the time filters or use of different integration times on space
and ground baselines causes the correlator to write out the data
slightly out of time sequence. {\tt FITLD} will therefore encounter
the multiple dump-rate condition described before and you must {\tt
TB} sort the data (see below).

The {\tt CL} table time sampling interval, set via the adverb {\tt
CLINT} should be carefully considered.  Because SVLBI datasets usually
have at least a few baselines upon which the correlator integration
times are extremely small, the {\tt CL} table can easily become too
large if {\tt CLINT} is unnecessarily small.

Adverbs {\tt DIGICOR=1} and {\tt DELCORR=1} should be set when loading
data generated by the \Indx{VLBA} correlator, as described in \Sec
9.2.1.1.\Iodx{VLBI}

The VLBA correlator assigns the data from the space antenna an antenna
number that depends upon the tracking station used for the downlink.
This is useful in data examination and calibration and can be changed
at later points in the data reduction using task \hbox{{\tt RESEQ}}.
The antenna codes used by the VLBA correlator for tracking stations
are two character codes always ending with the letter `Z'.  The
tracking station code definitions as of the {\tt 15OCT97} release are:
`GZ' (Goldstone), `NZ' (NRAO Green Bank), `RZ' (Robledo - Madrid),
`TZ' (Tidbinbilla), and `UZ' (Usuda).

\subsubsect{9.2.1.3. Sorting VLBA correlator data}

If time filters are used, or if multiple integration times are used on
different baselines, the VLBA correlator will write data that are not
in strict time-baseline ({\tt TB}) sort order. In general, task {\tt
UVSRT} can be used to sort randomly ordered \uv\ data files in \AIPS,
but has significant disk space requirements through the use of
intermediate scratch files. A special task, {\tt \Tndx{MSORT}}, has
been written which uses a direct memory sort with sufficiently large
buffers to accommodate the scale over which the data deviate from true
time-baseline sort order. No intermediate scratch files are used and
it can be significantly faster than {\tt UVSRT} for this special
case. The inputs to {\tt MSORT} are similar to those required by {\tt
UVSRT} and take the form:
\dispt{TASK\qs 'MSORT' ; INP \CR}{to review the inputs.}
\dispt{INDISK\qs{\it n} ; GETN\qs {\it ctn} \CR}{to specify the input
              file.}
\dispt{OUTDISK {\it n} ; OUTNAM\qs ' ', OUTCLA\qs ' '}{to specify the
             output file.}
\dispt{SORT\qs '\qs' \CR}{to select default sort order ('TB' or
             time-baseline).}
\dispt{GO \CR}{to run the program.}
\dispe{Note that if the input and output file names are identical, the
input file is sorted in place.  In place sorting may be necessary if
there is insufficient disk space for a second copy of the data set or
for the intermediate scratch files required by \hbox{{\tt UVSRT}}.
Never abort an in-place sort in progress because you will most likely
destroy the integrity of your data set.}

\subsubsect{9.2.1.4. Subarraying VLBA correlator data}

If the project was observed without using subarrays (defined as times
at which separate antennas are simultaneously observing different
sources or at different frequencies), {\it this step involving {\tt
USUBA} is not necessary and can be skipped}.

If the observations have been scheduled in separate subarrays, defined
either by source or frequency selection, the subarrays should be
labeled in \AIPS\ before proceeding any further.  The \Indx{VLBA}
correlator does not conserve subarray information, which in any event
often has no unique characterization.  This is specified in \AIPS\
using a revised version of task {\tt \Tndx{USUBA}} which now allows
subarrays to be defined through either the input adverbs, an external
{\tt KEYIN} text file, or through the use of an automatic algorithm to
identify and label subarrays found in the data. The automatic
algorithm is recommended.

For automatic subarray labeling by {\tt USUBA}, representative input
parameters would be:
\dispt{TASK\qs 'USUBA' ; INP \CR}{to review the inputs.}
\dispt{INDISK\qs{\it n} ; GETN\qs {\it ctn} \CR}{to specify the input
              file.}
\dispt{OPCODE\qs 'AUTO' \CR}{automatic subarray identification.}
\dispt{TIMERANG\qs 0 \CR}{no time range selection}
\dispt{ANTENNAS\qs 0 ; SOURCES\qs ' ' \CR}{no antenna or source
              selection}
\dispt{FREQID\qs -1 ; SUBA\qs 0 \CR}{no freq. id. or subarray selection}
\dispt{INFILE\qs ' ' \CR}{no external subarray identifications}
\dispt{GO \CR}{to run the program.}
\dispe{Alternatively, if {\tt FITLD} has erroneously identified a
subarray condition, but you {\bf know} you did not observe with
subarrays, you can set {\tt OPCODE = ' ' ; SUBARRAY= 1} to force all
data into the first subarray.}

\subsubsect{9.2.1.5. Indexing VLBA correlator data}

If {\tt FITLD} had not written {\tt NX} or {\tt CL} tables or it was
necessary to sort the data as described in \Sec 9.2.1.3, you must run
task \hbox{{\tt \Tndx{INDXR}}}.  {\tt INDXR} will generate an {\tt NX}
table, and if need be a {\tt CL} table. Typical parameters for {\tt
INDXR} are:
\dispt{TASK\qs 'INDXR' ; INP \CR}{to review the inputs.}
\dispt{INDISK\qs{\it n} ; GETN\qs {\it ctn} \CR}{to specify the input
              file.}
\dispt{PRTLEV\qs 0\CR}{to print minimal details of progress.}
\dispt{CPARM\qs 0, 0 ,$\triangle t$, 1 \CR}{CL interval $\triangle t$;
              recalculate model.}
\dispt{GO \CR}{to run the program.}
\dispe{Note that {\tt CPARM(4)} can be set to zero unless the
correlator model is required in later reduction (\eg\ in astrometry or
geodesy observations)  The {\tt CL} table sampling interval $\triangle
t$ should be chosen subject to the same considerations given regarding
adverb {\tt CLINT} in the discussion of {\tt FITLD} in \Sec
9.2.1.1-2.\Iodx{VLBI}}

\subsubsect{9.2.1.6. Concatenating VLBA correlator data}

Sometimes an observation is correlated using multiple passes through
the VLBA correlator.  In this context, multiple pass means different
IFs/pass; this is due to data rate limitations in the correlator.
{\tt FITLD} will load each pass into a separate disk file.  If it is
desired to join together the IFs correlated on each pass, the task
{\tt \Tndx{VBGLU}} should be used.  {\tt VBGLU} can adjoin different
data sets whose structures differ only in the frequencies covered and
which are otherwise identical.

The inputs to {\tt VBGLU} are rather simple.  Each of the input files
to be glued together is specified via {\tt INNAME}--{\tt IN4NAME},
and an output file is specified via \hbox{{\tt OUTNAME}}.  The choice
of input file 1 is important --- it should be the file with the
largest number of visibilities since it is the one used to set up the
times of the data in the output file (see the {\tt EXPLAIN} file).

\dispt{TASK\qs '\Tndx{VBGLU}' ; INP \CR}{to review the inputs.}
\dispt{INDISK\qs{\it n} ; GETN\qs {\it ctn} \CR}{to specify the input
              file.}
\dispt{IN2DISK\qs{\it n} ; GET2N\qs {\it ctn} \CR}{to specify the
              $2^{\und}$ input file.}
\dispt{IN3DISK\qs{\it n} ; GET3N\qs {\it ctn} \CR}{to specify the
              $3^{\urd}$ input file.}
\dispt{IN4DISK\qs{\it n} ; GET4N\qs {\it ctn} \CR}{to specify the
              $4^{\uth}$ input file.}
\dispt{OUTDISK\qs{\it n} ; GETON\qs {\it ctn} \CR}{to specify the
              output file.}
\dispt{GO \CR}{to run the program.}
\pd

\subsubsect{9.2.1.7. Labeling VLBA correlator polarization data}

The \Indx{VLBA} correlator may label the \indx{polarization} of the
output data incorrectly under certain limited circumstances. This is
something that has been corrected over time but it is well to check
the polarization labeling at this point. The cases where mis-labeling
may occur are: (i) dual parallel-hand correlation (\ie\ RR and LL
only), and (ii) single-polarization LL correlation. Full polarization
correlation data (\ie\ RR, LL, RL, LR) have generally been labeled
correctly.\Iodx{VLBI}

In case (i), the effect is to double the number of \AIPS\ IF channels
and label them all as \hbox{RR}. This can be corrected using interim
task {\tt \Tndx{FXPOL}}, which will correct the mislabeling within
\hbox{\AIPS}.  Calibration tables are lost in using {\tt FXPOL} so, if
needed, this task must be run immediately after \hbox{{\tt FITLD}}.
The {\tt CL} table can be re-generated using \hbox{{\tt INDXR}}.  Note
that although {\tt FXPOL} does not delete the {\tt CQ} table, it does
not properly update it so that, whenever time-filters are used for
correlation, {\tt FXPOL} should not be used.

Typical inputs for {\tt FXPOL} are:
\dispt{TASK\qs 'FXPOL' ; INP \CR}{to review the inputs.}
\dispt{INDISK\qs{\it n} ; GETN\qs {\it ctn} \CR}{to specify the input
              file.}
\dispt{GO \CR}{to run the program.}
\pd

In case (ii), LL data may simply be mis-labeled as \hbox{RR}. This
does not need to be corrected within \AIPS\ but the user needs to take
this into account when selecting or calibrating the data, particularly
in specifying the polarization in the amplitude calibration text file
(\Secs 9.4.2, 9.2.5.2). The Stokes axis can however be modified.
Before running {\tt PUTHEAD}, you should run {\tt GETHEAD} to check
which axis is the Stokes axis in the catalog header.  Typical input
parameters for {\tt GETHEAD} are:
\dispt{INP\qs GETHEAD\CR}{to review the inputs.}
\dispt{INDISK\qs{\it n} ; GETN\qs {\it ctn} \CR}{to specify the input
              file.}
\dispt{KEYWORD\qs 'CTYPEn' \CR}{to select a coordinate type.}
\dispt{GETHEAD \CR}{to get the coordinate type.}
\dispt{TYPE\qs KEYTYPE\CR}{to inspect the coordinate type.}
\dispe{You must pick the value of {\it\tt n\/} for which {\tt GETHEAD}
returns {\tt KEYTYPE} with the string value of {\tt 'STOKES'}.  Then,
run {\tt PUTHEAD} like this:}
\dispt{INP\qs PUTHEAD\CR}{to review the inputs.}
\dispt{INDISK\qs{\it n} ; GETN\qs {\it ctn} \CR}{to specify the input
              file.}
\dispt{KEYWORD\qs 'CRVALn' \CR}{to select a coordinate type.}
\dispt{KEYVALUE\qs = -2 \CR}{to set the STOKES value to 'LL' (or -1
             for 'RR').}
\dispt{PUTHEAD \CR}{to set the coordinate value.}
\pd
\vfill\eject

\subsubsect {9.2.1.8. Preparing the {\tt OB} table for SVLBI data}

The spacecraft orbit table ({\tt OB}) as produced by {\tt FITLD}
contains only the spacecraft position $(x,y,z)$ and velocity
$(v_x,v_y,v_z)$ as calculated to high accuracy from the JPL
reconstructed orbit using the SPICE package (developed at JPL). These
quantities are calculated by the correlator on-line software and are
passed directly through to \AIPS\ via {\tt FITLD} by the \Indx{VLBA}
correlator.  The orbit table is indexed on time and can include
information such as the angle between the spacecraft pointing
direction and the Sun, the time since the start and end of the last
eclipse and the spacecraft parallactic angle. The latter quantities
are not available to the correlator on-line software and, if desired,
need to be computed separately for later use in \hbox{\AIPS}. {\tt
\Tndx{OBTAB}} does not take long to run and it is recommended that it
be run at this point since the modifications made to the {\tt AN}
table are essential for later use in plotting or inspecting spacecraft
orbit information.  Sample inputs for {\tt OBTAB}, are as follows:
\dispt{TASK\qs 'OBTAB' ; INP \CR}{to review the inputs.}
\dispt{INDISK\qs{\it n} ; GETN\qs {\it ctn} \CR}{to specify the input
           file.}
\dispt{INVERS\qs 1 ; OUTVERS\qs INVERS \CR}{process {\tt OB} table 1
           in place.}
\dispt{TIMERANG\qs 0 \CR}{to select all times.}
\dispt{SUBARRAY\qs 1 \CR}{to select subarray number.}
\dispt{APARM 1, 0, 0, 0, 0, 0, 0, 0 \CR}{to update orbital elements in
           {\tt AN} table}
\dispt{GO \CR}{to run the program.}
\dispe{Note that {\tt APARM(8)} can be used to directly specify which
antenna is the orbiting antenna [this task assumes there is only one
orbiting antenna].\Iodx{VLBI}\Iodx{SVLBI}}

The tabulated orbital ephemeris data are stored in the {\tt OB} table
as discussed above, but \AIPS\ also makes provision for orbital
elements to be stored in the {\tt AN} table.  Task {\tt OBTAB} will
determine mean orbital elements from the {\tt OB} table and update the
{\tt AN} table under control of {\tt APARM(1)}. The orbital elements
can be examined by using {\tt PRTAB} to review the updated {\tt AN}
table. The mean elements are used to compute \uv\ coordinates for the
spacecraft so that model amplitudes and closure phases can be plotted
[by tasks {\tt VPLOT} and {\tt CLPLT}] while the \uv\ coordinates
generated by the correlator [or by {\tt UVFIX}] are used for model
division and subtraction, imaging, etc [\eg\ {\tt CALIB} and {\tt
IMAGR}].

The orbit table can be plotted using task \hbox{{\tt \tndx{OBPLT}}}.
Alternatively, task {\tt \tndx{TAPLT}} can be used to display
individual columns as illustrated below for the delta-T table.

\subsubsect{ 9.2.1.9. Loading the time corrections file for SVLBI data}

The round-trip residual delay measurements determined by the tracking
stations are supplied to the correlator in FITS format. These
so-called delta-T tables are not passed to \AIPS\ by the correlator at
present but can be loaded indirectly. Support for the delta-T tables
within \AIPS\ is planned once there is further information regarding
the format and availability of the proposed auxiliary time components
table.  This table might be used, for example, to plot the time
correction as a function of time.  Such information could be useful if
a user suspects a loss of coherence due to a poor predicted orbit or a
clock jump at the tracking station.  The table contains no internal
time stamps, so the row number must be used to determine the
approximate time of a given entry (there are typically 10 rows per
second).

The delta-T tables can be loaded at present using {\tt \tndx{FITLD}}
and attached to a null \uv\ data file, using input parameters as
follows:
\dispt{TASK\qs 'FITLD' ; INP \CR}{to review the inputs.}
\dispt{OUTDISK {\it n} \CR}{specify a separate output file.}
\dispt{OUTNAM\qs 'DUMMY', OUTCLA\qs 'DT'}{}
\dispt{INFILE\qs 'FITS:3551708.kct.a \CR}{external FITS file.}
\dispt{GO \CR}{to run the program.}
\dispe{The other {\tt \tndx{FITLD}} adverbs are not relevant in this
instance. Note that lower case letters can be used in the {\tt INFILE}
adverb if the trailing quotation mark is omitted.  {\tt FITLD} will
load the external FITS file successfully but will print an error
message complaining that no array geometry table was found. This
message can be ignored in this case.}

The delta-T table will appear as an unknown table of type {\tt UK},
and can be plotted using task {\tt \tndx{TAPLT}}:
\dispt{TASK\qs 'TAPLT' ; INP \CR}{to review the inputs.}
\dispt{INDISK\qs{\it n} ; GETN\qs {\it ctn} \CR}{to specify the input
              file.}
\dispt{INEXT\qs 'UK' \CR}{to select the delta-T table.}
\dispt{INVER\qs {\it ukver} \CR}{to select the table version.}
\dispt{BCOUNT\qs 0 ; ECOUNT\qs 0}{to select all records in table.}
\dispt{XINC\qs 1 \CR}{plot each record.}
\dispt{DOHIST\qs 0\CR}{to not plot as a histogram.}
\dispt{GRCHAN\qs 0 \CR}{to use graphics channel 1 on the TV.}
\dispt{APARM\qs 0 ; APARM(6)\qs 1 \CR}{only one column in the table.}
\dispt{BPARM\qs 0 ; CPARM\qs 0 \CR}{default plot control.}
\dispt{LTYPE\qs 3 \CR}{standard plot layout.}
\dispt{DOTV\qs 1 \CR}{for direct plotting on the TV device.}
\dispt{GO \CR}{to run the program.}
\dispe{A sample delta-T table is shown below.
\Iodx{SVLBI}\Iodx{VLBI}\Iodx{VLBA}}

\vskip 10pt
\if T\doFIG
   \centerline{\psfig{figure=FIG/COOK9E.PLT,height=3.5in}}
\else
   \vbox to 3.5in{\vfill\omit\vfill}
\fi

\vskip 5pt
{\Smpoint
\noindent A sample delta-T table, where the recorded delta-T value is
plotted against row number}
\vfill\eject

\subsubsect{9.2.2. Loading data from a MkIII/MkIV correlator}

\subsubsectt{9.2.2.1 Running {\tt MK3IN}}

Data from a \Indx{MkIII} correlator, such as that in Bonn, Germany or
Haystack, Massachusetts, can also be read into \hbox{\AIPS}.  To do
this you need to be supplied with the so called ``A'' tape output,
also known as ``type 52's.''  These data tapes can be read and
translated by the task \hbox{{\tt \Tndx{MK3IN}}}.  The process of
reading MkIII correlator data into \AIPS\ and preparing it for further
processing is more cumbersome than the equivalent process for VLBA
correlator data. This simply reflects the manner in which data are
generated on a baseline-based correlator with a limited number of
playback drives.\Iodx{VLBI}

Before running {\tt MK3IN}, run the task {\tt MK3TX} to extract
the text files from the MkIII archive tape.  These text files contain
information about the correlated scans in the data set. {\tt
\Tndx{MK3TX}} will first provide an index of all the text files and
then ask you to select files for loading onto disk.  It then asks you
interactively for the desired destination of the text files.  It is
important to load and concatenate all the ``A'' files, \ie\ those
files having names like {\tt A}{\it tttt\/}.  The meaning of the other
text files is described in the {\tt MK3TX} Explain file.  Sometimes
the text files are not on the tapes, which means that you cannot
select sub-sets of the data using the A-files, but is not otherwise
catastrophic.

If the A-files are present and have been loaded onto the disk, use
{\tt AFILE} to sort and edit these files to produce a list of scans to
be loaded by \hbox{{\tt MK3IN}}. Use {\tt APARM} settings in {\tt
AFILE} to establish criteria for selecting between any duplicate scans
which may appear on the archive.  If the data set contains data at
multiple frequencies, you should edit the resulting output text file
so that there is a version for each frequency, containing only those
scans at that frequency.

The final step before running {\tt MK3IN} is to create another text
file which provides the commands for the task.  This step is necessary
since some information that is needed by \AIPS\ is not present on the
tape.  Ideally, in this text file (as shown below), the parameter {\tt
STATIONS} should be a list of all the stations correlated, with the
exact name used at correlation. If you do not have such a list, you
can instead specify a list containing {\tt STATIONS\qs `ANY', `ANY'
$\ldots$} Note that there must be at least as many {\tt `ANY'} entries
as there are stations in the data set or some of the stations will not
be loaded.  The parameters in this text file are:
\dispxx{STOKES='RR','LL'}{the Stokes range of the output file.  The
          standard abbreviations are used to select the polarization
          range.  The largest consistent range is used. For example:
          {\tt STOKES='RR','LL'} will cause only RR and LL to be
          written.  {\tt STOKES='LL'} will cause just LL to be
          written. {\tt STOKES='RR','LR'} will cause all four circular
          polarization combinations to be in the output file, since RR
          and LR span the range of allowed \AIPS\ Stokes values.}
\dispxx{FREQCODE='R','L','r',l'}{the polarization codes used by MkIII
          correlators are anything but standard and they need to be
          supplied to {\tt MK3IN} using the parameter \hbox{{\tt
          FREQCODE}}.  The one character polarization identifiers are
          expected in the order RR, LL, RL, and \hbox{LR}.  The usual
          correlator convention is 'R'=RR, 'L'=LL, 'r'=RL, 'l'=LR and
          this is the default assumed by \hbox{{\tt MK3IN}}. However,
          other codes are possible.  For example {\tt FREQCODE='A',
          'B', 'C', 'D'} will interpret 'A' as RR, 'B' as LL and so
          forth, while {\tt FREQCODE='R', 'C', 'r', 'l'} will use the
          default abbreviations except that 'C'=\hbox{LL}.  If {\tt
          MK3IN} encounters an unidentified polarization code the task
          will report: {\tt AT20XX: Unidentified Stokes parameter:
          '{\it X}'}. In this case, modify the {\tt FREQCODE}
          parameter to include this polarization identifier.  This
          will ensure that polarizations are not misidentified
          inadvertently.}
\dispxx{NO\_POL=2}{the number of polarization correlations (\eg\ RR,
          LL, RL and LR), the default is 1.}
\displx{STATIONS='NRAO','VLA','OVRO','FDVS','MPI'}{station names.}
\dispx{/}{{\tt keyin} style delimiter.}
\pd
\Iodx{VLBI}\Iodx{MkIII}

Then, from inside {\tt AIPS}, mount the tape (\Sec 3.9) and run {\tt
\Tndx{MK3IN}}:
\dispt{TASK\qs 'MK3IN' ; INP \CR}{to review the inputs.}
\dispt{INFILE\qs 'MYVLB:PARAM.LIS' \CR}{to define the text control
         file.}
\disptt{IN2FILE\qs 'MYVLB:AFILE.LIS \CR}{to point to a file containing
         a list of scans to be loaded as produced by {\tt AFILE} }
\dispt{INTAPE\qs 4 \CR}{to specify the tape drive number.}
\dispt{NFILES\qs 0\CR}{to skip no files on tape.}
\dispt{OUTNA\qs 'EXP 86-34' \CR}{to select the output file name.}
\dispt{OUTCL\qs 'MK3IN' \CR}{to select the default output class name.}
\disptt{REFDATE\qs '12/11/89' \CR}{to tell {\tt MK3IN} the start date
         of the observations --- get this right or you may get
         negative times.}
\dispt{SOURCES\qs ''\CR}{to accept all sources found.}
\dispt{TIMERANG\qs 0\CR}{to accept data from all times found.}
\dispt{DOUVCOMP\qs 1 \CR}{to write data on disk in compressed format.}
\disptt{APARM\qs 1, 0 \CR}{to set the time increment in the {\tt CL}
         table entries in minutes (to 1 here).}
\disptt{APARM(7)\qs 1 \CR}{to separate sidebands into separate \AIPS\
         IFs; the default is to store both USB and LSB in the same
         IF.}
\dispt{GO \CR}{to run the program.}
\dispe{If the data are contained on more than one Exabyte or DAT tape,
load the second tape and re-run {\tt MK3IN}, setting {\us DOCONCAT = 1
\CR} so that the data are appended to the previous output file.
Before running {\tt MK3IN} a second time, it is important to set the
list of {\tt STATIONS} in the control file to exactly those found when
loading the first tape; use {\tt PRTAN} on the output file to obtain
this list.  Also leave additional {\tt `ANY'} entries after the list
for any stations that are on the second tape but which were not on the
first tape. The use of {\tt DOUVCOMP = 1} is recommended for most data
sets, see Appendix Y.}

\subsubsect{9.2.2.2. Sorting MkIII/IV data}

The \AIPS\ data files created by {\tt MK3IN} will be in an arbitrary
sort order.  Use {\tt \tndx{UVSRT}} to sort them into time-baseline
order:
\dispt{TASK 'UVSRT' ; INP \CR}{to review the inputs.}
\dispt{INDISK\qs {\it n} ; GETN\qs {\it ctn} \CR}{to select the input
             file.}
\dispt{OUTNA\qs INNA ; OUTCL\qs 'TBSRT' \CR}{to specify the output
             file.}
\dispt{SORT\qs 'TB' \CR}{to sort to time-baseline order.}
\dispt{GO \CR}{to make the sorted \uv\ file.}
\pd

\vfill\eject
\subsubsect{9.2.2.3. Concatenating MkIII/IV data}

If you did not set {\tt DOCONCAT=1} when running {\tt MK3IN} and
several files were loaded from tape for one observation, use {\tt
DBCON} to concatenate them together.  In order to have the
concatenated data all appear in a single subarray, both input files
for {\tt DBCON} must have the same reference day number and identical
antenna numbers.  That is, the antennas extension ({\tt AN}) files
with each input \uv\ data file must be the same.

You may list the contents of {\tt AN} files using \hbox{{\tt
\tndx{PRTAN}}}.  To run {\tt \tndx{DBCON}}:
\dispt{TASK\qs 'DBCON' ; INP \CR}{to review the inputs.}
\dispt{INDISK\qs {\it n1} ; GETN {\it ctn1} \CR}{to select the
             $1^{\ust}$ input file.}
\dispt{IN2DISK\qs {\it n2} ; GET2N\qs {\it ctn2} \CR}{to select the
             $2^{\und}$ input file.}
\dispt{OUTNA\qs INNA ; OUTCL\qs 'DBCON' \CR}{to specify the output
             file.}
\disptt{DOARRAY\qs 1 \CR}{to force {\tt DBCON} to mark the output data
             records as being in the same sub-array.  For this to work
             properly, both of the input files must have the same
             reference day and have identical antennas files.}
\dispt{GO \CR}{to concatenate the two files.}
\pd

\subsubsect{9.2.2.4. Merging MkIII/IV data}

\Indx{MkIII} \Indx{VLBI} correlators usually produce redundantly
correlated data. You must merge the data using {\tt \tndx{UVAVG}}:
\dispt{TASK\qs 'UVAVG' ; INP \CR}{to review the inputs.}
\dispt{INDISK {\it n} ; GETN\qs {\it ctn} \CR}{to specify the input
              file.}
\dispt{OUTNA\qs INNA ; OUTCL\qs 'UVMRG' \CR}{to specify the output
              file.}
\disptt{YINC\qs 4.0 \CR}{to set the averaging interval of the input
              data records (in seconds).}
\dispt{OPCODE 'MERG' \CR}{to direct the task to perform the merge
              operation.}
\dispt{GO \CR}{to run the program.}
\pd

The {\tt CL} table should only contain one entry for each antenna at
each time stamp. But, due to the merging process described above and
the fact that redundant correlations may have been performed, there is
one step to follow before you have consolidated your database fully.
You must run {\tt \tndx{TAMRG}} to remove the redundant {\tt CL}
entries:
\dispt{TASK\qs 'TAMRG' ; INP \CR}{to review the inputs.}
\dispt{INDISK {\it n} ; GETN\qs {\it ctn} \CR}{to specify the input
              file.}
\dispt{INEXT\qs 'CL' \CR}{to specify the table type to merge.}
\dispt{INVER\qs 1; OUTVER\qs INVER \CR}{to process the input table in place.}
\dispt{APARM\qs 4, 1, 4, 0, 1, 1, 1, 0 \CR}{to control the merging:
              don't ask why, just do it!}
\dispt{BPARM\qs 1, 4 \CR}{to set compared columns --- again, don't
              ask.}
\dispt{CPARM\qs 1.157e-5, 0.2 \CR}{to set degree of equality --- ditto.}
\dispt{GO \CR}{to run the program.}
\pd

\vfill\eject
\subsubsect{9.2.2.5. Correcting MkIII/IV sideband phase offsets}

If your observation contains a mixture of VLBA and non-VLBA antennas
and you have not stored the sidebands as separate IFs, there will be a
phase offset of about $130^{\deg}$ between the upper and lower
sidebands on baselines from VLBA to non-VLBA antennas.  A correction
for this offset is achieved using the task {\tt \Tndx{SBCOR}}:
\dispt{TASK\qs 'SBCOR' ; INP \CR}{to review the inputs.}
\dispt{INDISK {\it n1} ; GETN\qs {\it ctn} \CR}{to specify the input
               file.}
\dispt{OUTNA\qs INNA ; OUTCL\qs 'SBCOR' \CR}{to specify the output
               file.}
\dispt{BCHAN\qs  1 ; INP \CR}{to specify the lowest channel of lower
               sideband.}
\dispt{ECHAN\qs  4 ; INP \CR}{to specify the highest channel of
               lower sideband.}
\dispt{APARM(1)\qs 0 ; INP \CR}{to apply the default phase offset
               (\ie\ $-130^{\deg}$.)}
\disptt{ANTENNAS\qs {\it n1 , n2 , n3 ,...} ; INP \CR}{to specify the
                VLBA antenna numbers; use {\tt PRTAN} to identify VLBA
                antennas.}
\dispt{GO \CR}{to run the program.}
\pd

\subsubsect{9.2.2.6. Indexing MkIII/IV data}

Next, you must index your data.  The {\tt NX} table is useful as a
summary of the file for you, and is also used by the calibration
programs to provide quick access for reading data.  Create this file
with {\tt \tndx{INDXR}}:
\dispt{TASK\qs 'INDXR' ; INP \CR}{to review the inputs.}
\dispt{INDISK {\it n} ; GETN\qs {\it ctn} \CR}{to specify the input
            file.}
\disptt{CPARM\qs 0, 30, -1 \CR}{to allow $\leq 10$-minute time gaps
            within scans, to limit scans to $\leq 30$ minutes, and to
            not create a new {\tt CL} table.}
\dispt{GO \CR}{to run the program.}
\pd

Other than these initial loading and merging steps, the reduction of
\Indx{MkIII} and MkIV correlator data is identical to that of VLBA
correlator data.\Iodx{VLBI}

\subsubsect{9.2.3. Loading SVLBI data from the Penticton correlator}

The task {\tt \tndx{FITLD}} should be used to load data from the
\Indx{Penticton correlator} into \hbox{\AIPS}.  Other than options
{\tt DIGICOR} and {\tt DELCORR} which should not be requested, {\tt
FITLD} is to be run as described in \Sec 9.2.1.2.  The adverb {\tt
CLINT} is irrelevant as {\tt INDXR} must be run afterwards to generate
the initial {\tt CL} table.\Iodx{SVLBI}

The data must be sorted into time-baseline order ({\tt TB}) using {\tt
UVSRT} or {\tt MSORT} (\Sec 9.2.1.3).  Run {\tt INDXR} to index the
\uv data and create the intial {\tt CL} table (\Sec 9.2.1.5).

The calibration text files required by {\tt ANTAB} must be created by
hand for Penticton correlator data.

{\tt PCLOD} is not necessary for Penticton data.  {\tt PCCOR} is now
thought to process the {\tt PC} table produced by the Penticton
correlator, but has had problems with it in the past.
\vfill\eject

\subsubsect{9.3. Tools for data examination}

Before proceeding further it is important to examine the data, to make
sure they are all loaded, and (especially if this is the first time
you have reduced \Indx{VLBI} data) to familiarize yourself with the
data structure. As processing of the data continues it is also
important to inspect the data periodically to check on the progress of
the calibration process.  Use the verb {\tt IMHEAD} regularly to check
the \uv-data header, particularly the list of tables (as seen in \Sec
9.2.1.1).

Some tasks that can be used to examine the data and the associated
tables are {\tt LISTR}, {\tt DTSUM}, {\tt POSSM}, {\tt VPLOT}, {\tt
CLPLT}, {\tt EDITR}, {\tt TVFLG}, {\tt SPFLG}, {\tt SNEDT}, {\tt
SNPLT}, {\tt PRTAB}, {\tt FRPLT}, {\tt PRTAN}, {\tt COHER}, {\tt
OBPLT}, and \hbox{{\tt SHOUV}}.  Some of these tasks are described in
the next few pages.

\subsubsect {9.3.1 Textual displays}

As a first step, the task {\tt \tndx{LISTR}} can be used to give a
listing of the scans, with source names, time ranges, frequency ID's
and total number of visibilities per scan for each of your output
files.  It is often useful to print out a paper copy of this to
facilitate later data plotting/editing.  Use:
\dispt{TASK\qs 'LISTR' ; INP \CR}{to review the inputs.}
\dispt{INDISK\qs{\it n} ; GETN\qs {\it ctn} \CR}{to specify the input
              file.}
\dispt{OPTYP\qs 'SCAN' \CR}{to request printing of scan summaries.}
\dispt{DOCRT\qs -1 \CR}{to direct the output to a printer.}
\dispt{OUTPRINT\qs '  ' ; \CR}{to have the output printed
              immediately.}
\dispt{GO \CR}{to run the program.}
\dispe{Note that at the end of the above {\tt LISTR} output is useful
information about the frequency structure of your data set.  {\tt
LISTR} is also a good way to look for phase coherence.  If {\tt LISTR}
fails at this point, you may have forgotten to run {\tt INDXR} and/or
{\tt MSORT} (see \Secs 9.2.1.5 and 9.2.1.3).}

Other verbs/tasks for inspecting  your data include;
\hanstart {50pt}
\enumerate{1}{{\tt \tndx{IMHEAD}} lists the file header including
    information on the number of frequency channels and Stokes
    parameters in the data and gives a list of all the extension
    tables.}
\enumerate{2}{{\tt \tndx{PRTAB}} can be used to print the contents of
    any of these extension tables, for instance the {\tt SU} or Source
    table contains information about each of the sources observed.}
\enumerate{3}{{\tt \tndx{PRTAN}} provides a listing of the antennas
    names and their associated antenna numbers.  This is useful
    because in antennas are generaly specified by their antenna
    numbers.}
\enumerate{4}{{\tt \tndx{DTSUM}} produces a matrix showing the number
    of visibilities on each baseline for each scan allowing a check to
    be made that all baselines have been loaded.  It also tells you
    the data integration time.  {\tt DTSUM} also has a mode (triggered
    by setting {\tt APARM(1) = 1}) that will produce a useful matrix
    summary of your whole data set.  {\tt DTSUM} does not properly
    report the integration times when there are multiple integration
    times in the data set.}
\par\hanend

\vfill\eject
\subsubsect{9.3.2 Spectral displays: POSSM and SHOUV}

Your data file will probably contain a number of IFs, observed at
different frequencies, corresponding to the separate ``IF channels''
used during the observations.  While the VLA has a maximum of two such
IF channels (four polarizations are counted separately), \indx{VLBA}
antennas have up to eight IFs (and effectively 16 if double sideband
recording was used).  MkIII Mode A observations can produce up to 28
IF channels.  Within each IF channel are a number of equally spaced
and contiguous ``spectral channels'' generated from each IF data
stream by the correlator.  For continuum applications, the correlator
will generally produce 8 or 16 such spectral channels; in the
spectral-line case there may be as many as 1024 such spectral
channels.  For VSOP data, the VLBA correlator will generally produce
256 spectral channels per \hbox{IF}.  Use {\tt IMHEAD} to find the
number of IF channels and the number of spectral channels per IF
channel, or examine the {\tt LISTR} output.  The reason that the data
must be stored in narrow spectral channels, even for continuum
applications, is that, in VLBI, the geometrical and propagation errors
affecting the data can be large enough to cause significant phase
changes across an IF channel bandwidth, preventing a coherent
integration over the full bandwidth.

The frequency structure of the data can be inspected using {\tt
\Tndx{POSSM}}, which provides a plot of visibility data as a function
of frequency as integrated over a specified time interval.
Optionally, data from up to nine baselines can be plotted on a single
plot page. Initially it may be interesting to view the frequency
structure of data on a bright calibrator source, as in the example
below.  Because, prior to calibration, the phases in each IF channel
are likely to vary rapidly with time, it is important to average data
coherently only over a short time interval.  In general, you will see
phase slopes and offsets affecting the data; these phase errors must
be determined and removed before the data can be averaged in frequency
and/or time.  See \Sec 9.4.8 for more information and a sample plot.
To display the visibility spectrum of a source on the TV, use:
\dispt{TASK\qs 'POSSM' ; INP \CR}{to review the inputs.}
\dispt{INDISK {\it n} ; GETN\qs {\it ctn} \CR}{to specify the input
           file.}
\dispt{SOURCE\qs 'OQ208' \CR} {to specify a single source name.}
\dispt{TIMER\qs 1 2 15 0 1 2 15 30 \CR} {to define a time range.}
\dispt{ANTENNAS\qs 8 ; BASELINE\qs 0 \CR} {to plot all baselines to
           antenna 8.}
\dispt{DOCAL\qs -1 \CR}{to not apply any calibration.}
\displl{APARM\qs 1 , 1 , 0 , 0 , -180 , 180 , 0 , 0 , 1 , 0 \CR} {to
           control the plot as {\tt APARM(1)=1} to use vector
           averaging, {\tt APARM(2)=1} to use fixed scale plots, {\tt
           APARM(5)} and {\tt APARM(6)} to set phase range, {\tt
           APARM(9)=1} to plot all IFs together in one diagram.}
\dispt{BIF\qs 0 ; EIF\qs 0 ; BCHAN\qs 0 ; ECHAN\qs 0 \CR}{to include
           all IFs and spectral channels.}
\dispt{CODETYPE\qs' ' ; POLPLOT\qs ' ' \CR}{to plot amplitude and
           phase.}
\dispt{SOLINT\qs 0 \CR}{to average over the full time range.}
\disptt{NCOUNT\qs 9 ; BPARM\qs 0 ; OUTFILE\qs ' ' \CR} {to have 9 plots
           per page without division by ``channel 0'' and without
           writing the spectrum to a file.}
\dispt{DOTV\qs 1 \CR}{to plot on the TV, else create plot extension.}
\dispt{BADDISK 0 \CR}{to use all disks.}
\dispt{GO \CR}{to run the program.}
\dispe{Note that the amplitudes are totally uncalibrated at this stage
and are in units of ``correlation coefficients''; these will generally
appear on plots mislabeled as {\tt mJy} (representing multiples of
$10^{-3}$ correlation coefficients).}
\Iodx{VLBI}

Task {\tt \tndx{SHOUV}} is similar to {\tt POSSM} but produces text
output instead of plots.

\vfill\eject
\subsubsect{9.3.3 Time displays: VPLOT and CLPLT}

The task {\tt \Tndx{VPLOT}} can be used to view the visibility data as
a function of time (or other variables).  Again, data from several
baselines can appear on one plot page.  Plots of amplitudes and phases
and several other quantities can be made, although, to view closure
phase, you must use task \hbox{{\tt \tndx{CLPLT}}}.  Note that {\tt
VPLOT} will plot data from a single IF and spectral channel or can
coherently average the data over many spectral and IF channels.
Calibration can be applied before averaging these channels.  Also, if
desired, a model can be plotted against the data.  The model can
either be displayed at the times of the data samples or, with somewhat
less accuracy, continuously, even at times for which there is no
associated data or recorded \uv\ coordinate values.

The following parameters will display uncalibrated amplitudes and
phases from a single spectral channel of a single IF channel for a
short scan on a bright calibrator:
\dispt{TASK\qs 'VPLOT' ; INP \CR}{to review the inputs.}
\dispt{INDISK\qs {\it n} ; GETN\qs {\it ctn} \CR}{to specify the input
              file.}
\dispt{CLR2NAME \CR}{to ensure no model is plotted.}
\dispt{SOURCE 'OQ208' \CR} {to specify the source name.}
\dispt{BIF\qs 4 \CR}{to give first included IF channel.}
\disptt{EIF\qs 4 \CR}{to give last included IF channel;, if {\tt EIF}
              $>$ {\tt BIF} then IFs are averaged.}
\disptt{BCHAN\qs 8 \CR}{to set the lowest spectral channel to include
              in average prior to plotting.}
\disptt{ECHAN\qs 8 \CR}{to set the highest spectral  channel to
              include in average prior to plotting; no averaging in
              this case.}
\dispt{TIMER 1 2 15 0 1 2 25 00 \CR}{to define a 10-minute time
              range.}
\dispt{DOCAL\qs -1 ; DOBAND\qs -1  \CR}{to apply no calibration
              tables or bandpass tables to data.}
\dispt{OPTYP\qs ' '}{to display cross-correlations; {\tt 'AUTO'}
              to get auto-correlations.}
\dispt{SOLINT \qs 0} {to do no time averaging of the data before
              plotting.}
\dispt{XINC\qs 1 \CR}{to plot every record.}
\disptt{BPARM\qs 0 , -1 \CR}{to set $x$-axis type ({\tt BPARM(1) = 0}
              plots time (Hrs, min, sec)), $y$-axis type ({\tt
              BPARM(2)= -1} plots both amplitude and phase), and to
              use self-scaling.  See {\us EXPLAIN VPLOT \CR} for
              other options.}
\dispt{NCOUNT\qs 4 \CR}{to plot 4 baselines/page.}
\dispt{GO \CR}{to run the program.}
\dispe{An example {\tt VPLOT} output appears at the end of \Sec
9.4.8.2.  It may be useful to make a plot of data ``weight'' versus
time on the autocorrelation data from each antenna (set {\tt
BPARM(2)=16} and {\tt OPTYP = \hbox{'AUTO'}}).  The weight depends on
the number of valid bits correlated and is a good indication of tape
playback quality.\Iodx{VLBI}}

\subsubsect{9.3.4. EDITR}

Another task which can display data as a function of time is
\hbox{{\tt \tndx{EDITR}}}.  This program is used primarily to edit
data interactively (see \Sec 5.5.2), but its interactive aspects (\ie\
allowing the user to ``zoom'' in on certain time periods) make it
useful for pure data inspection.  Tasks {\tt TVFLG} (\Sec 4.4.3) and
{\tt SPFLG} (\Sec 10.2.2) are also useful in this way.

\vfill\eject
\subsubsect{9.3.5. SNPLT}

Supplied with your \Indx{VLBI} data will be a number of important
tables used for calibration and many more are generated as data
calibration proceeds.  \Sec 9.8 summarizes the contents of each of
these \indx{tables}.  Two of the most important tables are the
calibration or {\tt CL} table and the solution or {\tt SN} tables.

The task {\tt \tndx{SNPLT}} should be used periodically to inspect the
contents of the latest {\tt CL} and {\tt SN} tables.  The example
below plots the antenna-based amplitude corrections stored in {\tt CL}
table 2.
\dispt{TASK\qs 'SNPLT' ; INP \CR}{to review the inputs.}
\dispt{INDISK {\it n} ; GETN\qs {\it ctn} \CR}{to specify the input
            file.}
\dispt{OPTYPE\qs 'AMP' \CR}{to plot amplitudes.}
\dispt{INEXT\qs 'CL' ; INVER\qs {\it n}\CR}{to choose {\tt CL} table
            version.}
\dispt{DOTV 1 \CR} {to plot on the TV screen; otherwise, create plot
            extension files.}
\dispt{NCOUNT\qs 5 \CR}{to plot 5 antennas per page.}
\dispt{GO \CR}{to run the program.}
\dispe{{\tt SNPLT} can also be used to plot quantities from other
tables generated by the calibration process including the contents of
{\tt SN} (``solution tables''), {\tt TY} (``system temperature
tables''), and {\tt PC} (``phase-cal tables'').}

\subsubsect{9.3.6 COHER}

The task {\tt \Tndx{COHER}} can be used to determine the coherence
time in a \uv\ dataset broken down both on time and by antenna and
baseline. The coherence time is estimated by comparing vector and
scalar averaged amplitudes over increasing time averaging intervals.
Averaging is not performed over source scan boundaries. The coherence
time is defined as the averaging interval over which the ratio of
vector and scalar amplitudes falls below a pre-assigned level. This
can be set under user control. In addition, data that fall below a
specified signal-to-noise ratio can be excluded from the coherence
time estimates. Provision is made for selection by source name, time
range, IF channel, antenna and frequency id., and the ability to
average over a subset of individual frequency channels. The input
parameters to task {\tt COHER} take the form:

\dispt{TASK\qs 'COHER' ; INP \CR}{to review the inputs.}
\dispt{INDISK\qs{\it n} ; GETN\qs {\it ctn} \CR}{to specify the
              \uv\ input file.}
\dispt{APARM\qs 0 \CR}{SNR cutoff 5; vector to scalar cutoff 0.8.}
\dispt{TIMERANG\qs 0, 10, 5, 0, 0, 10, 15, 0 \CR}{time range
              selection.}
\dispt{BIF\qs 5 ; BCHAN\qs 1 ; ECHAN\qs 8 \CR}{IF and channel
               selection.}
\dispt{SOURCES\qs 'DA193' , '\qs ' \CR}{source selection.}
\dispt{FREQID\qs 1 \CR}{Frequency id. selection.}
\dispt{GO \CR}{to run the program.}
\pd

\subsubsect{9.3.7 FRPLT}

A preliminary examination of the coherence of individual scans or time
segments in the data can also be performed using task {\tt
\Tndx{FRPLT}}, which allows time series or fringe-rate spectra to be
plotted for a selected baseline. This task allows data to be selected
by the usual criteria, including time range, source name, and
frequency parameters, amongst others, and will then plot the
individual time series in amplitude and phase or the associated
fringe-rate spectrum. Provision is made for averaging over frequency
channels within each IF, for varying degrees of padding in the FFT,
and for division by the pseudo-continuum average ``channel zero''
before plotting. Typical input parameters to {\tt FRPLT} are:
\dispt{TASK\qs '\Tndx{FRPLT}' ; INP \CR}{to review the inputs.}
\dispt{INDISK\qs{\it n} ; GETN\qs {\it ctn} \CR}{to specify the input
             file.}
\dispt{SOURCES\qs 'DA193' , '\qs ' \CR}{source selection.}
\dispt{TIMERANG\qs 0, 10, 5, 0, 0, 10, 15, 0 \CR}{time range selection
             (required).}
\dispt{STOKES\qs 'LL' \CR}{Stokes selection.}
\dispt{BIF\qs 1 ; EIF\qs 0 \CR}{IF and frequency channel selection.}
\dispt{BCHAN\qs 3 ; ECHAN\qs 12 \CR}{}
\dispt{ANTENNAS\qs 3, 4 \CR}{select baseline 3-4 (required).}
\dispt{DOCAL\qs -1 ; DOPOL\qs -1 \CR}{to apply no continuum
               calibration.}
\dispt{DOBAND\qs -1 \CR}{to do no bandpass calibration.}
\dispt{APARM(1)\qs 1 ; APARM(2)\qs 0 \CR}{integration time 1 sec;
               self-scale the plots.}
\dispt{APARM(7)\qs 0 \CR}{plot fringe-rate spectra with no
               padding.}
\dispt{APARM(8)\qs 10 \CR}{pre-average all 10 frequency channels.}
\dispt{BPARM\qs 0 \CR}{no division by "channel zero".}
\dispt{DOTV\qs 1 \CR}{plot directly to the TV device.}
\dispt{GO \CR}{to run the program.}
\dispe{The underlying time series in amplitude and phase can be
plotted by setting {\tt APARM(7)=1}. Note that the baseline and time
range must be selected using {\tt ANTENNAS} and {\tt TIMERANG} and the
existing integration time in the data set using {\tt APARM(1)}. A
separate plot will be produced for each IF channel in all cases.}

\subsect{9.4. Calibration strategy}

We can now begin the process of calibrating \Indx{VLBI} data.  As the
\indx{calibration} process proceeds, both amplitude and phase
corrections are incorporated into the {\tt CL} tables. VLBI
correlator output is in terms of dimensionless ``correlation
coefficients.''  To convert to Janskys, large amplitude correction
factors have to be entered into the {\tt CL} tables.  In addition,
phase correction factors must be entered into the {\tt CL} table to
correct for phase offsets and ramps as functions of frequency and
time.  These corrections must be made so that the data can be averaged
over frequency and time without loss of coherence.  The process of
determining the phase corrections is known as ``{\it fringe-fitting}''
in VLBI; see \Sec 9.4.8.

Unlike VLA users, VLBI users normally do not attempt to calibrate the
absolute phase of the data using external calibrator sources.  VLBI
users just calibrate out the phase derivatives with respect to time
and frequency.  The absolute phases are normally left uncalibrated and
``self-calibration'' methods are then used to generate images (see
\Sec 9.6).  The alternative of absolute-phase calibration using an
external calibrator, known as ``phase-referencing'' in VLBI circles,
is a little more difficult in VLBI than for the \hbox{VLA}.  In general
terms, ``phase-referencing'' VLBI data in \AIPS\ is accomplished by
similar methods as used for VLA data in \AIPS\ .  A description of
``phase-referencing'' methods for VLBI data in AIPS will be added to
the \Cookbook\ at a later date [see the lecture by Beasley and Conway
in VLBI and the VLBA, 1995, ASP].

Optimum fringe-fitting results are obtained if amplitudes are
calibrated first, since, in this case, the data will be weighted
appropriately [the \AIPS\ task {\tt FIXWT} may be used to adjust the
weights in the data to reflect the scatter of the actual data].  We
therefore describe the process of amplitude calibration first in
\Sec 9.4.4.3.  Then, in \Sec 9.4.8, we describe the calibration of
residual phase using ``fringe-fitting'' techniques.  Note however,
that for observations of strong sources or observations using only
VLBA antennas (where the sensitivities on all baselines are roughly
the same), the order of the two calibration steps may be reversed.

\subsubsect{9.4.1 Incremental calibration philosophy}

The general strategy adopted by \AIPS\ for \indx{calibration} is,
starting with the lowest version of the {\tt CL} table, to incorporate
step-by-step amplitude and phase corrections for a number of different
effects.  At each stage either an existing {\tt CL} table is modified
or a new version is created from a lower version by a task which
applies a certain type of calibration.  Note that the actual
visibilities are not changed until you are satisfied that you have the
best possible calibration file; at this point the task {\tt SPLIT} can
be used to apply the calibration information of the best {\tt CL}
table to the data.  However at each point along the way the effect of
a particular {\tt CL} table on the data can be viewed using {\tt
\tndx{POSSM}} or {\tt \tndx{VPLOT}} by setting {\tt DOCAL=1} and {\tt
GAINUSE} equal to the chosen {\tt CL} table. Since many {\tt CL}
tables may be produced in the course of calibrating a \Indx{VLBI} data
set it is important to keep a note of which effects are included in
each one.  Ideally one should delete {\tt CL} tables which are judged
incorrect and ensure that the accumulated corrections lie in the
highest numbered {\tt CL} table. It is recommended that version one of
the {\tt CL} table, as produced by {\tt FITLD}, be copied to {\tt
CL.2} using {\tt TACOP} before any calibration is begun, and that {\tt
CL.2} be used as the starting point in the calibration sequence. An
effort is made within \AIPS\ to insure that {\tt CL.1} is not deleted
inadvertently. If this does occur however it can be re-generated using
task {\tt INDXR} (described in \Sec 9.2.1.5).  [Note that {\tt INDXR}
cannot re-generate some types of information, \eg\ the phase-cals
inserted by the MKIII correlator so that it is important to try to
preserve the first {\tt CL} table.] Note that the task {\tt
\tndx{TASAV}} can be used to copy all the tables to a dummy file
containing no data.  This can be used to save a ``snapshot'' of the
tables at various points in your data processing for insurance
purposes.  The tables can be copied back into your data file if
necessary using \hbox{{\tt TACOP}}.

\subsubsect{ Using {\tt SN} and {\tt CL} tables}

The various stages of calibration described below produce {\tt SN}
tables which are then used to create {\tt CL} tables using \hbox{{\tt
CLCAL}}.  The ancillary tasks {\tt SNCOR}, {\tt SNSMO}, {\tt SNEDT},
and {\tt CLCOR} can be used to modify the {\tt SN} and {\tt CL} tables
directly.  It is important to chose the proper methods of
interpolation in these tasks.

\subsubsect{9.4.2. Processing observing log and calibration information}

This section describes the processing of external calibration
information, as supplied in ASCII log files; for \Indx{VLBA} antennas,
the external calibration file for a given experiment can be obtained
by ftp to {\bf aspen.aoc.nrao.edu (146.88.5.8)} under user account
{\bf vlbiobs}. The files are named as {\it xxxxx}{\bf cal.vlba.Z},
where {\it xxxxx} is the project code (\eg\ bz199) and are stored in
compressed format.  Gain curve information can be obtained for the
VLBA antennas by anonymous ftp to host {\bf ftp.aoc.nrao.edu
(146.88.1.4)} to retrieve file {\bf vlba\_gains.key} in the {\bf pub}
sub-directory.  The gain curve file should be concatenated to the
external calibration file.  Similar calibration files for other
participating antennas and VSOP should be obtained from the
appropriate sites.

The standard VLBA format antenna calibration files contain a diversity
of information, not all of which is required by \hbox{\AIPS}. The
information that is used by \AIPS\ includes $T_{\rm sys}$ or related
total power measurements, edit flags as written by the tracking
stations or on-line monitor control system, weather information, and
pulse-calibration data. These external data currently must be read
into \AIPS\ by tasks {\tt ANTAB}, {\tt UVFLG}, {\tt APCAL} and {\tt
PCLOD} respectively, as described in \Secs 9.4.4.3 and 9.4.8.2,
although the relevant information will be passed directly through to
\AIPS\ by the VLBA correlator at some point in the near future.

\subsubsect{9.4.2.1 Automatic formatting of log files}

The external \indx{calibration} file, if suitably close to the
standard \Indx{VLBA} format, concatenated with the gain curve file,
can be automatically subdivided and re-formatted to comply with \AIPS\
requirements using task \hbox{{\tt \tndx{VLOG}}}.  Typical inputs
would be:
\dispt{TASK\qs 'VLOG' ; INP \CR}{to review the inputs.}
\dispt{INDISK\qs{\it n} ; GETN\qs {\it ctn} \CR}{to specify the {\tt
            FITLD} output file.}
\dispt{SUBARRAY\qs 1 \CR}{select the required subarray.}
\dispt{INFILE\qs 'FITS:bz199cal.vlba \CR}{external calibration file.}
\dispt{OUTFILE\qs 'FITS:BZ199' \CR}{prefix and directory for output
            files.}
\dispt{FQTOL\qs 1000 ; CPARM\qs 0 \CR}{tolerance for frequency match
            (kHz).}
\dispt{LTYPE\qs 3 \CR}{standard plot layout.}
\dispt{PRTLEV\qs 0 \CR}{do not echo calibration file to the screen.}
\dispt{GO \CR}{to run the program.}
\pd

A sequence of output text files will be created in the \${\tt FITS }
directory named {\tt BZ199.*} with suffixes:\Iodx{VLBI}

\hanstart{50pt}
\enumerate{1}{{\tt .TSYS:} $T_{\rm sys}$ calibration data,
including gain curves, suitable for direct use by \hbox{{\tt ANTAB}}.
An {\tt INDEX} record is constructed for each frequency id. if
possible. If no match can be made to the FQ data a warning message is
printed and the {\tt INDEX} keyword is omitted; the {\tt INDEX}
keyword must then be inserted by hand (see the HELP file for {\tt
ANTAB}).  Gain curve entries for the frequency and time range in the
\uv\ data are copied to this output file.  It is recommended to insert
$T_{\rm sys}$ values at the end of scans immediately before source
changes to avoid  interpolation problems for sources of greatly
differing flux density. Occasionally spurious data from previous
observing runs or system startup files will end up in the {\tt .TSYS}
file and must be edited out by hand.}

\enumerate{2}{{\tt .FLAG:} Flag data, suitable for direct use by
\hbox{{\tt UVFLG}}. In the older format "antennas=vlba\_xx" the
appropriate antenna and day numbers are inserted.}

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

\enumerate{4}{{\tt .PCAL:} Pulse-calibration data, for input to
\hbox{{\tt PCLOD}}. No editing is performed.}
\par\hanend

Files with suffixes {\tt .SCAN} and {\tt .MKIII} contain scan
summaries and MkIII information and are for information purposes only.

\subsubsect{9.4.2.2  VLA log files}

\subsubsect{9.4.2.3 SVLBI log files}

\vfill\eject
\subsubsect{9.4.2.4 Manual formatting of log files}

Partitioning of the \indx{calibration} file can and must be done by
hand if the calibration file format is sufficiently distinct from the
standard \indx{VLBA} format.  If your observation used non-VLBA
antennas you will need to edit the calibration text file manually to
add any log information supplied for these antennas.  The necessary
steps are as follows:

Extract the flagging and Tsys information from the calibration text
file.  You will also need to prepend gain curves to the $T_{\rm sys}$
file.  Try {\tt EXPLAIN ANTAB} to see an example file in the proper
format.  The parameter {\tt TIMEOFF} should be set to zero for each
station since both flag information and data are stored with UTC
times.  A new keyword {\tt DTIMRANG} is also supported which pads each
flagged time interval to insure that even very short flag intervals
are applied.\Iodx{VLBI}

While older VLBA format calibration files were supplied with the {\tt
ANTENNA} keyword, newer VLBA format calibration files are supplied
with the {\tt ANT\_NAME} keyword.  In the former case the file should
be edited to insert the antenna numbers as listed in the {\tt AN}
table (use {\tt PRTAN} on your \AIPS\ file to find these) and the
absolute day numbers must be replaced by relative day numbers with
respect to the \AIPS\ reference date.  In the latter case, no
adjustments to either day numbers or antenna numbers are necessary.

\subsubsect{9.4.3. Data editing}

Before proceeding to calibrate, you should first flag any obviously
bad data.  In summary, initial editing is based on the flagging
information supplied by the on-line antenna monitor systems, which is
applied using \hbox{{\tt UVFLG}}. This information may be extracted to
a {\tt .FLAG} file as outlined in the previous section or subsequent
editing based on the station report logs, or elevation limits can also
be performed using \hbox{{\tt UVFLG}}. Finally, graphical editing
tasks such as {\tt IBLED} and {\tt EDITR} may be used for interactive
baseline-based \indx{editing}.  Until the data is converted into
single-source data format, flagging information is stored in the {\tt
FG} table instead of being used to directly discard data.  This allows
for the possibility of `un-flagging' using {\tt OPCODE='UFLG'} in
\hbox{{\tt UVFLAG}}.

Task {\tt \tndx{UVFLG}} is capable of reading a text file listing
periods of known errors, and \indx{flagging} the corresponding data.
Set {\tt INFILE} inside {\tt UVFLG} to point to a text file, such as
the {\tt .FLAG} file described in \Sec 9.4.2, and run {\tt UVFLG} to
flag the data.  {\tt UVFLG} can, of course, be run without an external
control file, using instead the \AIPS\ inputs to delete particular
stations, IF channels, etc.~which are thought to be bad.

To edit \uv\ data based on elevation limits, {\tt UVFLG} can be used
with input parameters:
\dispt{TASK\qs 'UVFLG' ; INP \CR}{to review the inputs.}
\dispt{INDISK\qs{\it n} ; GETN\qs {\it ctn} \CR}{to specify the
              input file.}
\dispt{SOURCES\qs 'DA913' \CR}{source selection.}
\dispt{SUBARRAY\qs 1 \CR}{select the required subarray.}
\dispt{ANTENNAS\qs 3, 4, 5, 8 \CR}{antenna selection.}
\dispt{APARM(4)\qs 10 \CR}{elevation limit of 10 degrees.}
\dispt{FLAGVER\qs 1 \CR}{specify output flag table.}
\dispt{GO \CR}{to run the program.}
\dispe{This will generate a {\tt FG} table flagging time ranges that
fall below the specified elevation limit.}
\eject

Another \indx{editing} task which may be useful is {\tt \tndx{QUACK}},
which can edit, say, the first 30 to 60 seconds after each source
change.  This might be needed because (at non-VLBA antennas) the
telescopes were still slewing or system temperature measurements were
being made.

Tasks {\tt \tndx{EDITR}} and {\tt \tndx{IBLED}} can be used to inspect
and edit the data interactively. These tasks are similar in many
respects to {\tt TVFLG} ({\it q.v.}) but are more suited to
interferometers with small numbers of baselines. It is also possible
to use {\tt TVFLG} to perform your editing although the TV display is
somewhat confusing on sparse arrays of data, especially if there is
significant source structure.  Read \Secs 4.4 through 4.4.2 and \Secs
5.5 for more details on the editing of data.\iodx{flagging}\Iodx{VLBI}

If you flag a large fraction of the data set, you may wish to run {\tt
\tndx{UVCOP}} to discard the flagged data and conserve disk space.

\subsubsect{9.4.4 {\it a priori\/} calibration}

The \indx{calibration} steps described in this section use {\it a
priori\/} information about the performance of the antennas.  These
should be performed before any other {\it a posteriori} calibration.
The order of these different calibrations is not particularly
important, but probably they should be done in the order listed here.

The voltage threshold levels in the digital samplers at the antennas
may differ from their optimum theoretical values, and this may vary
from antenna to antenna. This sampler bias, which is usually only
significant in two bit quantization, introduces an antenna-based
amplitude offset.  In full polarization observations this appears as
an amplitude offset between {\tt RR} and \hbox{{\tt LL}}.  The amount
of the offset depends upon the detailed workings of the correlator
used.  For data from the VLBA correlator, if {\tt FITLD} was run with
{\tt DIGICOR = 0, 1} or {\tt 2}, task {\tt ACCOR} can be used to
remove these digital sampler biases.

Starting with the {\tt 15JUL95} version of \AIPS\ the recommended
method of amplitude calibration using {\it a priori\/} $T_{\rm sys}$
and antenna gain information is to use the tasks {\tt \tndx{ANTAB}}
and \hbox{{\tt \tndx{APCAL}}}. These new tasks offer greater
flexibility in amplitude calibration, including corrections for
atmospheric opacity.

The RCP and LCP feeds on each antenna will rotate in position angle
with respect to the source during the course of the observation for
Alt-Az antennas (which probably constitute a majority of the antennas
in your observation).  Since this rotation is a simple geometric
effect, it can be corrected by adjusting the phases without looking at
the data.  This correction must be performed before any phase
calibration which actually examines the data is executed.  This
correction is only important for \indx{polarization} observations.

\subsubsect{9.4.4.1. Digital sampler bias corrections for VLBA
correlator data}

*** {\tt ACCOR} is only intended to run on data from the \Indx{VLBA}
correlator. ***

Typically the amplitude offsets for the VLBA correlator are of order
$5-10\%$ but values as high as $20\%$ have been observed. These can be
corrected by examination of the autocorrelation spectra using task
\hbox{{\tt \tndx{ACCOR}}}. Since {\tt ACCOR} computes the necessary
correction by examining the total-power spectra, it must be run
immediately after {\tt FITLD} in the sense that nothing else should be
run that actually modifies the total-power spectra directly.  Although
{\tt ACCOR} ignores any {\tt SN} or {\tt CL} tables that are present,
it is essential to correct for the sampler biases before performing
any {\it a posteriori\/} calibration, \eg\ fringe-fitting or
self-calibration.

Typical inputs to {\tt ACCOR} for this correction would be:
\dispt{TASK\qs 'ACCOR' ; INP \CR}{to review the inputs.}
\dispt{INDISK {\it n}; GETN {\it ctn} \CR}{to specify the input file.}
\dispt{TIMERANG 0\CR}{select all data.}
\dispt{SOLINT \qs 120\CR}{solution interval for sampler corrections
           (min).}
\dispt{GO \CR}{to run the program.}
\dispe{The correction factors are expected to be fairly stable over
time but it is well to examine the solution ({\tt SN}) table generated
by {\tt \tndx{ACCOR}} using {\tt \tndx{SNPLT}} for any bad points or
inconsistent values.  One approach is to inspect the {\tt SN} table
and then run {\tt SNSMO} with clipping to get rid of discrepant
points.  Alternatively, the new interactive table editing task {\tt
SNEDT} can be used.}

For one-bit quantization, no significant sampler bias correction is
expected. In this case if the {\tt ACCOR} gain factors deviate from
unity this may point to overall scaling or {\it b}-factor errors. In
this respect it is recommended that {\tt ACCOR} be run on one bit data
as a consistency check.
\Iodx{VLBI}

\subsubsect{9.4.4.2 Smoothing and applying corrections}

{\tt SN} tables can be smoothed using tasks {\tt \tndx{SNEDT}} and
{\tt \tndx{SNSMO}} and before being used to update {\tt CL} tables
using \hbox{{\tt CLCAL}}.\iodx{calibration}

Typical inputs for {\tt SNSMO} would be:
\dispt{TASK\qs 'SNSMO ; INP \CR}{to review the inputs.}
\dispt{INDISK\qs {\it n} ; GETN {\it ctn} \CR}{to specify the input
                       file.}
\dispt{SOURCES\qs ' ' \CR}{use specify sources whose solutions are to be modified.}
\disptt{SELBAND\qs -1; SELFREQ\qs -1; FREQID\qs 0\CR}{do not select on frequency.}
\dispt{BIF\qs 0; EIF\qs 0\CR}{do not select by IF.}
\dispt{TIMERANG\qs 0; ANTENNAS\qs 0\CR}{ to not select in time or by antennas}
\disptt{SUBARRAY\qs 0\CR}{ to select the first subarray; NB, {\tt SNSMO} works only on one subarray at a time.}
\dispt{INTERPOL\qs ''\CR}{to use the boxcar smoothing method.}
\dispt{BPARM\qs 0.05,0 \CR}{to use a 3 minute smoothing time.}
\dispt{DOBLANK\qs 1 \CR}{to interpolate blanked values.}
\dispt{SMOTYPE\qs ''\CR}{to smooth amplitudes only.}
\dispt{CPARM\qs 0\CR}{to set ranges of allowed values.}
\disptt{INVER\qs {\it snin} ; OUTVER\qs 0\CR}{to read in the {\tt SN} table
    [created in this case by {\tt ACCOR}] and to create a new {\tt SN}
    table.}
\disptt{REFANT\qs 0 ; BADDISK\qs 0 \CR}{to keep current reference antenna;
                      to specify disks no to use for scratch files.}
\dispt{INP \CR}{to check the inputs.}
\dispt{GO \CR}{to run the task.}
\pd

Typical inputs for {\tt \tndx{CLCAL}} would be:
\dispt{TASK\qs 'CLCAL' ; INP \CR}{to review the inputs.}
\dispt{INDISK\qs {\it n} ; GETN {\it ctn} \CR}{to specify the input
                       file.}
\dispt{CALSOUR\qs ' ' \CR}{use all solutions produced by \hbox{{\tt
                       ACCOR}}.}
\dispt{SOURCE\qs  ' ' \CR}{apply corrections to all sources.}
\dispt{OPCODE  'CALI' \CR}{to apply {\tt SN} tables to a {\tt CL}
                       table.}
\dispt{INTERPOL \qs' ' \CR}{to use linear vector interpolation with no
                       {\tt SN} table smoothing.  see below for more
                       discussion of \hbox{{\tt INTERPOL}}.}
\dispt{SMOTYPE \qs ' '; INTPARM \qs 0 \CR}{to clear interpolation and
                       smoothing parameters.}
\dispt{SNVER\qs {\it snin} \CR}{to select the {\tt SN} table containing
           solutions to be interpolated.}
\dispt{GAINVER\qs {\it clin} \CR}{to select the {\tt CL} version to which
           solutions are to be applied.}
\disptt{GAINUSE\qs {\it clout} \CR}{to select the output {\tt CL} version,
           containing updated \indx{calibration} information.}
\disptt{REFANT\qs 0 ; BADDISK\qs 0 \CR}{Try to consistently use a single
                    reference antenna if possible during all steps of
                    calibration.}
\dispt{INP \CR}{to check the inputs.}
\dispt{GO \CR}{to run the task.}
\dispe{Note well that {\tt SNVER}=0 means here to combine the solutions from
all {\tt SN} tables, {\tt GAINVER}=0 means to apply the solutions to
{\tt CL} table 1, and {\tt GAINUSE}=0 means to write to {\tt CL} table
2 ---- using these defaults unintentionally can be the source of
serious errors.  If two {\tt SN} tables contain two similar attempts
at finding corrections and {\tt SNVER=0} then, effectively, {\tt
CLCAL} will apply the solutions twice!  You will almost never want to
use these defaults for {\tt VLBI} data reduction.}
\pd

The parameter {\tt INTERPOL} allows the user to choose between several
different methods of phase interpolation.  Use {\us EXPLAIN CLCAL \CR}
to view all the options.  The default interpolation option is {\tt
INTERPOL = 'BOX'}, in which the {\tt SN} table is smoothed with a
boxcar function before being linearly interpolated onto the {\tt CL}
table.  The boxcar smoothing times for delay, rate etc.~are specified
in parameter \hbox{{\tt INTPARM}}.  However it is recommended that
{\tt SN} smoothing be done prior to {\tt \tndx{CLCAL}} using task
\hbox{{\tt \tndx{SNSMO}}}.

With good quality data, the {\tt 'AMBG'} option should work well.
Note, however, that this option uses the {\tt SN} solutions
immediately before and after a {\tt CL} entry to make the
interpolation and it uses any {\tt SN} solution found for any source
specified in \hbox{{\tt CALSOUR}}.  Therefore, if {\tt CALSOUR} is
left blank (allowing all sources) and delay and rate solutions were
significantly different for different sources, then inappropriate
solutions may be applied for a few minutes before or after a source
change.

One way of avoiding this problem is to run {\tt CLCAL} with {\tt
INTERPOL = 'AMBG'} several times, once for each source, setting both
{\tt SOURCE} and {\tt CALSOUR} to the name of the desired source with
all other inputs remaining unchanged.  Another way of avoiding the
problem is to use {\tt INTERPOL = '\hbox{SELF}'}.  In this option,
only solutions found on a given source are used to calibrate that
source and the single {\tt SN} table entry closest in time for that
source is used without any interpolation.  This is not as good as
doing multiple runs with the {\tt INTERPOL = 'AMBG'} option because
there can potentially be jumps in phase at points equidistant from two
{\tt SN} table entries.\Iodx{VLBI}

The {\tt INTERPOL = 'POLY'} option is useful if there are bad {\tt SN}
solutions remaining in the data.  This option fits a polynomial to the
rate solutions and then integrates this polynomial to determine the
phase corrections to be entered into the {\tt CL} table.
% finally
% if long solution times are being used option {\tt 'PREF'} (primarily
% designed for phase-referencing phase interpolation) might be
% useful. Details on all of these interpolation schemes can be
% found in the {\tt CLCAL} explain file.

\subsubsect{9.4.4.3. Continuum amplitude calibration}

The calibration information in the external text files such as $T_{\rm
sys}$ and gain curve measurement<s are read into {\tt TY} and {\tt GC}
tables using \hbox{{\tt \tndx{ANTAB}}}.  These tables are then used by
{\tt \tndx{APCAL}} to generate an amplitude solution ({\tt SN}) table,
allowing an optional solution for atmospheric opacity. The {\tt SN}
table may then be smoothed and applied using {\tt SNSMO} and {\tt
CLCAL} respectively (see \Sec 9.4.4.2).  The user is advised to read
the {\tt ANTAB} help file closely and check the syntax of the text
file carefully.

The INDEX keyword is used to assign the tabulated $T_{\rm sys}$ data to
individual \AIPS\ IF channels and polarizations. Up-to-date
information on the usage of the {\tt INDEX} keyword may be found by
typing {\tt EXPLAIN \hbox{ANTAB}}.  Be careful to match up the proper
polarization labels for the tabulated $T_{\rm sys}$ information. The
frequency and polarization association for each IF channel in the
\AIPS\ file can be compared (use {\tt LISTR} with {\tt OPTYPE =
'SCAN'}) with that at the head of the calibration text file.

The CONTROL group at the head of the calibration file is used only to
specify a default index mapping. If the IF channel orders in the
calibration file and the $uv$ file are identical it is not required.

The default {\it b}-factor and source flux densities are not specified in
the {\tt ANTAB} input file. If source flux densities are required by
{\tt APCAL}, the source ({\tt SU}) table will be searched, into which
flux densities can be inserted using {\tt SETJY} if necessary.
\Iodx{VLBI}

{\tt ANTAB} permits specification of IF-dependent and tabulated gains;
the format description may be found by typing {\tt EXPLAIN
\hbox{ANTAB}}.

{\tt ANTAB} can be run multiple times to append to the same {\tt TY}
and {\tt GC} tables. Also, calibration files from separate antennas
(\eg\ VLA) which have $T_{\rm sys}$ data tabulated in a different format
can be concatenated and processed in one run. In this case the INDEX
keyword must be specified for each antenna to fix the data
format.

Note that {\tt ANTAB} will (usually) ignore calibration data for which
there are no corresponding $uv$ data [see the help file for {\tt
ANTAB}].  There is one exception however: calibration data for an
antenna that does not appear in the {\tt AN} table will cause {\tt
ANTAB} to crash.  If {\tt ANTAB} crashes under such circumstances, you
have two choices.  You can edit the calibration text file, removing
all reference to the missing antennas; or you can use the input adverb
{\tt SPARM} to specify explicitly the names of antennas for which
there are calibration data, but which do not appear in the {\tt AN}
table.

*** The use of {\tt SPARM} is no substitute for careful inspection of
the calibration text files. ***

  Having created the input text file, typical inputs for {\tt
\Tndx{ANTAB}} would be:
\dispt{TASK\qs 'ANTAB' ; INP \CR}{to review the inputs.}
\dispt{INDISK {\it n} ; GETN\qs {\it ctn} \CR}{to specify the input
                  file.}
\dispt{INFILE\qs 'MYVLB:BC25CAL.VLBA' \CR}{to specify the text file.}
\dispt{SUBARRAY\qs 1 \CR}{select subarray one.}
\dispt{TYVER\qs 0 ; GCVER\qs 0 \CR}{create new {\tt TY} and {\tt GC} tables.}
\dispt{BLVER\qs 0 \CR}{create new {\tt BL} table for any specified baseline factors.}
\dispt{PRTLEV\qs 1 \CR}{select print level.}
\dispt{GO \CR}{to run the program.}
\dispe{{\tt PRTLEV=1} will echo the \indx{calibration} file
as it is processed, which can be useful in locating format errors.}

The {\tt TY} table can be examined using {\tt SNPLT} or {\tt LISTR}
with {\tt OPTYPE='TSYS'} or {\tt 'TANT'}, and the {\tt GC} table using
\hbox{{\tt PRTAB}}. Inspection of the {\tt TY} table may reveal
anomalously high system temperatures, indicating possible bad data
(\eg\ due to weather).  Note that flagging bad data will not change
the appearance of the {\tt TY} table since no flags are applied in
plotting this table.  {\tt \Tndx{APCAL}} can then be used to derive an
amplitude calibration ({\tt SN}) table. Typical inputs to {\tt APCAL}
are:
\dispt{TASK\qs 'APCAL' ; INP \CR}{to review the inputs.}
\dispt{INDISK {\it n} ; GETN\qs {\it ctn} \CR}{to specify the input
                  file.}
\dispt{ANTENNAS\qs 0 ; SUBARRAY\qs 0 \CR}{default
                  selection adverbs.}
\dispt{SOURCES\qs ' ' ; STOKES ' ' \CR}{}
\dispt{BIF\qs 1 ; EIF\qs 0 ; FREQID\qs 1 \CR}{}
\dispt{TIMERANG\qs 0 ; OPCODE\qs ' ' \CR}{no opacity solution required.}
\dispt{TYVER\qs 0 ; GCVER\qs 0 \CR}{use latest created {\tt TY} and {\tt GC} tables.}
\dispt{SNVER\qs 0 \CR}{create new {\tt SN} table.}
\dispt{GO \CR}{to run the program.}
\dispe{The resulting solution ({\tt SN}) table can be
smoothed/clipped using {\tt SNSMO} and applied using {\tt CLCAL} as
described in \Sec 9.4.4.2).\Todx{APCAL}\Iodx{VLBI}}

\subsubsect{9.4.4.4 Polarization calibration: parallactic angle
corrections}

For full \indx{polarization} experiments, the parallactic angle
contribution to the phase should be removed at the very start of the
phase \indx{calibration}.  The parallactic angle correction is made
using task {\tt \tndx{CLCOR}} [Note that {\tt CLCOR} directly modifies
the  specified version of the {\tt CL} table so that you may wish to
first make a backup copy of the {\tt CL} table using {\tt TACOP}:
\dispt{TASK\qs 'CLCOR' ; INP \CR}{to review the inputs.}
\dispt{INDISK {\it n1} ; GETN\qs {\it ctn} \CR}{to specify the input
               file.}
\dispt{OPCODE\qs  'PANG' \CR}{to select the parallactic angle
               correction.}
\dispt{CLCORPRM\qs  1,0 \CR}{to specify the sense of parallactic
               angle removal.}
\dispt{GAINVER\qs {\it clin} \CR}{{\tt CL} table to update, NO DEFAULT!}
\dispt{GO \CR}{to run the program.}
\dispe{This will directly modify the specified version of the {\tt CL} table.}
\pd

\subsubsect{9.4.5. Bandpass calibration}

Full \indx{bandpass} response calibration is usually only performed
for \indx{spectral-line} observations although it can be important for
certain types of continuum obsrvations.

A quick and dirty bandpass calibration can be carried out for most
types of continuum observations by throwing away the outer channels in
the data set since these are the most affected by the bandpass
response function.  The number of channels to throw away should be
determined by examining the bandpass effects on the total-power
spectra and carefully weighing the competing considerations of
signal-to-noise loss by tossing channels versus non-closing errors by
keeping channels.  This procedure of tossing channels may not be as
good as performing an actual bandpass, but it is simpler and easier to
carry out.

It is suggested that integrating over a variable bandpass function is
one of the most significant sources of non-closing errors in continuum
VLBI data. By calibrating the bandpass before averaging over
frequency, these effects can be avoided.  In VLBA test observations, a
dynamic range of 28,000:1 was achieved on the source DA193 (Briggs
{\it et al.} 1994, VLBA Memo No 697A, ``High Dynamic Range Imaging
with the VLBA'') after applying bandpass calibration.

Bandpass calibration is carried out using the task {\tt \tndx{BPASS}}
using either the auto- or cross-correlation data. The output is a {\tt
BP} or bandpass table.  The derived bandpass solutions can be plotted
using {\tt POSSM} by setting {\tt APARM(8)=2}.  The effect of applying
these bandpass solutions to your data can also be viewed using {\tt
POSSM} by setting {\tt DOBAND=1} and \hbox{{\tt BPVER}}.  An example
of the inputs to produce bandpass spectra from the auto-correlation
data would be:
\vfill\eject
\dispt{TASK\qs '\tndx{BPASS}' ; INP \CR}{to review the inputs.}
\dispt{INDISK\qs {\it n1} ; GETN\qs {\it ctn1} \CR}{to select the
          multi-source visibility data as the input file.}
\disptt{CALSOUR\qs 'BLLAC','DA193' \CR}{to specify the continuum
          source(s) which were observed for the purpose of
          \tndx{bandpass} calibration.}
\dispt{BCHAN\qs 0 ; ECHAN\qs 0 \CR}{to use the whole spectrum.}
\dispt{DOCALIB\qs -1 \CR}{to not apply any calibration.}
\disptt{SOLINT\qs 0 \CR}{to average data over whole scans before
          determining the bandpass.}
\dispt{SMOOTH\qs 1, 0, 0 \CR}{to Hanning-smooth the spectrum.}
\dispt{BPASSPRM\qs 1, 0 \CR}{to use the self-spectra.}
\dispt{GO \CR}{to run the program.}
\dispe{This will produce a {\tt BP} table containing the antenna-based
bandpass functions to be applied to the data.  Since only the
self-spectra were used, the phase response of the bandpasses is not
determined.  If you wish to correct for phase errors across the band,
then you must first fringe-fit the calibrator data (see below), then
set {\tt DOCALIB} to 1 and {\tt BPASSPRM(1)} to 0, and run the task.
However, you should check your results very carefully.  The {\tt BP}
tables can be plotted with {\tt POSSM} or printed with \hbox{{\tt
PRTAB}}.  Note that this procedure merely creates a {\tt BP} table.
To use this {\tt BP} table, set {\tt BPVER} and {\tt DOBAND} as
described in \Sec 4.7.3 when running any later \AIPS\ tasks.}

\subsubsect{9.4.6. Spectral-line doppler correction}

Normally, when observing, you will have kept the frequency constant
throughout the run for ease of observing and also because most modern
video-converters (BBCs) can only be set to a precision of 10 kHz.
Therefore, although your data will have the same frequency, the center
\indx{velocity} of your spectrum will change with time and the
\indx{spectral-line} signals will wander backwards and forwards
through the spectrum.  To ensure that the velocity is constant
throughout the data you should run {\tt SETJY} and then \hbox{{\tt
CVEL}}.\Iodx{VLBI}\iodx{calibration}

     {\tt \tndx{SETJY}} will insert the velocity information required
in the {\tt SU table}:
\dispt{TASK\qs 'SETJY' ; INP \CR}{to review the inputs.}
\dispt{INDISK\qs {\it n1} ; GETN\qs {\it ctn1} \CR}{to select the
          data.}
\dispt{SOURCE\qs 'OH127.8' , '\qs ' \CR}{to specify the line source
          whose velocity is to be specified.}
\dispt{OPTYPE\qs ' ' \CR}{to switch off flux modification.}
\dispt{SYSVEL\qs -66.0 \CR}{to specify the velocity of the ``center''
          of the band in km/s.}
\disptt{APARM\qs 65, 0 \CR}{to specify which spectral pixel is the
          ``center'' of the band, actually the pixel to which {\tt
          SYSVEL} refers.}
\dispt{RESTFREQ\qs 1612e6,231.09e3 \CR}{to give the rest-frequency in
          Hz, \eg\ that of the OH transition.}
\dispt{VELTYP\qs 'LSR' \CR}{to select the rest frame of the velocity.}
\disptt{VELDEF\qs 'OPTICAL' \CR}{to define velocities by the optical
          convention (which we recommend --- please don't ask why).}
\dispt{GO \CR}{to run the program.}
\pd

     Then run {\tt \tndx{CVEL}}:
\dispt{TASK\qs 'CVEL' ; INP \CR}{to review the inputs.}
\dispt{INDISK\qs {\it n1} ; GETN\qs {\it ctn1} \CR}{to select the
          data.}
\dispt{OUTDISK 3 ; OUTCLASS 'CVEL' \CR}{to specify the output file.}
\disptt{SOURCE\qs 'OH127.8' , '\qs ' \CR}{to select the source(s) to
          be shifted, all others will be passed un-shifted.}
\dispt{DOBAND\qs 1 \CR}{to apply the bandpass correction ---
          important.}
\dispt{BPVER\qs 1 \CR}{to specify the version of {\tt BP} table to
          use.}
\dispt{GO \CR}{to run the program.}
\dispe{After applying the {\tt BP} table, {\tt \tndx{CVEL}} will not
copy it to the output file to protect you from applying it twice.
Although {\tt CVEL} allows you to select which sources are to be
shifted, the {\tt BP} table, if {\tt DOBAND} is set appropriately,
will be applied to all sources found.}

\subsubsect{9.4.7. Spectral-line amplitude calibration}

The calibration scheme suggested in \AIPS\ for spectral-line VLBI data
utilizes the total-power spectra method\footnote*{see Lecture 12 in
{\it VLBI, Techniques and Applications}, eds.~Felli and Spencer,
published by Reidel}, although the continuum method using \Tsys\
values (see \Sec 9.4.4.3) can also be used.  The first step is to
generate a so-called template spectrum.  This is a high quality
spectrum from the most sensitive antenna in the array that has been
corrected for the effects of the bandpass filter.  For example:
\dispt{TASK\qs '\tndx{SPLIT}' ; INP \CR}{to review the inputs.}
\dispt{INDISK {\it n} ; GETN\qs {\it ctn} \CR}{to specify the input
           file.}
\dispt{SOURCE\qs 'OH127.8', '\qs ' \CR}{to write the program source.}
\dispt{BCHAN\qs 0 ; ECHAN\qs 0 \CR}{to write all spectral channels.}
\dispt{DOCALIB\qs -1 \CR}{to avoid applying any calibration.}
\disptt{DOBAND\qs -1 \CR}{to skip the bandpass correction since the
           data will have been corrected already in \hbox{{\tt
           CVEL}}.}
\disptt{TIMERANG\qs 0 22 0 0 0 22 30 0 \CR}{to select the data from a
           range of times when the antenna elevation was high and the
           source spectrum of high quality.}
\dispt{APARM\qs 0, 0, 0, 0, 1 \CR}{to pass only self-spectra.}
\dispt{GO \CR}{to run the program.}
\pd

You should then run {\tt \tndx{ACFIT}} to do a least-squares fit of
the template total-power spectrum to the total-power spectra of all
other antennas and to write the resulting time-dependant amplitude
gain correction factors into an {\tt SN} table.
\Iodx{VLBI}\iodx{calibration}\iodx{spectral-line}
\dispt{TASK\qs 'ACFIT' ; INP \CR}{to review the inputs.}
\dispt{INDISK {\it n} ; GETN\qs {\it ctn} \CR}{to specify the input
          file.}
\dispt{IN2DISK {\it n} ; GET2N\qs {\it ctn} \CR}{to specify the
          template file.}
\dispt{CALSOUR\qs 'OH127.8 ' \CR}{to select the source to use for
          calibration.}
\dispt{DOCALIB\qs -1 \CR}{to avoid applying any previous calibration.}
\disptt{DOBAND\qs -1 \CR}{to skip the bandpass correction since it was
          done when {\tt CVEL} was run.}
\disptt{SOLINT\qs $n$ \CR}{to average the self-spectra over $n$
          minutes (\eg\ 10) before doing the least-squares fit.}
\dispt{REFANT\qs 1 \CR}{to select the desired reference antenna from
          the template file.}
\disptt{BCHAN\qs 50 ; ECHAN\qs 70 \CR}{to set the range of spectral
          channels over which the fit is performed.}
\disptt{APARM\qs 0, 0, 50, 0, 0.72 \CR}{program control: {\tt
          APARM(1)}  and {\tt APARM(2)} specify the orders of the
          polynomial spectral baseline to remove from the source and
          template spectra; {\tt APARM(3)} and {\tt APARM(4)} specify
          the sensitivity of the template antenna (in Jy/deg) in the
          first and second (if needed) polarizations; {\tt APARM(5)}
          and {\tt APARM(6)} specify the minimum and maximum relative
          antenna gains allowed, with defaults to allow all positive
          values; {\tt APARM(7)} specifies the maximum allowed gain
          error, with 0 meaning all; {\tt APARM(8)} specifies the
          print level, with 0 providing minimal information, 1
          providing useful information on the gains determined for
          each antenna and solution interval and 2 giving the gory
          details for each fit; {\tt APARM(9)} specifies that the fits
          are done after subtracting a spectral baseline (0) or
          without a baseline (1); and {\tt APARM(10)} controls whether
          baseline-subtracted spectra are written to an output file.}
\disptt{BPARM\qs 80, 120 \CR}{to set up to 5 pairs of start and stop
          channels to use in determining the baseline polynomial to be
          removed from the source spectra. The order of the
          polynomial is specified in {\tt APARM(1)}.}
\disptt{CPARM\qs 80, 120 \CR}{to set up to 5 pairs of start and stop
          channels to use in determining the baseline polynomial to be
          removed from the template spectra. The order of the
          polynomial is specified in {\tt APARM(2)}.}
\disptt{XPARM\qs 45.1, 48.0, 50.1, 49.5 \CR}{to specify \Tsys\ values
          in the first polarization for each IF for the template scan
          of the reference antenna. {\tt YPARM} provides an equivalent
          list for the data, if any, from a second polarization.}
\dispt{SNVER\qs 0 \CR}{to create a new {\tt SN} table into which the
          solutions are to be written.}
\dispt{GO \CR}{to run the program.}
\dispe{{\tt \tndx{ACFIT}} will generate an {\tt SN} table, which has
to be applied to the {\tt CL} table.}

If needed, run {\tt \tndx{SNSMO}} to smooth the amplitude correction
factors determined by {\tt ACFIT} before running \hbox{{\tt CLCAL}}.
A 30 minute smoothing interval for {\tt SNSMO} (set using {\tt CPARM
0.5,0}) should be sufficient.
\Iodx{VLBI}\iodx{calibration}\iodx{spectral-line}

\subsubsect{9.4.8. Phase calibration }

After carrying out amplitude calibration, the remaining calibration
steps are involved with calibrating the phase of the data within and
between the separate IF channels and between the different integration
periods to the integrate the data over both frequency and time without
loss of coherence.  Such phase offsets may be corrected using {\it a
priori\/} `phase-cal' measurements if available and/or by directly
fitting to the data.

For data from the VLBA correlator, phase-cal measurements for the VLBA
antennas and a few others are currently delivered via a {\tt .PCAL}
file that can be extracted from the {\tt .CAL} file using {\tt VLOG}
(see \Sec 9.4.2) and then loaded using task {\tt PCLOD} into a {\tt
PC} table.  Task {\tt PCCOR} is then used to incorporate the
phase-cals into an {\tt SN} table. (see \Sec 9.4.8.2 ).

If phase-cal measurements are available only for some antennas, you
can run {\tt CLCAL} using the {\tt OPCODE='CALP'} option to
incorporate the incomplete {\tt SN} table information loaded by {\tt
PCLOD} without throwing away data for the other antennas.

For MkIII data from the BONN correlator, phase-cal measurements are
incorporated directly into the first {\tt CL} table produced by {\tt
MK3IN} --- this is a strong reason to protect the first {\tt CL}
table.

If external pulse-\indx{calibration} data are not available then
directly fringe-fitting a short scan of data to measure the phase and
single-band delay offsets may be applicable under limited
circumstances (see \Sec 9.4.8.2b).

Even after removing instrumental phase offsets from each IF, the data
will in general still contain frequency and time dependent phase
variations.  The purpose of ``fringe-fitting'' is to determine these
phase errors and then remove them from the data.

The primary {\it AIPS} task for \indx{fringe-fitting} is \hbox{{\tt
\Tndx{FRING}}}.  This task estimates time variable station-based
delays (phase derivatives wrt frequency) and rates (phase derivatives
wrt time) using a self-calibration-like algorithm.  Once these delays
and rates are determined, the task {\tt \tndx{CLCAL}} is used to
produce the phase correction that should be applied to each
integration period and spectral channel to correct for delay
and rate effects.  This use of {\tt FRING} and \hbox{{\tt CLCAL}} is
discussed in detail in \Sec 9.4.8.3 .  An alternative to {\tt FRING}
is to use the tasks {\tt BLING} and {\tt BLAPP}; these are discussed
briefly in \Sec 9.4.8.4 .

*** The process of fringe-fitting, and then interpolating the solutions
using {\tt CLCAL}, can be a very time consuming process.  Although it
depends a lot on the size and structure of the data set, the
fringe-fitting time can equal or exceed the observing time for a large
data set.  For this reason it is probably wise to run through the
fringe-fitting procedure described in \Sec 9.4.8.3 on a small amount
of data first (say 30 minutes' worth) before attempting to process the
whole data set.  This is especially true if this is your first time
processing multi-IF, multi-channel VLBI data.  It is probably simplest
to use {\tt UVCOP} to copy out a short time range of data from your
main file and to work only on this initially.  Doing so also avoids the
possible confusion of having many versions of extension tables. ***

\subsubsect{9.4.8.1 Special considerations}

\subsubsect{SVLBI}

Task {\tt PCCOR} may require specialized modification for
\indx{SVLBI}; this question will be resolved once real data become
available.

Fringe-fitting of SVLBI data is expected to be difficult due to short
coherence times, low signal-to-noise ratios and high residual delay
and rate errors. The existing fringe-fitting tasks within \AIPS\ have
been enhanced to improve their performance when dealing with SVLBI
data. In addition, several new tasks have been written to address
several problems specific to SVLBI fringe-fitting.  The primary SVLBI
fringe-fitting tasks in \AIPS\ are {\tt BLING}, {\tt GPHAS}, and {\tt
FRING} and are discussed in \Secs 9.4.8.3-5.  The tasks {\tt COHER}
and {\tt FRPLT}, described in \Secs 9.3.6-7, may be of particular
interest when reducing SVLBI data.

There are several general assumptions made in this section relating to
delay discontinuities in the recorded data. As mentioned in \Secs
9.2.1.2 the data from separate tracking stations are expected to have
separate antenna numbers at this point. Amongst other things, this
prevents fringe-fitting tasks from attempting solutions across
tracking scan boundaries. In addition, it is also expected that
periods during which coherence is lost at the tracking stations will
be reflected in the monitor or log data based upon which flagging is
performed as described in \Sec 9.4.3 . Finally, correlator jobs are
expected to be split at known delay discontinuities at the tracking
stations. If these assumptions prove inadequate in practice, there are
secondary sources of information regarding discontinuities that are
included in the design that will have to be used, perhaps including
direct use of the delta-T tables to set scan boundaries.

A new task is being developed {\tt \tndx{OBEDT}} which allows
selection of specific orbital parameter ranges, through the creation
of an output flag ({\tt FG}) table. This can be used to constrain
initial fringe searching.\Iodx{VLBI}

\subsubsect{Spectral-line}

Delay and fringe-rate calibration of \indx{spectral-line} \Indx{VLBI}
data must be handled differently.  The residual delay cannot be
estimated from the source itself because, due to the very nature of
the source, the delay is a rapidly varying function of frequency.  The
continuum calibrator, observed for this purpose, is first used to
determine residual delays and fringe-rates which are then applied to
the spectral-line source.  A suitable channel or range of
spectral-line channels ``on-source'' is then used to determine the
residual fringe-rates.  It is very important to note that in some
situations, the residual fringe-rates determined from the calibrator
may not be applicable to the line source because the fringe-rate
residuals towards the two sources may be quite distinct.  In such
situations, the residual fringe-rates determined from the continuum
source should not be applied to the line source.  See \Sec 9.4.8.6 for
more details.  It is not clear that VSOP will observe a continuum
calibrator.

\subsubsect{Polarization}

In addition to phase calibrating the LL and RR data separately, for
\indx{polarization} data the R-L phase and delay offsets must also be
determined.  This is outlined in \Sec 9.4.8.7.  After fringe-fitting
all parallel-hand fringe solutions need to be re-referenced to the
same antenna.

\subsubsect{9.4.8.2. Instrumental phase corrections}

If you run {\tt \tndx{POSSM}} on a short ($\approx 1$ minute) section
of data on a strong calibrator using the inputs described in
\Sec 9.2.5 and set {\us DOCAL = -1 \CR}, you will see that each
individual IF channel has its own independent phase offset and its own
phase gradient against frequency.  These phase offsets and
instrumental ``single-band delays'' are caused by passage of the
signal through the electronics of the VLBA baseband converters (or
MkIII/MkIV video converter units).  The VLBA and MkIII systems can
inject narrow band signals (``phase-cals'') into the data recorded at
each antenna from which the IF channel phase offsets, and possibly the
instrumental single-band delays, can be determined.

Data produced by a MkIII correlator are provided with the phase
offsets in version 1 of the {\tt CL} table (see \Sec 9.2.2).  To check
whether your data from a MkIII correlator contains phase-cal data, use
{\tt SNPLT} on {\tt CL} table version 1 to plot the phases.  If the
values are non-zero, phase-cal data are present.

At some point the VLBA correlator will write the phase-cal information
directly to a {\tt PC} table.  However, at present (September 1997), the
phase-cal information is only available through a text file and is
read into the {\tt PC} table using the task \hbox{{\tt
\tndx{PCLOD}}}. Type {\tt EXPLAIN PCLOD} for further information.

Pulse-calibration data in a {\tt PC} table can be used by task {\tt
\tndx{PCCOR}} to generate a {\tt SN} table which corrects for the
single-band instrumental phase and delay offsets [note that {\tt
PCCOR} uses two pulse-cal's in each IF].  A short calibrator scan must
be specified which is used by {\tt \tndx{PCCOR}} to resolve any $2\pi$
phase ambiguities in the pulse-\indx{calibration} data.  The specified
time range must include at least one {\tt PC} table entry for each
antenna appearing in the {\tt PC} table.  Typical inputs to {\tt
PCCOR} are:
\dispt{TASK\qs 'PCCOR' ; INP \CR}{to review the inputs.}
\dispt{INDISK {\it n} ; GETN\qs {\it ctn} \CR}{to specify the input
             file.}
\dispt{TIMERANG\qs 1 2 15 0 1 2 20 0 \CR}{short scan on a calibrator.}
\dispt{SNVER\qs 0 \CR}{to create a new {\tt SN} table.}
\dispt{INVER\qs 1 \CR}{input {\tt PC} table version.}
\dispt{REFANT\qs 5 \CR}{specify reference antenna.}
\dispt{SUBARRAY\qs 1 ; FREQID\qs 1 \CR}{set subarray and freqid.}
\dispt{CALSOUR\qs '3C345',' ' \CR}{set calibrator source name.}
\dispt{GO \CR}{to run the program.}
\pd\todx{PCCOR}

The resulting solution table is applied using \hbox{{\tt CLCAL}}.  If
you are missing phase-cal information for some antennas, you must use
the {\tt 'CALP'} mode of {\tt \tndx{CLCAL}}; this mode allows
calibration information for some antennas to be incorporated into the
{\tt CL} table while passing other antennas through without
modification.  Examine the corrected data using {\tt \tndx{POSSM}} to
determine if the instrumental phase and delay offsets between the IF
channels have been removed correctly.\Iodx{VLBI}

%     If you are unsure whether your VLBI data has phase-cal
%information, use {\tt IMHEAD} to list the extension tables and look
%for a {\tt PC} extension.  Task {\tt PC2SN} can be used to read this
%{\tt PC} table and enter phase offsets and (where available)
%single-band delays into an {\tt SN} table.

To check that the applied phase-cals are valid, run {\tt POSSM} on a
short section of data containing a strong source setting {\tt DOCAL =
1}, {\tt GAINUSE} to the version number of the {\tt CL} table
containing the phase-cal \indx{calibration}, and {\tt APARM(9) = 1} to
place all IFs on the same plot.  The phase as a function of frequency
on each baseline should be smoothly varying, with no sharp jumps
between different IF channels.  There may be an overall gradient
between channels and small gradients within each channel (which should
be approximately the same from IF channel to IF channel, but not
necessarily the same as the gradient between channels).  Unless these
conditions hold for all baselines, you should proceed to \Sec 9.4.8.2b.

%If you are missing or have inadequate pulse-cal information, as is
%currently the case for many antennas, including the VSOP tracking
%stations, you will need to determine manual phase-cal corrections as
%is described in \Sec 9.4.8.2b.

\subsubsect{9.4.8.2b `Manual' instrumental phase corrections}

     If your file does not have phase-cal information, or if these
phase-cals do not successfully remove frequency phase offsets, you can
use observations of a bright calibrator source and the task {\tt
FRING} to correct for these effects.  If you attempted phase-cal
calibration, it is best to avoid possible confusion by first deleting
any partial or erroneous phase-cal information that already exists.
Using {\tt \tndx{CLCOR}}:
\dispt{TASK\qs 'CLCOR' ; INP \CR}{to review the inputs.}
\dispt{INDISK\qs {\it n} ; GETN {\it ctn} \CR}{to specify the input
              file.}
\dispt{GAINVER\qs {\it clin} \CR}{to specify which {\tt CL} table to
              modify.}
\dispt{OPCODE\qs 'PCAL' ; CLCORPRM 0 \CR}{to set phase-cals to zero.}
\dispt{INP \CR}{to check the inputs.}
\dispt{GO \CR}{to run the task.}
\dispe{If you have large known delay offsets, as may be common for
VSOP data, you may also wish to run {\tt CLCOR} using {\tt
OPCODE='SBDL'} to shift the center of the fringe search window.}

Now you can determine the phase offsets/single band delays by running
{\tt \tndx{FRING}} on a short section of calibrator data where all or
most of the antennas are present.  Suitable inputs for {\tt FRING} for
this purpose are shown below; for more details of some of the {\tt
FRING} input parameters see \Sec 9.4.8.3.  Note that it is simplest to
choose a single short section of data using {\tt TIMERANGE} and to set
{\tt SOLINT} equal to this interval so that a single solution is
achieved.  The interval chosen must be less than than an atmospheric
coherence time, but long enough that high signal-to-noise is
achieved. At centimeter wavelengths with Jansky-level calibrators,
solution intervals of a few minutes will work well.  For example:
\iodx{fringe-fitting}
\dispt{TASK\qs 'FRING' ; INP \CR}{to review the inputs.}
\dispt{INDISK\qs {\it n} ; GETN {\it ctn} \CR}{to specify the input
                 file.}
\dispt{CALSOUR\qs '0954+658 ' \CR}{to select a strong calibrator
                source.}
\dispt{TIMERANGE\qs 0,16,0,0,0,16,2,0 \CR} {to select a single short
                scan.}
\dispt{DOCALIB\qs 1 ; GAINUSE\qs 2\CR}{to apply the amplitude
                calibration from {\tt CL} table 2.}
\dispt{FLAGVER\qs 0 \CR}{to apply most recent flag table.}
\dispt{SMODEL\qs 0 \CR}{to use the null (point-source at the origin)
                source model.}
\disptt{REFANT\qs 1 \CR}{to specify a reference antenna that will give
		fringes to most other antennas.}
\disptt{SOLINT\qs 2 \CR}{to set the solution interval in minutes; do
                not exceed the atmospheric coherence time.}
\dispt{APARM 0; DPARM 0\CR}{to initialize {\tt FRING} options to
               defaults.}
\dispt{APARM(1)=2\CR}{to require at least 2 antennas.}
\dispt{APARM(6)=1\CR}{to solve for the rate, single-band delay and
               phase of each IF separately.}
\dispt{DPARM(1)=1\CR}{use only 1 baseline in the initial
                (coarse) fringe search.}
\dispt{DPARM(8)=1\CR}{to zero the fringe rates before writing the {\tt
                SN} table.}
\dispt{SNVER\qs 0 \CR}{to create a new {\tt SN} table.}
\disptt{ANTWT\qs 0 \CR}{to apply no additional weights to the antennas
                before doing the solutions.}
\dispt{INP \CR}{to check the inputs.}
\dispt{GO \CR}{to do the fit.}
\dispe{If there were no single scan where all the antennas were
present, you can run {\tt \tndx{FRING}} again for another scan setting
{\tt REFANT} to be one of the antennas found in the first run and {\tt
ANTENNAS} to this antenna plus all of the antennas {\it not} found in
the first run.  {\tt FRING} will generate a new {\tt SN} table each
time; be careful to keep track of which {\tt SN} tables you wish to
use.\Iodx{VLBI}}

The phase solutions in the {\tt SN} table(s) are interpolated onto a
\indx{calibration} or {\tt CL} table using task \hbox{{\tt
\tndx{CLCAL}}} as described in \Sec 9.4.4.2.  Be sure to set {\tt
CALSOUR} to the calibrator source used when running {\tt FRING} (in
the example above, {\tt CALSOUR \ '0954+658'''}) and to set {\tt
SOURCE = ''} --- this is how the calibrator solutions are applied to
the other sources in the data set.  Also, set {\tt REFANT} to whatever
was used when running \hbox{{\tt FRING}}.  If multiple runs of {\tt
FRING} were required, you can set {\tt SNVER=0} so that all {\tt SN}
tables are combined before being applied (you must first be careful to
delete all {\tt SN} tables except those generated by {\tt FRING} if
you do this).  Or you can run {\tt CLCAL} multiple times specifying
each {\tt SN} table in turn while keeping the same {\tt CL} table
versions.

     To check the output {\tt CL} table, run {\tt POSSM} for the scan
used for the {\tt FRING} solution with {\tt DOCAL = 1} and {\tt
GAINUSE = 3} (\ie\ the output {\tt CL} table from the {\tt CLCAL}
above).  The phase should be flat as a function of frequency on all
baselines.   It is also useful to run {\tt POSSM} on another scan
containing a strong calibrator to check that the assumption
of constant IF phase offset holds.

\subsubsect{9.4.8.3.  Antenna-based fringe-fitting}

To see an example of the residual phase errors in your data, use
{\tt \tndx{POSSM}} to view the phase on a short calibrator scan (at
some time other than that used to solve for the phase-offsets in \Sec
9.4.8.2b).  In general, there will be a gradient in phase between the
IFs (due to the ``multi-band'' delay) and also small gradients within
each IF (caused by small residual ``single-band'' delays).  These
time-variable phase gradients are mainly due to inaccuracies in the
geometrical time delays that the correlator assumed for the time of
arrival of the wavefront at each antenna.  These inaccuracies arise
from propagation effects through the troposphere and ionosphere,
inaccurate Earth geometry,  etc.~and give {\it phase} errors which are
proportional to frequency.  Such phase errors prevent integration of
the data over frequency (or cause a loss of coherence if you do).
Similarly, {\tt \tndx{VPLOT}} will show, on any single IF and spectral
channel, phases which change rapidly with {\it time}.   Again, these
are due to unavoidable inaccuracies in the correlator model; such
large ``phase rates'' prevent integration over time.  Both of these
plots are illustrated on the next page.\iodx{fringe-fitting}
\eject

\if T\doFIG
   \centerline{\psfig{figure=FIG/COOK9A.PLT,height=3.8in}\hss
      \psfig{figure=FIG/COOK9B.PLT,height=3.8in}}
\else
   \vbox to 3.8in{\vfill\omit\vfill}
\fi

{\Smpoint
\noindent {\it left:\/} A {\tt \tndx{POSSM}} plot of the 43-GHz
spectrum of the quasar NRAO150 on the Los Alamos to Kitt Peak
baseline. The plot shows that the observation was performed with 4
IFs, with 256 spectral channels within each \hbox{IF}.  The upper
frame shows the phase variation with frequency; within each IF, the
small phase slope is caused by a residual delay error.  The phase
offsets between the IFs can be clearly seen as well.  Both the
residual delay error and the phase offsets must be determined and
removed before the data can be spectrally averaged (see \Sec 9.4.8).

\noindent {\it right:\/} A {\tt \tndx{VPLOT}} plot of the amplitude
(upper frame) and phase (lower frame) as a function of time for the
source NRAO150 at 43 GHz on the baseline Kitt Peak to Mauna Kea. Note
how the phase varies as a function of time; this variation is
equivalent to a residual fringe rate of 8.3 mHz.  Unless the fringe
rate is determined and removed (see \Sec 9.4.8), the data cannot
be averaged in time.}

\centerline{\vbox{\hrule height 0.25pt width 3.0in}}
\vskip 10pt

\Iodx{VLBI}\iodx{calibration}\iodx{fringe-fitting}

You will want to run {\tt FRING} to correct for these residual rates.
{\tt FRING} uses a global fringe-fitting algorithm described by Schwab
and Cotton, 1983, {\it Astron. J.}, {\bf 88}, 688.  Suitable inputs
for the fringe-fitting task {\tt FRING} are:
\dispt{TASK\qs 'FRING' ; INP \CR}{to review the inputs.}
\dispt{INDISK\qs {\it n} ; GETN {\it ctn} \CR}{to specify the input file.}
\dispt{CALSOUR\qs ' ' \CR}{to find solutions for all sources.}
\dispt{TIMER\qs 0 \CR}{to find solutions for all times.}
\disptt{DOCALIB\qs 1 \CR}{to apply the most complete calibration file
        including amplitude calibration and IF and channel phase
        offsets.}
\disptt{GAINUSE\qs 3 \CR}{to use {\tt CL} table 3.}
\dispt{SNVER\qs 2 \CR}{to write solutions into {\tt SN} table 2.}
\disptt{BCHAN\qs 0; ECHAN\qs 0 \CR}{to use all spectral channels
        within each IF channel.}
\dispt{SMODEL\qs 0 \CR}{to use a point-source at the origin model for
        the sources.}
\dispt{CLR2NAME\qs \CR}{to not use a Clean-component model.}
\dispt{FLAGVER\qs 0 \CR}{to apply the most recent flag table.}
\disptt{REFANT\qs 1 \CR}{to choose an antenna that will give fringes
        for most of the scans.  This is important: {\tt \Tndx{FRING}}
        will \Iodx{VLBI}\iodx{calibration}\iodx{fringe-fitting} search
        for fringes to this antenna first.  If it fails for some
        reason, it will select another reference antenna, based on the
        {\tt ANTWT} data, and, if it still fails, give up [see however
        the discussion of the new {\tt SEARCH} adverb below].  In this
        case, you should look for scans with no fringes or a bad
        reference antenna may be causing the problem.  A big,
        sensitive antenna is often used as {\tt REFANT} (\eg\
        Effelsberg).  Occasionally, it may be helpful to split your
        data set up into 2 or 3 sections, which are fringe-fitted with
        different {\tt REFANT} (\eg\ a ``European'' and a ``US'' part
        of the observations).  Changes in reference antenna should, in
        general, not cause problems.}
\disptt{SEARCH\qs {\it ref2}, {\it ref3}, ...\CR}{if {\tt APARM(9)} is
        set, the antennas specified via {\tt SEARCH} augment the
        antenna specified via {\tt REFANT} allowing {\tt FRING} to
        search for fringes more exhaustively (see the {\tt HELP} file
        under {\tt APARM(9)}).  The use of {\tt APARM(9)} and {\tt
        SEARCH} makes {\tt FRING} much more likely to find fringes to
        weak antennas and is highly recommended.}
\disptt{ANTWT\qs 0 \CR}{to apply no additional weights to the antennas
        before doing the solutions.  If the amplitude calibration was
        incorrect, you can use this option to force antenna weights up
        or down to control the weight {\tt FRING} gives to data to
        each station when making the global solutions.  Unlesss the
        {\tt SEARCH} option described above is chosen, {\tt ANTWT}
        also controls the order in which antennas are tried as
        secondary reference antennas after failing to find fringes on
        the \hbox{{\tt REFANT}}.  Give higher weight to antennas you
        want to see used as secondary references.}
\disptt{SOLINT\qs 3 \CR}{to set the solution interval in minutes; do
        not exceed the atmospheric coherence time (see below).
        Setting {\tt SOLINT} to 0 sets solution intervals equal to
        scan lengths.}
\disptt{APARM(1)\qs 2 \CR}{to accept solutions when only 2 antennas are
        present; default is 6.}
\disptt{APARM(2)\qs 0 \CR}{to have the data divided by the model before
        fitting fringes; {\tt APARM(2)} $> 0$ tells {\tt FRING} that
        the data have already been divided by a model.}
\disptt{APARM(3)\qs 0 \CR}{to treat polarizations separately; {\tt
        APARM(3)} $> 0$ averages RR and LL.}
\dispt{APARM(4)\qs 0 \CR}{to not average frequencies within each IF
        before the solution.}
\disptt{APARM(6)\qs 1 \CR}{to get some useful, but limited, messages,
        including the SNR.}
\disptt{APARM(7)\qs 9 \CR}{to avoid false detections by setting a
        moderately high minimum for the SNR accepted.  You may wish to
        use a lower threshold (especially for SVLBI) although APARM(7)
        less than about 3 is probably not useful.}
\disptt{APARM(8)\qs 0 \CR}{to set the maximum number of antennas; used
        only if no {\tt AN} table is present.}
\disptt{APARM(9)\qs 1 \CR}{to enable the exhaustive search mode.}
\disptt{APARM(5)\qs 2 \CR}{to do separate least-squares fits for
        single- and multi-band delays.  {\tt APARM(5)} $\leq$ 0 means
        to solve separately for the rate, single band delay and phase
        of each \hbox{IF}.  $1.5>$ {\tt APARM(5)} $>0$ means to solve
        for one single rate and multi-band delay affecting all IFs.
        If, as here, $>1.5$, the task additionally solves for the
        difference between the multi-band delay and single-band delay,
        \ie\ it allows for a different gradient of phase versus
        frequency within an IF than between IFs.  Note, however, that
        unlike {\tt APARM(5)=0}, this option assumes that the
        single-band delay is the same in each IF; it therefore solves
        for a single value for the difference between multi-band and
        single-band delay effecting all IFs.  Normally users should
        use {\tt APARM(5)=2} for multi-IF data.}
\disptt{ANTENNAS\qs 0; DOFIT\qs 0\CR}{Only baselines between antennas
        listed in the {\tt ANTENNAS} adverb are used in the fringe
        search.  If any antennas are specified in {\tt DOFIT} however,
        a solution is made only for those antennas; all other selected
        antennas are assumed to be already calibrated and are passed
        through with no additional corrections.  See the {\tt HELP}
        file for {\tt FRING} under \hbox{{\tt DOFIT}}.  {\bf {\tt
        DOFIT} is only active if {\tt APARM(9)} is set.}\Todx{FRING}
        \Iodx{VLBI}\iodx{calibration}\iodx{fringe-fitting}}
\disptt{DPARM(1)\qs 1 \CR}{to use one baseline combination in the
        initial coarse (FFT) fringe search.  This provides a starting
        guess for the least-squares solution.  If you are searching
        for weak fringes you should consider using two and three
        baseline combinations in the search; this can improve
        sensitivity in the initial fringe search.  See Chapter 19 in
        {\it Synthesis Imaging in Radio Astronomy}, for an explanation
        of how this global multi-baseline searching works.  Note that
        if your source structure is complex and you have not divided
        the data by an accurate source model, then setting this
        parameter to one is safest.  FYI, {\tt DPARM(1)>1} is
        implemented for unequal integration times.}
\disptt{DPARM(2)\qs 0 \CR}{to set the full width of the delay window in
        nsec, centered around 0, to search; the default, chosen here,
        is to use the full Nyquist range defined by the frequency
        spacing.  A smaller search window can improve the detected SNR
        but can also result in lost data due to failed fringe
        searches. }
\disptt{DPARM(3)\qs 0 \CR}{to set the full width of the fringe-rate
        window in mHz, centered around 0; the default, chosen here, is
        to use the full Nyquist range defined by the integration time.
        A smaller search window can improve the detected SNR but can
        also result in lost data due to failed fringe searches.}
\disptt{DPARM(4)\qs 2 \CR}{to specify the correlator integration time
        in seconds; use {\tt DTSUM} to find the correct value.  For
        data from the VLBA correlator, {\tt DPARM(4)=0} will cause {\tt
        FRING} to determine the correct integration time by examining
        the data file directly.}
\disptt{DPARM(5)\qs 0 \CR}{to do both the coarse and the least squares
        solutions; set to 1 if you require only FFT solutions.}
\disptt{DPARM(6)\qs 1 \CR}{to keep, for single source files,
        frequencies separated in the output file; the default is to
        average frequencies within IFs. This parameter does not affect
        multi-source files.}
\disptt{DPARM(7)\qs 0 \CR}{to re-reference solutions to a common
        reference antenna;  when processing polarization data, set
        this to 1 to avoid the re-referencing.}
\disptt{DPARM(8)\qs 0\CR}{to disable the zero'ing options --- see
	the {\tt HELP} file.  {\bf WARNING, {\tt DPARM(8)$>0$} will
        discard parts of the final solution.  Be sure to use this
        option with extreme care}.}
\dispt{INP \CR}{to check the inputs.}
\dispt{GO \CR}{to do the fit --- finally.}
\dispe{Note that {\tt \Tndx{FRING}} finds solutions in two steps.
First approximate solutions are found in the FFT step using
combinations of one, two or three baselines (see {\tt DPARM(1)}
above).  Then, as long as {\tt DPARM(5) $<$ 1}, a least-squares
algorithm uses these approximate values as a starting point for
refining the solutions.}
\Iodx{VLBI}\iodx{calibration}\iodx{fringe-fitting}

Note that the {\tt \tndx{SOLINT}} interval should be selected with
consideration of the atmospheric coherence time, but must be long
enough that high ($>7$) signal-to-noise-ratio solutions are achieved.
For observations between 1.6 and 15 GHz, solution intervals of 3--6
minutes (and often longer) should be fine.  At other frequencies
shorter solution intervals may be required.  In these cases, consult
an expert or experiment with different length solution intervals on
short sections of data.  Note that solution intervals greater than the
scan length will never be used; the scan lengths are listed in the
{\tt NX} table and may be examined using \hbox{{\tt PRTAB}}.

If the source is complex, and especially if the visibility phase of
the source changes during {\tt SOLINT}, it is useful to divide the
data by a Clean model derived from previous observations or from an
earlier attempt at processing the data.  This Clean model can be
specified by filling in {\tt IN2NAME} {\it et al}.  Situations where
this is useful include observations of equal doubles (where there are
zeros in the amplitude and, hence, rapidly changing phases) or very
large sources (of order arc-seconds).  If you are using multi-baseline
searching (\ie\ {\tt DPARM(1) > 0}, then solutions may be more
sensitive to source structure and an input model may be useful if the
structure phases are larger than one radian on many baselines.

You should check the SNRs found by {\tt FRING} carefully; they are
printed if {\tt APARM(6) > 0}.  The SNRs estimated during the FFT
search are used to determine if the SNR of a solution is $\ge$ the
threshold set in {\tt APARM(7)}.  If they are not, then that solution
is flagged before being passed to the more accurate least-squares
routine.  Users should check that the SNRs found in the LSQ routine
match those expected.  If the detected SNRs are too low, {\tt SOLINT}
may be too long or other parameters may be set wrongly.

Be warned that proper scaling of the SNRs by FRING depends upon
whether or not the data weights have been properly calibrated.  Task
{\tt FIXWT} may be used to calibrate the weights, but changing the SNR
threshold for {\tt FRING} directly ({\tt APARM(7)}) usually produces
satisfactory results.

The final delay and rate solutions and their SNRs should be inspected
using \hbox{{\tt \tndx{LISTR}}}:
\dispt{TASK\qs 'LISTR' ; INP \CR}{to review the inputs.}
\dispt{INDISK {\it n} ; GETN\qs {\it ctn} \CR}{to specify the input
          file.}
\dispt{OPTYPE\qs 'GAIN' \CR}{to list gain solutions.}
\dispt{INEXT\qs 'SN' ; INVER\qs 2 \CR}{to list {\tt SN} table 2 (as
          above).}
\dispt{DPARM\qs 6, 0 \CR}{to list delay; use 7 for rate, 1 for phase,
          and 8 for SNR.}
\dispt{GO \CR}{to run the program.}
\vfill\eject
\dispe{Alternatively, the solutions can be plotted against time to
make sure they are sensible.  Use {\tt SNPLT}:}
\dispt{TASK\qs '\tndx{SNPLT}' ; INP \CR}{to review the inputs.}
\dispt{INDISK {\it n} ; GETN\qs {\it ctn} \CR}{to specify the input
          file.}
\disptt{OPTYPE\qs 'RATE' \CR}{to plot rate solutions, {\tt OPTYPE
          'DELA'} for delay solutions.}
\dispt{NCOUNT\qs 5 \CR}{to plot five antennas per page.}
\dispt{INEXT\qs 'SN' ; INVER\qs 2 \CR}{to plot {\tt SN} table 2 (as
          above).}
\dispt{GO \CR}{to run the program.}
\pd
\Iodx{VLBI}\iodx{calibration}\iodx{fringe-fitting}

It is a good idea to plot out the solutions for {\tt OPTYP 'RATE'},
{\tt 'DELA'} (single-band delay), and {\tt 'MDEL'} (multi-band delay)
as well as the associated {\tt 'SNR'}s.  They should be smoothly
varying functions.  Delays and rates should be found only within your
specified windows.  Check for suspicious detections at the limits of
the search windows --- for instance, they could be detections of side
lobes of the main fringe.  If you used windows smaller than Nyquist,
you may want to check your detections using bigger windows.  Gaps in
detections with time can occur if, \eg\ tapes were bad, antennas were
off source, the source visibility is in a minimum, or the reference
antenna choice was bad.  It pays to investigate such problems at this
point before proceeding.

Discrepant {\tt SN} solutions can be removed using the interactive
task {\tt \tndx{SNEDT}} or the non-interactive task \hbox{{\tt
\tndx{SNSMO}}}.  If, in the latter, the {\tt CPARM} values are set,
then the {\tt SN} solutions will be clipped if they differ from the
running mean by amounts which you can specify.  If the {\tt BPARM}
values are set, the solutions are then smoothed and clipped entries
can be replaced with mean values based on a boxcar- or
median-window-filter average.  See the explain file for details.
Although {\tt SNSMO} allows the option of modifying the input {\tt SN}
table, it is safest to have it create a new one.  If you have a lot of
discrepant {\tt SN} values, you should also consider using option {\tt
INTERPOL = 'POLY'} in task {\tt CLCAL} (see below).

If there isn't enough disk space to run {\tt \Tndx{FRING}} on all the
data at once (because of the large scratch file that {\tt FRING}
currently insists on creating), you can run {\tt FRING} multiple times
specifying time ranges and explicitly setting {\tt SNVER} to the same
{\tt SN} table.

If, for some reason, you set the parameters of {\tt FRING} or
{\tt SNSMO} wrongly and the resulting {\tt SN} table is unusable, it
is wise to avoid confusion by deleting it using {\tt EXTDEST} and
starting over again.

Once a valid {\tt SN} table has been produced, the next step is to
interpolate the solutions found onto the finer grid of entries in a
{\tt CL} table using the task \hbox{{\tt \tndx{CLCAL}}} with {\tt
INTERPOL = 'AMBG'} as described in \Sec 9.4.4.2.

Once a final {\tt CL} table is generated, its effect on the data can
be viewed using tasks {\tt \tndx{VPLOT}} and {\tt \tndx{POSSM}} by
setting {\tt DOCAL=1} and {\tt GAINUSE} to the version number of the
final {\tt CL} table; see \Sec 9.3.  Optionally, in {\tt VPLOT}, one
can average over spectral channels and/or IF channels before plotting.
Use {\tt VPLOT} to plot a time range covering a few {\tt FRING}
solution intervals on a strong source.  Phase variations should be
small with no jumps.  If this is not the case, check the inputs to
{\tt FRING} (especially {\tt SOLINT}) and \hbox{{\tt CLCAL}}.  A
comparison of before and after phases is shown in the plots on the
next page.

\subsubsect{9.4.8.4. Baseline-based fringe-fitting}

Baseline-based fringe-fitting, implemented in {\tt BLING} and {\tt
BLAPP}, is an alternative to using {\tt FRING} and {\tt CLCAL}
described above.  Whereas {\tt FRING} searches and solves for station
rates and delays globally, {\tt \Tndx{BLING}} makes independent fits
to each baseline for delays and rates, creating a {\tt BS} table of
baseline-based solutions.

In most cases, the global fringe-fitting described in \Sec 9.4.8.3
should be used since {\tt FRING} should be able to fringe-fit weaker
sources more reliably.  However, there are some instances in which
baseline-based fringe-fitting is to be preferred.  Amongst the
advantages of the baseline-based fringe-fitting are:
\eject

\if T\doFIG
   \centerline{\psfig{figure=FIG/COOK9C.PLT,height=4.0in}\hss
      \psfig{figure=FIG/COOK9D.PLT,height=4.0in}}
\else
   \vbox to 4.0in{\vfill\omit\vfill}
\fi

{\Smpoint
\noindent {\it left:\/} A {\tt \tndx{POSSM}} plot of the uncalibrated
spectrum of NRAO150 at 43 GHZ on the baseline Kitt Peak to Los Alamos.
The plot shows the spectrum for IF 1 to show the effects
of the residual delay error more clearly.  The phase slope as a
function of frequency is clear evidence for a small delay error in the
correlator model.
\Iodx{VLBI}\iodx{calibration}\iodx{fringe-fitting}

\noindent {\it right:\/} The same data as shown on the left, but
corrected for a delay error of -55 nanosec and a residual fringe-rate
of -2.0 milliHz.  Note how the phase as a function of frequency is now
flat and centered around zero degrees. These data can now be
averaged in frequency, if desired.
}

\centerline{\vbox{\hrule height 0.25pt width 4.0in}}

\hanstart {50pt}
\enumerate{1}{{\tt \Tndx{BLING}} may be more robust than {\tt FRING}
     even in the absence of an accurate source structure model.}

\enumerate{2}{Fringe solutions can be found for cross-polarized
     fringes without editing the \uv\ header.}

\enumerate{3}{As presently implemented, for a given number of IF and
     spectral channels, {\tt BLING} can  solve for longer scans than
     can \hbox{{\tt FRING}}.}

\enumerate{4}{{\tt BLING} has the option of adjustable, non-zero
     centered fringe-search windows, which can be controlled from an
     external file.  This option will be especially important in
     fringe-fitting Space VLBI data.}
\par\hanend

You may wish to leave the acceleration search in {\tt BLING} ({\tt
DPARM(7)} to {\tt DPARM(9)}) off. This is a special option for space
VLBI and will slow down {\tt BLING} considerably.

This section concerns the use of {\tt BLING} for baseline-based
fringe-fitting. Associated tasks include {\tt \tndx{BLAPP}}, which
interpolates {\tt BLING} solutions, and {\tt \tndx{BSPRT}}, which
prints solutions found by \hbox{{\tt BLING}}.

{\tt BLING} is distinguished from {\tt FRING} by the ability to
directly control the fringe search on each separate baseline, and by
the ability to solve for fringe acceleration if required. Separate
fringe windows in delay, rate and acceleration, and different solution
intervals can be set for each individual baseline. The fringe windows
may have non-zero offsets and can be specified using the input adverbs
or, more flexibly, by drawing up an external ASCII control file of
fringe-prediction windows and {\tt BLING} control parameters. The
latter option allows the specification of time-variable fringe-search
parameters across the observing file. The general algorithm follows
that described by Alef and Porcas, 1986, ({\it Astron. Astrophys.},
{\bf 168}, 365); {\tt BLING} also allows the stacking of data from
different baselines, as discussed by Schwab and Cotton, 1983, {\it
Astron. J.}, {\bf 88}, 688. In addition, model division is possible
before the fringe-fitting is performed and cross-polarized fringe
searches can also be conducted without editing the \uv\ header.  {\tt
BLING} writes the results to a {\tt BS} table. These baseline-based
solutions can be factorized into antenna-based corrections using the
separate task {\tt \tndx{BLAPP}}, and applied to the data.

Acceleration is solved for by conducting a coarse search in the
specified acceleration window. The results of this search are then
interpolated to estimate the final solution. Fringe acceleration
searches can considerably increase the amount of CPU time it takes to
run \hbox{{\tt \Tndx{BLING}}}.
\Iodx{VLBI}\iodx{calibration}\iodx{fringe-fitting}


Full details concerning {\tt BLING} input parameters can be found by
typing {\tt EXPLAIN \hbox{BLING}}. This includes information
concerning the format required for the external control file. Earlier
versions of {\tt BLING} are discussed in \AIPS\ Memo~89 (1994,
``Baseline-Oriented Fringe Searches in \AIPS'' by Chris Flatters).
Typical input parameters to {\tt BLING} are given below:
\dispt{TASK\qs 'BLING' ; INP \CR}{to review the inputs.}
\dispt{INDISK\qs{\it n} ; GETN\qs {\it ctn} \CR}{to specify the input
            file.}
\dispt{CALSOUR\qs 'DA193' \CR}{source selection.}
\dispt{STOKES\qs 'LL' \CR}{Stokes selection.}
\dispt{TIMERANG\qs 0, 10, 5, 0, 0, 11, 0, 0 \CR}{time range selection.}
\dispt{ANTENNAS\qs 3 ; BASELINE\qs 0 \CR}{select all baselines to
         antenna 3.}
\dispt{SUBARRAY\qs 1 \CR}{subarray selection.}
\dispt{FREQID\qs 1 ; BIF\qs 1 ; EIF\qs 0}{frequency selection.}
\dispt{BCHAN\qs 1 ; ECHAN\qs 0 \CR}{ }
\dispt{DOCAL\qs 1 ; GAINUSE\qs {\it clin} \CR}{apply amplitude
          calibration.}
\dispt{CLR2N ; NMAPS\qs 0 \CR}{no model division.}
\dispt{SOLINT\qs 0.5 \CR}{30-second fringe solution interval.}
\dispt{INFILE\qs ' ' \CR}{no external control file specified.}
\dispt{APARM(1)\qs 2 ; APARM(2)\qs 0\CR}{integration time; no model
           division.}
\dispt{APARM(3)\qs 0\CR}{no stacking.}
\dispt{APARM(4)\qs 0 ; APARM(5)\qs 0\CR}{set minimum acceptable SNR to
           5; accept coherence of 20\%}
\dispt{DPARM\qs 0 \CR}{default fringe windows; no acceleration search.}
\dispt{DOUVCOMP\qs 1 \CR}{use compressed scratch files.}
\dispt{BADDISK\qs 0}{scratch file selection.}
\dispt{GO \CR}{to run the program.}
\pd

Note that baseline-stacking ({\tt APARM(3)}) is not implemented for
data sets with unequal integration times. Also, note that the
fringe-rejection criteria are specified using {\tt APARM(4)} and {\tt
APARM(5)} and these are important parameters. The use of compressed
scratch files is recommended and is not believed to have a significant
impact on precision. Note also that {\tt APARM(2)} should be set and
that the source should be entered explicitly if model division is
required.

{\tt BLING} will execute with a summary line marking the start of each
baseline processed. The resulting {\tt BS} table can be examined using
task {\tt BSPRT}, with input parameters:
\dispt{TASK\qs '\tndx{BSPRT}' ; INP \CR}{to review the inputs.}
\dispt{INDISK\qs{\it n} ; GETN\qs {\it ctn} \CR}{to specify the input
         file.}
\dispt{INVERS\qs {\it bsin} \CR}{{\tt BS} table version number.}
\dispt{DOCRT\qs -1 \CR}{select output to an external file.}
\dispt{OUTPRINT\qs 'FITS:BSPRT.LIS' \CR}{output file name.}
\dispt{GO \CR}{to run the program.}
\dispe{For printing to the screen, select {\tt DOCRT=1}.}

The {\tt BS} table output includes the estimated fringe parameters and
their associated errors. Note that due to recent changes in FFT
interpolation the errors may be an overestimate at this time. The {\tt
BLING} solutions are interpolated and factorized into antenna-based
gain solutions using \hbox{{\tt BLAPP}}. This task either writes a
solution ({\tt SN}) table which can be applied using {\tt CLCAL}, or
allows a {\tt CL} table to be updated with the calibration information
directly. These options are selected using {\tt OPCODE='SOLV'} or {\tt
OPCODE='CAL'} respectively. {\tt BLAPP} can interpolate solutions with
unequal time sampling and includes the acceleration term in
interpolation if it is available. Typical inputs to {\tt \Tndx{BLAPP}}
are:
\dispt{TASK\qs 'BLAPP' ; INP \CR}{to review the inputs.}
\dispt{INDISK\qs{\it n} ; GETN\qs {\it ctn} \CR}{to specify the input
           file.}
\dispt{INVERS\qs {\it bsin} \CR}{input {\tt BS} table version number.}
\dispt{SOURCES\qs ' ' ; STOKES\qs 'LL' \CR}{source and Stokes
           selection.}
\dispt{FREQID\qs 1 \CR}{frequency id. selection}
\dispt{TIMERANG\qs 0 ; ANTENNAS 0 \CR}{time range and antenna
           selection.}
\dispt{SUBARRAY\qs 1 ; REFANT\qs 3 \CR}{subarray and reference antenna
       selection.}
\dispt{ANTWT\qs 0 \CR}{unit antenna weights.}
\dispt{OPCODE\qs 'SOLV' \CR}{solve for a {\tt SN} table.}
\dispt{GAINVER\qs {\tt clin} ; GAINUSE\qs {\tt clout} \CR}
      {specify {\tt CL} tables to read in and write out.}
\dispt{BADDISK\qs 0 \CR}{scratch file selection.}
\dispt{GO \CR}{to run the program.}
\dispe{The resulting solution ({\tt SN}) table can be plotted using
{\tt SNPLT} in the standard fashion. For {\tt OPCODE='CAL'} the input
and output {\tt CL} tables need to be specified using {\tt GAINVER}
and \hbox{{\tt GAINUSE}}. If an {\tt SN} table is generated it can be
smoothed or clipped using task {\tt SNSMO} and applied using {\tt
CLCAL} as described in \Sec 9.8.3.
\Iodx{VLBI}\iodx{calibration}\iodx{fringe-fitting}}

\subsubsect{9.4.8.5. SVLBI-specific techniques}

An alternative approach to direct fringe detection of each individual
baseline to the orbiting antenna is to first calibrate the ground
array using conventional fringe-fitting techniques, then coherently
combine all ground antennas to improve the fringe detection
sensitivity to the spacecraft.  This algorithm is implemented in the
new task \hbox{{\tt \Tndx{GPHAS}}}. This ``phasing-up'' of the
ground-array results in a single synthesized baseline to the
spacecraft that can be fringe-fit using either {\tt FRING} or
\hbox{{\tt BLING}}. The synthesized baseline can also be displayed and
edited in \AIPS\ using standard tasks.\Iodx{SVLBI}

The usefulness of this method may depend on the accuracy of the source
model as derived from the ground array imaging. This model correction
is applied before the data are combined in {\tt GPHAS} to form the
synthesized baseline to the spacecraft. The ground array calibration
and imaging can proceed by normal methods discussed elsewhere in the
Cookbook. In this initial phase, the data on baselines to the
spacecraft are excluded. We assume in what follows that this process
has been completed successfully, with a resulting image file and
\AIPS\ solution ({\tt SN}) table containing the ground array
calibration. This {\tt SN} table will lack any calibration information
for the spacecraft. Users are reminded that {\tt CLCAL} can merge
solution tables using {\tt OPCODE='MERG'}.

An important point to note is that the general \AIPS\ calibration
philosophy requires that each antenna, polarization and IF channel in
any given solution table have complete calibration information. If
calibration information is missing for one or more antennas, these
antennas will be flagged by gain in the output {\tt CL} table produced
by {\tt CLCAL} when the solution table is applied. A special mode in
{\tt CLCAL} has been introduced to allow incomplete calibration
information to be applied. In this mode, the {\tt CL} entries that
have no associated {\tt SN} table information are passed through to
the output {\tt CL} table unmodified. This mode is activated in {\tt
CLCAL} using {\tt OPCODE='CALP'}. This mode is identical to {\tt
OPCODE='CALI'},{\tt INTERPOL='SELF'} in all other respects, and the
other input adverbs have their customary meaning in this case. This
{\tt CLCAL} mode should be used in applying the ground-array {\tt SN}
table containing the calibration information. The resulting {\tt CL}
table will correctly calibrate the ground-array antennas but leave the
spacecraft uncalibrated. At this point it is possible to combine the
ground baselines using {\tt \Tndx{GPHAS}}:
\dispt{TASK\qs 'GPHAS' ; INP \CR}{to review the inputs.}
\dispt{INDISK\qs{\it n} ; GETN\qs {\it ctn} \CR}{to specify the input
         file.}
\dispt{IN2DISK\qs{\it n} ; GET2N\qs {\it ctn} \CR}{to specify the
         input image.}
\dispt{CMODEL\qs ' ' ; CMETHOD\qs ' ' \CR}{model division defaults.}
\dispt{SMODEL\qs 0 ; BCOMP\qs 0 ; NCOMP\qs 0 \CR}{}
\dispt{INVERS\qs 1 \CR}{input {\tt CC} table version number.}
\dispt{OUTDISK {\it n} \CR}{specify the output file.}
\dispt{OUTNAM\qs 'VSOP', OUTCLA\qs 'UV'}{}
\dispt{CALSOUR\qs 'DA193' \CR}{must be specified for model division.}
\dispt{STOKES\qs ' ' \CR}{Stokes selection}
\dispt{BCHAN\qs 1 ; ECHAN\qs 0 \CR}{default frequency selection.}
\dispt{BIF\qs 1 ; EIF\qs 0 \CR}{}
\dispt{DOCAL\qs 1 ; GAINUSE\qs {\it clin} \CR}{apply ground-array
              calibration.}
\dispt{ANTENNAS\qs 0 ; REFANT\qs 0 \CR}{select all antennas.}
\dispt{SOLINT\qs 0 \CR}{no averaging.}
\disptt{APARM\qs 11 1\CR}{to combine all baselines to antenna 11 and
              to reference output baseline to most commonly occuring
              reference antenna.}
\dispt{BADDISK\qs 0 \CR}{scratch file selection.}
\dispt{GO \CR}{to run the program.}
\dispe{Other standard selection and calibration adverbs are also
available. Type {\tt EXPLAIN GPHAS} for further details. The resulting
output file can be examined using standard tasks such as {\tt VPLOT}
and fringe-fit using {\tt FRING} or \hbox{{\tt BLING}}. The incremental
\indx{calibration} for the spacecraft can then be applied using similar
methods to those used to calibrate the ground array only, as discussed
above.\Iodx{SVLBI}}

\subsubsect{9.4.8.6. Spectral-line fringe-fitting}

The determination of the delay and fringe-rate \indx{calibration} is a
two or three-step process for \indx{spectral-line} \Indx{VLBI} data.
First, the residual delay and fringe-rates are estimated for each
antenna from the continuum calibrators.  Then, residual fringe-rates
must be determined again for the line source using a ``strong''
channel or range of channels.  As an intermediate step, the phases of
the line source should be examined to check that the calibrator's
residual fringe-rates haven't destroyed phase coherence; if so, then
the calibrator's residual fringe-rates should not be applied to the
line source.\iodx{fringe-fitting}

Because of limited computer memory, {\tt FRING} must trade off the
number of spectral channels against the length of the solution
interval.  For continuum calibrators in a spectral-line dataset, the
large number of spectral channels often forces {\tt FRING} to require
too short a solution interval.  This can be overcome be running {\tt
UVCOP} to extract the continuum calibrators into a separate data file
and then running {\tt AVSPC} with {\tt AVOPTION 'SUBS'} to average
spectral channels coherently within each \hbox{IF}. {\tt INDXR} should
be run to regenerate an {\tt NX} table. {\tt FRING} will then allow
more reasonable solution intervals.

Run {\tt FRING} as follows only on the continuum calibrators to
determine residual delays and fringe-rates:
\dispt{TASK\qs '\tndx{FRING}' ; INP \CR}{to review the inputs.}
\dispt{INDISK\qs {\it n} ; GETN {\it ctn} \CR}{to specify the input
            file.}
\dispt{CALSOUR\qs 'BLLAC','DA193' \CR}{to select continuum calibrator
            sources.}
\dispt{DOCALIB\qs 1 \CR}{to apply the current calibration.}
\dispt{GAINUSE\qs {\it clin}}{to specify which {\tt CL} table to use.}
\dispt{SMODEL\qs 0 \CR}{to use the null source model (points at the
            origin).}
\dispt{FLAGVER\qs 0 \CR}{to apply the most recent flag table.}
\disptt{BCHAN\qs 10 ; ECHAN\qs 115 \CR}{to exclude the edges of the
            band; normally the data in these channels are corrupted by
            the bandpass filters.}
\dispt{REFANT\qs 1 \CR}{to select a reference antenna (see continuum
            discussion).}
\disptt{SOLINT\qs 6 \CR}{to set the solution interval in minutes.  It
            should not exceed the coherence time.}
\dispt{APARM(6)\qs 1 \CR}{to get some useful, but limited, printout;
            gives SNR.}
\disptt{APARM(7)\qs 7 \CR}{to avoid false detections by setting the
            minimum SNR acceptable.  {\it Warning:\/} data with lower
            SNR will be flagged as bad.}
\disptt{DPARM(1)\qs 1 \CR}{to use one-baseline combination in initial,
            coarse fringe search (\hbox{FFT}).  This provides starting
            points for the least-squares solutions.}
\disptt{DPARM(2)\qs 10000 \CR}{to select a delay window in nsec,
            centered around 0(!). The default is to use the Nyquist
            range.  For a 250kHz-bandwidth observation, setting this
            value to 10000 nsec is equivalent to setting the search
            window to 5 delay channels, which is usually sufficient.}
\dispt{DPARM(3)\qs 200 \CR}{to select a fringe-rate window in mHz.}
\dispt{DPARM(4)=\qs 1 \CR}{to tell {\tt \tndx{FRING}} the correlator
            integration time.}
\dispt{DPARM(5)\qs 0 \CR}{to do the least-squares solution.}
\dispt{SNVER\qs 0 \CR}{to write solutions in a new {\tt SN} table.}
\dispt{GO \CR}{to do the fit.}
\Iodx{VLBI}\iodx{calibration}\iodx{spectral-line}\iodx{fringe-fitting}
\pd

If the calibrator had been extracted to a separate data set, use {\tt
TACOP} to copy the resultant {\tt SN} table back to the line data set.

Run {\tt \tndx{CLCAL}} to apply the delay and fringe-rate solutions to
all sources, as is described in \Sec 9.4.8.3, and then carefully
examine the phase coherence of the line source in a suitable line
channel (or group of channels) using {\tt \tndx{POSSM}} or {\tt
\tndx{COHER}} before and after applying the new {\tt CL} table.  It
may be that the fringe-rate solutions have worsened the phase
coherence.  In this case, you must run {\tt SNCOR} using the {\tt
'ZRAT'} option to zero the fringe-rates and then re-run \hbox{{\tt
CLCAL}}.

After this point, the calibrator data is usually of little or no
interest.  But, if you do plan to use the calibrator data further,
remember to be careful to juggle the {\tt SN} and {\tt CL} tables
correctly.  Even if you decide not to apply the calibrator
fringe-rates to the line-source, they are still applicable for the
calibrator itself.  The {\tt CL} table created using the un{\tt
'ZRAT'}-ed {\tt SN} table contains the proper corrections for the
calibrator data while the {\tt CL} table created using the {\tt
'ZRAT'}-ed {\tt SN} table contains the proper corrections for the the
line source.

Now re-run {\tt \Tndx{FRING}} to determine the residual fringe-rates
for the line source, this time selecting a suitable line channel or
group of channels:

\dispt{TASK\qs 'FRING' ; INP \CR}{to review the inputs.}
\dispt{INDISK\qs {\it n} ; GETN {\it ctn} \CR}{to specify the input
            file.}
\dispt{CALSOUR\qs 'OH127.8' , '\qs ' \CR}{to select the spectral-line
            source.}
\dispt{DOCALIB\qs 1 \CR}{to apply the previous amplitude and
            delay/rate calibration.}
\dispt{GAINUSE\qs {\it clin}}{to specify which  {\tt CL} table to use.}
\dispt{FLAGVER\qs 0 \CR}{to apply the most recent flag table.}
\dispt{SNVER\qs 0 \CR}{to write a new solution table.}
\disptt{BCHAN\qs 72 ; ECHAN\qs 72 \CR}{to select the strongest and/or
            simplest spectral channel as a reference.}
\disptt{REFANT\qs 1 \CR}{try to use the same reference antenna as in
            the previous run of \hbox{{\tt FRING}}.}
\disptt{SOLINT\qs 6 \CR}{to set the solution interval in minutes.  It
            should not exceed the coherence time.}
\dispt{APARM(6)\qs 1 \CR}{to get useful, but limited printout.}
\disptt{APARM(7)\qs 9 \CR}{to avoid false detections by setting the
             minimum SNR acceptable.  {\it Warning:\/} data with
             lower SNR will be flagged as bad.}
\disptt{DPARM(1)\qs 1 \CR}{to use one-baseline combination in initial,
             coarse fringe search (FFT).}
\disptt{DPARM(2)\qs = -1 \CR}{to prohibit a search in the delay domain
             by setting the delay window to a negative number.
             Remember setting this to 0 means to use the Nyquist
             value, which is not what we want.}
\disptt{DPARM(3)\qs 0 \CR}{to search for fringes over the full Nyquist
             fringe-rate window since we don't know where the fringes
             are.}
\disptt{DPARM(4)=\qs 0 \CR}{to let {\tt FRING} automatically determine
             the correlator integration time [if this fails, you will
             have to set the proper value here --- see {\tt DTSUM}].}
\dispt{DPARM(5)\qs 0 \CR}{to do the least-squares solution.}
\dispt{GO \CR}{to do the fit.}
\Iodx{VLBI}\iodx{calibration}\iodx{spectral-line}\iodx{fringe-fitting}
\pd

Then run {\tt \tndx{CLCAL}} again to apply these solutions to the
previous calibration tables. You have then generated a full set of
calibration tables and data.  Remember that the calibration
information for the continuum and line sources are stored in different
{\tt CL} tables.

\subsubsect{9.4.8.7. Polarization-specific fringe-fitting}

The phase and delay corrections obtained using RR and LL data can only
remove R-R and L-L offsets between different antennas.  There still
may be R-L phase and multi- and single-band delay offsets. The R-L
delay corrections can be determined using the RL and LR data and two
runfiles, {\tt CROSSPOL} and {\tt CRSFRING}, are available for
determining these effects.  This still leaves an overall R-L phase
offset.

Once the cross-hand calibration has been completed, the instrumental
\indx{polarization} (otherwise known as the feed D-terms), can be
determined. Several different methods are available for this purpose,
implemented in the tasks {\tt PCAL}, {\tt \tndx{LPCAL}} and
\hbox{{\tt \tndx{SPCAL}}}. The latter task is designed for
polarization \indx{calibration} of spectral-line datasets. {\tt PCAL}
is discussed briefly below and further details for each of these tasks
can be found in the appropriate {\tt EXPLAIN} files.

The determination of the absolute polarization position angle is
equivalent to the determination of the absolute R-L phase
difference. For an unresolved source this can be measured in much the
same way as for VLA data (see \Sec 4.6) using task {\tt LISTR} to
determine the cross-polarized phase on the polarization
calibrator. Alternatively, a source with known polarization properties
can be used, \eg\ 3C286 or 3C279.  For a resolved polarization
calibrator a sum of Clean components is required to compare to the
integrated polarization position angle as measured by the VLA or
single-dish observations nearby in time. Once the R-L phase correction
is known it is applied using task {\tt CLCOR} with {\tt OPCODE='POLR'}
(see \Sec 4.6).

After feed calibration and the determination of the absolute
polarization position angle, the final Stokes Q and U images can be
formed directly. Note that task {\tt PCNTR}, which is used for
displaying polarization images, allows an arbitrary rotation of all
polarization vectors under control of input adverb \hbox{{\tt ROTATE}}
(this is only necessary if {\tt CLCOR} wasn't used to correct the R-L
phase; also the polarization angle specified for {\tt PCNTR} is half
the R-L phase difference).

\subsubsect{9.4.8.7.1 R-L delay calibration}

{\tt \Tndx{CROSSPOL}} (see {\tt EXPLAIN CROSSPOL}) can determine
multi- and single-band R-L delay differences and produce an {\tt SN}
table which corrects for these effects.  It is best run on a set of
calibrator data for which the source is at least moderately polarized
(source \indx{polarization} dominates instrumental polarization).
Several baselines can be averaged but RL or LR fringes (or both) must
be detectable on each baseline to the reference antenna.  {\tt
OPCODE='AVIF'} will cause the single band R-L delays to be averaged.
This procedure should leave a single R-L phase difference that must be
determined from a calibrator of known polarization angle.  The {\tt
SN} table produced by {\tt CROSSPOL} should be applied to the {\tt CL}
table using \hbox{{\tt CLCAL}}.  The results can be checked using {\tt
POSSM} or \hbox{{\tt SHOUV}}.  The RL and LR phases should be
continuous across the bandpass on each baseline and be flat if the RR
and LL phases are flat (no residual delays).

\subsubsect{9.4.8.7.2 Feed D-term calibration}

The feed D-terms, or instrumental \indx{polarization} terms, can be
determined using \hbox{{\tt PCAL}}.  {\tt SOLTYPE}s {\tt 'ORI-'} and
{\tt 'RAPR'} are appropriate for \Indx{VLBI} data.  {\tt 'ORI-'} uses
a non-linear orientation-ellipticity feed model and is appropriate if
instrumental polarization exceeds a few percent (\eg\ EVN, or VLBA at
18 or 13 cm).  {\tt 'RAPR'} uses a linearized ``D-term'' model ---
this is faster but less accurate.

Typical inputs for {\tt \Tndx{PCAL}} would be:
\dispt{TASK\qs 'PCAL' ; INP \CR}{to review the inputs.}
\dispt{INDISK\qs {\it n} ; GETN {\it ctn} \CR}{to specify the input
            file.}
\dispt{CALSOUR\qs 'DA193' , '\qs ' \CR}{to select the source.}
\dispt{TIMERANG 0\CR}{to use all times.}
\dispt{SELBAND\qs 0; SELFREQ\qs 0; FREQID\qs -1\CR}{to select all frequencies.}
\dispt{BIF\qs 0; EIF\qs 0\CR}{to select all IFs.}
\dispt{ANTENNAS\qs 0; UVRANGE\qs 0 \CR}{to select all antennas and baselines.}
\dispt{SUBARRAY\qs 0\CR}{to select all subarrays.}
\dispt{FLAGVER\qs 0 \CR}{to apply the most recent flag table.}
\dispt{DOCALIB\qs 1 \CR}{to apply the previous amplitude and
            delay/rate calibration.}
\dispt{GAINUSE\qs {\it clin}}{to specify which {\tt CL} table to use.}
\dispt{IN2DISK\qs {\it n}; GET2N {\it ctn}\CR}{ to specify a clean map.}
\dispt{INVERS\qs 1\CR}{to select a CC table version.}
\disptt{REFANT\qs 1 \CR}{to use the same reference antenna as in
            the previous run of \hbox{{\tt CALIB}}.}
\disptt{NCOMP\qs 77; NMAPS\qs 1\CR}{to specify the number of clean components to use and to explicitly set the number of clean maps supplied.}
\disptt{SOLINT\qs 6 \CR}{to set the solution interval in minutes.  It
            should not exceed the coherence time.}
\dispt{SOLTYPE\qs 'RAPR'\CR}{specify the type of feed model.}
\dispt{PRTLEV\qs 0\CR}{to print minimal information}
\dispt{BPARM(1)\qs 0\CR}{use the initial feed model if found in the AN table.}
\dispt{BPARM(3)\qs 0\CR}{to not fit for R-L phase difference.}
\dispt{BPARM(4)\qs 0\CR}{to not specify the initial R-L phase.}
\dispt{BPARM(5)\qs 0\CR}{to not solve for Vpol.}
\disptt{BPARM(6)\qs 0; BPARM(7)\qs 0\CR}{to solve for the orientations
           of both polarizations of the reference antenna.}
\dispt{BPARM(8)\qs 0\CR}{to solve for all orientations.}
\dispt{BPARM(9)\qs 0\CR}{to solve for all ellipticities.}
\dispt{BPARM(10)\qs 0\CR}{to fit for the source polarization model
           parameters.}
\dispt{CPARM(1)\qs 0\CR}{to find separate solutions for each IF.}
\dispt{CPARM(8)\qs 0\CR}{to not limit the number of iterations.}
\dispt{CPARM(9)\qs 0\CR}{to use the default convergence tolerance.}
\dispt{CPARM(10)\qs 0\CR}{use default convergence criterion.}
\dispt{BADDISK 0 \CR}{to specify which disks to avoid for scratch.}
\dispt{GO \CR}{to run the program.}
\pd
\Iodx{VLBI}\iodx{calibration}\iodx{spectral-line}\iodx{fringe-fitting}
\Todx{PCAL}

The instrumental \indx{polarization} may vary rapidly with frequency
and independent solutions may be necessary in each \hbox{IF}.  Both
{\tt 'ORI-'} and {\tt 'RAPR'} model the source Q and U as scaled
versions of I which is generally only true in the limit of unresolved
or unpolarized sources.  The D-terms can be determined iteratively by
subtracting estimates of source polarization (Q,U clean components) in
\hbox{{\tt UVSUB}}.  Note: this should be done on data for which
instrumental polarization corrections have {\it not} been applied.

Tasks {\tt LPCAL} and {\tt SPCAL} also can be used to compute D-term
corrections for continuum and spectral-line polarization data
respectively.  Be forewarned that both of these tasks use linearized
D-term models.
\vfill\eject

\subsubsect{9.4.9. Baseline-based errors}

Baseline-based non-closing phase and amplitude errors can limit the
dynamic range of the final maps.  One way to proceed is to try to
solve directly for the non-closing effects using bright, point-like
calibrator observations and the task \hbox{{\tt \Tndx{BLCAL}}}.  This
task writes a {\tt BL} table containing the estimated non-closing
baseline-based errors which can later be applied in {\tt SPLIT}, or
any of the other calibration tasks.  To use {\tt BLCAL} the noise in
the calibrator-source images should approach the theoretical limit.
Furthermore, the signal-to-noise ratio in the visibility data must be
at least 100:1 on baseline-averaged data.  {\tt BLCAL} will divide
your data by your best model and then write a {\tt BL} table
containing the baseline-based corrections.  Use this task carefully
only after reading the {\tt EXPLAIN} file thoroughly.  As an example:
\dispt{TASK\qs 'BLCAL' ; INP \CR}{to review the inputs.}
\dispt{INDISK\qs {\it n1} ; GETN\qs {\it ctn1} \CR}{to select the
           multi-source visibility data as the input file.}
\dispt{IN2DISK\qs {\it n2} ; GET2N\qs {\it ctn2} \CR}{to select your
           best image as the input model file.}
\dispt{SOURCE\qs 'DA193' \CR}{to select your calibration source.}
\dispt{DOCALIB\qs 1 ; GAINUSE\qs {\it clin} \CR}{to select the
               {\tt CL} table to use.}
\dispt{BLVER\qs 1 \CR}{to create {\tt BL} table version 1.}
\disptt{SOLINT\qs 1440 \CR}{to determine one complex gain correction
           per baseline for the whole observation.}
\dispt{GO \CR}{to run the program.}
\pd
\Iodx{VLBI}\iodx{calibration}

\subsectt{9.5. After initial calibration}

\subsubsectt{9.5.1. Applying calibration}

Having obtained your best possible calibration {\tt CL} table (and
{\tt BP} and {\tt BL} tables if bandpass or baseline-dependent errors
were found), you finally get to make a calibrated data set.  This is
done with {\tt \tndx{SPLIT}}, which applies the calibration and splits
the database into separate files, one for each source observed.
\dispt{TASK\qs 'SPLIT' ; INP \CR}{to review the inputs.}
\dispt{INDISK {\it n} ; GETN\qs {\it ctn} \CR}{to specify the input
            file.}
\dispt{SOURCE\qs ' ' \CR}{to write  all sources.}
\dispt{DOCALIB\qs 1 ; GAINUSE\qs {\tt clin} \CR}{to specify
                 which {\tt CL} table to use.}
\dispt{DOBAND\qs 1; BPVER 1 \CR}{to apply {\tt BP} table 1 if present.}
\dispt{BLVER\qs {\it blin} \CR}{to apply {\tt BL} table 1 if present.}
\dispt{APARM(1)\qs 1 \CR}{to have all spectral channels within each IF
            averaged.}
\disptt{APARM(2)\qs 2 \CR}{to have an amplitude correction made for the
            correlator integration time (in seconds)}
\dispt{GO \CR}{to run the program.}
\dispe{The options for {\tt SPLIT} given above will apply calibration
and then average the spectral channels within each IF, but not average
IF channels together . To average over IF channels as well, set
{\tt APARM(1)=2} in {\tt SPLIT} or use task {\tt \tndx{AVSPC}}:}
\dispt{TASK\qs 'AVSPC' ; INP \CR}{to review the inputs.}
\dispt{INDISK {\it n} ; GETN\qs {\it ctn} \CR}{to specify the input
             file.}
\dispt{OUTDISK {\it n} ; OUTNAM\qs ' ', OUTCLA\qs ' '}{to specify the
             output file.}
\dispt{AVOPTION\qs 'AVIF' \CR}{to average over IFs.}
\dispt{BIF\qs 0 ; EIF\qs 0 \CR}{to select all IF channels}
\dispt{GO \CR}{to run the program.}
\todx{AVSPC}\pd

At this point, it is well worth spending time to examine your output
visibility data carefully.  You may plot the data against time with
{\tt VPLOT}, {\tt IBLED}, {\tt EDITR}, or {\tt UVPLT}, and list them
with {\tt LISTR}, {\tt PRTUV}, or \hbox{{\tt UVPRT}}.  {\tt POSSM} is
now no longer useful since you have averaged your data in frequency
space.\iodx{calibration}

\subsubsect{9.5.2. Time averaging}

It is now convenient to time average the data using {\tt \tndx{UVAVG}}
both to reduce the bulk of the data and to increase the
signal-to-noise for subsequent iterations of the
self-calibration/mapping cycle.  However, it is important to realize
that the fringe-fitting process to this point has only removed
gradients of phase over the fringe-fitting solution interval.  There
will still be stochastic atmospheric (and clock) phase errors
affecting the data on short time scales.  These phase errors can be
significant over minutes at frequencies of 22 GHz and above (and
possibly even at 15 GHz) and a reduction in amplitude can occur if
data are directly averaged.  Self-calibration should remove such phase
errors.

For data at frequencies below 15 GHz (and $\approx$\ minute
integrations), it should be safe to proceed with {\tt \tndx{UVAVG}}
(see below).  For higher frequency data, it may be worth your while to
examine the phase coherence of the data first.  {\tt \tndx{VPLOT}} can
be used to examine your target or calibrator data to see directly the
level of residual phase error over your chosen averaging time.
Alternatively, the task {\tt IBLED} allows you to view the degree of
coherence of data averaged over different averaging times.  If there
are coherence problems (and the target data has enough SNR),
{\tt \tndx{CALIB}} can be run to align the  phases prior to coherent
averaging. Try:\Iodx{VLBI}
\dispt{TASK\qs 'CALIB' ; INP \CR}{to review the inputs.}
\dispt{INDISK {\it n} ; GETN\qs {\it ctn} \CR}{to specify the
              single-source input file.}
\dispt{OUTNA\qs INNA ; OUTCL\qs 'ALIGN' \CR}{to specify the output
              file.}
\dispt{CALSOUR\qs ' ' ; SMODEL\qs 1, 0 \CR}{to use the source with a
              point-source model.}
\dispt{DOCALIB\qs -1 ; GAINUSE\qs 0 \CR}{to not apply any tables to
              the input data.}
\dispt{SOLTYPE\qs ' ' \CR}{to use normal least squares.}
\dispt{SOLMODE\qs 'P' \CR}{to solve for phase.}
\disptt{SOLINT\qs (10.0/60.0) \CR}{to solve for phase in 10-second
              intervals.  This should probably be set as low as the
              strength of the source will allow.  The limit is the
              integration time that gives a SNR $> 2$ on most
              baselines.}
\dispt{APARM(1)\qs 3 \CR}{to require 3 antennas present for solution.}
\dispt{APARM(6)\qs 0 \CR}{to skip diagnostic printout.}
\disptt{APARM(7)\qs 1 \CR}{to set the minimum allowed \hbox{SNR}.
              This limit should be low since the SNR is calculated
              as a phase difference from model and this can be large.
              Start with a value $\leq 1$.}
\disptt{ANTWT\qs 1 \CR}{to use weights from calibration with no
              additional weights applied to the antennas.  For the
              purposes of phase alignment, it is appropriate to use
              the data weights; this allows the noise in the solution
              to be distributed over the noisiest baselines.  This may
              not be the case when using {\tt CALIB} for
              self-calibration in the hybrid mapping sense (see \Sec
              9.6).}
\dispt{GO \CR}{to run the program.}
\dispe{Note that {\tt CALIB} will only give valid solutions if the
signal-to-noise over the solution interval on most baselines is
greater than 2 (and preferably much higher).  At high frequencies on
weak sources, it may not be possible to select a solution interval
long enough that the signal-to-noise satisfies this criterion, yet
short enough to follow the atmospheric phase variations.  In such
cases, it is probably best not to attempt to self-calibrate the data,
but instead to use a short averaging time and to live with any
coherence losses in the data.}
\Iodx{VLBI}\iodx{calibration}

When the data are sufficiently phase coherent, they should be averaged
over time down to a reasonable size using \hbox{{\tt \tndx{UVAVG}}}:
\dispt{TASK\qs 'UVAVG' ; INP \CR}{to review the inputs.}
\dispt{INDISK\qs {\it n} ; GETN\qs {\it ctn} \CR}{to specify the {\tt
            CALIB} output file as the {\tt UVAVG} input file.}
\dispt{OUTNA\qs INNA ; OUTCL\qs 'UVAVG' \CR}{to specify the output
            file.}
\dispt{YINC\qs 30.0 \CR}{to set the time-averaging interval to 30
            seconds.}
\dispt{OPCODE\qs ' ' \CR}{to enable the averaging operation.}
\dispt{GO \CR}{to run \hbox{{\tt UVAVG}}.}
\pd

\subsubsect{9.5.3. Verifying calibration}

Before proceeding to image your data, it's worth checking that the
calibration performed in \Sec 9.4 is sensible.  For each of your
sources, produce a plot of the correlated flux density against \uv\
distance using \hbox{{\tt \tndx{UVPLT}}}.  As well as identifying bad
data which can then be deleted with {\tt IBLED}, {\tt EDITR}, or {\tt
UVFLG}, these amplitude versus distances plots (especially those of
your calibrator sources) can be used to identify stations where the
amplitudes are too high or too low.  Furthermore, by fitting simple
models to the calibrator data, constant correction factors can be
determined for each station which can be used to correct the amplitude
calibration.  It is often the case that the amplitude calibration to a
certain station (particularly non-VLBA stations) is out by a constant
factor, either due to uncertainties in the antenna gain or in the
noise calibration signal.
\Iodx{VLBI}\iodx{calibration}

Most VLBI calibrator sources can be adequately described by one or two
Gaussian components.  The task {\tt \tndx{UVFIT}} can be used to fit
such a model while finding constant correction factors for the antenna
gains. Note that {\tt UVFIT} can handle no more than 25,000
visibilities, so further averaging with {\tt UVAVG} may be required.
The following example shows how to fit antenna gains and a single
elliptical Gaussian model of known position and flux to one of the
single-source data sets produced by {\tt SPLIT} and {\tt AVSPC}:
\dispt{TASK\qs 'UVFIT' ; INP \CR}{to review the inputs.}
\dispt{INDISK\qs {\it n} ; GETN\qs {\it ctn} \CR}{to specify the input
            \uv\ data set.}
\dispt{OPCODE\qs 'GAUS' ; NGAUS\qs 1 \CR}{to specify 1 Gaussian
            component.}
\dispt{GMAX\qs 1.2 ; DOMAX\qs FALSE \CR}{to fix the flux at 1.2 Jy.}
\dispt{GPOS\qs 0 ; DOPOS\qs FALSE \CR}{to hold the position fixed at
            the origin.}
\disptt{GWIDTH\qs 0.002 , 0.001 , 45. \CR}{to provide an initial guess
            of the Gaussian widths as $2 \times 1$ mas at a position
            angle of $45\deg$.}
\dispt{DOWIDTH\qs TRUE \CR}{to fit for size.}
\dispt{GAINERR\qs 1 \CR}{to fit for all antenna gains with initial
            guess $= 1$.}
\dispt{NITER\qs 50 \CR}{to limit the fitting to 50 iterations.}
\dispt{IMSIZE\qs 0.0005 , 0.01 \CR}{to limit sizes to be in the range
            0.5 to 10 mas.}
\dispt{DOCAT\qs TRUE ; INVER\qs 1 \CR}{to save the solution in a {\tt
            CC} file of version number 1.}
\dispt{INP \CR}{to check the inputs.}
\dispt{GO \CR}{to run \hbox{{\tt UVFIT}}.}
\dispe{{\tt UVFIT} can also be applied to the multi-source file, but
{\tt SOURCE}, {\tt DOCAL}, {\tt GAINUSE} etc.~must then be set.}

Another way to test your amplitude calibration is to use the task {\tt
\tndx{UVCRS}} for bright sources with long tracks.  This task
calculates correction factors for the amplitudes of the stations using
regions of the \uv\ plane where \uv\ tracks cross.  {\tt UVCRS} can
write the correction factors into an {\tt SN} table.

Once the scale factors are determined, there are a number of options
for correcting the data.  The simplest option is to apply the
correction factors to the single-source data sets using task
\hbox{{\tt \tndx{VBCAL}}}.  Alternatively, the correction factors can
be incorporated into the highest version {\tt CL} table of the
multi-source data file and task {\tt SPLIT} run again to make new
calibrated data files.  The corrections to the {\tt CL} table is done
with \hbox{{\tt CLCOR}}.  Unlike {\tt VBCAL}, {\tt \tndx{CLCOR}} must
be run separately for each antenna whose calibration you wish to
alter; {\tt ANTENNA} must be set to the antenna number you wish to
change, {\us OPCODE = 'GAIN' \CR} and {\tt CLCORPRM(1)} set to the
amplitude scale factor found in {\tt UVFIT} squared; all higher values
in the array {\tt CLCORPRM} should be zero.  The effect of the altered
calibration can be viewed using {\tt UVPLT} with {\tt DOCAL = 1}.  If
it is satisfactory, {\tt SPLIT} can be re-applied to the data.  We
recommend using {\tt CLCOR} to perform such amplitude corrections.

Another way of incorporating amplitude corrections is to edit the
calibration text files used by \hbox{{\tt \tndx{ANTAB}}}.  This can be
accomplished by setting the {\tt FT} parameters for affected stations.
For instance, if the Bonn scale factor is 1.043, set the {\tt FT}
parameter on the {\tt BONN TSYS} card to {\tt FT=(1.043*1.043)}.  If
amplitude calibration was carried out {\it after} fringe-fitting, then
it is only necessary to rerun {\tt ANTAB}, delete the latest
{\tt CL} table containing amplitude calibration and rerun {\tt
\tndx{APCAL}} using the highest {\tt CL} table produced in the
fringe-fitting step.  If however, as we have described in this
chapter, the amplitude calibration was done prior to fringe-fitting,
then correcting the amplitudes is more involved.  It is probably best
to delete all {\tt CL} tables except the first one and start again at
\Sec 9.4.  However, it may not be necessary to carry out the time
consuming {\tt FRING} solutions again.  If the amplitude changes are
small, the phase, rate and delay solutions will be essentially
unchanged.  Therefore, with care, the existing {\tt SN} tables can be
used in lieu of re-running \hbox{{\tt FRING}}.
\Iodx{VLBI}\iodx{calibration}

\subsect{9.6.  Self-calibration, imaging, and model-fitting}

We are now in a position to make images.  As with VLA data, we do this
by iteratively, self-calibrating the data and deconvolving using
Clean, MEM {\it et al.}.  We describe below a typical self-calibration
and imaging sequence for VLBI data.  The tasks used are described in
more detail in Chapter 5.

\hanstart {50pt}
\enumerate{1}{{\tt CALIB} self-calibrates the \uv\ data. }
\enumrnext{{\tt \tndx{IMAGR}} images and cleans. {\tt IMAGR} is now
     the preferred task for imaging {\tt VLBI} data in \AIPS\ .}
\enumrnext{{\tt SCMAP} images, cleans, and self-calibrates.
     {\tt \tndx{SCMAP}} is meant to provide the functionality of the
     popular VLBI data analysis package {\tt difmap}.}
\par\hanend
\vskip -6pt
\noindent The main difference between the processing of VLBI and VLA
data is that, initially, absolute phases of VLBI data are un-calibrated
(unless phase-referencing is used).  Therefore, many more iterations
around the imaging loop are required for the VLBI case; dozens of
self-calibration iterations are not uncommon.  Given this, it may be
convenient to use the procedure {\tt \tndx{HYB}} which executes a
whole cycle of hybrid mapping (\ie\ an {\tt \tndx{MX}} plus \hbox{{\tt
CALIB}}).  It also plots images and allows editing of Clean component
files prior to \indx{self-calibration}.  Type {\us HELP HYB \CR} for
more information.

Note that VLBI imaging is not an exact science and there are a number
of different views on the ``correct'' imaging method and the
``correct'' software to accomplish this method.  Some users take their
\AIPS\ data into a package written at CalTech to use the {\tt difmap}
program [see {\tt ftp://phobos.caltech.edu/pub/difmap/}].  Others use
the new \AIPS\ task {\tt SCMAP} (see \Sec 5), while still others
follow older {\tt HYB} path.  It is beyond the scope of this document
to explain in detail all aspects of VLBI imaging.  For more details,
see Craig Walker's chapter on ``Practical VLBI Imaging'' in the
publication {\it VLBI and the VLBA} which is available on the
World-Wide Web.  Here we make a few suggestions on how to control {\tt
\tndx{CALIB}} and \hbox{{\tt \tndx{IMAGR}}}.  Again, please note that
this task is new in {\tt 15JUL95} \AIPS\ and is preferable to all
previous imaging tasks (except perhaps the revised \hbox{{\tt
\tndx{SCMAP}}}).

\subsubsect{9.6.1.  {\tt CALIB}}

\hanstart {50pt}
\enumerate{1}{Start by correcting antenna phases only, \ie\ use
    {\us SOLMODE = 'P' \hbox{\CR}}.  Switch on the amplitude
    correction only after you have converged to a fairly good image.
    On the first iteration, you will need to invent an input model.
    For most extragalactic continuum sources, a point-source model is
    a good choice.  Set {\tt SMODEL(1)} to the zero-spacing flux
    density as interpolated by eye using \hbox{{\tt UVPLT}} and
    consider using a circular Gaussian model at the origin to reduce
    the impact of the longest spacings.  Start with the so-called SNR
    parameter {\tt APARM(7)} small ($\leq 1$) and gradually increase
    it as the image improves.  If this parameter is large during early
    iterations, when the model used is far from correct, then large
    portions of your data may be flagged.\iodx{self-calibration}}
\enumerate{2}{On subsequent iterations, use the Clean image as
    produced by {\tt IMAGR} as your input model.  Unlike VLA images,
    \Indx{VLBI} applications usually require Clean components well
    beyond the first negative component to be used in calculating the
    source model.  One possibility is to use {\tt PRTCC} to find the
    point where a significant fraction (\eg\ one third) of all new
    Clean components are negative.  An alternative is to use all of
    the Clean components, but to use tight windowing in {\tt IMAGR}
    --- which can now be done interactively on the TV as {\tt IMAGR}
    progresses.  Alternatively, use tight windowing and clipping of
    the Clean components with {\tt \tndx{CCEDT}} or {\tt \tndx{CCSEL}}
    before running \hbox{{\tt \tndx{CALIB}}}. Tight windowing is
    especially important when \uv\ coverage is poor.  Editing Clean
    components after {\tt \tndx{IMAGR}}, but before {\tt CALIB}, can
    be effective in removing possibly spurious features; if they are
    real they will usually reappear in later iterations.}
\enumerate{3}{When carrying out the next {\tt CALIB} iteration with
    the new Clean model, you can either self-calibrate the original
    data set or, alternatively, self-calibrate the data set which was
    used to produce that Clean model.  It is probably advantageous to
    go back to the original data set periodically.  Amongst other
    things, this can prevent the telescope amplitudes from
    ``wandering'' (see below).}
\enumerate{4}{If your array contains antennas that have a wide range
    of sensitivities, \eg\ the VLBA plus the phased VLA and/or the
    Bonn 100-m, it is helpful to alter the weights of the antennas in
    your {\tt CALIB} solutions.  If this is not done, then your
    solution will be dominated by only a few baselines and the
    uniqueness of the solution is not guaranteed.  Use {\tt PRTUV} to
    inspect the weights of your data.  Then set the {\tt CALIB} input
    array {\tt ANTWT}, which provides multiplicative factors adjusting
    the weights for each antenna prior to the {\tt CALIB} solution.
    Set these parameters so that the effective range of baselines
    weight is only 10 to 100.  Alternatively, use {\tt WTMOD} to raise
    the original weights to a power between 0.25 and 0.5.}
\enumerate{5}{As you iterate, keep an eye on how the model image is
    converging to fit the data.  Use {\tt VPLOT}, {\tt CLPLT} and
    \hbox{{\tt UVPLT}}.}
\enumerate{6}{When your source has a lot of extended structure and/or
    your VLBI array has relatively few short spacings, you should
    consider setting {\tt UVRANGE} to only include the range of
    spacings in which the model provides a good fit to the data.
    However, given the relatively small number of antennas in most
    VLBI observations, you may need to compromise to allow in enough
    baselines to get good self-cal solutions. }
\enumerate{7}{When you are finally ready to solve for amplitude
    corrections, you should first apply all previous phase calibration
    (including final phase-only self-calibration solution).  Then run
    {\tt \tndx{CALIB}} setting {\tt SOLMOD \ 'A+P'}, initially setting
    the solution interval ({\tt SOLINT}) to several hours.  Try to
    prevent the antenna amplitudes from ``wandering,'' which can
    sometimes happen if there is still a significant amount of short
    spacing flux density missing from the source model.  Setting {\tt
    UVRANGE} is useful, as is setting {\us CPARM(2) =1 \CR} to
    constrain the mean amplitude solutions over all antennas to be
    one. You can also set {\us SOLMODE='GCON' \CR} and the array {\tt
    GAINERR} to the expected standard deviation of the gains for each
    antenna.  This constrains amplitude solutions to conform to the
    expected statistics.  Setting the gain constraint factor {\tt
    SOLCON} to values larger than 1 will increase the importance of
    these gain error constraints.  Finally, going back and
    self-calibrating starting with the original data set and the best
    available Clean model is useful way to prevent amplitude wander.}
\par\hanend
\Iodx{VLBI}\iodx{self-calibration}

{\tt CALIB} has been enhanced however to improve its usefulness for
SVLBI datasets. This has involved the implementation of improved
antenna selection and partial array calibration, through the new
adverb \hbox{{\tt DOFIT}}. The possibility of solving only for a
subset of selected antennas has been implemented in this manner and
may prove useful for SVLBI data. The implementation of adverb {\tt
DOFIT} in {\tt CALIB} is analogous to its implementation in {\tt
FRING} [see \Sec 9.4.8.3].

\subsubsect{9.6.2.  {\tt IMAGR} and {\tt SCMAP}}

\hanstart {50pt}
\enumerate{1}{Before using {\tt IMAGR} or {\tt \tndx{SCMAP}}, print
    out and read the {\tt EXPLAIN} file.  It is a powerful and
    complicated task with many adverbs --- some of which are new ---
    and shouldn't be used blindly.}
\enumerate{2}{The quality of images produced may depend on the type of
    weighting used.  With VLBA-only experiments, the best quality
    images are often produced using natural ({\us UVWTFN\qs 'NA' \CR})
    weighting in \hbox{{\tt IMAGR}}.  These images will represent the
    extended structure of the source better.  If the highest
    resolution is required, try uniform ({\us UVWTFN\qs 'UN' \CR})
    weighting.  The {\tt ROBUST} parameter allows weightings
    intermediate between these two extremes often with both good
    signal-to-noise characteristics and a narrow synthesized beam.  It
    may also be worth experimenting with the {\tt UVBOX} parameter to
    allow smoothing of weights over larger areas of the \uv\ plane
    (\ie\ to use ``super-uniform weighting'').  If the array contains
    antennas with very different sensitivities, (for instance, if it
    includes Bonn or the phased VLA), then it may be advantageous to
    lower the weights of baselines to these antennas.  Although this
    increases the thermal noise in the image, it will improve the \uv\
    coverage, which, otherwise, will contain effectively only the
    baselines to these sensitive antennas.  One way of doing this is
    to use {\us UVWTFN = 'UV' \CR} in \hbox{{\tt IMAGR}}.  This option
    takes the fourth root of the input weights before applying uniform
    weighting.  {\tt SCMAP} also supports these weighting options.
    Another flexible (but deprecated) approach is to use task {\tt
    WTMOD} to change the weights in the data set prior to running
    \hbox{{\tt \tndx{IMAGR}}}.}
\enumerate{3}{After an initial self-calibration against a point-source
    starting model, the deconvolved image will often show spurious
    symmetric structure.  Convergence can be speeded up by placing
    Clean boxes {\tt CLBOX}) around the side showing the brighter
    structure.  Note that {\tt CLBOX} may be used to produced circular
    as well as rectangular windows for use with \hbox{{\tt IMAGR}}.
    Alternatively, {\tt CCEDT} can be used to edit the Clean
    components after {\tt IMAGR}, but before the next \hbox{{\tt
    CALIB}}.  {\tt IMAGR} and {\tt SCMAP} allow this to be done
    interactively at the start of each major Clean cycle including the
    first.}
\enumerate{4}{Use {\us DOTV = 1 \CR} to view the residuals and
    possibly modify the Clean boxes as you Clean.  You can stop
    Cleaning if you feel that you are including spurious structure
    into your model or if you feel you need to reset a Clean box to
    include a new feature}.
\enumerate{5}{{\tt \tndx{SCMAP}},at each self-calibration cycle,
    offers a powerful interactive data editing tool which displays
    input and residual data from up to 11 baselines simultaneously.}
\par\hanend

\noindent The hints outlined above are by no means the whole story
when it comes to self-calibrating and imaging \Indx{VLBI} data.
Unfortunately, it can still be somewhat of an art form.  Very
experienced users can produce noise-limited images, but there is no
simple recipe that will enable inexperienced users to do the same.
\iodx{self-calibration}

The existing weighting schemes available in {\tt IMAGR} are believed
to be sufficiently flexible for SVLBI imaging requirements. Further
information on this point will be obtained during the VSOP in-orbit
checkout period.

\subsubsect{9.6.3. Model-fitting}

For those \indx{SVLBI} datasets for which conventional aperture
synthesis imaging is not possible there are several other options.

Fringe-rate mapping is available, in the form of the task \hbox{{\tt
\tndx{FRMAP}}}. Type {\tt EXPLAIN FRMAP} within \AIPS\ for further
information.

An integrated model-fitting environment is provided in the form of the
task {\tt \tndx{SLIME}} ({\tt S}lick {\tt I}nteractive {\tt M}odel
{\tt E}ditor). This is an external application, written in the C
language, but linked against the standard \AIPS\ calibration and data
selection libraries, and is distributed separately from \hbox{\AIPS}.
It has an X-window based graphical user interface and allows data
display and interactive graphical editing of a direct representation
of the fitted model. Web-based information on {\tt SLIME} and the
Users Guide can be found via

{\bf http://info.aoc.nrao.edu/$\tilde{}$cflatter/slime.html} .

\noindent This task can be run directly from \AIPS; type {\tt EXPLAIN
SLIME} for further information. Note however that it is important to
average the data in time and frequency before using the model-fitter
(see \Sec 9.5.2)

\subsect{9.7. Data simulation within \AIPS\ }

In developing SVLBI data reduction support within \AIPS\ the
capability was required to generate fake datasets with
pre-fringe-fitting errors of various forms. A task was written for
this purpose, called \hbox{{\tt \tndx{DTSIM}}}. This task, when used
with an auxiliary task {\tt DTCHK}, has also been used to test the
correctness of \AIPS\ tasks in general. The simulator should be
understood as a software testing tool and does not have an error model
designed for highly sophisticated data simulations. Support is
implemented however for orbiting VLBI antennas.

The format of the output \uv\ data file, calibration errors, source
model and the fake schedule are specified in an external text file in
{\tt KEYIN} format. The required format is described in the {\tt DTSIM
EXPLAIN} file. The general model used in generating the fake data is
of the following general form:
$$V_{ij}^{pq} = G_i^p G_j^{q*} V_{mod}^{pq} + N_{ij}^{pq}$$
where $V_{ij}^{pq}$ is the simulated visibility data on baseline $i-j$
for polarization $pq$ ($p,q \in\ $RCP, LCP), and $V_{mod}$ and $N$ are
the model visibility and thermal noise contribution respectively. The
instrumental antenna-based complex gain terms are indicated as
$G_i^{p,q}$, and are parametrized by residual delay, phase and
bandpass errors. In addition, there is support for instrumental
polarization errors but this is not represented in the expression
above.

Task {\tt \tndx{DTSIM}} is run as follows:\Iodx{VLBI}
\dispt{TASK\qs 'DTSIM' ; INP \CR}{to review the inputs.}
\dispt{OUTDISK {\it n} \CR}{specify the output file.}
\dispt{OUTNAM\qs 'VSOP', OUTCLA\qs 'UV'}{}
\dispt{INFILE\qs 'FITS:DTSIM.INP' \CR}{{\tt KEYIN} input file.}
\dispt{PRTLEV\qs 0 \CR}{do not echo input text file.}
\dispt{GO \CR}{to run the program.}
\dispe{The resulting fake dataset has {\tt FQ, AN, SU}, and {\tt HI}
tables attached. The {\tt CL} table version 1 and the index table need
to be generated using \hbox{{\tt INDXR}}. The \uv\ data file is then
in standard \AIPS\ format.}

This task can be used to generate fake SVLBI datasets, and has been
used to test the fringe-fitting and other SVLBI software. The results
of these tests are described elsewhere, but an illustrative plot of
the performance of {\tt FRING} for various signal-to-noise ratio data
is shown in the figure below.

\vfill
\centerline{\vbox{\hrule height 0.25pt width 4.0in}}
\vfill

\vskip 5pt
\if T\doFIG
   \centerline{\psfig{figure=FIG/COOK9F.PLT,height=3.0in}}
\else
   \vbox to 3.0in{\vfill\omit\vfill}
\fi

\vskip 5pt
{\Smpoint
\noindent RMS of measured residual delay as determined by {\tt
\tndx{FRING}} for simulated 18cm VSOP data with a point double source
model of 1.5 mas E-W separation and a flux density ratio of 2:1.
\iodx{SVLBI}}
\vfill\eject

\subsect{9.8. Summary of VLBI calibration tables}

Several different tables are supplied with a VLBI data set created by
the Socorro and other correlator; various other tables (\eg\ {\tt SN}
tables) are created by the \indx{calibration} process. A  list of
these tables is given below for your edification.  Not all
\indx{tables} will be present with all files.
\Iodx{VLBI}

\dispxx{ AN}{Antenna table. Contains a list of the antenna names
      and station coordinates.  Also contains instrumental
      polarization terms.}
\dispxx{ AT}{Antenna Characteristics table. Contains additional
      information about antenna properties, including some time
      variable quantities.}
\dispxx{ BL}{Baseline offset table. Contains non-closing
       baseline-dependent phase and amplitude errors as determined by
       \hbox{{\tt BLCAL}}.}
\dispxx{ BS}{Baseline Solution table.  Contains baseline delay, rate
       and phase solutions as determined by \hbox{{\tt BLING}}.}
\dispxx{ CL}{Default calibration table.  Contains, amongst other
      things, the default calibration parameters for the amplitude
      (usually unity), phase, and single-band delay (usually zero) for
      each source for each IF as a function of time.  It also contains
      polynomial coefficients allowing the correlator delay and phase
      models to be recomputed.  As calibration proceeds, higher
      versions of this table are created which incorporate more and
      more calibration effects into the phase and delay entries.}
\dispxx{ CQ}{Correlator parameter frequency table. Contains VLBA
       correlation parameters for each \AIPS\ IF, and activates VLBA
       delay decorrelation corrections. Type {\tt EXPLAIN FXVLB} for
       further information.}
\dispxx{ CT}{{\tt CALC} table. Contains the input parameters passed to
       {\tt CALC} to generate the polynomials recorded in the {\tt IM}
       table.}
\dispxx{ FG}{Flag table. Contains information used to delete selected
      portions of the data.}
\dispxx{ FQ}{Frequency table. Contains information about the IF
      frequencies, channel spacings, bandwidths, etc.}
\dispxx{ GC}{Gain Calibration table. Contains the expected zenith
      gain and gain-elevation curve for each antenna. It is used for
      amplitude calibration.}
\dispxx{ HF}{Haystack {\tt FRNGE} table. Contains information
       generated from the \AIPS\ tables that can be exported to the
       {\tt CALC} and {\tt SOLVE} package.}
\dispxx{ IM}{Interferometer model table. Contains the actual
      polynomial coefficients which the VLBA correlator used to
      calculate the geometrical model.  Unlike the coefficients in the
      {\tt CL} table, these have not been re-interpolated onto the {\tt
      CL} time grid, but have time stamps corresponding to the times
      at which the correlator computed the geometrical model.}
\dispxx{ MC}{Model Components table. Contains the various components
       of the geometric model used in the VLBA correlator to generate
       the {\tt IM} table.}
\dispxx{ NX}{Index File. Contains information about the time, source,
      sub-array and location within the data file of each observation
      or ``scan.''  It is used by some \AIPS\ tasks in accessing the
      main data file and subsidiary tables.}
\dispxx{ OB}{Spacecraft Orbit table.  Contains information about the
      positions and velocities used by the correlator for an orbitting
      antenna.}
\dispxx{ PC}{Phase-calibration table. Contains phases within each
      IF computed from the injected phase calibration signals.  It is
      used to determine the phase offsets and single-band delays for
      each IF channel.}
\dispxx{ SN}{Solution table.  Contains antenna delay, rate, phase, and
      amplitude corrections solved for by {\tt CALIB} and \hbox{{\tt
       FRING}}.}
\dispxx{ SU} {Source table. Contains a list of the sources found
      within the multi-source file, including information on
      source positions and flux density}
\dispxx{ TY}{System temperatures table. Contains the system
      temperature as a function of time for each antenna and IF
      channel. It is used for amplitude calibration.}
\dispxx{ VT}{VLBA Tape table. Contains tape playback statistics for
       use mainly by the VLBA correlator group.}
\dispxx{ WX}{Weather table. Contains weather-related information for
       each station.}
\pd
\Iodx{VLBI}\iodx{calibration}\iodx{tables}
\centerline{\vbox{\hrule height 0.25pt width 4.0in}}

\vfill

\if T\doFIG
   \centerline{\psfig{figure=FIG/VLBA1A.PLT,height=3.5in}}
\else
   \vbox to 3.5in{\vfill\omit\vfill}
\fi
\vskip 10pt
{\Smpoint\parskip 3pt
\noindent The first scientific results reported from the \indx{VLBA}
correlator in the continuum.  We thank R. C. Walker for these data.
More details are available via the World-Wide Web.
}
\vfill
\eject

\if T\doFIG
   \centerline{\psfig{figure=FIG/VLBA1U.PLT,height=7.5in}}
\else
   \vbox to 7.5in{\vfill\omit\vfill}
\fi
\vskip 10pt
{\Smpoint\parskip 3pt
\noindent The first scientific results reported from the \indx{VLBA}
correlator in spectral lines.  We thank P. J. Diamond for these data.
More details are available via the World-Wide Web. \Iodx{VLBI}
}
\vfill
\end

%---------------------------------------------------------------------

\subsect {9.9 Other resources}

More detailed information can be found in the \AIPS\ memo. series and
other references, including:

1. {\it VLBI and the VLBA}, Astronomical Society of the Pacific (ASP)
Conference Series No. 82, 1995.

2. {\it VLBI Technology: Progress \& Future Observational Possibilities},
(eds. T. Sasao et al., Terra Scientific Publishing Company, 1994).

3. {\it Frontiers of VLBI} (eds. H. Hirabayashi et al., Universal Academy
Press, Inc. (Tokyo).

1. \AIPS\ memo 90.

1. Clark, B.G., VLBA memo .
1. Cotton, W.D., 1992, \AIPS\ memo 79.

2. Cotton, W.D., 1993, {\it AJ}, {\bf 106}, 1241.

3. Roberts {\it et al.}, 1994, {\it ApJ}, {\bf 427}, 718.

4. Kemball {\it et al.}, 1994, {\it A\&A}, {\bf 110}, 383.

5. Lepp\"{a}nen, K.L., 1995, Ph.D. thesis (Helsinki Univ. of Technology)

\hbox to \hsize{\hss\vbox{\hrule height 0.25pt width 4.0in}\hss}
\vfill\eject

\vfill
{\Smpoint\parskip 3pt
\noindent On the next page are the first scientific results reported
from the VLBA correlator in the continuum and in spectral line.  We
thank R. C. Walker and P. J. Diamond for these data.  More details are
available via the World-Wide Web.
}
\eject

\if T\doFIG
   \centerline{\psfig{figure=FIG/VLBA1A.PLT,height=3.5in}}
\else
   \vbox to 3.5in{\vfill\omit\vfill}
\fi
\vfill

\if T\doFIG
   \centerline{\psfig{figure=FIG/VLBA1B.PLT,height=4.8in}}
\else
   \vbox to 4.8in{\vfill\omit\vfill}
\fi

\eject
\end
