lon=ncread('/Users/yangyang/Aerosol_Variaiton/IRUN/UWND/dat/wind850_ECMWF.nc','longitude');
lat=ncread('/Users/yangyang/Aerosol_Variaiton/IRUN/UWND/dat/wind850_ECMWF.nc','latitude');
year=1979:2014;

WIND=ncread('/Users/yangyang/Aerosol_Variaiton/IRUN/WIND/ncfile/WIND_ECMWF_1979_2014.nc','WIND_DJF');

WIND_ECHINA=zeros(length(year),1);
WIND_ECHINA(:)=mean(mean(WIND(111:123,46:71,:),2),1);

WIND_ECHINA_10th=prctile(WIND_ECHINA,10);

WIND_weak=zeros(length(lon),length(lat));
WIND_ECHINA_weak=0;
WIND_year=zeros(length(year),1);
for yearID=1:length(year)
    if WIND_ECHINA(yearID)<WIND_ECHINA_10th
        WIND_year(yearID)=1;
        WIND_weak=WIND_weak+WIND(:,:,yearID)/4;
        WIND_ECHINA_weak=WIND_ECHINA_weak+WIND_ECHINA(yearID)/4;
    end
end

WIND_aveg=mean(WIND,3);
WIND_diff=WIND_weak-WIND_aveg;

WIND_ECHINA_aveg=mean(WIND_ECHINA);
WIND_ECHINA_diff=WIND_ECHINA_weak-WIND_ECHINA_aveg;

save('WIND_ECMWF_10th_1979_2014.mat','WIND_year','WIND_weak','WIND_aveg','WIND_diff')

nccreate('WIND_ECMWF_10th_1979_2014.nc','lat','Dimensions',{'lat',length(lat)},'Format','classic')
ncwrite('WIND_ECMWF_10th_1979_2014.nc','lat', lat)
ncwriteatt('WIND_ECMWF_10th_1979_2014.nc','lat','units','degrees_north')
ncwriteatt('WIND_ECMWF_10th_1979_2014.nc','lat','long_name','Latitude')
nccreate('WIND_ECMWF_10th_1979_2014.nc','lon','Dimensions',{'lon',length(lon)},'Format','classic')
ncwrite('WIND_ECMWF_10th_1979_2014.nc','lon', lon)
ncwriteatt('WIND_ECMWF_10th_1979_2014.nc','lon','units','degrees_east')
ncwriteatt('WIND_ECMWF_10th_1979_2014.nc','lon','long_name','Longitude')
nccreate('WIND_ECMWF_10th_1979_2014.nc','WIND_year','Dimensions',{'year',length(year)},'Format','classic')
ncwrite('WIND_ECMWF_10th_1979_2014.nc','WIND_year', WIND_year)
nccreate('WIND_ECMWF_10th_1979_2014.nc','WIND_weak','Dimensions',{'lon',length(lon),'lat',length(lat)},'Format','classic')
ncwrite('WIND_ECMWF_10th_1979_2014.nc','WIND_weak', WIND_weak)
nccreate('WIND_ECMWF_10th_1979_2014.nc','WIND_aveg','Dimensions',{'lon',length(lon),'lat',length(lat)},'Format','classic')
ncwrite('WIND_ECMWF_10th_1979_2014.nc','WIND_aveg', WIND_aveg)
nccreate('WIND_ECMWF_10th_1979_2014.nc','WIND_diff','Dimensions',{'lon',length(lon),'lat',length(lat)},'Format','classic')
ncwrite('WIND_ECMWF_10th_1979_2014.nc','WIND_diff', WIND_diff)
ncdisp('WIND_ECMWF_10th_1979_2014.nc')