annotate scripts/testfun/private/compare_plot_demos.m @ 18925:87324260043d

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.
author Andreas Weber <andy.weber.aw@gmail.com>
date Tue, 15 Jul 2014 22:18:35 +0200
parents f9cf5ae6b8a2
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
18874
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
1 ## Copyright (C) 2012 Ben Abbott <bpabbott@mac.com>
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
2 ##
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
3 ## This file is part of Octave.
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
4 ##
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
5 ## Octave is free software; you can redistribute it and/or modify it
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
6 ## under the terms of the GNU General Public License as published by
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
7 ## the Free Software Foundation; either version 3 of the License, or (at
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
8 ## your option) any later version.
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
9 ##
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
10 ## Octave is distributed in the hope that it will be useful, but
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
13 ## General Public License for more details.
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
14 ##
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
15 ## You should have received a copy of the GNU General Public License
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
16 ## along with Octave; see the file COPYING. If not, see
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
17 ## <http://www.gnu.org/licenses/>.
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
18
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
19 ## -*- texinfo -*-
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
20 ## @deftypefn {Function File} {} compare_plot_demos ()
18895
b8934a57e13e Improve plot comparison scripts.
Rik <rik@octave.org>
parents: 18877
diff changeset
21 ## @deftypefnx {Function File} {} compare_plot_demos ("toolkits", @{@var{toolkit1}, @var{toolkit2}, @dots{}@})
18874
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
22 ##
18895
b8934a57e13e Improve plot comparison scripts.
Rik <rik@octave.org>
parents: 18877
diff changeset
23 ## Uses @code{dump_demos} and @code{html_compare_plot_demos} to produce an
18925
87324260043d Improve plot comparison scripts.
Andreas Weber <andy.weber.aw@gmail.com>
parents: 18897
diff changeset
24 ## html comparison of the plot demos for each of Octave's graphics toolkits.
18874
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
25 ##
18895
b8934a57e13e Improve plot comparison scripts.
Rik <rik@octave.org>
parents: 18877
diff changeset
26 ## An m-file named @file{dump_plots.m} will be created in the current working
b8934a57e13e Improve plot comparison scripts.
Rik <rik@octave.org>
parents: 18877
diff changeset
27 ## directory. This function will be used to render and save the plot demo
b8934a57e13e Improve plot comparison scripts.
Rik <rik@octave.org>
parents: 18877
diff changeset
28 ## images.
18874
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
29 ##
18895
b8934a57e13e Improve plot comparison scripts.
Rik <rik@octave.org>
parents: 18877
diff changeset
30 ## If they do not already exist, directories for each available graphics
b8934a57e13e Improve plot comparison scripts.
Rik <rik@octave.org>
parents: 18877
diff changeset
31 ## toolkit are created. Each toolkit's directory will be populated with images
18874
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
32 ## of each plot demo in the png format.
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
33 ##
18895
b8934a57e13e Improve plot comparison scripts.
Rik <rik@octave.org>
parents: 18877
diff changeset
34 ## Finally, an html document named @file{compare_plot_demos.html} is produced.
b8934a57e13e Improve plot comparison scripts.
Rik <rik@octave.org>
parents: 18877
diff changeset
35 ## This page places each toolkit's images side by side for a convenient
18874
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
36 ## comparison of the results.
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
37 ##
18895
b8934a57e13e Improve plot comparison scripts.
Rik <rik@octave.org>
parents: 18877
diff changeset
38 ## If the property @qcode{"toolkits"} is given then compare only the listed
b8934a57e13e Improve plot comparison scripts.
Rik <rik@octave.org>
parents: 18877
diff changeset
39 ## toolkits in the cell string. The list may also include the toolkit
b8934a57e13e Improve plot comparison scripts.
Rik <rik@octave.org>
parents: 18877
diff changeset
40 ## @qcode{"matlab"}.
18874
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
41 ##
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
42 ## @end deftypefn
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
43
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
44 ## Author: Ben Abbott <bpabbott@mac.com>
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
45
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
46 function compare_plot_demos (varargin)
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
47
18895
b8934a57e13e Improve plot comparison scripts.
Rik <rik@octave.org>
parents: 18877
diff changeset
48 arg.toolkits = available_graphics_toolkits ();
18897
f9cf5ae6b8a2 Add image directory to plot comparison scripts.
Rik <rik@octave.org>
parents: 18895
diff changeset
49 arg.directories = {"plot/appearance", "plot/draw", "plot/util", "image"};
18895
b8934a57e13e Improve plot comparison scripts.
Rik <rik@octave.org>
parents: 18877
diff changeset
50 arg.fmt = "png";
18925
87324260043d Improve plot comparison scripts.
Andreas Weber <andy.weber.aw@gmail.com>
parents: 18897
diff changeset
51 arg.fcn_file = "dump_plot_demos.m";
18895
b8934a57e13e Improve plot comparison scripts.
Rik <rik@octave.org>
parents: 18877
diff changeset
52 arg.replace_images = false;
18874
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
53
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
54 for n = 1:2:numel(varargin)
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
55 if (! ischar (varargin{n}))
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
56 print_usage ();
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
57 else
18895
b8934a57e13e Improve plot comparison scripts.
Rik <rik@octave.org>
parents: 18877
diff changeset
58 arg.(varargin{n}) = varargin{n+1};
18874
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
59 endif
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
60 endfor
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
61
18895
b8934a57e13e Improve plot comparison scripts.
Rik <rik@octave.org>
parents: 18877
diff changeset
62 if (ischar (arg.toolkits))
b8934a57e13e Improve plot comparison scripts.
Rik <rik@octave.org>
parents: 18877
diff changeset
63 arg.toolkits = {arg.toolkits};
b8934a57e13e Improve plot comparison scripts.
Rik <rik@octave.org>
parents: 18877
diff changeset
64 elseif (! iscellstr (arg.toolkits))
b8934a57e13e Improve plot comparison scripts.
Rik <rik@octave.org>
parents: 18877
diff changeset
65 error ('compare_plot_demos: Invalid value for "toolkits"')
18874
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
66 endif
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
67
18895
b8934a57e13e Improve plot comparison scripts.
Rik <rik@octave.org>
parents: 18877
diff changeset
68 if (ischar (arg.directories))
b8934a57e13e Improve plot comparison scripts.
Rik <rik@octave.org>
parents: 18877
diff changeset
69 arg.directories = {arg.directories};
b8934a57e13e Improve plot comparison scripts.
Rik <rik@octave.org>
parents: 18877
diff changeset
70 elseif (! iscellstr (arg.directories))
b8934a57e13e Improve plot comparison scripts.
Rik <rik@octave.org>
parents: 18877
diff changeset
71 error ('compare_plot_demos: Invalid value for "directory"')
18874
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
72 endif
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
73
18895
b8934a57e13e Improve plot comparison scripts.
Rik <rik@octave.org>
parents: 18877
diff changeset
74 if (! ischar (arg.fmt))
b8934a57e13e Improve plot comparison scripts.
Rik <rik@octave.org>
parents: 18877
diff changeset
75 error ('compare_plot_demos: Invalid value for "fmt"')
18874
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
76 endif
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
77
18925
87324260043d Improve plot comparison scripts.
Andreas Weber <andy.weber.aw@gmail.com>
parents: 18897
diff changeset
78 ## Generate arg.fcn_file for rendering/saving the plot demo images
18895
b8934a57e13e Improve plot comparison scripts.
Rik <rik@octave.org>
parents: 18877
diff changeset
79 dump_demos (arg.directories, arg.fcn_file, arg.fmt);
18874
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
80
18895
b8934a57e13e Improve plot comparison scripts.
Rik <rik@octave.org>
parents: 18877
diff changeset
81 [~, fcn_name] = fileparts (arg.fcn_file);
18874
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
82
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
83 ## Generate the plot demo images for each toolkit
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
84 cwd = pwd ();
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
85 unwind_protect
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
86 addpath (pwd);
18895
b8934a57e13e Improve plot comparison scripts.
Rik <rik@octave.org>
parents: 18877
diff changeset
87 for n = 1:numel (arg.toolkits)
b8934a57e13e Improve plot comparison scripts.
Rik <rik@octave.org>
parents: 18877
diff changeset
88 if (! isdir (fullfile (cwd, arg.toolkits{n})))
b8934a57e13e Improve plot comparison scripts.
Rik <rik@octave.org>
parents: 18877
diff changeset
89 mkdir (arg.toolkits{n});
18874
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
90 endif
18895
b8934a57e13e Improve plot comparison scripts.
Rik <rik@octave.org>
parents: 18877
diff changeset
91 cd (arg.toolkits{n});
b8934a57e13e Improve plot comparison scripts.
Rik <rik@octave.org>
parents: 18877
diff changeset
92 if (arg.replace_images && ! isempty (dir (["*." arg.fmt])))
b8934a57e13e Improve plot comparison scripts.
Rik <rik@octave.org>
parents: 18877
diff changeset
93 delete (["*." arg.fmt]);
18874
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
94 endif
18895
b8934a57e13e Improve plot comparison scripts.
Rik <rik@octave.org>
parents: 18877
diff changeset
95 if (! strcmp (arg.toolkits{n}, "matlab"))
b8934a57e13e Improve plot comparison scripts.
Rik <rik@octave.org>
parents: 18877
diff changeset
96 close all;
b8934a57e13e Improve plot comparison scripts.
Rik <rik@octave.org>
parents: 18877
diff changeset
97 graphics_toolkit (arg.toolkits{n});
18874
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
98 try
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
99 eval (fcn_name);
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
100 catch
18895
b8934a57e13e Improve plot comparison scripts.
Rik <rik@octave.org>
parents: 18877
diff changeset
101 printf ("Error running plot demos for ""%s"" toolkit\n", arg.toolkits{n});
b8934a57e13e Improve plot comparison scripts.
Rik <rik@octave.org>
parents: 18877
diff changeset
102 disp (lasterror);
18874
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
103 end_try_catch
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
104 endif
18895
b8934a57e13e Improve plot comparison scripts.
Rik <rik@octave.org>
parents: 18877
diff changeset
105 cd (cwd);
18874
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
106 endfor
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
107 unwind_protect_cleanup
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
108 rmpath (cwd);
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
109 end_unwind_protect
18925
87324260043d Improve plot comparison scripts.
Andreas Weber <andy.weber.aw@gmail.com>
parents: 18897
diff changeset
110 if (! strcmp (arg.toolkits, "matlab"))
87324260043d Improve plot comparison scripts.
Andreas Weber <andy.weber.aw@gmail.com>
parents: 18897
diff changeset
111 ## Generate the html comparison of the images
87324260043d Improve plot comparison scripts.
Andreas Weber <andy.weber.aw@gmail.com>
parents: 18897
diff changeset
112 html_compare_plot_demos (arg.toolkits);
87324260043d Improve plot comparison scripts.
Andreas Weber <andy.weber.aw@gmail.com>
parents: 18897
diff changeset
113 else
87324260043d Improve plot comparison scripts.
Andreas Weber <andy.weber.aw@gmail.com>
parents: 18897
diff changeset
114 ## We need to run matlab manually before the html page can be created
87324260043d Improve plot comparison scripts.
Andreas Weber <andy.weber.aw@gmail.com>
parents: 18897
diff changeset
115 printf ('\nNow run %s in Matlab.\nAfter this run html_compare_plot_demos,\n', arg.fcn_file);
87324260043d Improve plot comparison scripts.
Andreas Weber <andy.weber.aw@gmail.com>
parents: 18897
diff changeset
116 printf ('for example html_compare_plot_demos ({"fltk", "gnuplot", "matlab"}), to create the html page.\n');
87324260043d Improve plot comparison scripts.
Andreas Weber <andy.weber.aw@gmail.com>
parents: 18897
diff changeset
117 endif
18874
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
118 endfunction
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
119