function [lon, mean_lon, lon_split] = unwrap_lon(lon, lon_split);
% newlon = unwrap_lon(lon, lon_split);
% 
%  attempts to make longitude one continuous line where data exist
%  if lon_split is not specified, try to do it automatically
%    otherwise, make the split occur at lon_split



if (~exist('lon_split'))
   slon = sin(pi*lon/180);
   clon = cos(pi*lon/180);
   mean_lon = 90 - (180/pi)*angle(mstdgap(slon) + i*mstdgap(clon));
   lon_split = mean_lon  - 180;
   lon_split = rem(mean_lon -360, 360) + 180;
end

lon = rem(lon - lon_split + 720  , 360) + lon_split ;

lon = lon - 360*floor(max(lon)/360);
