close all
clear all

ModelledResultsPath = '.\ModelResults\';

MeasuredResultsPath = '.\MeasuredResults\';


%files = dir([ModelledResultsPath 'amscale_2.5*.mat']);

files = dir([ModelledResultsPath 'amscale_2.75*platecd_2_*.mat']);

plot_num = 0;
for i = 1:length(files);
    
  ModelResults = LoadModelResults([ModelledResultsPath files(i).name]);
  Hs(i) = ModelResults.Hs;
  Tp(i) = ModelResults.Tp;
  Budal_Limit(i) = ModelResults.BudalLimit;
  
  Model_meanElecPow(i) = ModelResults.meanElecPow;
  Model_PercentOfBudal(i) = Model_meanElecPow(i)/Budal_Limit(i);
  
  Model_StdPTOElongation(i) = ModelResults.StdPTOElongation;
  Model_StdPTOElongationRate(i) = ModelResults.StdPTOElongationRate; 
  Model_PTO_Eff(i) = ModelResults.PTO_Eff;
  
  n = strfind(files(i).name,'WaveData');
  wavefilenm = files(i).name(n:end)
  MeasResults = LoadMeasResults([MeasuredResultsPath 'MeasuredResults_for' wavefilenm]);
  Meas_meanElecPow(i) = MeasResults.meanElecPow;
  Meas_PercentOfBudal(i) = Meas_meanElecPow(i)/Budal_Limit(i);
  
  Meas_StdPTOElongation(i) = MeasResults.StdPTOElongation;
  Meas_StdPTOElongationRate(i) = MeasResults.StdPTOElongationRate; 
  
  
  %Comparisons
  PercentError_meanElecPow(i) = 100*(Model_meanElecPow(i)-Meas_meanElecPow(i))/Meas_meanElecPow(i);
  
  disp(['Modelled Elec Pow = ' num2str(ModelResults.meanElecPow)]);
  disp(['Measured Elec Pow = ' num2str(MeasResults.meanElecPow)]);
  disp(' ')
  
  figure('Position',[520 64 824 1034]);
  subplot(3,2,1)
  plot(ModelResults.f,ModelResults.S_e,MeasResults.f,MeasResults.S_e);
  ylabel('S_e')
  legend('Model Results','Measured Results');
  subplot(3,2,2)
  plot(ModelResults.f,ModelResults.S_edot,MeasResults.f,MeasResults.S_edot);
  ylabel('S_edot')
  legend('Model Results','Measured Results');
  if(plot_num > 5)
    close all
    plot_num = 0;
  else
    plot_num = plot_num+1;
  end
end

figure
plot(Meas_meanElecPow,Model_meanElecPow,'x',[0 600],[0 600]);
set(gca,'FontSize',14)
xlabel('Measured Elec Power');
ylabel('Modelled Elec Power');
legend(['R^2 = ' num2str(rsquare(Meas_meanElecPow,Model_meanElecPow))],'Location','NorthWest');
print('-dpdf',[PlotDirectory 'MeasVModel_Power']);
print('-dpng',[PlotDirectory 'MeasVModel_Power']);


figure
plot(Meas_meanElecPow,100*Model_PTO_Eff,'x');
xlabel('Measured Elec Power');
ylabel('PTO Efficiency (%)');


figure('Position',[520 118 757 980]);
subplot(2,1,1)
plot(Hs,PercentError_meanElecPow,'x');
ylabel('Percent Error in modelled mean Elec Power');
xlabel('Sig Wave Height (m)');
subplot(2,1,2)
plot(Tp,PercentError_meanElecPow,'x');
ylabel('Percent Error in modelled mean Elec Power');
xlabel('Peak Period (s)');

figure
plot(Budal_Limit,Model_PercentOfBudal,'x',Budal_Limit,Meas_PercentOfBudal,'x');
xlabel('Budal Limit (W)');
ylabel('Percent converted');
legend('Modelled Results','Measured Results','Location','NorthWest');

figure
plot(Meas_StdPTOElongation,Model_StdPTOElongation,'x');
xlabel('Measured Std Deviation of PTO Elongation');
ylabel('Modelled Std Deviation of PTO Elongation');

figure
plot(Meas_StdPTOElongationRate,Model_StdPTOElongationRate,'x');
xlabel('Measured Std Deviation of PTO Elongation Rate');
ylabel('Modelled Std Deviation of PTO Elongation Rate');
