function TLm_fix(tlm_root,SL_new,cal_old,cal_new)
%
% Fixes TL computed according to incorrect SL and/or calibration factors.
% We define TL here as a negative number: TL=RL - SL;
% If SL goes up by 3 dB, the loss has to be increase, so our negative-valued TL must go down.
% So subtract (SL_new - SL_old) and add 20*log10(cal_new/cal_old);
%
%
% 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.
D=dir(['*',tlm_root,'*_TLm.mat']), nfile=length(D);
for jfile=1:nfile,
    answer=input(['Fix TLm file ',D(jfile).name,' (<CR> =yes, any char=no)? '],'s');
    if isempty(answer),
        eval(['load ',D(jfile).name]);
        if ~isempty(SL_new),
            delta_SL=SL_new - TLm.SL
            TLm.SL=SL_new;
            TLm.data=TLm.data - delta_SL;
            TLm.title=[TLm.title,'_SLfix'];
        end
        if ~isempty(cal_old),
			delta_RL=20*log10(cal_new/cal_old),
            TLm.data=TLm.data + delta_RL;
            TLm.title=[TLm.title,'_cfix'];
        end
        eval(['save ',D(jfile).name(1:end-8),'_fix',D(jfile).name(end-7:end),' TLm']);
    end
end
    
    
