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

DUST_temp=ncread('~/Aerosol_Variaiton/IRUN/read_nc/ncfile/read_nc_DUST.nc','DUST');

DUST_MAM=zeros(144,96,150);
DUST_JJA=zeros(144,96,150);
DUST_SON=zeros(144,96,150);
DUST_DJF=zeros(144,96,150);

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

DUST_MAM(:,:,:)=mean(DUST_temp(:,:,3:5,:),3);
DUST_JJA(:,:,:)=mean(DUST_temp(:,:,6:8,:),3);
DUST_SON(:,:,:)=mean(DUST_temp(:,:,9:11,:),3);

save('DUST.mat','DUST_DJF','DUST_MAM','DUST_JJA','DUST_SON')

nccreate('DUST.nc','Year','Dimensions',{'time',Inf},'Format','classic')
ncwrite('DUST.nc','Year', year)
ncwriteatt('DUST.nc','Year','long_name','Year')
nccreate('DUST.nc','lat','Dimensions',{'lat',96},'Format','classic')
ncwrite('DUST.nc','lat', lat)
ncwriteatt('DUST.nc','lat','units','degrees_north')
ncwriteatt('DUST.nc','lat','long_name','Latitude')
nccreate('DUST.nc','lon','Dimensions',{'lon',144},'Format','classic')
ncwrite('DUST.nc','lon', lon)
ncwriteatt('DUST.nc','lon','units','degrees_east')
ncwriteatt('DUST.nc','lon','long_name','Longitude')
nccreate('DUST.nc','DUST_DJF','Dimensions',{'lon',144,'lat',96,'year',length(year)},'Format','classic')
ncwrite('DUST.nc','DUST_DJF', DUST_DJF)
nccreate('DUST.nc','DUST_MAM','Dimensions',{'lon',144,'lat',96,'year',length(year)},'Format','classic')
ncwrite('DUST.nc','DUST_MAM', DUST_MAM)
nccreate('DUST.nc','DUST_JJA','Dimensions',{'lon',144,'lat',96,'year',length(year)},'Format','classic')
ncwrite('DUST.nc','DUST_JJA', DUST_JJA)
nccreate('DUST.nc','DUST_SON','Dimensions',{'lon',144,'lat',96,'year',length(year)},'Format','classic')
ncwrite('DUST.nc','DUST_SON', DUST_SON)
ncdisp('DUST.nc')