function makeGraphs0518()

numP = 14;
numD = 4;
label_half = '\delta = p / 2';
label_full = '\delta = p - 1';
label_st1  = '\delta = 1';
label_st2  = '\delta = 2';
timePrefix = 'phase2_time_';
spdpPrefix = 'phase2_speedup_';
subfigwidth= 0.49;
figwidth   = 0.65;

data = getDataScalabilityPhase2();

if mod(length(data), numP*numD)
  error('data has wrong length');
end
numC = length(data) / (numP*numD);

total_spdp_half = zeros(numP,1);
total_spdp_full = zeros(numP,1);
total_spdp_st1  = zeros(numP,1);
total_spdp_st2  = zeros(numP,1);
combs = [];

for offset = 0 : (numP*numD) : (numP*numD*(numC-1))

  %%% Get the problem instance
  comb = data(offset+1,1);
  combs = [combs comb];
  circuit = getIscasName(comb);
  SUN = getIscasSUN(comb);

  data_half = data(        offset+1 : offset +   numP, 2:3 );
  data_full = data(   numP+offset+1 : offset + 2*numP, 2:3 );
  data_st1  = data( 2*numP+offset+1 : offset + 3*numP, 2:3 );
  data_st2  = data( 3*numP+offset+1 : offset + 4*numP, 2:3 );

  %%%Now we have the four data sets for the four lines in the graph.

  %%%Plot time graph
  set(0,'DefaultAxesColorOrder',mycolormap0518);
  plot( data_half(:,1), data_half(:,2) ./ 60, ...
        data_full(:,1), data_full(:,2) ./ 60, ...
        data_st1(:,1),  data_st1(:,2)  ./ 60, ...
        data_st2(:,1),  data_st2(:,2)  ./ 60, ...
        'LineWidth', 1.5 );
  hold on
  plot( 1, SUN, '*k' );
  xlabel('Number of processors p');
  ylabel('Execution time T(n,p) [minutes]');
  title( [ 'Scalability experiments, phase 2: ISCAS circuit ' circuit ] );
  legend(label_half, label_full, label_st1, label_st2, 'Location','SouthWest');
  my_lim = ylim;
  my_lim(1) = 0;
  ylim(my_lim);
  my_lim = xlim;
  my_lim(1) = 0;
  xlim(my_lim);
  grid on;

  %%%Save time graph
  my_units = get(gcf,'PaperPosition');
  my_units(3) = my_units(3) * (subfigwidth/figwidth);
  set(gcf, 'PaperPosition', my_units);
  
  filename = sprintf('%scomb%02g', timePrefix, comb);
  saveas(gcf, [filename '.eps'], 'psc2' );
  saveas(gcf, [filename '.fig'] );
  saveas(gcf, [filename '.png'] );

  set(gcf,'PaperUnits','normalized');
  set(gcf,'PaperType','A4');
  set(gcf,'PaperOrientation','Landscape');
  set(gcf,'PaperPosition',[.1 .1 .8 .8]);
  saveas(gcf, [filename '.pdf'] );

  close

  %%% Get speedup
  spdp_half = (60*SUN) ./ data_half(:,2);
  spdp_full = (60*SUN) ./ data_full(:,2);
  spdp_st1  = (60*SUN) ./ data_st1(:,2);
  spdp_st2  = (60*SUN) ./ data_st2(:,2);

  total_spdp_half = total_spdp_half + spdp_half;
  total_spdp_full = total_spdp_full + spdp_full;
  total_spdp_st1  = total_spdp_st1  + spdp_st1;
  total_spdp_st2  = total_spdp_st2  + spdp_st2;

  %%% Plot speedup graph
  set(0,'DefaultAxesColorOrder',mycolormap0518);
  plot( data_half(:,1), spdp_half, ...
        data_full(:,1), spdp_full, ...
        data_st1(:,1),  spdp_st1, ...
        data_st2(:,1),  spdp_st2, ...
        'LineWidth', 1.5 );
  hold on
  plot( [0 24], [0 24], ':', 'LineWidth', 1.0, 'Color', [ hex2dec('40') hex2dec('0C') hex2dec('7A') ] ./ 256 );
  xlabel('Number of processors p');
  ylabel('Speedup S(n,p)');
  title( [ 'Scalability experiments, phase 2: ISCAS circuit ' circuit ] );
  legend( label_half, label_full, label_st1, label_st2, '(Linear speedup)', ...
          'Location','NorthWest' );
  my_lim = ylim;
  my_lim(1) = 0;
  ylim(my_lim);
  my_lim = xlim;
  my_lim(1) = 0;
  xlim(my_lim);
  grid on;

  %%% Save speedup graph
  my_units = get(gcf,'PaperPosition');
  my_units(3) = my_units(3) * (subfigwidth/figwidth);
  set(gcf, 'PaperPosition', my_units);
  
  filename = sprintf('%scomb%02g', spdpPrefix, comb);
  saveas(gcf, [filename '.eps'], 'psc2' );
  saveas(gcf, [filename '.fig'] );
  saveas(gcf, [filename '.png'] );

  set(gcf,'PaperUnits','normalized');
  set(gcf,'PaperType','A4');
  set(gcf,'PaperOrientation','Landscape');
  set(gcf,'PaperPosition',[.1 .1 .8 .8]);
  saveas(gcf, [filename '.pdf'] );

  close

end

%%% Plot aggregate speedup graph
set(0,'DefaultAxesColorOrder',mycolormap0518);
plot( data_half(:,1), total_spdp_half ./ numC, ...
      data_full(:,1), total_spdp_full ./ numC, ...
      data_st1(:,1),  total_spdp_st1  ./ numC, ...
      data_st2(:,1),  total_spdp_st2  ./ numC, ...
      'LineWidth', 1.5 );
hold on
plot( [0 24], [0 24], ':', 'LineWidth', 1.0, 'Color', [ hex2dec('40') hex2dec('0C') hex2dec('7A') ] ./ 256 );
xlabel('Number of processors p');
ylabel('Average speedup S(n,p)');
title( 'Scalability experiments, phase 2: all problem instances' );
legend( label_half, label_full, label_st1, label_st2, '(Linear speedup)', ...
        'Location','NorthWest' );
my_lim = ylim;
my_lim(1) = 0;
ylim(my_lim);
my_lim = xlim;
my_lim(1) = 0;
xlim(my_lim);
grid on;

%%% Save aggregate speedup graph
filename = sprintf('%sall', spdpPrefix);
saveas(gcf, [filename '.eps'], 'psc2' );
saveas(gcf, [filename '.fig'] );
saveas(gcf, [filename '.png'] );

set(gcf,'PaperUnits','normalized');
set(gcf,'PaperType','A4');
set(gcf,'PaperOrientation','Landscape');
set(gcf,'PaperPosition',[.1 .1 .8 .8]);
saveas(gcf, [filename '.pdf'] );


%%% Write out stuff to paste into to thesis.
width = num2str(subfigwidth);
fid = fopen('phase2.figures.txt','wt');

fprintf(fid, '%%%%%% Figures showing runtimes and speedup for each circuit\n');
t_caption  = 'Execution time $T(n,p)$.';
s_caption  = 'Speedup $S(n,p)$.';
for comb = combs
  t_filename = sprintf('%scomb%02g', timePrefix, comb);
  t_label    = sprintf('fig:ScalabilityPhase2RuntimeComb%02g', comb);
  s_filename = sprintf('%scomb%02g', spdpPrefix, comb);
  s_label    = sprintf('fig:ScalabilityPhase2SpeedupComb%02g', comb);
  label      = sprintf('fig:ScalabilityPhase2Comb%02g', comb);
  capShort = sprintf('Execution time $T(n,p)$ and speedup $S(n,p)$ of PSG for different combinations of $p$ and $\\delta$ on ISCAS circuit \\texttt{%s}.', getIscasName(comb));
  capLong  = sprintf('%s In the left figure, the black asterisk denotes $SU(n)$, the time taken by the sequential implementation.', capShort);
  capLong  = sprintf('%s In the right figure, the dotted line denotes the theoretical linear speedup $S(n,p)=p$.', capLong);
  
  fprintf(fid, '\\begin{figure}[htbp]\n');
  fprintf(fid, '  \\sffamily\n');
  fprintf(fid, '  \\centering\n');
  fprintf(fid, '  \\subfloat[%s]{\n', t_caption);
  fprintf(fid, '    \\includegraphics[width=%s\\textwidth]{scalability/%s}\n', width, t_filename);
  fprintf(fid, '    \\label{%s}\n', t_label);
  fprintf(fid, '  }\n');
  fprintf(fid, '  \\subfloat[%s]{\n', s_caption);
  fprintf(fid, '    \\includegraphics[width=%s\\textwidth]{scalability/%s}\n', width, s_filename);
  fprintf(fid, '    \\label{%s}\n', s_label);
  fprintf(fid, '  }\n');
  fprintf(fid, '  \\caption[%s]\n', capShort);
  fprintf(fid, '          {%s}\n', capLong);
  fprintf(fid, '  \\label{%s}\n', label);
  fprintf(fid, '\\end{figure}\n\n');
end

fprintf(fid, '\n\n%%%%%% Figure showing aggregate speedup\n');
width = num2str(0.8);
  filename = sprintf('%sall', spdpPrefix);
  label    = sprintf('fig:ScalabilityPhase2SpeedupAll');
  capShort = sprintf('Speedup $S(n,p)$ of PSG for different combinations of $p$ and $\\delta$ for all ISCAS circuits tested.');
  capLong  = sprintf('%s The dotted line denotes the theoretical linear speedup $S(n,p)=p$.', capShort);
  
  fprintf(fid, '\\begin{figure}[htbp]\n');
  fprintf(fid, '  \\sffamily\n');
  fprintf(fid, '  \\begin{center}\n');
  fprintf(fid, '    \\includegraphics[width=%s\\textwidth]{scalability/%s}\n', width, filename);
  fprintf(fid, '    \\caption[%s]\n', capShort);
  fprintf(fid, '            {%s}\n', capLong);
  fprintf(fid, '    \\label{%s}\n', label);
  fprintf(fid, '  \\end{center}\n');
  fprintf(fid, '\\end{figure}\n\n');


fprintf(fid, '\n\n%%%%%% References to time graphs\n');
for comb = combs
  label = sprintf('fig:ScalabilityPhase2RuntimeComb%02g', comb);
  fprintf(fid, ' \\autoref{%s}', label);
end
fprintf(fid, '\n');
for comb = combs
  label = sprintf('fig:ScalabilityPhase2RuntimeComb%02g', comb);
  fprintf(fid, ' \\ref{%s}', label);
end
fprintf(fid, '\n\n%%%%%% References to speedup graphs\n');
for comb = combs
  label = sprintf('fig:ScalabilityPhase2SpeedupComb%02g', comb);
  fprintf(fid, ' \\autoref{%s}', label);
end
fprintf(fid, '\n');
for comb = combs
  label = sprintf('fig:ScalabilityPhase2SpeedupComb%02g', comb);
  fprintf(fid, ' \\ref{%s}', label);
end
fprintf(fid, '\n\n%%%%%% References to aggregate speedup graph\n');
  label = sprintf('fig:ScalabilityPhase2SpeedupAll');
  fprintf(fid, '\\autoref{%s}\n', label);
  fprintf(fid, '\\ref{%s}\n\n', label);


fclose(fid);


end

% % % %%% Write out stuff to paste into to thesis.
% % % width = num2str(figwidth);
% % % fid = fopen('phase2.figures.txt','wt');
% % % 
% % % fprintf(fid, '%%%%%% Figures showing runtimes for each circuit\n');
% % % for comb = combs
% % %   filename = sprintf('%scomb%02g', timePrefix, comb);
% % %   label    = sprintf('fig:ScalabilityPhase2RuntimeComb%02g', comb);
% % %   capShort = sprintf('Execution time $T(n,p)$ of PSG for different combinations of $p$ and $\\delta$ on ISCAS circuit \\texttt{%s}.', getIscasName(comb));
% % %   capLong  = sprintf('%s The black asterisk denotes $SU(n)$, the time taken by the sequential implementation.', capShort);
% % %   
% % %   fprintf(fid, '\\begin{figure}[htbp]\n');
% % %   fprintf(fid, '  \\sffamily\n');
% % %   fprintf(fid, '  \\begin{center}\n');
% % %   fprintf(fid, '    \\includegraphics[width=%s\\textwidth]{scalability/%s}\n', width, filename);
% % %   fprintf(fid, '    \\caption[%s]\n', capShort);
% % %   fprintf(fid, '            {%s}\n', capLong);
% % %   fprintf(fid, '    \\label{%s}\n', label);
% % %   fprintf(fid, '  \\end{center}\n');
% % %   fprintf(fid, '\\end{figure}\n\n');
% % % end
% % % fprintf(fid, '\n\n%%%%%% Figures showing S(n,p) for each circuit\n');
% % % for comb = combs
% % %   filename = sprintf('%scomb%02g', spdpPrefix, comb);
% % %   label    = sprintf('fig:ScalabilityPhase2SpeedupComb%02g', comb);
% % %   capShort = sprintf('Speedup $S(n,p)$ of PSG for different combinations of $p$ and $\\delta$ on ISCAS circuit \\texttt{%s}.', getIscasName(comb));
% % %   capLong  = sprintf('%s The dotted line denotes the theoretical linear speedup $S(n,p)=p$.', capShort);
% % %   
% % %   fprintf(fid, '\\begin{figure}[htbp]\n');
% % %   fprintf(fid, '  \\sffamily\n');
% % %   fprintf(fid, '  \\begin{center}\n');
% % %   fprintf(fid, '    \\includegraphics[width=%s\\textwidth]{scalability/%s}\n', width, filename);
% % %   fprintf(fid, '    \\caption[%s]\n', capShort);
% % %   fprintf(fid, '            {%s}\n', capLong);
% % %   fprintf(fid, '    \\label{%s}\n', label);
% % %   fprintf(fid, '  \\end{center}\n');
% % %   fprintf(fid, '\\end{figure}\n\n');
% % % end
% % % fprintf(fid, '\n\n%%%%%% Figure showing aggregate speedup\n');
% % %   filename = sprintf('%sall', spdpPrefix);
% % %   label    = sprintf('fig:ScalabilityPhase2SpeedupAll');
% % %   capShort = sprintf('Speedup $S(n,p)$ of PSG for different combinations of $p$ and $\\delta$ for all ISCAS circuits tested.');
% % %   capLong  = sprintf('%s The dotted line denotes the theoretical linear speedup $S(n,p)=p$.', capShort);
% % %   
% % %   fprintf(fid, '\\begin{figure}[htbp]\n');
% % %   fprintf(fid, '  \\sffamily\n');
% % %   fprintf(fid, '  \\begin{center}\n');
% % %   fprintf(fid, '    \\includegraphics[width=%s\\textwidth]{scalability/%s}\n', width, filename);
% % %   fprintf(fid, '    \\caption[%s]\n', capShort);
% % %   fprintf(fid, '            {%s}\n', capLong);
% % %   fprintf(fid, '    \\label{%s}\n', label);
% % %   fprintf(fid, '  \\end{center}\n');
% % %   fprintf(fid, '\\end{figure}\n\n');
% % % 
% % % 
% % % fprintf(fid, '\n\n%%%%%% References to time graphs\n');
% % % for comb = combs
% % %   label = sprintf('fig:ScalabilityPhase2RuntimeComb%02g', comb);
% % %   fprintf(fid, ' \\autoref{%s}', label);
% % % end
% % % fprintf(fid, '\n');
% % % for comb = combs
% % %   label = sprintf('fig:ScalabilityPhase2RuntimeComb%02g', comb);
% % %   fprintf(fid, ' \\ref{%s}', label);
% % % end
% % % fprintf(fid, '\n\n%%%%%% References to speedup graphs\n');
% % % for comb = combs
% % %   label = sprintf('fig:ScalabilityPhase2SpeedupComb%02g', comb);
% % %   fprintf(fid, ' \\autoref{%s}', label);
% % % end
% % % fprintf(fid, '\n');
% % % for comb = combs
% % %   label = sprintf('fig:ScalabilityPhase2SpeedupComb%02g', comb);
% % %   fprintf(fid, ' \\ref{%s}', label);
% % % end
% % % fprintf(fid, '\n\n%%%%%% References to aggregate speedup graph\n');
% % %   label = sprintf('fig:ScalabilityPhase2SpeedupAll');
% % %   fprintf(fid, '\\autoref{%s}\n', label);
% % %   fprintf(fid, '\\ref{%s}\n\n', label);
% % % 
% % % 
% % % fclose(fid);
