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);
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_12.mat','UWND_ANN','UWND_GLOBAL_ANN','UWND_JJA','UWND_DJF')

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