function [c] = xrectang(a,b,epsi)

% xrectang adds or subtracts multiples of 360 degrees to angle b
% to attempt to bring it within del degrees of angle a.
%
% begun 12 december 1998 by paul hemenway

if abs(b-a)<epsi
   c=b;
   return;
end

z = b-a;
[zr,del] = rectang(z);

cd=min(zr,360-zr);

if cd>epsi
  fprintf('the closest difference is %d:  cannot get within %d degrees\n'...
          ,cd,epsi);
  return;
end

cv=[(b+del-360)-a,(b+del)-a,(b+del+360)-a];

cwhr=find(abs(cv)==min(abs(cv)));

c = cv(cwhr) + a;


