function [PVal,s] = k2_diff_plot(loc,n1,sims,D,s)

%K2_DIFF_PLOT compares the K-functions of two point populations, and plots p-values for 
%clustering of pop1 relative to pop1 + pop2

%Written by: TONY E. SMITH, 2/3/01

%Programs Called: k2_diff

% INPUTS:
%     (i)   loc  = combined location file [loc(i)=(Xi, Yi),i=1..n]
%                  where n = n1 + n2. It is assumed that points for
%                  pop1 are in the first n1 rows.]
%     (ii)  n1   = size of pop1.
%     (iii) sims = number of relabelings
%     (iv)  D    = vector of distance values at which to measure clustering.

%     (v)   s    = optional specification of random seed. Default seed = 23311.
%                  s = 1 if random seed is to be used.
%                  s = 5_digit positive integer to be used as seed 



% OUTPUTS:  PVal = Vector of P-Values at each distance.
%              s = seed used

% SCREEN OUTPUT: Plot of P-Values at each distance.

% SET Seed Value for Random Number generator


if nargin == 4
   
   s = 23311 ; %default random seed

	%s = 51987; %For Myrtle case
   
   %s = 89365 ; %For Forest case
   
elseif s == 1
   
   s = 100000*rand;
   
else
   
   s = s;
   
end



% CALL K2_DIFF

PVal = k2_diff(loc,n1,sims,D,s);

% Compute Dmin

%  Dmin = Minimum distance between points in the given point pattern.
%         (This is useful for interpreting the resulting plot.)

L = loc(1:n1,:);

Dist = dist_vec(L);

Dmin = min(Dist)

% PLOT RESULTS

plot(D,PVal,'k.','MarkerSize',20);

hold on;

plot(D,PVal,'k-','LineWidth',2);

hold on;

SIG = .05*ones(length(D),1);

plot(D,SIG,'r--');

plot(D,1-SIG,'r--');

xlabel('Radius','Fontsize',12, 'FontWeight', 'bold');

ylabel('clustered                    P-Value                   dispersed',...
   'Fontsize',12, 'FontWeight', 'bold');



