%
%  rectangular_plate_constraint_nodes.m  ver 1.0  September 12, 2012
%
function[con_nodes,num_con_nodes,con_dof,num_con_dof,rflag]=...
                    rectangular_plate_constraint_nodes(nx,ny,nd,idn,nem)
%
%
num_con_nodes=0;
num_con_dof=0;
%
con_nodes=zeros(1,1);
con_dof=zeros(1,1);
%
rflag=0;
%
j=1;  % important
%
if(idn==1)
    disp(' ');
    disp(' Constrain rotational dof at corner nodes?  1=yes 2=no ');
    irot=input(' ');
    if(irot==1)
        rflag=1;
        con_nodes=[1  nx   (nx*(ny-1)+1)  nx*ny    ]';
        j=j+4;
    end    
end
%
if(idn >=2 )  % left
    disp(' ');
    disp(' Constrain rotational dof at left edge?  1=yes 2=no ');
    irot=input(' ');
    if(irot==1)    
        rflag=1;
        ijk=1;    
        for i=1:ny
            con_nodes(j)=ijk;
            j=j+1;
            ijk=ijk+nx;
        end  
    end
end
%  
if(idn==3 || idn==5 || idn==6)  % bottom
    disp(' ');
    disp(' Constrain rotational dof at bottom edge?  1=yes 2=no ');
    irot=input(' ');
    if(irot==1)
        rflag=1;
        for i=1:nx
            con_nodes(j)=i;
            j=j+1;     
        end  
    end
end
%
if(idn>=4 )  % right
    disp(' ');
    disp(' Constrain rotational dof at right edge?  1=yes 2=no ');
    irot=input(' ');
    if(irot==1)     
        rflag=1;
        ijk=nx;
        for i=1:ny
            con_nodes(j)=ijk;
            j=j+1;
            ijk=ijk+nx;
        end  
    end
end
%
if(idn==6)  % top
    disp(' ');
    disp(' Constrain rotational dof at top edge?  1=yes 2=no ');
    irot=input(' ');
    if(irot==1)
        rflag=1;
        for i=(nx*(ny-1)+1):(nx*ny)
            con_nodes(j)=i;
            j=j+1;
        end  
    end
end
%
if(rflag==1)
    con_nodes=sort(con_nodes);
    con_nodes=unique(con_nodes);
%
    num_con_nodes=length(con_nodes);
%
    con_dof=zeros(nem,1);
%
    ijk=1;
    for i=1:num_con_nodes
        con_dof(ijk)=3*con_nodes(i)-1;
        ijk=ijk+1;
        con_dof(ijk)=3*con_nodes(i);
        ijk=ijk+1;
    end
%
    num_con_dof=length(con_dof);
%
    for i=1:num_con_dof
        if(con_dof(i)<1)
            con_dof(i)=[];
        end
    end    
%
    num_con_dof=length(con_dof);
%
end