% function micom_timeseries(EXPID,YearBeg,YearEnd)
% plot the time series of sst,sst,..., during YearBeg and YearEnd

clear all;
close all;

%% Load Data
sst=load('sst.asc');         %two colums:first is time,second is data
sss=load('sss.asc');
ice_area_arc=load('ice_area_arctic.asc');
ice_area_ant=load('ice_area_antarctic.asc');
ice_volume_arc=load('ice_volume_arctic.asc');
ice_volume_ant=load('ice_volume_antarctic.asc');
ice_area_arc(:,2)=ice_area_arc(:,2)/1e12;
ice_area_ant(:,2)=ice_area_ant(:,2)/1e12;
ice_volume_arc(:,2)=ice_volume_arc(:,2)/1e12;
ice_volume_ant(:,2)=ice_volume_ant(:,2)/1e12;
%to change ice area unit m^2 to 10^6km^2
%to change ice volume unit m^2 to 1000km^3
%% Anual Mean
num=size(sst,1);             %totoal elements
year=fix(num/12);            %number of the year,round towards zero

%% --Sea Surface Temperature--
figure
figsize(8.26,11.69)
% figsize(11.69,8.26)
%plot monthly mean
subaxis(4,1,1,'SpacingVert',0);
H=plot(sst(:,2));
set(H,'color',[.8,.8,.8],'linewidth',1)
set(gca,'box','on','nextplot','add','xlim',[1,num],'ylim',[17,19],'ytick',17.2:0.4:19)
% H=plot(12*([1:year]-1)+6,sst_ave);
H=plot(runmean(sst(:,2),60)); % 5-year running mean
set(H,'linewidth',2,'color','k')
% set(gca,'xtick',get(gca,'xtick'),'xticklabel',fix(get(gca,'xtick')/12))
set(gca,'xtick',[]);
set(gca,'fontsize',16,'linewidth',1.5);
text(96,18.8,'a) SST','fontsize',14)
% title('Annual Mean Global SST','fontsize',16);
% xlabel('Year','fontsize',16);
ylabel('Deg C','fontsize',16);

% xx1=59*12:59*12:year*12;
xx1=59*12:59*12:236*12;
xx2(1:3:3*length(xx1))=xx1;
xx2(2:3:3*length(xx1))=xx1;
xx2(3:3:3*length(xx1))=NaN;

yy1=100*ones(1,length(xx1));
yy2(1:3:3*length(xx1))=0;
yy2(2:3:3*length(xx1))=yy1;
yy2(3:3:3*length(xx1))=NaN;

plot(xx2,yy2,'--r','linewidth',1);
%% --Sea Surface Salinity--
%plot monthly mean
subaxis(4,1,2,'SpacingVert',0);
H=plot(sss(:,2));
set(H,'color',[.8,.8,.8],'linewidth',1)
set(gca,'box','on','nextplot','add','xlim',[1,num],'ylim',[34.45,34.85],'ytick',34.5:0.1:34.8)

H=plot(runmean(sss(:,2),60));

set(H,'linewidth',2,'color','k')
set(gca,'xtick',[]);
set(gca,'fontsize',16,'linewidth',1.5);

text(96,34.8,'b) SSS','fontsize',14)
% title('Annual Mean Global SSS','fontsize',16);
% xlabel('Year','fontsize',16);
ylabel('SSS (psu)','fontsize',16);

plot(xx2,yy2,'--r','linewidth',1);

%% --Arctic Sea Ice Area--
%plot monthly mean
subaxis(4,1,3);
H=plot(ice_area_arc(:,2));
set(H,'color',[.8,.8,.8],'linewidth',1)
set(gca,'box','on','nextplot','add','xlim',[1,num],'ylim',[0,18],'ytick',3:4:18)
H=plot(runmean(ice_area_arc(:,2),60));
set(H,'linewidth',2,'color','k')

plot(1:num,11.87*ones(size(1:num)),'--k','linewidth',1.5);
plot(1:num,6.95*ones(size(1:num)),'-.k','linewidth',1);
plot(1:num,15.40*ones(size(1:num)),'-.k','linewidth',1);

set(gca,'xtick',[]);
set(gca,'fontsize',16,'linewidth',1.5);
text(96,16.5,'c) Arctic ice area','fontsize',14)
% title('Arctic Sea Ice Area','fontsize',16);
% xlabel('Year','fontsize',16);
ylabel('Area (10^6km^2)','fontsize',16);

plot(xx2,yy2,'--r','linewidth',1);
mean(ice_area_arc(:,2))
%% --Antarctic Sea Ice Area--
%plot monthly mean
subaxis(4,1,4);
H=plot(ice_area_ant(:,2));
set(H,'color',[.8,.8,.8],'linewidth',1)
set(gca,'box','on','nextplot','add','xlim',[1,num],'ylim',[0,20],'ytick',2:4:20)

H=plot(runmean(ice_area_ant(:,2),60));
set(H,'linewidth',2,'color','k')

plot(1:num,11.52*ones(size(1:num)),'--k','linewidth',1.5);
plot(1:num,3.14*ones(size(1:num)),'-.k','linewidth',1);
plot(1:num,18.27*ones(size(1:num)),'-.k','linewidth',1);

set(gca,'xtick',59*12:59*12:year*12,'xticklabel',59:59:year*12,...
    'xminortick','on','xgrid','off','ygrid','off')
set(gca,'fontsize',16,'linewidth',1.5);
text(96,17.5,'d) Antarctic ice area','fontsize',14)
% title('Antarctic Sea Ice Area','fontsize',16);
xlabel('Year','fontsize',16);
ylabel('Area (10^6km^2)','fontsize',16);

plot(xx2,yy2,'--r','linewidth',1);
mean(ice_area_ant(:,2))

% hb=bar(xx1,yy1,0.1,'edgecolor',[0 1 0],'facecolor',[1  1 1],'linestyle','--');
% ch = get(hb,'child');
% set(ch,'FaceAlpha',.9)
set(gcf,'color','w');
export_fig (gcf, 'Global_Timeseries', '-pdf', '-png','-m2.5','-r300', '-a2', '-q101', '-painters', '-rgb');
break


%% --Arctic Sea Ice Volume--
figure
%plot monthly mean
subaxis(2,1,1);
H=plot(ice_volume_arc(:,2));
set(H,'color',[.8,.8,.8],'linewidth',1)
set(gca,'box','on','nextplot','add','xlim',[1,num],'ylim',[0,35])

H=plot(ice_volume_arc(:,2),60);

set(H,'linewidth',2,'color','k')
%add the last year ticklabel
set(gca,'xtick',[12*([1:10:year]-1)+6,num],'xticklabel',...
	{int2str(fix(ice_volume_arc(12*([1:10:year]-1)+6,1))),int2str(fix(ice_volume_arc(end,1)))},...
	'xminortick','on','xgrid','on','ygrid','on');
%set(gca,'fontsize',16);
title('Annual Mean Arctic Sea Ice Volume','fontsize',16);
xlabel('Year','fontsize',16);
ylabel('Units:1000km^3','fontsize',16);

%% --Antarctic Sea Ice Volume--
%plot monthly mean
subaxis(2,1,2);
H=plot(ice_volume_ant(:,2));
set(H,'color',[.8,.8,.8],'linewidth',1)
set(gca,'box','on','nextplot','add','xlim',[1,num],'ylim',[0,25])

H=plot(runmean(ice_volume_ant(:,2),60));
set(H,'linewidth',2,'color','k')
%add the last year ticklabel
set(gca,'xtick',[12*([1:10:year]-1)+6,num],'xticklabel',...
	{int2str(fix(ice_volume_arc(12*([1:10:year]-1)+6,1))),int2str(fix(ice_volume_arc(end,1)))},...
	'xminortick','on','xgrid','on','ygrid','on');
%set(gca,'fontsize',16);
title('Arctic Sea Ice Volume','fontsize',16);
xlabel('Year','fontsize',16);
ylabel('Units:1000km^3','fontsize',16);

set(gcf,'color','w');
% export_fig (gcf, 'Global_Timeseries', '-pdf', '-png','-m2.5','-r300', '-a2', '-q101', '-painters', '-rgb');