NAME:
  osismean
 PURPOSE:
  Compute mean of a set of OSIRIS XD spectra.
 DESCRIPTION:
  Given a set of spectra, this will perform a straight average of the
    provided spectra.  First, the relative signal level (relsig) is
    computed between all members of the set.  This relative level is
    normalized to 1.0 for the individual spectrum with the highest
    signal level.  Then, only those spectra with relsig >= 0.8 will be
    used for the set mean.  If there aren't 4 spectra in this clase, then
    the brightest 4 spectra will be used, unless there aren't 4 spectra.
    In this latter case, all spectra will be averaged.
 CATEGORY:
  Spectroscopy
 CALLING SEQUENCE:
  osismean,spec,bad,specmean
 INPUTS:
  spec  - Input spectrum to be cleaned up.
  bad   - Array of flags for each point.  0=good, 1=bad.
 OPTIONAL INPUT PARAMETERS:

 KEYWORD INPUT PARAMETERS:
  REF       - If provided, the relative signal levels are measure relative to
                 this spectrum out of the stack.
  ALL       - Flag, if true, forces averaging all spectra regardless of relsig.
  NORMALIZE - Flag, if true, will renormalize all the spectra to REF prior to
                 averaging.

 OUTPUTS:
  relsig   - Relative signal levels among set of input spectra.
  specmean - Average spectrum from the set of spectra.
  badmean  - Bad flag vector for the average spectrum.
 KEYWORD OUTPUT PARAMETERS:
  SIGMA    - Uncertainty of final weighted average output points.  Note, any
                uncertainty of zero means there is no uncertainty.  This will
                coincide mostly with points that aren't marked bad.
 COMMON BLOCKS:

 SIDE EFFECTS:

 RESTRICTIONS:

 PROCEDURE:

 MODIFICATION HISTORY:
  98/08/13, Written by Marc W. Buie, Lowell Observatory
  2000/10/1, MWB, added SIGMA keyword (calculation patterned after MEANERR2)