disp(' ');
disp(' fatigue_damage_sum.m  ver 1.1  by Tom Irvine');
disp(' ');
disp(' This script calculates a relative damage index ');
disp(' for a rainflow output. ');
%
%
clear b;
clear THM;
clear length;
%
disp(' ');
disp(' The input array must have two columns: ');
disp('  amplitude & cycles ');
disp(' ');
%
disp(' Select file input method ');
disp('   1=external ASCII file ');
disp('   2=file preloaded into Matlab ');
disp('   3=Excel file ');
file_choice = input('');
%
if(file_choice==1)
        [filename, pathname] = uigetfile('*.*');
        filename = fullfile(pathname, filename);
        fid = fopen(filename,'r');
        THM = fscanf(fid,'%g %g',[2 inf]);
        THM=THM';
end
if(file_choice==2)
        THM=input(' Enter array name:  ');
end
if(file_choice==3)
        [filename, pathname] = uigetfile('*.*');
        xfile = fullfile(pathname, filename);
%        
        THM = xlsread(xfile);
%         
end
%
disp(' ');
b = input(' Enter the fatigue exponent: ');
disp(' ');
%
num=length(THM(:,1));
%
damage=0;
for(i=1:num)
   damage=damage+THM(i,2)*(THM(i,1))^b;
end
%
out1=sprintf(' relative damage index =  %8.4g ',damage);
disp(out1);