close all
clear all



BaseFolder = 'MonoChromaticRun';
ResultsFolder = 'latest_batch_results';

results_table = readtable(['../' BaseFolder '/' ResultsFolder '/batch_runs.log']);
table_size = size(results_table);

for i = 1:table_size(1)
  files = dir(['../' BaseFolder '/' ResultsFolder '/' results_table.pblogFilename{i} '/../matlab/*_raw.mat']);
  results_data{i} = load([files.folder '\' files.name]);

disp(num2str(i));
end


A = 0.25;
T = [15 30 60 90];

for i = 1:length(T)
figure
subplot(3,1,1)
t = (results_data{i}.XB_Time-results_data{i}.XB_Time(1))*24*3600;
plot(t,results_data{i}.XB_Alt-mean(results_data{i}.XB_Alt)); 
hold all;
plot(t,A*cos(2*pi*t/T(i)));
xlabel('time (s)');
ylabel('meters');
grid on;
title(['A = ' num2str(A) 'm   T = ' num2str(T(i)) 's'])
legend('Heave pos','wave height')

subplot(3,1,2)
t = (results_data{i}.SC_Time-results_data{i}.SC_Time(1))*24*3600;
pos = results_data{i}.SC_Range;
plot(t,results_data{i}.SC_Range)
ylim([min(pos(800:end)) max(pos(800:end))]);
xlabel('time (s)');
ylabel('Piston Pos (in)');
grid on;

subplot(3,1,3)
t = (results_data{i}.PC_Time-results_data{i}.PC_Time(1))*24*3600;
rpm = results_data{i}.PC_RPM;
plot(t,rpm)
ylim([min(rpm(800:end)) max(rpm(800:end))]);
xlabel('time (s)');
ylabel('RPM');
grid on;


print(['MonoChromaticResults_A' num2str(A) '_T' num2str(T(i)) '.pdf'],'-dpdf','-fillpage');
end
