; APGPS
;---------------------------------------------------------------
;! Apply GPS-derived ionospheric corrections
;# Task Calibration VLA
;-----------------------------------------------------------------------
;;  Copyright (C) 1996-1998, 2019
;;  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
;-----------------------------------------------------------------------
APGPS     LLLLLLLLLLLLUUUUUUUUUUUU CCCCCCCCCCCCCCCCCCCCCCCCCCCCC
APGPS     Task to apply ionospheric delay and Faraday rotation
          corrections derived from GPS measurements
INNAME                             Input UV file name (name)
INCLASS                            Input UV file name (class)
INSEQ             0.0     9999.0   Input UV file name (seq. #)
INDISK            0.0        9.0   Input UV file disk unit #
ANTENNAS                           Antennas to correct
SUBARRAY          0.0     9999.0   Subarray to correct
                                   0 -> all
OPCODE                             Corrections to apply
                                   'IFR ' - Faraday rotation
                                            only
                                   'DISP' - dispersive delay
                                            and Faraday rotn
                                   default: IFR only
INVERS                             Version number of GP table
                                   containing GPS data
GAINVER                            Input CL table version
GAINUSE                            Output CL table version
PRTLEV                             Print level
                                      0 -> none
                                      1 -> solutions
                                      2 -> more detail
----------------------------------------------------------------
APGPS
Task:   Uses GPS delay data stored in a GP table to calculate phase
        corrections due to the excess path length of the ionosphere
        and to calculate the ionospheric Faraday rotation.  Moving
        sources are supported if there is a PO table.

Adverbs
  INNAME.....Input UV file name (name).      Standard defaults.
  INCLASS....Input UV file name (class).     Standard defaults.
  INSEQ......Input UV file name (seq. #).    0 => highest.
  INDISK.....Disk drive # of input UV file.  0 => any.
  ANTENNAS...List of antenna numbers to correct. If all of the
             entries are zero then ionospheric corrections will
             be generated for all antennas. If any of the
             entries are not blank then corrections will only be
             generated for those antennas with numbers listed in
             this array unless at least one entry is negative
             when corrections will be generated for all antennas
             except those whose numbers correspond to the
             absolute values of the non-zero entries.
  SUBARRAY...Subarray to correct. Corrections will only be
             generated for the subarray with this number unless
             this number is zero, in which case all antennas
             matching the ANTENNAS selection will be corrected
             in all subarrays.
  OPCODE.....Type of corrections to generate. If this is 'DISP'
             then both dispersive delay and ionospheric
             Faraday rotation corrections will be generated
             otherwise only ionospheric Faraday corrections
             will be generated.
  INVERS.....Version number of GP table.  0 => highest
  GAINVER....Version number of CL table to use.   0 => highest
             (used to define times at which corrections are
             calculated)
  GAINUSE....Version number of output CL table.   0 => new
  PRTLEV.....Print level
                0 => no printout (default)
                1 => model TEC, gradients in latitude and
                     longitude and residual sum of squares
----------------------------------------------------------------
APGPS:  Calculate ionospheric Faraday rotation and delay from
        GPS data
Documentor: Chris Flatters
Related Programs: LDGPS

APGPS fits a simple model of the total electron content of the
ionosphere to GPS delay data and uses this model to calculate
corrections for the ionospheric Faraday rotation and delay.
The model is parameterized by the total electron content at the
zenith above the GPS receiver and linear gradiants in latitude
and longitude.  This isa  reasonable model only for reasonably
compact arrays situated close to a GPS receiver.

If you use APGPS for arrays more than a few kilometers in size,
you should use ANTENNAS to make sure that corrections are only
applied to antennas close to the receiver. If you have data from
more than one receiver then you can run APGPS for each receiver,
selecting a different set of antennas for each run.

This program is primarily intended to correct VLA data using
data from GPS receivers at the VLA site.

                             PRINTOUT

If PRTLEV is set to 1 or a greater value then APGPS will
print out

- the model TEC at the zenith,
- the TEC gradients in latitude and longitude,
- the residual sum of the squares, and
- the fractional error bound

every time it recalculates the ionospheric model.  If the
true ionospheric model is characterized by a vector x
(with x(1) = TEC, x(2) = gradient in longitude, x(3) = gradient
in latitude) and the model calculated by APGPS is x' then
the fractional error that is printed is an upper bound on

      || x - x' || / || x ||

where || x || denotes the L2 norm (or the sum of the squares)
of x.

The residual sum of the squares and the error bound may help
in finding poor solutions.

If PRTLEV is set to 2 or more then APGPS will also print out
the model zenith TEC for each satellite that provided data in
the solution interval (identified by PRN) and the mean and
standard deviations of the measured zenith TECs.
