function [Phiplot,DOFvecplot] = interpmd(Phi,Nodes,DOFvec)
%
%  Name: interpmd
% 
%  Usage:
% 
%   Description:
%     Interpolates mode shapes in Phi
%     from the DOF in DOFvec to all the
%     locations in Nodes (using primary direction
%     from DOFvec)
%
%  Version SWD960705
%
%  Author(s): Scott W. Doebling, doebling@lanl.gov
%
%  Institution: Los Alamos National Laboratory,
%		ESA-EA
%
%  Copyright (c) 1996, The Regents of the University
%     	of California. (See top level of code for
%	full copyright statement.)


dir = DOFvec(1,2);

%
%  Create unmeasDOF using DOFvec and Nodes
%

unmeasDOF = [0 0];

for i = 1:size(Nodes,1),

    if isempty(find(DOFvec(:,1) == Nodes(i,1))),
	unmeasDOF = [unmeasDOF;Nodes(i,1) dir];
    end
end

unmeasDOF(1,:) = [];

%
%  Determine the independent coordinates based on sensor direction
%

indir = find(abs(dir) ~= [1 2 3]);

%
%  Build list of node coordinates corresponding to DOFvec, unmeasDOF
%

DOFcoord = zeros(size(DOFvec,1),3);

for i = 1:size(DOFvec,1),

    drow = find(Nodes(:,1) == DOFvec(i,1));
    DOFcoord(i,:) = Nodes(drow,2:4);

end

unmeasDOFcoord = zeros(size(unmeasDOF,1),3);

for i = 1:size(unmeasDOF,1),

    drow = find(Nodes(:,1) == unmeasDOF(i,1));
    unmeasDOFcoord(i,:) = Nodes(drow,2:4);

end

DOFcoord

%
%  Create x,y in matrix form from DOFcoord
%

%[x,y] = meshgrid(DOFcoord(:,indir(1)),DOFcoord(:,indir(2)))
%[xu,yu] = meshgrid(unmeasDOFcoord(:,indir(1)),unmeasDOFcoord(:,indir(2)))

x = DOFcoord(:,indir(1));
y = DOFcoord(:,indir(2));

x
y

xu = unmeasDOFcoord(:,indir(1));
yu = unmeasDOFcoord(:,indir(2));

xu
yu

%
%  Interpolate the modal displacements for each mode
%

for k = 1:size(Phi,2),

%    Convert Phi to matrix form for this mode

   %for i = 1:size(x,1),

	%for j = 1:size(x,2),

	    %dsens = find(DOFcoord(:,indir(1)) == x(i,j) & DOFcoord(:,indir(2)) == y(i,j));

	    %if isempty(dsens),
		%disp('ERROR: NEED PLAID GRID TO INTERPOLATE')
	    %else
		%z(i,j) = Phi(dsens,k);
	    %end
	%end
    %end

    %unmeasPhi(:,k) = interp2(x,y,z,xu,yu);
    unmeasPhi(:,k) = griddata(x,y,Phi(:,k),xu,yu);
    

end

%
%  Convert fit matrix back to vector form
%

Phi
unmeasPhi

%
%  Assemble Phiplot and DOFvecplot
%

Phiplot = [Phi;unmeasPhi];

DOFvecplot = [DOFvec;unmeasDOF];

return