# HG changeset patch # User Andreas Weber # Date 1468684170 -7200 # Node ID 3f8ed6d7cb1c8032a83d4e250be952580d8c6b56 # Parent ad1790bb8f71467c8c1ac5829ef56d0086a958ae 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. diff -r ad1790bb8f71 -r 3f8ed6d7cb1c scripts/testfun/private/dump_demos.m --- 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"); diff -r ad1790bb8f71 -r 3f8ed6d7cb1c scripts/testfun/private/html_compare_plot_demos.m --- 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, "

\nGenerated on %s by %s with GNU Octave %s

", - 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, "\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, '\n', ... - column_header, toolkits{t}); - endfor - fprintf (fid, "\n"); + fid = fopen (in.output_fmt (page), "w"); + unwind_protect + fputs (fid, header); + fprintf (fid, "

\nGenerated on %s by %s with GNU Octave %s

", + datestr (now (), 0), mfilename, version); - for m = 1:numel (in.figfiles) - [~, file] = fileparts (in.figfiles{m}); - fn = [file "." in.fmt]; - fprintf (fid, "\n"); - for k = toolkits - ffn = fullfile (k{:}, fn); - fprintf (fid, " -
%s diary
%s
", ffn); - if (exist (ffn, "file")) - fprintf (fid, "", ... - 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", "
")); - endif + ## Create page previous/next + if (page > 1) + previous_page_link = sprintf ('previous page
', in.output_fmt (page - 1)); + else + previous_page_link = ""; + endif + + if (! last_page) + next_page_link = sprintf ('next page
', in.output_fmt (page + 1)); + else + next_page_link = ""; + endif + + fprintf (fid, '%s%s
', previous_page_link, next_page_link); + + ## Create table header + fprintf (fid, "\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, "\n"); + fprintf (fid, '\n', ... + column_header, toolkits{t}); endfor fprintf (fid, "\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, "\n", file); + for k = toolkits + ffn = fullfile (k{:}, fn); + fprintf (fid, " \n"); + endfor + fprintf (fid, "\n"); + endfor + + fprintf (fid, '
%s diary
%s
", ffn); + if (exist (ffn, "file")) + fprintf (fid, "", ... + 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", "
")); + endif + endif + fprintf (fid, "
\n'); + fprintf (fid, '%s%s
', 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 diff -r ad1790bb8f71 -r 3f8ed6d7cb1c scripts/testfun/private/html_plot_demos_template.html --- 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 @@
-