function [ cen_lon, cen_lat, seed ] = florida_centroid_pop ( gen_lon, ...
  gen_lat, sample_num, pop_lon, pop_lat, pop_cdf, seed )

%*****************************************************************************80
%
%% FLORIDA_CENTROID_POP estimates centroids of Voronoi regions, given generators.
%
%  Discussion:
%
%    The calculation is based on population sampling.
%
%  Licensing:
%
%    This code is distributed under the GNU LGPL license.
%
%  Modified:
%
%    04 July 2016
%
%  Parameters:
%
%    Input, real GEN_LON(*), GEN_LAT(*), the longitude and latitude 
%    of generators to be displayed on a map of Florida.
%
%    Input, integer SAMPLE_NUM, the number of samples to use.
%
%    Input, real POP_LON(M), POP_LAT(M), the longitude and latitude for
%    the population data points.
%
%    Input, real POP_CDF(M+1), the CDF for the population.
%
%    Input, integer SEED, a seed for the random number generator.
%
%    Output, real CEN_LON(*), CEN_LAT(*), the longitude and latitude 
%    of the population centroids of the Voronoi regions.
%
%    Output, integer SEED, a seed for the random number generator.
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'FLORIDA_CENTROID_POP:\n' );
  fprintf ( 1, '  MATLAB version\n' );
  fprintf ( 1, '  Estimate population centroids of Voronoi regions,\n' );
  fprintf ( 1, '  given generators.\n' );
%
%  Initialize the counts for each generator.
%
  n = length ( gen_lon );
  cen_lat = zeros ( n, 1 );
  cen_lon = zeros ( n, 1 );
  cen_count = zeros ( n, 1 );
%
%  Choose random persons in Florida.
%
  [ indx, seed ] = florida_sample_pop ( sample_num, pop_cdf, seed );
%
%  Associate each sample person with one of the generators.
%
  for s = 1 : sample_num

    d_min = Inf;
    i_min = 0;
    for i = 1 : n
      d = ( pop_lat(indx(s)) - gen_lat(i) ) ^ 2 ...
        + ( pop_lon(indx(s)) - gen_lon(i) ) ^ 2;
      if ( d < d_min )
        d_min = d;
        i_min = i;
      end
    end

    cen_lat(i_min) = cen_lat(i_min) + pop_lat(indx(s));
    cen_lon(i_min) = cen_lon(i_min) + pop_lon(indx(s));
    cen_count(i_min) = cen_count(i_min) + 1;

  end
%
%  Set the centroid estimates.
%
  for i = 1 : n
    if ( cen_count(i) == 0 )
      cen_lon(i) = gen_lon(i);
      cen_lat(i) = gen_lat(i);
    else
      cen_lon(i) = cen_lon(i) / cen_count(i);
      cen_lat(i) = cen_lat(i) / cen_count(i);
    end
  end

  return
end

