function cdf_mat = set_discrete_cdf ( m1, m2, pdf_mat )

%*****************************************************************************80
%
%% set_discrete_cdf() sets a CDF from a discrete PDF.
%
%  Discussion:
%
%    The array PDF_MAT:
%
%      1,1  1,2  ...  1,M2
%      2,1  2,2  ...  2,M2
%      ...  ...  ...  ....
%     M1,1 M1,2  ... M1,M2
%
%    The corresponding geometric locations:
%
%      (1,M2) (2,M2) .... (M1,M2)
%      .....  .....  ....  ....
%      (1,2)  (2,2)  .... (M1,2)
%      (1,1)  (2,1)  .... (M1,1)
%
%    The discrete integration procedure orders the PDF_MAT array entries
%    by reading down the first column, then down the second, and so on.
%
%    This corresponds to "reading" the geometry by starting at the bottom
%    left, and reading to the right, then moving up one row, and so on.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    23 August 2016
%
%  Author:
%
%    John Burkardt
%
%  Input:
%
%    integer M1, M2, the number of rows and columns
%    of PDF data.
%
%    real PDF_MAT(M1,M2), the discrete PDF for the cell (I,J),
%    normalized so that the sum over all cells is 1.
%
%  Output:
%
%    real CDF_MAT(M1,M2), the discrete CDF for the cell (I,J).
%    CDF_MAT(M1,M2) should be 1 (or very close to it).
%
  total = 0.0;
  for j = 1 : m2
    for i = 1 : m1
      total = total + pdf_mat(i,j);
      cdf_mat(i,j) = total;
    end
  end

  return
end
