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;

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_DJF=zeros(length(lon),length(lat),length(year));
VWND_DJF=zeros(length(lon),length(lat),length(year));

n=1;
for yearID=1:length(year)
    UWND_DJF(:,:,yearID)=(u(:,:,n)+u(:,:,n+1)+u(:,:,n+2))/3;
    VWND_DJF(:,:,yearID)=(v(:,:,n)+v(:,:,n+1)+v(:,:,n+2))/3;
    n=n+3;
end


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

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