function flat_floor, data, nbox=nbox, ul=ul, ll=ll, ur=ur, lr=lr, shifted=shifted
;
;+
;NAME:
;	flat_floor
;PURPOSE:
;	To shift a series of images so that the background level 
;	is the same for all images.
;SAMPLE CALLING SEQUENCE:
;	data3 = flat_floor(data, /lr)
;	data3 = flat_floor(data, /lr, shifted=shifted)
;INPUT:
;	data	- The data cube
;KEYWORD INPUT:
;	nbox	- The size of the subbox to find the average of
;		  and to make zero.  Default is 4 (4x4 pixels)
;	ll	- Make the lower left box equal to zero (DEFAULT)
;	lr	- Make the lower right box equal to zero
;	ul	- Make the upper left box equal to zero
;	ur	- Make the upper right box euqal to zero
;OUTPUT:
;	shift	- amount shifted
;HISTORY:
;	Written 4-May-95 by M.Morrison
;-
;
if (n_elements(nbox) eq 0) then nbox = 4
;
nx = n_elements(data(*,0,0))
ny = n_elements(data(0,*,0))
n  = n_elements(data(0,0,*))

x0 = 0 & x1 = nbox-1
y0 = 0 & y1 = nbox-1
if (keyword_set(ll) or keyword_set(ul)) then begin & x0 = 0		& x1 = nbox-1		& end	;left
if (keyword_set(ur) or keyword_set(lr)) then begin & x0 = nx-1-nbox	& x1 = nx-1		& end	;right
if (keyword_set(ul) or keyword_set(ur)) then begin & y0 = ny-1-nbox	& y1 = ny-1		& end	;up
if (keyword_set(ll) or keyword_set(lr)) then begin & y0 = 0		& y1 = nbox-1		& end	;down

out = data
shifted = fltarr(n)
for i=0,n-1 do begin
    temp = data(x0:x1, y0:y1, i)
    avg = total(temp)/n_elements(temp)
    shifted(i) = avg
    out(*,*,i) = out(*,*,i) - avg
end
;
return,out
end
