load ~/NC/grid
month=1:1800;

PRECC_temp=ncread('~/Aerosol_Variaiton/IRUN/read_nc/ncfile/read_nc_PREC.nc','PRECC')*1e3*60*60*24;    %m/s->mm/day;
PRECL_temp=ncread('~/Aerosol_Variaiton/IRUN/read_nc/ncfile/read_nc_PREC.nc','PRECL')*1e3*60*60*24;    %m/s->mm/day;

PRECT_temp=PRECC_temp+PRECL_temp;

PRECT_MONTH=zeros(144,96,1800);

% Change size
for i=1:144
    for j=1:96
        n=0;
        for yearID=1:150
            for monthID=1:12
                n=n+1;
                PRECT_MONTH(i,j,n)=PRECT_temp(i,j,monthID,yearID);
            end
        end
    end
end

save('PRECT_monthly.mat','PRECT_MONTH')

nccreate('PRECT_monthly.nc','Month','Dimensions',{'time',Inf},'Format','classic')
ncwrite('PRECT_monthly.nc','Month', month)
ncwriteatt('PRECT_monthly.nc','Month','long_name','Month')
nccreate('PRECT_monthly.nc','lat','Dimensions',{'lat',96},'Format','classic')
ncwrite('PRECT_monthly.nc','lat', lat)
ncwriteatt('PRECT_monthly.nc','lat','units','degrees_north')
ncwriteatt('PRECT_monthly.nc','lat','long_name','Latitude')
nccreate('PRECT_monthly.nc','lon','Dimensions',{'lon',144},'Format','classic')
ncwrite('PRECT_monthly.nc','lon', lon)
ncwriteatt('PRECT_monthly.nc','lon','units','degrees_east')
ncwriteatt('PRECT_monthly.nc','lon','long_name','Longitude')
nccreate('PRECT_monthly.nc','PRECT_MONTH','Dimensions',{'lon',144,'lat',96,'month',length(month)},'Format','classic')
ncwrite('PRECT_monthly.nc','PRECT_MONTH', PRECT_MONTH)
ncdisp('PRECT_monthly.nc')