load ~/NC/grid
year=1:150;

PRECC_temp=ncread('~/Aerosol_Variaiton/IRUN/read_nc/ncfile/read_nc_PREC.nc','PRECC');
PRECL_temp=ncread('~/Aerosol_Variaiton/IRUN/read_nc/ncfile/read_nc_PREC.nc','PRECL');
PRECT_temp=PRECC_temp+PRECL_temp;

PRECT_ANN=zeros(144,96,150);
PRECT_DJF=zeros(144,96,150);
PRECT_JJA=zeros(144,96,150);

PRECT_ANN(:,:,:)=mean(PRECT_temp,3);
PRECT_JJA(:,:,:)=mean(PRECT_temp(:,:,[6,7,8],:),3);
PRECT_DJF(:,:,1)=mean(PRECT_temp(:,:,[1,2],1),3);
for yearID=2:150
    PRECT_DJF(:,:,yearID)=(PRECT_temp(:,:,12,yearID-1)+PRECT_temp(:,:,1,yearID)+PRECT_temp(:,:,2,yearID))/3;
end


save('PRECT.mat','PRECT_ANN','PRECT_DJF','PRECT_JJA')

nccreate('PRECT.nc','Year','Dimensions',{'time',Inf},'Format','classic')
ncwrite('PRECT.nc','Year', year)
ncwriteatt('PRECT.nc','Year','long_name','Year')
nccreate('PRECT.nc','lat','Dimensions',{'lat',96},'Format','classic')
ncwrite('PRECT.nc','lat', lat)
ncwriteatt('PRECT.nc','lat','units','degrees_north')
ncwriteatt('PRECT.nc','lat','long_name','Latitude')
nccreate('PRECT.nc','lon','Dimensions',{'lon',144},'Format','classic')
ncwrite('PRECT.nc','lon', lon)
ncwriteatt('PRECT.nc','lon','units','degrees_east')
ncwriteatt('PRECT.nc','lon','long_name','Longitude')
nccreate('PRECT.nc','PRECT_ANN','Dimensions',{'lon',144,'lat',96,'year',length(year)},'Format','classic')
ncwrite('PRECT.nc','PRECT_ANN', PRECT_ANN)
nccreate('PRECT.nc','PRECT_DJF','Dimensions',{'lon',144,'lat',96,'year',length(year)},'Format','classic')
ncwrite('PRECT.nc','PRECT_DJF', PRECT_DJF)
nccreate('PRECT.nc','PRECT_JJA','Dimensions',{'lon',144,'lat',96,'year',length(year)},'Format','classic')
ncwrite('PRECT.nc','PRECT_JJA', PRECT_JJA)
ncdisp('PRECT.nc')