NAME:
  occtime
 PURPOSE:   (one line only)
  Extract simple occultation timing from an occultation lightcurve
 DESCRIPTION:
  This program reads a lightcurve file that containes an occultation and 
    fits a perfect occultation model to get the start and stop times of
    the occultation.
  There are other files expected that provide supporting information for
    the occultation.
   xtrack.in   - contains general information about the occultation
                   leading and trailing blanks on a line do not matter
                   any lines after the required set are ignored
     line 1 - Object code (for geteph, see ephem.pro)
     line 2 - RA of the star (sexigesimal string)
     line 3 - Dec of the star (sexigesimal string)
     line 4 - geocentric UT date and time of appulse
     line 5 - 1-sigma down-track uncertainty (in seconds)
     line 6 - 1-sigma cross-track uncertainty (in km)

   crosstrack.dat - created by occxtrack

   lcinfo.dat  - definition of region of fitting for the lightcurves for
                   all stations
     col 1 - Site code
     col 2 - Number of points in perfect model
     col 3 - Start time of model relative to prediction
     col 4 - End time of model relative to prediction
     col 5 - point number of ingress (first point showing a drop)
     col 6 - point number of egress (last point showing a drop)

 CATEGORY:
  Occultations
 CALLING SEQUENCE:
  occtime,fnlc
 INPUTS:
  fnlc - Name of lightcurve file.  The data are expected to be in tabular
           format, space separated.  The first column is often the point
           number but is not used by this program.  Only these columns are
           used:
           col 2 - Julian Date of lightcurve measurement (mid-time, UTC)
           col 3 - Flux from target star, usually normalized

           Anything after column 3 is ignored but usually contains
             then non-normalized flux, x,y position, and FWHM in pixels.

           If the filename is of the form ..lc, the
              string is used to provide the default value for TEAM

 OPTIONAL INPUT PARAMETERS:
 KEYWORD INPUT PARAMETERS:
  NOSAVE - Flag, if set suppresses saving the output grapics
  TEAM   - String, name of the team/data [default from fnlc if the right form]
  XRANGE - time range to plot [seconds], default is to plot it all
  YRANGE - flux range to plot, default is to plot full range
  NOTSIG - Flag, if set suppresses showing the time sigma hacks on the plot
  MCMC   - Flag, if set runs a MCMC fit and error analysis run on the
              event.  This should not be run until you have a good simple
              fit for the event and lcinfo.dat is set properly.  Note that
              that the event times found in events.dat are not used by
              this program and are not updated automatically.
  FNCONFIG - Config file to read, default='config.ini', overrides TAG
  FNSITES - name of the file with site location information (default=sites.dat)
  FNEVENTS - name of occultation events file (default=events.dat)
  FNXTRACK - crosstrack file to read, default='crosstrack.dat', overrides TAG
  TAG      - Extra tag for certain file names.  Default is ''.  This is
              used when there are multiple objects in an occultation
              dataset.  The files that are modified are:
               fnconfig, fnxtrack, and saved lightcurve plots
              crosstrack.dat becomes crosstrack_.dat, you don't
              provide the underscore, just the tag.  Note that the sites.dat
              and events. dat files work for all bodies.
 
 OUTPUTS:
   plots mostly but window 0 is saved to Results/__lc.png,
      unless you supply a TAG then it would be ___lc.png
 KEYWORD OUTPUT PARAMETERS:
 CONFIGURATION:
   File: config.ini
   [global]
     objectid - string with the object id (see ephem.pro)
     ora      - Apparent position of star at time of occultation
     odec     - Apparent position of star at time of occultation
     geomid   - UT date and time of geocentric closest approach
     tsig     - 1-sigma uncertainty in event time (down-track) in seconds
     xsig     - 1-sigma cross-track uncertainty in km
 COMMON BLOCKS:
 SIDE EFFECTS:
 RESTRICTIONS:
 PROCEDURE:
 MODIFICATION HISTORY:
  Written by Marc W. Buie, Southwest Research Institute, 2020/01/31
  2020/03/29, MWB, code simplifications
  2020/10/06, MWB, added support for config.ini file
  2022/03/27, MWB, now reads model information from config.ini if lcinfo.dat
                      is not found
  2022/06/07, MWB, added FNCONFIG,FNCHORDS,FNXTRACK keywords
  2022/12/14, MWB, convert to using fnsites.dat and fnevents.dat
  2023/03/16, MWB, fixed D&R time to account for non-zero baseline
  2023/03/28, MWB, force renormalization of lightcurve