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

AOD_67th=prctile(AOD_DAILY,67,3);
AOD_33th=prctile(AOD_DAILY,33,3);
PO_Daily=zeros(length(lon),length(lat),length(day));
CL_Daily=zeros(length(lon),length(lat),length(day));

for i=1:length(lon)
for j=1:length(lat)
for dayID=1:length(day);
    if AOD_DAILY(i,j,dayID)>AOD_67th(i,j)
        PO_Daily(i,j,dayID)=1;
    end
    if AOD_DAILY(i,j,dayID)<AOD_33th(i,j)
        CL_Daily(i,j,dayID)=1;
    end
end
end
end


save('POCL_Daily.mat','PO_Daily','CL_Daily')

nccreate('POCL_Daily.nc','Day','Dimensions',{'time',Inf},'Format','classic')
ncwrite('POCL_Daily.nc','Day', day)
ncwriteatt('POCL_Daily.nc','Day','long_name','Day')
nccreate('POCL_Daily.nc','lat','Dimensions',{'lat',96},'Format','classic')
ncwrite('POCL_Daily.nc','lat', lat)
ncwriteatt('POCL_Daily.nc','lat','units','degrees_north')
ncwriteatt('POCL_Daily.nc','lat','long_name','Latitude')
nccreate('POCL_Daily.nc','lon','Dimensions',{'lon',144},'Format','classic')
ncwrite('POCL_Daily.nc','lon', lon)
ncwriteatt('POCL_Daily.nc','lon','units','degrees_east')
ncwriteatt('POCL_Daily.nc','lon','long_name','Longitude')
nccreate('POCL_Daily.nc','PO_Daily','Dimensions',{'lon',144,'lat',96,'day',length(day)},'Format','classic')
ncwrite('POCL_Daily.nc','PO_Daily', PO_Daily)
nccreate('POCL_Daily.nc','CL_Daily','Dimensions',{'lon',144,'lat',96,'day',length(day)},'Format','classic')
ncwrite('POCL_Daily.nc','CL_Daily', CL_Daily)
ncdisp('POCL_Daily.nc')