load ~/NC/grid.mat
load ~/Aerosol_Variaiton/IRUN/CCN/ncfile/POCLCCN_Daily_145.mat
load ~/Aerosol_Variaiton/IRUN/PRECT/ncfile/PRECT_daily_145.mat
day=1:92;

%a=sum(PO_Month);
%b=sum(CL_Month);

PRECT_PO_day=zeros(144,96,30);
PRECT_CL_day=zeros(144,96,30);


for i=1:length(lon)
for j=1:length(lat)
n=0;
m=0;
for dayID=1:length(day)
    if PO_Daily(i,j,dayID)==1
        n=n+1;
        PRECT_PO_day(i,j,n)=PRECT_DAILY(i,j,dayID);
    end
    if CL_Daily(i,j,dayID)==1
        m=m+1;
        PRECT_CL_day(i,j,m)=PRECT_DAILY(i,j,dayID);
    end
end
end
end

PRECT_PO=mean(PRECT_PO_day,3);
PRECT_CL=mean(PRECT_CL_day,3);

PRECT_POCL=PRECT_PO-PRECT_CL;

save('PRECT_POCLCCN_composite_daily_145.mat','PRECT_PO','PRECT_CL','PRECT_POCL')

nccreate('PRECT_POCLCCN_composite_daily_145.nc','lat','Dimensions',{'lat',96},'Format','classic')
ncwrite('PRECT_POCLCCN_composite_daily_145.nc','lat', lat)
ncwriteatt('PRECT_POCLCCN_composite_daily_145.nc','lat','units','degrees_north')
ncwriteatt('PRECT_POCLCCN_composite_daily_145.nc','lat','long_name','Latitude')
nccreate('PRECT_POCLCCN_composite_daily_145.nc','lon','Dimensions',{'lon',144},'Format','classic')
ncwrite('PRECT_POCLCCN_composite_daily_145.nc','lon', lon)
ncwriteatt('PRECT_POCLCCN_composite_daily_145.nc','lon','units','degrees_east')
ncwriteatt('PRECT_POCLCCN_composite_daily_145.nc','lon','long_name','Longitude')
nccreate('PRECT_POCLCCN_composite_daily_145.nc','PRECT_PO','Dimensions',{'lon',144,'lat',96},'Format','classic')
ncwrite('PRECT_POCLCCN_composite_daily_145.nc','PRECT_PO', PRECT_PO)
nccreate('PRECT_POCLCCN_composite_daily_145.nc','PRECT_CL','Dimensions',{'lon',144,'lat',96},'Format','classic')
ncwrite('PRECT_POCLCCN_composite_daily_145.nc','PRECT_CL', PRECT_CL)
nccreate('PRECT_POCLCCN_composite_daily_145.nc','PRECT_POCL','Dimensions',{'lon',144,'lat',96},'Format','classic')
ncwrite('PRECT_POCLCCN_composite_daily_145.nc','PRECT_POCL', PRECT_POCL)
ncdisp('PRECT_POCLCCN_composite_daily_145.nc')
