function [i]=interv(t,x)
% usage: [i]=interv(knots,xvalues)
% largest index left so that t(i) <= x.
% x is xolumn vector
    
% find i so that t(i) is closest to x
    m = max(size(x));
    i = zeros(m,1);
    for n=1:m
        if(x(n)>t(max(size(t))))
            i=-1; % failed
            return            
        end
        [min_diff,i(n)] = min(abs(t-x(n)));
        if t(i(n))>x(n)   
            i(n) = i(n)-1;
        end    
        % count out multiple same t(1)'s
        if i(n)==1
            for j = 2:max(size(t))
                if t(j)> x(n)
                    break
                end
            end                
            i(n)=j-1;
        end
        end
    end

        
        