
area=ncread('areacella_fx_NorESM1-M_piControl_r0i0p0.nc','areacella');
land=ncread('sftlf_fx_NorESM1-M_piControl_r0i0p0.nc','sftlf')/100;

%FPATH='/cluster/work/users/ingo/noresm/NF2005AERAMIP_f19_f19_CMIP6aero_01/run/NF2005AERAMIP_f19_f19_CMIP6aero_01.cam2.h1.1979-01-01-00000.nc';
FPATH='NF2005AERAMIP_f19_f19_CMIP6aero_01.cam2.h1.1979-01-01-00000.nc';

VARS={'EMI_BC','EMI_POM','EMI_SO2','EMI_SO4',...
 'EMI_BC_CMIP6','EMI_POM_CMIP6','EMI_SO2_CMIP6','EMI_SO4_CMIP6',...
 'BC_AX_CLXF','BC_NI_CLXF','BC_N_CLXF','OM_NI_CLXF',...
 'SO2_CLXF','SO4_PR_CLXF'};

figure(1)
clf
for n=1:numel(VARS) 
  VNAME=char(VARS{n});
  data=ncread(FPATH,VNAME)*24*3600*365*1e-9; % Tg/s
  gtot(n)=sum(sum(data.*area));
  ind=find(land>0.01); 
  glnd(n)=sum(sum(data(ind).*area(ind)));
  % 
  subplot(4,4,n) 
  bar([gtot(n) glnd(n) gtot(n)-glnd(n)]); 
  xlim=get(gca,'xlim');ylim=get(gca,'ylim');
  text(xlim(2),ylim(2),VNAME,'horiz','right','vert','top','interpreter','none'); 
end

%%%%

PREFIX='/tos-project1/NS2345K/noresm/inputdata/atm/cam/camoslo/emissions/IPCC_emiss_';
SUFFIX='_1850-2005.nc';
VARS2={'bcair','bcbb','bcff','pombb','pomff','so2bb','so2ff'};
figure(2)
clf
for n=1:numel(VARS2)
  VNAME=char(VARS2{n});
  switch VNAME 
  case {'bcair','bcff'} 
    VNAME2='emiss_bc';
  case 'bcbb' 
    VNAME2='emiss_bc_bb';
  case 'pombb'
    VNAME2='emiss_pom_bb';
  case 'pomff' 
    VNAME2='emiss_pom';
  case 'so2bb'
    VNAME2='emiss_so2_bb';
  case 'so2ff' 
    VNAME2='emiss_so2';
  end 
  data=squeeze(sum(ncread([PREFIX VNAME SUFFIX],VNAME2,[1 1 1 1 17],[inf inf inf 1 1]),3))*24*3600*365*1e-9;  % Tg/s
  gtot2(n)=sum(sum(data.*area));
  ind=find(land>0.01); 
  glnd2(n)=sum(sum(data(ind).*area(ind)));
  % 
  subplot(4,4,n) 
  bar([gtot2(n) glnd2(n) gtot2(n)-glnd2(n)]); 
  xlim=get(gca,'xlim');ylim=get(gca,'ylim');
  text(xlim(2),ylim(2),VNAME,'horiz','right','vert','top','interpreter','none'); 
end 

