function mortality_table ( )

%*****************************************************************************80
%
%% mortality_table() constructs a mortality table().
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    11 February 2024
%
%  Author:
%
%    John Burkardt
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'mortality_table():\n' );
  fprintf ( 1, '  MATLAB/Octave version %s\n', version ( ) );
  fprintf ( 1, '  Test mortality().\n' );

  [ age, combined, male, female ] = mortality_count ( );
  [ age, combined_pdf, male_pdf, female_pdf ] = mortality_pdf ( );
  [ age, combined_cdf, male_cdf, female_cdf ] = mortality_cdf ( );
  [ age, combined_this_year, male_this_year, female_this_year ] = mortality_this_year ( );

  [ combined_life, male_life, female_life ] = mortality_average_life ( );

  n = length ( age );

  fprintf ( 1, '\n' );
  fprintf ( 1, '  COMBINED STATISTICS = Male + Female\n' );
  fprintf ( 1, '  Average life span = %g\n', combined_life );
  fprintf ( 1, '\n' );
  fprintf ( 1, '    Bracket  Pop       Deaths      PDF       CDF   This Year\n' );
  fprintf ( 1, '\n' );

  pop = sum ( combined );
  for i = 1 : n
    fprintf ( 1, '  [%3d:%3d]  %7d  %7d  %8.4f  %8.4f  %8.4f\n', ...
    age(i), age(i)+1, pop, combined(i), combined_pdf(i), combined_cdf(i), ...
    combined_this_year(i) );
    pop = pop - combined(i);
  end

  fprintf ( 1, '\n' );
  fprintf ( 1, '  MALE STATISTICS\n' );
  fprintf ( 1, '  Average life span = %g\n', male_life );
  fprintf ( 1, '\n' );
  fprintf ( 1, '    Bracket  Pop       Deaths      PDF       CDF   This Year\n' );
  fprintf ( 1, '\n' );

  pop = sum ( male );
  for i = 1 : n
    fprintf ( 1, '  [%3d:%3d]  %7d  %7d  %8.4f  %8.4f  %8.4f\n', ...
    age(i), age(i)+1, pop, male(i), male_pdf(i), male_cdf(i), ...
    male_this_year(i) );
    pop = pop - male(i);
  end

  fprintf ( 1, '\n' );
  fprintf ( 1, '  FEMALE STATISTICS\n' );
  fprintf ( 1, '  Average life span = %g\n', female_life );
  fprintf ( 1, '\n' );
  fprintf ( 1, '    Bracket  Pop       Deaths      PDF       CDF   This Year\n' );
  fprintf ( 1, '\n' );

  pop = sum ( female );
  for i = 1 : n
    fprintf ( 1, '  [%3d:%3d]  %7d  %7d  %8.4f  %8.4f  %8.4f\n', ...
    age(i), age(i)+1, pop, female(i), female_pdf(i), female_cdf(i), ...
    female_this_year(i) );
    pop = pop - female(i);
  end

  return
end

