load ~/NC/grid
load ~/NC/area_1.9_2.5.mat
year=1:150;

U10_temp=ncread('~/Aerosol_Variaiton/IRUN/read_nc/ncfile/read_nc_U10.nc','U10');

U10_ANN=zeros(144,96,150);
U10_SON=zeros(144,96,150);

U10_ANN(:,:,:)=mean(U10_temp,3);
U10_SON(:,:,:)=mean(U10_temp(:,:,9:11,:),3);

U10_GLOBAL_ANN=zeros(150,1);
for yearID=1:150
    U10_GLOBAL_ANN(yearID)=sum(sum(U10_ANN(:,:,yearID).*area,2),1)/sum(area(:));
end


save('U10.mat','U10_ANN','U10_GLOBAL_ANN','U10_SON')

nccreate('U10.nc','Year','Dimensions',{'time',Inf},'Format','classic')
ncwrite('U10.nc','Year', year)
ncwriteatt('U10.nc','Year','long_name','Year')
nccreate('U10.nc','lat','Dimensions',{'lat',96},'Format','classic')
ncwrite('U10.nc','lat', lat)
ncwriteatt('U10.nc','lat','units','degrees_north')
ncwriteatt('U10.nc','lat','long_name','Latitude')
nccreate('U10.nc','lon','Dimensions',{'lon',144},'Format','classic')
ncwrite('U10.nc','lon', lon)
ncwriteatt('U10.nc','lon','units','degrees_east')
ncwriteatt('U10.nc','lon','long_name','Longitude')
nccreate('U10.nc','U10_ANN','Dimensions',{'lon',144,'lat',96,'year',length(year)},'Format','classic')
ncwrite('U10.nc','U10_ANN', U10_ANN)
nccreate('U10.nc','U10_SON','Dimensions',{'lon',144,'lat',96,'year',length(year)},'Format','classic')
ncwrite('U10.nc','U10_SON', U10_SON)
nccreate('U10.nc','U10_GLOBAL_ANN','Dimensions',{'year',length(year)},'Format','classic')
ncwrite('U10.nc','U10_GLOBAL_ANN', U10_GLOBAL_ANN)
ncdisp('U10.nc')