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

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

PRECC_ANN=zeros(144,96,150);
PRECC_DJF=zeros(144,96,150);
PRECC_MAM=zeros(144,96,150);
PRECC_JJA=zeros(144,96,150);
PRECC_SON=zeros(144,96,150);
PRECC_JAN=zeros(144,96,150);
PRECC_JUL=zeros(144,96,150);

PRECC_ANN(:,:,:)=mean(PRECC_temp,3);
PRECC_MAM(:,:,:)=mean(PRECC_temp(:,:,[3,4,5],:),3);
PRECC_JJA(:,:,:)=mean(PRECC_temp(:,:,[6,7,8],:),3);
PRECC_SON(:,:,:)=mean(PRECC_temp(:,:,[9,10,11],:),3);
PRECC_DJF(:,:,1)=mean(PRECC_temp(:,:,[1,2],1),3);
for yearID=2:150
    PRECC_DJF(:,:,yearID)=(PRECC_temp(:,:,12,yearID-1)+PRECC_temp(:,:,1,yearID)+PRECC_temp(:,:,2,yearID))/3;
end
PRECC_JAN(:,:,:)=PRECC_temp(:,:,1,:);
PRECC_JUL(:,:,:)=PRECC_temp(:,:,7,:);
PRECC_MONTH=PRECC_temp;

save('PRECC.mat','PRECC_ANN','PRECC_DJF','PRECC_MAM','PRECC_JJA','PRECC_SON','PRECC_JAN','PRECC_JUL','PRECC_MONTH')

nccreate('PRECC.nc','Year','Dimensions',{'time',Inf},'Format','classic')
ncwrite('PRECC.nc','Year', year)
ncwriteatt('PRECC.nc','Year','long_name','Year')
nccreate('PRECC.nc','lat','Dimensions',{'lat',96},'Format','classic')
ncwrite('PRECC.nc','lat', lat)
ncwriteatt('PRECC.nc','lat','units','degrees_north')
ncwriteatt('PRECC.nc','lat','long_name','Latitude')
nccreate('PRECC.nc','lon','Dimensions',{'lon',144},'Format','classic')
ncwrite('PRECC.nc','lon', lon)
ncwriteatt('PRECC.nc','lon','units','degrees_east')
ncwriteatt('PRECC.nc','lon','long_name','Longitude')
nccreate('PRECC.nc','PRECC_ANN','Dimensions',{'lon',144,'lat',96,'year',length(year)},'Format','classic')
ncwrite('PRECC.nc','PRECC_ANN', PRECC_ANN)
nccreate('PRECC.nc','PRECC_DJF','Dimensions',{'lon',144,'lat',96,'year',length(year)},'Format','classic')
ncwrite('PRECC.nc','PRECC_DJF', PRECC_DJF)
nccreate('PRECC.nc','PRECC_MAM','Dimensions',{'lon',144,'lat',96,'year',length(year)},'Format','classic')
ncwrite('PRECC.nc','PRECC_MAM', PRECC_MAM)
nccreate('PRECC.nc','PRECC_JJA','Dimensions',{'lon',144,'lat',96,'year',length(year)},'Format','classic')
ncwrite('PRECC.nc','PRECC_JJA', PRECC_JJA)
nccreate('PRECC.nc','PRECC_SON','Dimensions',{'lon',144,'lat',96,'year',length(year)},'Format','classic')
ncwrite('PRECC.nc','PRECC_SON', PRECC_SON)
nccreate('PRECC.nc','PRECC_JAN','Dimensions',{'lon',144,'lat',96,'year',length(year)},'Format','classic')
ncwrite('PRECC.nc','PRECC_JAN', PRECC_JAN)
nccreate('PRECC.nc','PRECC_JUL','Dimensions',{'lon',144,'lat',96,'year',length(year)},'Format','classic')
ncwrite('PRECC.nc','PRECC_JUL', PRECC_JUL)
nccreate('PRECC.nc','PRECC_MONTH','Dimensions',{'lon',144,'lat',96,'month',12,'year',length(year)},'Format','classic')
ncwrite('PRECC.nc','PRECC_MONTH', PRECC_MONTH)
ncdisp('PRECC.nc')