NAME: 
  ltcrv
 PURPOSE: 
  Photometric lightcurve reductions against a single comparison star.
 DESCRIPTION:
 Generates lightcurve products including entries in the PHOT.data
 table, wrphot file and plots.
 CATEGORY:
  Photometry
 CALLING SEQUENCE:
  pro ltcrv,stand,fil,jd,am,serial,mag,err,object,objno,comp,dofil, $
       jdobs,redmag,rederr 

 INPUTS:
  stand  - String array of standard names.  (See coord.)
  fil    - String array of filter names for observations.
  jd     - Double precision array of Julian dates.
  am     - Floating point array of the airmass of observations.
  serial - Serial number of observation.
  mag    - Raw instrumental magnitudes.
  err    - Uncertainties on the raw magnitudes.
  object - Standard name of program object to reduce against comp star.
  objno  - Serial number of program object.  (Usually 0)
  comp   - Standard name of comparison star.
  dofil  - Name of filter to reduce.
 OPTIONAL INPUT PARAMETERS:
 KEYWORD INPUT PARAMETERS:
  BAD     - Set of flags that will mark data bad (if 1), good if 0.
  BINFAC  - Maximum amount of comparison star point to bin (default=6)
  COLORNAME - Name of reduction color to put in data table, eg 'B-V'. Normally
              this will be the color corresponding to the color of the transf
              record fetched. For a non standard filter such as 'M' there will
              be no transf record and colorname is passed as '' or skipped.
  CTERM   - Color term and error (default=[0,0])
  DATABASE- string, name of photometry MYSQL database, by default 'phot'
  DB      - Flag, if set, reduced object observations will be saved to database.
  DVERBOSE-  Code for dbphot and other routines for db transaction verbosity.
  FILE    - name of file to write reduced object data using wrphot. By default, 
               no file is written.
  FILTNAME- Proper name of filter, should be just one or two characters.
               if not given, 1=B, 2=V, 3=R is used for the default
  FORCE   - Two element vector that contains override values for the
                mean extinction and its uncertainty.  This replaces the
                initial fit for mean extinction.
  K2      - Second order extinction coefficient and error (default=[0,0])
  NOEDIT  - Flag, if true will inhibit editing the bad flags of the data.
  NOFILES - Flag, if true will inhibit generation of the summary file.
  NOPLOT  - Flag, if true will inhibit the summary plot.
  NOPRINT - Flag, if true, will inhibit the summary printout to the screen.
  NOSAVE  -  Flag, if true, will inhibit modification of files or databases.
  OCOLOR  - Standard color and error for object (default=[0,0])
  OBJNAME - Proper name of object, default = object:objno
  PLOTWIN - Plot window to use for output plots (default = current window)
  REFID -   String uniquely identifying observing run. This is used in 
               updating the data table in the phot 
               database. It must be specified if DB is used.
  SCOLOR  - Standard color and error for star (default=[0,0])
  STDMAG  - Standard magnitude and error for star (default=[0,0])
  TABLE   - string, name of photometry database table, by default 'data'.

 OUTPUTS:
  jdobs  - Final Julian date of reduced observation of program object.
  redmag - Final reduced magnitude of object compared to comp star.
  rederr - Final uncertainty.
 KEYWORD OUTPUT PARAMETERS:
  NOBS -   Final number of observations reduced. (Note: includes object
             observations marked bad.)
 COMMON BLOCKS:
 SIDE EFFECTS:
 Update data table in photometry data base, after removing previous 
 observations for the same object, rundate, filter and color. Observations
 marked bad are not included in the data base. (see jdobs, NOBS).
 RESTRICTIONS:
 PROCEDURE:
 MODIFICATION HISTORY:
  93/07/28 - Written by Marc W. Buie.  Patterned after a similiar program
              of David Tholen's.
  93/10/25, MWB, added optional transformation coefficients.
  93/12/10 - MWB, added extinction override (FORCE)
  96/02/21 - MWB, total rewrite, added BAD flags
 2006/08/09 - Peter L. Collins, Lowell Observatory.
                add db output for reduced obs parallel to wrphot and header cleanup.
 2006/09/26, PLC, add INSTRUMENT keyword to pass through to dbphot.
 2006/10/16 - PLC, add NOSAVE flag.
 2006/12/07 - PLC, replace instrument and rundate keywords by REFID and
                   change calls to dbphot.
 2006/12/14, MWB, added PLOTWIN keyword.
 2006/12/28, PLC, added DVERBOSE keyword.
 2007/01/05, MWB, added NOEDIT keyword.
 2007/02/05, PLC, fixes to deal with bad flags, and special cases with
                  all objects or all comp obs marked bad. It is now set
                  up so all obs placed in db have bad flags = 0.
                  Calls to dbphot now provide color field. Dbphot scrubbing
                  now occurs at start. Added NOBS and COLORNAME keywords.
 2009/10/02, MWB, changed Polyfitw call to poly_fit equivalent
 2012/10/10, MWB, fixed problem with FORCE=0 case that caused code to crash
 2014/03/06, MWB, added REFCOLOR, REFAM, AMSQ, COLSQ keywords