load ~/NC/grid.mat
load ~/Aerosol_Variaiton/DRUN/SST/ncfile/ENSO_Season.mat
load ~/Aerosol_Variaiton/DRUN/DUST/ncfile/DUST.mat
year=1:150;

a=sum(EN_SON);
b=sum(LL_SON);

DUST_EN_SON=zeros(144,96,a);
DUST_LL_SON=zeros(144,96,b);

n=0;
m=0;
for yearID=1:length(year)
    if EN_SON(yearID)==1
        n=n+1;
        DUST_EN_SON(:,:,n)=DUST_SON(:,:,yearID);
    end
    if LL_SON(yearID)==1
        m=m+1;
        DUST_LL_SON(:,:,m)=DUST_SON(:,:,yearID);
    end
end

DUST_EN=mean(DUST_EN_SON,3);
DUST_LL=mean(DUST_LL_SON,3);

DUST_ENSO=DUST_EN-DUST_LL;

save('DUST_ENSO_composite_monthly_SON.mat','DUST_EN','DUST_LL','DUST_ENSO')

nccreate('DUST_ENSO_composite_monthly_SON.nc','lat','Dimensions',{'lat',96},'Format','classic')
ncwrite('DUST_ENSO_composite_monthly_SON.nc','lat', lat)
ncwriteatt('DUST_ENSO_composite_monthly_SON.nc','lat','units','degrees_north')
ncwriteatt('DUST_ENSO_composite_monthly_SON.nc','lat','long_name','Latitude')
nccreate('DUST_ENSO_composite_monthly_SON.nc','lon','Dimensions',{'lon',144},'Format','classic')
ncwrite('DUST_ENSO_composite_monthly_SON.nc','lon', lon)
ncwriteatt('DUST_ENSO_composite_monthly_SON.nc','lon','units','degrees_east')
ncwriteatt('DUST_ENSO_composite_monthly_SON.nc','lon','long_name','Longitude')
nccreate('DUST_ENSO_composite_monthly_SON.nc','DUST_EN','Dimensions',{'lon',144,'lat',96},'Format','classic')
ncwrite('DUST_ENSO_composite_monthly_SON.nc','DUST_EN', DUST_EN)
nccreate('DUST_ENSO_composite_monthly_SON.nc','DUST_LL','Dimensions',{'lon',144,'lat',96},'Format','classic')
ncwrite('DUST_ENSO_composite_monthly_SON.nc','DUST_LL', DUST_LL)
nccreate('DUST_ENSO_composite_monthly_SON.nc','DUST_ENSO','Dimensions',{'lon',144,'lat',96},'Format','classic')
ncwrite('DUST_ENSO_composite_monthly_SON.nc','DUST_ENSO', DUST_ENSO)
ncdisp('DUST_ENSO_composite_monthly_SON.nc')
