annotate scripts/testfun/private/dump_demos.m @ 18959:4c45986a278e

dump_demos.m: Check if file exists before demo and add timing. * dump_demos.m: Skip demo if output print file already exists. Add tic/toc timing for demo (calculation + plotting) and printing. This allows benchmarks and finding regressions which causes slow plotting or printing.
author Andreas Weber <andy.weber.aw@gmail.com>
date Sat, 26 Jul 2014 12:23:11 +0200
parents 87324260043d
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) 2010 Søren Hauberg
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} {} dump_demos ()
18875
0075f3fba930 dump_demos.m: Update to match new plot directory structure
Andreas Weber <andy.weber.aw@gmail.com>
parents: 18874
diff changeset
21 ## @deftypefnx {Function File} {} dump_demos (@var{dirs})
0075f3fba930 dump_demos.m: Update to match new plot directory structure
Andreas Weber <andy.weber.aw@gmail.com>
parents: 18874
diff changeset
22 ## @deftypefnx {Function File} {} dump_demos (@var{dirs}, @var{mfile})
0075f3fba930 dump_demos.m: Update to match new plot directory structure
Andreas Weber <andy.weber.aw@gmail.com>
parents: 18874
diff changeset
23 ## @deftypefnx {Function File} {} dump_demos (@var{dirs}, @var{mfile}, @var{fmt})
18895
b8934a57e13e Improve plot comparison scripts.
Rik <rik@octave.org>
parents: 18877
diff changeset
24 ## Produce a script, with the name specified by @var{mfile}, containing
b8934a57e13e Improve plot comparison scripts.
Rik <rik@octave.org>
parents: 18877
diff changeset
25 ## the demos in the directories, @var{dirs}. The demos are assumed to produce
b8934a57e13e Improve plot comparison scripts.
Rik <rik@octave.org>
parents: 18877
diff changeset
26 ## graphical output, whose renderings are saved with the specified format,
18874
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
27 ## @var{fmt}.
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
28 ##
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
29 ## The defaults for each input are;
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
30 ##
18895
b8934a57e13e Improve plot comparison scripts.
Rik <rik@octave.org>
parents: 18877
diff changeset
31 ## @table @var
18875
0075f3fba930 dump_demos.m: Update to match new plot directory structure
Andreas Weber <andy.weber.aw@gmail.com>
parents: 18874
diff changeset
32 ## @item @var{dirs}
18925
87324260043d Improve plot comparison scripts.
Andreas Weber <andy.weber.aw@gmail.com>
parents: 18897
diff changeset
33 ## @code{@{"plot/appearance", "plot/draw", "plot/util", "image"@}}
18874
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
34 ## @item @var{mfile}
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
35 ## @code{"dump.m"}
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
36 ## @item @var{fmt}
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
37 ## @code{"png"}
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
38 ## @end table
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
39 ##
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
40 ## For example, to produce PNG output for all demos of the functions
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
41 ## in the plot directory;
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
42 ##
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
43 ## @example
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
44 ## dump_demos plot dump.m png
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
45 ## @end example
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
46 ## @seealso{fntests, test, demo}
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
47 ## @end deftypefn
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
48
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
49 ## Author: Søren Hauberg <soren@hauberg.org>
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
50
18925
87324260043d Improve plot comparison scripts.
Andreas Weber <andy.weber.aw@gmail.com>
parents: 18897
diff changeset
51 function dump_demos (dirs={"plot/appearance", "plot/draw", "plot/util", "image"}, output="dump_plot_demos.m", fmt="png")
18875
0075f3fba930 dump_demos.m: Update to match new plot directory structure
Andreas Weber <andy.weber.aw@gmail.com>
parents: 18874
diff changeset
52
0075f3fba930 dump_demos.m: Update to match new plot directory structure
Andreas Weber <andy.weber.aw@gmail.com>
parents: 18874
diff changeset
53 if (nargin > 3)
18874
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
54 print_usage ();
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
55 endif
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
56
18895
b8934a57e13e Improve plot comparison scripts.
Rik <rik@octave.org>
parents: 18877
diff changeset
57 if (ischar (dirs))
b8934a57e13e Improve plot comparison scripts.
Rik <rik@octave.org>
parents: 18877
diff changeset
58 dirs = {dirs};
b8934a57e13e Improve plot comparison scripts.
Rik <rik@octave.org>
parents: 18877
diff changeset
59 elseif (! iscellstr (dirs))
b8934a57e13e Improve plot comparison scripts.
Rik <rik@octave.org>
parents: 18877
diff changeset
60 error ("dump_demos: DIRS must be a cell array of strings with directory names");
b8934a57e13e Improve plot comparison scripts.
Rik <rik@octave.org>
parents: 18877
diff changeset
61 endif
b8934a57e13e Improve plot comparison scripts.
Rik <rik@octave.org>
parents: 18877
diff changeset
62
b8934a57e13e Improve plot comparison scripts.
Rik <rik@octave.org>
parents: 18877
diff changeset
63 [~, funcname, ext] = fileparts (output);
b8934a57e13e Improve plot comparison scripts.
Rik <rik@octave.org>
parents: 18877
diff changeset
64 if (isempty (ext))
b8934a57e13e Improve plot comparison scripts.
Rik <rik@octave.org>
parents: 18877
diff changeset
65 output = [output ".m"];
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
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
68 ## Create script beginning (close figures, etc.)
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
69 fid = fopen (output, "w");
18875
0075f3fba930 dump_demos.m: Update to match new plot directory structure
Andreas Weber <andy.weber.aw@gmail.com>
parents: 18874
diff changeset
70 fprintf (fid, "%% DO NOT EDIT! Generated automatically by dump_demos.m\n");
18895
b8934a57e13e Improve plot comparison scripts.
Rik <rik@octave.org>
parents: 18877
diff changeset
71 fprintf (fid, "function %s ()\n", funcname);
18874
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
72 fprintf (fid, "close all\n");
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
73 fprintf (fid, "more off\n");
18925
87324260043d Improve plot comparison scripts.
Andreas Weber <andy.weber.aw@gmail.com>
parents: 18897
diff changeset
74 fprintf (fid, "diary diary.log\n");
18874
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
75
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
76 ## Run and print the demos in each directory
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
77 for i = 1:numel (dirs)
18895
b8934a57e13e Improve plot comparison scripts.
Rik <rik@octave.org>
parents: 18877
diff changeset
78 d = dirs{i};
b8934a57e13e Improve plot comparison scripts.
Rik <rik@octave.org>
parents: 18877
diff changeset
79 if (! is_absolute_filename (d))
b8934a57e13e Improve plot comparison scripts.
Rik <rik@octave.org>
parents: 18877
diff changeset
80 d = dir_in_loadpath (d);
18875
0075f3fba930 dump_demos.m: Update to match new plot directory structure
Andreas Weber <andy.weber.aw@gmail.com>
parents: 18874
diff changeset
81 endif
18895
b8934a57e13e Improve plot comparison scripts.
Rik <rik@octave.org>
parents: 18877
diff changeset
82 if (! exist (d, "dir"))
b8934a57e13e Improve plot comparison scripts.
Rik <rik@octave.org>
parents: 18877
diff changeset
83 error ("dump_demos: directory %s does not exist", d);
18875
0075f3fba930 dump_demos.m: Update to match new plot directory structure
Andreas Weber <andy.weber.aw@gmail.com>
parents: 18874
diff changeset
84 endif
18874
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
85 dump_all_demos (d, fid, fmt);
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
86 endfor
18875
0075f3fba930 dump_demos.m: Update to match new plot directory structure
Andreas Weber <andy.weber.aw@gmail.com>
parents: 18874
diff changeset
87
18925
87324260043d Improve plot comparison scripts.
Andreas Weber <andy.weber.aw@gmail.com>
parents: 18897
diff changeset
88 ## Stop and flush diary
87324260043d Improve plot comparison scripts.
Andreas Weber <andy.weber.aw@gmail.com>
parents: 18897
diff changeset
89 fprintf (fid, "diary off\n");
87324260043d Improve plot comparison scripts.
Andreas Weber <andy.weber.aw@gmail.com>
parents: 18897
diff changeset
90
18874
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
91 ## Create script ending
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
92 fprintf (fid, "end\n\n")
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
93
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
94 ## Close script
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
95 fclose (fid);
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
96 endfunction
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
97
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
98 function dump_all_demos (directory, fid, fmt)
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
99 dirinfo = dir (fullfile (directory, "*.m"));
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
100 flist = {dirinfo.name};
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
101 ## Remove uigetdir, uigetfile, uiputfile, etc.
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
102 flist = flist(! strncmp (flist, "ui", 2));
18895
b8934a57e13e Improve plot comparison scripts.
Rik <rik@octave.org>
parents: 18877
diff changeset
103 ## Remove linkaxes, linkprops
b8934a57e13e Improve plot comparison scripts.
Rik <rik@octave.org>
parents: 18877
diff changeset
104 flist = flist(! strncmp (flist, "link", 4));
b8934a57e13e Improve plot comparison scripts.
Rik <rik@octave.org>
parents: 18877
diff changeset
105 ## Remove colormap
b8934a57e13e Improve plot comparison scripts.
Rik <rik@octave.org>
parents: 18877
diff changeset
106 flist = flist(! strncmp (flist, "colormap", 8));
18874
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
107 for i = 1:numel (flist)
18895
b8934a57e13e Improve plot comparison scripts.
Rik <rik@octave.org>
parents: 18877
diff changeset
108 fcn = flist{i};
b8934a57e13e Improve plot comparison scripts.
Rik <rik@octave.org>
parents: 18877
diff changeset
109 fcn(end-1:end) = []; # remove .m
b8934a57e13e Improve plot comparison scripts.
Rik <rik@octave.org>
parents: 18877
diff changeset
110 demos = get_demos (fcn);
18874
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
111 for d = 1:numel (demos)
18895
b8934a57e13e Improve plot comparison scripts.
Rik <rik@octave.org>
parents: 18877
diff changeset
112 idx = sprintf ("%02d", d);
18925
87324260043d Improve plot comparison scripts.
Andreas Weber <andy.weber.aw@gmail.com>
parents: 18897
diff changeset
113 base_fn = sprintf ("%s_%s", fcn, idx);
18959
4c45986a278e dump_demos.m: Check if file exists before demo and add timing.
Andreas Weber <andy.weber.aw@gmail.com>
parents: 18925
diff changeset
114 fn = sprintf ('%s.%s', base_fn, fmt);
18874
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
115 fprintf (fid, "\ntry\n");
18959
4c45986a278e dump_demos.m: Check if file exists before demo and add timing.
Andreas Weber <andy.weber.aw@gmail.com>
parents: 18925
diff changeset
116 ## First check if the file already exists, skip demo if found
4c45986a278e dump_demos.m: Check if file exists before demo and add timing.
Andreas Weber <andy.weber.aw@gmail.com>
parents: 18925
diff changeset
117 fprintf (fid, " if (! exist ('%s', 'file'))\n", fn);
18925
87324260043d Improve plot comparison scripts.
Andreas Weber <andy.weber.aw@gmail.com>
parents: 18897
diff changeset
118 ## Invoke the ancient, deprecated random seed
87324260043d Improve plot comparison scripts.
Andreas Weber <andy.weber.aw@gmail.com>
parents: 18897
diff changeset
119 ## generators, but there is an initialization mismatch with the more modern
87324260043d Improve plot comparison scripts.
Andreas Weber <andy.weber.aw@gmail.com>
parents: 18897
diff changeset
120 ## generators reported here (https://savannah.gnu.org/bugs/?42557).
87324260043d Improve plot comparison scripts.
Andreas Weber <andy.weber.aw@gmail.com>
parents: 18897
diff changeset
121 fprintf (fid, " rand ('seed', 1);\n");
18959
4c45986a278e dump_demos.m: Check if file exists before demo and add timing.
Andreas Weber <andy.weber.aw@gmail.com>
parents: 18925
diff changeset
122 fprintf (fid, " tic ();\n");
18895
b8934a57e13e Improve plot comparison scripts.
Rik <rik@octave.org>
parents: 18877
diff changeset
123 fprintf (fid, " %s\n\n", demos{d});
18959
4c45986a278e dump_demos.m: Check if file exists before demo and add timing.
Andreas Weber <andy.weber.aw@gmail.com>
parents: 18925
diff changeset
124 fprintf (fid, " t_plot = toc ();\n");
18895
b8934a57e13e Improve plot comparison scripts.
Rik <rik@octave.org>
parents: 18877
diff changeset
125 fprintf (fid, " fig = (get (0, 'currentfigure'));\n");
b8934a57e13e Improve plot comparison scripts.
Rik <rik@octave.org>
parents: 18877
diff changeset
126 fprintf (fid, " if (~ isempty (fig))\n");
18874
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
127 fprintf (fid, " figure (fig);\n");
18959
4c45986a278e dump_demos.m: Check if file exists before demo and add timing.
Andreas Weber <andy.weber.aw@gmail.com>
parents: 18925
diff changeset
128 fprintf (fid, " fprintf ('Printing ""%s"" ... ');\n", fn);
4c45986a278e dump_demos.m: Check if file exists before demo and add timing.
Andreas Weber <andy.weber.aw@gmail.com>
parents: 18925
diff changeset
129 fprintf (fid, " tic ();\n");
4c45986a278e dump_demos.m: Check if file exists before demo and add timing.
Andreas Weber <andy.weber.aw@gmail.com>
parents: 18925
diff changeset
130 fprintf (fid, " print ('-d%s', '%s');\n", fmt, fn);
4c45986a278e dump_demos.m: Check if file exists before demo and add timing.
Andreas Weber <andy.weber.aw@gmail.com>
parents: 18925
diff changeset
131 fprintf (fid, " t_print = toc ();\n");
4c45986a278e dump_demos.m: Check if file exists before demo and add timing.
Andreas Weber <andy.weber.aw@gmail.com>
parents: 18925
diff changeset
132 fprintf (fid, " fprintf ('[%%f %%f] done\\n',t_plot, t_print);\n");
18874
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
133 fprintf (fid, " end\n");
18895
b8934a57e13e Improve plot comparison scripts.
Rik <rik@octave.org>
parents: 18877
diff changeset
134 # Temporary fix for cruft accumulating in figure window.
b8934a57e13e Improve plot comparison scripts.
Rik <rik@octave.org>
parents: 18877
diff changeset
135 fprintf (fid, " close ('all');\n");
18959
4c45986a278e dump_demos.m: Check if file exists before demo and add timing.
Andreas Weber <andy.weber.aw@gmail.com>
parents: 18925
diff changeset
136 fprintf (fid, " else\n");
4c45986a278e dump_demos.m: Check if file exists before demo and add timing.
Andreas Weber <andy.weber.aw@gmail.com>
parents: 18925
diff changeset
137 fprintf (fid, " fprintf ('File ""%s"" already exists.\\n');\n", fn);
4c45986a278e dump_demos.m: Check if file exists before demo and add timing.
Andreas Weber <andy.weber.aw@gmail.com>
parents: 18925
diff changeset
138 fprintf (fid, " end\n");
18874
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
139 fprintf (fid, "catch\n");
18925
87324260043d Improve plot comparison scripts.
Andreas Weber <andy.weber.aw@gmail.com>
parents: 18897
diff changeset
140 fprintf (fid, " fprintf ('ERROR in %s: %%s\\n', lasterr ());\n", base_fn);
87324260043d Improve plot comparison scripts.
Andreas Weber <andy.weber.aw@gmail.com>
parents: 18897
diff changeset
141 fprintf (fid, " err_fid = fopen ('%s.err', 'w');\n", base_fn);
87324260043d Improve plot comparison scripts.
Andreas Weber <andy.weber.aw@gmail.com>
parents: 18897
diff changeset
142 fprintf (fid, " fprintf (err_fid, '%%s', lasterr ());\n");
87324260043d Improve plot comparison scripts.
Andreas Weber <andy.weber.aw@gmail.com>
parents: 18897
diff changeset
143 fprintf (fid, " fclose (err_fid);\n");
18874
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
144 fprintf (fid, "end\n\n");
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
145 endfor
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
146 endfor
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
147 fprintf (fid, "close all\n");
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
148 endfunction
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
149
18895
b8934a57e13e Improve plot comparison scripts.
Rik <rik@octave.org>
parents: 18877
diff changeset
150 function retval = get_demos (fcn)
b8934a57e13e Improve plot comparison scripts.
Rik <rik@octave.org>
parents: 18877
diff changeset
151 [code, idx] = test (fcn, "grabdemo");
18874
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
152 num_demos = length (idx) - 1;
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
153 retval = cell (1, num_demos);
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
154 ## Now split the demos into a cell array
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
155 for k = 1:num_demos
18895
b8934a57e13e Improve plot comparison scripts.
Rik <rik@octave.org>
parents: 18877
diff changeset
156 retval{k} = oct2mat (code(idx(k):idx(k+1)-1));
18874
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
157 endfor
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
158 endfunction
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
159
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
160 function code = oct2mat (code)
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
161 ## Simple hacks to make things Matlab compatible
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
162 code = strrep (code, "%!", "%%");
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
163 code = strrep (code, "!", "~");
18895
b8934a57e13e Improve plot comparison scripts.
Rik <rik@octave.org>
parents: 18877
diff changeset
164 ## Simply replacing double quotes with single quotes
18875
0075f3fba930 dump_demos.m: Update to match new plot directory structure
Andreas Weber <andy.weber.aw@gmail.com>
parents: 18874
diff changeset
165 ## causes problems with strings like 'hello "world"'
18895
b8934a57e13e Improve plot comparison scripts.
Rik <rik@octave.org>
parents: 18877
diff changeset
166 ## More complicated regexprep targets only full double quoted strings
b8934a57e13e Improve plot comparison scripts.
Rik <rik@octave.org>
parents: 18877
diff changeset
167 code = regexprep (code, "^([^']*)\"(.*)\"", "$1'$2'",
b8934a57e13e Improve plot comparison scripts.
Rik <rik@octave.org>
parents: 18877
diff changeset
168 "lineanchors", "dotexceptnewline");
18874
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
169 code = strrep (code, "#", "%");
18895
b8934a57e13e Improve plot comparison scripts.
Rik <rik@octave.org>
parents: 18877
diff changeset
170 ## Fix the format specs for the errorbar demos changed by the line above
18874
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
171 code = strrep (code, "%r", "#r");
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
172 code = strrep (code, "%~", "#~");
18895
b8934a57e13e Improve plot comparison scripts.
Rik <rik@octave.org>
parents: 18877
diff changeset
173 endkeywords = {"endfor", "endfunction", "endif", "endwhile", "end_try_catch"};
18874
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
174 for k = 1:numel (endkeywords)
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
175 code = strrep (code, endkeywords{k}, "end");
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
176 endfor
18895
b8934a57e13e Improve plot comparison scripts.
Rik <rik@octave.org>
parents: 18877
diff changeset
177 commentkeywords = {"unwind_protect", "end_unwind_protect"};
18874
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
178 for k = 1:numel (commentkeywords)
18895
b8934a57e13e Improve plot comparison scripts.
Rik <rik@octave.org>
parents: 18877
diff changeset
179 code = strrep (code, commentkeywords{k}, ["%" commentkeywords{k}]);
18874
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
180 endfor
18895
b8934a57e13e Improve plot comparison scripts.
Rik <rik@octave.org>
parents: 18877
diff changeset
181
b8934a57e13e Improve plot comparison scripts.
Rik <rik@octave.org>
parents: 18877
diff changeset
182 ## Fix up sombrero which now has default argument in Octave
b8934a57e13e Improve plot comparison scripts.
Rik <rik@octave.org>
parents: 18877
diff changeset
183 code = strrep (code, "sombrero ()", "sombrero (41)");
18874
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
184 endfunction
18895
b8934a57e13e Improve plot comparison scripts.
Rik <rik@octave.org>
parents: 18877
diff changeset
185