NAME:
	inst2std
 PURPOSE: (one line)
	Apply photometric transformation from instrumental to standard mags.
 DESCRIPTION:
  The formula for applying transformation to a photometric measurement
  follows the basic formalism (including signs) from Hardie.  A time
  dependent term has been added.  The formula looks like this:

    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

    This routine also supports two extra terms that fill out the second
       order expansion.  These terms are:

        + fX^2 + gC^2

 CATEGORY:
	Photometry
 CALLING SEQUENCE:
	inst2std,jd,am,inst,instsig,color,colorsig, $
     tran,transig,jdref,std,stdsig
 INPUTS:
  jd       - Julian date of observation for each entry.
  am       - Floating point array of the airmass of observations.
	inst     - Instrumental magnitude
	instsig  - Uncertainty of the instrumental magnitude
	color    - Standard system color for object.
	colorsig - Uncertainty on the standard color
	tran     - Transformation coefficients (vector)
                tran[0] = (k)  principal extinction coefficient
                tran[1] = (k") second order extinction coefficient
                tran[2] = (e)  color term
                tran[3] = (Z)  zero-point
                tran[4] = (n)  time-dependent extinction term
     if provided:
                tran[5] = (f)  airmass squared term
                tran[6] = (g)  color squared term
  transig  - Uncertainty on the transformation coefficients (vector).
                (no uncertainty on reference time)
     tran and transig can either be 5-element vectors or 5xN element arrays.
                       or either be 7-element vectors or 7xN element arrays.
         These two arrays must match in rank and size
  jdref    - Time reference point for extinction
                must match the number of transformation sets provided
 OPTIONAL INPUT PARAMETERS:
 KEYWORD INPUT PARAMETERS:
  REFAM - Optional air mass reference for the transformation.  The default
             is an airmass=0.  The rules for this input are the same as
             REFCOLOR.  Either scalar or length N from TIDX.
  REFCOLOR - Optional color reference for the color term transformation.
                 This term is normally C * (B-V) or some other standard
                 color.  As written, the reference color is zero and this
                 is the default.  By providing this value you are using
                     C * ( (B-V) - REFCOLOR ) for the term instead.
                 This can either be a scalar or a vector.  If a vector it
                 must match the length N in TIDX.  Vector input is not
                 allowed if you are not using an array of coefficients.
  TIDX     - Indexing array, same length as the input observations.  This
                keyword is ignored if the input transformation vectors is
                a simple 5-element vector.  If the transformation is provided
                as a 5xN array then this keyword is REQUIRED.
             Each element gives the index into the set of transformation
             values.  This allows combining data that have different
             photometric transformation coefficients.
 KEYWORD OUTPUT PARAMETERS:
 OUTPUTS:
	std      - Standard magnitude.
	stdsig   - Uncertainty of the standard magnitude.
 COMMON BLOCKS:
 SIDE EFFECTS:
 RESTRICTIONS:
 PROCEDURE:
 MODIFICATION HISTORY:
	Written: Marc W. Buie, Lowell Observatory, 1992/03/31.
  1997/02/10, MWB, total rewrite
  2013/06/02, MWB, allow option for data to be covered by different
                     transformation coefficients.
  2013/06/25, MWB, added REFCOLOR keyword
  2014/02/26, MWB, added vector option for REFCOLOR, added REFAM keyword,
                     added option for extra transformation terms