load ~/NC/grid
load ~/NC/area_1.9_2.5.mat
year=1:150;

ADESF_temp=ncread('~/Aerosol_Variaiton/IRUN/read_nc/ncfile/read_nc_ADESF.nc','ADESF');

ADESF_ANN=zeros(144,96,150);

ADESF_ANN(:,:,:)=mean(ADESF_temp,3);

ADESF_DJF=zeros(144,96,150);

ADESF_DJF(:,:,1)=mean(ADESF_temp(:,:,[1,2],1),3);
for yearID=2:150
    ADESF_DJF(:,:,yearID)=(ADESF_temp(:,:,12,yearID-1)+ADESF_temp(:,:,1,yearID)+ADESF_temp(:,:,2,yearID))/3;
end


ADESF_GLOBAL_ANN=zeros(150,1);
for yearID=1:150
    ADESF_GLOBAL_ANN(yearID)=sum(sum(ADESF_ANN(:,:,yearID).*area,2),1)/sum(area(:));
end


save('ADESF.mat','ADESF_ANN','ADESF_GLOBAL_ANN','ADESF_DJF')

nccreate('ADESF.nc','Year','Dimensions',{'time',Inf},'Format','classic')
ncwrite('ADESF.nc','Year', year)
ncwriteatt('ADESF.nc','Year','long_name','Year')
nccreate('ADESF.nc','lat','Dimensions',{'lat',96},'Format','classic')
ncwrite('ADESF.nc','lat', lat)
ncwriteatt('ADESF.nc','lat','units','degrees_north')
ncwriteatt('ADESF.nc','lat','long_name','Latitude')
nccreate('ADESF.nc','lon','Dimensions',{'lon',144},'Format','classic')
ncwrite('ADESF.nc','lon', lon)
ncwriteatt('ADESF.nc','lon','units','degrees_east')
ncwriteatt('ADESF.nc','lon','long_name','Longitude')
nccreate('ADESF.nc','ADESF_ANN','Dimensions',{'lon',144,'lat',96,'year',length(year)},'Format','classic')
ncwrite('ADESF.nc','ADESF_ANN', ADESF_ANN)
nccreate('ADESF.nc','ADESF_DJF','Dimensions',{'lon',144,'lat',96,'year',length(year)},'Format','classic')
ncwrite('ADESF.nc','ADESF_DJF', ADESF_DJF)
nccreate('ADESF.nc','ADESF_GLOBAL_ANN','Dimensions',{'year',length(year)},'Format','classic')
ncwrite('ADESF.nc','ADESF_GLOBAL_ANN', ADESF_GLOBAL_ANN)
ncdisp('ADESF.nc')