function TL2WAY=se_term_TL(R_sr_ax,z_t,z_rec,TLm_root,rho_ax)
%
% Call TL2WAY=se_term_TL(nrho,R_sr_ax,z_t,z_rec,TLm_root)
%
% Evaluates 2-way TL along a tripline of length R_sr_ax
%
%
% 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.
if nargin<1, R_sr_ax=[]; end
if nargin<2, z_t=[]; end
if nargin<3, z_rec=[]; end
if nargin<4, TLm_root=[]; end
if nargin<5, rho_ax=[]; end
%
gui_global
if isempty(R_sr_ax),
    dx=SRC.txyvp(:,2) - REC.txyvp(:,2); dy=SRC.txyvp(:,3) - REC.txyvp(:,3);
    R_sr_ax=median(sqrt(dx.^2 + dy.^2));
    dx1=SRC.txyvp(:,2) - TGT.txyvp(:,2); dy1=SRC.txyvp(:,3) - TGT.txyvp(:,3);
    dx2=TGT.txyvp(:,2) - REC.txyvp(:,2); dy2=TGT.txyvp(:,3) - REC.txyvp(:,3);
    R_st=min(sqrt(dx1.^2 + dy1.^2));
    rho=R_st/R_sr_ax;
    disp(['Min R_st = ',num2str([R_st,rho]),'; rho = ',num2str(rho)])
end
if isempty(z_t), z_t=mean(TGT.txyvp(:,6)); end
if isempty(z_rec),
    z_rec=REC.txyvp(1,6) + REC.dzr;         % Take median over all receiver depths:
end
if isempty(TLm_root), TLm_root=[GUI.TLm_dir,GUI.omtl_root]; end
if isempty(rho_ax), rho_ax=linspace(.1,.9,101); end
%
tlm_file=[TLm_root,'.mat']; str=['load ',tlm_file]; disp(str); eval(str);
%
R_max=max(TLm.scales2{3}); R_sr_max=max(R_sr_ax);
if R_sr_max>R_max,
    error(['WARNING: Max R_sr > R_max from TLm file: ',num2str([R_sr_max,R_max])]);
end
[dum,ii_zt]=min(abs(TLm.scales2{2}-z_t));
if length(z_rec)==1,
    [dum,ii_zr]=min(abs(TLm.scales2{2}-z_rec));
else
    ii_zr=find(TLm.scales2{2}>min(z_rec) & TLm.scales2{2}<=max(z_rec));
end
%
nR_sr=length(R_sr_ax); nrho=length(rho_ax);
TL_str=zeros(nR_sr,nrho);
for jsr=1:nR_sr,
    R_sr=R_sr_ax(jsr);
	R_st_ax=rho_ax*R_sr;
	for jr=1:nrho,
        R_st=R_st_ax(jr); R_tr=R_sr - R_st;
        TL_st=interp1(TLm.scales2{3},squeeze(TLm.data(1,ii_zt,:,1)),R_st,'linear','extrap');
        TL_tr=interp1(TLm.scales2{3},squeeze(TLm.data(1,ii_zt,:,1)),R_tr,'linear','extrap');
        TL_str(jsr,jr)=TL_st + TL_tr;
	end
end
%
TL2WAY=mat2data(TL_str,{'R_{SR} - km','R_{ST}/R_{SR}'},{R_sr_ax(:)' rho_ax},'2-Way TL - dB',tlm_file,1,1);
