; TD_STEP5
;---------------------------------------------------------------
;! Time-dependent imaging procedure sequence: later steps
;# procedure AP IMAGING OOP INTERACTIVE
;-----------------------------------------------------------------------
;;  Copyright (C) 2014
;;  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
;-----------------------------------------------------------------------
TD_STEP5  LLLLLLLLLLLLUUUUUUUUUUUU CCCCCCCCCCCCCCCCCCCCCCCCCCCCC
TD_STEP5   Does imaging of target source
INNAME                             Input UV data (name)
INCLASS                            Input UV data (class)
INSEQ                              Input UV data (seq. #)
INDISK                             Input UV data disk drive #
TD_TIMES                           List of time limits for the
                                   "short" time intervals (days)
PRTLEV                             Debug level displays:
                                     1 INPUTS for each task
                                     2 IMHEAD for each task
         ******** SPLIT parameters ***************************
DOCALIB          -1.0      101.0   > 0 calibrate data & weights
                                   > 99 do NOT calibrate weights
GAINUSE                            CL (or SN) table to apply
FLAGVER                            Flag table version
         ******** non-target model parameters ****************
NMAPS           1.       4096.     Number of fields (max 4096)
IN2NAME                            Cleaned map name (name)
IN2CLASS                           Cleaned map name (class)
IN2SEQ            0.0     9999.0   Cleaned map name (seq. #)
IN2DISK                            Cleaned map disk unit #
         ******** target IMAGR parameters ********************
NCHAV                              Number of chan. to average.
CHINC                              Channel incr. between maps.
OUTNAME                            Output image name (name)
OUTDISK                            Output image disk drive #
OUTSEQ          -1.0     9999.0    Output seq. no.
CELLSIZE      1.E-12               (X,Y) size of grid in asec
IMSIZE          0.0      8192.     Minimum image size
FLDSIZE         -1.       8192.    Clean size of each field.
RASHIFT                            RA shift per field (asec)
DECSHIFT                           DEC shift per field (asec)
UVTAPER         0.                 (U,V) Gaussian taper
                                     units are kilo-lambda
UVRANGE         0.                 Min & max baseline (klambda)
GUARD         -1.0         0.9     x,y guard band fractional
                                   radius
ROTATE                             Rotate image CCW from N by
                                   ROTATE degrees
ZEROSP                             0-spacing fluxes and weights
                                   SEE HELP!!
UVWTFN                             UV dist. weight function
UVSIZE          0.                 Array size for doing uniform
                                   weights.  0 -> actual field
                                   size.
ROBUST                             Robustness power: -5 -> pure
                                   uniform weights, 5 => natural
UVBOX           0.        128.     Additional rows and columns
                                   used in weighting.
UVBXFN                             Box function type when UVBOX
                                   > 0.  0 -> 1 round pill box.
XTYPE           0.         10.     Conv. function type in x
                                     default spheroidal
YTYPE           0.         10.     Conv. function type in y
                                     default spheroidal
XPARM                              Conv. function parms for x
YPARM                              Conv. function parms for y
NITER    *         0.0             Maximum # of Clean components
BOXFILE                            Input file of field params
                                   and Clean boxes; ' ' => use
                                   FLDSIZE, RASHIFT, DECSHIFT,
                                   NBOXES, CLBOX only.
OBOXFILE *                         Output file for final Clean
                                   boxes
GAIN     *         0.0         2.0 Clean loop gain
FLUX     *                         Minimum Clean component (Jy)
MINPATCH *         0.0             Min. BEAM half-width in AP.
BMAJ     *      -999.9             FWHM(asec) major axis Clean
         *                         restoring beam.
BMIN     *      -999.9             FWHM(asec) minor axis Clean
         *                         restoring beam.
BPA      *      -360.0       360.0 Clean beam position angle
FACTOR   *        -5.0         5.0 Speedup factor see HELP
CMETHOD  *                         Modeling method:
         *                         'DFT','GRID','    '
IMAGRPRM                           Task enrichment parameters
                                   (1) Antenna diameter (m)
                                   (2) Source Spectral index
                                   (3) Frequency scaling factor
                                   (4) > 0 -> SDI Clean factor
                                   (5) >0 => scale residuals
                                   (6) Half-width in x of box
                                   (7) Half-width in y of box
                                   (8) Filter components whose
                                   neighborhood is weaker than
                                   IMAGRPRM(8) Jy.  0 -> don't
                                   (9) Radius in pixels for the
                                   IMAGRPRM(8) test.
                                   (10) multiplier of image size
                                   to get beam size: 0 => 2;
                                   2, 1, 0.5 0.25 supported
                                   (11-16) Multi-scale controls
                                   (17) spectral index radius
                                        0 -> no correction
                                   (18) Limit grids (see help)
                                   (19) Dynamic range limit
                                   (20) Retry factor (see help)
IMAGRPRM ?                         Task enrichment parameters
         ?                         (1) Antenna diameter (m)
         ?                         (4) > 0 -> SDI Clean factor
         ?                         (5) >0 => scale residuals
         ?                         (6) Half-width in x of box
         ?                         (7) Half-width in y of box
         ?                         (8) Filter components whose
         ?                         neighborhood is weaker than
         ?                         IMAGRPRM(8) Jy.  Can TELL
         ?                         only if non-zero on GO.
         ?                         0 -> no filtering.
         ?                         (9) Radius in pixels for the
         ?                         IMAGRPRM(8) test.
         ?                         (11-15) Multi-scale controls
         ?                         (18) Limit grids (see help)
         ?                         (19) Dynamic range limit
         ?                         (20) Retry factor (see help)
IM2PARM                            Yet more parameters:
                                   (1) Auto boxes: allowed #
                                   (2)           : island level
                                   (3)           : peak required
                                   (4)           : limit wrt max
                                   (5)           : extend boxes
                                   (6)           : edge skip
                                   (7) reset boxes for next chan
                                   (8) TV timeout interval: init
                                   (9) timeout after 1st: in sec
                                   (11) baseline-dependent avg
                                        max time in sec
                                   (12) field size 0 -> infinite
                                   (13) Number channels averaged
IM2PARM  ?                         Yet more parameters:
         ?                         (1) Auto boxes: allowed #
         ?                         (2)           : island level
         ?                         (3)           : peak required
         ?                         (4)           : limit wrt max
         ?                         (5)           : extend boxes
         ?                         (6)           : edge skip
         ?                         (9) timeout after 1st: in sec
NGAUSS             0.0        10.0 Number of scales to use
WGAUSS             0.0             Scales in arc sec >= 0
FGAUSS             0.0             Minimum flux for each resol.
MAXPIXEL *         0.0    500000.0 Maximum pixels searched in
         *                         each major cycle.
IN3NAME                            Spectral index image name
IN3CLASS                           Spectral index image class
IN3SEQ                             Spectral index image sequence
                                   number
IN3DISK                            Spectral index image disk
IN4NAME                            Spectral curvature name
IN4CLASS                           Spectral curvature class
IN4SEQ                             Spectral curvature sequence
                                   number
IN4DISK                            Spectral curvature disk
FQTOL                              Frequency tolerance in kHz
                                   (primary beam & spec index)
DOTV     *        -1.0      4096.0 Display residuals on TV ?
                                   Start with field = DOTV
BADDISK           -1.0      1000.0 Disks to avoid for scratch.
----------------------------------------------------------------
TDSTEP5
Type:  Procedure
 Use:  See HELP TDEPEND for a full discussion.  TDSTEP5 taks as input
       a fully calibrated and edited single source uv data set.  It
       also takes a set of image facets containing a model of the
       emission in the field other than that from the time-dependent
       target source.  TDSTEP5 initially deletes any APPEND uv dataset
       and any target image files with class 'TRGT*'.  It then loops
       over the time ranges doing:
       a. SPLIT to make 'ISPLIT' containing all data for time range(i)
       b. UVSUB the final model produced in step 4 (and contained in
          adverbs NMAPS and IN2NAME, IN2CLASS, etc.) to make ISOURC
          containing only the target source visibilities
       c. IMAGR on the target source, making NGAUSS images of a single
          facet
       d. UVSUB the model found in (c) from ISPLIT and append the
          result to APPEND, a data set containing all sources except
          the target.
       e. Rename the target images from ICL0nn to TRGTnn.
       f. It then deletes IUVSUB, ISPLIT, and all beams.

       The output of this step is a UV data set from which the
       time-variable target source has been removed (as best one can
       at this iteration of the imaging and self-cal).  It has name
       OUTNAME, class 'APPEND', sequence 1, and disk OUTDISK.  A set
       of images (NGAUSS facets) at each time interval is also left
       behind.  They have name OUTNAME, class TRGTnn, disk OUTDISK,
       and sequence number equal to the time step number.

Adverbs:
  INNAME.....Input UV data file (name).       Standard defaults.
  INCLASS....Input UV data file (class).      Standard defaults.
  INSEQ......Input UV data file (seq. #).     0 => highest.
  INDISK.....Input UV data file disk drive #. 0 => any.
  TD_TIMES...A list of break times for imaging intervals in which the
             target source is not likely to change.  Time interval I
             is TD_TIMES(I) to TD_TIMES(I+1) in days.
  PRTLEV.....For debug purposes: 1 => INPUTS for each task are
             printed.  2 => IMHEADER for each input file is also
             printed.  3 => also INPUTS for each zap, 4 also IMHEADER
             for each zap.
  OUTNAME....Output image name (name).       Standard defaults.
             Used for data set called class APPEND only.
  OUTDISK....The disk drive # of almost everything.  0 => highest with
             space but you shoukd not depend on this.

************  Adverbs strictly for SPLIT step ************************

  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).
  GAINUSE....version number of the SN table to apply to single-source
             files.   0 => highest.
  FLAGVER....specifies the version of the flagging table to be applied.
              0 => highest numbered table.
             <0 => no flagging to be applied.

************  Adverbs strictly for 1st UVSUB step ********************

         The following point at the images made from data not
         containing the target (time-variable) source:

  NMAPS......Number of image files to use for model.  For multi-scale
             models, set NMAPS = NFIELD * NGAUSS to include the Clean
             components of the extended resolutions.  If more than one
             file is to be used, the NAME, CLASS, DISK and SEQ of the
             subsequent image files will be the same as the first file
             except that the LAST 3 or 4 characters of the CLASS will
             be an increasing sequence above that in IN2CLASS.  Thus,
             if INCLASS='ICL005', classes 'ICL005' through 'ICLnnn'
             or 'ICnnnn', where nnn = 5 + NMAPS - 1 will be used.  Old
             names (in which the 4'th character is not a number) are
             also supported: the last two characters are '01' through
             'E7' for fields 2 through 512.  In old names, the highest
             field number allowed is 512; in new names it is 4096.
  IN2NAME....Model map name (name).      Standard defaults.
  IN2CLASS...Model map name (class).     Standard defaults.
  IN2SEQ.....Model map name (seq. #).    0 => highest.
  IN2DISK....Disk drive # of model map.  0 => any.

************  Adverbs strictly for IMAGR ************************

  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 channels, then a multi-channel
             image will result.  Note that the last output channel may
             include data from fewer than NCHAV input channels unless
             ECHAN, BCHAN, CHINC, and NCHAV are very carefully
             chosen.
             The term "averaged" applies to the output image; each
             channel is kept separate in the uv data used in the
             imaging so that it may be gridded and model subtracted
             at the correct frequency.  IM2PARM(13) overrides this and
             actually averages a number of channels together on the
             fly before gridding.  Be aware that the values of NCHAV,
             CHINC, and IM2PARM(13) interact and should be consistent.
  CHINC......Number of input channels to skip between images. 0 => 1
             The i'th output channel includes input channels
                 BCHAN + (i-1)*CHINC
             through
                 MIN (ECHAN, BCHAN + (i-1)*CHINC + NCHAV - 1).
             See also IM2PARM(13) for considerations.
  OUTNAME....Output image name (name).       Standard defaults.
  OUTDISK....The disk drive # of output images.  0 => highest with space
             Image and Beam go on same disk.  Note:  OUTCLASS='xCLnnn'
             where x=Stokes, nnn=field number and 'xBMnnn' is the beam
             CLASS.  If NITER=0, OUTCLASS='xIMnnn'
             If OUTDISK <= 0, ALLOKAY is ignored (set to 0).
  OUTSEQ.....Output sequence number. 0 => highest to produce unique maps
             and beam.  Note that this will produce, potentially, maps
             and beams with a variety of sequence numbers depending on
             what files are already on disk.  If OUTSEQ > 0, all images
             and beams for all fields are assigned that sequence number
             and pre-existing files are reused.  An error will occur if
             the pre-existing files are of different sizes than the ones
             currently being requested.  WARNING: this will be very
             likely if you are switching between no Clean and Cleaning
             since the default beams are of diferent size.
             If OUTSEQ <= 0, ALLOKAY is ignored (set to 0).
  CELLSIZE...(X,Y) pixel separation in asec.
  IMSIZE.....(X,Y) The minimum desired size of the fields regardless of
             the FLDSIZE for component search.
  FLDSIZE....(X,Y) field size in pixels for the component search during
             Cleaning; one per field. Should be in the range 32X32 to
             8192X8192. Output image size will be increased to the next
             highest power of two (or IMSIZE if that is greater), but
             only the region  specified will be searched for
             components.  Default is IMSIZE-10.  Set FLDSIZE(1,i) and
             FLDSIZE(2,i) = -1, if you want there to be NO clean box
             initially in field i.  This isn't necessary if you are
             using auto-boxing (IM2PARM(1) > 0).  TV options may be
             used to delete, change and create Clean boxes
             interactively.  The BOXFILE option and the NVSS WWW
             server may help in entering these values;see below.
  RASHIFT....RA shift of the phase center of each field from the tangent
             point of the uv data in asec.  Map center = tangent point +
             shift. If X>0 shifts map center to east.  NOTE: RASHIFT is
             a shift in RA scaled by cos (Dec_0) as
                Ra_new(i) = RA_0 + RASHIFT(i) / cos (Dec_0)
             where _0 => the tangent point in the uv data.  This is a
             change for 15OCT99 from shifts in -SIN projection (which
             do not work for -NCP data and large angles).  If the UV
             data have been rotated then RASHIFT and DECSHIFT refer to X
             and Y in the new coordinate system.
             The BOXFILE option and the NVSS WWW server may help in
             entering these values;see below.
  DECSHIFT...Declination shift of map center from tangent point of each
             field in asec.  Map center = tangent point + shift.  If Y>0
             shifts map center to north.
             The BOXFILE option and the NVSS WWW server may help in
             entering these values;see below.
  UVTAPER....(U,V) Gaussian taper (kilo-lambda) at 30% level
  UVRANGE....(Minimum,Maximum) baseline (kilo-lambda) in map.
  GUARD......Fraction of the x and y radius for which uv samples are not
             allowed.  < 0 => just enough to avoid mathematical errors
             in the convolution.
             0 => 0.3 * SQRT(taper weight at 0.3 from edge).
  ROTATE.....Rotation angle to be applied in degrees.
  ZEROSP.....(1)= zero spacing Stokes I flux density.  Zero spacing flux
               is placed at the center of FIELD 1.
             (2)= zero spacing Stokes Q flux density
             (3)= zero spacing Stokes U flux density
             (4)= zero spacing Stokes V flux density
             (5)= weight for zero spacing flux.
             Both ZEROSP(1) and ZEROSP(5) must be > 0 to apply this
             option.  The zero-spacing data sample is appended to the
             end of the input data set and participates in any uniform
             weighting, gridding, etc. in the same way any other sample
             does.  ******* NOTE THAT THIS IS NOT THE SAME AS OTHER
             IMAGING TASKS USAGE OF ZEROSP.  ****************
  UVWTFN.....Weighting function of (u-v) plane in 2 character code.
             If the 1st character is N use "natural" weighting (the
               weights attached to the data with no variation due to
               local density).  Otherwise, use "uniform" weighting
               in which the weights are scaled by the local density of
               weights under control of adverbs UVSIZE, UVBOX, UVBXFN,
               and ROBUST.
             The second character (and also the first) controls any
               alteration of the weights to be done before they are
               used in the natural or uniform weighting:
               2nd character = S  => take square root of weight_in
               2nd character = V  => take fourth root of weight_in
               2nd character = O  => use 1.0
               UVWTFN = 'CS' => take 1 / square root of weight_in
               UVWTFN = 'CV' => take 1 / fourth root of weight_in
               UVWTFN = 'C?' => take 1 / weight_in  where ? is any
                                character except S, V, O
  UVSIZE.....Size of the array used to count samples for uniform
             weighting.  Does not have to be a power of two and can be
             smaller than or bigger than the image size.  The default is
             the size of the first output image.
  ROBUST.....Briggs' "robustness" parameter.  "Uniform" weights are
             tempered by a constant being added to the local density of
             weights.  ROBUST = -4 is nearly pure uniform weighting,
             ROBUST = +4 is nearly pure natural weighting.  Use of this
             option requires a second array in the "AP" memory and may
             therefore force the data to be sorted.  The option is
             turned off if ROBUST < -7 and uniform weighting is turned
             off is ROBUST > 7.  See HELP ROBUST - the AIPS ROBUST
             differs numerically from that of Briggs.
  UVBOX......(U,V) box size for weighting.  This is the support radius
             over which a sample is counted.  I.e., the sample or its
             weight is counted over an area 2*UVBOX+1 cells on each side
             in the UV plane, where the UV cell size is (after
             correcting units) given by 1 / (UVSIZE(i) * CELLSIZE(i)).
  UVBXFN.....If UVBOX > 0, UVBXFN controls how the samples are counted
             as a function of u and v (UVBXFN < 0) or of radius (UVBXFN
             > 0).  In the latter case, the function is 0 for radius >
             UVBOX.  Functions are pill box, linear, exponential, and
             Gaussian for ABS(UVBXFN) = 1-4, resp.  0 -> 1.  See HELP
             UVBXFN.
  XTYPE......Convolution function type in X-direction
             1=Pill-box, 2=exponential, 3=Sinc, 4=Exp*Sinc,
             5=Spheroidal, 6=exp*BESSJ1(x)/x.   <= 0 or > 5  -> 5.
  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.
  NITER......Clean iteration limit. 0 => no Cleaning.
  BOXFILE....Input text file used to simplify the specification of large
             numbers of fields and/or large numbers of Clean boxes.
             Leading and trailing blanks from all lines in the text
             file are discarded, so "column 1" below means the first
             non-blank column in the card.
             This option is used to specify field parameters for
             fields 1 through NFIELD which are then copied to the
             fields used for additional scales (if any).  To specify a
             field's parameters, put the letter F or f in column 1
             followed by the field number, the X and Y FLDSIZE values,
             the RASHIFT amd the DECSHIFT for the field (separated by
             blanks).  Any field specified in this way overrides the
             corresponding parameters given in the adverbs.  Thus,
             F  2  450 450 -25.5 6.7
             specifies that field 2 is to have a FLDSIZE of 450x450 with
             an RASHIFT of -25.6 and a DECSHIFT of 6.7 arcsec.  If this
             is the only F card in the file, then fields 1 and 3 through
             NFIELD are set by the adverb values.  As an alternative, a
             field may also be specified with a "coordinates" card
             having a C or c in column one.  After the C, give the field
             number, the X and Y FLDSIZE values and the center Right
             Ascension (HH MM SS.S) and Declination (signDD MM SS.S)
             separated by blanks.  Thus
             C  2  450 450  11 34 45.67 -00 14 23.1
             specifies that field 2 is to have a FLDSIZE of 450x450 with
             a center RA of 173.6902917 degrees and a center Declination
             of -0.23975 degrees.  All 9 numbers must be given; the sign
             is optional for positive declinations and is given only on
             the degrees term.

             To set a BCOMP include put the letter B or b in column 1
             followed by the field number and the value of BCOMP to
             be used.  Thus, to include no components from field 98 and
             some from 99 include the lines:
             B   98     0
             B   99   243
             Fields 1 through NFIELD*(Number of scales) may be
             specified.

             To set Clean boxes, specify one box per line, as field
             blc-x blc-y trc-x trc-y (5 integers) e.g.
             1 200 205 220 222
             1 230 232 240 241
             2 100 100 130 121
             ...
             or circular "boxes" as
             field -1 radius center-x center-y  (5 ints) e.g.
             001  -1  10 210 214
             001  -1   5 235 237
             ....
             Column 1 must contain a numeric character (part of the
             field number); otherwise the line is treated as some
             other sort of line.  Fields with no boxes specified --
             and auto-boxing turned off (IM2PARM(1) = 0) --- default
             to the size specified by IMSIZE and FLDSIZE (see above
             and including FLDSIZEs read from this file).  This option
             overrides NBOXES and CLBOX if any boxes for field one
             appear in the file.  Otherwise, those adverbs are used
             for field 1.      E.g.  BOXFILE 'FITS:BOXES'
             Fields 1 through NFIELD*(Number of scales) may be
             specified.  If you do not give boxes for a field >
             NFIELD, then the boxes for the corresponding field at
             full resolution (0 scale) are copied to those at the
             lower resolutions (larger scales).
             If BOXFILE = ' ', NBOXES and CLBOX apply unchanged as do
             the FLDSIZE, RASHIFT, and DECSHIFT adverbs.
             The NVSS WWW server may help in preparing these values;see
             below.
             The number of Clean boxes per field is limited to
                  min [ 4096, (64*4096)/(NFIELD*NGAUSS) ]
             To specify that a field has no Clean boxes, specify the
             BLC and TRC as four zeros.

             To mark regions which should never be Cleaned, include
             lines beginning with U or u.  Following that character
             with at least one blank, enter the facet number and four
             values as for Clean boxes (i.e either rectangular or
             circular).  The UNClean boxes may be changed with the TV
             when DOTV is true.  Thus, for example
             U 2 100 100 130 121
             u    001  -1   5 235 237
             will protect one area in each of facets 1 and 2 from
             Cleaning.  This option is primarily used to isolate a
             source to one special facet and to keep it from being
             Cleaned in another facet.  Modeling routines may then use
             the special facet - or all facets except the special one
             - to isolate the source.  Task CCEDT is also used for
             this purpose when UNClean boxes have not been used.

             When combining more than one spectral channel or IF, you
             may wish to alter their relative weights in a temporary
             fashion.  The BOXFILE option allows this with W cards:
             W in column 1, then a weight, then a channel number (0 ->
             all), and last an optional IF number (absent -> 0, 0 ->
             all).  For example:
             W  0.1   1
             W  0.5   2
             W  0.8   2  3
             W  0.1  63
             Assigns weight 1 to all channels 3-62, weight 0.1 to all
             channels 1 and 63, weight 0.5 to channel 2 except for 0.8
             in channel 2, IF 3.  These "weights" multiply the weights
             already assigned to the data.

             When imaging with multiple facets, especially with
             multiple scales, you may wish to have some of the facets
             ignored in the Cleaning.  To do this, give "I" cards with
             a facet number or a range of facet numbers as
             I  18

             I  23 36
             to image facets 18 and 23 through 26 but never consider
             them for Cleaning.  Note, when giving a range, the first
             number must be lower than the second number.

             The BOXFILE option is essential when NFIELD > 64.
  OBOXFILE...Output text file to record the Clean boxes used.  If
             BOXFILE is also used and OBOXFILE points at a new file,
             then IMAGR starts by copying all of BOXFILE to OBOXFILE.
             Then, each time a TV REBOX or TVBOX is selected the file
             is rewritten (as the TV interaction ends) with all of the
             Clean boxes currently in force for all fields.  The lines
             in the file containing other kinds of information are
             retained throughout.  Thus, one can set OBOXFILE=BOXFILE
             or for safety make a new OBOXFILE but then use that as
             input the next time.
  GAIN.......The Clean loop gain.  0 => 0.10.
  FLUX.......Stop Clean when abs(resid. image max) < FLUX in Jy.
             If FLUX < 0 then Clean stops after the first negative
             Clean component (the actual value of FLUX is then
             irrelevant).  Note that on restarts and in OVERLAP < 2
             mode, when the residual levels are known for all fields,
             the Clean is stopped if all fields are below 1.05 *
             FLUX.  When each facet is Cleaned, the Clean proceeds
             until the next component is less than 1.0 * FLUX however.
             This "slop" is to prevent expensive major cycles being
             initiated to deal with weak bumps that appear after the
             model has been subtracted and the fields re-imaged.
  MINPATCH...Minimum half width of the portion of the beam which is used
             in the AP minor Clean. (init 51)  Use 51 for deep Cleans of
             extended sources.  Use a large value if the beam has big
             side-lobes.
  BMAJ.......The FWHM (asec) major axis of the restoring beam. If 0;
             value obtained from fitting to the beam.  If <0; output
             will contain the residual image.  This is for the
             point-source resolution.  It will be corrected to the
             other scales (if any).
  BMIN.......The FWHM (asec) minor axis of the restoring beam.
  BPA........The position angle in the unrotated image of BMAJ.
  FACTOR.....FACTOR>0 causes deeper Clean in each major cycle, speeding
                Clean, maybe "eating" extended structure.  OVERLAP=2
                mode may need speeding with FACTOR and/or larger
                MAXPIXEL.
             FACTOR=0 => the normal Clark Clean. FACTOR=-0.3 is good for
                deep Cleans of extended structure.
  CMETHOD....This determines the method used to compute the model
             visibility values.
             'DFT' uses the direct Fourier transform, this method is the
                   most accurate.
             'GRID' does a gridded-FFT interpolation model computation.
             '    ' allows the program to use the fastest method,
                    except that DFT will be used on images <= 128 for
                    accuracy reasons.
  IMAGRPRM...Correction control parameters (SEE EXPLAIN IMAGR):
             (1) If > 0 then make frequency dependent primary beam
               corrections assuming an antenna diameter of IMAGRPRM(1)
               meters.  Can change with TELL which only makes sense if
               you are going to repeat the subtraction with a filtered
               set of components (see IMAGRPRM(8)).  Note that VLA and
               ATCA arrays (TELESCOPE header parameter) use the
               default primary beam parameters defined elsewhere in
               AIPS, while other antennas actually use IMAGRPRM(1) as
               the diameter of a "standard" telescope.  See FQTOL
               below also.
             (2) Visibility amplitudes will be corrected to the average
               frequency assuming a spectral index of IMAGRPRM(2).
               Note: the typical optically thin synchrotron spectral
               index is about -0.7.
             (3) If > 0, then the u,v and w terms are scaled by
               IMAGRPRM(3) before imaging.
             (4) If > 0, then SDI Clean will be used when the fraction
               of residual pixels in the Clean boxes stronger than
               half the maximum residual exceeds IMAGRPRM(4).  <= 0 ->
               never use or allow SDI Clean.  Can change with TELL.
               If SDI Clean is enabled, the output CC files will have
               been merged.
             (5) If > 0 then scaling of residuals is requested and
             (6) Half-width in x of box to determine the dirty beam area
               (default = 5)
             (7) Half-width in y of box to determine the dirty beam area
               (default = 5)  Can change (5)-(7) with TELL.
             (8) If non-zero, select only those Clean components having
               > ABS(IMAGRPRM(8)) Jy within a radius of IMAGRPRM(9)
               cells of the component.  If IMAGRPRM(8) < 0, the abs
               value of the flux near the component is used.  This is
               an optional filter to remove weak isolated components
               which can cause a significant bias.  Can change with
               TELL but only if it was non-zero to begin with.  A copy
               of the input data has to be made for this option and it
               is only made if IMAGRPRM(8) is non-zero.  If this
               option is selected, the output CC files will have been
               merged.  Note that IMAGRPRM(8) should always be <= 0
               for images of Q, U, and V Stokes parameters since
               negative brightnesses are valid.  Filtering is done on
               restarts, when requested from the TV, on certain
               Cleaning failures, on normal completion (after which
               the task may resume Cleaning depending on IMAGRPRM(9)
               until the completion points such as NITER and FLUX are
               reached a second time) and on final exit.  If ALLOKAY
               >= 2, the filter is not applied on the restart.  If the
               filtering option was selected at the start (IMAGRPRM(8)
               non zero), it may be turned off by setting IMAGRPRM(8)
               exactly 0 and running TELL.  To delete all negative
               regions, set IMAGRPRM(8) to a tiny positive number.
             (9) The abs(IMAGRPRM(9)) is the radius in cells for the
               area in which fluxes are computed.  If IMAGRPRM(9) < 0,
               the Clean will restart following the "final" filtering
               on the assumption that enough changes are made by the
               filter that more Cleaning will be needed.
               abs (IMAGRPRM(9)) < 1.1 => 3.1.  Can change with TELL.
             (10) = multiplier of max image size to set beam size.
               Values of 2, 1, 0.5, and 0.25 are allowed.  0 => 2.
               Smaller beam images are a bit faster, but less accurate
               in the early Clean cycles.  The largest beam image used
               is 2048 on a side except when IMAGRPRM(1) > 0.75.  When
               IMAGRPRM(10) is 1, the limit is 4096 and when
               IMAGRPRM(10) > 1.5, the beam is twice the image size
               limited by 32768.
             Multi-scale experimental controls are based on
                BeamRatio = (field beam area) / (min beam area)
             (11) Multi-scale experimental control: select which
               field to Clean using peak fluxes (in Jy/beam) weighted
               by 1 / (BeamRatio)**IMAGRPRM(11).  This is important.
             (12) Multi-scale experimental control: decrement the
               value of IMAGRPRM(11) used above by IMAGRPRM(12) each
               time an non-point resolution field is Cleaned until it
               is 0.
             (13) Multi-scale experimental control: use gain =
               GAIN * [ {1/BeamRatio} ** IMAGRPRM(13) ]
             (14,15) Multi-scale experimental control: use
               factor = FACTOR * (1 - IMAGRPRM(14) * [ 1 -
                 1.0/({BeamRatio} ** IMAGRPRM(15)) ]
             (16) Multi-scale experimental control: use maxpixel
               = MAXPIXEL + IMAGRPRM(16) * (BeamRatio)
             Multi-scale experimental control limits:
                 0 <= IMAGRPRM(11) <= 1.0    not changed by TELL
                 0 <= IMAGRPRM(12) <= 0.1    changed by TELL
                 0 <= IMAGRPRM(13) <= 1.0    changed by TELL
                 0 <= IMAGRPRM(14) <= 1.0    changed by TELL
                 0 <= IMAGRPRM(15) <= 1.0    changed by TELL
                 0 <= IMAGRPRM(16)           changed by TELL
             (17) 1 => use a spectral-index image represented in
               IN3NAME, IN3CLASS, IN3SEQ, IN3DISK below to correct the
               Clean component model for each channel.  IN4NAME et al
               will also be used as a curvature image iff IN3NAME are
               specified.
               IMAGRPRM(17)-0.5 is used as a radius in pixels over
               which the spectral index image is averaged.  When it is
               small (0 < IMAGRPRM(17) <~ 1), the spectral index is
               interpolated rather than averaged.  See FQTOL below as
               well.  When doing spectral index, the primary beam
               correction (IMAGRPRM(1)) costs very little extra.
             (18) In OVERLAP>=2 mode, when imaging multiple fields,
               IMAGR grids and FFTs multiple fields in an attempt to
               determine the next one to Clean.  Multiple fields are
               done to reduce I/O in this search which may otherwise
               have to re-read the work file several times to find the
               next field to Clean.  The limit on the number of fields
               done depends on the maximum size of the AP, the size of
               the images, etc - trying to guess when I/O will be
               expensive in time.  Sometimes, IMAGR will make more
               images than are needed at a subsequent excess cost.  To
               limit the number of fields imaged at any one try, set
               IMAGRPRM(18) to the maximum number you want to allow.
               The task will now reduce the maximum number when the
               multiple fields all have similar maxima - i.e. after
               the wide dynamic range early cleans are done.
             (19) In OVERLAP>= 2 mode, when Cleaning a field with a
               small bright source, it is possible to Clean too
               deeply.  Then weak lumps due to sidelobes of strong
               sources in other fields are treated as sources in the
               present field.  By the time the present field is
               Cleaned again, these errors become very apparent.  This
               parameter is used to limit the weakest source Cleaned
               in this major cycle to IMAGRPRM(19) times the strongest
               source in this cycle.  The default is the sum of the
               maximum sidelobe outside a radius of 5 pixels and the
               maximum sidelobe outside a radius of MINPATCH pixels.
               IMAGRPRM(19) is also used to limit the depth of a SDI
               Clean major cycle.  SDI never goes deeper than 0.33 of
               the peak, but even that may be too much.
             (20) In OVERLAP >= 2 mode, the objective function of the
               selected field after it is re-imaged is compared to the
               objective function of the second best field (without
               re-imaging).  If the second best now appears better
               than the selected field by a factor greater than
               IMAGRPRM(20), then the task will try another field.
               0 = 1.005.  (Values < 1 are converted to 1/IMAGRPRM(20)
               and, finally, values > 5 => 1.005.)
  IM2PARM....Even more IMAGR parameters:
             Auto-Clean boxing (can be changed by TELL):
                (1) IMAGR can create Clean boxes automatically.  In
                    OVERLAP 2 mode it will do this only in the facet
                    about to be Cleaned.  In OVERLAP < 2, it looks at
                    every facet at each major cycle.  It will find no
                    more than the strongest IM2PARM(1) boxes each time
                    it looks.  <= 0 => don't do.  Limit 50.
                (2) The auto-boxing starts by finding islands of
                    emission > IM2PARM(2) * rms in the residual image.
                    This defines the size of the box if it is
                    accepted.  (0 -> 3.0)
                (3) A box can only be accepted if its peak brightness
                    is > IM2PARM(3) * rms in the residual.  A box is
                    also accepted only if the peak in it is not
                    already in a Clean box.
                    < IM2PARM(2) -> IM2PARM(2) + 2.0
                (4) A box is also only accepted if its peak brightness
                    is > IM2PARM(4) * maximum residual in the whole
                    image.  < 0.01 OR > 0.9 -> 0.1
                (5) The box determined by the island may be extended
                    outward in all directions by IM2PARM(5) pixels.
                    < -1 => 1.  Note that -1 means compressed by 1 in
                    radius or in all directions for rectangles.
                (6) The residual image is examined only in an ellipse
                    (circle if IMSIZE(1) = IMSIZE(2)) of radius in X
                    of IMSIZE(1)/2 - IM2PARM(6) and in Y of
                    IMSIZE(2)/2 - IM2PARM(6).  <= 0 -> 5
                (7) When imaging an output cube, should channel N+1
                    begin with the boxes of channel N or only with
                    those set up by BOXFILE, CLBOX, etc.?
                    > 0 - begin with initial boxes in each channel
                    < 0 - pass boxes along to next channel
                    = 0 => +1 when auto-boxing, -1 when not doing
                          auto-boxing
             TV timeout controls:
                (8) The first TV display resumes Cleaning after
                    IM2PARM(8) seconds.  0 -> 600
                (9) After the first, the TV display resumes Cleaning
                    after IM2PARM(9) seconds.  0 -> 30.
             Baseline-depndent and frequency averaging:
                (11) The maximum elapsed time over which averaging of
                     data may be done in seconds.  0 -> infinite
                (12) The desired field of view radius in arc minutes
                     which is not to be distorted by time averaging in
                     a baseline-dependent fashion.  <= 0 -> infinite
                     or no averaging.  The field of view is the region
                     in which averaging is not to reduce the amplitude
                     by more than 1% on any baseline.  No data
                     separated by more than 268.5 wavelengths divided
                     by IM2PARM(12) are averaged together.  It might
                     be wise to make this parameter larger than the
                     field of view about which you care.
                (13) Average IM2PARM(13) channels together in the
                     on-the-fly averaging when IM2PARM(12) > 0.  Note
                     that you can get channel averaging without time
                     averaging by setting IM2PARM(11) to a small
                     enough (but > 0) value while setting IM2pARM(12)
                     to an appropriate value.  If IM2PARM(13) is 1,
                     IMAGR will compute the number of channels based
                     on the maximum possible baseline and the value of
                     IM2PARM(12).  This parameter must be <= NCHAVG
                     and both NCHAVG and CHINC should be integer
                     multiples of IM2PARM(13).
             Future expansion:
                (10)
                (14) - (40)
  NGAUSS.....Number of scales to use.  0 -> WGAUSS=0 and NGAUSS =
             1.  The total number of scales is NGAUSS and the
             total number of fields imaged will be NFIELD*NGAUSS.
             Clean boxes specified for fields 1-NFIELD will be copied
             to the corresponding fields NFIELD+1 to NFIELD*NGAUSS
             unless (using BOXFILE) you have specified them already.
             RASHIFT, DECSHIFT, FLDSIZE are specified only for fields
             1-NFIELD.  See multi-scale Clean discussion in the
             Explain section.
  WGAUSS.....The FWHM of the circular Gaussian source models to be
             used.  If a point source is to be used (which is
             recommended), then WGAUSS(1) should be 0 and WGAUSs(2)
             through WGAUSS(NGAUSS) > 0.  IMAGR will go through the
             widths to insure that, if a WGAUSS of 0 is used, it is
             the first one.  All resolutions now have components from
             all resolutions restored to them scaled appropriately
             with the widths of the fatter of the two resolutions.
  FGAUSS.....The minimum flux in Jy/beam for each scale in the
             same order as WGAUSS.  Must be >= FLUX to have much
             effect.
  MAXPIXEL...The maximum number of pixels that are searched for
             components inside the ``AP'' in each major cycle.  <= 0
             => 20000.  This number affects the cpu usage significantly.
             Too many causes the task to search over many points it will
             never use.  Too few causes the task to do many more small
             major cycles, also at great expense.  Use this with great
             caution, but big wins are possible using larger sizes on
             very large Cleans.  OVERLAP=2 mode may need speeding with
             FACTOR > 0 and/or larger MAXPIXEL.
  IN3NAME....Image name of spectral index image; no default.
  IN3CLASS...Image class of spectral index image; no default.
  IN3SEQ.....Image sequence of spectral index image; 0 -> highest.
  IN3DISK....Disk of spectral image image; 0 -> any.
  IN4NAME....Image name of spectral index curvature image; no
             default.  Curvature images should be base 10 rather than
             base e - they differ by a factor of 2.3.  Also the
             reference frequency for them is 1 GHz.  These are changes
             done 2010-07-13.
  IN4CLASS...Image class of spectral index curvature image; no
             default.
  IN4SEQ.....Image sequence of spectral index curvature image;
             0 -> highest.
  IN4DISK....Disk of spectral curvature image image; 0 -> any.
  FQTOL......Frequency tolerance in kHz.  Spectral channels with FQTOL
             are handled together (use the same average CC model) when
             applying the primary beam and spectral index
             corrections.  Default is to do each channel separately
             which can take a long time.
  DOTV.......Display residuals on TV channel 1. > 0.5 => display field
             number DOTV initially. Can be changed interactively and by
             TELL. When using this option, you may interact with the
             residual images, selecting which field is examined in what
             window, resetting the Clean boxes, and stop the Cleaning of
             the current channel.  IMAGR uses DOTV in the form of the
             nearest integer; set it only to integer values.
  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.
----------------------------------------------------------------

            See EXPLAIN IMAGR for more information on the
            imaging parameters.
