function h = h_measure ( dim_num, n, z, ns, sample_routine )

%*****************************************************************************80
%
%% h_measure() determines the pointset quality measure H.
%
%  Discussion:
%
%    The H measure of dispersion for a set of N points in an DIM_NUM-dimensional
%    region is the maximum distance between a point in the region and 
%    some point in the set.
%
%    To compute this quantity exactly, for every point X in the region,
%    find the nearest element Z of the point set and compute the distance.
%    H is then the maximum of all these distances.
%
%    To ESTIMATE this quantity, carry out the same process, but only for
%    NS sample points in the region.
%
%    Under this measure, a mesh with a smaller value of H is preferable.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    08 July 2021
%
%  Author:
%
%    John Burkardt
%
%  Reference:
%
%    Max Gunzburger and John Burkardt,
%    Uniformity Measures for Point Samples in Hypercubes.
%
%  Input:
%
%    integer DIM_NUM, the spatial dimension.
%
%    integer N, the number of points.
%
%    real Z(DIM_NUM,N), the points.
%
%    integer NS, the number of sample points.
%
%    character SAMPLE_ROUTINE, the name of the function to be used to
%    return sample points in the region.  The function must have the form
%      x = sample_routine ( dim_num, n )
%
%  Output:
%
%    real H, the H quality measure.
%
  h = 0.0;

  for k = 1 : ns

    x = feval ( sample_routine, 1, dim_num );

    closest = find_closest ( dim_num, n, 1, x, z );

    dist = sum ( ( x(1,1:dim_num) - z(closest(1),1:dim_num) ).^2 );

    h = max ( h, dist );

  end

  h = sqrt ( h );

  return
end
