function Efrac =frcenbar(xloc,phic,numdiv,nn)
%
%  Name:  frcenbar.m
%
%  Usage: 
%
%    Calculates the fractional strain energy for a bar element
%
%  Input:
%  Nodes = List of nodes in DIAMOND geometry format
%  barnodes = 2-element vector containing indices of nodes for this bar
%	phi = Mode shape value at each end of the bar element, for each mode
%  interpopt = 'linear','spline', or 'cubic'
%  numdiv = number of subdivisions for the bar
%  mode_anal=vector of modes to use
%
%  Output:
%	Etot(i)=total strain energy in the element for mode i
% 	Efrac(i,j)=energy in the jth subdivision of the element for the ith mode
%

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

%
% Define the parameters for the numerical integration
%

%nn=5;  % Numerically integrate at 5 points across each element subdivision

nmode = size(phic,2);

%
%  Determine the Length of the bar

%L = norm(xloc(end)-xloc(1));

%
%  Determine integration points

% Initialize Efrac and Etot

Efrac = zeros(nmode,numdiv);

%
% Loop over the number of modes
%

for i = 1:nmode
   
   %phicfit=interp1(xloc,phic(:,i),xfit,interpopt);
   
   for j=1:numdiv
      
   	xvalues=xloc( (j-1)*nn + 1 : j*nn + 1);
	   phicvalues=phic( (j-1)*nn+1 : j*nn + 1,i).^2;
      Efrac(i,j)=trapz(xvalues,phicvalues);
      
   end
   
end


