  function [Q,R] = cgsa (A)
% function [Q,R] = cgsa (A)
% Gram Schmidt QR factorization of A
 [m,n] = size(A); 
 for j=1:n
   q = A(:,j);
   for i=1:j-1 
     r = A(:,j)'*Q(:,i);
     q = q -r*Q(:,i);
     R(i,j) = r;
   end
%%---------- error exit for case rjj == 0
     r = norm(q) ;
     if (r == 0.0) 
         error(' zero column encountered!')
     end
     Q(:,j) = q / r;
     R(j,j) = r; 
 end 
