function ModelResults = LoadModelResults(filenm);

load(filenm);

ModelResults.meanElecPow = nanmean(dl.Current.*dl.Voltage);
ModelResults.maxElecPow = max(dl.Current.*dl.Voltage);
ModelResults.Hs = MeasWaveData.SigWaveHeight;
ModelResults.Tp = MeasWaveData.PeakPeriod;
ModelResults.BudalLimit = MeasWaveData.BudalLimit;

ModelResults.PTO_Eff = nanmean((dl.Current.*dl.Voltage)./(dl.Force.*dl.ElonRate));

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');
Fforce = get(Plate,'Forces');

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

Elongation = zeros(length(t),1);
ElongationRate = zeros(length(t),1);
SpringTension = zeros(length(t),1);
StictionTension = zeros(length(t),1);

s = zeros(length(t),3);
for i = 1:length(t)
    [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));
        %StictionTension(i) = ppval(Stiction_Force_Coeffs,ElongationRate(i));
    else
        Elongation(i) = 0;
        ElongationRate(i) = 0;
    end
end

ModelResults.MeanPTOElongation = mean(Elongation);
ModelResults.MaxPTOElongation = max(Elongation);
ModelResults.MinPTOElongation = min(Elongation);
ModelResults.StdPTOElongation = std(Elongation);

ModelResults.MeanPTOElongationRate = mean(ElongationRate);
ModelResults.MaxPTOElongationRate = max(ElongationRate);
ModelResults.MinPTOElongationRate = min(ElongationRate);
ModelResults.StdPTOElongationRate = std(ElongationRate);


n_windows = 8;

[f, Pxx] = tseries2spectrum(t,Elongation-mean(Elongation),n_windows);
idx = find(f<=1);
ModelResults.f = f(idx);
ModelResults.S_e = Pxx(idx);

[f, Pxx] = tseries2spectrum(t,ElongationRate,n_windows);
ModelResults.S_edot = Pxx(idx);

[f, Pxx] = tseries2spectrum(t,dl.Voltage-mean(dl.Voltage),n_windows);
ModelResults.S_voltage = Pxx(idx);

[f, Pxx] = tseries2spectrum(t,dl.Current-mean(dl.Current),n_windows);
ModelResults.S_current = Pxx(idx);

power = dl.Voltage.*dl.Current;
[f, Pxx] = tseries2spectrum(t,power-mean(power),n_windows);
ModelResults.S_pow = Pxx(idx);


end

