function b = r8bto_to_r8ge ( m, l, a, n )

%*****************************************************************************80
%
%% R8BTO_TO_R8GE copies a R8BTO matrix to a R8GE matrix.
%
%  Discussion:
%
%    The R8BTO storage format is for a block Toeplitz matrix. The matrix
%    can be regarded as an L by L array of blocks, each of size M by M.
%    The full matrix has order N = M * L.  The L by L matrix is Toeplitz,
%    that is, along its diagonal, the blocks repeat.
%
%    Storage for the matrix consists of the L blocks of the first row,
%    followed by the L-1 blocks of the first column (skipping the first row).
%    These items are stored in the natural way in an (M,M,2*L-1) array.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    08 July 2016
%
%  Author:
%
%    John Burkardt
%
%  Parameters:
%
%    Input, integer M, the order of the blocks of the R8BTO matrix.
%
%    Input, integer L, the number of blocks in a row or column of the
%    R8BTO matrix.
%
%    Input, real A(M,M,2*L-1), the R8BTO matrix.
%
%    Output, integer N, the order of the matrix, N = M*L.
%
%    Output, real B(N,N), the R8GE matrix.
%
  n = m * l;

  for i = 1 : n

    i1 = 1 + floor ( ( i - 1 ) / m );
    i2 = i - m * ( i1 - 1 );

    for j = 1 : n

      j1 = 1 + floor ( ( j - 1 ) / m );
      j2 = j - m * ( j1 - 1 );

      if ( i1 <= j1 )
        b(i,j) = a(i2,j2,j1+1-i1);
      else
        b(i,j) = a(i2,j2,l+i1-j1);
      end

    end

  end

  return
end
