function segment = p12_boundary_segment ( segment_index, m, segment_length )

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

    n01 = round ( 0.500 * ( segment_length - 1 ) / 5.75 );

    n02 = round ( ( 0.500 + 0.250) * ( segment_length - 1 ) ...
              / 5.75 ) - n01;
    
    n03 = round ( ( 0.500 + 0.250 + 0.125 ) * ( segment_length - 1 ) ...
              / 5.75 ) - n01 - n02;

    n04 = round ( ( 0.500 + 0.250 + 0.125 + 0.250 ) * ( segment_length - 1 ) ...
              / 5.75 ) - n01 - n02 - n03;

    n05 = round ( ( 0.500 + 0.250 + 0.125 + 0.250 + 0.375 ) ...
              * ( segment_length - 1 ) ...
              / 5.75 ) - n01 - n02 - n03 - n04;

    n06 = round ( ( 0.500 + 0.250 + 0.125 + 0.250 + 0.375 + 1.000 ) ...
              * ( segment_length - 1 ) ...
              / 5.75 ) - n01 - n02 - n03 - n04 - n05;

    n07 = round ( ( 0.500 + 0.250 + 0.125 + 0.250 + 0.375 + 1.000 + 0.375 ) ...
              * ( segment_length - 1 ) ...
              / 5.75 ) - n01 - n02 - n03 - n04 - n05 - n06;

    n08 = round ( ( 0.500 + 0.250 + 0.125 + 0.250 + 0.375 + 1.000 + 0.375 + 0.625 ) ...
              * ( segment_length - 1 ) ...
              / 5.75 ) - n01 - n02 - n03 - n04 - n05 - n06 - n07;

    n09 = round ( ( 0.500 + 0.250 + 0.125 + 0.250 + 0.375 + 1.000 + 0.375 + 0.625 ...
                 + 0.125 ) ...
              * ( segment_length - 1 ) ...
              / 5.75 ) - n01 - n02 - n03 - n04 - n05 - n06 - n07 - n08;

    n10 = round ( ( 0.500 + 0.250 + 0.125 + 0.250 + 0.375 + 1.000 + 0.375 + 0.625 ...
                 + 0.125 + 0.375 ) ...
              * ( segment_length - 1 ) ...
              / 5.75 ) - n01 - n02 - n03 - n04 - n05 - n06 - n07 - n08 - n09;

    n10 = round ( ( 0.500 + 0.250 + 0.125 + 0.250 + 0.375 + 1.000 + 0.375 + 0.625 ...
                 + 0.125 + 0.625 ) ...
              * ( segment_length - 1 ) ...
              / 5.75 ) - n01 - n02 - n03 - n04 - n05 - n06 - n07 - n08 - n09;

    n11 = round ( ( 0.500 + 0.250 + 0.125 + 0.250 + 0.375 + 1.000 + 0.375 + 0.625 ...
                 + 0.125 + 0.625 + 0.500 ) ...
              * ( segment_length - 1 ) ...
              / 5.75 ) - n01 - n02 - n03 - n04 - n05 - n06 - n07 - n08 - n09 - n10;

    n12 = segment_length - 1 - n01 - n02 - n03 - n04 - n05 ...
          - n06 - n07 - n08 - n09 - n10 - n11;

    s(1:2,1:12) = [ ...
    0.000,  0.000; ...
    0.500,  0.000; ...
    0.500,  0.250; ...
    0.625,  0.250; ...
    0.625,  0.000; ...
    1.000,  0.000; ...
    1.000,  1.000; ...
    0.625,  1.000; ...
    0.625,  0.375; ...
    0.500,  0.375; ...
    0.500,  1.000; ...
    0.000,  1.000 ]';

    j = 0;

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

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

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

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

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

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

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

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

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

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

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

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

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

  else

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

  end

  return
end
