NAME: 
  avgspec
 PURPOSE: 
  Robust average of a set of 1-D spectra from FITS files.
 DESCRIPTION:
 CATEGORY:
  Spectroscopy
 CALLING SEQUENCE:
  avgspec,root,outsuf,start,nspec,result
 INPUTS:
  root   - Root of file name(s) (no . at the end, may include path).
  outsuf - Suffix for the output file name.  (name will be root+'.'+outsuf)
  start  - First spectrum number of sequence to average.
  last   - Last spectrum number of sequence to average. (if negative, this
             number is interpreted to be the number of spectra to average).
 OPTIONAL INPUT PARAMETERS:
 KEYWORD INPUT PARAMETERS:
  EXCLUDE   - Scalar or vector of spectrum numbers to exclude from average.
  SCALE     - range of pixels to use for scaling all spectra to each other.
              The default is to use all pixels for scaling.
  REFERENCE - Spectrum number to use as the scaling reference.  The scale
              factors are determined relative to this one.
  OUTROOT   - Root of output file name, default=root

  Values for header in output spectrum

  JD        - JD of midtime of output average spectrum (default=none)
  AIRMASS   - Effective airmass of spectrum (default=none)
  OBJECT    - Name of object (default=none)

 OUTPUTS:
  result - Final averaged spectrum.  This is also saved to a FITS file.
 KEYWORD OUTPUT PARAMETERS:
  SCFACTOR  - Vector of relative scaling factors for each spectrum.
 COMMON BLOCKS:
 SIDE EFFECTS:
 RESTRICTIONS:
 PROCEDURE:
 MODIFICATION HISTORY:
  95/09/18 - Written by Marc W. Buie, Lowell Observatory
  96/05/29, MWB, changed 4th argument to LAST from NSPEC