function cdf_value = cdf_discrete_value ( data_num, data_x, cdf_num, cdf_x )

%*****************************************************************************80
%
%% cdf_discrete_value() evaluates a discrete CDF.
%
%  Discussion:
%
%    Given an initial set of SAMPLE_NUM values SAMPLE_X, and SAMPLE_MIN, 
%    SAMPLE_MAX, the minimum and maximum values in the range, we create 
%    a new vector of SAMPLE_NUM+2 = DATA_NUM values called DATA_X, 
%    containing a lower value, the sorted values of X, and finally 
%    an upper value.
%
%    We can regard the sample data as implicitly defining a piecewise
%    linear sample CDF over the range [SAMPLE_MIN,SAMPLE_MAX].
%    To evaluate this function, we first determine 
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    14 February 2003
%
%  Author:
%
%    John Burkardt
%
%  Input:
%
%    integer DATA_NUM, the number of data values.
%
%    real DATA_X(DATA_NUM), the data values.
%
%    integer CDF_NUM, the number of CDF 
%
%    real CDF_X(CDF_NUM), the X values.
%  
%  Output:
%
%    real CDF_VALUE(CDF_NUM), the value of the discrete CDF.
%
  for cdf = 1 : cdf_num
%
%  Locate CDF_X.
%
    if ( cdf_x(cdf) < data_x(1) )

      cdf_value(cdf) = 0.0;

    elseif ( data_x(data_num) < cdf_x(cdf) )

      cdf_value(cdf) = 1.0;

    else

      for data = 2 : data_num - 1
        if ( cdf_x(cdf) <= 0.5 * ( data_x(data-1) + data_x(data) ) )
          cdf_value(cdf) = ( data - 1 ) / data_num ...
            + ( cdf_x(cdf) - data_x(data-1) ) ...
            / ( data_x(data) - data_x(data-1) ) / data_num;
          break
        end
      end
 
   end

  end

  return
end

