lon=ncread('/Users/yangyang/Aerosol_Variaiton/IRUN/U10/dat/uwnd.10m.gauss.2001.nc','lon');
lat=ncread('/Users/yangyang/Aerosol_Variaiton/IRUN/U10/dat/uwnd.10m.gauss.2001.nc','lat');
year=1:14;
month=1:168;
yearreal=2001:2014;

U10_MONTH=zeros(length(lon),length(lat),length(month));
U10_temp=zeros(length(lon),length(lat),12,length(year));

for yearID=1:length(year)
    utemp=ncread(['/Users/yangyang/Aerosol_Variaiton/IRUN/U10/dat/uwnd.10m.gauss.',num2str(yearreal(yearID)),'.nc'],'uwnd');
    vtemp=ncread(['/Users/yangyang/Aerosol_Variaiton/IRUN/U10/dat/vwnd.10m.gauss.',num2str(yearreal(yearID)),'.nc'],'vwnd');
    for monthID=1:12
        U10_temp(:,:,1,yearID)=sqrt((mean(utemp(:,:,1:31),3)).^2+(mean(vtemp(:,:,1:31),3)).^2);
        U10_temp(:,:,2,yearID)=sqrt((mean(utemp(:,:,32:59),3)).^2+(mean(vtemp(:,:,32:59),3)).^2);
        U10_temp(:,:,3,yearID)=sqrt((mean(utemp(:,:,60:90),3)).^2+(mean(vtemp(:,:,60:90),3)).^2);
        U10_temp(:,:,4,yearID)=sqrt((mean(utemp(:,:,91:120),3)).^2+(mean(vtemp(:,:,91:120),3)).^2);
        U10_temp(:,:,5,yearID)=sqrt((mean(utemp(:,:,121:151),3)).^2+(mean(vtemp(:,:,121:151),3)).^2);
        U10_temp(:,:,6,yearID)=sqrt((mean(utemp(:,:,152:181),3)).^2+(mean(vtemp(:,:,152:181),3)).^2);
        U10_temp(:,:,7,yearID)=sqrt((mean(utemp(:,:,182:212),3)).^2+(mean(vtemp(:,:,182:212),3)).^2);
        U10_temp(:,:,8,yearID)=sqrt((mean(utemp(:,:,213:243),3)).^2+(mean(vtemp(:,:,213:243),3)).^2);
        U10_temp(:,:,9,yearID)=sqrt((mean(utemp(:,:,244:273),3)).^2+(mean(vtemp(:,:,244:273),3)).^2);
        U10_temp(:,:,10,yearID)=sqrt((mean(utemp(:,:,274:304),3)).^2+(mean(vtemp(:,:,274:304),3)).^2);
        U10_temp(:,:,11,yearID)=sqrt((mean(utemp(:,:,305:334),3)).^2+(mean(vtemp(:,:,305:334),3)).^2);
        U10_temp(:,:,12,yearID)=sqrt((mean(utemp(:,:,335:365),3)).^2+(mean(vtemp(:,:,335:365),3)).^2);
    end
end
    
U10_ANN=zeros(length(lon),length(lat),length(year));      
U10_ANN(:,:,:)=mean(U10_temp,3);




save('U10_NCEP.mat','U10_ANN')

nccreate('U10_NCEP.nc','lat','Dimensions',{'lat',length(lat)},'Format','classic')
ncwrite('U10_NCEP.nc','lat', lat)
ncwriteatt('U10_NCEP.nc','lat','units','degrees_north')
ncwriteatt('U10_NCEP.nc','lat','long_name','Latitude')
nccreate('U10_NCEP.nc','lon','Dimensions',{'lon',length(lon)},'Format','classic')
ncwrite('U10_NCEP.nc','lon', lon)
ncwriteatt('U10_NCEP.nc','lon','units','degrees_east')
ncwriteatt('U10_NCEP.nc','lon','long_name','Longitude')
nccreate('U10_NCEP.nc','U10_ANN','Dimensions',{'lon',length(lon),'lat',length(lat),'year',length(year)},'Format','classic')
ncwrite('U10_NCEP.nc','U10_ANN', U10_ANN)
ncdisp('U10_NCEP.nc')