pro x_combine,dat1,dat2,dat_out,xout,vmin=vmin,vmax=vmax,dy=dy

; Purpose:
;	combine two image along x-direction
; INPUT:
;	dat1: left image
;	dat2: right image
; Keywords:
;	vmin,vmax, choose suitible grey scale
;	dy: dimension in y-direction cut to caculate correlataion factor
; OUTPUT: 
;	dat_out
; HISTORY:
;	Deng Y. Y., May-09,2000, HSOS

xs=size(dat1)
typ=xs(3)
xs1=xs(1)
ys=xs(2)
xs2=size(dat2)
xs2=xs2(1)

if n_elements(dy) eq 0 then dy=100
if n_elements(vmax) eq 0 then vmax=80
if n_elements(vmin) eq 0 then vmin=-80

window,0,xsize=xs1,ysize=ys
tvscl,dat1>vmin<vmax
window,1,xsize=xs2,ysize=ys
tvscl,dat2>vmin<vmax
print,''
print,'Now, press Mouse on window "0" to choose Correlation region'
wset,0
cursor,x1,y1,4,/device
print,''
print,'Now, press Mouse on window "1" to choose Correlation region'
wset,1
cursor,x2,y2,4,/device

xdd=min([xs1-1-x1,x2])
yini=y1-dy
yend=y1+dy
c1=dat1(x1-xdd:x1+xdd,yini:yend)
c2=dat2(x2-xdd:x2+xdd,yini:yend)
acpole,c1,c2,shx,shy

dat21=shift(dat2,0,shy)
x2=x2-shx
dat11=dat1(0:x1,*)
dat21=dat21(x2+1:*,*)
dat_out=[dat11,dat21]
xout=x1+xs2-x2

window,2,xs=xout,ys=ys
tvscl,dat_out>vmin<vmax

end






