function indx = indxfn2( tval, tvec )
%--------------------------------------------------------------------------
%
% PURPOSE: Find the index of the point in tval closest to tvec.
% FIRST AUTHOR:  Rob McEwen
% DATE:    05/2/11
% CHANGE LOG:  Date    Name    Comment
%         (1)
%
%--------------------------------------------------------------------------
%
  indxup = find(tvec > tval);
  indxdn = find(tvec < tval);
  if( isempty(indxup) | isempty(indxdn) )
    fprintf('indxfn2::val %.2f is not contained within vec.\n', tval);
    %indx = NaN;
    if( isempty(indxup) )
        indx = indxdn(end);
    elseif( isempty(indxdn) )
        indx = indxup(1);
    end
    return
  end
  
  if( abs(tvec(indxup(1)) - tval) < abs(tvec(indxdn(end)) - tval) )
    indx = indxup(1);
  else
    indx = indxdn(end);
  end
  
