NAME: 
  mkbias
 PURPOSE: 
  Collect and combine CCD bias frames into a superbias frame
 DESCRIPTION:

  The files are assumed to be named as 'root'NNN where 'root' is the
  root of the file name that you supply and NNN is a three digit number.
  If your file name has an imbedded '.' then add it to the root.

  The specified range of files are all read in from FITS files.  Then each
  image has the overscan mean subtracted (if desired), cropped (as indicated).
  These images are then averaged.  The averaging is done with AVGCLIP.PRO
  which does a robust average of the image stack so that cosmic rays or
  other transient image defects are eliminated.

  When done, the resulting bias image is returned to the caller and the image
  is saved to a FITS file with the specified output filename.

 CATEGORY:
  CCD data processing
 CALLING SEQUENCE:
  mkbias,root,outsuf,start,nframes,bias,good
 INPUTS:
  root    - Root of the file name (you must include . in the name).
  outsuf  - The suffix of the final output file.
  start   - First frame number to read (integer or long).
               Start can also be a vector of explicit frame numbers to load.
               In this case, nframes need not be specified and in fact will
               be ignored.
               Additionally, start can also be a string array containing the
               file names of all files to be read.  In this case, set nframes
               to 0 or someother innocuous integer.  Exclude is treated
               differently.  In this case, exclude is a vector of the same
               length as start and is 0 if the file is to be used, 1 if not.
  nframes - Number of frames to average.
 OPTIONAL INPUT PARAMETERS:
 KEYWORD INPUT PARAMETERS:

   CROP     = region of original image to save, default=no cropping.
                 [x1,x2,y1,y2]

  DIGITS   - Optional input to indicate how many digits are in the suffix
                of the file name.  The default for this input is 0.  In this
                case it uses the ROBOCCD scheme which is three digits up
                to 999.  After that, it gets complicated, see numtoflist
                for more information.  If you were to give it a value of
                three you would get the same behavior except you won't get
                the ROBOCDD extension.  This is really designed for when
                you have four or more digits.

   DDIR     = Directory to look for raw data in.  Default = ''

   EXCLUDE - Optional vector of image numbers that should be excluded from
                average.  Default is to include all frames.

   OVERSCAN = column overscan region to use for frame bias level,
                 default=no overscan subtraction.

   RDNOISE  - Read noise of CCD [in DN], default=10
   MINGOOD - Minimum number of frames required to be considered a good
                bias.  (Default=15)
   MAXBAD  - Maximum number of bad rows allowed per image (see gradebias)
                Default is inherited from gradebias

 OUTPUTS:
  bias - Final robust averaged/cropped bias image.
  good  - Flag, true if this collection of bias images is considered to be
            good.
 KEYWORD OUTPUT PARAMETERS:
 COMMON BLOCKS:
 SIDE EFFECTS:
 RESTRICTIONS:
 PROCEDURE:
 MODIFICATION HISTORY:
  95/03/09 - Initial crude version written, Marc W. Buie, Lowell Observatory
  95/06/13, MWB, added OVERSCAN and CROP keywords
  95/11/22, MWB, add EXCLUDE keyword
  2000/02/02, MWB, rewrite to add support for multigroup FITS files.
  2000/02/28, MWB, added support for frame numbers > 999.
  2001/02/23, MWB, added option to provide input file list.
  2001/04/28, MWB, added DDIR keyword.
  2005/01/04, MWB, changed so .fits tag can come and go in file names.
  2006/07/14, MWB, added RDNOISE keyword
  2006/10/23, MWB, fixed output header keyword problem (remove BSCALE/BZERO)
  2007/06/20, MWB, fixed minor bug with image list for start
  2015/04/26, MWB, added tool to provide a quality grade for set of images
  2015/05/03, MWB, added much more sophisticated logic to build the superbias.
                      Automatic filtering of bad frames is done internally.
  2016/05/29, MWB, added DIGITS keyword