function segment = p15_boundary_segment ( segment_index, m, segment_length )

%*****************************************************************************80
%
%% p15_boundary_segment returns a boundary segment in problem 15.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    12 April 2009
%
%  Author:
%
%    John Burkardt
%
%  Input:
%
%    integer SEGMENT_INDEX, the index of the boundary segment.
%
%    integer M, the spatial dimension.
%
%    integer SEGMENT_length, the number of points in the segment.
%
%  Output:
%
%    real SEGMENT(M,SEGMENT_length), points on the boundary segment.
%
  if ( segment_index == 1 )

    sl_extra = segment_length - 9;

    n1 = round ( 10.0 * ( sl_extra ) / 36 );
    n2 = round (  1.0 * ( sl_extra ) / 36 );
    n2 = max ( n2, 0 );
    n3 = round (  6.0 * ( sl_extra ) / 36 );
    n3 = max ( n3, 0 );
    n4 = round (  1.0 * ( sl_extra ) / 36 );
    n4 = max ( n4, 0 );
    n5 = round ( 10.0 * ( sl_extra ) / 36 );
    n5 = max ( n5, 0 );
    n6 = round (  1.0 * ( sl_extra ) / 36 );
    n6 = max ( n6, 0 );
    n7 = round (  6.0 * ( sl_extra ) / 36 );
    n7 = max ( n7, 0 );
    n8 = sl_extra - n1 - n2 - n3 - n4 - n5 - n6 - n7;

    n1 = n1 + 1;
    n2 = n2 + 1;
    n3 = n3 + 1;
    n4 = n4 + 1;
    n5 = n5 + 1;
    n6 = n6 + 1;
    n7 = n7 + 1;
    n8 = n8 + 1;

    s(1:2,1) = [  -8.0,  -1.0 ]';
    s(1:2,2) = [   2.0,  -1.0 ]';
    s(1:2,3) = [   2.0,   0.0 ]';
    s(1:2,4) = [   8.0,   0.0 ]';
    s(1:2,5) = [   8.0,   1.0 ]';
    s(1:2,6) = [  -2.0,   1.0 ]';
    s(1:2,7) = [  -2.0,   0.0 ]';
    s(1:2,8) = [  -8.0,   0.0 ]';

    j = 0;

    for i = 1 : n1
      j = j + 1;
      segment(1:2,j) = ( ( n1 - i + 1 ) * s(1:2,1)   ...
                       + (      i - 1 ) * s(1:2,2) ) ...
                       / ( n1         );
    end

    for i = 1 : n2
      j = j + 1;
      segment(1:2,j) = ( ( n2 - i + 1 ) * s(1:2,2)   ...
                       + (      i - 1 ) * s(1:2,3) ) ...
                       / ( n2         );
    end

    for i = 1 : n3
      j = j + 1;
      segment(1:2,j) = ( ( n3 - i + 1 ) * s(1:2,3)   ...
                       + (      i - 1 ) * s(1:2,4) ) ...
                       / ( n3         );
    end

    for i = 1 : n4
      j = j + 1;
      segment(1:2,j) = ( ( n4 - i + 1 ) * s(1:2,4)   ...
                       + (      i - 1 ) * s(1:2,5) ) ...
                       / ( n4         );
    end

    for i = 1 : n5
      j = j + 1;
      segment(1:2,j) = ( ( n5 - i + 1 ) * s(1:2,5)   ...
                       + (      i - 1 ) * s(1:2,6) ) ...
                       / ( n5         );
    end

    for i = 1 : n6
      j = j + 1;
      segment(1:2,j) = ( ( n6 - i + 1 ) * s(1:2,6)   ...
                       + (      i - 1 ) * s(1:2,7) ) ...
                       / ( n6         );
    end

    for i = 1 : n7
      j = j + 1;
      segment(1:2,j) = ( ( n7 - i + 1 ) * s(1:2,7)   ...
                       + (      i - 1 ) * s(1:2,8) ) ...
                       / ( n7         );
    end

    for i = 1 : n8
      j = j + 1;
      segment(1:2,j) = ( ( n8 - i + 1 ) * s(1:2,8)   ...
                       + (      i - 1 ) * s(1:2,1) ) ...
                       / ( n8         );
    end

    j = j + 1;
    segment(1:2,j) = s(1:2,1);

  else

    fprintf ( 1, '\n' );
    fprintf ( 1, 'P15_boundary_segment - Fatal error!\n' );
    fprintf ( 1, '  Illegal SEGMENT_INDEX = %d\n', segment_index );
    error ( 'P15_boundary_segment - Fatal error!' );

  end

  return
end
