%% longch.m is designed to check the values of longitude
%% vectors in the plasma#.m code. Any values less than
%% -pi will have 2pi added to them, while any above pi
%% will have 2pi subtracted from them. This will allow
%% longitude vectors to be corrected so that all values are
%% between -pi and pi.

function lon=longch(lon)

% lon = (input) input longitude vector
% lon = (output) corrected output longitude vector

while sum(sum(lon<=-pi)) | sum(sum(lon>pi))
 lon(lon<=-pi)=lon(lon<=-pi)+2*pi;              %correct longitudes below -pi
 lon(lon>pi)=lon(lon>pi)-2*pi;                  %correct longitudes above -pi 
end
