function reverb_map(SGRAM,SRC,REC,PRI,dxy,nxy,tsize)
%
% Call reverb_map(SGRAM,SRC,REC,PRI,dxy,nxy,tsize);
%
% Example call:
% 
% reverb_map(SGRAM,SRC,REC,1.6533,3,100,GUI.tsize)
%
[ntau,nbeam,nseq]=size(SGRAM.data); dt=SGRAM.y(2)-SGRAM.y(1);
sinphi_ax=linspace(-1,3,nbeam); dsinphi=sinphi_ax(2)-sinphi_ax(1);
ntau_PRI=round(PRI/dt); ntau_buf=round(.1/dt);
nchunk=floor(ntau/ntau_PRI) - 4,
nchunk=3,
%
for jseq=1:nseq,
	t_hod=SGRAM.z(jseq);
	[emin,jT]=min(abs(SRC.txyvp(:,1)/60 - t_hod));
	xy_src=SRC.txyvp(jT,2:3); xy_rec=REC.txyvp(jT,2:3); 
xlo=min(xy_src(1),xy_rec(1)) - dxy; 
xhi=max(xy_src(1),xy_rec(1)) + dxy; 
ylo=min(xy_src(2),xy_rec(2)) - dxy; 
yhi=max(xy_src(2),xy_rec(2)) + dxy;
nx=nxy; ny=nxy;
xax=linspace(xlo,xhi,nx)'; yax=linspace(ylo,yhi,ny)';
[xg,yg]=meshgrid(xax,yax); ngrid=prod(size(xg));
	phi_rs=atan2(xy_src(1)-xy_rec(1),xy_src(2)-xy_rec(2))*180/pi;
	rng_sr=sqrt(sum((xy_src-xy_rec).^2));
	tau_sr=rng_sr/(.001*SRC.c);
%
% Compute patch two-way travel times and angles:
	dx=xg-xy_rec(1); dy=yg-xy_rec(2);
	phi_rp=atan2(dx,dy);
	rng_rp=sqrt(dx.^2 + dy.^2);
	dx=xg-xy_src(1); dy=yg-xy_src(2);
%	phi_sp=atan2(dx,dy);
	rng_sp=sqrt(dx.^2 + dy.^2);
	tau_p=(rng_rp + rng_sp)/(.001*SRC.c);
	dtau=tau_p - tau_sr;		% nxy by nxy
%
	sinphi_src=sin_space(xy_rec,xy_src,REC.LOB,1),
	[emin,jsin_src]=min(abs(sinphi_ax-sinphi_src)),
	iib=[jsin_src-10:jsin_src+10];
	rep_data=squeeze(SGRAM.data(:,:,jseq)); size(rep_data)
% Find max in bearing and tau:
	[pmax,jmax]=max(rep_data(:,iib)); 
	[pmax2,jmax2]=max(pmax); 
	[pmax3,jtau_DB]=max(rep_data(:,iib(jmax2)));
% Go back to start of time, modulo ntau_PRI, and allow buffer of .1 s:
	jtau_DB=rem(ntau_PRI,jtau_DB - ntau_buf);
	jbrg_DB=iib(jmax2);
	sinphi_DB=sinphi_ax(jbrg_DB);
	brg_DB=sin_space(0,sinphi_DB,0,0);
	LOB=phi_rs-brg_DB,
%
	sinphi_rp=sin_space(repmat(xy_rec,[ngrid,1]),[xg(:),yg(:)],LOB);
	sinphi_rp=reshape(sinphi_rp,[nx,ny]);
% Beam numbers to extract for each patch:
	jphi_rp=round((sinphi_rp - sinphi_ax(1))/dsinphi)+1;
%%	min(jphi_rp(:)),max(jphi_rp(:)),size(jphi_rp),nbeam,
	sg=zeros(ny,nx);
	for jch=1:nchunk,
		jtau_DB0=jtau_DB + (jch-1)*ntau_PRI;
% Tau indices to extract for each patch:
		jtau_rp=jtau_DB0 + round(dtau/dt);
		jtau_ok=find(jtau_rp<=ntau);
		ii=ntau*(jphi_rp(jtau_ok)-1) + jtau_rp(jtau_ok); 
%%		max(ii), prod(size(rep_data)), keyboard
		sg(jtau_ok)=sg(jtau_ok) + 10.^(rep_data(ii)/10);
	end
	sg_db=10*log10(max(1e-30,sg/nchunk));
	figure;
	imagesc(xax,yax,sg_db)
	xlabel('E-W Position - km');
	ylabel('N-S Position - km');
	mycolorbar2;
	plot_size(gca,'in',tsize(1),tsize(2));
	plot_set3(gca,1.5,'Arial',14,1);
	rev_max=ceil(max(sg_db(:))/5)*5; rev_min=rev_max - 60;
	set(gca,'clim',[rev_min,rev_max]);
	axis('equal'); axis('tight'); axis('xy'); hold on;
	plot_cfill(xy_src(1),xy_src(2),'o','k',8);
	plot_cfill(xy_src(1),xy_src(2),'o','c',5);
	plot_cfill(xy_rec(1),xy_rec(2),'o','k',8);
	plot_cfill(xy_rec(1),xy_rec(2),'o','r',5);
	% Plot LOB of Receiver:
%	if isfield(REC,'LOB') & REC.aperture>0,
		phi=LOB*pi/180; line_pts=[.25 1];
		ax=axis; lmark=max([diff(ax(1:2)),diff(ax(3:4))])/50;
		x_arrow=xy_rec(1) + 2*lmark*sin(phi)*line_pts;
		y_arrow=xy_rec(2) + 2*lmark*cos(phi)*line_pts;
		ha=plot_cfill(x_arrow,y_arrow,'none','k',8,'-',1.5);
%	end
pause,
end
%
% COPYRIGHT (c) 2008
% 
% Applied Research Laboratories, The University of Texas at Austin
% (ARL:UT)
% All rights reserved.
% 
% This material may be reproduced by or for the U.S. Government
% only. This notice must appear in all copies of this file and its
% derivatives. Further distribution outside the U.S. Government is
% prohibited without the explicit written authorization from the
% Director of the Environmental Sciences Laboratory, ARL:UT.
% 
% THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
% EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO THE
% IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
% PURPOSE, OR NONINFRINGEMENT.
% 
% IN NO EVENT WILL ARL:UT BE LIABLE FOR ANY DAMAGES WHATSOEVER ARISING
% OUT OF THE USE OR INABILITY TO USE THIS SOFTWARE, EVEN IF ARL:UT HAS
% BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
