; BSGRD
;---------------------------------------------------------------
;! Task to image beam-switched single-dish data
;# TASK SINGLEDISH AP IMAGING OOP
;-----------------------------------------------------------------------
;;  Copyright (C) 1997, 1999-2000
;;  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
;-----------------------------------------------------------------------
BSGRD     LLLLLLLLLLLLUUUUUUUUUUUU CCCCCCCCCCCCCCCCCCCCCCCCCCCCC
BSGRD     Image beam-switched data
INNAME                             Input UV file name (name)
INCLASS                            Input UV file name (class)
                                   Last char + and - for throws
INSEQ             0.0     9999.0   Input UV file name (seq. #)
INDISK            0.0        9.0   Input UV file disk unit #
                                   Cal. info for input:
TIMERANG                           Time range to include
DOCALIB          -1.0        2.0   If >0 calibrate data
GAINUSE                            CS table to apply
FLAGVER                            Flag table version
STOKES                             Stokes' parameter to image.
OUTNAME                            Output UV file name (name)
OUTCLASS                           Output UV file name (class)
OUTSEQ            0.0     9999.0   Output UV file name (seq. #)
OUTDISK           0.0        9.0   Output UV file disk unit #.
OPTYPE                             Projection code e.g. '-SIN'
APARM                              1,2,3 = RA (h,m,s)
                                   4,5,6 = Dec (d,m,s)
IMSIZE         32.       4096.     Image size (X,Y) in pixels
CELLSIZE    0.000001     4096.     Cell size in arc seconds
ROTATE                             Correct throw angle (deg)
                                   > 0 => in gridding
                                   < 0 => shift gridded image
SHIFT                              (X,Y) image shift in asec
REWEIGHT                           (1) <= 0 -> interp image
                                       =  1 -> convolved image
                                       =  2 -> weight image
                                       =  3 -> 1/sigma**2 image
                                   (2) Min convolved weight
                                       = REWEIGHT(2) *
                                         max(convolved weight)
                                       < 0 => use abs value
XTYPE       -2000.       2000.     Conv. function type in x
                                     default spheroidal
                                     New round types - SEE HELP
                                     100*out + temp (see help)
YTYPE       -2000.       2000.     Conv. function type in y
                                     default spheroidal
XPARM                              Conv. function parms for x
YPARM                              Conv. function parms for y
FACTOR                             Correct the beam throws by
                                   multiplying by FACTOR
ORDER                              Baseline order (0 or 1)
DPARM                              Parameters: (see HELP)
                                   (1) scale factor plus image
                                       over minus (0 -> 1)
                                   (2) > 0 => apply scale before
                                       differencing, else apply
                                       scale with convolution
                                   (3-4) x-pixel baseline region
                                       1 for both images
                                   (5-6) x-pixel baseline region
                                       2 for both images
DOCAT          -1.          1.     > 0 => keep intermediate
                                   images
BADDISK                            Disk drive #'s to avoid
----------------------------------------------------------------
BSGRD
Task:  This task will select random position beam-switched single-dish
       data in AIPS uv form in a specified field of view from two data
       sets, one for the "plus" throw and one for the "minus" throw.  It
       makes two images, rotates the two images, removes linear
       baselines from each row of the images.  Then it applies a
       convolution function to the difference of the two images to bring
       the plus and minus images, sign corrected, into alignment.
       Finally, it regrids the correc ted image into the specified
       coordinate system.  Calibration and flagging may be applied
       during the selection process.  If the requested image is too
       large the program will fail.  Use SDIMG for such cases followed
       by OGEOM (for rotation) and BSCOR for the correction.
Adverbs:
  INNAME.....Input single-dish data file name (name).
  INCLASS....Input single-dish data file name (class).  The first five
             characters are used.  The sixth character is assumed to be
             "+" for the plus throw and "-" for the minus throw (as
             produced by OTFBS).
  INSEQ......Input single-dish data file name (seq. #).
  INDISK.....Disk drive # of input single-dish data file.
  DOCALIB....If true (>0), then calibrate the data using information in
             the specified CS table.
  GAINUSE....Version number of the CS table to apply to the data if
             DOCALIB=1.  0 = highest numbered.
  FLAGVER....Specifies the version of the flagging table to be applied.
             0 => highest numbered table. <0 => no flagging to be
             applied.
  STOKES.....Stokes' type of the desired image:
             'I' => I polarization,
             'Q' => Q polarization,
             'U' => U polarization,
             'V' => V polarization,
             'RR' => right circular polarization,
             'LL' => left circluar polarization,
             other => 'I'
  OUTNAME....Output file name (name).  blank => INNAME
  OUTCLASS...Output file name (class).  blank => INCLASS
  OUTSEQ.....Output file name (seq. #). 0 => lowest unique
  OUTDISK....Disk drive # of output UV file.  0 => highest with
             space for the file.
  OPTYPE.....Projection code:
             '-TAN' = tangent projection (optical),
             '-SIN' = sine projection (normal interferometer),
             '-ARC' = arc projection (Schmidt camera, single
                      dish images),
             '-NCP' = North celestial pole (WSRT),
             '-STG' = stereographic projection,
             '-AIT' = Aitoff projection, (large field)
             '-GLS' = Global sinusoidal projection (large field)
             '-MER' = Mercator projection,
             '    ' => '-SIN'
             See AIPS memo nos. 27 and 46 for more detail.
  APARM......1,2,3 are the RA as (h,m,s)
             4,5,6 are the Dec, as (d,m,s)
             The specified position is the CENTER of the RA and DEC
             range before the application of the shifts (if any).
             Default: uv data header RA and DEC, or, if they are 0, uv
             data header Observed RA and Dec.  If the data coordinates
             are relative Az-El (i.e. beam switched data), then there is
             no default and 0,0 would be the normal center.
             If APARM(4) is -0 then use APARM(4)=-0.1.
  IMSIZE.....(X,Y) image size in pixels.  Must be even and between 32
             and 4096.
  CELLSIZE...(X,Y) cell size in arc seconds.
  ROTATE.....Rotate the throw angle by ROTATE degrees CCW.  Actually it
             just shifts the two images in elevation by throw-length *
             sin(ROTATE) and in azimuth by throw-length*(1-cos(ROTATE))
             There are 2 methods of doing the rotation/shift:
                If ROTATE > 0, the initial gridding is done shifted.
                If ROTATE < 0, the gridded images are interpolated onto
                   shifted images.
                Note that ROTATE = -355 is the same angle as ROTATE = 5,
                but the images are done differently.
  SHIFT......Probably wouldn't do what you expect: shifts the reference
             pixel by -SHIFT(1)/CELL(1), -SHIFT(2)/CELLS(2).  The
             reference value is still set by APARM (see above).
  REWEIGHT...(1) Selects the kind of output image:
                <= 0 => interpolated image (convolved image
                        divided by a convolved image with the
                        data replaced by 1.0's).
                 = 1 => convolved image of data.
                 = 2 => convolved image with data replaced by 1,
                        i.e an image of the data weights (sum of
                        input data weight * uniform weight
                        correction * convolving function at each
                        cell)
                 = 3 => image of K/sigma**2 for an interpolated
                        image assuming the input weights are
                        K/sigma**2 for the data samples
             (2) Minimum convolved weight (image with data replaced by
                 1.0's) to remain unblanked = REWEIGHT(2) *
                 max(convolved weight).
                 < 0 => use abs(convolved weight) compared to
                        abs(REWEIGHT(2)*max(convolved weight))
                 0 => -0.01. for interpolation output and no blanking
                        for convolution and weight outputs
  XTYPE......Convolution function type in X-direction
                1=Pillbox, 2=exponential, 3=Sinc, 4=Exp*Sinc,
                5=Spheroidal, 6=Exp*BESSJ1(x)/x
                = 0 or > 6 (& < 11) -> 5.
                11 - 16 => circular functions in radius corresponding to
                1 - 6 types above; YTYPE, YPARM are ignored.
             If XTYPE < 0, then abs(xtype) is used and some of the XPARM
             values are assumed to be in arc seconds rather than cells.
             See HELP UV1TYPE through HELP UV6TYPE for details.
             There are two convolutions, first to the + and - images and
             then from the corrected az-el image to an ra-dec image.
             XTYPE = 100*xtype(2) + xtype(1).  Same for YTYPE.
             Note that both xtype(i) have to have the same sign.
  YTYPE......Convolution function type in Y-direction
  XPARM......Array containing parameters for XTYPE.  See HELP UVnTYPE
             when n=convolution type.  XPARM(5) is number samples of
             convolution function used per image cell for circular
             functions - 100 is used for X/Y separable functions (types
             1-6).  XPARM for the second gridding type is the same as
             for the first if they are of the same type.  Otherwise,
             the second gridding uses default values for XPARM.
  YPARM......Array containing parameters for YTYPE.
  FACTOR.....Change the beam throws by FACTOR.
  ORDER......Order of baseline removed from each row of each image.
             Only 0 and 1 are allowed.
  DPARM......Parameters:
             (1) The plus beam may be scaled by DPARM(1) wrt the minus
                 beam.  (You may need to use IMFIT to determine this
                 ratio.  Be sure to fit a baseline as well as a
                 Gaussian.)  0 => 1.
             (2) The ratio may be applied at two different stages:
                 if DPARM(2) > 0, the images are scaled before they are
                 differenced.  Otherwise, the scaling is done through a
                 modification of the convolution function.
             (3) Start x pixel of both images to use for the first of
                 2 baseline regions.  0 => 1.  N.B. this applies after
                 BLC(1) has been applied.
             (4) End x pixel of both images to use for first baseline
                 region.  0 => all (not a good default).
                 N.B. above N.B.
             (5) Start x pixel of both images to use for the second of
                 2 baseline regions.  0 => none.  N.B. above N.B.
             (6) End x pixel of both images to use for second baseline
                 region.  0 => all (an okay default).
             It has been found by experimentation that it is essential
             to use the same baseline regions for both images.
  DOCAT......> 0 => keep the intermediate images (BSGRD+, BSGRD-,
            BSROT+, BSROT-, and BSGCOR) as well as the final output
            image.  <= 0 => delete these asap.
  BADDISK...Disk drive #'s to avoid for scratch files
----------------------------------------------------------------
