NAME:
   transf

 PURPOSE: (one line)
   Determine transformation coefficients from instrumental to standard mags.

 DESCRIPTION:

   This will take a set of all-sky standard star measurements and derive
     the best fitting set of transformation coefficients from instrumental
     to standard magnitudes.

   Normally, you give this routine ALL the data taken with a single filter.
     Only those objects that are standards in this filter and the alternate
     color will be used in the fit.  Only those that should be standards
     can end up marked as bad from this program.

   My conventions for the photometric fit are patterned after Hardie's
     nomenclature.  However, there is one additional term I've added which
     is a first order expansion term of extinction with respect to time.
     The basic formula for the transformation is:

       m0 = m - kX - n(t-t0)X - k"CX + eC + Z

        where
           m  = instrumental magnitude
           k  = extinction coefficient, mag/airmass
           X  = airmass
           n  = coefficient of the 1st order expansion of extinction as a
                  function of time
           t  = Time of observation (in hours)
           t0 = Reference time for n, time dependent correction is zero at
                  this time, usually is the middle of the observation set.
           k" = second order extinction coefficient
           C  = Standard system color of the object
           e  = color term
           Z  = zero point
           m0 = Standard magnitude

   The fitting process takes advantage of the uncertainties on the instrumental
     magnitude and the uncertainties on the forced terms.  The uncertainties
     on the catalog standard magnitudes are ignored.  The coefficients, k",
     e, and n are considered to be auxillary coefficients and can be either
     fit for or forced.  k" and e can be forced to explicit values.  n is
     either fit for or set to 0.  The extinction and zero-point are always
     fit for.

 CATEGORY:
   Photometry

 CALLING SEQUENCE:
  transf,names,jd,filter,color1,color2,airm,mag,err,bad,
    [ RESID=resid,FILE=landfile,NOPLOT=noplot,OTHER=other,
      OLAB=olab,TITLE=title ]

 INPUTS:
  names  - String array of standard names.
  jd     - Julian date of observations.
  filter - Filter number of data. (0-U, 1-B, 2-V, 3-R, 4-I)
  color1 - First filter for color.
  color2 - Second filter for color.  (eg., B-V is 1,2)
  airm   - Vector of airmasses for observations.
  mag    - Vector of instrumental magnitudes.
  err    - Vector of uncertainties.
  bad    - Vector of flags, 0=good, 1=bad, default is good

 OPTIONAL INPUT PARAMETERS:

 KEYWORD INPUT PARAMETERS:

  These keywords affect how the fit is done.

  CTERM  - Optional, fixed color term.  If provided, the color term is
              assumed, not fitted.
  K2     - Second order extinction coefficient.  If provided, this term
              is assumed, not fitted.
  KTIME  - Flag, enable time dependent extinction.

 -------------------

  These keywords affect the plotting output

  NOPLOT   - Flag, if true inhibits the summary plots.
  OLAB     - Label for the plot of residuals vs. OTHER.
  OTHER    - If provided, allows plotting the residuals against some other
              variable, eg., exposure time.  Must match the length of
              the data input vectors.

 -------------------

  Other control options

  FILE     - Optional name for the Landolt "system" Standards catalog.
  NOEDIT   - Flag, if set inhibits final interactive editing of fitted points.
             This keyword has no effect and is not necessary if the current
             plotting device is 'PS'.
  RESID    - Flag, if true enables printing a full residual table.
  TITLE    - Title for plots.
  NOFILES  - Flag, if true supresses saving information to summary files.
  NOSAVE  -  Flag, if true supresses saving information to databases or
             summary files. NOSAVE implies NOFILES.
  CHISCALE -Flag, if true rescales final solution to force reduced Chi=1.0
  TAGDATE  -String identifying date of data.
  TAGINST  -String identifying instrument.
  HISTFILE -File name of history file to update extintion values in.
             Only one line for TAGDATE/TAGINST is allowed.  If a duplicate
             is found, the appropriate line is replaced.
  MAGRESID - Edit bad values by mag residual, not sigma residuals
  DB       - flag, if set will use MYSQL server and validly populate outputs
                fitted, nobs, chi2, quality and comments.
  DATABASE - Name of MYSQL database for transformation search. Passed 
                to puttran.  The default is 'phot'. Used only when DB set.
  DVERBOSE  - flag passed to gettran and puttran to set  db screen verbosity.
  TABLENAME- Name of table in MYSQL database for transformation search.
                Passed to puttran. The default is 'transf'. Used only if DB set


 OUTPUTS:
  No explicit vector outputs.  All output is graphical, printed to the
    screen, or saved to external files.

 KEYWORD OUTPUT PARAMETERS:

 COMMON BLOCKS:
  None

 SIDE EFFECTS:

 RESTRICTIONS:

 PROCEDURE:

 MODIFICATION HISTORY:
  93/08/05, Initial version completed, Marc W. Buie, Lowell Observatory.
  93/10/05, MWB, added support for 1993 catalog.
  95/02/22, MWB, modified plots.
  96/10/16, MWB, added summary save to file, NOFILES, CHISCALE, TAG*, and
                   HISTFILE keywords actions added.
  96/11/22, MWB, changed to new master photometry catalog
  97/01/24, MWB, added MAGRESID flag
  97/2/7, MWB, massive rewrite
  2004/02/09, MWB, changed path to transf files.
  2006/08/02, MWB, added DB, DATABASE, TABLENAME keywords
  2006/10/16, PLC, added NOSAVE keyword
  2006/12/28, PLC, added DVERBOSE flag.