function [pto_mean pow_disp_mean] = Compute_FlatPlate_Performance(dir,name,Hs,Ls,Lc,dt,tf,b)


results_filenm = create_filenm([dir 'FlatPlate_' name],Hs,Ls,Lc,dt,tf,b)

if(exist([results_filenm '.mat']))
  load([results_filenm '.mat']);
else
  pto_mean = -1;
  pow_disp_mean = -1;
  return;
end

t = get(Buoy,'t');

%Get Buoy motion results
x = get(Buoy,'x');
xdot = get(Buoy,'xdot');
xddot = get(Buoy,'xddot');
 
%Get Plate motion results
y = get(Plate,'x');
ydot = get(Plate,'xdot');
yddot = get(Plate,'xddot');

%plotting results

Bforce = get(Buoy,'Forces');
Pforce = get(Plate,'Forces');

idx = find(isnan(x(:,1)));
if(~isempty(idx))
    disp('WARNING:  NaN detected');
    pto_mean = NaN;
    pow_disp_mean = NaN;
    return;
end


N = length(t);

xoB = get(Buoy,'x0');
xoF = get(Plate,'x0');

S = get(Plate,'Area');

Elongation = zeros(N,1);
ElongationRate = zeros(N,1);
SpringTension = zeros(N,1);
DampingTension = zeros(N,1);
s = zeros(N,3);
for i = 1:N
    [Elongation(i),ElongationRate(i),s(i,:)] = TetherElongations(xoB,x(i,:)',xdot(i,:)',p_aB,xoF,y(i,:)',ydot(i,:)',p_aF);
    if(Elongation(i) > 0)  %If ram is fully retracted, tether is slack and no force is exerted.
        SpringTension(i) = ppval(Spring_Force_Coeffs,Elongation(i));
        DampingTension(i) = ppval(Damping_Force_Coeffs,ElongationRate(i));
    else
        Elongation(i) = 0;
        ElongationRate(i) = 0;
    end
end

%Compute and display auxillary results
pto_power = ElongationRate.*DampingTension;
disp_power = -ydot(1:N,3).*Pforce{3}(1:N,3);

pto_mean = mean(pto_power);
pow_disp_mean = mean(disp_power);

disp(['Mean PTO Power = ' num2str(pto_mean) ' Watts']);
disp(['Mean Power Dissipated = ' num2str(pow_disp_mean) ' Watts']);
disp(['Peak Tether Tension = ' num2str(max(SpringTension+DampingTension)/4.45) ' lbs']);
disp(['Mean Tether Tension = ' num2str(mean(SpringTension+DampingTension)/4.45) ' lbs']);
disp(['Flat Plate Surface area = ' num2str(S(3)) ' m^2']);
disp(['Max Plate Pressure = ' num2str((max(SpringTension+DampingTension)/4.45)/(S(3)*39.4^2)) ' psi']);



