% main BC emis validation
%%%%%%%%%%%%%%%%%%%%%%%%%
clc;clear;close all;fclose all;
%%%%%%%%%%%%%%%%%%%%%%%%%%
%%
in_dir='F:/Data/BB4CMIP/raw/';
fn_in='BC-em-biomassburning_input4MIPs_emissions_CMIP_VUA-CMIP-BB4CMIP6-1-2_gn_185001-201512.nc';
info_in=ncinfo([in_dir,fn_in]);

fn_area='gridcellarea-em-biomassburning_input4MIPs_emissions_CMIP_VUA-CMIP-BB4CMIP6-1-2_gn.nc';
gridcellarea=ncread([in_dir,fn_area],'gridcellarea'); %unit: m^2
% fn_out='test2.nc';
varname='BC';
% yr_st=2015;
% yr_end=2015;
% BC
ii=2015;
fn_out_BC=['BB4CMIP6-BC-Biomass_',sprintf('%d',ii),'.nc'];
disp(['Processing ',fn_out_BC]);
[flag]=fun_avergedata([in_dir,fn_in],['./',fn_out_BC],'BC',ii,ii,1.0,'kg m-2 s-1');
if flag==1
    disp('done!')
end
%%
var=ncread(fn_out_BC,'BC');
lat=ncread(fn_out_BC,'lat');
lon=ncread(fn_out_BC,'lon');
var(var==0)=NaN;
[fig_handle]=fun_plot_025x025_gobal(double(lat),double(lon),double(var),1);
colorbar;
%%
ndays=reshape([31 28 31 30 31 30 31 31 30 31 30 31],1,1,12);
BC_emis_mat=var.*repmat(gridcellarea,1,1,12).*repmat(ndays*24*3600,1440,720,1);
%%
BC_emis_mon=reshape(sum(sum(BC_emis_mat,1),2)./1e9,12,1);
BC_emis_year=sum(BC_emis_mon);
% 
% tic
% [flag]=fun_avergedata(fn_in,fn_out,varname,yr_st,yr_end);
% toc
% info_in=ncinfo(fn_in);
% info_out=ncinfo(fn_out);
% 
% var=ncread(fn_out,varname);

