function segment = p11_boundary_segment ( segment_index, m, segment_length )

%*****************************************************************************80
%
%% p11_boundary_segment returns a boundary segment in problem 11.
%
%  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 )

    n1 = round ( ( segment_length - 1 ) / 4 );

    n2 = round ( ( 1.0 + 0.5 ) * ( segment_length - 1 ) / 4 ) - n1;
    
    n3 = round ( ( 1.0 + 0.5 + ( 1.0 - 0.5 ) ) * ( segment_length - 1 ) ...
                / 4 ) - n1 - n2;

    n4 = round ( ( 1.0 + 0.5 + ( 1.0 - 0.5 ) + ( 1.0 - 0.5 ) ) ...
                * ( segment_length - 1 ) / 4 ) - n1 - n2 - n3;

    n5 = round ( ( 1.0 + 0.5 + ( 1.0 - 0.5 ) + ( 1.0 - 0.5 ) + 0.5 ) ...
                * ( segment_length - 1 ) / 4 ) - n1 - n2 - n3 - n4;

    n6 = segment_length - 1 - n1 - n2 - n3 - n4 - n5;

    s(1:2,1) = [  0.0,  0.0 ]';
    s(1:2,2) = [  1.0,  0.0 ]';
    s(1:2,3) = [  1.0,  0.5 ]';
    s(1:2,4) = [  0.5,  0.5 ]';
    s(1:2,5) = [  0.5,  1.0 ]';
    s(1:2,6) = [  0.0,  1.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,1) ) ...
                       / ( n6         );
    end

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

  else

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

  end

  return
end
