changeset 22126:3f8ed6d7cb1c

Improve plot comparison in sripts/testfun dump_demos.m: Use ~ instead of ! for matlab compatibility. Isolate demos in functions. html_compare_plot_demos.m: Wrap html page after 50 demos per page, add prevoius and next links per page.
author Andreas Weber <andy.weber.aw@gmail.com>
date Sat, 16 Jul 2016 17:49:30 +0200
parents ad1790bb8f71
children 7a70004cae61
files scripts/testfun/private/dump_demos.m scripts/testfun/private/html_compare_plot_demos.m scripts/testfun/private/html_plot_demos_template.html
diffstat 3 files changed, 104 insertions(+), 71 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/testfun/private/dump_demos.m	Fri Jul 15 16:32:13 2016 -0700
+++ b/scripts/testfun/private/dump_demos.m	Sat Jul 16 17:49:30 2016 +0200
@@ -116,36 +116,41 @@
       idx = sprintf ("%02d", d);
       base_fn = sprintf ("%s_%s", fcn, idx);
       fn = sprintf ('%s.%s', base_fn, fmt);
-      fprintf (fid, "\ntry\n");
+      ## Wrap each demo in a function which create a local scope
+      ## to prevent that a previous demo overwrites i or pi, for example
+      fprintf (fid, "\nfunction %s ()\n", base_fn);
+      fprintf (fid, "  try\n");
       ## First check if the file already exists, skip demo if found
-      fprintf (fid, " if (! exist ('%s', 'file'))\n", fn);
+      fprintf (fid, "   if (~ exist ('%s', 'file'))\n", fn);
       ## Invoke the ancient, deprecated random seed generators, but there is an
       ## initialization mismatch with the more modern generators reported
       ## here (https://savannah.gnu.org/bugs/?42557).
-      fprintf (fid, "  rand ('seed', 1);\n");
-      fprintf (fid, "  tic ();\n");
-      fprintf (fid, "  %s\n\n", demos{d});
-      fprintf (fid, "  t_plot = toc ();\n");
-      fprintf (fid, "  fig = (get (0, 'currentfigure'));\n");
-      fprintf (fid, "  if (~ isempty (fig))\n");
-      fprintf (fid, "    figure (fig);\n");
-      fprintf (fid, "      fprintf ('Printing ""%s"" ... ');\n", fn);
-      fprintf (fid, "      tic ();\n");
-      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, "    rand ('seed', 1);\n");
+      fprintf (fid, "    tic ();\n");
+      fprintf (fid, "    %s\n\n", demos{d});
+      fprintf (fid, "    t_plot = toc ();\n");
+      fprintf (fid, "    fig = (get (0, 'currentfigure'));\n");
+      fprintf (fid, "    if (~ isempty (fig))\n");
+      fprintf (fid, "      figure (fig);\n");
+      fprintf (fid, "        fprintf ('Printing ""%s"" ... ');\n", fn);
+      fprintf (fid, "        tic ();\n");
+      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, "    end\n");
+      ## Temporary fix for cruft accumulating in figure window.
+      fprintf (fid, "    close ('all');\n");
+      fprintf (fid, "   else\n");
+      fprintf (fid, "     fprintf ('File ""%s"" already exists.\\n');\n", fn);
+      fprintf (fid, "   end\n");
+      fprintf (fid, "  catch\n");
+      fprintf (fid, "    fprintf ('ERROR in %s: %%s\\n', lasterr ());\n", base_fn);
+      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, "  end\n");
-      ## Temporary fix for cruft accumulating in figure window.
-      fprintf (fid, "  close ('all');\n");
-      fprintf (fid, " else\n");
-      fprintf (fid, "   fprintf ('File ""%s"" already exists.\\n');\n", fn);
-      fprintf (fid, " end\n");
-      fprintf (fid, "catch\n");
-      fprintf (fid, "  fprintf ('ERROR in %s: %%s\\n', lasterr ());\n", base_fn);
-      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, "end\n\n");
+      fprintf (fid, "end\n");
+      fprintf (fid, "%s ();\n", base_fn);
     endfor
   endfor
   fprintf (fid, "close all\n");
--- a/scripts/testfun/private/html_compare_plot_demos.m	Fri Jul 15 16:32:13 2016 -0700
+++ b/scripts/testfun/private/html_compare_plot_demos.m	Sat Jul 16 17:49:30 2016 +0200
@@ -59,9 +59,10 @@
   ## Set defaults
   in.fmt = "png";
   in.figfiles = {};
-  in.output= "compare_plot_demos.html";
+  in.output_fmt = @(p) sprintf ("compare_plot_demos_%02i.html", p);
   in.template = "html_plot_demos_template.html";
   in.column_width = 600;
+  in.plots_per_page = 50;
 
   ## Parse inputs
   for n = 1:2:numel(varargin)
@@ -83,53 +84,82 @@
   header = template(1:n-1);
   trailer = template(n+numel(anchor):end);
 
-  fid = fopen (in.output, "w");
-  unwind_protect
-    fputs (fid, header);
-    fprintf (fid, "<p><b>\nGenerated on %s by %s with GNU Octave %s</p>",
-             datestr (now (), 0), mfilename, version);
+  page = 1;
+  do
+    start_fig = (page - 1) * in.plots_per_page + 1;
+    stop_fig = page * in.plots_per_page;
+    last_page = stop_fig > numel (in.figfiles);
+    if (last_page)
+      stop_fig = numel (in.figfiles);
+    endif
 
-    ## Create table header
-    fprintf (fid, "<table border='1'><tr>\n");
-    for t = 1:numel(toolkits)
-      ## set default
-      column_header = upper (toolkits{t});
-      if (isfield (in, toolkits{t}))
-        column_header = [column_header, in.(toolkits{t})];
-      endif
-      fprintf (fid, '<th>%s <a href="%s/diary.log">diary</a></th>\n', ...
-                    column_header, toolkits{t});
-    endfor
-    fprintf (fid, "</tr>\n");
+    fid = fopen (in.output_fmt (page), "w");
+    unwind_protect
+      fputs (fid, header);
+      fprintf (fid, "<p><b>\nGenerated on %s by %s with GNU Octave %s</p>",
+               datestr (now (), 0), mfilename, version);
 
-    for m = 1:numel (in.figfiles)
-      [~, file] = fileparts (in.figfiles{m});
-      fn = [file "." in.fmt];
-      fprintf (fid, "<tr>\n");
-      for k = toolkits
-        ffn = fullfile (k{:}, fn);
-        fprintf (fid, "  <td>%s<br>", ffn);
-        if (exist (ffn, "file"))
-          fprintf (fid, "<img src='%s' style='width: %dpx;'>", ...
-                        ffn, in.column_width);
-        else
-          err_fn = strrep (ffn, ".png", ".err");
-          if (! exist (err_fn, "file"))
-            warning("File %s doesn't exist...", err_fn);
-          else
-            err_fid = fopen (err_fn);
-            msg = char (fread (err_fid))';
-            fclose (err_fid);
-            fprintf (fid, "%s", strrep (msg, "\n", "<br>"));
-          endif
+      ## Create page previous/next
+      if (page > 1)
+        previous_page_link = sprintf ('<a href="%s">previous page</a><br>', in.output_fmt (page - 1));
+      else
+        previous_page_link = "";
+      endif
+
+      if (! last_page)
+        next_page_link = sprintf ('<a href="%s">next page</a><br>', in.output_fmt (page + 1));
+      else
+        next_page_link = "";
+      endif
+
+      fprintf (fid, '%s%s<br>', previous_page_link, next_page_link);
+
+      ## Create table header
+      fprintf (fid, "<table border='1'><tr>\n");
+      for t = 1:numel(toolkits)
+        ## set default
+        column_header = upper (toolkits{t});
+        if (isfield (in, toolkits{t}))
+          column_header = [column_header, in.(toolkits{t})];
         endif
-        fprintf (fid, "</td>\n");
+        fprintf (fid, '<th>%s <a href="%s/diary.log">diary</a></th>\n', ...
+                      column_header, toolkits{t});
       endfor
       fprintf (fid, "</tr>\n");
-    endfor
-    fputs (fid, trailer);
-  unwind_protect_cleanup
-    fclose (fid);
-  end_unwind_protect
+      for m = start_fig:stop_fig
+        [~, file] = fileparts (in.figfiles{m});
+        fn = [file "." in.fmt];
+        fprintf (fid, "<tr id=\"%s\">\n", file);
+        for k = toolkits
+          ffn = fullfile (k{:}, fn);
+          fprintf (fid, "  <td>%s<br>", ffn);
+          if (exist (ffn, "file"))
+            fprintf (fid, "<img src='%s' style='width: %dpx;'>", ...
+                          ffn, in.column_width);
+          else
+            err_fn = strrep (ffn, ".png", ".err");
+            if (! exist (err_fn, "file"))
+              warning("File %s doesn't exist...", err_fn);
+            else
+              err_fid = fopen (err_fn);
+              msg = char (fread (err_fid))';
+              fclose (err_fid);
+              fprintf (fid, "%s", strrep (msg, "\n", "<br>"));
+            endif
+          endif
+          fprintf (fid, "</td>\n");
+        endfor
+        fprintf (fid, "</tr>\n");
+      endfor
+
+      fprintf (fid, '</table>\n');
+      fprintf (fid, '%s%s<br>', previous_page_link, next_page_link);
+
+      fputs (fid, trailer);
+      page++;
+    unwind_protect_cleanup
+      fclose (fid);
+    end_unwind_protect
+  until (stop_fig == numel (in.figfiles))
 
 endfunction
--- a/scripts/testfun/private/html_plot_demos_template.html	Fri Jul 15 16:32:13 2016 -0700
+++ b/scripts/testfun/private/html_plot_demos_template.html	Sat Jul 16 17:49:30 2016 +0200
@@ -49,8 +49,6 @@
 
 <div id="content">
 <!-- ##ADD TABLE HERE## -->
-</tr>
-</table>
 
 <div id="sf_logo">
   <a href="http://sourceforge.net"><img src="http://sourceforge.net/sflogo.php?group_id=2888&amp;type=1"