%
%  continuous_beam_base_PSD.m  ver 1.1  October 15, 2012
%
function[fig_num,psd_resp,rd_psd,acc_power_trans,rd_power_trans]=...
      continuous_beam_base_PSD(iu,acc_trans,rd_trans,fig_num)
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
disp(' ');
disp(' The input PSD must have two columns:  freq(Hz) & PSD(G^2/Hz)');
disp(' ');
disp(' Select file input method for input PSD ');
disp('   1=external ASCII file ');
disp('   2=file preloaded into Matlab ');
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';
else
   FS = input(' Enter the matrix name:  ','s');
   THM=evalin('caller',FS);   
end
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
PSD_in=THM;
%
[psd_resp]=psd_mult_trans(PSD_in,acc_trans);
%
[~,rms_base]=calculate_PSD_slopes(PSD_in(:,1),PSD_in(:,2));
[~,rms]=calculate_PSD_slopes(psd_resp(:,1),psd_resp(:,2));
%
leg_a=sprintf('Base Input %5.2g GRMS',rms_base);
leg_b=sprintf('Response %5.2g GRMS',rms);
%     
t_string=sprintf('Accel PSD'); 
x_label=sprintf(' Frequency(Hz) ');
y_label=sprintf(' Accel(G^2/Hz) ');
%
[fig_num]=...
plot_PSD_two(fig_num,x_label,y_label,t_string,PSD_in,psd_resp,leg_a,leg_b);
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
disp(' ');
out1=sprintf('  Acceleration Response:  %8.3g GRMS',rms);
disp(out1);
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
[rd_psd]=psd_mult_trans(PSD_in,rd_trans);
%
[~,rms]=calculate_PSD_slopes(rd_psd(:,1),rd_psd(:,2));
%
if(iu==1)
    t_string=sprintf('Relative Displacement PSD %6.3g inch RMS',rms);
else
    t_string=sprintf('Relative Displacement PSD %6.3g m RMS',rms);    
end
%
x_label=sprintf(' Frequency(Hz) ');
y_label=sprintf(' Disp(in^2/Hz) ');
%
[fig_num]=plot_PSD(fig_num,x_label,y_label,t_string,rd_psd);      
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
disp(' ');
if(iu==1)
    out1=sprintf('Relative Displacement Response:  %8.3g inch RMS',rms);
else
    out1=sprintf('Relative Displacement Response:  %8.3g m RMS',rms);    
end
disp(out1);
% 
n=length(acc_trans(:,1));
%
acc_power_trans=zeros(n,1);
 rd_power_trans=zeros(n,1);
%
acc_power_trans(:,1)=acc_trans(:,1);
 rd_power_trans(:,1)= rd_trans(:,1);
%
for i=1:n
    acc_power_trans(i,2)=acc_trans(i,2)^2;
     rd_power_trans(i,2)= rd_trans(i,2)^2;
end