clear all;close all;

% air=ncread('air_2m_ocn_ts_YR_1871-2009_mask_corrected.nc','var_ts');
air=ncread('air_2m_lnd_ts_YR_1871-2009_mask_corrected.nc','var_ts');
% air=ncread('air_2m_ts_YR_1871-2009.nc','var_ts');

% monthly mean
for k=1:1668
	air2(k)=mean(air( (k-1)*240+1: k*240));
end
% annual mean
for k=1:139
	air3(k)=mean(air( (k-1)*2880+1: k*2880));
end

% anomaly to 1961-1990 mean, ref: CRUTEM4
air4=air3-mean(air3(91:120));

% anomaly to 1979-2009 mean
% air4=air3-mean(air3(109:139));

% anomaly to all
% air4=air3-mean(air3);
%%
figure;hold on
tmp=air4;
tmp(find(air4<0))=NaN;
bar(1871:2009,tmp,1,'r','edgecolor','none');
tmp=air4;
tmp(find(air4>=0))=NaN;
bar(1871:2009,tmp,1,'b','edgecolor','none');
axis tight;box on; 
set(gcf,'color','white');
air5=runmean(air4,2);
plot(1871:2009,air5,'k-','linewidth',3);
set(gca,'xlim',[1870 2010],'xtick',1870:10:2010,'ylim',[-1.4 1.4],'fontsize',14,'fontweight','bold');
xlabel('Year','fontsize',14,'fontweight','bold');
ylabel('Temperature anomaly','fontsize',14,'fontweight', 'bold');
title('Global averagered surface air temperature','fontsize',14,'fontweight','bold');

figsize(11.6,8.3); 
% export_fig air_2m_ts_YR_1871-2009_matlab_bar -pdf -png -m1 -r300 -a2 -q101 -painters -rgb
export_fig air_2m_lnd_ts_YR_1871-2009_matlab_bar -pdf -png -m1 -r300 -a2 -q101 -painters -rgb
%%
figure
plot(1871:2009,air4,'ko-','linewidth',2);
grid on; box on; hold on;
set(gca,'xlim',[1870 2010],'xtick',1870:10:2010,'ylim',[-0.8 0.8],'fontsize',14,'fontweight','bold');
xlabel('Year','fontsize',14,'fontweight','bold');
ylabel('Temperature anomaly','fontsize',14,'fontweight', 'bold');
title('Global averagered surface air temperature','fontsize',14,'fontweight','bold');
figsize(11.6,8.3); 
set(gcf,'color','white');
% export_fig air_2m_ts_YR_1871-2009_matlab -pdf -png -m1 -r300 -a2 -q101 -painters -rgb
%%
figure(2)
plot(1871:2009,air4,'ko-','linewidth',2);
grid on; box on; hold on;
set(gca,'xlim',[1950 2010],'xtick',1950:5:2010,'ylim',[-0.8 0.8],'fontsize',14,'fontweight','bold');
xlabel('Year','fontsize',14,'fontweight','bold');
ylabel('Temperature anomaly','fontsize',14,'fontweight', 'bold');
title('Global averagered surface air temperature','fontsize',14,'fontweight','bold');
figsize(11.6,8.3); 
set(gcf,'color','white');
% export_fig air_2m_ts_YR_1950-2009_matlab -pdf -png -m1 -r300 -a2 -q101 -painters -rgb
