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

function lon=longch2(lon)

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

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