function two_src_visibility,flux,area,x,y,pa=PA,PLOT=plot

; PURPOSE: returns  complex visibility of two sources on RHESSI uvcircles

; INPUTS:
; Flux = float(2) = flux vector for two sources
; Area = float(2) = area vector for two sources 
;      = !pi*[a1^2,a2^2] where a1, a2 are Gaussian widths in asec
; x = float(2) = x coordinate of two sources relative to map center (asec)
; y = float(2) = y coordinate of two sources relative to map center (asec)

;OPTIONAL INPUTS:
; pa = vector of position angles (defaults to 32 values on 0 to 2*!pi) 
; /plot to plot the amplitude profile
;
; OUTPUT:
;  complex visibility of two sources
;;OPTIONAL INPUTS:
; ejs dec 12, 2006

default,pa,findgen(32)*!pi/32   ; from 0 to 180 degrees

pitch=(hsi_grid_parameters()).pitch
kx=cos(pa) # (1/pitch)
ky=sin(pa) # (1/pitch)
k=sqrt(kx^2+ky^2)

x1=x-mean(x)  ; shift to center of sources
y1=y-mean(y)
relvis1= exp(-2*!pi*k^2*area[0])
relvis2= exp(-2*!pi*k^2*area[1])

phz1 = kx*x1[0]+ky*y1[0]
phz2 = kx*x1[1]+ky*y1[1]

i=complex(0,1)

vis = relvis1*flux[0]*exp(i*phz1) + relvis2*flux[1]*exp(i*phz2)

amp=abs(Vis)
if keyword_set(plot) then begin
   window,/free
   plot,amp,/xst,/yst,tit='TWO-SOURCE VISIBILITY AMPLITUDE',/ylog,yra=[0.01,1]*total(flux),psym=-6,symsiz=0.3
   for j=0,8 do oplot,32*[j,j],[0.01,1]*total(flux)
   legend,/right,/bottom,['Flux='+strcompress(flux[0],/rem)+strcompress(flux[1]),$
                          'xpos='+strcompress(x[0],/rem)+strcompress(x[1]),$
                          'ypos='+strcompress(y[0],/rem)+strcompress(y[1]),$
                          'area='+strcompress(area[0],/rem)+strcompress(area[1])],/clear,textcolor=1


endif

return,vis

end

area=!pi*[3,3]^2
flux=[200.,100.]
x=[-20,20]
y=[-20,20]
vis=two_src_visibility(flux,area,x,y,/plot)
;write_png,'2src_visF200-100W3-3.png',255b-tvrd()

area=!pi*[3,3]^2
flux=[100.,100.]
x=[-20,20]
y=[-20,20]
vis=two_src_visibility(flux,area,x,y,/plot)
write_png,'2src_visF100-100W3-3.png',255b-tvrd()

area=!pi*[2,3]^2
flux=[200.,100.]
x=[-20,20]
y=[-20,20]
vis=two_src_visibility(flux,area,x,y,/plot)
write_png,'2src_visF200-100W2-3.png',255b-tvrd()

area=!pi*[2,4]^2
flux=[200.,100.]
x=[-20,20]
y=[-20,20]
vis=two_src_visibility(flux,area,x,y,/plot)
write_png,'2src_visF200-100W2-4.png',255b-tvrd()



end



