%-----------------------------------------------------------------------
%;  Copyright (C) 2000-2008, 2013-2015, 2018-2025
%;  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
%-----------------------------------------------------------------------

\APPEN{VLBA Data Calibration in \AIPS}{A Step-by-Step Recipe for VLBA
    Data Calibration in \AIPS}{VLBAeasy}
\renewcommand{\Chapt}{23}

\renewcommand{\titlea}{31-December-2025 (revised 14-October-2025)}
\renewcommand{\Rheading}{\AIPS\ \cookbook:~\titlea\hfill}
\renewcommand{\Lheading}{\hfill \AIPS\ \cookbook:~\titlea}
\markboth{\Lheading}{\Rheading}

This appendix provides a step-by-step guide to calibrating many types
of \Indx{VLBA} and \Indx{HSA} (High Sensitivity Array or Effelsberg,
Arecibo, GBT, and phased VLA) experiments.  Continuum strong-source or
phase-referencing observations are included, as are simple
spectral-line observations.  This appendix applies specifically to
data sets with full calibration transfer.  There is an addendum
(\Sec{nonvlba}) describing issues with flagging for non-VLBA data
sets and other matters for cases in which not all calibration data are
loaded by {\tt FITLD}\@.  It may often be used (with some
modifications in loading amplitude data) for data sets containing
other antennas.\iodx{VLBI} Simple VLBA utilities that go all the way
up to and including fringe-fitting are described.

% \sects{Revision History}
%
% \begin{itemize}
% \item\ {Released Version 1.0 by Jim Ulvestad, 13 June 2000}
% \item\ {Version 1.1, VLBA utils, VLA calib, other corrections 29 June 2000}
% \item\ {Version 1.2, minor corrections, 20 July 2000}
% \item\ {Version 1.3: added more VLBA utilities, 2 January 2001}
% \item\ {Version 1.4: added more VLBA utilities, 1 June 2001}
% \item\ {Version 2.0: major revision, by Amy Mioduszewski, 13
%          December 2001}
% \end{itemize}

\Sects{Quick Guide}{VLBAquick}
This section is meant as a reminder for people who have some idea how
to reduce straightforward VLBI data and a familiarity with \AIPS\@.
For further details see the rest of this appendix and/or Chapter 9.
This section does not include things like {\tt CVEL} or {\tt AVSPEC}
that might be useful for spectral line observations.  Also, this section
refers to procedures that can loaded by typing {\tt RUN VLBAUTIL}.  All
these steps are performed, in this order, by the {\tt
31DEC25 \tndx{VLBAPIPE}} (section \Sec{VLBApipe}) pipeline procedure.
\begin{enumerate}
\item\ {{\tt VLBALOAD} --- load the data}
\item\ {{\tt VLBAFIX} --- fix the data (separate frequencies, merge
         tables, create index table, etc.)}
\item\ {{\tt VLBAEOPS} --- correct earth orientation parameters}
\item\ {{\tt VLBATECR} --- (if frequency $<$ 10 GHz) remove dispersive
         delay from ionosphere}
\item\ {{\tt VLBAPANG} --- correct parallactic angle}
\item\ {{\tt VLBACCOR} --- correct sampler threshold errors from
         correlator}
\item\ {{\tt VLBAPCOR} or {\tt VLBAMPCL} --- (if more than 1 IF)
         correct instrumental delays, use {\tt POSSM} to inspect
         correction}
\item\ {{\tt VLBAFRNG} or {\tt VLBAFRGP} --- fringe fit data}
\item\ {{\tt VLBABPSS} --- calibrate bandpass, use {\tt POSSM} to
         inspect bandpass solutions}
\item\ {{\tt VLBAAMP} --- corrects any auto-correlation departure from
         unity caused by previous steps and performs a-priori
         amplitude calibration, use {\tt SNPLT} to check that
         nothing has gone wrong in the amplitude calibration.}
\item\ {{\tt RFLAG} --- flag data that are too variable in time
                        or frequency; optionally stop pipeline.}
\item\ {{\tt IMAGR} and {\tt FRING} or {\tt CALIB} --- do one round of
        self-calibration on each source in {\tt CALSOUR} optionally}
\item\ {{\tt SPLIT} --- apply all calibration and possibly average
        data spectrally}
\item\ {{\tt IMAGR} --- image data}
\end{enumerate}
\vfill\eject

These steps, in a different order, are also performed by the older {\tt
VLBARUN} (section \Sec{VLBApipe}) pipeline procedure.
\begin{enumerate}
\item\ {{\tt VLBALOAD} --- load the data}
\item\ {{\tt VLBAFIX} --- fix the data (separate frequencies, merge
         tables, create index table, etc.)}
\item\ {{\tt VLBAEOPS} --- correct earth orientation parameters}
\item\ {{\tt VLBATECR} --- (if frequency $<$ 10 GHz) remove dispersive
         delay from ionosphere}
\item\ {{\tt VLBACCOR} --- correct sampler threshold errors from
         correlator}
\item\ {{\tt VLBAPCOR} or {\tt VLBAMPCL} --- (if more than 1 IF)
         correct instrumental delays, use {\tt POSSM} to inspect
         correction}
\item\ {{\tt VLBABPSS} --- calibrate bandpass, use {\tt POSSM} to
         inspect bandpass solutions}
\item\ {{\tt VLBAAMP} --- corrects any auto-correlation departure from
         unity caused by previous steps and performs a-priori
         amplitude calibration, use {\tt SNPLT} to check that
         nothing has gone wrong in the amplitude calibration.}
\item\ {{\tt VLBAPANG} --- correct parallactic angle}
\item\ {{\tt VLBAFRNG} or {\tt VLBAFRGP} --- fringe fit data}
\item\ {{\tt RFLAG} --- flag data that are too variable in time
                        or frequency}
\item\ {{\tt IMAGR} and {\tt FRING} or {\tt CALIB} --- do one round of
        self-calibration on each source in {\tt CALSOUR} optionally}
\item\ {{\tt SPLIT} --- apply all calibration and possibly average
        data spectrally}
\item\ {{\tt IMAGR} --- image data}
\end{enumerate}

\sects{Table Philosophy}

\AIPS\ follows an incremental calibration process on multi-source data
sets.  Calibration solutions are written to {\tt SN} (``Solution'')
tables, which can be inspected in various ways.  {\tt CLCAL} is used
to apply an {\tt SN} table and write a new {\tt CL} (``Calibration'')
table, which stores the cumulative calibrations.   If the procedure in
VLBAUTIL is used, much of this is hidden, however most procedures will
report the new SN and\/or CL that are produced.  The actual
visibilities are not altered until the final calibration is applied
using {\tt SPLIT} (or {\tt SPLAT}), which produces single-source
(or multi-source) data sets that can be imaged.  With this philosophy,
it is easy to back up a step or two if errors are made in processing.
Users should keep track of which tables contain which solutions and
calibrations as they go through the calibration process.

A key verb to be aware of is {\tt EXTDEST}, which can delete any
unwanted table.  For example, to delete {\tt SN} version 3 from the
data set cataloged as data set 1 on disk 1, type {\tt INDISK 1;
GETNAME 1; INEXT 'SN'; INVER 3; INP EXTDEST; EXTDEST}\@.  {\it Beware
of the fact that once a table is deleted, there is no `undelete'
function.}

\sects{Data set assumed in this Appendix}

This appendix assumes a VLBA-only data set observed at several
frequency bands (\eg\ 1.6, 2.3, and 5.0 GHz).  To include data from
the non-VLBA antennas see \Sec{nonvlba}\@.  It is also assumed that
phase-referencing programs have been observed according to the
philosophy discussed in detail in VLBA Scientific Memo No.~24.  The
hypothetical observation considered here contains the following
sources:

\begin{itemize}
\item\ {`CAL-BAND' --- fringe-search and bandpass calibrator}
\parskip 0pt
\item\ {`CAL-AMP' --- amplitude-check source}
\item\ {`CAL-POL' --- polarization position angle calibrator}
\item\ {`STRONG' --- strong target source}
\item\ {`CAL-PHASE' --- phase-reference source}
\item\ {`TARGET' --- weak target source, to be calibrated with CAL-PHASE}
\end{itemize}

In the text below, table versions, such as {\tt SN} version 1, are
referred to as {\tt SN} 1.

\sects{VLBA Utilities}

Note that there are simple VLBA procedures (``front ends'' to standard
tasks) that will take the user all the way from data loading up to and
including fringe-fitting.  These are tremendous labor-savers for those
working with reasonably straightforward data sets.  For spectral line,
use the procedures to calibrate a lower spectral resolution version of
the spectral line data and copy the final calibration to the line set.
To access the utilities, type {\tt RUN VLBAUTIL} from inside \AIPS\@.
The procedures that we will use in this appendix are:

\begin{itemize}
\item {{\tt \tndx{VLBALOAD}}: loads VLBA data with simplified inputs}
\item {{\tt \tndx{VLBASUMM}}: makes summary listings of your data set}
\item {{\tt \tndx{VLBAFIX}}: Fixes VLBA data}
\item {{\tt \tndx{VLBATECR}}: automatically downloads and applies
    ionospheric corrections}
\item {{\tt \tndx{VLBAEOPS}}: automatically downloads and applies
    corrections to the Earth Orientation Parameters used by the
    correlator}
\item {{\tt \tndx{VLBACCOR}}: determines amplitude corrections caused
    by errors in sampler thresholds}
\item {{\tt \tndx{VLBAPANG}}: determines phase corrections for
    parallactic angles}
\item {{\tt \tndx{VLBAPCOR}}: determines instrumental phase
    corrections using pulse cals}
\item {{\tt \tndx{VLBAMPCL}}: determines instrumental phase
    corrections using {\tt FRING}}
\item {{\tt \tndx{VLBACPOL}}: calibrates cross polarization delays}
\item {{\tt \tndx{VLBABPSS}}: does bandpass calibration}
\item {{\tt \tndx{VLBAAMP}}: does adjustment due to normalization
    errors and a-priori amplitude calibration}
\item {{\tt \tndx{VLBAFRNG}}: does global fringe fit using {\tt
      FRING}}
\item {{\tt \tndx{VLBAFRGP}}: does global fringe fit for phase
    referenced experiments using {\tt FRING}}
\item {{\tt \tndx{VLBASNPL}}: plots the {\tt SN} or {\tt CL} tables
    versus time}
\item {{\tt \tndx{VLBACRPL}}: plots the cross-correlation spectrum}
\end{itemize}

There are two additional procedures that can make life easier, called
{\tt ANTNUM} and {\tt SCANTIME}\@.  {\tt ANTNUM} will return the
antenna number of the antenna corresponding to a certain character
string.  For example, in many data sets, typing {\tt REFANT = ANTNUM
('BR')} will be the equivalent of typing {\tt REFANT = 1}\@.  {\tt
SCANTIME} will return the time range of a given scan number, for use
in various programs.  Typing {\tt TIMERANG = SCANTIME(4)} will fill
the eight-element array {\tt TIMERANG} with the start and stop times
of the $4^{\uth}$ scan of a given data set.

Note that all of the {\tt VLBAUTIL} procedures have {\tt HELP} files
with good discussions about when to use the simple procedures and when
to use the tasks directly.  Also, note that the procedures do not
include data editing, which should be performed at appropriate points
in the calibration process.  You only need to {\tt RUN VLBAUTIL} once
to access all of the procedures.  If you run it again for any reason,
it is a good idea to type {\tt COMPRESS} immediately afterward
to avoid overflowing \AIPS\' symbol memory.

\Sects{VLBA Pipeline}{VLBApipe}

{\tt \Tndx{VLBAPIPE}} and {\tt \Tndx{VLBARUN}} are two similar
procedures which use the VLBA calibration procedures (from
{\tt \indx{VLBAUTIL}}) and some logic to calibrate and image VLBA data.
They both attempt to make intelligent decisions on defaults, so they can
be run fairly automatically if the names of the sources are known.  If
desired, {\tt VLBAPIPE} and {\tt VLBARUN} will produce diagnostic plot
files and write them to disk, creating an HTML file to ease examination
of these files.  Images will be produced but only one phase-only
self-cal is done (if requested), so the images should be considered
diagnostic in nature.

{\tt VLBAPIPE} and {\tt VLBARUN} do all the calibration steps described
in \Sec{VLBAquick} and the next few sections but in a different order.
They do not do polarization calibration.  They offers options to use
{\tt CLIP} and/or {\tt RFLAG} to do flagging.  They also offer options
to flag data at low elevations and to try to clean up bad values in the
system temperature table.  Although {\tt VLBAPIPE} and {\tt VLBARUN} are
intended for simple VLBI observations, the addition of non-VLBA antennas
should work if all the non-VLBA system temperature and gain curve
information are loaded into the first {\tt TY} and {\tt GC} tables.

The two piplines use essentially the same input adverbs, except for the
meaning of {\tt DOFLAG} parameter.  Sample inputs for procedure
{\tt \Tndx{VLBAPIPE}} are:
\dispt{RUN \tndx{VLBAUTIL} \CR}{to acquire the procedures used by {\tt
           VLBAPIPE}.}
\dispt{RUN \tndx{VLBAPIPE} \CR}{to acquire {\tt VLBAPIPE}.}
\dispt{INDISK\qs{\it n\/} ; GETN\qs {\it ctn\/} \CR}{to specify the
           input data file.}
\dispt{OPTYPE\qs 'CONT' \CR}{to say this is a continuum data set.}
\dispt{CLINT\qs 0 \CR}{to use default.}
\dispt{CHREFANT\qs 'FD' \CR}{to set reference antenna to Fort Davis.}
\dispt{CHINC\qs -1 \CR}{to have the procedure determine an appropriate
           channel increment for {\tt FRING}\@.}
\dispt{TIMERANG\qs 0 \CR}{to have VLBAPIPE determine a good instrumental
           delay calibration scan.}
\dispt{INVER\qs 0 \CR}{{\tt PC} table to use, -1 if you want to force
           manual phase cal.}
\displ{CALSOUR\qs 'CAL-BAND', 'CAL-PHASE', 'CAL-AMP' \CR}{to
           list calibrators, bandpass and initial {\tt FRING}calibrator
           {\it must} be first.}
\displ{SOURCES\qs 'CAL-PHASE', 'TARGET', $\ldots$ \CR}{to
           list phase referencing and target pairs.}
\dispt{INFILE\qs '' \CR}{set if you want to apply a zenith delay file
           produced by {\tt \Tndx{DELZN}}.}
\dispt{SOLINT\qs 0 \CR}{to use 1 minute averages in {\tt FRING}\@.}
\dispt{IMSIZE\qs 512 \CR}{to make images and specify size of target
           images.}
\dispt{FACTOR\qs 0 \CR}{to make calibrator images 128x128.}
\dispt{DOCLIP\qs $fp , fc$ \CR}{to run {\tt CLIP} to flag a sample
           when the parallel-hand flux is above $|fp|$ or the cross-hand
           flux is above $|fc|$.  If $fp$ is positive, the clip is
           done after amplitude calibration; if negative, it is done
           before the bandpass and amplitude calibration.  The
           appropriate values for $fp$ and $fc$ are different in these
           two cases.}
\dispt{DOFLAG\qs 1 \CR}{to run {\tt RFLAG} on each source
           individually.}
\dispt{TYSMOLEV\qs 100\CR}{to clip system temperatures above 100 K with
           median-window filtering at 10 K and replacing the clipped
           values with nearby good ones.}
\dispt{ELEVLIM\qs 15 \CR}{to flag out all data for which the elevation
           is $< 15$ degrees.}
\dispt{SELFCAL\qs 1 \CR}{to do one pass of self-cal, phase only on each
           calibrator prior to the final {\tt SPLIT}\@>}
\dispt{GET2N\qs {\it ctn2\/} ; NMAPS=1 \CR}{to use a model for the
           bandpass calibration.}
\dispt{BPASS5\qs -2 \CR}{to normalize bandpass scans before the fit.
           Default is +1 to normalize the bandpass functions themselves
           without normalization of the data.}
\dispt{BPSOLINT\qs 0 \CR}{to make a solution for each calibration scan.
           {\tt BPSOLINT=-1} averages all calibration scans.}
\dispt{DOBAND\qs 3 \CR}{to interpolate the bandpass over time.  {\tt
           DOBAND=1} (the default) averages all bandpass records.}
\dispt{CALTASK\qs 'CALIBS' \CR}{to use {\tt FRING} for the initial time
           series calibration but use {\tt CALIB} for any self-cal.
           Other choices are {\tt 'CALIB'} and {\tt 'FRING'} (the
           default) to use the specified task for all time series
           calibrations.}
\dispt{DOPLOT\qs 1 \CR}{to make some diagnostic plots.  Use level 2 only
           if there are serious issues; it generates a lot of plots.}
\dispt{OUTFILE\qs '{\it /directory/name} \CR}{to specify directory for
           output plots.  If this is set, plots are written out from
           \AIPS\ and organized in an HTML file for easy viewing.
           The plots, HTML file, and message file contents are put in
           a dated subdirectory below the specified directory.}
\dispt{OUTTEXT\qs '{\it email@somewhere.edu} \CR}{to specify an e-mail
           address if the user wants to be notified when the pipeline
           is done.}
\dispt{BADDISK 0 \CR}{to specify which disks to avoid for scratch.}
\dispt{VLBAPIPE \CR}{to run the procedure.}

The order of operations differs between the two pipelines.  The most
significant difference is that {\tt FRING} is run before {\tt BPASS} in
{\tt VLBAPIPE}\@.  This should insure that the bandpass solutions, when
there are multiple primary calirator scans, remain phase coherent.
The only adverb that differs between the two pipeline scripts is {\tt
DOFLAG}\@.  In {\tt VLBAPIPE}, the pipeline will shut down after running
{\tt RFLAG} if $0 < {\tt DOFLAG} < 10$ to allow you to rerun the
pipeline using the {\tt RFLAG} flag tables.  Presumably, the calibration
in the second pass should be better.  If {\tt DOFLAG} $\ge 10$ in {\tt
VLBAPIPE} or {\tt DOFLAG}$ > 0$ in {\tt VLBARUN} the pipeline invokes
{\tt RFLAG} and then continues to the optional self-cal step followed by
{\tt SPLIT} and {\tt IMAGR}\@.  {\tt VLBARUN} uses the value of {\tt
DOFLAG} as an initial clip level in {\tt RFLAG} but only if it is
greater than 100.  {\tt VLBAPIPE} does not use the initial clip option
in {\tt RFLAG}, leaving that to the {\tt DOCLIP} adverb.

It is a good idea to examine your {\tt TY} table with {\tt SNPLT} before
running {\tt VLBAPIPE}; this will tell you what a reasonble upper limit
to $T_{\rm sys}$ will be and whether there are bad values in need of
correction.  {\tt \tndx{SNRMS}} provides a summary of the statistics of
tables such as the {\tt TY} table.  It's maxima and rmses will make
problems with the table very clear.  Note that editing with {\tt CLIP}
is always a good idea. {\tt RFLAG} appears to work well at low
frequencies but to be overly enthusiastic at C-band and above.  Note
that the flagging is done after all calibration steps, so you may
examine your data with and without the new flags to determine their
correctness.  {\tt RFLAG} is run using baseline-dependent clip levels
and so should work with arrays containing high-sensitivity telescopes as
well as the VLBA\@.  You may wish to use {\tt VLBAPIPE} without {\tt
  RFLAG} (or to discard the flags produced by {\tt RFLAG}) and then run
{\tt SPFLG} to flag the visibility data interactively.  Then use {\tt
  VLBAPIPE} over again applying the manually produced flags.  Procedure
{\tt R\_RESTART} ({\tt P\_RESTART} in {\tt VLBARUN}) will clear away all
plot and calibration tables from your data set, leaving any flag tables.
Do not delete version one of the {\tt CL} and {\tt FG} tables since they
contain the initial calibration and on-line flagging information.

{\tt \Tndx{VLBAPIPE}} and {\tt \Tndx{VLBARUN}} will then run and produce
the requested number of diagnostic plots.  For details on the plots
produced for each level of {\tt DOPLOT} see {\tt EXPLAIN VLBAPIPE}.  If
an e-mail address is specified then a  {\tt VLBAPIPE DONE} or {\tt
VLBAPIPE FAILED} message will be sent.  However, the {\tt VLBAPIPE
FAILED} message will only be sent if {\tt VLBAPIPE} failed because of
problems with the inputs, if the pipeline failed because a task it was
running failed this message is not sent.  It is highly recommended that
the user read the explain file for {\tt \Tndx{VLBAPIPE}}\@.

A similar {\tt RUN} file named {\tt \Tndx{VLBAMPHC}} is available
to calibrate, flag, and image data sets for secondary phase stopping
centers when DiFX has been used to correlate multiple centers from a
single pointing.  A pipeline called {\tt \tndx{VLBARFI}} appeared in
{\tt 31DEC21}\@.  It calibrates a data set concentrating on the
autocorrelation data on which it performs a statistical analysis.
%\eject

\sects{Data Loading and Inspection}
\iodx{VLBI}

\begin{enumerate}

\item\ {Load the data using {\tt VLBALOAD} (which is a very simplified
{\tt FITLD}).  {\tt CLINT} should be set so that there are several
{\tt CL} table entries for each self-calibration or fringe-fitting
interval anticipated; this will minimize interpolation error during
the calibration process.  However, setting {\tt CLINT} too short will
result in a needlessly large table.  Somewhere between {\tt CLINT =
0.25} and {\tt CLINT = 1.0} is about right.  A {\tt FITLD} parameter
that is set automatically in {\tt VLBALOAD} is {\tt WTTHRESH = 0.7},
which results in irrevocable discarding of all data with playback
weight less than 0.7.  The only way around this is to use {\tt FITLD}
\Todx{VLBAUTIL}\Todx{VLBALOAD}}explicitly.  The data will be assigned
weights that reflect the playback weight plus the integration time and
channel bandwidth.  If you run {\tt FITLD} explicitly you may turn
this off with {\tt DOWEIGHT <= 0}.

\item\ Correct data with {\tt VLBAFIX}\@. {\it If
necessary}, {\tt VLBAFIX} sorts (with {\tt MSORT})\@, splits into
different frequencies (with {\tt UVCOP})\@, fixes the polarization
structure (with {\tt FXPOL}), and indexes (with {\tt INDXR}) the data.
{\tt VLBAFIX} will also correct for subarrays (with {\tt USUBA}), but
you must tell it to do so.  There are only 2 inputs of interest in
{\tt VLBAFIX}, {\tt CLINT}\@, the CL table interval, and {\tt
SUBARRAY} which should be set to 1 if there are subarrays and 0 if
not.  This is a very benign procedure, it can be run on
every data set read into \AIPS\ and will only perform the
necessary fixes.  Note that, if the data are split into different
frequencies, the flag table is applied and deleted.

\item\ {At this point it is a good idea to get a listing of the
antennas and scans in your data by running {\tt VLBASUMM}\@.  {\tt
VLBASUMM} runs {\tt PRTAN} over all antenna tables and {\tt LISTR}
with {\tt OPTYPE='SCAN'} and gives a choice of writing a text file to
disk or sending the listing to a printer.
\Todx{VLBAUTIL}\Todx{VLBASUMM}\Iodx{VLBI}}

\item\ {Apply corrections to the Earth Orientation Parameters (EOPs).
VLBI correlators must use measurements of the Earth Orientation
Parameters (EOPs) to take them out of the observations.  These change
slowly with time and therefore the EOPs used by the correlator must be
continually updated, and they are generally best two weeks or more after
the observation.  Since we try to correlate observations as quickly as
possible, it is likely that the EOPs used are not the most accurate.
Therefore it is recommended that all phase-referencing experiments be
corrected for this possible error.  The procedure{\tt VLBAEOPS} will do
this correction.  {\tt \tndx{VLBAEOPS}} automatically downloads a file
with correct EOPs and runs {\tt CLCOR} to correct the EOPs.  If the
automatic download does not work, {\tt VLBAEOPS} can use a file which
you have downloaded.  {\it Warning: this procedure does not work well
over concatenated data sets containing multiple days; uss {\tt CLCOR}
explicitly and set {\tt CLCORPRM(2)}.}}

\item\ {Apply ionospheric corrections, if desired, with
{\tt \tndx{VLBATECR}}\@.  This procedure automatically downloads
Global Positioning System (GPS) models of the electron content in the
ionosphere and uses them to correct the dispersive delays and Faraday
rotation caused by the ionosphere.  If the automatic download does not
work,  {\tt VLBATECR} can also use a file which you have downloaded,
This is particularly important for phase referencing and polarization
experiments at low frequency.  We recommend {\tt VLBATECR} for all
experiments at 8~GHz or lower. {\tt VLBATECR} is only as good as the
ionospheric model, so it is a very good idea to compare the corrected
and uncorrected phases using {\tt VPLOT}\@.  To inspect the phases using
{\tt VPLOT}, use options {\tt BPARM = 0, 2; APARM=0; DOCAL=1;
  GAINUSE={\it highest} CL {\it table}}\@.  The phases should not wind
as much (although they will probably not be completely flattened), when
the corrected {\tt CL} table is applied.  To see the corrections
themselves, use {\tt SNPLT} on the new {\tt CL} table setting {\tt
  OPTYPE = 'DDLY'}\@.  In {\tt 31DEC23}, tasks {\tt \tndx{MFIMG}} and
{\tt \tndx{TEPLT}} may be of interest after running {\tt
  \tndx{TECOR}}\@.}

\item\ {For a simple spectral-line data set, or any data set with high
spectral resolution, it is a very good idea to average the data set
to a smaller number of channels before deriving the calibration
parameters.  Otherwise, the calibration tasks may take forever to run.
It is recommended that you quickly inspect the channels of interest
for your line data (\eg\ with {\tt UVPLT}\@) for high points. Remove
obviously high amplitudes with {\tt CLIP} (or \eg\ {\tt UVMLN}, {\tt
  SPFLG}) before averaging.  Inspect the full resolution data also for
high delays and fringe rates.  Spectral averaging in such cases may
not be acceptable.  Continue calibration on the averaged data set as
if it were a continuum set.  There is a better method to calibrate
spectral line data described in \Sec{acfit} and \Sec{lineFRING}, but
the one used here is simpler and will usually give acceptable results.
To reduce the data-set size, run the task {\tt AVSPC} with {\tt
  AVOPTION = 'SUBS'}\@.  For example, to average IFs with $N_{\rm
  chan}$ down to 32 channels, set the adverb {\tt CHANNEL = $N_{\rm
    chan}/32$} (\eg\ to average from 2048 to 32 channels, use {\tt
  CHANNEL = 64}\@).\todx{AVSPC}}

\end{enumerate}

\Sects{Amplitude and Delay Calibration}{VLBAampcal}

Amplitude \indx{calibration} uses measured antenna gains and system
temperatures ($T_{\rm sys}$), as well as finding a correction for
voltage offsets in the samplers.  Even though this is substantially still
the case, we now recommend a somewhat different
amplitude calibration procedure than in the past based on VLBA Scientific
Memo \#37 (Walker 2015). \iodx{VLBI}

Before amplitude calibration is done, there must be information for
all antennas in the gain curve ({\tt GC}), system temperature ({\tt
  TY}), and weather ({\tt WX}) tables (weather tables are needed for
the opacity correction in {\tt APCAL}).  Missing $T_{\rm sys}$ and
gain curve information can usually be obtained in {\tt \tndx{ANTAB}}
format and loaded with the \AIPS\ task {\tt ANTAB}.  \Sec{nonvlba} has
information on including non-VLBA calibration information, if they are
not already included in the data.  \Sec{vlba+vla} has details on how
to incorporate the pre-EVLA \Indx{VLA} $T_{\rm sys}$ and gain curves.
Otherwise consult \Sec{antabformat}\@.

\begin{enumerate}

\item\ {Correct sampler offsets and apply amplitude calibration by
running {\tt VLBACCOR}\@.  The procedure {\tt VLBACCOR} runs
{\tt ACCOR}, {\tt SNSMO}, and {\tt CLCAL}. {\tt ACCOR} uses the
autocorrelation to correct the sampler voltage offsets.  After
{\tt ACCOR} creates an {\tt SN} table, {\tt SNSMO} smooths the table
in order to remove any outlying points.  Then the {\tt SN} table is
applied to the highest {\tt CL} table using {\tt CLCAL} (using {\tt
INTERPOL='2PT'}), and a new {\tt CL} table is created.}


\item\ {Next, the instrumental delay residuals must be removed.  These
offsets or ``instrumental single-band delays'' are caused by the
passage of the signal through the electronics of the VLBA baseband
converters or MkIII/MkIV video converter units.  There are two
different methods to remove these instrumental delays, one for the
case where you have pulse-cal information for some, but not
necessarily all, of your antennas; and one for the case where you have
no pulse-cal information at all.  Note that the preferred method for
continuum experiments is to use the pulse-cals, since they correct the
instrumental delay over the whole experiment, rather than on a short
scan.  Spectral-line observers would have switched off the pulse-cals
as they interfere with line observations, so they are forced to use
the second (strong source) method.  For VLBA continuum experiments
before April 1999, you can load the pulse-cal data using {\tt PCLOD};
consult the \Sec{vlblogs}\@.}
\begin{itemize}
\item\ {For the case where you have some pulse-cal information, run
{\tt VLBAPCOR}\@.  {\tt VLBAPCOR} is another procedure which runs
quite a few tasks, {\tt PCCOR}, {\tt CLCAL}, {\tt FRING} (sometimes)
and {\tt CLCAL} again (sometimes).  {\tt PCCOR} extracts pulse-cal
information from the {\tt PC} table and creates an {\tt SN} table.
Then {\tt CLCAL} is run to apply that {\tt SN} table to the highest
{\tt CL} table, creating a new {\tt CL} table.  If there are antennas
that do not have information in the {\tt PC} table, or their {\tt PC}
entries are wrong, then {\tt VLBAPCOR} can run {\tt FRING} on a short
calibrator scan (input {\tt TIMERANG})\@.  The {\tt SN} table from
{\tt FRING} contains corrections for the antennas left out of the {\tt
PC} table, and is applied to {\tt CL} table without corrections from
{\tt PCCOR}, and added to the {\tt CL} table with the {\tt PC}
corrections.  For the simplest case of all VLBA antennas, the inputs
for {\tt VLBAPCOR} should be {\tt TIMER={\it time range on} CAL-BAND
{\it with good fringes for all baselines}; REFANT=$n$; SUBARRAY=0;
CALSOUR='CAL-BAND''; GAINUSE=0; OPCODE=''; ANTENNAS=0}\@.  For the
case where you have the VLA (in this example antenna 11), which does
not have pulse-cals, your inputs should be the same as above except
{\tt OPCODE='CALP'; ANTENNAS=11,0}\@.  For the second case it is
important that there are no ``Failed'' solutions from {\tt
FRING}; if there are failed solutions, then you should delete the
tables that were created and find another {\tt TIMERANG} with good
fringes to the {\tt REFANT}.  Also see {\tt EXPLAIN VLBAPCOR} for a
detailed description of the steps involved with using pulse-cals
and {\tt FRING} without using {\tt
  VLBAPCOR}\@.\Todx{VLBAUTIL}\Todx{VLBAPCOR}\Iodx{VLBI}}

\item\ {The alternate method is to solve for the phase cals
``manually'' with {\tt VLBAMPCL}\@.  This method uses the fringes on a
strong source to compute the delay and phase residuals for each
antenna and IF\@. {\tt VLBAMPCL} runs {\tt FRING} to find the
corrections and then {\tt CLCAL} to apply them.  If there is no
calibrator scan that includes all antennas then there is an option to
run {\tt FRING} and {\tt CLCAL} again on another source and/or time
range in order to correct the antenna(s) not corrected by the first
scan. For the simplest case where all antennas have strong fringes to
{\tt CAL-BAND}, set {\tt TIMERANG = {\it time range of scan on
    calibrator with strong fringes to all antennas}; REFANT = $n$;
  CALSOUR = 'CAL-BAND'; GAINUSE = {\it highest} CL {\it table}; OPCODE
  = ''}.  There must be no ``Failed'' solutions from {\tt FRING}, if
there are any failed solutions the data from that antenna/IF will be
completely deleted from the data set.\Todx{VLBAMPCL}}

\item\ {Now you {\it must} check the results of correcting your
instrumental delays using {\tt \Tndx{VLBACRPL}} or {\tt POSSM}\@.  Set
{\tt GAINUSE={\it highest} CL {\it table}}, and plot
cross-correlations ({\tt VLBACRPL} will do this for you).  The plotted
cross-correlations should show the phase slope removed from each IF
and there should no longer be a phase jump between IFs, although the
phase does not have to be at $0^\circ$.  If you do a ``manual''
instrumental delay correction (\ie\ you used {\tt FRING}\@, not {\tt
PCCOR}); then the phases far in time from the scan on which {\tt
FRING} was performed may have a small slope and a small phase jump
between the IFs.  Also non-zero phase slopes still may be seen at low
elevations, where the atmosphere causes additional delay residuals, or
for low-frequency observations where the ionospheric delay varies.  If
you see significant phase slopes, or phase jumps between IFs on {\it
  any} baseline, then the instrumental phase corrections have not
worked and you need to figure out why and start
again.\Iodx{VLBA}\iodx{VLBI}}
\end{itemize}

\item\ {Next you must calibrate the bandpass shapes.  To do this, run
{\tt VLBABPSS} on the bandpass calibrator, {\tt CAL-BAND}\@.  Make
sure that the spectral line data for the bandpass calibrator are clean
and devoid of high points, using {\tt UVPLT} or {\tt SPFLG}\@.  Inputs
for {\tt VLBABPSS} are {\tt CALSOUR = 'CAL-BAND'} and a model for
your calibrator if you have one.  Then you must examine the {\tt BP}
table using {\tt POSSM} by setting {\tt
  APARM(8)=2}\@.\todx{VLBABPSS}}

\item\ {Now it is time to finish the amplitude calibration by running
{\tt \Tndx{VLBAAMP}}\@. This procedure runs several tasks: {\tt
  ACSCL}, {\tt SNSMO}, {\tt CLCAL}, {\tt APCAL} and {\tt CLCAL}\@.
After the previous steps the calibrated autocorrelation amplitudes
will be offset from unity; {\tt ACSCL} corrects this offset.  {\tt
  ACSCL} creates an {\tt SN} which is then smoothed by {\tt SNSMO} and
{\tt CLCAL} is run to apply the calibration to the next {\tt CL}
table.  Then to finalize the amplitude calibration, {\tt APCAL} is run
on the highest {\tt TY} and {\tt GC} tables, and a new {\tt SN} table
is created.  Adverb {\tt DOFIT} controls whether {\tt APCAL} also uses
the weather tables to fit and correct for opacity.  It is desirable to
perform an atmospheric opacity correction at high frequencies,
particularly if very accurate source fluxes are needed. See
\Sec{vlbcamp} for a more detailed discussion of {\tt APCAL}\@. Lastly,
{\tt VLBAAMP} runs {\tt CLCAL} to apply the amplitude calibration {\tt
  SN} table to the {\tt CL} created by the last run on {\tt CLCAL}\@.
{\tt VLBAAMP} will print messages telling you about the new tables it
has created. To keep track of your tables, it is important to copy
these messages.\Iodx{VLBA}\iodx{VLBI}\Todx{VLBAUTIL}}

\item\ {At this point it is a {\it very} good idea to examine your
calibration.}

\begin{itemize}

\item\ {Run the task {\tt SNPLT} or procedure {\tt VLBASNPL} (which is
a very simplified {\tt SNPLT}) to examine the tables created by {\tt
ACCOR}\@.  Use {\tt INEXT='CL'; OPTYPE= 'AMP'; INVERS=CL-{\it
table-with-sampler-offsets}; DOTV=1} (to display to the TV; for a
hardcopy use {\tt DOTV=-1} and {\tt LWPLA} to print the plot files).
The solutions that {\tt SNPLT} plots should be close to 1000 milligain
or 1 gain.\Todx{VLBASNPL}}

\item\ {Run {\tt SNPLT} or {\tt VLBASNPL} to examine the amplitude
calibration.  This time look at the {\tt SN} table that {\tt APCAL}
created.  Use {\tt INEXT='SN'; OPTYPE= 'AMP'; INVERS={\it highest} SN
{\it table}; DOTV=1} for {\tt VLBASNPL}; or to inspect IF $m$, use
{\tt BIF = $m$; EIF = $m$; OPTYP = 'AMP'; INVER = 0; INEXT = 'SN';
  OPCODE = '~'; NPLOT = 10; DOTV = 1; GO SNPLT}\@.  For a hard copy,
use {\tt DOTV = -1; GO SNPLT; GO LWPLA}\@.  Plotted amplitudes are the
square-roots of the system-equivalent flux densities (SEFDs), in
Jansky, where the SEFD is the flux density of a source that would
double the system temperature. (Low numbers are good!)  At centimeter
wavelengths, VLBA antennas have SEFDs near 300~Jy, so gains above
$30^\circ$ elevation should be near 17--18 and should vary slowly and
smoothly with time (\ie\ change in elevation) for an individual
source.  To look at the input system temperatures, run {\tt SNPLT}
with {\tt OPTYP = 'TSYS'; INEXT = 'TY'; INVER = 0}\@.  On rare
occasions, you might find clearly discrepant points that have leaked
in from a different frequency band. In that case, you can use task
{\tt SNEDT}, or the clipping option of {\tt SNSMO}, to get rid of the
bad points.  You may notice that at low elevations the gains on
individual antennas are high.  All data below a given elevation can be
flagged by running {\tt UVFLG};  \eg\ to flag all data below
$10^\circ$, run {\tt UVFLG} with {\tt APARM(4)=0} and {\tt APARM(5) =
10}\@.  Note that {\tt FG} tables are not applied to tables, so
flagged data still may have points plotted by {\tt SNPLT}\@.  The
$T_{\rm sys}$ measurements are also a very good diagnostic of bad data
from poor weather, equipment failures, {\it etc.}.  If there are time
ranges of unusually high or low $T_{\rm sys}$ you may consider
flagging those time ranges using {\tt UVFLG} or {\tt EDITA}\@.  Be
particularly suspicious of patches of unusual gains at only one IF or
{\tt STOKES} of an antenna.  Remember, one of the best things you can
do for your final result is to get rid of bad data.}

\item\ {You may wish to use your favorite method of inspecting data
for flagging (\eg\ {\tt EDITR}, {\tt SPFLG}, {\tt TVFLG}, {\tt
  IBLED})\@.  On-line flags are already included in {\tt FG} 1 unless
they were applied as the data were split into separate frequencies.
For example, run {\tt EDITR} with inputs {\tt SOURCES= 'CAL-BAND',''}
(do each source separately); {\tt DOCAL=1; GAINUSE={\it highest} CL
  {\it table}; FLAGVER=0; OUTFGVER=0; DOTWO=1;
  ANTUSE=1,2,3,4,5,6,7,8,9,10}\@.  Once you gain experience you might
want to set {\tt CROWDED=2 ; DO3COL=1} which allows 3-color displays
of all polarizations and IFs in one plot with a faster method for the TV
displays; this can speed up editing significantly.  Look for anomalously
high or low amplitudes, remember there can be a slow change in amplitude
with time due to source structure.  Some people do no additional
flagging at this stage, but later use the results of fringe-fitting and
visibility plots of calibrated data to point the way to bad
data.\iodx{editing}\todx{EDITR}}
\end{itemize}

\item\ {For spectral-line experiments needing velocity accuracy better
than 1 km/s, a Doppler correction should be performed.  Use {\tt
CVEL}; see \Sec{vlbBPcal} and \Sec{cvel} for details.}

\item\ {This is a useful time to run {\tt TASAV} to save all your
ancillary tables to another file.  If you foul up the calibration, the
relevant tables can be copied back using {\tt TACOP}\@.\todx{TASAV}}

\end{enumerate}

\vfill\eject
\Sects{Rate and Phase Calibration}{VLBAd+r+p}

Now that the data have calibrated amplitudes, the next step is to do
the calibration of the antenna rates and phases.  This
section describes that process.\Iodx{VLBA}\iodx{VLBI}

\begin{enumerate}

\item\ {Correct the antenna parallactic angles, if desired, using
{\tt VLBAPANG}\@.  The RCP and LCP feeds on alt-az antennas will rotate
in position angle with respect to the source during the course of the
observation (all VLBA and VLA antennas are alt-az).  Since this
rotation is a simple geometric effect, it can be corrected by
adjusting the phases without looking at the data.  You {\it must} do
this correction for polarization experiments and phase referencing
experiments. Parallactic angles are important for phase referencing
because the parallactic angle difference between calibrator and target is
different at different stations which leads to an extra phase error which
can be corrected.  {\tt VLBAPANG} copies the highest numbered {\tt CL}
table with {\tt TACOP} and then runs {\tt CLCOR} ({\tt OPCODE = 'PANG';
CLCORPRM = 1,0}).  {\tt VLBAPANG} has no inputs that require
discussion.  Be sure to correct the parallactic angles before any of
the following steps.  Again keep track of which {\tt CL} tables add
which correction.\Todx{VLBAPANG}}

\item\ {Now you must remove global frequency- and time-dependent phase
errors using {\tt FRING} or one of the procedures which use this task,
{\tt VLBAFRNG} or {\tt VLBAFRGP}\@. This cannot be done simply for
spectral-line sources, so the practice here is to determine delay and
rate solutions from the (continuum) phase-reference sources and
interpolate them over the spectral line observations.  The procedures
run {\tt FRING} along with {\tt CLCAL}\@.  {\tt VLBAFRNG} and {\tt
  VLBAFRGP} use {\tt FRING}, with {\tt VLBAFRGP} specifically for
phase referencing.  For all these procedures, if the {\tt SOURCES}
adverb is set, then {\tt CLCAL} is run once for each source in {\tt
  SOURCES}\@.  For the phase-referencing procedure ({\tt VLBAFRGP}),
any source that is in the {\tt SOURCES} list that is {\it not\/} in
the {\tt CALSOUR} list will be phase referenced to the {\it first}
source in the {\tt CALSOUR} list.  These procedures will produce new
(highest numbered) {\tt SN} and {\tt CL} tables.  Since it is probably
best to run {\tt CLCAL} on each source separately, {\tt SOURCES}
should always be set.  To use {\tt VLBAFRGP} for a simple phase
referencing experiment (remember that {\tt CAL-PHASE} is the phase
reference calibrator), set {\tt
  CALSOUR='CAL-PHASE','CAL-BAND','CAL-AMP','CAL-POL','STRONG';
  GAINUSE={\it highest} CL {\it table}; REFANT=$n$; SEARCH 9 4 1 3 5 6 7
8 10; SOLINT={\it coherence time}; DPARM(7)=1} {\it (if a polarization
experiment)}; {\tt SOURCES='CAL-PHASE', 'CAL-BAND', 'CAL-AMP',
'CAL-POL', 'STRONG','TARGET'; INTERPOL='SIMP'.}  For this example, {\tt
FRING} will be run on the sources in {\tt CALSOUR} and then {\tt
CLCAL} will be run 6 times, with all of the sources except {\tt TARGET}
referenced to themselves and {\tt TARGET} referenced to {\tt CAL-PHASE},
using interpolation method {\tt SIMP}\@.  For a non-phase-referencing
experiment you would use {\tt VLBAFRNG} with inputs the same as above
except for {\tt SOURCES}, which would not contain {\tt TARGET}\@.  The
results will be the highest {\tt SN} and {\tt CL} tables.  The {\tt
INTERPOL} to use is a personal preference.  You might want to
restrict the channel range slightly using {\tt BCHAN} and {\tt ECHAN},
since the channels at the high end of each IF will have lower SNR, due
to the cutoffs in the bandpass filters.  For a data set with 16
channels per IF, numbered from 1 to 16, setting {\tt ECHAN} to 14 or
15 may be worth trying.  Note that some people like to run {\tt CALIB}
rather than {\tt FRING} or {\tt KRING} for this stage of
phase-referencing observations, but fringe fitting is recommended, as
it solves for rates.\Todx{VLBAUTIL}
\Todx{VLBAFRNG}\Todx{VLBAFRGP}

The above fringe fit may take a bit of time, depending on the
computer and the spectral resolution.  Then, use {\tt SNPLT} or {\tt
VLBASNPL} to inspect the solutions in the {\tt SN} table.  It's not
totally out of the question that some data will be found that need
flagging, which can be done with {\tt UVFLG}\@.  In that case, it's a
good idea to delete the last {\tt SN} and {\tt CL} table and re-run
{\tt VLBAFRGP} or {\tt VLBAFRNG}\@.

This \indx{fringe-fitting} stage is the most likely place
where things can go wrong, for reasons that are not immediately
apparent to the observer.  Below, a few common examples are listed.
\iodx{calibration}\iodx{VLBI}\Iodx{VLBA}}

\begin{itemize}

\item\ {{\bf Many solutions failed.}  The source may be too weak, or
the coherence time too short.  Try increasing or decreasing {\tt
SOLINT}\@.  Or narrow the search window.  For most VLBA data, {\tt
DPARM(2) = 400} and {\tt DPARM(3) = 60} should be a good first step,
though the rate window specified in {\tt DPARM(3)} is proportional to
the observing frequency, and may need to be larger at 22~GHz and
above. For more options you could try
running {\tt FRING} and reduce the SNR threshold with {\tt
APARM(7)} or averaging the RR and LL ({\tt APARM(3)=1})\@.
One last thing to try is to abandon {\tt FRING} and
solve for the phases in {\tt CALIB}, obviously not ideal since you
will not get rates or delays, but it is a hit worth taking if the
the calibration can be salvaged.}

\item\ {{\bf Some antenna has low SNR, and may cause an entire set of
solutions to go bad.} This typically happens because an antenna should
have been flagged.  A common cause is when OV is looking at the White
Mountains, and neither the on-line system nor the astronomer has
flagged the data.  Then, you need to run {\tt UVFLG} and re-run {\tt
VLBAFRGP} or {\tt VLBAFRNG}\@.}

\item\ {{\bf There are discrepant delay/rate solutions.} Look at the
solutions you believe, and try  {\tt VLBAFRGP} or {\tt VLBAFRNG} again
with {\tt DPARM(2)} and {\tt DPARM(3)} specified appropriately.  Full
widths are specified, so if the good solutions fall between $+15$~mHz
and $-15$~mHz, use {\tt DPARM(3) = 30}\@.  (Actually, you should use a
value somewhat larger to allow some margin.)  It may be that an
antenna is suffering from radio-frequency interference, so some
channels and/or IFs will need to be flagged.}

\item\ {{\bf Some solutions are outside the specified delay/rate
range.}  This can happen because the initial coarse fringe search uses
the range specified by {\tt DPARM(2)} and {\tt DPARM(3)}, but the
least-squares solution can take off from there and go elsewhere.}

\item\ {{\bf Delays and rates for some station change rapidly near the
beginning or end of the observation.}  This may be caused by low
elevation at the relevant station.  Depending on how desperate you are
to include low-SNR data, you may wish to flag some time range, or flag
all data at elevations below $5^\circ$, $10^\circ$ or even $20^\circ$
(particularly at high frequencies or for phase referencing)
with {\tt UVFLG}\@.}

\item\ {{\bf Phases wrap rapidly, particularly on the phase-reference
source, CAL-PHASE\@.}  There may not be a lot you can do about this
initially, because it's possible that the tropospheric delay just
changed too fast for the cycle time used in the observation,
especially at low elevation.  However, you may wish to note the times
and antennas when the phase connection is best (typically the
southwestern antennas near transit).  Later, when imaging the program
source, it can be helpful to image with a subset of antennas and time
ranges, then use that initial image to self-calibrate the rest of the
data.}

\end{itemize}


\item\ {Use {\tt SNPLT} or {\tt VLBASNPL} to inspect the interpolation
of the phases in the {\tt CL} table\@.  When you inspect the {\tt CL}
table notice any phase wraps that seem out of place. The human eye is
better at pattern matching than a computer and these phases may be in
error.  You can use {\tt \tndx{SNBLP}} to examine the phase solutions
on a baseline basis (as they actually affect the visibilities).  This
may make problems more apparent.  If so you might want to run {\tt
  CLCAL} independently and try another interpolation method or you
might want to edit the {\tt CL} table.  Remember that this is your
last calibration table; you want to get rid of any bad calibration now
before applying it to the data.  Getting rid of spurious wraps in the
final {\tt CL} table ({\tt SNEDT}) or flagging the data associated
with fast changing phases ({\tt SNFLG}) will improve your final image
more consistently than anything else, {\it particularly} for phase
referencing.\Todx{VLBAUTIL}\Todx{VLBASNPL}\Iodx{VLBI}}

\end{enumerate}

\Sects{Final Calibration Steps}{VLBAfinal}

\begin{enumerate}

\item\ {If you used {\tt AVSPC} to reduce the size of the data set
used in determining \indx{calibration}, you must copy your final
calibration tables back to the full-size data set.  This can be done
with task {\tt TACOP}\@.  For bookkeeping purposes, it may be best to
copy over all the {\tt CL} tables with the same table numbers in both
the averaged and un-averaged data sets. Copy the {\tt FG} table as
well, since  any data which are bad in the averaged data set will be
bad in the full resolution data set.  After inspecting the data with
{\tt UVPLT} or {\tt VPLOT}, run {\tt EDITR}, {\tt TVFLG}, {\tt CLIP},
{\tt SPFLG}, or other data editor to edit the bad data from the
calibrated spectral-line data set.}

\item\ {After you have corrected the bandpass for spectral line data,
you may want to correct for the change in frequency by the motion of the
antennas with respect to the Sun {\it etc.}. This is done with {\tt
CVEL}, after the source velocities are entered in the {\tt SU} table
with {\tt SETJY}\@.  For a detailed description see \Sec{cvel}\@.\@}

\item\ {Polarization calibration still remains, if desired, and if all
the appropriate calibration sources were observed.  This can be done
in a variety of ways; see \Sec{phasecal} for details.\iodx{VLBI}}

\item\ {Finally, apply the calibration to the visibility data and make
single-source data sets using {\tt SPLIT}\@.  (Some people
might wish to use {\tt SPLAT} to average over time as well as spectral
channel.) Inputs for a continuum observation are {\tt SOURCES = '~';
BIF = 0; EIF = 0; DOPOL = -1} (or 1 if polarization calibration was
attempted){\tt ; DOBAND = 1; DOUVCOMP = 1; NCHAV = 0; APARM = 2,0;
DOCALIB = 1; GAINUSE = {\it highest} CL {\it table}}\@.  For a
spectral-line observation, set {\tt APARM = 0}, because you don't want to
average over frequency.  Use {\tt OUTDISK} and {\tt OUTCLASS} as
appropriate for your computer and record-keeping purposes.\todx{SPLIT}}

\end{enumerate}

The single-source data sets are now ready for imaging and possible
self-calibration.  At this point, it is a good idea to look at the
amplitude check source `CAL-AMP' using tasks such as {\tt UVPLT}, {\tt WIPER}
or {\tt VPLOT} in order to see if there are any antenna gain calibrations that
must be adjusted.  Doing a {\tt WIPER} for each target source is a
good idea also, because there may be discrepant amplitude points due
to interference or poor fringe fits (among other things).  The task
{\tt WIPER} makes {\tt UVPLT} like plots but is designed to do flagging.

\Sects{Incorporating non-VLBA antennas}{nonvlba}

Many non-VLBA telescopes have their amplitude calibration incorporated
in the tables loaded by {\tt FITLD}\@. We retain the following sections
for the case where some telescopes are not included in calibration
tables for whatever reason.

The phased-EVLA came on-line in February 2013.   Its calibration is
very different from the old VLA.  With the phased-EVLA either an {\tt
ANTAB} style file was provided to the observer or the calibration
information is attached to the data.  This calibration is generated from
the switched power measurements attached to the EVLA only data.
There is no need for special calibration steps.  However, the observer may
wish to improve the calibration by editing the switched power and recreating
the {\tt ANTAB} style file.  More information on this can be found in
\Sec{vlamp}.  There is a separate section (\Sec{vlba+vla}) dealing with
pre-EVLA VLA data.

\Subsections{Loading $T_{\rm sys}$ and Gain Curves}{tsys}

Most telescopes that do not have $T_{\rm sys}$ and gain curve
information attached to the data will provide the user with a text
{\tt ANTAB} format file that can be loaded with {\tt ANTAB}\@.  Please
see {\tt EXPLAIN ANTAB} for more information on the {\tt ANTAB}
format. \todx{ANTAB}  Follow the steps below to load calibration
information and amplitude calibrate the data.
\begin{enumerate}

\item\ {To prevent any chance of having to re-run {\tt FITLD},
first save the VLBA {\tt TY} and {\tt GC} (and all your other)
tables by running {\tt TASAV}\@.  Then run {\tt ANTAB} with {\tt CALIN}
set to the {\tt ANTAB} file and setting {\tt TYVER} and {\tt GCVER}
to the highest numbered tables (usually 1).  You don't want to leave
{\tt TYVER} and {\tt GCVER} equal to 0 because that causes {\tt ANTAB}
to create new {\tt TY} and {\tt GC} tables with only the antennas in the
file you are loading.  If {\tt ANTAB} fails, it is
most likely caused by the input file not being formatted correctly.
Perhaps you needed to add an {\tt INDEX} entry or the file wasn't in true
{\tt ANTAB} format.  Also, if {\tt ANTAB} fails check that the {\tt TY}
and {\tt GC} tables have not been corrupted.  If they have you should
delete the tables and copy the original tables from the {\tt TASAV}'ed
file with {\tt TACOP}}\@.

\item\ {Now, run {\tt VLBAAMP} as described in \Sec{VLBAampcal} to
combine the gain and system temperature information for all antennas
into the appropriate {\tt SN} and {\tt CL} tables.  Then, use
{\tt SNPLT} or {\tt VLBASNPL} as described in \Sec{VLBAampcal} to make
sure that the resulting {\tt SN} now contains amplitude calibration
for all the antennas and IFs included in the project.\todx{VLBACALA}}

\end{enumerate}

\Subsections{Pointing Flags}{ptflags}

The VLA, GBT, AR and possibly other telescope's on-line systems produce
only recorder-related flags, not pointing flags.  Thus, for example, there
are no flags for when the telescope is not on-source.  This can lead to a
large amount of bad data  especially if you are changing source frequently.
However, the \Indx{VLBI} scheduling program {\tt SCHED} creates a {\tt *.flag}
file which contains estimates of how long it takes these antennas to
slew.  The {\tt *.flag} file will also contain flags for all
antennas in the experiment, so it is best to remove the flags that
pertain to the VLBA antennas.  The flag file can be read in with {\tt
UVFLG} using the {\tt INTEXT} adverb.

\Sects{Pre-EVLA VLA data}{vlba+vla}

{\bf The method described in this section is only meant for VLA data
from before February 2013 (before the phased-EVLA came on-line).}
The observation being calibrated may have incorporated either a single
\indx{VLA} antenna or the phased VLA, but the amplitude
\indx{calibration} parameters for the VLA were not transferred
automatically.  You will need to obtain an input text file for the VLA
then run {\tt ANTAB} before {\tt APCAL}\@.  Before February 2013,
the gains and system temperatures for this file, in an appropriate
format, were supplied in a file called {\tt {\it xxxxx}cal.y.gz'},
where {\tt `{\it xxxxx}'} is the observation code (\eg\ `bm120'),
located at {\tt https://www.vlba.nrao.edu/astro/VOBS/astronomy/mmmyy/xxxxx/}.
That file contains instructions on editing the file to get correct
inputs.  For a phased array or a 1.3-cm observation in which 3
antennas are used, follow the instructions in \Sec{VLBA+y27}; for a
single antenna, use \Sec{VLBA+y1}\@.\iodx{VLBI}

\Subsections{Single VLA Antenna}{VLBA+y1}

{\bf The method described in this section is only meant
for VLA data from before February 2013.}
Depending on the age of your observation, you may have to add an
{\tt INDEX} entry within the {\tt TSYS}
card ({\bf Do not separate the {\tt INDEX} entry from the {\tt TSYS}
entry by a ``/'' !!!}), un-comment the {\tt GAIN} line for your
particular observing frequency, and un-comment the {\tt TSYS} line.
There are examples of {\tt INDEX} entries in the comments at the head
of the file.

Beginning in June 2003, the {\tt INDEX}, {\tt GAIN}, and {\tt TSYS}
information in this table are reformatted to be directly acceptable to
\AIPS\@.  You should check the times in the text file to make sure
that your observation has been properly described.  Only a few special
cases will require editing of the file; in most cases you are able to
invoke {\tt ANTAB} with no editing.  Once you are satisfied with the
{\tt ANTAB} file, load the data following the directions in \Sec{tsys}.

\Subsections{Phased VLA}{VLBA+y27}

{\bf The method described in this section is only meant
for phased-VLA data from before February 2013.}
The VLA may be phased on a program source (`STRONG'), or may be phased on a
phase-reference source (`CAL-PHASE'), with the resulting solutions
applied to the program source (`TARGET').  Rather than recording a
system temperature, the VLA system will record a ratio of antenna
temperature to system temperature, which will vary as the array phases
up.  In order to convert the ratio of antenna and system temperatures
to a  usable gain, the flux density of some source will be needed.
\Iodx{VLBA}\iodx{VLBI}

\begin{enumerate}

\item\ {Load and calibrate the VLA data by standard means (see
\Rchap{cal} and \Rappen{Olderdata}).  Determine the flux density of a
relevant strong source, usually either `STRONG' or `CAL-PHASE'\@.
Then, on the VLBI data set, insert the flux density of this source
into the {\tt SU} table using {\tt SETJY}\@.  For example, if the
source is `CAL-PHASE' and its flux density is 0.432 Jy, run {\tt
  SETJY} with {\tt SOURCES = 'CAL-PHASE'; BIF = 0; EIF = 0; ZEROSP =
  0.432,0; OPTYPE = '\ '}\@.}

\item\ {Edit the input file as indicated above for a single VLA
antenna.  Again, an {\tt INDEX} line, a {\tt GAIN} line, and a {\tt
TSYS} line must be checked (after June 2003) or be created or
un-commented.  The {\tt GAIN} line is independent of observing band
(the source flux is used to determine the gain), and the {\tt TSYS}
line should include the parameter {\tt `SRC/SYS'}, indicating that the
ratio of antenna temperature to system temperature is being supplied.}

\item\ {Run {\tt ANTAB} to read in the input file of amplitude
\indx{calibration} parameters.  Then run {\tt VLBACALA} to put this in
an {\tt SN} table.  Both steps are essentially the same as for a
single VLA antenna (see \Sec{VLBA+y1}).  The most likely problem is
that {\tt APCAL} in {\tt VLBACALA} will fail because you forgot to
enter a source flux density using {\tt SETJY}, although the error
message may not always make this obvious.\todx{ANTAB}\Todx{VLBACALA}}

\item\ {Run {\tt VLBASNPL} or {\tt SNPLT} to inspect the resulting
{\tt SN} table, as for the single VLA antenna.  In this instance, you
should see that the phased \indx{VLA} is very sensitive.  If the
phasing worked well at centimeter wavelengths, the amplitude should be
near 4 or 5 instead of the value of 17 or 18 seen for a single VLBA
antenna.  At the start of scans where the VLA is being phased, you may
see a rapid change in the amplitude gain (toward smaller numbers) as
the antenna phases are brought into alignment. The {\tt SN} table
should be inspected very carefully, because there may be data that
should be flagged when the VLA phasing did not work well.  Three
possible reasons for poor phasing are (1) the source is too weak; (2)
the troposphere is misbehaving; or (3) there was radio-frequency
interference at the VLA\@.}

\end{enumerate}

\sects{Summary for non-VLBA antennas}
Following the insertion of the amplitude solutions for the non-VLBA
antennas, you can return to follow the standard path for calibration
of \Indx{VLBA} data.  Although the procedures from here on are identical
to the VLBA-only case, the observer may wish to pay attention to several
issues.\iodx{VLBI}

\begin{enumerate}

\item\ {Many non-VLBA antennas are more sensitive than a single VLBA
antenna, it can be a good idea to use the most sensitive antenna as the
reference antenna for fringe-fitting.}

\item\ {Non-VLBA antennas may have a larger delay offset than VLBA
antennas.  The user should pay close attention to the fringe
fits, and be aware of the possibility that non-VLBA antennas may have
larger residual delays and rates than a VLBA antenna.}

\item\ {Many non-VLBA antennas do not slew as rapidly as the VLBA\@.
The {\tt FG} table supplied by calibration transfer may not include all
the on-line flags, and may not incorporate information about the pointing
of non-VLBA antennas, and when they arrive on source.  Therefore, some
judicious flagging by the user may be necessary.  See \Sec{ptflags} for
a discussion of applying flags produced by the scheduling software SCHED.}

\item\ {The elevation limit for non-VLBA antennas is generally different
and usually higher than the VLBA's limit ($> 2^\circ$)  which may
cause sources to rise and set at different antennas at different times.
For example, the VLA has an elevation limit of  $8^\circ$, this means that a source
will rise later and set earlier at the VLA than it does at Pie Town or Los Alamos.}

\end{enumerate}

\sects{Some Useful References}

\begin{enumerate}

\item\ {Chatterjee, S., ``Recipes for Low Frequency \indx{VLBI}
Phase-referencing and GPS Ionospheric Correction,'' \Indx{VLBA}
Scientific Memo No.~22, May 1999.\hfill\break
{\tt https://library.nrao.edu/vlbas.html}}

\item\ {Ulvestad, Jim, ``VLBA Calibration Transfer with External
Telescopes, Version 1.1,''  VLBA Operations Memo No.~34, July 30,
1999. {\tt https://library.nrao.edu/vlbao.shtml}}

\item\ {Ulvestad, Jim, ``A Step-By-Step Recipe for VLBA Data
Calibration in \AIPS\, Version 1.3'' VLBA Scientific Memo No.~25 (the
basis of this appendix), January 2, 2001.\hfill\break
{\tt https://library.nrao.edu/vlbas.html}}

\item\ {Ulvestad, Jim, Greisen, Eric W., Mioduszewski, Amy
``\AIPS\ Procedures for Initial VLBA Data Reduction, Version
2.0'' \AIPS\ Memo No.~105 April 26, 2001.\hfill\break
{\tt https://www.aips.nrao.edu/aipsdoc.html \# MEMOS}}

\item\ {Wrobel, J. M., Walker, R. C., Benson, J. M., \& Beasley, A. J.,
``Strategies for Phase Referencing with the VLBA,'' VLBA Scientific
Memo No.~24, June 2000.\hfill\break
{\tt https://library.nrao.edu/vlbas.html}}

\end{enumerate}

\sects{Additional recipes}

% chapter C *************************************************
\recipe{Orange baked bananas}

\bre
\Item {Mix in a saucepan 1/2 cup firmly packed {\bf brown sugar},
         1 tablespoon {\bf cornstarch}, 1/8 teaspoon {\bf cinnamon},
         and a few grains {\bf salt}.}
\Item {Add gradually, blending in 3/4 cup boiling water.}
\Item {Bring rapidly to boiling and cook about 5 minutes or until
         sauce is thickened, stirring constantly.}
\Item {Remove from heat and blend in $1 {1\over2}$ teaspoons grated
         {\bf orange peel}, 1/4 cup {\bf orange juice}, 1 teaspoon
         {\bf lemon juice}, and 2 tablespoons {\bf butter}.}
\Item {Peel and cut into halves lengthwise 6 {\bf bananas} with
         all-yellow or green-tipped peel.}
\Item {Arrange halves cut side down in baking dish and brush with
         about 2 tablespoons melted {\bf butter}.}
\Item {Sprinkle 1/2 teaspoon {\bf salt} over bananas and then pour
         the orange sauce over bananas.}
\Item {Bake at \dgg{375} for 10 to 20 minutes.}
\ere
\vfill\eject

% chapter  *************************************************
\recipe{Mexican chicken vegetable soup with bananas}

\bre
\Item {In large, covered kettle, over medium-low heat, simmer 4 pounds
     cut up {\bf stewing chicken}, 1/c cup coarsely  chopped {\bf
     onion}, 1 teaspoon {\bf salt}, and 4 cups of hot {\bf water} for
     2 hours or until chicken is tender.}
\Item {Remove chicken to cutting board; cut meat from bones into
     chunks; discard bones. Skim any fat from surface of broth.}
\Item {Add chicken, 1/2 cup chopped {\bf celery}, 1 12-ounce can
     whole-kernel {\bf corn} and 1 16-ounce can {\bf tomatoes} to
     soup. Continue simmering, covered for 10 minutes. Season to
     taste.}
\Item {Five minutes before serving, peel 4 firm (green-tipped) {\bf
     bananas}, slice diagonally into 1-inch slices. }
\Item {Add sliced bananas to soup, continue cooking just until bananas
     are tender.  Serve immediately.}
\item[ ]{\hfill Thanks to Turbana Corporation ({\tt www.turbana.com}).}
\ere

% chapter *************************************************
\recipe{Orange gingered bananas}

\bre
\Item {Combine in a small saucepan 1/4 cup {\bf orange juice}
   and 1/2 teaspoon {\bf cornstarch}.  Cook and stir over medium heat
   until boiling.}
\Item {Add 1/4 cup {\bf orange juice}, 1 1/2 teaspoons {\bf
   honey}, and 1 1/2 teaspoons chopped {\bf crystallized ginger} and
   cook, stirring, until thoroughly heated.}
\Item {Place 2 peeled, green-tipped {\bf bananas} in a shallow
   baking dish and cover with sauce.}
\Item {Bake at $350\deg$ about 15 minutes or until the bananas are
   tender (but not soft), basting with the sauce several times.}
\ere

% chapter  *************************************************
\recipe{Frozen Push-Ups}

\bre
\Item {Peel 2 {\bf bananas} and slice into blender or
    food processor.}
\Item {Add 1 6-ounce can frozen {\bf orange juice} (thawed), 1/2
    cup instant non-fat {\bf dry milk}, 1/2 cup {\bf water}, and 1 cup
    plain low-fat {\bf yogurt}.}
\Item {Cover and blend until foamy.  Pour into small paper cups
    and freeze.}
\Item {To eat, squeeze bottom of cup.}
\item[ ]{\hfill Thanks to Ruthe Eshleman {\it The American Heart
     Association Cookbook}.}
\ere

% chapter *************************************************
\recipe{Banana mallow pie}

\bre
\Item {Combine 2 cups {\bf vanilla wafer} crumbs and 1/3 cup melted
     {\bf butter}.  Press into 9-inch pie plate and bake at \dgg{375}
     for 8 minutes.}
\Item {Prepare a 3 1/8 ounce package {\bf vanilla pie filling} using 1
     3/4 cup {\bf milk}.  Cover surface with transparent wrap and
     chill.}
\Item {Fold 1 1/2 cups {\bf mini-marshmallows} and 1 cup {\bf Cool
     Whip} into pie filling.}
\Item {Slice 2 {\bf bananas} into pie crust, pour filling over
     bananas, and chill several hours or overnight.}
\ere
%\eject

