function [T] = subT(t1,t2,T)

%   modifies ordered list of non-overlapping segments
%   so that the interval t1,t2 is not contained in any output segments
%   Usage: T = subT(t1,t2,T);
 
%   make sure t1,t2 are properly ordered
if(t1 > t2) 
  temp = t1;
  t1 = t2;
  t2 = temp;
end

if(~isempty(T))
   %  if t1 falls in an interval,  divide the interval into 2
   i1 = find((T(:,1) <=  t1)&(t1 <= T(:,2)));
   if(~isempty(i1))
      T = [T(1:i1-1,:); T(i1,1) t1; t1 T(i1,2) ; T(i1+1:end,:)];
   end
   %  if t2 falls in an interval,  divide the interval into 2
   i2 = find((T(:,1) <=  t2)&(t2 <= T(:,2)));
   if(~isempty(i2))
      T = [T(1:i2-1,:); T(i2,1) t2; t2 T(i2,2) ; T(i2+1:end,:)];
   end
   %  eliminate any pairs in list T that are completely covered by the
   %  interval (t1,t2)
   T = T(find(1-((t1 <= T(:,1))&(T(:,2) <= t2))),:);
end
