function y=mod2pi(x)

% y = modpi(x)
% 
% Takes input in radians.  Returns values between 0 and 2pi.

y = rem( x + pi, 2*pi ) - pi;

ii = find( y < -pi );
if ~isempty( ii )
    y(ii) = y(ii) + 2*pi;
end
