function vineplot(H0,H1,Y,U0,S0,V0,q,d,fs_out,nref,nresp,nxhigh,nxlow,dnx,hERAconva,respDOF,refDOF)
%
%  Function: vineplot.m
%
%  Usage:  function vineplot(H0,H1,Y,U0,S0,V0,q,d,fs_out,nref,nresp,nxhigh,nxlow,dnx,hERAconva)
%
%  Description:  Modified verision of era.m to allow for vine plots 
%  
%  Applies the Eigensystem Realization Algorithm (ERA) to the 
%  impulse response from the FRF matrix 'G'
%
%  Reference for ERA:
%    "An Eigensystem Realization Algorithm for
%    Modal Parameter Identification and Model Reduction," 
%    Juang, J-N, and Pappa, R.S., Journal of Guidance, Control, and
%    Dynamics, Vol. 8, No. 5, pp. 620-627, 1985.
%
%  Version EGS960826
%
%  Author(s): Scott Doebling, doebling@lanl.gov
%             Phillip Cornwell, cornwell@lanl.gov
%             Erik Straser, estraser@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.)

%  Define variables and allocate space for matrices
fprintf(1,' Running Vine Plots ... ');
numnx=(nxhigh-nxlow)/dnx+1;
i=0;

% Start loop over model order
for nx=nxlow:dnx:nxhigh

  i=i+1;

  % Form A, B, C, D, V, W
  U0N = U0(:,1:nx);
  S0N = S0(1:nx,1:nx);
  V0N = V0(:,1:nx);
  SNsqrt = sqrt(S0N);
  SNinv = sqrt(inv(S0N));

  A = SNinv * U0N' * H1 * V0N * SNinv;
  B = SNsqrt * V0N(1:nref,:)';
  C = U0N(1:nresp,:) * SNsqrt;
  D = Y(1:nresp,:);

  V = U0N * SNsqrt;
  W = SNsqrt *  V0N';

  % Compute emac
  [emac_era,msv_era] = emaccomp(A,V,W,q,d,fs_out);

  % Run era2mode
  [phic_resp,phic_ref,freq,damp,emac,mpc_resp,mpc_ref,cmi_resp,cmi_ref,msv] = era2mode(A,B,C,fs_out,emac_era,msv_era,respDOF,refDOF);

  % Fill in freq and cmi vectors for plotting
  temp1 = length(freq);
  freq_s(1:temp1,i) = freq;
  cmi_s(1:temp1,i) = cmi_resp;

  % Plot the line
  for j = 1:temp1
    x1 = freq(j);
    y1 = nx;
    len = cmi_resp(j)*dnx;
    line([x1 x1],[y1 y1+len]);
    drawnow
  end

end

fprintf(1,'Done.\n');

return
