NAME:
  moscal
 PURPOSE:
  Apply standard CCD image correction steps to a raw group-FITS image.
 DESCRIPTION:

 CATEGORY:
  CCD data processing

 CALLING SEQUENCE:
  moscal,root,outdir,start,nframes,bias,dark,flat

 INPUTS:
  root    - Root of the file name (you must include . in the name).
  outdir  - The directory to write the calibrated files to.  Don't make
              this the same as the input directory.
  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.
  nframes - Number of frames to average.
  bias    - Bias frame image name to subtract from each raw frame.
  dark    - Dark frame image name to subtract from each raw frame.
  flat    - Flat frame image name to subtract from each raw frame.

 OPTIONAL INPUT PARAMETERS:

 KEYWORD INPUT PARAMETERS:

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

   DOALL   - Process all images, if not set will only process OBJECT frames.

   EXCLUDE - Optional vector of image numbers that should be excluded from
                processing.  Default is to include all frames in the range
                provided.

   EXPKEY = String - FITS keyword to read to get exposure time, $
              default = EXPTIME

   FLOAT - Flag, if set will cause the output data to be saved as float
             Otherwise, it will be saved as 16-bit integer data.

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

   SKIP - Flag, if set will direct the program to skip any output files
             that are already present.

 OUTPUTS:
   The calibrated images are written to outdir.  Don't make this the same
   as the current directory!

   An additional file, 'root'+dgain, is written that contains the mean of
     each chip before and after the gaincor correction.

 KEYWORD OUTPUT PARAMETERS:

 COMMON BLOCKS:

 SIDE EFFECTS:

 RESTRICTIONS:

 PROCEDURE:

 MODIFICATION HISTORY:
  2000/02/03, Written by Marc W. Buie, Lowell Observatory
  2000/02/28, MWB, added support for frame numbers > 999.
  2003/03/30 ,MWB, added fix from 0 DN pixels (usually from KPNO)
  2003/05/30, MWB, cosmetic changes to program internals plus added saving
                      the differential gain data to a file.
  2013/03/22, MWB, added FLOAT keyword
  2013/10/06, MWB, added SKIP keyword.  Also, this program now skips any
                      image that does not have OBSTYPE='OBJECT'
  2015/06/11, MWB, added DOALL keyword