comparison scripts/testfun/private/html_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 1b02bfff39d0
children
comparison
equal deleted inserted replaced
18924:9a5e03801d23 18925:87324260043d
15 ## You should have received a copy of the GNU General Public License 15 ## You should have received a copy of the GNU General Public License
16 ## along with Octave; see the file COPYING. If not, see 16 ## along with Octave; see the file COPYING. If not, see
17 ## <http://www.gnu.org/licenses/>. 17 ## <http://www.gnu.org/licenses/>.
18 18
19 ## -*- texinfo -*- 19 ## -*- texinfo -*-
20 ## @deftypefn {Function File} {} html_compare () 20 ## @deftypefn {Function File} {} html_compare (@var{toolkits})
21 ## @deftypefnx {Function File} {} html_compare (@var{name}, @var{value}, @dots{}) 21 ## @deftypefnx {Function File} {} html_compare (@var{toolkits}, @var{name}, @var{value}, @dots{})
22 ## 22 ##
23 ## Produces an html document to compare the plot demos produced by Octave's 23 ## Produces an html document to compare the plot demos produced by
24 ## gnuplot and FLTK toolkits with those produced by Matalb. 24 ## @var{toolkits}.
25 ## 25 ##
26 ## Valid property names, and their defaults, are; 26 ## Valid property names, and their defaults, are:
27 ## 27 ##
28 ## @table @samp 28 ## @table @samp
29 ## @item date
30 ## @code{datestr (now (), 0)}
31 ## @item fmt 29 ## @item fmt
32 ## @code{"png"} 30 ## @code{"png"}
33 ## @item mfiles
34 ## @code{sort (cellstr (ls ("gnuplot")))}
35 ## @item gnuplot
36 ## @code{sprintf ("Gnuplot %s", __gnuplot_version__ ())}
37 ## @item matlab
38 ## @code{"Matlab Version 7.11.0.584 (R2010b)"}
39 ## @item octave
40 ## @code{sprintf ("Octave %s", version)}
41 ## @item output 31 ## @item output
42 ## @code{"compare_plots.html"} 32 ## @code{"compare_plot_demos.html"}
43 ## @item template 33 ## @item template
44 ## @code{"html_template.html"} 34 ## @code{"html_plot_demos_template.html"}
35 ## @item column_width
36 ## @code{600}
45 ## @end table 37 ## @end table
46 ## 38 ##
47 ## The template parameter refers to a specially formatted html file 39 ## The template parameter refers to a specially formatted html file
48 ## which accompanies this m-file script. 40 ## which accompanies this m-file script.
49 ## 41 ##
50 ## This script may be used to generate the index.html page loaded by 42 ## Additional toolkit description can be added to the column header
51 ## the link below. 43 ## with a parameter named equal to the toolkit. For example:
52 ## 44 ##
53 ## @example 45 ## @example
54 ## @group 46 ## @group
55 ## http://octave.sourceforge.net/compare_plots 47 ## @code{html_compare_plot_demos ({"gnuplot", "fltk"}, "gnuplot", " 4.6 patchlevel 5")}
56 ## @end group 48 ## @end group
57 ## @end example 49 ## @end example
58 ## 50 ##
59 ## This is done by following the instructions below. 51 ## @seealso{compare_plot_demos, dump_demos, demo}
60 ##
61 ## @enumerate
62 ## @item Begin by downloading a local copy of the web page.
63 ##
64 ## @example
65 ## @group
66 ## $ wget -vcr --level 1 http://octave.sourceforge.net/compare_plots/
67 ## @end group
68 ## @end example
69 ##
70 ## @item Use @code{dump_demos} to produce the script used to produce the
71 ## demo plots. In this example the script is @code{dump.m}.
72 ##
73 ## @example
74 ## @group
75 ## octave:1> dump_demos plot dump.m png
76 ## @end group
77 ## @end example
78 ##
79 ## @item Produce the gnuplot and fltk plots, and place them in their
80 ## designated directories.
81 ##
82 ## @example
83 ## @group
84 ## octave:2> dump
85 ## octave:3> movefile *.png octave.sourceforge.net/compare_plots/gnuplot/.
86 ## octave:4> graphics_toolkit fltk
87 ## octave:5> close all
88 ## octave:6> dump
89 ## octave:7> movefile *.png octave.sourceforge.net/compare_plots/fltk/.
90 ## @end group
91 ## @end example
92 ##
93 ## @item Start Matlab and edit the script @code{dump.m} to correct the
94 ## remaining Octave specific syntax so that it will run under Matlab.
95 ##
96 ## @item Run @code{dump.m} under Matlab, and place the plots in the
97 ## designated matlab directory.
98 ##
99 ## @example
100 ## @group
101 ## >> dump
102 ## >> movefile *.png octave.sourceforge.net/compare_plots/matlab/.
103 ## @end group
104 ## @end example
105 ##
106 ## @item The web page comparing all plot demos is created by
107 ##
108 ## @example
109 ## @group
110 ## octave:8> cd octave.sourceforge.net/compare_plots
111 ## octave:9> html_compare output index.html
112 ## @end group
113 ## @end example
114 ##
115 ## @item Finally, the new page may be loaded into your browser.
116 ##
117 ## @seealso{dump_demos, demo}
118 ## @end deftypefn 52 ## @end deftypefn
119 53
120 ## Author: Ben Abbott <bpabbott@mac.com> 54 ## Author: Ben Abbott <bpabbott@mac.com>
121 55
122 function html_compare_plot_demos (varargin) 56 function html_compare_plot_demos (toolkits, varargin)
123 57
124 ## TODO - Names of the toolkits should be input 58 ## Set defaults
125 ## Set defaults
126 in.date = datestr (now (), 0);
127 in.fmt = "png"; 59 in.fmt = "png";
128 in.figfiles = {}; 60 in.figfiles = {};
129 in.octave = sprintf ("Octave %s", version); 61 in.output= "compare_plot_demos.html";
130 in.output= "compare_plots.html";
131 in.template = "html_plot_demos_template.html"; 62 in.template = "html_plot_demos_template.html";
132 in.toolkits = {"gnuplot", "matlab", "fltk"}; 63 in.column_width = 600;
133 64
134 ## Parse inputs 65 ## Parse inputs
135 for n = 1:2:numel(varargin) 66 for n = 1:2:numel(varargin)
136 in.(lower(varargin{n})) = varargin{n+1}; 67 in.(lower(varargin{n})) = varargin{n+1};
137 endfor 68 endfor
138 69
139 for t = 1:numel(in.toolkits) 70 ## Compile a list of all files for all toolkits
140 if (! isfield (in, in.toolkits{t})) 71 for t = 1:numel(toolkits)
141 ## Column headers for the html page 72 filter = sprintf ("%s/*.%s", toolkits{t}, in.fmt);
142 in.(in.toolkits{t}) = upper (in.toolkits{t}); 73 in.figfiles = union (in.figfiles, {dir(filter).name});
143 endif
144 ## Compile a list of all files for all toolkits
145 if (t == 1)
146 in.figfiles = {dir(sprintf ("gnuplot/*.%s", in.fmt)).name};
147 else
148 filter = sprintf ("%s/*.%s", in.toolkits{t}, in.fmt);
149 in.figfiles = union (in.figfiles, {dir(filter).name});
150 endif
151 endfor 74 endfor
152 75
153 fid = fopen (which (in.template), "r"); 76 fid = fopen (which (in.template), "r");
154 template = char (fread (fid)) .'; 77 template = char (fread (fid)) .';
155 fclose (fid); 78 fclose (fid);
156 79
157 template = strrep (template, "##OCTAVE##", in.octave); 80 anchor = "<!-- ##ADD TABLE HERE## -->";
158 template = strrep (template, "##GNUPLOT##", in.gnuplot); 81 n = findstr (template, anchor);
159 template = strrep (template, "##MATLAB##", in.matlab); 82 header = template(1:n-1);
160 83 trailer = template(n+numel(anchor):end);
161 n1 = findstr (template, "<!-- ##BEGIN## -->");
162 n2 = findstr (template, "<!-- ##END## -->");
163 header = template(1:n1-1);
164 middle = template(n1+18:n2-1);
165 trailer = template(n2+15:end);
166 84
167 fid = fopen (in.output, "w"); 85 fid = fopen (in.output, "w");
168 unwind_protect 86 unwind_protect
169 fputs (fid, header); 87 fputs (fid, header);
88 fprintf (fid, "<p><b>\nGenerated on %s by %s with GNU Octave %s</p>",
89 datestr (now (), 0), mfilename, version);
90
91 ## Create table header
92 fprintf (fid, "<table border='1'><tr>\n");
93 for t = 1:numel(toolkits)
94 ## set default
95 column_header = upper (toolkits{t});
96 if (isfield (in, toolkits{t}))
97 column_header = strcat (column_header, in.(toolkits{t}));
98 endif
99 fprintf (fid, '<th>%s <a href="%s/diary.log">diary</a></th>\n', column_header, toolkits{t});
100 endfor
101 fprintf (fid, "</tr>\n");
102
170 for m = 1:numel(in.figfiles) 103 for m = 1:numel(in.figfiles)
171 [~, file] = fileparts (in.figfiles{m}); 104 [~, file] = fileparts (in.figfiles{m});
172 fputs (fid, strrep (middle, "##PLOT##", strcat (file, ".", in.fmt))); 105 fn = strcat (file, ".", in.fmt);
106 fprintf (fid, "<tr>\n");
107 for k = toolkits
108 ffn = fullfile (k{:}, fn);
109 fprintf (fid, " <td>%s<br>", ffn);
110 if (exist (ffn, "file"))
111 fprintf (fid, "<img src='%s' style='width: %dpx;'>", ffn, in.column_width);
112 else
113 err_fn = regexprep(ffn, ".png", ".err");
114 if (! exist (err_fn, "file"))
115 warning("File %s doesn't exist...", err_fn);
116 else
117 err_fid = fopen (err_fn);
118 msg = char (fread (err_fid))';
119 fclose (err_fid);
120 fprintf (fid, "%s", strrep (msg, "\n", "<br>"));
121 endif
122 endif
123 fprintf (fid, "</td>\n");
124 endfor
125 fprintf (fid, "</tr>\n");
173 endfor 126 endfor
174 fputs (fid, trailer); 127 fputs (fid, trailer);
175 unwind_protect_cleanup 128 unwind_protect_cleanup
176 fclose (fid); 129 fclose (fid);
177 end_unwind_protect 130 end_unwind_protect