lon_ECMWF=ncread('/Users/yangyang/Aerosol_Variaiton/MODIS/dat/WIND_ECMWF.nc','longitude');
lat_ECMWF=ncread('/Users/yangyang/Aerosol_Variaiton/MODIS/dat/WIND_ECMWF.nc','latitude');
lat=-89.5:1:89.5;
lon=-179.5:1:179.5;
year=1:14;
month=1:168;

UWND_ECMWF_temp=ncread('/Users/yangyang/Aerosol_Variaiton/MODIS/dat/WIND_ECMWF.nc','u');
temp=UWND_ECMWF_temp(1:180,:,:);
UWND_ECMWF_temp2(1:180,:,:)=UWND_ECMWF_temp(181:360,:,:);
UWND_ECMWF_temp2(181:360,:,:)=temp;
UWND_ECMWF_temp2(:,1:181,:)=UWND_ECMWF_temp2(:,181:-1:1,:);

UWND_ECMWF=zeros(length(lon),length(lat),length(month));
for j=1:180
    UWND_ECMWF(:,j,:)=(UWND_ECMWF_temp2(:,j,:)+UWND_ECMWF_temp2(:,j+1,:))/2;
end

UWND_temp=zeros(length(lon),length(lat),12,length(year));

n=0;
for yearID=1:length(year)
    for monthID=1:12
        n=n+1;
        UWND_temp(:,:,monthID,yearID)=UWND_ECMWF(:,:,n);
    end
end
        
UWND_DJF=zeros(length(lon),length(lat),length(year));
UWND_DJF(:,:,1)=mean(UWND_temp(:,:,[1,2],1),3);
for yearID=2:length(year)
    UWND_DJF(:,:,yearID)=(UWND_temp(:,:,12,yearID-1)+UWND_temp(:,:,1,yearID)+UWND_temp(:,:,2,yearID))/3;
end


VWND_ECMWF_temp=ncread('/Users/yangyang/Aerosol_Variaiton/MODIS/dat/WIND_ECMWF.nc','v');
temp=VWND_ECMWF_temp(1:180,:,:);
VWND_ECMWF_temp2(1:180,:,:)=VWND_ECMWF_temp(181:360,:,:);
VWND_ECMWF_temp2(181:360,:,:)=temp;
VWND_ECMWF_temp2(:,1:181,:)=VWND_ECMWF_temp2(:,181:-1:1,:);

VWND_ECMWF=zeros(length(lon),length(lat),length(month));
for j=1:180
    VWND_ECMWF(:,j,:)=(VWND_ECMWF_temp2(:,j,:)+VWND_ECMWF_temp2(:,j+1,:))/2;
end

VWND_temp=zeros(length(lon),length(lat),12,length(year));

n=0;
for yearID=1:length(year)
    for monthID=1:12
        n=n+1;
        VWND_temp(:,:,monthID,yearID)=VWND_ECMWF(:,:,n);
    end
end
        
VWND_DJF=zeros(length(lon),length(lat),length(year));
VWND_DJF(:,:,1)=mean(VWND_temp(:,:,[1,2],1),3);
for yearID=2:length(year)
    VWND_DJF(:,:,yearID)=(VWND_temp(:,:,12,yearID-1)+VWND_temp(:,:,1,yearID)+VWND_temp(:,:,2,yearID))/3;
end

WIND_DJF=sqrt(UWND_DJF.*UWND_DJF+VWND_DJF.*VWND_DJF);

save('WIND_ECMWF.mat','WIND_DJF','UWND_DJF','VWND_DJF')

nccreate('WIND_ECMWF.nc','Year','Dimensions',{'time',Inf},'Format','classic')
ncwrite('WIND_ECMWF.nc','Year', year)
nccreate('WIND_ECMWF.nc','lat','Dimensions',{'lat',length(lat)},'Format','classic')
ncwrite('WIND_ECMWF.nc','lat', lat)
ncwriteatt('WIND_ECMWF.nc','lat','units','degrees_north')
ncwriteatt('WIND_ECMWF.nc','lat','long_name','Latitude')
nccreate('WIND_ECMWF.nc','lon','Dimensions',{'lon',length(lon)},'Format','classic')
ncwrite('WIND_ECMWF.nc','lon', lon)
ncwriteatt('WIND_ECMWF.nc','lon','units','degrees_east')
ncwriteatt('WIND_ECMWF.nc','lon','long_name','Longitude')
nccreate('WIND_ECMWF.nc','WIND_DJF','Dimensions',{'lon',length(lon),'lat',length(lat),'year',length(year)},'Format','classic')
ncwrite('WIND_ECMWF.nc','WIND_DJF', WIND_DJF)
nccreate('WIND_ECMWF.nc','UWND_DJF','Dimensions',{'lon',length(lon),'lat',length(lat),'year',length(year)},'Format','classic')
ncwrite('WIND_ECMWF.nc','UWND_DJF', UWND_DJF)
nccreate('WIND_ECMWF.nc','VWND_DJF','Dimensions',{'lon',length(lon),'lat',length(lat),'year',length(year)},'Format','classic')
ncwrite('WIND_ECMWF.nc','VWND_DJF', VWND_DJF)
ncdisp('WIND_ECMWF.nc')