load ~/NC/grid.mat
load ~/Aerosol_Variaiton/IRUN/EASMI/ncfile/EASM_Year.mat
load ~/Aerosol_Variaiton/IRUN/DUST/ncfile/DUST.mat
year=1:150;

a=sum(Strong_Year);
b=sum(Weak_Year);

DUST_strong_year=zeros(144,96,a);
DUST_weak_year=zeros(144,96,b);

n=0;
m=0;
for yearID=1:length(year)
    if Strong_Year(yearID)==1
        n=n+1;
        DUST_strong_year(:,:,n)=DUST_JJA(:,:,yearID);
    end
    if Weak_Year(yearID)==1
        m=m+1;
        DUST_weak_year(:,:,m)=DUST_JJA(:,:,yearID);
    end
end

DUST_strong=mean(DUST_strong_year,3);
DUST_weak=mean(DUST_weak_year,3);

DUST_EASM=DUST_strong-DUST_weak;

DUST_strong_year(isnan(DUST_strong_year))=-999;
DUST_weak_year(isnan(DUST_weak_year))=-999;

VAR_strong=zeros(a,1);
VAR_weak=zeros(b,1);
H=zeros(length(lon),length(lat));
for i=1:length(lon)
    for j=1:length(lat)
        VAR_strong(:)=DUST_strong_year(i,j,:);
        VAR_weak(:)=DUST_weak_year(i,j,:);
        [~,H(i,j)]=ranksum(VAR_strong,VAR_weak,'alpha',0.05);
    end
end


save('DUST_EASM_composite.mat','DUST_strong','DUST_weak','DUST_EASM')

nccreate('DUST_EASM_composite.nc','lat','Dimensions',{'lat',96},'Format','classic')
ncwrite('DUST_EASM_composite.nc','lat', lat)
ncwriteatt('DUST_EASM_composite.nc','lat','units','degrees_north')
ncwriteatt('DUST_EASM_composite.nc','lat','long_name','Latitude')
nccreate('DUST_EASM_composite.nc','lon','Dimensions',{'lon',144},'Format','classic')
ncwrite('DUST_EASM_composite.nc','lon', lon)
ncwriteatt('DUST_EASM_composite.nc','lon','units','degrees_east')
ncwriteatt('DUST_EASM_composite.nc','lon','long_name','Longitude')
nccreate('DUST_EASM_composite.nc','DUST_strong','Dimensions',{'lon',144,'lat',96},'Format','classic')
ncwrite('DUST_EASM_composite.nc','DUST_strong', DUST_strong)
nccreate('DUST_EASM_composite.nc','DUST_weak','Dimensions',{'lon',144,'lat',96},'Format','classic')
ncwrite('DUST_EASM_composite.nc','DUST_weak', DUST_weak)
nccreate('DUST_EASM_composite.nc','DUST_EASM','Dimensions',{'lon',144,'lat',96},'Format','classic')
ncwrite('DUST_EASM_composite.nc','DUST_EASM', DUST_EASM)
nccreate('DUST_EASM_composite.nc','H','Dimensions',{'lon',144,'lat',96},'Format','classic')
ncwrite('DUST_EASM_composite.nc','H', H)
ncdisp('DUST_EASM_composite.nc')
