load ~/NC/grid.mat
load ~/Aerosol_Variaiton/IRUN/SST/ncfile/ENSO_Month.mat
load ~/Aerosol_Variaiton/IRUN/DUSTSF/ncfile/DUSTSF_monthly.mat
month=1:1800;

a=sum(EN_Month);
b=sum(LL_Month);

DUSTSF_EN_month=zeros(144,96,a);
DUSTSF_LL_month=zeros(144,96,b);

n=0;
m=0;
for monthID=1:length(month)
    if EN_Month(monthID)==1
        n=n+1;
        DUSTSF_EN_month(:,:,n)=DUSTSF_MONTH(:,:,monthID);
    end
    if LL_Month(monthID)==1
        m=m+1;
        DUSTSF_LL_month(:,:,m)=DUSTSF_MONTH(:,:,monthID);
    end
end

DUSTSF_EN=mean(DUSTSF_EN_month,3);
DUSTSF_LL=mean(DUSTSF_LL_month,3);

DUSTSF_ENSO=DUSTSF_EN-DUSTSF_LL;

%DUSTSF_ENSO(DUSTSF_ENSO==0)=-999;

VAR_EN=zeros(a,1);
VAR_LL=zeros(b,1);
H=zeros(length(lon),length(lat));
for i=1:length(lon)
    for j=1:length(lat)
        VAR_EN(:)=DUSTSF_EN_month(i,j,:);
        VAR_LL(:)=DUSTSF_LL_month(i,j,:);
        [~,H(i,j)]=ranksum(VAR_EN,VAR_LL);
    end
end

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

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