% BBAND   Build a symmetric band matrix
%       
%       A=BBAND(B)
%       Given a matrix B which contains the rows of the Band matrix up to
%       the diagonal, this function constructs a band matrix of this
%       input.
%       
%       Input format of B with bandwidth l
%
%       [0...................................b(1,1)]
%       [0............................b(2,1),b(2,2)]
%       [0.....................b(3,1),b(3,2),b(3,3)]
%       [..........................................]
%       [b(l+1,1),b(l+1,2),b(l+1,3)......b(l+1,l+1)]
%       [b(l+2,2),b(l+2,3),b(l+3,4)......b(l+2,l+2)]
%       [..........................................]
%
%
%       Software of the MaSe - Group
%       mase-at-cs.kuleuven.ac.be
%       Revision Date: 08/04/2005


function A=BBAND(B)
  
 % initial tests
   if (isempty(B))
     disp('the matrix is empty')
   else   
  
 % initialization
    [n,l]=size(B);
   
 A=zeros(n,n);
 
 % just constructed by a loop, this function is not very efficient,
 % but that is also not required
 for i=1:n
   if (i<=l)
     A(i,1:i)=B(i,l-i+1:l);  
   else
     A(i,i-l+1:i)=B(i,:);
   end
 end
   
 A=A+triu(A',1);
   
 end
   