function [x_out]=netcdf_ecco_GenericgridRotateLon(x_in,lon0_in,lon0_out,lonSyst); %lonSyst=1: we use degree east from greenwich %lonSyst=2: we use degree east/west from greenwich %-this routine first set longitude according to lonSyst %and then change the 0 longitude from lon0_in to lon0_out %-input: lon0_in is the current 0 longitude, in degree east from greenwich % lon0_out is the new 0 longitude, in degree east from greenwich % x_in is longitude relative to lon0_in %output: x_out is longitude relative to lon0_out if lonSyst==2 tmp1=find(x_in>=180); x_in(tmp1)=x_in(tmp1)-360; tmp1=find(x_in<-180); x_in(tmp1)=x_in(tmp1)+360; elseif lonSyst==1 tmp1=find(x_in<0); x_in(tmp1)=x_in(tmp1)+360; tmp1=find(x_in>=360); x_in(tmp1)=x_in(tmp1)-360; else fprintf('lonSyst must be 1 or 2 => stop \n'); return; end; x_out=x_in-(lon0_out-lon0_in); if lonSyst==2 tmp1=find(x_out>=180); x_out(tmp1)=x_out(tmp1)-360; tmp1=find(x_out<-180); x_out(tmp1)=x_out(tmp1)+360; elseif lonSyst==1 tmp1=find(x_out<0); x_out(tmp1)=x_out(tmp1)+360; tmp1=find(x_out>=360); x_out(tmp1)=x_out(tmp1)-360; end