clc;clear all;close all
file1='/data3/yiwen/cesm2/OBS_data/RAPID/2022/'
file2='/data3/yiwen/cesm2/OBS_data/OSNAP/2020/'
file3='/data3/yiwen/cesm2/OBS_data/MOVE/2022/'   %renew
file4='/data3/yiwen/cesm2/OBS_data/SAMBA/2017/'

load([file1,'MOC_OBS_time.mat'])
load([file2,'OSNAP_2022.mat'])
load([file3,'MOVE_2022.mat'])
load([file4,'SAMBA_2017.mat'])

%======= correlation ========%
[R,P] = corrcoef(OBS_MOC_year(11:17),OSNAP_year{1})
[R,P] = corrcoef(OBS_MOC_year(1:end),MOVE_year(5:end))

%======= monthly date =========%
% start_date = datetime(2004, 4, 1);
% end_date = datetime(2022, 1, 1);
% time = start_date:calmonths(1):end_date;

T=linspace(2000,2023,10);
Y1=ones(1,10);
set(0,'defaultfigurecolor','w')
set(gcf,'Position',[100 100 1000 800])
% ======= (1) Monthly data ======= %
time=linspace(2014,2020,71);
OSNAP_mean=nanmean(OSNAP_mon{1});
subplot(4,1,1)
plot(time,OSNAP_mon{1},'LineWidth',3,'Color','g');hold on
plot([2014.5:1:2020.5-1],OSNAP_year{1}(1:end-1),'LineWidth',2,...
     'Color',[0.4660 0.6740 0.1880],'Markerfacecolor',[0.4660 0.6740 0.1880],'Marker','o','LineStyle','-')
plot(T,OSNAP_mean*Y1,'LineWidth',1,'Color','k','LineStyle','--')
text(2000.5,18,sprintf('%.2f[SV]',OSNAP_mean),'LineWidth',4)
xlim([2000 2023]);ylim([5 25])
legend('OSNAP 53N','Location','southwest');legend boxoff
ylabel('Transport[SV]')
set(gca,'Fontsize',12,'Linewidth',2);grid on;box off
set(gca,'XMinorTick','on','YMinorTick','on','TickDir','out');ytickformat('%.2f')
set(gca, 'YAxisLocation', 'left', 'YTickLabelMode', 'auto', 'YTickMode', 'auto');    


time=linspace(2004,2022,214);
MOC_mean=nanmean(OBS_MOC_mon);
subplot(4,1,2)
plot(time,OBS_MOC_mon,'LineWidth',3,'Color','r');hold on
plot([2004.5:1:2022.5-1],OBS_MOC_year(1:end-1),'LineWidth',2,...
     'Color',[0.6350 0.0780 0.1840],'Markerfacecolor',[0.6350 0.0780 0.1840],'Marker','o','LineStyle','-');hold on
plot(T,MOC_mean*Y1,'LineWidth',1,'Color','k','LineStyle','--')
text(2000.5,19,sprintf('%.2f[SV]',MOC_mean),'LineWidth',4)
xlim([2000 2023]);ylim([5 25])
legend('RAPID 26.5N','Location','southwest');legend boxoff
ylabel('Transport[SV]')
set(gca,'Fontsize',12,'Linewidth',2);grid on;box off
set(gca,'XMinorTick','on','YMinorTick','on','TickDir','out');ytickformat('%.2f')
set(gca, 'YAxisLocation', 'right', 'YTickLabelMode', 'auto', 'YTickMode', 'auto'); 

time=linspace(2000,2022,273);
MOVE_mean=nanmean(-MOVE_mon);
subplot(4,1,3)
plot(time,-MOVE_mon,'LineWidth',3,'Color',[1 0 1]);hold on
plot([2000.5:1:2022.5-1],-MOVE_year(1:end-1),'LineWidth',2,...
    'Color',[0.9290 0.6940 0.1250],'Markerfacecolor',[0.9290 0.6940 0.1250],'Marker','o','LineStyle','-');hold on
plot(T,MOVE_mean*Y1,'LineWidth',1,'Color','k','LineStyle','--')
text(2022,20,sprintf('%.2f[SV]',MOVE_mean),'LineWidth',4)
xlim([2000 2023]);ylim([0 30])
legend('MOVE 16N','Location','southwest');legend boxoff
ylabel('Transport[SV]')
set(gca,'Fontsize',12,'Linewidth',2);grid on;box off
set(gca,'XMinorTick','on','YMinorTick','on','TickDir','out');ytickformat('%.2f')
set(gca, 'YAxisLocation', 'left', 'YTickLabelMode', 'auto', 'YTickMode', 'auto'); 

time=linspace(2009,2017,98);
subplot(4,1,4)
plot(time,SAMBA_mon,'LineWidth',3,'Color',[0 0.4470 0.7410]);hold on
plot([2009.5:1:2017.5-1],SAMBA_year(1:end-1),'LineWidth',2,...
    'Color','b','Markerfacecolor','b','Marker','o','LineStyle','-');hold on
plot(T,0*Y1,'LineWidth',2,'Color','k','LineStyle','--')
xlim([2000 2023]);ylim([-15 15])
legend('SAMBA 34.5S','Location','southwest');legend boxoff
ylabel('Anomaly[SV]')
set(gca,'Fontsize',12,'Linewidth',2);grid on;box off
set(gca,'XMinorTick','on','YMinorTick','on','TickDir','out');ytickformat('%.2f')
set(gca, 'YAxisLocation', 'right', 'YTickLabelMode', 'auto', 'YTickMode', 'auto'); 

% ===== save to .jpg ======%
% set(gcf, 'PaperPositionMode' , 'auto' )
% print( 'OBS_array2' , '-djpeg' , '-r800' )




