close all
clear all

Jan = load('January2012DeploymentSummaryData.mat');
Jun = load('June2012DeploymentSummaryData');
Nov = load('November2012DeploymentSummaryData.mat');
April = load('April2013DeploymentSummaryData.mat');
Sept = load('Sept2013DeploymentSummaryData.mat');


yi_Controller = ceil(Nov.yi_Controller);


idx_resistive = find(yi_Controller == 1);
idx_scheduled = find(yi_Controller == 2);
idx_latching = find(yi_Controller == 3);

idx_scheduled = idx_scheduled(1:end-83);


%Compute Mean Lines


Nov_Mean = mean(Nov.yi_meas(1:405));
Jun_Mean = mean(Jun.yi_meas);
Jan_Mean = mean(Jan.yi_meas);
April_Mean = mean(April.yi_meas);
Sept_Mean = mean(Sept.yi_meas);


figure('Position',[19 45 1538 1093],'PaperPositionMode','manual','PaperType','usletter','PaperPosition',[0 0 11 8.5],'PaperOrientation','landscape');
set(gca,'FontSize',20);
plot(Jan.yi_meas,100*Jan.yi_meas./Jan.yi_max,'kd',...
     Jun.yi_meas,100*Jun.yi_meas./Jun.yi_max,'x',...
     Nov.yi_meas(1:405),100*Nov.yi_meas(1:405)./Nov.yi_max(1:405),'ro',...
     April.yi_meas,100*April.yi_meas./April.yi_max,'go',...
     Sept.yi_meas,100*Sept.yi_meas./Sept.yi_max,'mo'...
     );
legend('January 2012 Deployment','June 2012 Deployment','November 2012 Deployment','May 2013 Deployment','Sept 2013 Deployment','Location','NorthWest');
xlabel('Rectified Power (Watts)');
ylabel('Percentage of Theoretical Maximum');
print('PercentageOfMaxVsRectifiedPower','-dpdf');
print('PercentageOfMaxVsRectifiedPower','-dpng');



figure('Position',[19 45 1538 1093],'PaperPositionMode','manual','PaperType','usletter','PaperPosition',[0 0 11 8.5],'PaperOrientation','landscape');
set(gca,'FontSize',20);
plot(Jan.yi_Hs,100*Jan.yi_meas./Jan.yi_max,'kd',...
     Jun.yi_Hs,100*Jun.yi_meas./Jun.yi_max,'x',...
     Nov.yi_Hs(1:405),100*Nov.yi_meas(1:405)./Nov.yi_max(1:405),'ro',...
     April.yi_Hs,100*April.yi_meas./April.yi_max,'go',...
     Sept.yi_Hs,100*Sept.yi_meas./Sept.yi_max,'mo'...     
 );
legend('January 2012 Deployment','June 2012 Deployment','November 2012 Deployment','May 2013 Deployment','Sept 2013 Deployment','Location','SouthEast');
xlabel('Significant Wave Height (m)');
ylabel('Percentage of Theoretical Maximum');
print('PercentageOfMaxVsWaveHeight','-dpdf');
print('PercentageOfMaxVsWaveHeight','-dpng');


figure('Position',[19 45 1538 1093],'PaperPositionMode','manual','PaperType','usletter','PaperPosition',[0 0 11 8.5],'PaperOrientation','landscape');
set(gca,'FontSize',20);
plot(Jan.yi_Hs,Jan.yi_meas,'kd',...
     Jun.yi_Hs,Jun.yi_meas,'x',...
     Nov.yi_Hs(1:405),Nov.yi_meas(1:405),'ro',...
     April.yi_Hs,April.yi_meas,'go',...
     Sept.yi_Hs,Sept.yi_meas,'mo'...
 );
legend(['January 2012 Deployment: Mean = ' num2str(Jan_Mean,3) ' Watts'],...
       ['June 2012 Deployment: Mean = ' num2str(Jun_Mean,3) ' Watts'],...
       ['November 2012 Deployment: Mean = ' num2str(Nov_Mean,3) ' Watts'],...
       ['May 2013 Deployment: Mean = ' num2str(April_Mean,3) ' Watts'],...
       ['Sept 2013 Deployment: Mean = ' num2str(Sept_Mean,3) ' Watts'],...
       'Location','SouthEast');
xlabel('Significant Wave Height (m)');
ylabel('Rectified Power (W)');
print('RectifiedPowerVsWaveHeight','-dpdf');
print('RectifiedPowerVsWaveHeight','-dpng');

idx_Jun = find(Jun.yi_Hs < 2);
idx_Nov = find(Nov.yi_Hs < 2);
idx_Apr = find(April.yi_Hs < 2);
idx_Sept = find(Sept.yi_Hs < 2);

A = [Jun.yi_Hs(idx_Jun)'  ones(length(idx_Jun),1)];
B = 100*Jun.yi_meas(idx_Jun)'./Jun.yi_max(idx_Jun)';
x_Jun = A\B;

A = [Nov.yi_Hs(idx_Nov)'  ones(length(idx_Nov),1)];
B = 100*Nov.yi_meas(idx_Nov)'./Nov.yi_max(idx_Nov)';
x_Nov = A\B;

A = [April.yi_Hs(idx_Apr)'  ones(length(idx_Apr),1)];
B = 100*April.yi_meas(idx_Apr)'./April.yi_max(idx_Apr)';
x_Apr = A\B;

A = [Sept.yi_Hs(idx_Sept)'  ones(length(idx_Sept),1)];
B = 100*Sept.yi_meas(idx_Sept)'./Sept.yi_max(idx_Sept)';
x_Sept = A\B;


figure('Position',[19 45 1538 1093],'PaperPositionMode','manual','PaperType','usletter','PaperPosition',[0 0 11 8.5],'PaperOrientation','landscape');
set(gca,'FontSize',20);
plot(Jun.yi_Hs(idx_Jun),100*Jun.yi_meas(idx_Jun)./Jun.yi_max(idx_Jun),'x',...
     Nov.yi_Hs(idx_Nov),100*Nov.yi_meas(idx_Nov)./Nov.yi_max(idx_Nov),'ro',...
     April.yi_Hs(idx_Apr),100*April.yi_meas(idx_Apr)./April.yi_max(idx_Apr),'go',...
     Sept.yi_Hs(idx_Sept),100*Sept.yi_meas(idx_Sept)./Sept.yi_max(idx_Sept),'mo',...
     Jun.yi_Hs(idx_Jun),x_Jun(1)*Jun.yi_Hs(idx_Jun)+x_Jun(2),'-b',...
     Nov.yi_Hs(idx_Nov),x_Nov(1)*Nov.yi_Hs(idx_Nov)+x_Nov(2),'-r',...
     April.yi_Hs(idx_Apr),x_Apr(1)*April.yi_Hs(idx_Apr)+x_Apr(2),'-g',...
     Sept.yi_Hs(idx_Sept),x_Sept(1)*Sept.yi_Hs(idx_Sept)+x_Sept(2),'-m'...
 );
legend('June Deployment','November Deployment','May Deployment','Sept Deployment','Location','NorthWest');
xlabel('Significant Wave Height (m)');
ylabel('Percentage of Theoretical Maximum');
print('PercentageOfMaxVsWaveHeightLessThan2m','-dpdf');
print('PercentageOfMaxVsWaveHeightLessThan2m','-dpng');

