function yw = int(xo,yo,xw)

% function yf = int(xo,yo,xf);
%
% xo = original x; yo = original y; xf = final x; yf = final y;
%
% this is an interpolation routine that does not require monotonic x.  
% it's a combination of nearest neighbor and linear interpolation depending
% on the inputs.  it should work ok as long as the original data is _close_
% to single valued.  This routine assumes that both xo and xw are in 
% ascending order.

% dail, 5/13/98

% check to make sure data are not too far apart
if max(diff(xo)) > 1.5*max(diff(xw))
 warning('Data are widely spaced.  Results may be inaccurate.')
end

m = 1;
yw = nan*ones(size(xw));

for l=1:length(xw)
 if xo(m) < xw(l) 
  while xo(m+1) < xw(l)
   m = m+1;
   if m+1 > length(xo), break, end
  end
  if m+1 > length(xo)
   return;
  else
   yw(l) = table1([ xo(m) yo(m); xo(m+1) yo(m+1) ],xw(l));
  end 
 end
end


