%
disp(' ');
disp(' cubic_spline.m  ver 1.0  August 22, 2011 ');
disp(' by Tom Irvine  Email: tomirvine@aol.com ');
disp(' ');
%
clear length;
clear x;
clear y;
clear xx;
clear yy;
clear THM;
%
    disp(' The time history must be in a two-column matrix format: ')
    disp(' Time(sec)  & amplitude ')
    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 the matrix name:  ');
    end
    if(file_choice==3)
        [filename, pathname] = uigetfile('*.*');
        xfile = fullfile(pathname, filename);
%        
        THM = xlsread(xfile);
%         
    end
%
    x=double(THM(:,1));
    y=double(THM(:,2));   
    n = length(x);
%
figure(1);
plot(x,y)
title('Input Data');
xlabel('Time (sec)');
grid on;
%
disp(' ');
disp(' Enter new sample rate (samples/sec)');
sr=input(' ');
dt=1/sr;
%
i=0;
%
np=round((x(n)-x(1))/dt);
np=np+1;
%
xx=linspace(x(1),x(n),np); 
%
out1=sprintf('\n number of interpolated points = %d \n',length(xx));
disp(out1);
%
yy = spline(x,y,xx);
figure(2);
plot(xx,yy)
title('Interpolated Data');
xlabel('Time (sec)');
grid on;
%
sz=size(xx);
if(sz(2)>sz(1))
    xx=xx';
end
%
sz=size(yy);
if(sz(2)>sz(1))
    yy=yy';
end
interpolated = [xx yy];
%
disp(' ');
disp(' Output array name:  interpolated ');