%N readimcg %F $MIR/src/subs/cgsubs.for
%D Read in image dealing with averaging and blanking
%P nebk
%: plotting
%B
      subroutine readimcg (init, blank, lun, ibin, jbin, krng, blc,
     *                     trc, norm, nimage, image, blanks, dmm)

      real blank, image(*), dmm(3)
      integer nimage(*), lun, ibin(2), jbin(2), krng(2), blc(3),
     *  trc(3)
      logical blanks, init, norm
  ---------------------------------------------------------------------
  Read in the specified window from the image and apply spatial
  and spectral binning as desired

  Input:
    init        True to initialize output array and normalization
                image first
    blank       Value to use for magic blanking
    lun         Handle of image
    ibin        Increment and binning for i direction
    jbin        Increment and binning for j direction
    krng        First pixel in k direction to read and number of
                pixels to average
    blc,trc     Input window, in unbinned pixels, to read and bin
    norm        If true, normalize the summed image before
                exiting.  It is up to you to renitialize at
                the appropriate time with INIT on the next call
  Output
    nimage      Normalization image; it is the number of pixels
                that were averaged together at each output pixel
                location.  Will be zero for blanked pixels
    image       Output image (binned, normalized)
    blanks      True if blanks in output image
  Input/output
    dmm         Data min, max, abs max so far
