NAME:
  gradeflat
 PURPOSE:   (one line only)
  Automatic quality grading of a set of CCD flat images against a superflat
 DESCRIPTION:
 CATEGORY:
  CCD data processing
 CALLING SEQUENCE:
  gradeflat,cube,flat,grade,fail
 INPUTS:
  cube - 3-d cube of original flat images, if you need to subtract overscan
              and crop, this should be done prior to building the cube
  flat - 2-d image which is the superflat frame
 OPTIONAL INPUT PARAMETERS:
 KEYWORD INPUT PARAMETERS:
  DISPLAY  - Flag, if set, generates some diagnostic plots
  MAXSIG   - Maximum sigma excursion allowed for an image (default=3) before
                it is flagged as bad.
 OUTPUTS:
  grade - This is the grade of this cube/flat pair.  This is related to
             a unit of standard deviation.  A bad set of data will have
             a large value, typically much greater than 3.   A good set of
             data will be comfortably less than 3.
  fail  - This is the number of frames that fail the test of being consistent
             with the ensemble of frames.  This number will be somewhere
             between 0 and the number of frames in the cube.  Don't expect
             this number to be zero but it should be small.
 KEYWORD OUTPUT PARAMETERS:
  SIGRATIO - Standard deviation of the individual good image grades.
 COMMON BLOCKS:
 SIDE EFFECTS:
 RESTRICTIONS:
  This tool is ok but could be better.
 PROCEDURE:
 MODIFICATION HISTORY:
  Written by Marc W. Buie, Southwest Research Institute, 2015/04/26