function LONG=lon_tr(long,art)
% LONG=lon_tr(long,art) transforms longitudes to 0-360 (art>0) or -180-180 (art<0)
% if art==0 transforms longitudes, so all longitudes are within
%  long(1)-180 and long(1)+180
% if art is missing it looks in the current figure window to fit the
% longitudes in the current x-Achsis
if nargin==0; warning('lon_tr, wrong number of arguments=0'); end
if nargin>2 ; warning('lon_tr, wrong number of arguments>2'); end

LONG=long;
if isempty(long); return; end

if nargin<2
    ii=get(0,'CurrentFigure');
    if isempty(ii); return; end
    xx=get(gca,'Xlim');
    if xx(1)<0 & xx(2)<=180;
        art=-1;
    elseif xx(2)<=360
        art=1;
    else
        art=0;
    end
end
if art==0; 
    ii=long>long(1)+180;
    long(ii)=long(ii)-360;
    ii=long<long(1)-180;
    long(ii)=long(ii)+360;
    LONG=long;
    return; 
end
LONG=rem(long,360);
if art>0;
    ii=LONG<0;   LONG(ii)=LONG(ii)+360;
    ii=LONG>0; 
    if min(LONG(ii))>=180;
        ii=LONG==0; LONG(ii)=360;
    end
elseif art<0;
    ii=LONG>180; LONG(ii)=LONG(ii)-360;
end
    
