function bgrab, data_in, siz=siz, mag=mag, fixed_size=fixed_size, $
		xsubs=xsubs, ysubs=ysubs, corner=corner
;
;+
;NAME:
;	bgrab (Bruner Grab)
;PURPOSE:
;	Mouse driven routine to extract a sub-array from a data cube
;SAMPLE CALLING SEQUENCE:
;	sdata = bgrab(data)
;	sdata = bgrab(data, bin=4)
;	sdata = bgrab(data, siz=64)
;	sdata = bgrab(data, siz=[128,64])
;	sdata = bgrab(data, /corner)
;INPUT:
;	data	- The data cube to extract data from
;OPTIONAL KEYWORD INPUT:
;	siz	- The size of the box.  Default is 64x64.  If the value
;		  is scalar, X and Y size will be that value.  The value
;		  can have two elements which would be the X and Y size.
;		  It is the number of pixels to extract from the input
;		  image, not the number of pixels displayed (if mag does
;		  not equal zero).
;	mag	- The magnification factor that the image was displayed
;		  with.  Default is 1 (raw)
;	fixed_size - ??
;	corner	- If set, user can click on the two corners to specify the
;		  window to extract.
;OPTIONAL KEYWORD OUTPUT:
;	xsubs	- The starting and ending x subscripts that were extracted
;	ysubs	- The starting and ending y subscripts that were extracted
;HISTORY:
;       M. Bruner 4/13/93
;	13-Jun-93 (MDM) - Added header - change parameters some
;			- Added XSUBS and YSUBS options
;			- Added /CORNER option
;	21-Jun-93 (MDM) - Corrected sizing of the window when it is resized
;			  interactively
;			- Corrected marking of the box (it was off by 1)
;-
;
case n_elements(siz) of
    1: begin & nx=siz(0)	& ny=siz(0)	& end
    2: begin & nx=siz(0)	& ny=siz(1)	& end
    else: begin & nx=64		& ny=64		& end
end
if (n_elements(mag) eq 0) then mag=1
;
s=size(data_in)
xx0=fix(s(1)/2*mag)		;xx*, yy*, and nn* are coordinates in graphics device
yy0=fix(s(2)/2*mag)
case (s(0)<4) of
   0: print,'Input is not an array' 
   1: print,"Sorry, I don't do vectors."
   4: print,"OOF!  I can't handle more than three dimensions."
   else: begin
	if (not keyword_set(corner)) then begin
		nnx = nx*mag
		nny = ny*mag
		box_cursor, xx0, yy0, nnx, nny, /init, /message
		nx = nnx/mag
		ny = nny/mag
	end else begin
		get_boxcorn, xx0, yy0, xx1, yy1, /device
		nx = (xx1-xx0+1)/mag
		ny = (yy1-yy0+1)/mag
	end

	xx0 = fix(xx0/mag)*mag		;make it a multiple of the mag factor
	yy0 = fix(yy0/mag)*mag		;make it a multiple of the mag factor
	xx1 = xx0+(nx)*mag
	yy1 = yy0+(ny)*mag
	draw_boxcorn, xx0, yy0, xx1, yy1, /device
	data_out = data_in(xx0/mag:xx0/mag+nx-1, yy0/mag:yy0/mag+ny-1,*)
	xsubs = [xx0/mag, xx0/mag+nx-1]
	ysubs = [yy0/mag, yy0/mag+ny-1]
      end
endcase
;
return,data_out
end
