function [bdom]=orca_beta_dom(nmode,nrng,nzs,nzr,rng,phis,phir,kn,beta)
%
% Computes complex received spectrum tf(1:ndf,1:nzr,1:nzs) using narrowband approx.
%
%
% 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.
iim=[1:nmode];
bdom=zeros(nzr,nrng,nzs,2);
for jrng=1:nrng,
% 1 by nmode:
	attn_fac=exp(-imag(kn(iim))*rng(jrng));
	for jzs=1:nzs,
		for jzr=1:nzr,
	        phi_prod=abs(phis(jzs,iim).*phir(jzr,iim));			% 1 by nmode
			field_modes=phi_prod .* attn_fac;
			[field_max,jm_max]=max(field_modes); jm_max=min(jm_max,nmode-1);
			iisig=find(field_modes>.5*field_max);
			iisig=min(iisig,nmode-1);
			bdom(jzr,jrng,jzs,1)=beta(jm_max);
			[db,iidb]=max(abs(beta(jm_max)-beta(iisig)));
			bdom(jzr,jrng,jzs,2)=beta(iisig(iidb));
		end
	end
end

