load ~/NC/grid
year=1:150;

AOD_temp=ncread('~/Aerosol_Variaiton/IRUN/read_nc/ncfile/read_nc_AOD.nc','AOD');

AOD_ANN=zeros(144,96,150);
AOD_DJF=zeros(144,96,150);
AOD_MAM=zeros(144,96,150);
AOD_JJA=zeros(144,96,150);
AOD_SON=zeros(144,96,150);
AOD_JAN=zeros(144,96,150);
AOD_JUL=zeros(144,96,150);

AOD_ANN(:,:,:)=mean(AOD_temp,3);
AOD_MAM(:,:,:)=mean(AOD_temp(:,:,[3,4,5],:),3);
AOD_JJA(:,:,:)=mean(AOD_temp(:,:,[6,7,8],:),3);
AOD_SON(:,:,:)=mean(AOD_temp(:,:,[9,10,11],:),3);
AOD_DJF(:,:,1)=mean(AOD_temp(:,:,[1,2],1),3);
for yearID=2:150
    AOD_DJF(:,:,yearID)=(AOD_temp(:,:,12,yearID-1)+AOD_temp(:,:,1,yearID)+AOD_temp(:,:,2,yearID))/3;
end
AOD_JAN(:,:,:)=AOD_temp(:,:,1,:);
AOD_JUL(:,:,:)=AOD_temp(:,:,7,:);

save('AOD.mat','AOD_ANN','AOD_DJF','AOD_MAM','AOD_JJA','AOD_SON','AOD_JAN','AOD_JUL')

nccreate('AOD.nc','Year','Dimensions',{'time',Inf},'Format','classic')
ncwrite('AOD.nc','Year', year)
ncwriteatt('AOD.nc','Year','long_name','Year')
nccreate('AOD.nc','lat','Dimensions',{'lat',96},'Format','classic')
ncwrite('AOD.nc','lat', lat)
ncwriteatt('AOD.nc','lat','units','degrees_north')
ncwriteatt('AOD.nc','lat','long_name','Latitude')
nccreate('AOD.nc','lon','Dimensions',{'lon',144},'Format','classic')
ncwrite('AOD.nc','lon', lon)
ncwriteatt('AOD.nc','lon','units','degrees_east')
ncwriteatt('AOD.nc','lon','long_name','Longitude')
nccreate('AOD.nc','AOD_ANN','Dimensions',{'lon',144,'lat',96,'year',length(year)},'Format','classic')
ncwrite('AOD.nc','AOD_ANN', AOD_ANN)
nccreate('AOD.nc','AOD_DJF','Dimensions',{'lon',144,'lat',96,'year',length(year)},'Format','classic')
ncwrite('AOD.nc','AOD_DJF', AOD_DJF)
nccreate('AOD.nc','AOD_MAM','Dimensions',{'lon',144,'lat',96,'year',length(year)},'Format','classic')
ncwrite('AOD.nc','AOD_MAM', AOD_MAM)
nccreate('AOD.nc','AOD_JJA','Dimensions',{'lon',144,'lat',96,'year',length(year)},'Format','classic')
ncwrite('AOD.nc','AOD_JJA', AOD_JJA)
nccreate('AOD.nc','AOD_SON','Dimensions',{'lon',144,'lat',96,'year',length(year)},'Format','classic')
ncwrite('AOD.nc','AOD_SON', AOD_SON)
nccreate('AOD.nc','AOD_JAN','Dimensions',{'lon',144,'lat',96,'year',length(year)},'Format','classic')
ncwrite('AOD.nc','AOD_JAN', AOD_JAN)
nccreate('AOD.nc','AOD_JUL','Dimensions',{'lon',144,'lat',96,'year',length(year)},'Format','classic')
ncwrite('AOD.nc','AOD_JUL', AOD_JUL)
ncdisp('AOD.nc')