; UVIMG
;---------------------------------------------------------------
;! Grid UV data into an "image"
;# TASK UV IMAGING
;-----------------------------------------------------------------------
;;  Copyright (C) 1995, 1997, 2000, 2003-2004, 2006, 2009-2010,
;;  Copyright (C) 2015-2017
;;  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
;-----------------------------------------------------------------------
UVIMG     LLLLLLLLLLLLUUUUUUUUUUUU CCCCCCCCCCCCCCCCCCCCCCCCCCCCC
UVIMG:  Task to grid UV data into an "image"
INNAME                             UV data (name).
INCLASS                            UV data (class).
INSEQ             0.0    9999.0    UV data (seq. #).  0 => high
INDISK                             Disk unit #.       0 => any
OUTNAME                            Image data (name).
OUTCLASS                           Image data (class).
OUTSEQ            0.0    9999.0    Image data (seq. #). 0=>high
OUTDISK                            Disk unit #.       0 => any
SOURCES                            Source list
TIMERANG                           Time range to list
STOKES                             Stokes type to list.
SELBAND                            Bandwidth to select (kHz)
SELFREQ                            Frequency to select (MHz)
FREQID                             Freq. ID to select.
BIF               0.0      100.0   Lowest IF number 0=1
EIF               0.0      100.0   Highest IF number
BCHAN             0.0     2048.0   Low channel number 0=>1
ECHAN             0.0     2048.0   High channel number
ANTENNAS                           Antennas to list
BASELINE                           Baselines with ANTENNAS
UVRANGE           0.0              UV range in kilolambda
SUBARRAY          0.0     1000.0   Subarray, 0=>1
                                   Cal. info for input:
DOCALIB          -1.0      101.0   > 0 calibrate data & weights
                                   > 99 do NOT calibrate weights
GAINUSE                            CAL (CL or SN) table to apply
DOPOL            -1.0       10.0   If >0 correct polarization.
PDVER                              PD table to apply (DOPOL>0)
BLVER                              BL table to apply.
FLAGVER                            Flag table version
DOBAND           -1.0       10.0   If >0 apply bandpass cal.
                                   Method used depends on value
                                   of DOBAND (see HELP file).
BPVER                              Bandpass table version
SMOOTH                             Smoothing function. See
                                   HELP SMOOTH for details.
DPARM                              Control info:
                                   (1) 0=amp, 1=phase, 2=rms,
                                       3=rms/mean, 4=real part,
                                       5=imaginary, 6=count
                                   (2) 0=vec avg, 1=scalar
                                   (3) >0 = baseline as ant pair
                                       for B as x-axis only
                                   (4) >0 => divide by source
                                       IPOL flux
                                   (5) x-axis interval: is B for
                                       TB and is ignored, else
                                       is the 2nd sort parameter
                                       NO default.       Units:
                                       seconds, wavelengths
                                   (6) y-axis interval: T for TB
                                       first sort parameter
                                       NO default
                                   (7) > 0 => do NOT divide by
                                       the summed weights
                                   (8) > 0 -> use XTYPE, YTYPE
                                       and interpolate to grid
                                   (9) > 0 -> empty cells set
                                       to zero, else blanked
                                   (10) Use data weight to the
                                       power 1/DPARM(10)
IMSIZE            1.0    8192.0    Output image size in x,y
                                   x ignored if B
NCHAV                              Number of channels to include
                                   in each plane
CHINC                              Increment between start
                                   channels of each plane
SORT                               Desired uv image axes
XTYPE           0.         20.     Conv. function type in x
                                     default spheroidal
                                     New round types - SEE HELP
YTYPE           0.         20.     Conv. function type in y
                                     default spheroidal
XPARM                              Conv. function parms for x
YPARM                              Conv. function parms for y
BADDISK                            Disk to avoid for scratch.
----------------------------------------------------------------
UVIMG
Type:  Task
Use:   Grids UV data of the selected type to form an image.  UVIMG
       will work on single- and multi-source files in any sort order.
       It grids the data by the SORT parameters with the 2nd (faster)
       parameter on the x axis and the 1st (slower) parameter on the y
       axis.  All samples falling into a cell are averaged by vector
       or scalar averaging. Each included channel and IF may be
       gridded to a separate plane of the output 3- or 4-dimensional
       image.  Spectral channels, but not IFs, may be "averaged"
       together (where u,v,w are adjusted for each frequency before
       gridding).

       Note that it is usually essential to specify DPARM(5) and
       DPARM(6) since an increment of 1 is normally not useful.

       The task attempts to grid the data sample and its Hermitian
       except when the two axes are normal baseline number (DPARM(3)
       <= 0) and/or baseline length and/or time.  In these three
       cases, the two would land on top of each other and, at least
       for phase, would be destructive.  Note that both samples may
       not land on the grid, as in axes X, Y, Z, and M.

       DPARM(8) was added to signal your intention to use convolving
       functions when interpolating to the grid.  XTYPE and YTYPE are
       convolve a sample potentially to multiple cells in the UVIMG
       plane.  Since this operation is not normally desired, the task
       now requires you to set this additional adverb before it will
       use XTYPE, YTYPE, XPARM, and YPARM.

Adverbs:
  INNAME.....UV file name (name).          Standard defaults.
  INCLASS....UV file name (class).         Standard defaults.
  INSEQ......UV file name (seq. #).        0 => highest.
  INDISK.....Disk unit #.                  0 => any.
  OUTNAME....Image file name (name).       Standard defaults.
  OUTCLASS...Image file name (class).      Standard defaults.
  OUTSEQ.....Image file name (seq. #).     0 => highest.
  OUTDISK....Output disk unit #.           Standard defaults.
  SOURCES....List of sources to be gridded. '  '=> all; if any starts
             with a '-' then all except ANY source named.
  TIMERANG...Time range of the data to be gridded. In order:
             Start day, hour, min., sec, end day, hour, min., sec. in
             days relative to reference date.
  STOKES.....The desired Stokes type of the gridded data  ' ' => 'I'.
             Only 1 Stokes type may be used: I, Q, U, V, RR, LL, RL,
             LR, XX, YY, XY, YX
  SELBAND....Bandwidth of data to be selected. If more than one IF is
             present SELBAND is the width of the first IF required.
             Units = kHz, 0=> all
  SELFREQ....Frequency of data to be selected. If more than one IF is
             present SELFREQ is the frequency of the first IF
             required. Units = MHz, 0=> all
  FREQID.....Frequency identifier to select (you may determine which
             is applicable from the OPTYPE='SCAN' listing produced by
             LISTR). If either SELBAND or SELFREQ are set their values
             overide that of FREQID, however setting SELBAND and
             SELFREQ may occasionally result in an ambiguity, in which
             case the task will request that you use FREQID.
  BIF........Lowest IF to grid.  IF will be axis 4.
             **************************************************
             NOTE to VLA users: IF=1 corresponds to the VLA
             AC ifpairs and IF=2 corresponds to the BD ifpairs.
             **************************************************
  EIF........Highest IF to grid.      0 => highest.
  BCHAN......First channel to grid.   0 => 1.
  ECHAN......Last channel to grid.    0 => highest.
  ANTENNAS...A list of the antennas to grid.  If any number is
             negative then all antennas listed are NOT desired and all
             others are.  All 0 => grid all.
  BASELINE...Baselines are specified for the LIST option using
             BASELINE. Eg. baselines 1-6,1-8, 2-6 and 2-8 use
             ANTENNAS=1,2; BASELINE=6,8.
  UVRANGE....Range of projected spacings to be gridded in 1000's of
             wavelengths.  0  =>  1, 1.E10
  SUBARRAY...Subarray number to grid. 0=>1.
  DOCALIB....If true (>0), calibrate the data using information in the
             specified Cal (CL) table for multi-source or SN table for
             single-source data.  Also calibrate the weights unless
             DOCALIB > 99 (use this for old non-physical weights).
             MUST be false for data not in T* order.
  GAINUSE....Version number of the Cal. table to apply to the data if
             DOCALIB=1.  Refers to a CL table for multisource data of
             an SN table for single source.  0 => highest.
  DOPOL......If > 0 then correct data for instrumental polarization as
             represented in the AN or PD table.  This correction is
             only useful if PCAL has been run or feed polarization
             parameters have been otherwise obtained.  See HELP DOPOL
             for available correction modes: 1 is normal, 2 and 3 are
             for VLBI.  1-3 use a PD table if available; 6, 7, 8 are
             the same but use the AN (continuum solution) even if a PD
             table is present.
  PDVER......PD table to apply if PCAL was run with SPECTRAL true and
             0 < DOPOL < 6.  <= 0 => highest.
  BLVER......Version number of the baseline based calibration (BL)
             table to appply. <0 => apply no BL table, 0 => highest.
  FLAGVER....Specifies the version of the flagging table to be
             applied. 0 => highest numbered table.  <0 => no flagging
             to be applied.
  DOBAND.....If true (>0) then correct the data for the shape of the
             antenna bandpasses using the BP table specified by BPVER.
             The correction has five modes:
             (a) if DOBAND=1 all entries for an antenna in the table
             are averaged together before correcting the data.
             (b) if DOBAND=2 the entry nearest in time (including
             solution weights) is used to correct the data.
             (c) if DOBAND=3 the table entries are interpolated in
             time (using solution weights) and the data are then
             corrected.
             (d) if DOBAND=4 the entry nearest in time (ignoring
             solution weights) is used to correct the data.
             (e) if DOBAND=5 the table entries are interpolated in
             time (ignoring solution weights) and the data are then
             corrected.
  BPVER......Specifies the version of the BP table to be applied.
             <0 => no BP correction.
  SMOOTH.....Specifies the type of spectral smoothing to be applied to
             a uv database . The default is not to apply any smoothing.
             The elements of SMOOTH are as follows:
             SMOOTH(1) = type of smoothing to apply: 0 => no smoothing
               To smooth before applying bandpass calibration
                 1 => Hanning, 2 => Gaussian, 3 => Boxcar, 4 => Sinc
               To smooth after applying bandpass calibration
                 5 => Hanning, 6 => Gaussian, 7 => Boxcar, 8 => Sinc
             SMOOTH(2) = the "diameter" of the function, i.e. width
               between first nulls of Hanning triangle and sinc
               function, FWHM of Gaussian, width of Boxcar. Defaults
               (if < 0.1) are 4, 2, 2 and 3 channels for SMOOTH(1) =
               1 - 4 and 5 - 8, resp.
             SMOOTH(3) = the diameter over which the convolving
               function has value - in channels.  Defaults: 1,3,1,4
               times SMOOTH(2) used when input SMOOTH(3) < net
               SMOOTH(2).
  DPARM......Control info:
             (1) controls the type of information to be gridded:
                 0 => amplitude,
                 1 => phase,
                 2 => RMS of amplitude
                 3 => RMS of amplitude / mean of amplitude
                 4 => real part of visibility
                 5 => imaginary part of visibility
                 6 => count of samples
             (2) controls the type of averaging:
                <= 0 => vector average,
                 > 0 => scalar averaging (amplitude only).
             (3) controls how "baseline number" is computed
                <= 0 => normal baselines (1-1,1-2, 1-3, ... 1-N,
                        2-2,2-3, 2-4, ... 2-N, 3-3,3-4, ...)
                 > 0 => as antenna pair gridding each sample
                        twice (1-1,1-2, 1-3, ... 1-N, 2-1, 2-2, 2-3,
                        ... 2-N, 3-1, 3-2, ... 3-N, ...)
             (4) <= 0 => grid amplitudes as found in data set
                 > 0 => divide amplitudes by source flux
             (5) x-AXIS interval: 0 -> 1 except 1.0 is forced for
                 B type axis.  Units are wavelengths for U, V, W, X,
                 Y, Z, and M sort orders and seconds for T.
             (6) Y-axis interval: 0 -> 1 except 1.0 is forced for
                 B type axis.  Units are wavelengths for U, V, W, X,
                 Y, Z, and M sort orders and seconds for T.
             (7) > 0 => do NOT divide by the count (or sum of
                        convolution weights) for DPARM(1) types 0
                        through 5.  Makes image a convolution such as
                        done by IMAGR, UVMAP, et al.
                 <= 0 => do divide by the sum of counts or convolution
                        function weights in each cell.  Makes image an
                        interpolation of the data.
             (8) >  0 => use XTYPE, YTYPE, XPARM, and YPARM to convolve
                        to the grid.
                 <= 0 => put each sample at the nearest grid cell.
             (9) >  0 => empty cells are set to 0 - if you plan to FFT
                        the image you must set DPARM(9) > 0.
                 <= 0 => emptry cells are set to magic blanks except
                        for DPARM(1) = 6
             (10) > 0 => use data weight when gridding to the power
                        1/DPARM(10)
  IMSIZE.....X,Y output image size, no sensible default except for B
             type axis which will be forced,
  NCHAV......NCHAV is the number of channels to be averaged together
             in in the gridding process.  0 => 1.  If this value is
             less than the total number of spectral channels, then the
             output image will have multiple planes of averaged
             channels.  Note that all spectral planes will include
             data from NCHAV input channels so the actual ECHAN used
             may be less than that specified (or in the data set).
             To make a single plane image from multiple IFs and
             multiple spectral channels set
                   NCHAV >= (EIF-BIF+1) * (ECHAN-BCHAN+1)
  CHINC......Number of input channels to skip between images. 0 => 1
             The i'th spectral plane includes input channels
                 BCHAN + (i-1)*CHINC
             through
                 MIN (ECHAN, BCHAN + (i-1)*CHINC + NCHAV - 1).
             CHINC is ignored if NCHAV >= ECHAN-BCHAN+1.
  SORT.......The YX axis types are specified by two keys which are
             characters in the adverb SORT.  The legal keys are:
                B => baseline number
                T => time order
                U => u spatial freq. coordinate
                V => v spatial freq. coordinate
                W => w spatial freq. coordinate
                R => baseline length.
                P => baseline position angle.
                X => descending ABS(u)
                Y => descending ABS(v)
                Z => ascending ABS(u)
                M => ascending ABS(v)
             Any blank character is replaced with the corresponding
             character in the UV data base sort order.
      If XPARM(8) > 0, then
         XTYPE......Convolution function type in X-direction
                       0 -> none - take nearest pixel
                       1=Pillbox, 2=exponential, 3=Sinc, 4=Exp*Sinc,
                       5=Spheroidal, 6=Exp*BESSJ1(x)/x
                       > 6 (& < 11) -> 5.
                       11 - 16 => circular functions in radius
                       corresponding to 1 - 6 types above; YTYPE,
                       YPARM are ignored.
                    See HELP UV1TYPE through HELP UV6TYPE for details.
         YTYPE......Convolution function type in Y-direction
         XPARM......Array containing parameters for XTYPE.
                    See HELP UVnTYPE when n=convolution type.
         YPARM......Array containing parameters for YTYPE.
  BADDISK....Disk numbers to avoid for scratch files.  Scratch
             files may be created by the sorting routines if
             calibration or flagging is applied.
----------------------------------------------------------------
