%
%   assembly_ms.m  ver 1.1  January 25, 2012
%
function[stiff,mass,dof,dof_status]=assembly_ms(ne,klocal,mlocal,ibc,dof,node_int,dx)
%
    isp=length(node_int);
    dof_status=ones(dof,1);
%
    for i=1:dof
			for j=1:dof
         		 sg(i,j)=0.;
				 mg(i,j)=0.;        
             end
    end
%
   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);
				 mg(ii+i,jj+j)=mg(ii+i,jj+j)+mlocal(k,i,j);
             end
        end
        ii=ii+2;
        jj=jj+2;
    end
%%%%
%%%%    Apply bc
%%%%
%%%%    ibc=input(' 1=free-free 2=fixed-free 3=fixed-fixed  4=pinned-pinned ');
%%%%
%
disp(' ');
out1=sprintf(' ibc=%d ',ibc);
disp(out1);
%
stiff=sg;
mass=mg;
%
if(ibc==1) % free-free
%
     for j=isp:-1:1
         nd=2*node_int(j)-1;
         stiff(:,nd)=[];
         stiff(nd,:)=[];
         mass(:,nd)=[];
         mass(nd,:)=[];
         dof_status(nd)=0;
     end
     
% 
end
if(ibc==2) % fixed-free
     for j=isp:-1:1
         nd=2*node_int(j)-1;
         stiff(:,nd)=[];
         stiff(nd,:)=[];
         mass(:,nd)=[];
         mass(nd,:)=[];  
         dof_status(nd)=0;
     end
%
     for j=2:-1:1
        nd=j;
        stiff(:,nd)=[];
        stiff(nd,:)=[];
        mass(:,nd)=[];
        mass(nd,:)=[];
        dof_status(nd)=0;        
     end
%
end
if(ibc==3) % fixed-fixed 
%
     for j=dof:-1:(dof-1)
        nd=j;
        stiff(:,nd)=[];
        stiff(nd,:)=[];
        mass(:,nd)=[];
        mass(nd,:)=[];
        dof_status(nd)=0;
     end
%
     for j=isp:-1:1
         nd=2*node_int(j)-1;
         stiff(:,nd)=[];
         stiff(nd,:)=[];
         mass(:,nd)=[];
         mass(nd,:)=[];
         dof_status(nd)=0;
     end
%
     for j=2:-1:1
        nd=j;
        stiff(:,nd)=[];
        stiff(nd,:)=[];
        mass(:,nd)=[];
        mass(nd,:)=[];
        dof_status(nd)=0;  
     end
% 
end
if(ibc==4) % pinned-pinned
%    
     j=(dof-1);
        nd=j;
        stiff(:,nd)=[];
        stiff(nd,:)=[];
        mass(:,nd)=[];
        mass(nd,:)=[];
        dof_status(nd)=0;
%
     for j=isp:-1:1
         nd=2*node_int(j)-1;
         stiff(:,nd)=[];
         stiff(nd,:)=[];
         mass(:,nd)=[];
         mass(nd,:)=[];
         dof_status(nd)=0;  
     end
%
     j=1;
        nd=j;
        stiff(:,nd)=[];
        stiff(nd,:)=[];
        mass(:,nd)=[];
        mass(nd,:)=[];
        dof_status(nd)=0;  
% 
end
%
dof=max(size(mass));