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

UWND_temp=ncread('~/Aerosol_Variaiton/IRUN/read_nc/ncfile/read_nc_UWND.nc','UWND');

UWND_ANN=zeros(144,96,150);
UWND_ANN(:,:,:)=mean(UWND_temp,3);

UWND_JJA=zeros(144,96,150);
UWND_JJA(:,:,:)=mean(UWND_temp(:,:,6:8,:),3);

UWND_DJF=zeros(144,96,150);
UWND_DJF(:,:,1)=(UWND_temp(:,:,1,1)+UWND_temp(:,:,2,1))/2;
for yearID=2:length(year)
    UWND_DJF(:,:,yearID)=(UWND_temp(:,:,12,yearID-1)+UWND_temp(:,:,1,yearID)+UWND_temp(:,:,2,yearID))/3;
end

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


save('UWND.mat','UWND_ANN','UWND_GLOBAL_ANN','UWND_JJA','UWND_DJF')

nccreate('UWND.nc','Year','Dimensions',{'time',Inf},'Format','classic')
ncwrite('UWND.nc','Year', year)
ncwriteatt('UWND.nc','Year','long_name','Year')
nccreate('UWND.nc','lat','Dimensions',{'lat',96},'Format','classic')
ncwrite('UWND.nc','lat', lat)
ncwriteatt('UWND.nc','lat','units','degrees_north')
ncwriteatt('UWND.nc','lat','long_name','Latitude')
nccreate('UWND.nc','lon','Dimensions',{'lon',144},'Format','classic')
ncwrite('UWND.nc','lon', lon)
ncwriteatt('UWND.nc','lon','units','degrees_east')
ncwriteatt('UWND.nc','lon','long_name','Longitude')
nccreate('UWND.nc','UWND_ANN','Dimensions',{'lon',144,'lat',96,'year',length(year)},'Format','classic')
ncwrite('UWND.nc','UWND_ANN', UWND_ANN)
nccreate('UWND.nc','UWND_JJA','Dimensions',{'lon',144,'lat',96,'year',length(year)},'Format','classic')
ncwrite('UWND.nc','UWND_JJA', UWND_JJA)
nccreate('UWND.nc','UWND_DJF','Dimensions',{'lon',144,'lat',96,'year',length(year)},'Format','classic')
ncwrite('UWND.nc','UWND_DJF', UWND_DJF)
nccreate('UWND.nc','UWND_GLOBAL_ANN','Dimensions',{'year',length(year)},'Format','classic')
ncwrite('UWND.nc','UWND_GLOBAL_ANN', UWND_GLOBAL_ANN)
ncdisp('UWND.nc')