disp(' ');
disp(' RD_n.m  ver 1.1  March 12, 2013'); 
disp(' by Tom Irvine  Email: tom@vibrationdata.com ');
disp(' ');
disp(' This script calculates the Miners cumulative damage index (CDI) ');
disp(' for an electronic component, using an extension of Steinbergs ');
disp(' fatigue method.')
%
clear rd;
clear THM;
clear length;
%
disp(' ');
disp(' The input file must have two columns: ');
disp('      relative displacement peak-to-peak (inch)  & 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)
        FS = input(' Enter the matrix name:  ','s');
        THM=evalin('caller',FS);
end
if(file_choice==3)
        [filename, pathname] = uigetfile('*.*');
        xfile = fullfile(pathname, filename);
%        
        THM = xlsread(xfile);
%         
end
%
disp(' ');
Z=input(' Enter Z 3-sigma limit (inch) ');
%
n=length(THM(:,1));
%
CDI=0;

%
rd=THM(:,1)/2;  %  convert to zero-to-peak
%
rd_Z_ratio = rd/Z;
%
iflag=0;
%
for i=1:n
%
    cycles=THM(i,2);
%
    if(rd_Z_ratio(i)>=6)
        disp(' Failure:  relative displacement exceeds upper limit. ');
        iflag=1;
        break;  
    end
%
    N=10^(6.05-6.4*log10(rd_Z_ratio(i)));
%
    d=(cycles/N);
%
    CDI=CDI+d;
%
end
%
if(iflag==0)
%
    out1=sprintf(' Miners CDI = %6.3g',CDI);
    disp(out1);
%
    disp(' ');
    iq=input(' Extrapolate damage CDI to longer durations?  1=yes  2=no ');
    disp(' ');
%
    if(iq==1)
        nd=input(' Enter duration multiplier ');
        disp(' ');
        out1=sprintf(' Miners CDI * %6.3g = %6.3g',nd,CDI*nd);
        disp(out1);
%    
    end
%
end