function [phi_out,dofvec_out,idofvec] = msecomp(nmsemeth, phi_in, dofvec_in, Nodes);
%
%  Name:   msecomp
%
%  Usage:  msecomp
%
%  Computes mode shape expansion
%
% 	nmsemeth = 1 -- geometric expansion (spatial curve fit)
%	nmsemeth = 2 --  OPE (Orthogonal Procrustes Expansion)
% 
%	idofvec -- vector of indices of measured mode shape dof in full mode shape matrix

%  Version SWD970121
%
%  Author(s): Scott W. Doebling, doebling@lanl.gov
%
%  Institution: Los Alamos National Laboratory,
%               ESA-EA
%
%  Copyright (c) 1997, The Regents of the University
%       of California. (See top level of code for
%       full copyright statement.)
%

if nmsemeth == 1,  % Geometric Expansion (spatial curve fit)

%
%  Determine which DOF measurements are present
%

ixtr = ~isempty(find(abs(dofvec_in(:,2)) == 1));
iytr = ~isempty(find(abs(dofvec_in(:,2)) == 2));
iztr = ~isempty(find(abs(dofvec_in(:,2)) == 3));
ixrot = ~isempty(find(abs(dofvec_in(:,2)) == 4));
iyrot = ~isempty(find(abs(dofvec_in(:,2)) == 5));
izrot = ~isempty(find(abs(dofvec_in(:,2)) == 6));

%
%  Interpolate the displacements
%

%   SPECIAL CASE: Z TRANSLATIONAL MEASUREMENTS ONLY

if ~ixtr & ~iytr & iztr,

   nnodes = size(phi_in,1);

   nmodes = size(phi_in,2);

%	Set x and y translations and z rotations to zero

   phi_xtr = zeros(nnodes,nmodes);
   phi_ytr = zeros(nnodes,nmodes);
   phi_zrot = zeros(nnodes,nmodes);

   phi_ztr = phi_in;

%
%       Initialize x and y rotation matrices
%

   phi_xrot = zeros(nnodes,nmodes);
   phi_yrot = zeros(nnodes,nmodes);
 
%
%  Determine the rotations from the displacements
%  

for i = 1:nmodes,

%  Make matrix of Z displacements and vectors of x and y locations

   [xfp,yfp,ztrmat,xlist,ylist] = dof2list(dofvec_in,Nodes,phi_ztr(:,i));

%  Compute rotations based only on z values

   [dzdx,xrotmat] = gradient(ztrmat,xlist,ylist);

%  Define yrot to be negative of dz/dx

   yrotmat = -1 * dzdx;

%  Convert from matrix format back to column format

   phi_xrot(:,i) = atan(list2dof(xrotmat,xfp,yfp,Nodes,dofvec_in(:,1)));
   phi_yrot(:,i) = atan(list2dof(yrotmat,xfp,yfp,Nodes,dofvec_in(:,1)));

end

%
%  Compute the output mode shape matrix and dof matrix
%

   phi_out = zeros(nnodes*6,nmodes);
   dofvec_out = zeros(nnodes*6,2);
   idofvec = zeros(nnodes*6,1);


   for i = 1:nnodes,

	phi_out(((i-1)*6+1):(i*6),:) = [phi_xtr(i,:);phi_ytr(i,:);phi_ztr(i,:);phi_xrot(i,:);phi_yrot(i,:);phi_zrot(i,:)];

	dofvec_out(((i-1)*6+1):(i*6),:) = [dofvec_in(i,1)*ones(6,1) [1:6]'];

        idofvec((i-1)*6 + 3) = i;

   end

end

elseif nmsemeth == 2  % OPE (Orthogonal Procrustes Expansion)
 
    [de,ue] = ope(ua,da,ue);

end

return