function [SIG_t,SIG_z]=tlm_var_bw(fft_root,ii_avg,flims)
%
% Call [SIG_t,SIG_z]=tlm_var_bw(fft_root,ii_avg,flims);
%
%
% 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.
view_global
%
if nargin<2, ii_avg=[1 1]; end
%
if nargin<1 | isempty(fft_root),
    fft_file=uigetfile('*_fft');
    fft_root=fft_file(1:end-4);
end
%
FFT=fft_read1_open(fft_root);
if nargin<3, flims=[FFT.f1,FFT.f2]; end
%
out_root=[fft_root,'_BW'];
ii_use=0;
if exist([out_root,'_TLm.mat']),
    ii_use=input('Use existing _BW_TLm.mat file (0=no, 1=yes, <CR>=yes): ');
    if isempty(ii_use), ii_use=1; end
end
if exist([out_root,'_TLm.mat']) & ii_use,
    disp('Loading existing TLm file');
    eval(['load ',out_root,'_TLm.mat']); 
    bw=TLm.scales{1}, nband=TLm.dims(1);
else
	geom_file='J:\GCT\NAV\gct_swami_array';
	SL=185; dT=.5;
%	f1=FFT.f1; f2=linspace(f1+5,FFT.f2,6); bw=f2 - f1;
    f1=flims(1)+2.5; f2=flims(2)-2.5;
    bw=[1 2 4 8 16 f2-f1]; nband=length(bw);
	Tlims=FFT.hodax([1,end]) + [5,-5]/60,
	iiph=[1:20]';
	TL_freq=[ones(nband,1)*f1, f1+bw(:)];
%
    TLm=TLm_calc(fft_root,out_root,Tlims,dT,iiph,TL_freq,0,SL,[],0,[],geom_file);
    TLm.labels{1}='Bandwidth - Hz'; TLm.scales{1}=bw;
    TLm.labels2{1}=TLm.labels{1}; TLm.scales2{1}=TLm.scales{1};
    eval(['save ',out_root,'_TLm TLm']);
end
V2=V;
%V.ii_img=3; V.grid_dims=[2,3]; V.iisc2=1; view5(TLm,[2,3,1],1,1,[8,4.5]);
V=V2;
%
if ii_avg(1),
    SIG_t.title=TLm.title;
	SIG_t.ndim=2; SIG_t.dims=[nband,1];
	SIG_t.labels={'Center Frequency - Hz','Dummy'};
	SIG_t.scales={TLm.scales{1},[1]};
	SIG_t.dlab='sig_{80-20}';
	SIG_t.data=zeros(SIG_t.dims);
	SP=data_avg(TLm,3,[],-120,0,0);
    SP.data(:,:,2)=SP.data(:,:,3) - SP.data(:,:,1);
    SP2=data_avg(SP,2,[],-50,0,0);
    size(SP2.data)
	SIG_t.data=SP2.data(:,1,2);
	SIG_t.clim=[min(SIG_t.data(:)),max(SIG_t.data(:))];
	V2=V;
	V.ii_img=-1; V.sym={'o'}; V.sty={'none'}; V.dot={[7]}; V.iilog(1)=1; V.iilog(1)=0;
	view5(SIG_t,[2 1 3],0,1,[4.5,2.5]); title('Temporal Variability'); fig1=gcf;
	V=V2;
else
    SIG_t=[];
end
if ii_avg(2),
    SIG_z.title=TLm.title;
	SIG_z.ndim=2; SIG_z.dims=[nband,1];
	SIG_z.labels={'Center Frequency - Hz','Dummy'};
	SIG_z.scales={TLm.scales{1},[1]};
	SIG_z.dlab='sig_{80-20}';
	SIG_z.data=zeros(SIG_z.dims);
    iiph=[1:16]';
	SP=data_avg(TLm,2,{[] [iiph] [] []},-120,0,0);
    SP.data(:,2,:)=SP.data(:,3,:) - SP.data(:,1,:);
    SP2=data_avg(SP,3,[],-50,0,0);
	SIG_z.data=SP2.data(:,2,1);
	SIG_z.clim=[min(SIG_z.data(:)),max(SIG_z.data(:))];
	V2=V;
	V.ii_img=-1; V.sym={'o'}; V.sty={'none'}; V.dot={[7]}; V.iilog(1)=1; V.iilog(1)=0;
	view5(SIG_z,[2 1 3],0,1,[4.5,2.5]); title('Depth Variability'); fig2=gcf;
	V=V2;
else
    SIG_z=[];
end
if all(ii_avg),
    ovlay([fig1,fig2]);
end
