
function DAT = LCDF(loc,bins,Dmax)

% This program computes Local CDFs of Point Totals

% Written by: TONY E. SMITH, 2/4/98

% INPUTS:
%     (i)   loc = file of locations (xi,yi), i=1..m
%     (ii)  bins = number of bins to use in CDF
%     (iii) Dmax = max pairwise distance
% OUTPUTS: DAT = (m x bins) array of CDF's

[m,n] = size(loc) ;

%Compute pairwise distances

D = zeros(m*(m-1)/2, 3) ; %Matrix of loc-dist pairs

i = 1 ;

k = 1 ;  %counter for D.

while i < m
   
   j = i + 1 ;
   
   while j <= m
      
      D(k,1) = sqrt((loc(i,1) - loc(j,1))^2 + ...
         (loc(i,2) - loc(j,2))^2);

      D(k,2) = i ;
      
      D(k,3) = j ;  
                
      j = j + 1 ;
      
      k = k + 1 ;
      
   end
   
   i = i + 1 ;
   
end

%Count point frequencies

C = zeros(m,bins) ;

[M,n] = size(D) ;

k = 1 ;

while k <= M 
   
   if D(k,1) <= Dmax/2
      
      % The following 'max' is to allow zero distances
      
      b = max(1,ceil(bins * (D(k,1)/(Dmax/2)))) ; 
      
      i = D(k,2) ;
      
      j = D(k,3) ;
      
      C(i,b) = C(i,b) + 1 ;
      
      C(j,b) = C(j,b) + 1 ;
      
   end
   
   k = k + 1 ;
   
end

%Construct CDF's

k = 1 ;

while k < bins
   
   C(:,k + 1) = C(:,k + 1) + C(:,k) ;
   
   k = k + 1 ;
   
end

C = C/(m - 1) ;  %normalize by max point total, m - 1 .

DAT = C ;



