function wdata = wrap_around(data,modulus,leftmost)

%WRAP_AROUND -- Wrap around a circle with an arbitrary leftmost point
%
%  wdata = wrap_around(data,modulus)
%  wdata = wrap_around(data,modulus,leftmost)
%
%  DATA is a real matrix of arbitrary shape.
%  MODULUS is a positive number. LEFTMOST defaults to 0
%  WDATA values are guaranteed to be >= leftmost and < (leftmost+modulo)
%
%  Definition:
%   wdata = mod(data-leftmost,modulo) + leftmost
%
%  Example:
%   d=[-361 -360 -359 -181 -180 -179 -1 0 1 179  180  181 359 360 361] ; 
%   wrap_around(d,360,-180)
%     [  -1    0    1  179 -180 -179 -1 0 1 179 -180 -179  -1   0   1]
%
%  Note: This function is not intended to work with complex numbers.
%        Use MATLAB's ANGLE and UNWRAP for that.
%
%  See also MOD, ANGLE, UNWRAP.

% Original coding by Alex Petrov, Ohio State University
% $Revision: 1.0 $  $Date: 2006/04/03 17:25 $
%
% Part of the utils toolbox version 1.1 for MATLAB version 5 and up.
% http://alexpetrov.com/softw/utils/
% Copyright (c) Alexander Petrov 1999-2006, http://alexpetrov.com
% Please read the LICENSE and NO WARRANTY statement in ../utils_license.m

if (nargin==2)  leftmost = 0 ; end

wdata = mod(data-leftmost,modulus) + leftmost ;

%---  Return WDATA
%%%%% End of WRAP_AROUND.M
