load ~/NC/grid
year=1:150;
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);

DUST_ECHINA_33threshold=prctile(DUST_ECHINA,33);
DUST_ECHINA_67threshold=prctile(DUST_ECHINA,67);

DUST_33th=zeros(length(lon),length(lat));
DUST_67th=zeros(length(lon),length(lat));
DUST_ECHINA_33th=0;
DUST_ECHINA_67th=0;
DUST_year_33th=zeros(150,1);
DUST_year_67th=zeros(150,1);
for yearID=1:length(year)
    if DUST_ECHINA(yearID)<DUST_ECHINA_33threshold
        DUST_year_33th(yearID)=1;
        DUST_33th=DUST_33th+DUST(:,:,yearID)/49;
        DUST_ECHINA_33th=DUST_ECHINA_33th+DUST_ECHINA(yearID)/49;
    end
    if DUST_ECHINA(yearID)>DUST_ECHINA_67threshold
        DUST_year_67th(yearID)=1;
        DUST_67th=DUST_67th+DUST(:,:,yearID)/49;
        DUST_ECHINA_67th=DUST_ECHINA_67th+DUST_ECHINA(yearID)/49;
    end
end

DUST_diff=DUST_33th-DUST_67th;
DUST_ECHINA_diff=DUST_ECHINA_33th-DUST_ECHINA_67th;

save('DUST_33th_67th.mat','DUST_year_33th','DUST_year_67th','DUST_33th','DUST_67th','DUST_diff')

nccreate('DUST_33th_67th.nc','lat','Dimensions',{'lat',96},'Format','classic')
ncwrite('DUST_33th_67th.nc','lat', lat)
ncwriteatt('DUST_33th_67th.nc','lat','units','degrees_north')
ncwriteatt('DUST_33th_67th.nc','lat','long_name','Latitude')
nccreate('DUST_33th_67th.nc','lon','Dimensions',{'lon',144},'Format','classic')
ncwrite('DUST_33th_67th.nc','lon', lon)
ncwriteatt('DUST_33th_67th.nc','lon','units','degrees_east')
ncwriteatt('DUST_33th_67th.nc','lon','long_name','Longitude')
nccreate('DUST_33th_67th.nc','DUST_year_33th','Dimensions',{'year',length(year)},'Format','classic')
ncwrite('DUST_33th_67th.nc','DUST_year_33th', DUST_year_33th)
nccreate('DUST_33th_67th.nc','DUST_year_67th','Dimensions',{'year',length(year)},'Format','classic')
ncwrite('DUST_33th_67th.nc','DUST_year_67th', DUST_year_67th)
nccreate('DUST_33th_67th.nc','DUST_33th','Dimensions',{'lon',144,'lat',96},'Format','classic')
ncwrite('DUST_33th_67th.nc','DUST_33th', DUST_33th)
nccreate('DUST_33th_67th.nc','DUST_67th','Dimensions',{'lon',144,'lat',96},'Format','classic')
ncwrite('DUST_33th_67th.nc','DUST_67th', DUST_67th)
nccreate('DUST_33th_67th.nc','DUST_diff','Dimensions',{'lon',144,'lat',96},'Format','classic')
ncwrite('DUST_33th_67th.nc','DUST_diff', DUST_diff)
ncdisp('DUST_33th_67th.nc')