close all
clear all

pdf = 1;  %This option prints the plots as individual .pdf files.
ps = 1;  %This option puts all plots into one .ps file.  To make this into a .pdf use "ps2pdf -sPAPERSIZE=11x17 print_filenm.ps"


print_filenm = 'DelMar_Comparisons';





  name = 'del_mar_hamilton_v0';

  ENV.depth = 100;
  ENV.tf = 330; 
  ENV.dt = .01;
  ENV.ramptime = 30;
  ENV.xwaveamp = 2.5;
  ENV.xwaveperiod = 15;
  ENV.xwavephase = 0;
  ENV.xwind = 20;

  ENV.currentscale = 1;

  ENV.forcing_type =  'velocity'; %'velocity';  % -or- 'wave-follower'
 
  ENV.input_type = 'random';  % -or- 'random'

  LAYOUT.config = 1;  %0 = no esp, no stretch-hose
		      %1 = esp directly in line with nilspin at 15m depth, no stretch-hose
 
  config = [0 1 2];

  for i = 1:length(config)
    LAYOUT.config = config(i);

    filenm = make_filename(ENV,LAYOUT,name);
    filenm


    results{i} = load([filenm '.mat']);
  end


Condition_String = ['Wave Amp = ' num2str(ENV.xwaveamp) ' m   Wave Period = ' num2str(ENV.xwaveperiod) ' s'];

figure('Position',[222 546 1390 922],'PaperType','tabloid','PaperOrientation','landscape','PaperPositionMode','auto','PaperPosition',[.5 .5 16.5 10.5])

legend_str{1} = 'No ESP, No Stretch Hose';
legend_str{2} = 'ESP In-Line at 15m depth, No Stretch Hose';
legend_str{3} = 'ESP In-Line at 15m depth, 5m Stretch Hose';


%Compare Static Positions
subplot(1,2,1)
plot(results{1}.x,results{1}.z);
hold all
plot(results{2}.x,results{2}.z);
plot(results{3}.x,results{3}.z);
legend(legend_str,'Location','NorthWest');
xlabel('m');
ylabel('m');

%Compare Static Tensions along mooring line
subplot(1,2,2)
plot(results{1}.s,results{1}.T);
hold all
plot(results{2}.s,results{2}.T);
plot(results{3}.s,results{3}.T);
legend(legend_str,'Location','NorthWest');
xlabel('Distance from Anchor along mooring line');
ylabel('Tension (lbs)');

print('-dpsc2','foo');

if(pdf) print('-dpdf',[print_filenm '_StaticPositionComparisons']); end
if(ps) print('-dpsc2',print_filenm); end



figure('Position',[222 546 1390 922],'PaperType','tabloid','PaperOrientation','landscape','PaperPositionMode','auto','PaperPosition',[.5 .5 16.5 10.5])
%Plot Dynamic Positions
subplot(1,3,1)
plot(results{1}.x_s,results{1}.z_s);
title(legend_str{1});
xlabel('m');
ylabel('m');

%Plot Dynamic Positions
subplot(1,3,2)
plot(results{2}.x_s,results{2}.z_s);
title(legend_str{2});
xlabel('m');
ylabel('m');

%Plot Dynamic Positions
subplot(1,3,3)
plot(results{3}.x_s,results{3}.z_s);
title(legend_str{3});
xlabel('m');
ylabel('m');

if(pdf) print('-dpdf',[print_filenm '_DynamicPositionComparisons']); end
if(ps) print('-dpsc2','-append',print_filenm); end

figure('Position',[222 546 1390 922],'PaperType','tabloid','PaperOrientation','landscape','PaperPositionMode','auto','PaperPosition',[.5 .5 16.5 10.5])


subplot(1,2,1)
%Compare Dynamic Tensions at Buoy
plot(results{1}.t,results{1}.T_t(:,end));
hold all
plot(results{2}.t,results{2}.T_t(:,end));
plot(results{3}.t,results{3}.T_t(:,end));

legend(['No ESP, No Stretch Hose  -  Mean = ' num2str(mean(results{1}.T_t(:,end)),4) ' lbs  -  Std Dev = ' num2str(sqrt(var(results{1}.T_t(:,end))),3) ' lbs'], ...
       ['ESP In-Line at 15m depth, No Stretch Hose  -  Mean = ' num2str(mean(results{2}.T_t(:,end)),4) ' lbs  -  Std Dev = ' num2str(sqrt(var(results{2}.T_t(:,end))),3) ' lbs'], ...
       ['ESP In-Line at 15m depth, 5m Stretch Hose  -  Mean = ' num2str(mean(results{3}.T_t(:,end)),4) ' lbs  -  Std Dev = ' num2str(sqrt(var(results{3}.T_t(:,end))),3) ' lbs'], ...
	'Location','NorthWest');
xlabel('time (s)');
ylabel('Tension (lbs)');
title(['Tensions At Buoy  - ' Condition_String]);

subplot(1,2,2)
%Compare Dynamic Tensions at Anchor
plot(results{1}.t,results{1}.T_t(:,1));
hold all
plot(results{2}.t,results{2}.T_t(:,1));
plot(results{3}.t,results{3}.T_t(:,1));
legend(legend_str,'Location','NorthWest');
xlabel('time (s)');
ylabel('Tension (lbs)');
title('Tensions At Anchor');

if(pdf) print('-dpdf',[print_filenm '_AnchorBuoyTensionComparisons']); end
if(ps) print('-dpsc2','-append',print_filenm); end



figure('Position',[222 546 1390 922],'PaperType','tabloid','PaperOrientation','landscape','PaperPositionMode','auto','PaperPosition',[.5 .5 16.5 10.5])

subplot(1,2,1)
%Compare Dynamic Tensions at ESP Location (top of Nilspin versus just below ESP)
loc_0 = 5;
loc_1 = 5;
loc_2 = 5;
plot(results{1}.t,results{1}.T_t(:,loc_0));
hold all
plot(results{2}.t,results{2}.T_t(:,loc_1));
plot(results{3}.t,results{3}.T_t(:,loc_2));


legend(['No ESP, No Stretch Hose  -  Mean = ' num2str(mean(results{1}.T_t(:,loc_0)),4) ' lbs  -  Std Dev = ' num2str(sqrt(var(results{1}.T_t(:,loc_0))),3) ' lbs'], ...
       ['ESP In-Line at 15m depth, No Stretch Hose  -  Mean = ' num2str(mean(results{2}.T_t(:,loc_1)),4) ' lbs  -  Std Dev = ' num2str(sqrt(var(results{2}.T_t(:,loc_1))),3) ' lbs'], ...
       ['ESP In-Line at 15m depth, 5m Stretch Hose  -  Mean = ' num2str(mean(results{3}.T_t(:,loc_2)),4) ' lbs  -  Std Dev = ' num2str(sqrt(var(results{3}.T_t(:,loc_2))),3) ' lbs'], ...
	'Location','NorthWest');
xlabel('time (s)');
ylabel('Tension (lbs)');
title(['Tensions Below ESP Location  - ' Condition_String]);


subplot(1,2,2)
%Compare Dynamic Tensions at ESP Location (top of Nilspin versus just above ESP)
loc_0 = 5;
loc_1 = 7;
loc_2 = 7;
plot(results{1}.t,results{1}.T_t(:,loc_0));
hold all
plot(results{2}.t,results{2}.T_t(:,loc_1));
plot(results{3}.t,results{3}.T_t(:,loc_2));

legend(['No ESP, No Stretch Hose  -  Mean = ' num2str(mean(results{1}.T_t(:,loc_0)),4) ' lbs  -  Std Dev = ' num2str(sqrt(var(results{1}.T_t(:,loc_0))),3) ' lbs'], ...
       ['ESP In-Line at 15m depth, No Stretch Hose  -  Mean = ' num2str(mean(results{2}.T_t(:,loc_1)),4) ' lbs  -  Std Dev = ' num2str(sqrt(var(results{2}.T_t(:,loc_1))),3) ' lbs'], ...
       ['ESP In-Line at 15m depth, 5m Stretch Hose  -  Mean = ' num2str(mean(results{3}.T_t(:,loc_2)),4) ' lbs  -  Std Dev = ' num2str(sqrt(var(results{3}.T_t(:,loc_2))),3) ' lbs'], ...
	'Location','NorthWest');
xlabel('time (s)');
ylabel('Tension (lbs)');
title(['Tensions Above ESP Location  - ' Condition_String]);

if(pdf) print('-dpdf',[print_filenm '_ESP_Location_TensionComparisons']); end
if(ps) print('-dpsc2','-append',print_filenm); end


figure('Position',[222 546 1390 922],'PaperType','tabloid','PaperOrientation','landscape','PaperPositionMode','auto','PaperPosition',[.5 .5 16.5 10.5])

subplot(1,2,1)
%Compare Axial Accelerations at ESP Location (top of Nilspin versus just below ESP)
loc_0 = 5;
loc_1 = 7;
loc_2 = 7;
plot(results{1}.t,[0; diff(results{1}.u_t(:,loc_0))/results{1}.dt]);
hold all
plot(results{2}.t,[0; diff(results{2}.u_t(:,loc_1))/results{2}.dt]);
plot(results{3}.t,[0; diff(results{3}.u_t(:,loc_2))/results{3}.dt]);

legend(['No ESP, No Stretch Hose  -  Max = ' num2str(max(abs(diff(results{1}.u_t(:,loc_0))/results{1}.dt)),4) ' m/s^2  -  Std Dev = ' num2str(sqrt(var(diff(results{1}.u_t(:,loc_0))/results{1}.dt)),3) ' m/s^2'], ...
       ['ESP In-Line at 15m depth, No Stretch Hose  -  Max = ' num2str(max(abs(diff(results{2}.u_t(:,loc_1))/results{2}.dt)),4) ' m/s^2  - Std Dev = ' num2str(sqrt(var(diff(results{2}.u_t(:,loc_1))/results{2}.dt)),3) ' m/s^2'], ...
       ['ESP In-Line at 15m depth, 5m Stretch Hose  -  Max = ' num2str(max(abs(diff(results{3}.u_t(:,loc_2))/results{3}.dt)),4) ' m/s^2  -  Std Dev = ' num2str(sqrt(var(diff(results{3}.u_t(:,loc_2))/results{3}.dt)),3) ' m/s^2'], ...
	'Location','NorthWest');
xlabel('time (s)');
ylabel('Axial Accelerations (m/s^2)');
title(['Axial Accelerations at ESP Location  - ' Condition_String]);

subplot(1,2,2)
%Compare Normal Accelerations at ESP Location (top of Nilspin versus just below ESP)
plot(results{1}.t,[0; diff(results{1}.v_t(:,loc_0))/results{1}.dt]);
hold all
plot(results{2}.t,[0; diff(results{2}.v_t(:,loc_1))/results{2}.dt]);
plot(results{3}.t,[0; diff(results{3}.v_t(:,loc_2))/results{3}.dt]);

legend(['No ESP, No Stretch Hose  -  Max = ' num2str(max(abs(diff(results{1}.v_t(:,loc_0))/results{1}.dt)),4) ' m/s^2  -  Std Dev = ' num2str(sqrt(var(diff(results{1}.v_t(:,loc_0))/results{1}.dt)),3) '  m/s^2'], ...
       ['ESP In-Line at 15m depth, No Stretch Hose  -  Max = ' num2str(max(abs(diff(results{2}.v_t(:,loc_1))/results{2}.dt)),4) ' m/s^2  Std Dev = ' num2str(sqrt(var(diff(results{2}.v_t(:,loc_1))/results{2}.dt)),3) '  m/s^2'], ...
       ['ESP In-Line at 15m depth, 5m Stretch Hose  -  Max = ' num2str(max(abs(diff(results{3}.v_t(:,loc_2))/results{3}.dt)),4) ' m/s^2  Std Dev = ' num2str(sqrt(var(diff(results{3}.v_t(:,loc_2))/results{3}.dt)),3) '  m/s^2'], ...
	'Location','NorthWest');
xlabel('time (s)');
ylabel('Normal Accelerations (m/s^2)');
title(['Normal Accelerations at ESP Location  - ' Condition_String]);


print('-dpdf','DelMar_ESP_Accel_Comparison');
if(pdf) print('-dpdf',[print_filenm '_ESP_Accel_Comparison']); end
if(ps) print('-dpsc2','-append',print_filenm); end


if(0*ps) 
cmd = (['ps2pdf -sPAPERSIZE=11x17 ' print_filenm '.ps']);
system(cmd);
end

