%calculate and plot moc trend in linwind

ifil='../../data/processed/moc_linw.nc';
moc=ncread(ifil,'MOC_LINW');
y=ncread(ifil,'YU_OCEAN');
z=ncread(ifil,'ST_OCEAN');
t=ncread(ifil,'TIME1');
timeStr=datevec(daynoleap2datenum(t,1900));


%calculate trend
mocT=squeeze(moc(:,:,1))+NaN;
for k=1:length(z)
 for j=1:length(y)
  tmp = polyfit(timeStr(:,1),squee(moc(j,k,:)),1);
  mocT(j,k) = tmp(1);
 end
end

figure(1); in=[0:4:40]
 set(gca,'nextplot','add','linewidth',1.5,'box','on', ...
         'tickdir','out','fontsize',20,'ydir','reverse', ...
         'xlim',[-80 -40],'ylim',[0 6000])
 flat_pcolor(y,z,squee(moc(:,:,1))')
 ax_lat

 amcolormap(jet,in); amcaxis(in);
          [cc]=amcolorbar('horiz',in);
          set(cc,'linewidth',2,'tickdir','out','fontweight','bold', ...
                  'xtick',in(1:2:end),'xticklabel',in(1:2:end),'position', ...
                  [0.130+0.15 0.1100 0.7750-0.3 0.0611/4], ...
                  'fontsize',20)
 legend('off')
 brighten(0.5)
 title('MOC in Sv 1980')

figure(2); in=[0:4:40]
 set(gca,'nextplot','add','linewidth',1.5,'box','on', ...
         'tickdir','out','fontsize',20,'ydir','reverse', ...
         'xlim',[-80 -40],'ylim',[0 6000])
 flat_pcolor(y,z,squee(moc(:,:,45))')
 ax_lat

 amcolormap(jet,in); amcaxis(in);
          [cc]=amcolorbar('horiz',in);
          set(cc,'linewidth',2,'tickdir','out','fontweight','bold', ...
                  'xtick',in(1:2:end),'xticklabel',in(1:2:end),'position', ...
                  [0.130+0.15 0.1100 0.7750-0.3 0.0611/4], ...
                  'fontsize',20)
 legend('off')
 brighten(0.5)
 title('MOC in Sv 2014')

figure(3); in=[0:4:40]
 set(gca,'nextplot','add','linewidth',1.5,'box','on', ...
         'tickdir','out','fontsize',20,'ydir','reverse', ...
         'xlim',[-80 -40],'ylim',[0 6000])
 flat_pcolor(y,z,squee(moc(:,:,1))' + 45*mocT')
 ax_lat

 amcolormap(jet,in); amcaxis(in);
          [cc]=amcolorbar('horiz',in);
          set(cc,'linewidth',2,'tickdir','out','fontweight','bold', ...
                  'xtick',in(1:2:end),'xticklabel',in(1:2:end),'position', ...
                  [0.130+0.15 0.1100 0.7750-0.3 0.0611/4], ...
                  'fontsize',20)
 legend('off')
 brighten(0.5)
 title('MOC in Sv 1980 + 45*calculated trend')

figure(4); in=[-0.05:0.05:0.3]
 set(gca,'nextplot','add','linewidth',1.5,'box','on', ...
         'tickdir','out','fontsize',20,'ydir','reverse', ...
         'xlim',[-80 -40],'ylim',[0 6000],'fontweight','bold')
 flat_pcolor(y,z,mocT')
 ax_lat

 amcolormap(jet,in); amcaxis(in);
          [cc]=amcolorbar('horiz',in);
          set(cc,'linewidth',2,'tickdir','out','fontweight','bold', ...
                  'xtick',in(2:2:end),'xticklabel',in(2:2:end),'position', ...
                  [0.130+0.1 0.1100+0.025 0.7750-0.2 0.0611/4], ...
                  'fontsize',20)
 ylabel('Depth   [m]')
 legend('off')
 brighten(0.5)
 %title('MOC trend [Sv/yr]')
 print -dpsc -bestfit -r300 -painters ../ps/mocTrend.ps
 !nobleed.sh ../ps/mocTrend.ps ../ps/mocTrendNoble.ps
