function [TLm,handles]=TLm_plot(tlm_root,Tlims,jrec,ii_img,psize,NBAin,iirng, ...
	iired,iinewfig,cols);
%
% Call [TLm,handles]=TLm_plot(tlm_root,Tlims,jrec,ii_img,psize,NBAin,iirng, ...
%	iired,iinewfig);
%
% tlm_root	= root of _TLm.mat file containing measured TL, 
%			  or TLm structure itself
% psize		= size of plot in [width,height];
%
view_global
%
if nargin<1, tlm_root=[]; end
if nargin<2, Tlims=[]; end
if nargin<3, jrec=[]; end
if nargin<4 | isempty(ii_img), ii_img=1; end
if nargin<5 | isempty(psize), psize=[6,2.5]; end
if nargin<6, NBAin=[]; end
if nargin<7, iirng=0; end
if nargin<8, iired=0; end
if nargin<9, iinewfig=1; end
if nargin<10, cols='rbgmck'; end
% 
handles=[];
if ischar(tlm_root) | isempty(tlm_root),
	[tlm_file,tlm_root,iif,path_back]=adi_check_file(tlm_root,'_TLm.mat','TLm');
	if ~iif, return; end
	str=['load ',tlm_root,'_TLm']; eval(str);
	if ~isempty(path_back); eval(['cd ''',path_back,'''']); end
	if exist('NBA')==1 & isempty(NBAin), NBAin=NBA; end
elseif isstruct(tlm_root),
	TLm=tlm_root;
else
	disp('USER ERROR: tlm_root must be character string, empty, or TLm structure');
	return
end
%
nrec=TLm.dims(2);
if nrec==1, ii_img=0; end
%
if iinewfig, figure; end
%
if isempty(Tlims),
	iit=1:length(TLm.scales{3});
else
	iit=find(TLm.scales{3}>=Tlims(1) & TLm.scales{3}<=Tlims(2));
end
if isempty(jrec) | jrec(1)==0,
	jrec=[1:nrec];
else
	if any(jrec>nrec | jrec<1), 
		error(['USER ERROR: bad receiver specification: ',int2str(jrec)]);
	end
end
%
if diff(TLm.clim)>100, TLm.clim(1)=TLm.clim(2) - 60; end
if ii_img==0,
% Choose horizontal axis as range or time:
	if iirng & isfield(TLm,scales2),
		t_hour=TLm.scales2{3}(iit); xlab=TLm.labels2{3}
	else
		t_hour=TLm.scales{3}(iit); xlab=TLm.labels{3};
		if iirng, disp(['Cannot plot vs range since TLm has no field scales2']); end
	end
	if isfield(TLm,'iinan'), t_hour(TLm.iinan)=NaN; end
	[nf,nrec,nt]=size(TLm.data); nt=length(iit);
	if length(jrec)==1 & isfield(TLm,'range_sr') & iired,
		dr_dt=[diff(t_hour); 0]; dr_dt(nt)=dr_dt(nt-1); 
		ii_red=find(dr_dt<0); ii_blue=find(dr_dt>=0);
		for jr=1:length(jrec),
			jj=jrec(jr);
			tl=squeeze(TLm.data(1,jj,iit));
			h1=plot_cfill(t_hour(ii_red),tl(ii_red),'none','r',4,'-',2); hold on;
			h2=plot_cfill(t_hour(ii_blue),tl(ii_blue),'none','b',4,'-',2); hold on;
			handles=[handles,h1,h2];
		end
	else
		ncol=length(cols);
		for jr=1:length(jrec),
			jj=jrec(jr);
			jcol=mod(jr-1,ncol) + 1;
			tl=squeeze(TLm.data(1,jj,iit));
			h1=plot_cfill(t_hour,tl,'none',cols(jcol),4,'-',2); hold on;
			handles=[handles,h1];
		end
	end
	xlabel(xlab); ylabel(TLm.dlab); grid on; zoom on;
	ax=axis; ax(3:4)=TLm.clim; axis(ax); 
	plot_set3(gca,2,'Arial',-14,1);
	plot_size(gca,'in',psize(1),psize(2));
	ax=axis; str=strrep(TLm.title,'_','\_');
	text(ax(2),ax(4),str,'HorizontalAl','Right','VerticalAlignment','Top', ...
		'FontName','Arial','FontSize',9);
	clipline
else
    if isfield(V,'iisc2'), iisc2=V.iisc2; else, iisc2=0; end
    V.iisc2=1;
    view5(TLm,[2,3,1],1,0,psize,1);
    V.iisc2=iisc2;
end
%
if ~isempty(NBAin),
	if isempty(Tlims),
		iit2=1:length(NBAin.time_favg);
	else
		iit2=find(NBAin.time_favg>=Tlims(1) & NBAin.time_favg<=Tlims(2));
	end
	TLm.range=interp1(NBA.time_favg,NBA.range,TLm.scales{3});
	hold on; plot(NBAin.time_favg(iit2),NBAin.TL_favg(iit2),'r');
	plot(NBAin.time_favg(iit2),NBAin.TLi(iit2,:),'r--');
	NBA=NBAin;
	str=['save ',TLm.title,'_TLm TLm NBA'], eval(str)
end
%
if iirng & ~isempty(NBAin),
	figure
	plot(NBAin.time_favg(iit2),NBAin.range(iit2),'b');
	xlabel(TLm.labels{3}); ylabel('S-R Range - km');
	plot_set3(gca,2,'Arial',-14,1);
	plot_size(gca,'in',psize(1),.5*psize(2));
	grid on;
%
	figure
	cols='brgmck'; ncol=length(cols);
	for jr=1:length(jrec),
		jj=jrec(jr);
		jcol=mod(jr-1,ncol) + 1;
		tl=squeeze(TLm.data(1,jj,iit));
		plot_cfill(TLm.range(iit),tl,'none',cols(jcol),4,'-',2); hold on;
	end
	plot(NBAin.range(iit2),NBAin.TL_favg(iit2),'r');
	plot(NBAin.range(iit2),NBAin.TLi(iit2,:),'r--');
	xlabel('S-R Range - km'); ylabel('TL - dB');
	plot_set3(gca,2,'Arial',-14,1);
	plot_size(gca,'in',psize(1),psize(2));
	grid on;
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.
