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

ADE_temp=ncread('~/Aerosol_Variaiton/IRUN/read_nc/ncfile/read_nc_ADE.nc','ADE');

ADE_ANN=zeros(144,96,150);

ADE_ANN(:,:,:)=mean(ADE_temp,3);

ADE_DJF=zeros(144,96,150);

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


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


save('ADE.mat','ADE_ANN','ADE_GLOBAL_ANN','ADE_DJF')

nccreate('ADE.nc','Year','Dimensions',{'time',Inf},'Format','classic')
ncwrite('ADE.nc','Year', year)
ncwriteatt('ADE.nc','Year','long_name','Year')
nccreate('ADE.nc','lat','Dimensions',{'lat',96},'Format','classic')
ncwrite('ADE.nc','lat', lat)
ncwriteatt('ADE.nc','lat','units','degrees_north')
ncwriteatt('ADE.nc','lat','long_name','Latitude')
nccreate('ADE.nc','lon','Dimensions',{'lon',144},'Format','classic')
ncwrite('ADE.nc','lon', lon)
ncwriteatt('ADE.nc','lon','units','degrees_east')
ncwriteatt('ADE.nc','lon','long_name','Longitude')
nccreate('ADE.nc','ADE_ANN','Dimensions',{'lon',144,'lat',96,'year',length(year)},'Format','classic')
ncwrite('ADE.nc','ADE_ANN', ADE_ANN)
nccreate('ADE.nc','ADE_DJF','Dimensions',{'lon',144,'lat',96,'year',length(year)},'Format','classic')
ncwrite('ADE.nc','ADE_DJF', ADE_DJF)
nccreate('ADE.nc','ADE_GLOBAL_ANN','Dimensions',{'year',length(year)},'Format','classic')
ncwrite('ADE.nc','ADE_GLOBAL_ANN', ADE_GLOBAL_ANN)
ncdisp('ADE.nc')