%
%   rectangular_plate_mass_stiff.m  ver 1.1  October 8, 2012
%
function[mass,stiff,total_volume,total_mass]=rectangular_plate_mass_stiff...
  (nelem,nodex,nodey,node1,node2,node3,node4,mu,beta,thick,dof,rho,D)
%
mass=zeros(dof,dof);
stiff=zeros(dof,dof);
total_volume=0;
%
progressbar;
%
for ijk=1:nelem
%
    progressbar(ijk/nelem);
%
    if ijk==1
        [mass_local,stiff_local,area]=...
         plate_mass_stiff(nodex,nodey,node1,node2,node3,node4,mu,beta,ijk);
    end
%
    total_volume=total_volume+area*thick;
%
    n1=(3*node1(ijk))-2;
    n2=(3*node2(ijk))-2;
    n3=(3*node3(ijk))-2;
    n4=(3*node4(ijk))-2;
%
    pr=[n1 n1+1 n1+2  n2 n2+1 n2+2  n3 n3+1 n3+2  n4 n4+1 n4+2  ];
    pc=pr;       
%
    for i=1:12 
        for j=1:12
             mass(pr(i),pc(j))= mass(pr(i),pc(j))+mass_local(i,j);            
            stiff(pr(i),pc(j))=stiff(pr(i),pc(j))+stiff_local(i,j);
        end
    end
%
end
%
pause(0.5);
%
progressbar(1); 
%
stiff=stiff*D;
volume=total_volume;
%
disp(' ');
disp(' Enter uniform nonstructural mass? '); 
disp(' 1=yes 2=no ');
%
amass=0;
tmass=0;
ins=input(' ');
if(ins==1)
    disp(' ');
    disp(' Select method '); 
    disp(' 1= Add mass   ');
    disp(' 2= Specify total mass'); 
    imeth=input(' ');
    disp(' ');
    if(imeth==1)
       amass=input(' Enter added mass(lbm) ');
       amass=amass/386;
    else
       tmass=input(' Enter total mass(lbm) ');
       tmass=tmass/386;
    end
end
%
rho_s=rho;
%
if(ins==1)
%%%     disp(' 1= Add mass   ');
%%%     disp(' 2= Specify total mass'); 
    if(imeth==1)
%%%       amass=input(' Enter added mass(lbm) ');
          rho=rho_s+(amass/volume);
    else
%%%       tmass=input(' Enter total mass(lbm) ');
          rho=tmass/volume;
    end
end
%
total_mass=386*rho*volume;
%
disp(' ');
out1 = sprintf(' structural mass    = %8.4g lbm',386*(rho_s*volume));
out2 = sprintf(' nonstructural mass = %8.4g lbm',386*(rho-rho_s)*volume);
out3 = sprintf(' total mass         = %8.4g lbm \n',total_mass);
out4 = sprintf(' volume = %8.4g in^3  \n',volume);
out5 = sprintf(' total mass density = %8.4g lbm/in^3 \n',total_mass/volume);
disp(out1);
disp(out2);
disp(out3);
disp(out4);
disp(out5);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
mass=mass*rho*thick;
%