function [xloc,Efrac,Etot]=fracten(x,phi,interpchoice,numdiv,mode_anal)
%
%  Name:  fracten.m
%
%  Usage:  [xfit,Efrac,Etot]=fracten(x,phi,interpchoice,numdiv,mode_anal)
%
%  This m-file calculated the fractional energies for each mode
%
%   input:
%	x=xlocations of the beam from xlow to xhigh
%	phi=y displacements of mode shapes corresponding to x
%	interpchoice=linear,spine and cubic	
%  	numdiv=number of subdivisions for the beam
%  	mode_anal=vector of modes to use
%
%   output:
%	xfit=xlocation of the divided beam
%	Etot(i)=total strain energy for mode i
% 	Efrac(i,j)=energy of the jth element of the ith mode
%
%  Version SWD970115
%
%  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 number of subdivisions for the numerical integration
%

nn=5;
dx=(max(x)-min(x))/(numdiv*nn);
xfit=min(x):dx:max(x);
xloc=min(x):dx*nn:max(x);
%
% Loop over the number of modes
%
for i=mode_anal
   phifit=interp1(x,phi(:,i),xfit,interpchoice);
   phifitp=gradient(phifit,dx);
   phifitpp=gradient(phifitp,dx);
   phifitpp2=phifitpp.*phifitpp;
   for j=1:numdiv
   	xvalues=xfit((j-1)*nn+1:j*nn+1);
	phipp2values=phifitpp2((j-1)*nn+1:j*nn+1);
	Efrac(i,j)=trapz(xvalues,phipp2values);
   end
   Etot(i)=sum(Efrac(i,:));
end
