;$Id: array_points2histo.pro,v 1.2 2005/02/09 14:02:26 azuah Exp $
; INPUT must be strictly 2D arrays.
;###############################################################################
; 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 array_points2histo_x $
	; INPUT
	, in $
	; OUTPUT
	, out

	size_in = size( in, /dimension )
	n = size_in[ 0 ]
	if n eq 0 then n = 1 ; Point -> Vector

	size_out = size_in
	size_out[ 0 ] = n + 1

	out = dblarr( size_out )
	out[0, *] = in[0, *]
	out[n, *] = in[n-1, *]

	for i = 1, n - 1 do out[i, *] = ( in[i-1, *] + in[i, *] ) / 2d

end

pro array_points2histo_y $
	; INPUT
	, in $
	; OUTPUT
	, out


	in = [ [ in ] ]
	size_in = size( in, /dimension )

	if n_elements( size_in ) lt 2 then size_in = [ size_in, 1 ]
	n = size_in[ 1 ]

	size_out = size_in
	size_out[ 1 ] = n + 1

	out = dblarr( size_out )

	out[*, 0] = in[*, 0]
	out[*, n] = in[*, n-1]

	for i = 1, n - 1 do out[*, i] = ( in[*, i-1] + in[*, i] ) / 2d

end

pro array_points2histo $
	, z, x, y

	zsize = size( z )
	nx = zsize[1]
	ny = zsize[2]

if n_elements( x[*, 0] ) eq nx then begin
	array_points2histo_x, x, xp
	array_points2histo_x, y, yp
endif else begin
	xp = x
	yp = y
endelse

if n_elements( x[0, *] ) eq ny then begin
	array_points2histo_y, xp, x
	array_points2histo_y, yp, y
endif else begin
	x = xp
	y = yp
endelse

end