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

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

DUSTSF_EN_SON=zeros(144,96,a);
DUSTSF_LL_SON=zeros(144,96,b);

n=0;
m=0;
for yearID=1:length(year)
    if EN_SON(yearID)==1
        n=n+1;
        DUSTSF_EN_SON(:,:,n)=DUSTSF_SON(:,:,yearID);
    end
    if LL_SON(yearID)==1
        m=m+1;
        DUSTSF_LL_SON(:,:,m)=DUSTSF_SON(:,:,yearID);
    end
end

DUSTSF_EN=mean(DUSTSF_EN_SON,3);
DUSTSF_LL=mean(DUSTSF_LL_SON,3);

DUSTSF_ENSO=DUSTSF_EN-DUSTSF_LL;

save('DUSTSF_ENSO_composite_monthly_SON.mat','DUSTSF_EN','DUSTSF_LL','DUSTSF_ENSO')

nccreate('DUSTSF_ENSO_composite_monthly_SON.nc','lat','Dimensions',{'lat',96},'Format','classic')
ncwrite('DUSTSF_ENSO_composite_monthly_SON.nc','lat', lat)
ncwriteatt('DUSTSF_ENSO_composite_monthly_SON.nc','lat','units','degrees_north')
ncwriteatt('DUSTSF_ENSO_composite_monthly_SON.nc','lat','long_name','Latitude')
nccreate('DUSTSF_ENSO_composite_monthly_SON.nc','lon','Dimensions',{'lon',144},'Format','classic')
ncwrite('DUSTSF_ENSO_composite_monthly_SON.nc','lon', lon)
ncwriteatt('DUSTSF_ENSO_composite_monthly_SON.nc','lon','units','degrees_east')
ncwriteatt('DUSTSF_ENSO_composite_monthly_SON.nc','lon','long_name','Longitude')
nccreate('DUSTSF_ENSO_composite_monthly_SON.nc','DUSTSF_EN','Dimensions',{'lon',144,'lat',96},'Format','classic')
ncwrite('DUSTSF_ENSO_composite_monthly_SON.nc','DUSTSF_EN', DUSTSF_EN)
nccreate('DUSTSF_ENSO_composite_monthly_SON.nc','DUSTSF_LL','Dimensions',{'lon',144,'lat',96},'Format','classic')
ncwrite('DUSTSF_ENSO_composite_monthly_SON.nc','DUSTSF_LL', DUSTSF_LL)
nccreate('DUSTSF_ENSO_composite_monthly_SON.nc','DUSTSF_ENSO','Dimensions',{'lon',144,'lat',96},'Format','classic')
ncwrite('DUSTSF_ENSO_composite_monthly_SON.nc','DUSTSF_ENSO', DUSTSF_ENSO)
ncdisp('DUSTSF_ENSO_composite_monthly_SON.nc')
