%
%   mspan_beam_assembly_unc_buckling.m  ver 1.0  by Tom Irvine
%
function[stiff,gdiff,stiff_unc,gdiff_unc,dof,dof_status,ivector]=...
                mspan_beam_assembly_unc_buckling(ne,klocal,glocal,LBC,RBC,dof,numi,int_index)
%
    dof_status=ones(dof,1);
    ivector=zeros(dof,1);
    
    for i=1:2:(dof-1)
        ivector(i)=1;
    end
%
    sg=zeros(dof,dof);
    gg=zeros(dof,dof);    
%
   ii=0;
   jj=0;
    for k=1:ne
        
        for i=1:4
			for j=1:4
				 sg(ii+i,jj+j)=sg(ii+i,jj+j)+klocal(k,i,j);
				 gg(ii+i,jj+j)=gg(ii+i,jj+j)+glocal(k,i,j);
            end
        end
        ii=ii+2;
        jj=jj+2;
    end

%%%%

%
clear gdiff;
clear stiff;
%
stiff=sg;
gdiff=gg;

stiff_unc=sg;
gdiff_unc=gg;

%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%

N=max(size(gdiff));
%

if(RBC==3) % right fixed
%
     stiff(N,:)=[];
     stiff(:,N)=[];
     gdiff(N,:)=[];
     gdiff(:,N)=[];
%
     dof_status(N)=0;
     ivector(N)=[];
%
end

if(RBC==2 || RBC==3) % right pinned or fixed
%    
     Nm1=N-1; 
     stiff(Nm1,:)=[];
     stiff(:,Nm1)=[];
     gdiff(Nm1,:)=[];
     gdiff(:,Nm1)=[];
%
     dof_status(Nm1)=0; 
     ivector(Nm1)=[];
%     
end
%
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%

for i=numi:-1:1
   
     np=2*int_index(i)-1;
    
     stiff(np,:)=[];
     stiff(:,np)=[];
     gdiff(np,:)=[];
     gdiff(:,np)=[];    
    
     dof_status(np)=0; 
     ivector(np)=[];
     
end

%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%
if(LBC==3) % left fixed
%    
     stiff(2,:)=[];
     stiff(:,2)=[];
%
     gdiff(2,:)=[];
     gdiff(:,2)=[];
%
     dof_status(2)=0;
     ivector(2)=[];
%
end
%
if(LBC==2 || LBC==3) % left pinned or fixed
%    
     stiff(1,:)=[];
     stiff(:,1)=[];
%
     gdiff(1,:)=[];
     gdiff(:,1)=[];
%
     dof_status(1)=0; 
     ivector(1)=[];     
%
end
%
%
dof=max(size(gdiff));
%
