# HG changeset patch
# User Pantxo Diribarne <pantxo.diribarne@gmail.com>
# Date 1508938260 -7200
#      Wed Oct 25 15:31:00 2017 +0200
# Node ID 23adc47ed869429100352e000b0e2d74123794e2
# Parent  7f9494466fd9e00af4fc9837c26cc7c40038583b
imported patch summary

diff -r 7f9494466fd9 -r 23adc47ed869 scripts/testfun/private/dump_demos.m
--- a/scripts/testfun/private/dump_demos.m	Sun Oct 15 21:06:47 2017 +0200
+++ b/scripts/testfun/private/dump_demos.m	Wed Oct 25 15:31:00 2017 +0200
@@ -86,7 +86,13 @@
   fprintf (fid, "close all\n");
   fprintf (fid, "more off\n");
   fprintf (fid, "diary diary.log\n");
+  
 
+  ## Load previous diary data if any
+  fprintf (fid, "if (exist ('diary.mat', 'file'))\n");
+  fprintf (fid, "  load diary.mat\n");
+  fprintf (fid, "endif\n");
+  
   ## Run and print the demos in each directory
   for i = 1:numel (dirs)
     d = dirs{i};
@@ -104,6 +110,9 @@
 
   ## Stop and flush diary
   fprintf (fid, "\ndiary off\n");
+  
+  ## Save diary data also
+  fprintf (fid, "\nsave -7 diarydat.mat \n");
 
   ## Create script ending
   fprintf (fid, "end\n\n");
@@ -123,6 +132,7 @@
   flist = flist(! strncmp (flist, "link", 4));
   ## Remove colormap
   flist = flist(! strncmp (flist, "colormap", 8));
+  kk = 0;
   for i = 1:numel (flist)
     fcn = flist{i};
     fcn(end-1:end) = [];  # remove .m
@@ -155,6 +165,9 @@
       fprintf (fid, "      print ('-d%s', '%s');\n", fmt, fn);
       fprintf (fid, "      t_print = toc ();\n");
       fprintf (fid, "      fprintf ('[%%f %%f] done\\n',t_plot, t_print);\n");
+      fprintf (fid, "      diarydat.('%s').plot = t_plot;\n", base_fn);
+      fprintf (fid, "      diarydat.('%s').print = t_print;\n", base_fn);
+      fprintf (fid, "      diarydat.('%s').warning = lastwarn ();\n", base_fn);
       fprintf (fid, "    end\n");
       ## Temporary fix for cruft accumulating in figure window.
       fprintf (fid, "    close ('all');\n");
@@ -166,7 +179,10 @@
       fprintf (fid, "  err_fid = fopen ('%s.err', 'w');\n", base_fn);
       fprintf (fid, "  fprintf (err_fid, '%%s', lasterr ());\n");
       fprintf (fid, "  fclose (err_fid);\n");
+      fprintf (fid, "  diarydat.('%s').error = lasterr ();\n", base_fn);
       fprintf (fid, "end\n");
+      fprintf (fid, "lasterr ('');\n");
+      fprintf (fid, "lastwarn ('');\n");
     endfor
   endfor
   fprintf (fid, "\nclose all\n");
diff -r 7f9494466fd9 -r 23adc47ed869 scripts/testfun/private/html_compare_plot_demos.m
--- a/scripts/testfun/private/html_compare_plot_demos.m	Sun Oct 15 21:06:47 2017 +0200
+++ b/scripts/testfun/private/html_compare_plot_demos.m	Wed Oct 25 15:31:00 2017 +0200
@@ -73,6 +73,9 @@
   for t = 1:numel(toolkits)
     filter = sprintf ("%s/*.%s", toolkits{t}, in.fmt);
     in.figfiles = union (in.figfiles, {dir(filter).name});
+    data(t).tkname = toolkits{t};
+    load (fullfile (pwd, toolkits{t}, "diarydat.mat"));
+    data(t).diary = diarydat;
   endfor
 
   fid = fopen (which (in.template), "r");
@@ -132,7 +135,9 @@
         [~, file] = fileparts (in.figfiles{m});
         fn = [file "." in.fmt];
         fprintf (fid, "<tr id=\"%s\">\n", file);
+        ll = 1;
         for k = toolkits
+          data(ll++).diary.(file).href = [in.output_fmt(page) "#" file];
           ffn = fullfile (k{:}, fn);
           fprintf (fid, "<td><span>%s</span><br>", ffn);
           if (exist (ffn, "file"))
@@ -165,4 +170,167 @@
     end_unwind_protect
   until (stop_fig == numel (in.figfiles))
 
+  ## Warnings, errors and timing summary
+  fid = fopen (in.output_fmt (page), "w");
+  unwind_protect
+    fprintf (fid, "%s\n", header);
+    fprintf (fid, "<h2>Generated on %s by %s with GNU Octave %s</h2>\n", ...
+             datestr (now (), 0), mfilename, version);
+    if (page > 1)
+      prev_page_link = fprintf (fid, "<p><a href=\"%s\">%s</a></p>\n", ...
+                                in.output_fmt (page - 1), "previous page");
+    endif
+    
+    warnstr = errstr = corrstr = "";
+    breakerr = breakwarn = false;
+    
+    plots = {};
+    tplot = [];
+    tprint = [];
+    
+    tsummary = [];
+    
+    file = "";
+    ntk = numel (toolkits);
+    for ii = 1:numel (in.figfiles)
+      [~, tmp] = fileparts (in.figfiles{ii});
+      if (! isempty (file) && ! strcmp (file(1:end-3), tmp(1:end-3)))
+        if (! exist ("Timing", "dir"))
+          mkdir Timing
+        endif
+        plt = sprintf("%s.png", file(1:end-3));
+        fname = fullfile ("Timing", plt);
+        if (! exist (fname, "file"))
+          hf = figure ();
+          subplot (2,1,1)
+          bar (tplot)
+          ylabel ("plot time (s)")
+          subplot (2,1,2)
+          bar (tprint)
+          ylabel ("print time (s)")
+          print (fname)
+          delete (hf);
+        endif
+        breakwarn = breakerr = true;
+        plots = [plots plt];
+        tsummary = [tsummary [mean(tplot(:,2)./tplot(:,1));
+                              mean(tprint(:,2)./tprint(:,1))]];
+        tplot = [];
+        tprint = [];
+      endif
+      file = tmp;
+      tplot = [tplot; zeros(1,ntk)];
+      tprint = [tprint; zeros(1,ntk)];
+
+      for t = 1:ntk
+        if (isfield (data(t).diary, file)
+            && isfield (data(t).diary.(file), "plot"))
+          tplot(rows(tplot),t) = data(t).diary.(file).plot;
+          tprint(rows(tprint),t) = data(t).diary.(file).print;
+        else
+          tplot(rows(tplot),t) = nan;
+          tprint(rows(tprint),t) = nan;
+        endif
+        
+        if (isfield (data(t).diary, file)
+            && isfield (data(t).diary.(file), "warning")
+            && ! isempty (data(t).diary.(file).warning))
+          if (breakwarn)
+            warnstr = sprintf ("%s<br>\n", warnstr);
+            breakwarn = false;
+          endif
+          warnstr = sprintf ("%s<a href=\"%s\">%s (%s): %s</a><br>\n", ...
+                             warnstr, data(t).diary.(file).href, ...
+                             file, toolkits{t}, ...
+                             data(t).diary.(file).warning);
+        endif
+        
+        if (isfield (data(t).diary, file)
+            && isfield (data(t).diary.(file), "error")
+            && ! isempty (data(t).diary.(file).error))
+          if (breakerr)
+            errstr = sprintf ("%s<br>\n", errstr);
+            breakerr = false;
+          endif
+          errstr = sprintf ("%s<a href=\"%s\">%s (%s): %s</a><br>\n", ...
+                   errstr, data(t).diary.(file).href, file, toolkits{t}, ...
+                            data(t).diary.(file).error);
+        endif
+      endfor
+
+      ## Report correlation between images when there are only 2 toolkits
+      if (ntk == 2 && strcmp (in.fmt, "png")
+          && exist (fullfile (toolkits{1}, [file ".png"]), "file")
+          && exist (fullfile (toolkits{2}, [file ".png"]), "file"))
+        ccoef = 0;
+        im1 = imread (fullfile (pwd, toolkits{1}, [file ".png"]));
+        im2 = imread (fullfile (pwd, toolkits{2}, [file ".png"]));
+        if (all (size (im1) == size (im2))) 
+          ccoef = corr (im1(:), im2(:));
+        else
+          ccoef = nan;
+        endif
+        if (isnan (ccoef))
+          corrstr = sprintf ("%s<a href=\"%s\">%s: NaN</a><br>\n", ...
+                             corrstr, data(1).diary.(file).href, file);        
+        elseif (ccoef < 0.95)
+          corrstr = sprintf ("%s<a href=\"%s\">%s: %3.2f</a><br>\n", ...
+                             corrstr, data(1).diary.(file).href, file, ...
+                             ccoef);
+        endif
+      endif
+    endfor
+    
+    fprintf (fid, "<h1>Plots with warnings</h1>%s\n", warnstr);
+    fprintf (fid, "<h1>Plots with errors</h1>%s\n", errstr);
+    fprintf (fid, "<h1>Plots correlation coefficient &lt; 0.95</h1>%s\n", ...
+             corrstr);
+    fprintf (fid, "<h1>Timing</h1>\n");
+    fprintf (fid, "<h2>Summary</h2>\n");
+    meanpl = mean (tsummary(1,! isnan(tsummary(1,:))));
+    fprintf (fid, ["<p>Average ratio between toolkits", ...
+                   "(&gt; 1 means second toolkit is slower):", ...
+                   "%3.2f (plot), %3.2f (print)</p>\n"], ...
+             mean (tsummary(1,! isnan(tsummary(1,:)))), ...
+             mean (tsummary(2,! isnan(tsummary(2,:)))));
+    
+    fprintf (fid, "<table>\n");
+
+    [~, idx] = sort (tsummary(1,:));
+    tsummary = tsummary(:,idx);
+    oplots = plots(idx); 
+    for ii = 1:numel (oplots)
+      if (! mod (ii-1, 3))
+        fprintf (fid, "<tr>\n");
+      endif
+      fprintf (fid, "<td><span>%s: %3.2f (plot), %3.2f (print)</span><br>", ...
+               oplots{ii}(1:end-4), tsummary(1,ii), tsummary(2,ii));
+      fprintf (fid, "</td>\n");
+      if (! mod (ii, 3))
+        fprintf (fid, "</tr>\n");
+      endif
+    endfor
+    fprintf (fid, "</table>\n");
+
+    fprintf (fid, "<h2>Details</h2>\n");
+    fprintf (fid, "<table>\n");
+    for ii = 1:numel (plots)
+      if (! mod (ii-1, 3))
+        fprintf (fid, "<tr>\n");
+      endif
+      fprintf (fid, "<td><span>%s</span><br>", plots{ii}(1:end-4));
+      fprintf (fid, "<img alt=\"%s\" src=\"%s\" style=\"width:%dpx\">", ...
+               plots{ii}(1:end-4), fullfile ("Timing", plots{ii}), ...
+               in.column_width);
+      fprintf (fid, "</td>\n");
+      if (! mod (ii, 3))
+        fprintf (fid, "</tr>\n");
+      endif
+    endfor
+    fprintf (fid, "</table>\n");
+      
+    fprintf (fid, "%s\n", trailer);
+  unwind_protect_cleanup
+    fclose (fid);
+  end_unwind_protect
 endfunction
