; APGS
;---------------------------------------------------------------
;! deconvolves image with Gerchberg-Saxton algorithm
;# Task Imaging AP
;-----------------------------------------------------------------------
;;  Copyright (C) 1995
;;  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
;-----------------------------------------------------------------------
;---------------------------------------------------------------
APGS      LLLLLLLLLLLLUUUUUUUUUUUU CCCCCCCCCCCCCCCCCCCCCCCCCCCCC
APGS :  Task which deconvolves the Gerchberg-Saxton way.
                                   Dirty image
INNAME                                Image name (name)
INCLASS                               Image name (class)
INSEQ              0.0      9999.0    Image name (seq. #)
INDISK             0.0         4.0    Image disk drive #
                                   Beam image
IN2NAME                               Image name (name)
IN2CLASS                              Image name (class)
IN2SEQ             0.0      9999.0    Image name (seq. #)
IN2DISK            0.0         4.0    Image disk drive #
                                   GS  image
OUTNAME                               Image name (name)
OUTCLASS                              Image name (class)
OUTSEQ            -1.0      9999.0    Image name (seq. #)
OUTDISK            0.0         4.0    Image disk drive #

GAIN              -1.0         1.0 GS  loop gain
NITER              0.0     32767.0 Maximum # of GS components
DOTV              -1.0         1.0 TV display of residuals?
NBOXES             0.0        10.0 Number of boxes for CLEAN
BOX                0.0      4096.0 Four coordinates for each box
BADDISK           -1.0      1000.0 Disks to avoid for scratch.
OFFSET            -1.0      1000.0 Beam offset for stabilisation
----------------------------------------------------------------
APGS
Type: Task
Use: APGS  deconvolves the dirty beam from the dirty map thus
producing a map with the units of brightness (Jy/pixel).
Conversion to other units e.g. KELVIN can be done with AXDEFINE.
APGS  may be restarted if further improvement is desired. This
program is slow but should be comparable to APCLN if the map
contains many picture elements. The task CONVL may be used to
convolve the map to the resolution produced by a CLEAN program.
     The algorithm used in the program is due to Gerchberg and
Saxton. The GS map is constrained to be non-zero, and positive,
only in the regions defined by the BOXes. Data and image plane
constraints are imposed alternately while transforming to and
from the image plane. If the BOXes are chosen to surround the
source snugly then the algorithm will converge faster and will
have more chance of finding a unique image. To obtain smoother
images a non-zero value of OFFSET may be chosen. This adds a
delta function to the beam as is done in PHCLN. Try values of
0.01 - 0.2 for OFFSET.
     This is an experimental program; please relay any
complaints etc. to Tim Cornwell at the VLA
Adverbs:
  INNAME......The dirty image name.   Standard defaults.
  INCLASS.....The dirty image class.  Standard defaults.
  INSEQ.......The dirty image seq. #. 0 => highest.
  INDISK......The dirty image disk drive #. 0 => any
  IN2NAME.....The beam image name.  blank => actual
              INNAME, otherwise standard defaults.
  IN2CLASS....The beam image class.  Standard defaults
              except blank => 'RBEM' if INCLASS = 'RMAP'
                 'LBEM' if INCLASS = 'LMAP'
                 'IBEM' if INCLASS = anything else
              Only positive images can be made so that Q,U,V
              GS  images are impossible. ( One day....)
  IN2SEQ......The beam image seq . #.  0 => actual INSEQ
  IN2DISK.....The beam image disk drive #.  0 => any
  OUTNAME.....The GS  image name.  blank => Standard defaults
              based on INNAME.
  OUTCLASS....The GS  image class.  Standard behavior with
              default =   'RGS ' if INCLASS = 'RMAP'
                          'LGS ' if INCLASS = 'LMAP'
                          'IGS ' if INCLASS = anything else
  OUTSEQ......The GS  image seq. #.  0 => highest unique
              If >0; image will be created if new,
              overwritten if image name exists.
  OUTDISK.....The GS  disk drive no. 0 => highest with space
  GAIN........The GS  loop gain.  0 => 0.01, for most cases
                0.02 will work well. NOTE that this only
                affects the route taken to the final GS
                image NOT the image itself.
  NITER.......GS  iteration limit.  0 => 20
  DOTV........Display GS  map on TV channel 1. > 0 => yes.
              If true, you may stop the GS ing with TV button
              D after each GS  map is displayed.
  NBOXES......The number of rectangular boxes.  The GS image is
              non-zero only within these boxes. 0=>1
  BOX.........A 4x10 array with the BLC and TRC of each box.
              0 => use inner quarter of input map (first box)
              0 => ignore box (boxes 2 - 10)
  BADDISK.....This array contains the numbers of disks on which
              it is desired that scratch files not be located.
              BADDISK has no effect on input and output maps.
  OFFSET......Add a blip of size offset to the beam before
              deconvolving. If the blip is positive then a
              smoother image will result at the cost of a
              slightly poorer fit to the data. Try values in the
              range 0.01 to 0.2.
----------------------------------------------------------------
