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

WIND_year=ncread('/Users/yangyang/Aerosol_Variaiton/IRUN/WIND/ncfile/WIND_10th.nc','WIND_year');
DUST=ncread('/Users/yangyang/Aerosol_Variaiton/IRUN/DUST/ncfile/DUST.nc','DUST_DJF');

DUST_ECHINA=zeros(length(year),1);
DUST_ECHINA(:)=mean(mean(DUST(45:50,60:72,:),2),1);

a=sum(WIND_year);

DUST_weak_temp_IRUN=zeros(144,96,a);
DUST_ECHINA_weak=0;
n=0;
for yearID=1:length(year)
    if WIND_year(yearID)==1
        n=n+1;
        DUST_weak_temp_IRUN(:,:,n)=DUST(:,:,yearID);
        DUST_ECHINA_weak=DUST_ECHINA_weak+DUST_ECHINA(yearID)/sum(WIND_year);
    end
end
DUST_weak=mean(DUST_weak_temp_IRUN,3);


DUST_aveg=mean(DUST,3);
DUST_diff_IRUN=DUST_weak-DUST_aveg;

DUST_ECHINA_aveg=mean(DUST_ECHINA);
DUST_ECHINA_diff_IRUN=DUST_ECHINA_weak-DUST_ECHINA_aveg;




WIND_year=ncread('/Users/yangyang/Aerosol_Variaiton/DRUN/WIND/ncfile/WIND_10th.nc','WIND_year');
DUST=ncread('/Users/yangyang/Aerosol_Variaiton/DRUN/DUST/ncfile/DUST.nc','DUST_DJF');

DUST_ECHINA=zeros(length(year),1);
DUST_ECHINA(:)=mean(mean(DUST(45:50,60:72,:),2),1);

b=sum(WIND_year);
DUST_weak_temp_DRUN=zeros(144,96,b);
DUST_ECHINA_weak=0;
n=0;
for yearID=1:length(year)
    if WIND_year(yearID)==1
        n=n+1;
        DUST_weak_temp_DRUN(:,:,n)=DUST(:,:,yearID);
        DUST_ECHINA_weak=DUST_ECHINA_weak+DUST_ECHINA(yearID)/sum(WIND_year);
    end
end
DUST_weak=mean(DUST_weak_temp_DRUN,3);


DUST_aveg=mean(DUST,3);
DUST_diff_DRUN=DUST_weak-DUST_aveg;

DUST_ECHINA_aveg=mean(DUST_ECHINA);
DUST_ECHINA_diff_DRUN=DUST_ECHINA_weak-DUST_ECHINA_aveg;


DUST_weak_temp_IRUN(isnan(DUST_weak_temp_IRUN))=-999;
DUST_weak_temp_DRUN(isnan(DUST_weak_temp_DRUN))=-999;

VAR_weak_IRUN=zeros(a,1);
VAR_weak_DRUN=zeros(b,1);
H=zeros(length(lon),length(lat));
for i=1:length(lon)
    for j=1:length(lat)
        VAR_weak_IRUN(:)=DUST_weak_temp_IRUN(i,j,:);
        VAR_weak_DRUN(:)=DUST_weak_temp_DRUN(i,j,:);
        [~,H(i,j)]=ranksum(VAR_weak_IRUN,VAR_weak_DRUN,'alpha',0.05);
    end
end

DUST_diff_IRUN_DRUN=DUST_diff_IRUN-DUST_diff_DRUN;



save('DUST_10th_IRUN_DRUN.mat','DUST_diff_IRUN_DRUN')

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