;$Id: array_oned2twod.pro,v 1.2 2005/02/09 14:02:26 azuah Exp $
;
;
; Turns 1d arrays into 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.
;
;###############################################################################
function array_oned2twod_v2 $
	, xin, yin $
	, xout, yout

	; Make scalars arrays.
	x = reform( [ xin ] )
	y = reform( [ yin ] )

	; Determine the sizes.
	size_x = size( x )
	size_y = size( y )

	; Determine the dimensions.
	dx = size_x[1]
	dy = size_y[ size_y[0] ]

	; Change the dimensions if necessary.
	if size_x[0] eq 1 then begin
		xout = reform( x # (dblarr( dy ) + 1d) $
			, dx, dy )
	endif else begin
		xout = x
	endelse

	if size_y[0] eq 1 then begin
		yout = reform( (dblarr( dx ) + 1d) # y $
			, dx, dy )
	endif else begin
		yout = y
	endelse

	return, 1

end

function array_oned2twod_v1 $
	; INPUT
	, xin, yin $
	; OUTPUT
	, xout, yout

	x = reform( xin )
	y = reform( yin )

	size_x = size( x )
	size_y = size( y )

	case 3^size_x[0] * 2^size_y[0] of

		1: begin
			message, 'Both X and Y are scalars.', /continue
			return, 1
		end

		2: begin	; 1 X y array, [ 0, 1 ]
			xout = y
			xout = x
			yout = y
			message, 'Scalar X and vector Y', /continue
			return, 1
		end

		3: begin ; x X 1 array, [ 1, 0 ]
			yout = x
			yout = y
			xout = x
			message, 'x X 1 array', /continue
			return, 1
		end

		6: begin ; x X y array, [ 1, 1 ]
			xvec = dblarr( n_elements( x ) ) + 1d
			yvec = dblarr( n_elements( y ) ) + 1d

			xout = x # yvec
			yout = xvec # y
			print, 'yout size is ', size( yout )
			message, 'X, Y Vectors are converted to 2D arrays.', /continue
			return, 1
		end

		12: begin ; [ 1, 2 ]
			yvec = dblarr( n_elements( y[0, *] ) ) + 1d

			xout = x # yvec
			yout = y
			return, 1
		end

		18: begin ; [ 2, 1 ]
			xvec = dblarr( n_elements( x[*, 0] ) ) + 1d

			yout = xvec # y
			xout = x
			return, 1
		end

		36: begin ; [ 2, 2 ]
			xout = x
			yout = y
			return, 1
		end

		else: begin
			message, 'Input array has bigger dimensionality than 2', /continue
			return, 0
		end

	endcase

end


function array_oned2twod $
 	; INPUT
	, xin, yin $
	; OUTPUT
	, xout, yout $
	, _extra=_extra

	return, array_oned2twod_v2( xin, yin, xout, yout )

end