# HG changeset patch # User Andreas Weber # Date 1405455515 -7200 # Node ID 87324260043d908668824326bc97eb9598931630 # Parent 9a5e03801d2352b5857552dc1910b1d4935bcdc8 Improve plot comparison scripts. * compare_plot_demos.m: pass toolkits{} to html_compare_plot_demos. Give instructions for toolkit matlab. Fix whitespace issue. * dump_demos.m: fix typo in default dir. Consistently use dump_plot_demos.m for main worker script. Create diary and error messages for inclusion in html page. Set random seed for better comparison. * html_plot_demos_template.html: Allow variable toolkits (removed hard-coded gnuplot, matlab, fltk sequence). Fix some whitespace issues. * html_compare_plot_demos.m: Rewrite docstring. The instructions are no longer needed because compare_plot_demos handles them. Add "toolkits" and column_width param. Dynamically add toolkits in html, add diary.log link. diff -r 9a5e03801d23 -r 87324260043d scripts/testfun/private/compare_plot_demos.m --- a/scripts/testfun/private/compare_plot_demos.m Mon Jul 14 21:40:28 2014 -0700 +++ b/scripts/testfun/private/compare_plot_demos.m Tue Jul 15 22:18:35 2014 +0200 @@ -21,7 +21,7 @@ ## @deftypefnx {Function File} {} compare_plot_demos ("toolkits", @{@var{toolkit1}, @var{toolkit2}, @dots{}@}) ## ## Uses @code{dump_demos} and @code{html_compare_plot_demos} to produce an -## html comparison of the plot demos for each of Octave's graphics toolkits. +## html comparison of the plot demos for each of Octave's graphics toolkits. ## ## An m-file named @file{dump_plots.m} will be created in the current working ## directory. This function will be used to render and save the plot demo @@ -48,7 +48,7 @@ arg.toolkits = available_graphics_toolkits (); arg.directories = {"plot/appearance", "plot/draw", "plot/util", "image"}; arg.fmt = "png"; - arg.fcn_file = ""; + arg.fcn_file = "dump_plot_demos.m"; arg.replace_images = false; for n = 1:2:numel(varargin) @@ -75,11 +75,7 @@ error ('compare_plot_demos: Invalid value for "fmt"') endif - if (isempty (arg.fcn_file)) - arg.fcn_file = "dump_plot_demos.m"; - endif - - ## Generate "dump_plot_demos.m" for rendering/saving the plot demo images + ## Generate arg.fcn_file for rendering/saving the plot demo images dump_demos (arg.directories, arg.fcn_file, arg.fmt); [~, fcn_name] = fileparts (arg.fcn_file); @@ -111,10 +107,13 @@ unwind_protect_cleanup rmpath (cwd); end_unwind_protect - - ## Generate the html comparison of the images - ## TODO: pass the toolkits{} to allow number of columns to be formatted - html_compare_plot_demos ("output", "compare_plot_demos.html") - + if (! strcmp (arg.toolkits, "matlab")) + ## Generate the html comparison of the images + html_compare_plot_demos (arg.toolkits); + else + ## We need to run matlab manually before the html page can be created + printf ('\nNow run %s in Matlab.\nAfter this run html_compare_plot_demos,\n', arg.fcn_file); + printf ('for example html_compare_plot_demos ({"fltk", "gnuplot", "matlab"}), to create the html page.\n'); + endif endfunction diff -r 9a5e03801d23 -r 87324260043d scripts/testfun/private/dump_demos.m --- a/scripts/testfun/private/dump_demos.m Mon Jul 14 21:40:28 2014 -0700 +++ b/scripts/testfun/private/dump_demos.m Tue Jul 15 22:18:35 2014 +0200 @@ -30,7 +30,7 @@ ## ## @table @var ## @item @var{dirs} -## @code{@{"plot/appearance", "plot/draw", "plot/util", "image/"@}} +## @code{@{"plot/appearance", "plot/draw", "plot/util", "image"@}} ## @item @var{mfile} ## @code{"dump.m"} ## @item @var{fmt} @@ -48,7 +48,7 @@ ## Author: Søren Hauberg -function dump_demos (dirs={"plot/appearance", "plot/draw", "plot/util", "image/"}, output="dump.m", fmt="png") +function dump_demos (dirs={"plot/appearance", "plot/draw", "plot/util", "image"}, output="dump_plot_demos.m", fmt="png") if (nargin > 3) print_usage (); @@ -71,6 +71,7 @@ fprintf (fid, "function %s ()\n", funcname); fprintf (fid, "close all\n"); fprintf (fid, "more off\n"); + fprintf (fid, "diary diary.log\n"); ## Run and print the demos in each directory for i = 1:numel (dirs) @@ -84,6 +85,9 @@ dump_all_demos (d, fid, fmt); endfor + ## Stop and flush diary + fprintf (fid, "diary off\n"); + ## Create script ending fprintf (fid, "end\n\n") @@ -106,13 +110,18 @@ demos = get_demos (fcn); for d = 1:numel (demos) idx = sprintf ("%02d", d); + base_fn = sprintf ("%s_%s", fcn, idx); fprintf (fid, "\ntry\n"); + ## 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, " %s\n\n", demos{d}); fprintf (fid, " drawnow;\n"); fprintf (fid, " fig = (get (0, 'currentfigure'));\n"); fprintf (fid, " if (~ isempty (fig))\n"); fprintf (fid, " figure (fig);\n"); - fprintf (fid, " name = '%s_%s.%s';\n", fcn, idx, fmt); + fprintf (fid, " name = '%s.%s';\n", base_fn, fmt); fprintf (fid, " if (isempty (dir (name)))\n"); fprintf (fid, " fprintf ('Printing ""%%s"" ... ', name);\n") fprintf (fid, " print ('-d%s', name);\n", fmt); @@ -124,7 +133,10 @@ # Temporary fix for cruft accumulating in figure window. fprintf (fid, " close ('all');\n"); fprintf (fid, "catch\n"); - fprintf (fid, " fprintf ('ERROR in %s_%s: %%s\\n', lasterr ());\n", fcn, idx); + 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"); endfor endfor diff -r 9a5e03801d23 -r 87324260043d scripts/testfun/private/html_compare_plot_demos.m --- a/scripts/testfun/private/html_compare_plot_demos.m Mon Jul 14 21:40:28 2014 -0700 +++ b/scripts/testfun/private/html_compare_plot_demos.m Tue Jul 15 22:18:35 2014 +0200 @@ -17,159 +17,112 @@ ## . ## -*- texinfo -*- -## @deftypefn {Function File} {} html_compare () -## @deftypefnx {Function File} {} html_compare (@var{name}, @var{value}, @dots{}) +## @deftypefn {Function File} {} html_compare (@var{toolkits}) +## @deftypefnx {Function File} {} html_compare (@var{toolkits}, @var{name}, @var{value}, @dots{}) ## -## Produces an html document to compare the plot demos produced by Octave's -## gnuplot and FLTK toolkits with those produced by Matalb. +## Produces an html document to compare the plot demos produced by +## @var{toolkits}. ## -## Valid property names, and their defaults, are; +## Valid property names, and their defaults, are: ## ## @table @samp -## @item date -## @code{datestr (now (), 0)} ## @item fmt ## @code{"png"} -## @item mfiles -## @code{sort (cellstr (ls ("gnuplot")))} -## @item gnuplot -## @code{sprintf ("Gnuplot %s", __gnuplot_version__ ())} -## @item matlab -## @code{"Matlab Version 7.11.0.584 (R2010b)"} -## @item octave -## @code{sprintf ("Octave %s", version)} ## @item output -## @code{"compare_plots.html"} +## @code{"compare_plot_demos.html"} ## @item template -## @code{"html_template.html"} +## @code{"html_plot_demos_template.html"} +## @item column_width +## @code{600} ## @end table ## ## The template parameter refers to a specially formatted html file ## which accompanies this m-file script. ## -## This script may be used to generate the index.html page loaded by -## the link below. -## -## @example -## @group -## http://octave.sourceforge.net/compare_plots -## @end group -## @end example -## -## This is done by following the instructions below. -## -## @enumerate -## @item Begin by downloading a local copy of the web page. -## -## @example -## @group -## $ wget -vcr --level 1 http://octave.sourceforge.net/compare_plots/ -## @end group -## @end example -## -## @item Use @code{dump_demos} to produce the script used to produce the -## demo plots. In this example the script is @code{dump.m}. +## Additional toolkit description can be added to the column header +## with a parameter named equal to the toolkit. For example: ## ## @example ## @group -## octave:1> dump_demos plot dump.m png -## @end group -## @end example -## -## @item Produce the gnuplot and fltk plots, and place them in their -## designated directories. -## -## @example -## @group -## octave:2> dump -## octave:3> movefile *.png octave.sourceforge.net/compare_plots/gnuplot/. -## octave:4> graphics_toolkit fltk -## octave:5> close all -## octave:6> dump -## octave:7> movefile *.png octave.sourceforge.net/compare_plots/fltk/. -## @end group -## @end example -## -## @item Start Matlab and edit the script @code{dump.m} to correct the -## remaining Octave specific syntax so that it will run under Matlab. -## -## @item Run @code{dump.m} under Matlab, and place the plots in the -## designated matlab directory. -## -## @example -## @group -## >> dump -## >> movefile *.png octave.sourceforge.net/compare_plots/matlab/. -## @end group -## @end example -## -## @item The web page comparing all plot demos is created by -## -## @example -## @group -## octave:8> cd octave.sourceforge.net/compare_plots -## octave:9> html_compare output index.html +## @code{html_compare_plot_demos ({"gnuplot", "fltk"}, "gnuplot", " 4.6 patchlevel 5")} ## @end group ## @end example ## -## @item Finally, the new page may be loaded into your browser. -## -## @seealso{dump_demos, demo} +## @seealso{compare_plot_demos, dump_demos, demo} ## @end deftypefn ## Author: Ben Abbott -function html_compare_plot_demos (varargin) +function html_compare_plot_demos (toolkits, varargin) - ## TODO - Names of the toolkits should be input - ## Set defaults - in.date = datestr (now (), 0); + ## Set defaults in.fmt = "png"; in.figfiles = {}; - in.octave = sprintf ("Octave %s", version); - in.output= "compare_plots.html"; + in.output= "compare_plot_demos.html"; in.template = "html_plot_demos_template.html"; - in.toolkits = {"gnuplot", "matlab", "fltk"}; + in.column_width = 600; ## Parse inputs for n = 1:2:numel(varargin) in.(lower(varargin{n})) = varargin{n+1}; endfor - for t = 1:numel(in.toolkits) - if (! isfield (in, in.toolkits{t})) - ## Column headers for the html page - in.(in.toolkits{t}) = upper (in.toolkits{t}); - endif - ## Compile a list of all files for all toolkits - if (t == 1) - in.figfiles = {dir(sprintf ("gnuplot/*.%s", in.fmt)).name}; - else - filter = sprintf ("%s/*.%s", in.toolkits{t}, in.fmt); - in.figfiles = union (in.figfiles, {dir(filter).name}); - endif + ## Compile a list of all files for all toolkits + for t = 1:numel(toolkits) + filter = sprintf ("%s/*.%s", toolkits{t}, in.fmt); + in.figfiles = union (in.figfiles, {dir(filter).name}); endfor fid = fopen (which (in.template), "r"); template = char (fread (fid)) .'; fclose (fid); - template = strrep (template, "##OCTAVE##", in.octave); - template = strrep (template, "##GNUPLOT##", in.gnuplot); - template = strrep (template, "##MATLAB##", in.matlab); - - n1 = findstr (template, ""); - n2 = findstr (template, ""); - header = template(1:n1-1); - middle = template(n1+18:n2-1); - trailer = template(n2+15:end); + anchor = ""; + n = findstr (template, anchor); + 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); + + ## 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 = strcat (column_header, in.(toolkits{t})); + endif + fprintf (fid, '\n', column_header, toolkits{t}); + endfor + fprintf (fid, "\n"); + for m = 1:numel(in.figfiles) [~, file] = fileparts (in.figfiles{m}); - fputs (fid, strrep (middle, "##PLOT##", strcat (file, ".", in.fmt))); + fn = strcat (file, ".", in.fmt); + fprintf (fid, "\n"); + for k = toolkits + ffn = fullfile (k{:}, fn); + fprintf (fid, " \n"); + endfor + fprintf (fid, "\n"); endfor fputs (fid, trailer); unwind_protect_cleanup diff -r 9a5e03801d23 -r 87324260043d scripts/testfun/private/html_plot_demos_template.html --- a/scripts/testfun/private/html_plot_demos_template.html Mon Jul 14 21:40:28 2014 -0700 +++ b/scripts/testfun/private/html_plot_demos_template.html Tue Jul 15 22:18:35 2014 +0200 @@ -15,7 +15,7 @@ -
%s diary
%s
", ffn); + if (exist (ffn, "file")) + fprintf (fid, "", ffn, in.column_width); + else + err_fn = regexprep(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, "
@@ -31,7 +31,7 @@