%Called from make_MOC_all.m

addpath /data/mgoes/AX8/Time_transform/
addpath /data/mgoes/matlab/timeutil
addpath /data/mgoes/matlab/timeplt
addpath /data/mgoes/matlab
addpath /data/mgoes/matlab/mystuff

close all

%1st annual
%2nd Goes
%3rd Thacker
%4th Stommel
trash = 1000;
%trash = 100;%39;%39;%%39;%37;%36; %Sv
%load moc_mht_all.mat

 time(   moc_all(:,4) > trash,:)=[];
 mht_geo(moc_all(:,4) > trash,:)=[];
 mht_all(moc_all(:,4) > trash,:)=[];
 moc_geo(moc_all(:,4) > trash,:)=[];
 moc_all(moc_all(:,4) > trash,:)=[];


moc_all = moc_geo;
mht_all = mht_geo;

 month = yfraction2month(time(:,1));
 mes = str2num(month(:,5:6));
 
 clim = make_clim(moc_geo,month,'clim');
 clim = squeeze(clim);
 
 
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%5
 figure(5),clf
% set(gcf,'PaperPosition',[1 1 5 5]); 
 set(gcf,'PaperPosition',[1 1 6 3]); 
 set(gcf,'DefaultLineLineWidth',1.5)
 wysiwyg;
plot(1:12,clim(:,1),'-s')%,'color',cc{1})
hold on
plot(1:12,clim(:,2),'-d')%,'color',cc{2})
plot(1:12,clim(:,3),'-o')%,'color',cc{3})
plot(1:12,clim(:,4),'g-^')%,'color',cc{3})
 ylabel('MOC (Sv)')
set(gca,'fontsize',11,...
    'xlim',[0 13],'ylim',[10 24],'xtick',2:2:12,...
     'xticklabel',{'feb','apr','jun','aug','oct','dec'})
grid on
%leg = legend('Ann','G17','T07','Stomm','location','southwest');
leg = legend('SMEAN','RSEAS','RDIST','TSMEAN','location','southwest');
%print -dpng -r600 moc_clim_new.png
print -dpng -r600 moc_clim_new_acr.png
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 clim = make_clim(mht_geo,month,'clim');
 clim = squeeze(clim);
 
 figure(6),clf
% set(gcf,'PaperPosition',[1 1 5 5]); 
 set(gcf,'PaperPosition',[1 1 6 3]); 
 set(gcf,'DefaultLineLineWidth',1.5)
 wysiwyg;
 plot(1:12,clim(:,1),'-s')%,'color',cc{1})
hold on
plot(1:12,clim(:,2),'-d')%,'color',cc{2})
plot(1:12,clim(:,3),'-o')%,'color',cc{3})
plot(1:12,clim(:,4),'g-^')%,'color',cc{3})
 ylabel('MHT (PW)')
set(gca,'fontsize',11,...
    'xlim',[0 13],'ylim',[-.1 .8],'xtick',2:2:12,...
     'xticklabel',{'feb','apr','jun','aug','oct','dec'})
grid on
%leg = legend('Ann','G17','T07','Stomm','location','southwest');
leg = legend('SMEAN','RSEAS','RDIST','TSMEAN','location','southwest');
%print -dpng -r600 mht_clim_new.png
print -dpng -r600 mht_clim_new_acr.png

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%5 
 myfigure(10),clf
 set(gcf,'PaperPosition',[1 1 6 3]); 
 set(gcf,'DefaultLineLineWidth',1.5)
 wysiwyg;
 h(1)=plot(time,mht_all(:,1),'-s','markersize',3);hold on
 h(2)=plot(time,mht_all(:,2),'-d','markersize',3);
 h(3)=plot(time,mht_all(:,3),'-o','markersize',3);
 h(4)=plot(time,mht_all(:,4),'g-^','markersize',3);
xlim([2002 2018])
 %legend('Ann','T07','G17','Stomm')
legend('SMEAN','RDIST','RSEAS','TSMEAN');
 ylabel('MHT (PW)')
 set(gca,'fontsize',12)
% print -dpng -r600 mht_timeseries_new.png
 print -dpng -r600 mht_timeseries_new_acr.png
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%55
 myfigure(11),clf
 set(gcf,'PaperPosition',[1 1 6 3]); 
 set(gcf,'DefaultLineLineWidth',1.5)
 wysiwyg;
 h(1)=plot(time,moc_all(:,1),'-s','markersize',3);hold on
 h(2)=plot(time,moc_all(:,2),'-d','markersize',3);
 h(3)=plot(time,moc_all(:,3),'-o','markersize',3);
 h(4)=plot(time,moc_all(:,4),'g-^','markersize',3);
%plot(time,moc_all,'-s','markersize',3);
 xlim([2002 2018])
 %legend('Ann','T07','G17','Stomm')
 legend('SMEAN','RDIST','RSEAS','TSMEAN');
ylabel('MOC (Sv)')
 set(gca,'fontsize',12)
%print -dpng -r600 moc_timeseries_new.png
print -dpng -r600 moc_timeseries_new_acr.png

 cc = get(h,'color');
 
 %FOR MHT
mht_dif1 = zeros(1,12);
mht_dif0 = mht_dif1;
mht_dif2 = mht_dif1;
mht_dif3 = mht_dif1;
for ii=1:12      
ai = (mes==ii);
N = nnz(ai);
%mht_dif1(ii) = median(mht_all(ai,2)-mht_all(ai,3));
%std_dif1(ii) = std( mht_all(ai,2)-mht_all(ai,3))/sqrt(N);
%mht_dif0(ii) = median(mht_all(ai,2)-mht_all(ai,1));
%std_dif0(ii) = std( mht_all(ai,2)-mht_all(ai,1))/sqrt(N);
%mht_dif2(ii) = median(mht_all(ai,3)-mht_all(ai,1));
%std_dif2(ii) = std( mht_all(ai,3)-mht_all(ai,1))/sqrt(N);
mht_dif1(ii) = median(mht_all(ai,3)-mht_all(ai,2));
std_dif1(ii) = std( mht_all(ai,2)-mht_all(ai,3))/sqrt(N);
mht_dif0(ii) = median(mht_all(ai,1)-mht_all(ai,2));
std_dif0(ii) = std( mht_all(ai,2)-mht_all(ai,1))/sqrt(N);
mht_dif2(ii) = median(mht_all(ai,1)-mht_all(ai,3));
std_dif2(ii) = std( mht_all(ai,3)-mht_all(ai,1))/sqrt(N);
mht_dif3(ii) = median(mht_all(ai,4)-mht_all(ai,3));
std_dif3(ii) = std( mht_all(ai,4)-mht_all(ai,3))/sqrt(N);
end

%stop
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
figure(1),clf
% set(gcf,'PaperPosition',[1 1 5 5]); 
 set(gcf,'PaperPosition',[1 1 6 3]); 
 set(gcf,'DefaultLineLineWidth',1.5)
 wysiwyg;
h2 = axes('Position', [0.1500 0.1100 0.7500 0.8150]);
 plot(1:12,mht_dif1,'-s','color',cc{3});%,'-s');%T07-G27
 hold on
 %set(h2,'xlim',[0 13],'ylim',[-0.04 0.04],'xticklabel',[],'fontsize',11)
 %set(h1,'xlim',[0 13],'ylim',[-0.4 0.4],'xticklabel',[],'fontsize',11)
% errorbar(1:12,mht_dif1,std_dif1,'color',cc{1},'markersize',3)
 %set(gca,'YColor',cc{1})
 ylabel('\Delta MHT (PW)')

% h2 = axes('Position', [0.1500 0.1100 0.7500 0.8150]);
%hold on,
%plot(h2,1:12,[mht_dif0],'-d','color',cc{2})
plot(h2,1:12,mht_dif2/10,'-o','color',cc{1});hold on
plot(h2,1:12,mht_dif3,'-^','color',cc{4})
%plot(h2,1:12,mht_dif1,'-s','color',cc{1});%'g-s')
%plot(h2,0,-1,'-s','color',cc{1})
set(h2,'fontsize',11,...
    'xlim',[0 13],'ylim',[-0.08 0.08],'xtick',2:2:12,...
     'xticklabel',{'feb','apr','jun','aug','oct','dec'})%
 %,'color','none','YAxisLocation','right')
%    'xlim',[0 13],'ylim',[-0.3 0.4],'xtick',2:2:12,...
 %errorbar(h2,1:12,mht_dif0,std_dif0,'-s','color',cc{2},'markersize',3)
 
% errorbar(h2,1:12,mht_dif2/10,std_dif2/10,'-s','color',cc{1},'markersize',3)
% errorbar(h2,1:12,mht_dif3,std_dif3,'-s','color',cc{4},'markersize',3)
% errorbar(h2,1:12,mht_dif1,std_dif1,'color',cc{3},'markersize',3)
%set(gca,'YColor',cc{2})
grid on
%leg = legend('G17-Annual','T07-Annual','G17-T07','location','northwest')
%leg = legend('T07-G17','Ann-G17(/10)','Stomm-G17','location','southwest')
leg = legend('RDIST-RSEAS','SMEAN-RSEAS(/10)','TSMEAN-RSEAS','location','southwest');
%print -dpng -r600 mht_dif_clim_new.png
print -dpng -r600 mht_dif_clim_new_acr.png

%stop

%  figure(2),
%  plot(1:12,mht_dif0,'r-s')       
%  hold on
%  plot(1:12,mht_dif2,'g-d')       
%  errorbar(1:12,mht_dif0,std_dif0,'r-s')       
%  errorbar(1:12,mht_dif2,std_dif2,'g-d')       

 
 %FOR MOC
moc_dif1 = zeros(1,12);
moc_dif0 = moc_dif1;
moc_dif2 = moc_dif1;
moc_dif3 = moc_dif1;
for ii=1:12      
ai = (mes==ii);
N=nnz(ai);
% moc_dif1(ii) = mean(moc_all(ai,2)-moc_all(ai,3));
% std_dif1(ii) = std( moc_all(ai,2)-moc_all(ai,3))/sqrt(N);
% moc_dif0(ii) = mean(moc_all(ai,2)-moc_all(ai,1));
% std_dif0(ii) = std( moc_all(ai,2)-moc_all(ai,1))/sqrt(N);
% moc_dif2(ii) = mean(moc_all(ai,3)-moc_all(ai,1));
% std_dif2(ii) = std( moc_all(ai,3)-moc_all(ai,1))/sqrt(N);
moc_dif1(ii) = median(moc_all(ai,3)-moc_all(ai,2));
std_dif1(ii) = std( moc_all(ai,2)-moc_all(ai,3))/sqrt(N);
moc_dif0(ii) = median(moc_all(ai,1)-moc_all(ai,2));
std_dif0(ii) = std( moc_all(ai,2)-moc_all(ai,1))/sqrt(N);
moc_dif2(ii) = median(moc_all(ai,1)-moc_all(ai,3));
std_dif2(ii) = std( moc_all(ai,3)-moc_all(ai,1))/sqrt(N);
moc_dif3(ii) = median(moc_all(ai,4)-moc_all(ai,3));
std_dif3(ii) = std( moc_all(ai,4)-moc_all(ai,3))/sqrt(N);
end

%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
figure(2),clf
 %set(gcf,'PaperPosition',[1 1 5 5]); 
 set(gcf,'PaperPosition',[1 1 6 3]); 
 set(gcf,'DefaultLineLineWidth',1.5)
 wysiwyg;
h2 = axes('Position', [0.1500 0.1100 0.7500 0.8150]);
a1=plot(1:12,moc_dif1,'-s','color',cc{3});%,'-s');
hold on
set(h2,'xlim',[0 13],'ylim',[-1.0 1.0],'xticklabel',[],'fontsize',11,'ytick',[-1.0:.2:1.0])
%errorbar(1:12,moc_dif1,std_dif1,'color',cc{1},'markersize',3)
%set(gca,'YColor',cc{1})
ylabel('\Delta MOC (Sv)')

%h2 = axes('Position', [0.1500 0.1100 0.7500 0.8150]);
%hold on,
a2=plot(h2,1:12,moc_dif2/10,'-o','color',cc{1});%'g-s')
%hold on
a3=plot(h2,1:12,moc_dif3,'-^','color',cc{4});%'g-s')
%a4=plot(h2,0,-100,'-s','color',cc{1});%'g-s')
%a4=plot(h2,1:12,moc_dif1,'-s','color',cc{1});%'g-s')
 %set(h2,'color','none','YAxisLocation','right','fontsize',11,...
 %    'xlim',[0 13],'ylim',[-10 10],'ytick',[-10:2:10],'xtick',2:2:12,...
 %     'xticklabel',{'feb','apr','jun','aug','oct','dec'})
set(h2,'fontsize',11,...
    'xlim',[0 13],'ylim',[-1 1],'xtick',2:2:12,...
     'xticklabel',{'feb','apr','jun','aug','oct','dec'})
 %errorbar(h2,1:12,moc_dif2/10,std_dif2/10,'-s','color',cc{1},'markersize',3)
 %errorbar(h2,1:12,moc_dif3,std_dif3,'-s','color',cc{4},'markersize',3)
 %errorbar(h2,1:12,moc_dif1,std_dif1,'color',cc{3},'markersize',3)
%set(gca,'YColor',cc{2})
grid on
%leg = legend('Ann-G17','Stomm-G17','T07-G17','location','northwest')
%leg = legend('T07-G17','Ann-G17 (/10)','Stomm-G17','location','southwest')
leg = legend('RDIST-RSEAS','SMEAN-RSEAS(/10)','TSMEAN-RSEAS','location','southwest');
%print -dpng -r600 moc_dif_clim_new.png
print -dpng -r600 moc_dif_clim_new_acr.png

% figure(3),
%  plot(1:12,moc_dif1,'b-o')
%  hold on 
%  errorbar(1:12,moc_dif1,std_dif1,'b-o')
% 
%  figure(4),
%  plot(1:12,moc_dif0,'r-s')       
%  hold on
%  plot(1:12,moc_dif2,'g-d')       
%  errorbar(1:12,moc_dif0,std_dif0,'r-s')       
%  errorbar(1:12,moc_dif2,std_dif2,'g-d')       

 
