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

VWND_temp=ncread('~/Aerosol_Variaiton/DRUN/read_nc/ncfile/read_nc_VWND.nc','VWND');

VWND_ANN=zeros(144,96,150);
VWND_ANN(:,:,:)=mean(VWND_temp,3);

VWND_JJA=zeros(144,96,150);
VWND_JJA(:,:,:)=mean(VWND_temp(:,:,6:8,:),3);

VWND_DJF=zeros(144,96,150);
VWND_DJF(:,:,1)=(VWND_temp(:,:,1,1)+VWND_temp(:,:,2,1))/2;
for yearID=2:length(year)
    VWND_DJF(:,:,yearID)=VWND_temp(:,:,2,yearID);
end

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


save('VWND_02.mat','VWND_ANN','VWND_GLOBAL_ANN','VWND_JJA','VWND_DJF')

nccreate('VWND_02.nc','Year','Dimensions',{'time',Inf},'Format','classic')
ncwrite('VWND_02.nc','Year', year)
ncwriteatt('VWND_02.nc','Year','long_name','Year')
nccreate('VWND_02.nc','lat','Dimensions',{'lat',96},'Format','classic')
ncwrite('VWND_02.nc','lat', lat)
ncwriteatt('VWND_02.nc','lat','units','degrees_north')
ncwriteatt('VWND_02.nc','lat','long_name','Latitude')
nccreate('VWND_02.nc','lon','Dimensions',{'lon',144},'Format','classic')
ncwrite('VWND_02.nc','lon', lon)
ncwriteatt('VWND_02.nc','lon','units','degrees_east')
ncwriteatt('VWND_02.nc','lon','long_name','Longitude')
nccreate('VWND_02.nc','VWND_ANN','Dimensions',{'lon',144,'lat',96,'year',length(year)},'Format','classic')
ncwrite('VWND_02.nc','VWND_ANN', VWND_ANN)
nccreate('VWND_02.nc','VWND_JJA','Dimensions',{'lon',144,'lat',96,'year',length(year)},'Format','classic')
ncwrite('VWND_02.nc','VWND_JJA', VWND_JJA)
nccreate('VWND_02.nc','VWND_DJF','Dimensions',{'lon',144,'lat',96,'year',length(year)},'Format','classic')
ncwrite('VWND_02.nc','VWND_DJF', VWND_DJF)
nccreate('VWND_02.nc','VWND_GLOBAL_ANN','Dimensions',{'year',length(year)},'Format','classic')
ncwrite('VWND_02.nc','VWND_GLOBAL_ANN', VWND_GLOBAL_ANN)
ncdisp('VWND_02.nc')