load ~/NC/grid.mat
load ~/Aerosol_Variaiton/IRUN/AOD/ncfile/POCL_Daily.mat
load ~/Aerosol_Variaiton/IRUN/AOD/ncfile/AOD_daily.mat
day=1:92;

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

AOD_PO_day=zeros(144,96,30);
AOD_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;
        AOD_PO_day(i,j,n)=AOD_DAILY(i,j,dayID);
    end
    if CL_Daily(i,j,dayID)==1
        m=m+1;
        AOD_CL_day(i,j,m)=AOD_DAILY(i,j,dayID);
    end
end
end
end

AOD_PO=mean(AOD_PO_day,3);
AOD_CL=mean(AOD_CL_day,3);

AOD_POCL=AOD_PO-AOD_CL;

save('AOD_POCL_composite_daily.mat','AOD_PO','AOD_CL','AOD_POCL')

nccreate('AOD_POCL_composite_daily.nc','lat','Dimensions',{'lat',96},'Format','classic')
ncwrite('AOD_POCL_composite_daily.nc','lat', lat)
ncwriteatt('AOD_POCL_composite_daily.nc','lat','units','degrees_north')
ncwriteatt('AOD_POCL_composite_daily.nc','lat','long_name','Latitude')
nccreate('AOD_POCL_composite_daily.nc','lon','Dimensions',{'lon',144},'Format','classic')
ncwrite('AOD_POCL_composite_daily.nc','lon', lon)
ncwriteatt('AOD_POCL_composite_daily.nc','lon','units','degrees_east')
ncwriteatt('AOD_POCL_composite_daily.nc','lon','long_name','Longitude')
nccreate('AOD_POCL_composite_daily.nc','AOD_PO','Dimensions',{'lon',144,'lat',96},'Format','classic')
ncwrite('AOD_POCL_composite_daily.nc','AOD_PO', AOD_PO)
nccreate('AOD_POCL_composite_daily.nc','AOD_CL','Dimensions',{'lon',144,'lat',96},'Format','classic')
ncwrite('AOD_POCL_composite_daily.nc','AOD_CL', AOD_CL)
nccreate('AOD_POCL_composite_daily.nc','AOD_POCL','Dimensions',{'lon',144,'lat',96},'Format','classic')
ncwrite('AOD_POCL_composite_daily.nc','AOD_POCL', AOD_POCL)
ncdisp('AOD_POCL_composite_daily.nc')
