clear
clc

f1='/Volumes/Backup Plus/PAROCE/OND_2022_sic.nc';
f2='/Volumes/Backup Plus/PAROCE/OND_clim_sic.nc';
f3='/Volumes/Backup Plus/PAROCE/OND_2022_sit.nc';
f4='/Volumes/Backup Plus/PAROCE/OND_clim_sit.nc';

sic22=ncread(f1,'siconc')*100; 
sic22(sic22<5)=nan;
sicclim=ncread(f2,'siconc')*100; 
sicclim(sicclim<5)=nan;

sit22=ncread(f3,'sivolu');
sit22(isnan(sic22)==1)=nan;
sitclim=ncread(f4,'sivolu');
sitclim(isnan(sicclim)==1)=nan;
f5='/Volumes/Backup Plus/PAROCE/so025_eORCA025_cellarea.nc';
area=ncread(f5,'cell_area');
ca=repmat(area,1,1,92);
siv22=sit22.*ca;
sivclim=sitclim.*ca;


X=ncread(f1,'nav_lon');
Y=ncread(f1,'nav_lat');
X=double(X);
Y=double(Y);
ind1=find(X>-180&X<-120&Y>-80&Y<-70);
ind2=find(X>-180&X<-120&Y>-70&Y<-60);


for i=1:92
    t1=sic22(:,:,i);
    c22in(i)=nanmean(t1(ind1));
    t2=sicclim(:,:,i);
    cclimin(i)=nanmean(t2(ind1));
    t3=siv22(:,:,i);
    t22in(i)=nanmean(t3(ind1));
    t4=sivclim(:,:,i);
    tclimin(i)=nanmean(t4(ind1));
    t5=sic22(:,:,i);
    c22out(i)=nanmean(t5(ind2));
    t6=sicclim(:,:,i);
    cclimout(i)=nanmean(t6(ind2));
    t7=siv22(:,:,i);
    t22out(i)=nanmean(t7(ind2));
    t8=sivclim(:,:,i);
    tclimout(i)=nanmean(t8(ind2));
end


%%
set(gcf,'Position',[350 200 800 600]);
ha = tight_subplot(2,2,[0.1 0.08],[.06 .06],[.08 .02]);

axes(ha(1))
plot(c22in,'color',sixteen2ten('#2D59D2')/255,'LineWidth',1.5)
hold on
plot(cclimin,'color',sixteen2ten('#E85472')/255,'LineWidth',1.5)
set(gca,'xtick',[1 32 62],'xticklabel',{'Oct' 'Nov' 'Dec'},'fontname','Arial','fontsize',14);
legend('2022','Clim','fontname','Arial','fontsize',14);
ylabel('SIC (%)','fontname','Arial','fontsize',14)
axis([1 92 0 100])
text(5,90,"a",'FontSize',16,'FontWeight','bold','fontname','Arial')
title('Onshore SIC','FontSize',16,'fontname','Arial')

axes(ha(2))
plot(t22in,'color',sixteen2ten('#2D59D2')/255,'LineWidth',1.5)
hold on
plot(tclimin,'color',sixteen2ten('#E85472')/255,'LineWidth',1.5)
set(gca,'xtick',[1 32 62],'xticklabel',{'Oct' 'Nov' 'Dec'},'fontname','Arial','fontsize',14);
legend('2022','Clim','fontname','Arial','fontsize',14);
ylabel('SIV (m^3)','fontname','Arial','fontsize',14)
axis([1 92 0 11*1e7])
text(5,10*1e7,"b",'FontSize',16,'FontWeight','bold','fontname','Arial')
title('Onshore SIV','FontSize',16,'fontname','Arial')


axes(ha(3))
plot(c22out,'color',sixteen2ten('#2D59D2')/255,'LineWidth',1.5)
hold on
plot(cclimout,'color',sixteen2ten('#E85472')/255,'LineWidth',1.5)
set(gca,'xtick',[1 32 62],'xticklabel',{'Oct' 'Nov' 'Dec'},'fontname','Arial','fontsize',14);
legend('2022','Clim','fontname','Arial','fontsize',14);
ylabel('SIC (%)','fontname','Arial','fontsize',14)
axis([1 92 0 100])
text(5,90,"c",'FontSize',16,'FontWeight','bold','fontname','Arial')
title('Offshore SIC','FontSize',16,'fontname','Arial')


axes(ha(4))
plot(t22out,'color',sixteen2ten('#2D59D2')/255,'LineWidth',1.5)
hold on
plot(tclimout,'color',sixteen2ten('#E85472')/255,'LineWidth',1.5)
set(gca,'xtick',[1 32 62],'xticklabel',{'Oct' 'Nov' 'Dec'},'fontname','Arial','fontsize',14);
legend('2022','Clim','fontname','Arial','fontsize',14);
ylabel('SIV (m^3)','fontname','Arial','fontsize',14)
axis([1 92 0 11*1e7])
text(5,10*1e7,"d",'FontSize',16,'FontWeight','bold','fontname','Arial')
title('Offshore SIV','FontSize',16,'fontname','Arial')
