function SIG=tlm_var(tlm_root)
%
%
% 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
%
D=dir([tlm_root,'*TLm.mat']); nfile=length(D);
%
cf=zeros(1,nfile);
nTmax=0;
for jfile=1:nfile,
	eval(['load ',D(jfile).name]);
    cf(jfile)=TLm.scales{1}(1);
	Tlims=[TLm.scales{3}(1)+5/60,TLm.scales{3}(end)-5/60];
    nTmax=max(nTmax,TLm.dims(3));
    if isfield(TLm,'scales2'), sc2=TLm.scales2{2}; lab2=TLm.labels2{2}; end
end
[cf_sort,iis]=sort(cf); [dum,iis2]=sort(iis);
%%disp(cf); disp(cf_sort); disp(iis); disp(iis2); keyboard
% Construct multi-frequency TLm dataset:
TLG=TLm; TLG.dims(1)=nfile; TLG.dims(3)=nTmax; TLG.scales{3}=[0:nTmax-1]*diff(TLm.scales{3}(1:2));
TLG.data=NaN*ones(TLG.dims); TLG.scales2=TLG.scales; TLG.labels2=TLG.labels; 
TLG.scales2{2}=sc2; TLG.labels2{2}=lab2;
TLG.clim=[-15,0]; TLG.labels{3}='Time - hr';
%
for jf=1:nfile,
	eval(['load ',D(jf).name]);
    jfile=iis2(jf);
%    figure(203); V.ii_img=1; view5(TLm,[2 3 1],0,0,[2.25,1.75],0); pause
	Tlims=[TLm.scales{3}(1)+5/60,TLm.scales{3}(end)-5/60];
    ii=[1:TLm.dims(3)];
    TLG.data(jfile,:,ii)=TLm.data(1,:,ii);
    TLG.data(jfile,:,:)=TLG.data(jfile,:,:) - max(max(TLG.data(jfile,:,:)));
    TLG.scales{1}(jfile)=TLm.scales{1}(1);
    TLG.scales2{1}(jfile)=TLm.scales{1}(1);
%    
	SP=data_avg(TLm,3,{[],[],Tlims,[]},-120,0,0);
%
	if jf==1,
        SIG=SP;
	    SIG.dims=[nfile,SIG.dims(2)];
        SIG.labels=SIG.labels(1:2); SIG.scales=SIG.scales(1:2); SIG.ndim=2;
        SIG.dlab='sig_{20/80}';
        SIG.data=zeros(SIG.dims);
        sc2=SIG.scales2{2}; lab2=SIG.labels2{2};
    end
	SIG.data(jfile,:)=SP.data(1,:,3) - SP.data(1,:,1);
    SIG.scales{1}(jfile)=SP.scales{1}(1);
end
V2=V;
V.ii_img=3; V.grid_dims=[5,4]; V.iisc2=1; view5(TLG,[2,3,1],1,1,[8,4.5]);
V=V2;
%
SIG.scales2=SIG.scales; SIG.scales2{2}=sc2;
SIG.labels2=SIG.labels; SIG.labels2{2}=lab2;
Vtemp=V;
V.ii_img=0; V.iiq=[1:nfile]; V.iisc2=1; V.size=[2.5,2.5];
%%view5(SIG,[2 1 3]);
V=Vtemp;
%
V2=V;
V.ii_img=-1; V.sym={'o'}; V.sty={'none'}; V.dot={[7]};
SIGm=data_avg(SIG,2,[],-50,0,0); SIGm.clim=[0,7];
view5(SIGm,[2 1 3],0,1,[4.5,2.5]);
V=V2;
