;###############################################################################
; LICENSE:
;  The software in this file is written by an employee of 
;  National Institute of Standards and Technology 
;  as part of the DAVE software project.
;
;  The DAVE software package is not subject to copyright protection
;  and is in the public domain. It should be considered as an
;  experimental neutron scattering data reduction, visualization, and
;  analysis system. As such, the authors assume no responsibility
;  whatsoever for its use, and make no guarantees, expressed or
;  implied, about its quality, reliability, or any other
;  characteristic. The use of certain trade names or commercial
;  products does not imply any endorsement of a particular product,
;  nor does it imply that the named product is necessarily the best
;  product for the stated purpose. We would appreciate acknowledgment
;  if the DAVE software is used of if the code in this file is
;  included in another product.
;
;###############################################################################
pro test_drebin
for k=0,1 do begin
	if (k eq 0) then begin
		; histo input
		; define input histogram
		x_in=[-0.25,0.25,1.25,3.75,5.75]
		z_in=[100,200,100,200]
		nx_in=n_elements(x_in)
		w_in=x_in[1:nx_in-1]-x_in[0:nx_in-2]
		t_in=z_in*w_in
		dt_in=sqrt(t_in)
		dz_in=dt_in/w_in
		;
		; define output histogram channel limits
		x_out=[0,0.75,2,2.75,3.75,5,6.25,7]
	endif
	if (k eq 1) then begin
		; points input
		; define the input data
		x_in=[1,2,2.25,4.25,5,5.75,6.75,7,8,9]
		z_in=[225,200,250,200,150,200,225,150,100,75]
		dz_in=sqrt(z_in)
		t_in=z_in
		;
		; define output histogram channel limits
		x_out=[0,2,3.5,6.5,8,10]
	endif
	;
	; rebin the data
	drebin,x_in,z_in,dz_in,x_out,z_out,dz_out,err=err,emsg=emsg
	;
	if (err ne 0) then print,err
	if (emsg ne "") then print,emsg
	nx_out=n_elements(x_out)
	w_out=x_out[1:nx_out-1]-x_out[0:nx_out-2]
	t_out=z_out*w_out
	dt_out=dz_out*w_out
	print,""
	print,t_out
	print,dt_out^2
	print,total(t_in),total(t_out)
	print,z_out
endfor
;
end
