%%% Loads saved data from runAlldegProjPlots.m to generate
%%% Performance Profiles

if j == 1 || j == 2
    title2str = 'per size';
    if j == 1
        %%%% x axis for plot
        dims = mm;
        varlabel = 'sizeM';
        xlabelstr = 'm';
        title3str = 'n = ';
        nstr = num2str(nn(1));
        title5str = strcat('density = ', num2str(PP(1)));
        sizeordensestr = 'persizeM';
    elseif j == 2
        %%%% x axis for plot
        dims = nn;
        varlabel = 'sizeN';
        xlabelstr = 'n';
        title3str = 'm = ';
        nstr = num2str(nn(1));
        title5str = strcat('density = ', num2str(PP(1)));
        sizeordensestr = 'persizeN';
    end
elseif j == 3
    %%%% x axis for plot
    dims = PP;
    varlabel = 'dense';
    xlabelstr = 'density';
    title2str = 'per dense';
    title3str = 'm = ';
    title5str = '';
    nstr = strcat(num2str(mm(1)), 'n = ', num2str(nn(1)));
    sizeordensestr = 'perdense';
end

if i == 1
    title4str = 'tol = 1e-2';
    tol = 1e-2;
elseif i == 2
    title4str = 'tol = 1e-4';
    tol = 1e-4;
elseif i == 3
    title4str = 'tol = 1e-14';
    tol = 1e-14;
end

%%% Load time 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
strtimesemism = 'avertimesemi';
strtimeInexactsemism = 'avertimeInexactsemi';
strtimeHLWB = 'avertimeHLWB';
strtimeLSQ = 'avertimeLSQ';
load(strcat(varlabel,'semi',numstr,'.mat'),strtimesemism)
load(strcat(varlabel,'Inexactsemi',numstr,'.mat'),strtimeInexactsemism)
load(strcat(varlabel,'HLWB',numstr,'.mat'),strtimeHLWB)
load(strcat(varlabel,'LSQ',numstr,'.mat'),strtimeLSQ)


%%% Load relative residual 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
strrelresidssemism = 'averrelresidssemi';
strrelresidsInexactsemism = 'averrelresidsInexactsemi';
strrelresidsHLWB = 'averrelresidsHLWB';
strrelresidsLSQ = 'averrelresidsLSQ';
load(strcat(varlabel,'semi',numstr,'.mat'),strrelresidssemism)
load(strcat(varlabel,'Inexactsemi',numstr,'.mat'),strrelresidsInexactsemism)
load(strcat(varlabel,'HLWB',numstr,'.mat'),strrelresidsHLWB)
load(strcat(varlabel,'LSQ',numstr,'.mat'),strrelresidsLSQ)


%%% Form S and T for performance profile 

% time for performance profile
T(:,1) = eval(strtimesemism);
T(:,2) = eval(strtimeInexactsemism);
T(:,3) = eval(strtimeHLWB);
T(:,4) = eval(strtimeLSQ);

% relative residual for performance profile

S(:,1) = eval(strrelresidssemism);
S(:,2) = eval(strrelresidsInexactsemism);
S(:,3) = eval(strrelresidsHLWB);
S(:,4) = eval(strrelresidsLSQ);

% if relative residual is greater than tol, then set time to NaN (failed to
% solve)

for i = 1:4
    failtocnvrge = S(:,i) > tol;
    T(failtocnvrge,i) = NaN; 
end

perf(T,1,title4str)

fig = gcf;

saveas(fig,strcat(varlabel,numstr,'.png'))


% end of loadData