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=1985:2005;

u=ncread('/Users/yangyang/Extreme_Aerosol/Meteorology/WIND850/dat/wind850_ECMWF.nc','u');
v=ncread('/Users/yangyang/Extreme_Aerosol/Meteorology/WIND850/dat/wind850_ECMWF.nc','v');

uwnd_temp=zeros(length(lon),length(lat),36);
vwnd_temp=zeros(length(lon),length(lat),36);

n=1;
for yearID=1:36
    uwnd_temp(:,:,yearID)=(u(:,:,n)+u(:,:,n+1)+u(:,:,n+2))/3;
    vwnd_temp(:,:,yearID)=(v(:,:,n)+v(:,:,n+1)+v(:,:,n+2))/3;
    n=n+3;
end

UWND_DJF=uwnd_temp(:,:,7:27);
VWND_DJF=vwnd_temp(:,:,7:27);


save('UWND_ECMWF_1985_2005.mat','UWND_DJF')

nccreate('UWND_ECMWF_1985_2005.nc','Year','Dimensions',{'year',length(year)},'Format','netcdf4_classic')
ncwrite('UWND_ECMWF_1985_2005.nc','Year', year)
nccreate('UWND_ECMWF_1985_2005.nc','lat','Dimensions',{'lat',length(lat)},'Format','netcdf4_classic')
ncwrite('UWND_ECMWF_1985_2005.nc','lat', lat)
ncwriteatt('UWND_ECMWF_1985_2005.nc','lat','units','degrees_north')
ncwriteatt('UWND_ECMWF_1985_2005.nc','lat','long_name','Latitude')
nccreate('UWND_ECMWF_1985_2005.nc','lon','Dimensions',{'lon',length(lon)},'Format','netcdf4_classic')
ncwrite('UWND_ECMWF_1985_2005.nc','lon', lon)
ncwriteatt('UWND_ECMWF_1985_2005.nc','lon','units','degrees_east')
ncwriteatt('UWND_ECMWF_1985_2005.nc','lon','long_name','Longitude')
nccreate('UWND_ECMWF_1985_2005.nc','UWND_DJF','Dimensions',{'lon',length(lon),'lat',length(lat),'year',length(year)},'Format','netcdf4_classic')
ncwrite('UWND_ECMWF_1985_2005.nc','UWND_DJF', UWND_DJF)
ncdisp('UWND_ECMWF_1985_2005.nc')