clear all;close all;
addpath('~/output/carbon/NOIIANOC_mr03_hist2/Cant');
DataPath='~/output/carbon/NOIIANOC_mr03_hist2/Cant/';

kx=360;ky=365;kz=70;
nmask=ncread('~/tools/data/mask_tnx1v1_nordic.nc','mask_nordic');
nmask=repmat(nmask,[1,1,kz]);

depth=ncread('~/tools/data/tnx1v1_depth.nc','depth');

yr=1990:2009;

[yr depth]=meshgrid(yr,depth);

anthct=nan(kz,20);
maget=nan(kz,20);
n=1;
for T0=1990:2009
	%FNAME=['NOIIANOC_mr03_hist2_Cant_SF6_r10_s86_t',num2str(T0),'_depth_nordic.mat'];
	FNAME=['NOIIANOC_mr03_hist2_Cant_CFC12_r10_s999_t',num2str(T0),'_depth_nordic.mat'];
	load([DataPath,FNAME],'mage','Cant_ttd');
	
	Cant_ttd(find(nmask~=2))=NaN;
	anthcp=nanmean(Cant_ttd,1);
	anthcp=nanmean(anthcp,2);
	anthcp=squeeze(anthcp);
	anthct(:,n)=anthcp;

	mage(find(nmask~=2))=NaN;
	mage(isinf(mage))=NaN;
	magep=nanmean(mage,1);
	magep=nanmean(magep,2);
	magep=squeeze(magep);
	maget(:,n)=magep;

	n=n+1;
end

%save ttd_decadal_change_sf6.mat anthct maget yr depth
save ttd_decadal_change_cfc12.mat anthct maget yr depth
%break

%% anthc
figure; hold on;
pcolor(yr,depth,anthct);shading flat;hc=colorbar;
set(gca,'ydir','reverse','xlim',[1990 2009],'ylim',[0 4000],'fontsize',16,'fontweight','bold');
grid on;box on;
caxis([0 50]);
xlabel('Year','fontsize',16,'fontweight','bold');
ylabel('Depth (m)','fontsize',16,'fontweight','bold');
title('Cant (umol/kg)','fontsize',16,'fontweight','bold');
%cmap=cbrewer('seq','YlOrRd',24);
cmap=cbrewer('div','RdYlBu',20);
colormap(flipud(cmap));
cbfit(hc,4);
set(gcf,'color','white');figsize(11.69,8.26);
%pathout='~/output/carbon/NOIIANOC_mr03_hist2/profile/hovmoller/';
pathout='/Users/heyc/output/carbon/NOIIANOC_mr03_hist2/profile/hovmoller/';
%figname='anthc_ttd_sf6_1990-2009';
figname='anthc_ttd_cfc12_1990-2009';
mfile=[mfilename('fullpath'),'.m'];
fighist(mfile,pathout,figname)
%save2pdf([pathout,figname])
export_fig (gcf, [pathout,figname], '-png','-m2.5','-r300', '-a2', '-q101', '-painters', '-rgb');
%
%% danthc
figure; hold on;
pcolor(yr(:,2:end),depth(:,2:end),anthct(:,2:end)-anthct(:,1:end-1));shading flat;hc=colorbar;
set(gca,'ydir','reverse','xlim',[1990 2009],'ylim',[0 4000],'fontsize',16,'fontweight','bold');
grid on;box on;
caxis([-2 2]);
xlabel('Year','fontsize',16,'fontweight','bold');
ylabel('Depth (m)','fontsize',16,'fontweight','bold');
title('Cant rate (umol/kg/yr)','fontsize',16,'fontweight','bold');
%cmap=cbrewer('seq','YlOrRd',24);
cmap=cbrewer('div','RdBu',24);
colormap(flipud(cmap));cbfit(hc,4);
set(gcf,'color','white');figsize(11.69,8.26);
pathout='~/output/carbon/NOIIANOC_mr03_hist2/profile/hovmoller/';
figname='anthc_rate_ttd_sf6_1990-2009';
figname='anthc_rate_ttd_cfc12_1990-2009';
mfile=[mfilename('fullpath'),'.m'];
fighist(mfile,pathout,figname)
%save2pdf([pathout,figname])
export_fig (gcf, [pathout,figname], '-png','-m2.5','-r300', '-a2', '-q101', '-painters', '-rgb');

%% maget
figure; hold on;
pcolor(yr,depth,maget);shading flat;hc=colorbar;
set(gca,'ydir','reverse','xlim',[1990 2009],'ylim',[0 4000],'fontsize',16,'fontweight','bold');
%caxis([0 200]);
caxis([0 350]);
xlabel('Year','fontsize',16,'fontweight','bold');
ylabel('Depth (m)','fontsize',16,'fontweight','bold');
title('TTD mean age (yr)','fontsize',16,'fontweight','bold');
cmap=cbrewer('div','RdYlBu',24);
colormap(flipud(cmap));cbfit(hc,4);
set(gcf,'color','white');figsize(11.69,8.26);
mfile=[mfilename('fullpath'),'.m'];
fighist(mfile,pathout,figname)
pathout='~/output/carbon/NOIIANOC_mr03_hist2/profile/hovmoller/';
figname='mage_ttd_sf6_1990-2009';
figname='mage_ttd_cfc12_1990-2009';
mfile=[mfilename('fullpath'),'.m'];
fighist(mfile,pathout,figname)
%save2pdf([pathout,figname])
export_fig (gcf, [pathout,figname], '-png','-m2.5','-r300', '-a2', '-q101', '-painters', '-rgb');
