%
%   ODE_acceleration_input.m   ver 1.2  November 18, 2013
%
function[FFI,accel_dof,nff,nem,nfree,enforced_dof,free_dof,ngw]=...
                          ODE_acceleration_input(iu,ndof,NT,t,file_choice)
%
num=ndof;
%
if(iu==1)
    disp(' Each acceleration file must have two columns: time(sec) & accel(in/sec^2) ');
end
if(iu==2)
    disp(' Each acceleration file must have two columns: time(sec) & accel(G) ');
end
if(iu==3)
    disp(' Each acceleration file must two columns: time(sec) & accel(m/sec^2) ');
end
%
disp(' ');
disp(' Enter the number of acceleration files ');
%
nff=input(' ');
%
MAX=100000;
%
tt=zeros(MAX,nff);
ff=zeros(MAX,nff);
%
accel_dof=zeros(ndof,1);
%
for i=1:ndof
    accel_dof(i)=-999;
end    
%    
disp(' ');
disp(' Note: the first dof is 1 ');
%
for i=1:nff
    disp(' ');
    out1=sprintf(' Enter acceleration file %d ',i);
    disp(out1);
% 
    if(file_choice==1)
        FS = input(' Enter the matrix name:  ','s');
        F=evalin('caller',FS);
    end
    if(file_choice==2)
        [filename, pathname] = uigetfile('*.*');
        xfile = fullfile(pathname, filename);
%        
        F = xlsread(xfile);
%         
    end
%    
    a=F(:,1);
    b=F(:,2);
%    
    L=length(a);
%    
    if(L>MAX)
        L=MAX;
    end
%    
    tt(1:L,i)=a(1:L);
    ff(1:L,i)=b(1:L);
%    
    disp(' ');
    disp(' Enter the number of dofs at which this acceleration is applied ');   
%   
    nfa=input(' '); 
%   
    for j=1:nfa
        disp(' ');
%
        if(j==1 && nfa==1)
            disp(' Enter the dof number for this acceleration ');
        end    
        if(j==1 && nfa>1)        
            disp(' Enter the first dof number for this acceleration ');
        end
        if(j>1 && nfa>1)        
            disp(' Enter the next dof number for this acceleration ');        
        end
        nn=input(' ');
        accel_dof(nn)=i;
    end
end 
%
% interpolate force
%
disp(' begin interpolation ');
%
FFI=zeros(NT,nff);
%
for i=1:nff
%
    clear tint;
    clear fint;
%
    tstart=tt(1,i);
    tt(:,i)=tt(:,i)-tstart;   
%
    last=MAX;
%    
    for(j=2:MAX)
        if(tt(j,i)<=tt(j-1,i))
            last=j-1;
            break
        end
    end      
%
    tint=tt(1:last,i);
    fint=ff(1:last,i);
%
    t=t';
    FFI(:,i) = interp1(tint,fint,t);
%
end 
%
if(iu==2)
    FFI=FFI*386;
end
%
j=1;
k=1;
for i=1:num
    if(accel_dof(i)>0)
        enforced_dof(k)=i;
        k=k+1;
    else
        free_dof(j)=i;
        j=j+1;
    end
end
%
nem=length(enforced_dof);
nfree=length(free_dof);
%
for i=1:nem
    ngw(i)=enforced_dof(i);
end
for i=1:nfree
    ngw(i+nem)=free_dof(i);
end
%
clear temp;
temp=sort(enforced_dof,'descend');
enforced_dof=temp;
%
clear temp;
temp=sort(free_dof,'descend');
free_dof=temp;
%
disp(' end interpolation ');
%