clear
clc

f='/Volumes/Backup Plus/backup/polar/ERA5/radiation.nc';
for i=36
    slhfclim=mean(ncread(f,'slhf',[1 1 i],[1440 361 30],[1 1 12])/86400,3);
    ssrclim=mean(ncread(f,'ssr',[1 1 i],[1440 361 30],[1 1 12])/86400,3);
    strclim=mean(ncread(f,'str',[1 1 i],[1440 361 30],[1 1 12])/86400,3);
    sshfclim=mean(ncread(f,'sshf',[1 1 i],[1440 361 30],[1 1 12])/86400,3);
    netclim=slhfclim+ssrclim+strclim+sshfclim;
end
f0='/Volumes/Backup Plus/backup/polar/ERA5/rad20_22.nc';
for i=36
    slhf=ncread(f0,'slhf',[1 1 i],[1440 361 1],[1 1 1])/86400;
    ssr=ncread(f0,'ssr',[1 1 i],[1440 361 1],[1 1 1])/86400;
    str=ncread(f0,'str',[1 1 i],[1440 361 1],[1 1 1])/86400;
    sshf=ncread(f0,'sshf',[1 1 i],[1440 361 1],[1 1 1])/86400;
    net=slhf+ssr+str+sshf;
end
x0=ncread(f0,'longitude');
y0=ncread(f0,'latitude');
[X,Y]=meshgrid(x0,y0);
X=double(X);Y=double(Y);


ssra=permute(ssr-ssrclim,[2 1]);
stra=permute(str-strclim,[2 1]);
slhfa=permute(slhf-slhfclim,[2 1]);
sshfa=permute(sshf-sshfclim,[2 1]);
neta=permute(net-netclim,[2 1]);

%%

set(gcf,'Position',[350 200 800 500]);
ha = tight_subplot(2,3,[0.05 0.02],[.04 .04],[.02 .02]);

axes(ha(1))
% m_proj('azimuthal equal-area','latitude',-90,'radius',50,'rectbox','on');
m_proj('azimuthal equal-area','latitude',-70,'longitude',-140,'radius',30,'rectbox','on');
hold on;
m_pcolor(X,Y,neta);
m_gshhs_i('color','k');
% m_grid('xaxislocation','top','xticklabels',[],'yticklabels',[],'fontsize',8);
m_grid('xaxislocation','top','xtick',[-160 -120],'ytick',[-90 -80 -70 -60 -50],'fontsize',10);
colortable = textread('/Users/jinfei/Documents/MATLAB/colorbar/temp_19lev.txt');
colormap(colortable);
caxis([-150 150]);


axes(ha(2))
m_proj('azimuthal equal-area','latitude',-70,'longitude',-140,'radius',30,'rectbox','on');
hold on;
m_pcolor(X,Y,ssra);
m_gshhs_i('color','k');
m_grid('xaxislocation','top','xtick',[-160 -120],'ytick',[-90 -80 -70 -60 -50],'fontsize',10);
colortable = textread('/Users/jinfei/Documents/MATLAB/colorbar/temp_19lev.txt');
colormap(colortable);
caxis([-150 150]);


axes(ha(3))
m_proj('azimuthal equal-area','latitude',-70,'longitude',-140,'radius',30,'rectbox','on');
hold on;
m_pcolor(X,Y,stra);
m_gshhs_i('color','k');
m_grid('xaxislocation','top','xtick',[-160 -120],'ytick',[-90 -80 -70 -60 -50],'fontsize',10);
colortable = textread('/Users/jinfei/Documents/MATLAB/colorbar/temp_19lev.txt');
colormap(colortable);
caxis([-150 150]);


axes(ha(4))
m_proj('azimuthal equal-area','latitude',-70,'longitude',-140,'radius',30,'rectbox','on');
hold on;
m_pcolor(X,Y,slhfa);
m_gshhs_i('color','k');
m_grid('xaxislocation','top','xtick',[-160 -120],'ytick',[-90 -80 -70 -60 -50],'fontsize',10);
colortable = textread('/Users/jinfei/Documents/MATLAB/colorbar/temp_19lev.txt');
colormap(colortable);
caxis([-150 150]);


axes(ha(5))
m_proj('azimuthal equal-area','latitude',-70,'longitude',-140,'radius',30,'rectbox','on');
hold on;
m_pcolor(X,Y,sshfa);
m_gshhs_i('color','k');
m_grid('xaxislocation','top','xtick',[-160 -120],'ytick',[-90 -80 -70 -60 -50],'fontsize',10);
colortable = textread('/Users/jinfei/Documents/MATLAB/colorbar/temp_19lev.txt');
colormap(colortable);
caxis([-150 150]);
colorbar;
hcb1 = colorbar('FontSize',12,'YTick',[-150 0 150]);
set(hcb1,'position',[0.7 0.055 0.02 0.4])
title(hcb1,'%');

delete(ha(6))

%%
clear
clc

f='/Volumes/Backup Plus/backup/polar/ERA5/downflux.nc';
% ncdisp(f)
x0=ncread(f,'longitude');
y0=ncread(f,'latitude');
[X,Y]=meshgrid(x0,y0);

ssrdcclim=mean(ncread(f,'ssrdc',[1 1 1],[1440 361 30],[1 1 1])/86400,3);
ssrdclim=mean(ncread(f,'ssrd',[1 1 1],[1440 361 30],[1 1 1])/86400,3);
strdcclim=mean(ncread(f,'strdc',[1 1 1],[1440 361 30],[1 1 1])/86400,3);
strdclim=mean(ncread(f,'strd',[1 1 1],[1440 361 30],[1 1 1])/86400,3);

ssrdca=permute(ncread(f,'ssrdc',[1 1 31],[1440 361 1],[1 1 1])/86400-ssrdcclim,[2 1]);
ssrda=permute(ncread(f,'ssrd',[1 1 31],[1440 361 1],[1 1 1])/86400-ssrdclim,[2 1]);
strdca=permute(ncread(f,'strdc',[1 1 31],[1440 361 1],[1 1 1])/86400-strdcclim,[2 1]);
strda=permute(ncread(f,'strd',[1 1 31],[1440 361 1],[1 1 1])/86400-strdclim,[2 1]);

set(gcf,'Position',[350 200 500 500]);
ha = tight_subplot(2,2,[0.05 0.02],[.04 .04],[.02 .02]);
axes(ha(1))
m_proj('azimuthal equal-area','latitude',-70,'longitude',-140,'radius',30,'rectbox','on');
hold on;
m_pcolor(X,Y,ssrda);
m_gshhs_i('color','k');
m_grid('xaxislocation','top','xtick',[-160 -120],'ytick',[-90 -80 -70 -60 -50],'fontsize',10);
colortable = textread('/Users/jinfei/Documents/MATLAB/colorbar/temp_19lev.txt');
colormap(colortable);
caxis([-150 150]);


axes(ha(2))
m_proj('azimuthal equal-area','latitude',-90,'radius',50,'rectbox','on');
hold on;
m_pcolor(X,Y,strda);
m_gshhs_i('color','k');
m_grid('xaxislocation','top','xticklabels',[],'yticklabels',[],'fontsize',8);
colortable = textread('/Users/jinfei/Documents/MATLAB/colorbar/temp_19lev.txt');
colormap(colortable);
caxis([-150 150]);


axes(ha(3))
m_proj('azimuthal equal-area','latitude',-90,'radius',50,'rectbox','on');
hold on;
m_pcolor(X,Y,ssrdca);
m_gshhs_i('color','k');
m_grid('xaxislocation','top','xticklabels',[],'yticklabels',[],'fontsize',8);
colortable = textread('/Users/jinfei/Documents/MATLAB/colorbar/temp_19lev.txt');
colormap(colortable);
caxis([-150 150]);


axes(ha(4))
m_proj('azimuthal equal-area','latitude',-90,'radius',50,'rectbox','on');
hold on;
m_pcolor(X,Y,strdca);
m_gshhs_i('color','k');
m_grid('xaxislocation','top','xticklabels',[],'yticklabels',[],'fontsize',8);
colortable = textread('/Users/jinfei/Documents/MATLAB/colorbar/temp_19lev.txt');
colormap(colortable);
caxis([-150 150]);


%%
ssru=permute(ssr-ncread(f,'ssrd',[1 1 31],[1440 361 1],[1 1 1])/86400,[2 1]);
ssruclim=permute(ssrclim-ssrdclim,[2 1]);
ssrua=ssru-ssruclim;
set(gcf,'Position',[350 200 600 700]);
m_proj('azimuthal equal-area','latitude',-70,'longitude',-140,'radius',30,'rectbox','on');
hold on;
m_pcolor(X,Y,ssrua);
m_gshhs_i('color','k');
m_grid('xaxislocation','top','xtick',[-160 -120],'ytick',[-90 -80 -70 -60 -50],'fontsize',10);
colortable = textread('/Users/jinfei/Documents/MATLAB/colorbar/temp_19lev.txt');
colormap(colortable);
caxis([-150 150]);

% a=colorbar('southoutside','FontSize',12,'position',[0.24 0.1 0.5 0.03],'YTick',[-150 -100 -50 0 50 100 150]);
% title(a,'W m^-^2');






