NAME:
  linkobj2
 PURPOSE:
  Cross check source lists from one field and identify moving objects.
 DESCRIPTION:

 CATEGORY:
  Astrometry
 CALLING SEQUENCE:
  linkobj2,tag,files
 INPUTS:
  tag   - name of the field, should not contain any blanks
  files - string array of file names for source lists to be linked.
 OPTIONAL INPUT PARAMETERS:

 KEYWORD INPUT PARAMETERS:

  BADCOL    - Array of column numbers, any source found within 2.5 pixels of
                these columns will be discarded.  Default = no bad columns.

  CLEANAUTO - Flag, if set, all objects previously identified by "auto"
                that are flagged with "?" and appear at the end of the list
                will be removed from the list before any new linked objects
                are added.

  KEYLIST=  - Name of a file containing a correspondence list. This list
                 associates a set of standard names with the actual keyword
                 names found in a FITS file header. If this keyword is
                 omitted, a default list is used, as if a file with the
                 following contents had been supplied:
                  AIRMASS   K  AIRMASS
                  DATE      K  DATE-OBS
                  DATETMPL  T  DD-MM-YYYY
                  EXPDELTA  V  0.0
                  EXPTIME   K  EXPTIME
                  FILTER    K  FILTERS
                  FILENAME  K  CCDFNAME
                  OBJECT    K  OBJECT
                  UT        K  UT 
                 The middle column is a flag. It may be K, for Keyword,
                 T, for Template, or V, for Value. If it is V, the contents
                 of the third field on that line should make sense for the
                 name in the first field.

  KILLSRD -   Flag, if set, this program will delete the pair of offending
                 srd files if the mean offset between the fixed sources is
                 out of range.  When this happens, the .obj file is not
                 altered, an error message is printed on the screen, and
                 time-stamped information is written to linkobj2.err in
                 the current directory.

  MAXDUPLERATE - Maximum motion rate permitted for a duple, in arcsec/hour.
                The default is 5.0 arcsec/hour.  Warning, making this too
                big can create a very large number of false positive
                detections.

  MAXINCLINATION - Maximum motion angle from the ecliptic to be allowed.
                      Used for duple only.  Default=no limit

  MAXMAGDIFF - Maximum magnitude difference allowed between two measurements
                   to be tagged as a moving object.  This is used ONLY for
                   checks of duples.  The default value is 1.0 mag.  However,
                   the allowed difference can be larger if the photometric
                   errors are large.  The test is to keep objects whose
                   variation is 3-sigma or less or magdiff less than maxmagdiff

  MAXOBJ    - Maximum number of objects to report as linkages.  Default
                is to report everything.  Only the first MAXOBJ objects
                will be reported.  This can safeguard against the situation
                where a bad astrometric solution leads to a very large number
                of linkages.

  MAXOFFSET - Maximum offset post-correlation in pixels to flag a bad
                overlay.  Default is 1.5 pixels.  Use the feature with
                extreme caution.  It's very easy to let garbage through if
                you make this too big.

  MAXRATE   - Maximum motion rate permitted for a tripet, in arcsec/hour.
                The default is 50.0 arcsec/hour.

  MINHITS   - When linking 3 or more frames, this variable controls the
                minimum number of coincident hits that are required to
                flag the link as valid.  Default=3.

  MINRATE   - Minimum motion rate permitted for a tripet, in arcsec/hour.
                The default is 1.0 arcsec/hour.

  PATH      - Optional path for original image directory.
                If not specified, the current directory is used.

  SNRTHRESH - Signal-to-noise ratio threshold.  Default is to use all objects
                in the input lists.  If you provide a threshold, all objects
                with SNR less than this will be excluded from the linking.

  SRDDIR    - Directory for the srd files, default=current directory

 OUTPUTS:

 KEYWORD OUTPUT PARAMETERS:

 COMMON BLOCKS:

 SIDE EFFECTS:

 RESTRICTIONS:

 PROCEDURE:

 MODIFICATION HISTORY:
   98/03/11, Written by Marc W. Buie, Lowell Observatory
   2000/02/08, MWB, numerous bug fixes and enhancements.
   2000/03/09, MWB, minor bug fix for n-tuples and added MINHITS
   2000/05/01, MWB, added MAXOFFSET keyword
   2000/07/31, MWB, added MAXOBJ keyword
   2000/10/18, MWB, added SNRTHRESH keyword
   2003/10/01, MWB, converted my Delfile call to system file_delete routine
   2004/06/24, MWB, added MAXMAGDIFF keyword
   2010/07/19, MWB, minor tweak to accomodate change to frmdxdy
   2015/03/28, MWB, changed error logging to use logerror procedure
                    Also changed to generate obj files even with an error
                      this change now bypasses the /KILLSRD flag operation.
   2016/05/29, MWB, added SRDDIR keyword