close all 
clear all;
%Create .spec file
 lengths = [100 250 500 1000 1500 2000 3000 4000];  %meters
 periods = 4:.5:16  %sec
 
 amp = 1/.0254/12;
 
 for m = 1:size(lengths,2)
 length = lengths(m)
 
 for n = 1:size(periods,2)
 per = periods(n)
 omega = 2*pi/per
 fid = fopen('Cable.spec','w');
 fprintf(fid,'#define LENGTH %6.3f \n',length);
 fprintf(fid,'#define NNODES %d \n',length); 
 fprintf(fid,'#define AMP %6.3f \n',amp);
 fprintf(fid,'#define PER %6.3f \n',per);
  fprintf(fid,'#define OMEGA %6.3f \n',omega);
 fclose(fid);
 clear fid
 
 
 results_filenm = ['Results'];
 cmd = ['!cable.exe -in winchdeploy.cab -out ',results_filenm,'.crs -quit -first -last -sample 0.2 -snap_dt 10'];
 eval(cmd);
 
 cmd = ['!res2mat.exe -in ',results_filenm,'.crs -out ',results_filenm,'.mat -totals -lbs'];
 eval(cmd);
 
load Results 

MaxT(m,n) = max(T_t(round(size(t,1)/2):end,2))
MeanT(m,n) = mean(T_t(round(size(t,1)/2):end,2))
MinT(m,n) = min(T_t(round(size(t,1)/2):end,2))

MaxAmp(m,n,1) = max(z_t(round(size(t,1)/2):end,1)-mean(z_t(round(size(t,1)/2):end,1)))
MaxAmp(m,n,2) = max(z_t(round(size(t,1)/2):end,2)-mean(z_t(round(size(t,1)/2):end,2)))

RAO(m,n) = MaxAmp(m,n,1)/MaxAmp(m,n,2)

DynamicLoad = MaxT-MeanT

%figure
%plot(t,T_t)

%figure
%plot(t,z_t(:,1)-mean(z_t(:,1)),t,z_t(:,2)-mean(z_t(:,2)))

if (m > 1) 
figure(1)
plot(periods,DynamicLoad)
xlabel('Period');
ylabel('Dynamic Loads (lbs)');

figure(2)
plot(periods,RAO);
xlabel('Period');
ylabel('RAO');
end

end

end

DynamicLoad = MaxT-MeanT

figure(1)
plot(periods,DynamicLoad(1,:),periods,DynamicLoad(2,:),periods,DynamicLoad(3,:),periods,DynamicLoad(4,:))
xlabel('Period');
ylabel('Dynamic Loads (lbs)');
legend('100m','250m','500m','1000m');
title('Dynamic loads at various depths and periods for 1 meter amplitude ship motion');
print -depsc2  'DynLoad-Wire'
 

figure(2)
plot(periods,RAO(1,:),periods,RAO(2,:),periods,RAO(3,:),periods,RAO(4,:),periods,RAO(6,:),periods,RAO(8,:))
xlabel('Period');
ylabel('RAO');
legend('100m','250m','500m','1000m','2000m','4000m');
title('BIN motion relative to 1 meter amplitude ship motion');
print -depsc2  'RAO-Wire'

figure(3)
subplot(2,1,1)
plot(periods,DynamicLoad(1,:),periods,DynamicLoad(3,:),periods,DynamicLoad(4,:),periods,DynamicLoad(6,:))
xlabel('Period');
ylabel('Dynamic Loads (lbs)');
legend('100m','500m','1000m','2000m');
xlim([5 16])

subplot(2,1,2)
plot(periods,RAO(1,:),periods,RAO(3,:),periods,RAO(4,:),periods,RAO(6,:),periods,RAO(8,:))
xlabel('Period');
ylabel('RAO');
legend('100m','500m','1000m','2000m','4000m');
xlim([5 16])
print -depsc2 'Wire-Results'



