% Function: mseplot.m
% 
% Usage: mseplot
% 
% Description:
%    
%	Overlays the expanded mode shapes with the
%	raw mode shapes
%
%  ASSUMES Z-TRANSLATIONS ONLY MEASURED AND X AND Y ROTATIONS ONLY CURVE-FIT
%

% Version SWD970118
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% This matlab source code was originally     %
% developed as part of "DIAMOND" at          %
% Los Alamos National Laboratory. It may     %
% be copied, modified, and distributed in    %
% any form, provided:                        %
%  a) This notice accompanies the files and  %
%     appears near the top of all source     %
%     code files.                            %
%  b) No payment or commercial services are  %
%     received in exchange for the code.     %
%                                            %
% Original copyright is reserved by the      %
% Regents of the University of California,   %
% in addition to Scott W. Doebling, Phillip  %
% J. Cornwell, Erik G. Straser, and Charles  %
% R. Farrar.                                 %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%  Make sure the variables exist
%

if ~exist('phir_resp_d'), 
	disp('ERROR: DAMAGED MODE SHAPES NOT PRESENT IN WORKSPACE')
        return
end


if ~exist('phir_resp_d_exp'), 
	disp('ERROR: EXPANDED MODE SHAPES NOT PRESENT IN WORKSPACE')
end

if ~exist('Nodes') | ~exist('Bars'),
	disp('ERROR: GEOMETRY NOT PRESENT IN THE WORKSPACE')
end


%
%  ASSUMES Z-TRANSLATIONS ONLY MEASURED AND X AND Y ROTATIONS ONLY CURVE-FIT
%

%
%  Draw the undeformed mode shape
%

axes(haxes)
hold off
cla

[Nodes_def,nscale] = drawmode(Bars,Nodes,phir_resp_d(:,mode_anal),Freq_d(mode_anal),respDOF_d,1,0,0,0,0,haxes);

hold on

%
%  Draw the curve-fit rotations
%  ----------------------------

for i = 1:length(respDOF_d),

%    Find entries in expanded mode shapes that contain x and y rotations at this node

    xrotrow = find(respDOF_d_exp(:,1) == respDOF_d(i,1) & abs(respDOF_d_exp(:,2)) == 4);
    yrotrow = find(respDOF_d_exp(:,1) == respDOF_d(i,1) & abs(respDOF_d_exp(:,2)) == 5);

%    Define x and y rotations

    xrot = nscale * phir_resp_d_exp(xrotrow,mode_anal);
    yrot = nscale * phir_resp_d_exp(yrotrow,mode_anal);
    
%    Find coordinates of this node

    coordrow = find(Nodes(:,1) == respDOF_d(i,1));
    nodcoord = Nodes_def(coordrow,2:4);

%    Use line length that is multiple of full geometry size

    lenlinex = 0.05 * (max(Nodes(:,2)) - min(Nodes(:,2)));
    lenliney = 0.05 * (max(Nodes(:,3)) - min(Nodes(:,3)));

%    Compute the line vectors in 3 dimensions

%    xrotline0 = nodcoord - lenliney * 0.5 * [0 cos(xrot) sin(xrot)];
%    xrotline1 = nodcoord + lenliney * 0.5 * [0 cos(xrot) sin(xrot)];

    xrotlinex = nodcoord(1) * ones(1,2);
    xrotliney = nodcoord(2) * ones(1,2) + lenliney * 0.5 * [-cos(xrot) cos(xrot)];
    xrotlinez = nodcoord(3) * ones(1,2) + lenliney * 0.5 * [-sin(xrot) sin(xrot)];
    
    
%    yrotline0 = nodcoord + lenlinex * 0.5 * [cos(yrot)  0  -sin(yrot)];
%    yrotline1 = nodcoord - lenlinex * 0.5 * [cos(yrot)  0  -sin(yrot)];
    
    yrotliney = nodcoord(2) * ones(1,2);
    yrotlinex = nodcoord(1) * ones(1,2) + lenlinex * 0.5 * [cos(yrot) -cos(yrot)];
    yrotlinez = nodcoord(3) * ones(1,2) + lenlinex * 0.5 * [-sin(yrot) sin(yrot)];
  

%    Draw the lines

     line(xrotlinex, xrotliney, xrotlinez, 'color', 'g')
    
     line(yrotlinex, yrotliney, yrotlinez, 'color', 'r')

end

hold off

%
%  Draw the legend
%

%legend('y-','MEAS MODE','g','Curve Fit x rot','r','Curve Fit y rot')

xlabel('X')
ylabel('Y')
zlabel('Z')
