annotate scripts/testfun/private/dump_demos.m @ 18877:1b02bfff39d0

Moved scripts for plot comparison to ./private * compare_plot_demos.m, dump_demos.m, html_compare_plot_demos.m, html_plot_demos_template.html: Moved to ./private
author Andreas Weber <andy.weber.aw@gmail.com>
date Sun, 29 Jun 2014 13:58:33 +0200
parents scripts/testfun/dump_demos.m@0075f3fba930
children b8934a57e13e
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})
18874
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
24 ## Produces a script, with the name specified by @var{mfile}, containing
18875
0075f3fba930 dump_demos.m: Update to match new plot directory structure
Andreas Weber <andy.weber.aw@gmail.com>
parents: 18874
diff changeset
25 ## the demos in the directories, @var{dirs}. The demos are assumed to produce
18874
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
26 ## graphical output, whose renderings are saved with specified format,
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 ##
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
31 ## @table @samp
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}
0075f3fba930 dump_demos.m: Update to match new plot directory structure
Andreas Weber <andy.weber.aw@gmail.com>
parents: 18874
diff changeset
33 ## @code{@{"plot/appearance", "plot/draw", "plot/util"@}}
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 ## @group
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
45 ## dump_demos plot dump.m png
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
46 ## @end group
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
47 ## @end example
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
48 ## @seealso{fntests, test, demo}
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
49 ## @end deftypefn
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
50
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
51 ## Author: Søren Hauberg <soren@hauberg.org>
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
52
18875
0075f3fba930 dump_demos.m: Update to match new plot directory structure
Andreas Weber <andy.weber.aw@gmail.com>
parents: 18874
diff changeset
53 function dump_demos (dirs= {"plot/appearance", "plot/draw", "plot/util"}, output="dump.m", fmt="png")
0075f3fba930 dump_demos.m: Update to match new plot directory structure
Andreas Weber <andy.weber.aw@gmail.com>
parents: 18874
diff changeset
54
0075f3fba930 dump_demos.m: Update to match new plot directory structure
Andreas Weber <andy.weber.aw@gmail.com>
parents: 18874
diff changeset
55 if (nargin > 3)
18874
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 endif
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
58
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
59 if (strfind (output, ".m") != numel (output) - 1)
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
60 output = strcat (output, ".m");
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
61 endif
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
62
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
63 ## Create script beginning (close figures, etc.)
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
64 fid = fopen (output, "w");
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
65 n = find (output == ".", 1, "last");
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
66 if (isempty (n))
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
67 n = numel (output);
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
68 else
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
69 n = n - 1;
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
70 endif
18875
0075f3fba930 dump_demos.m: Update to match new plot directory structure
Andreas Weber <andy.weber.aw@gmail.com>
parents: 18874
diff changeset
71 fprintf (fid, "%% DO NOT EDIT! Generated automatically by dump_demos.m\n");
18874
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
72 fprintf (fid, "function %s ()\n", output(1:n));
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
73 fprintf (fid, "close all\n");
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
74 fprintf (fid, "more off\n");
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)
18875
0075f3fba930 dump_demos.m: Update to match new plot directory structure
Andreas Weber <andy.weber.aw@gmail.com>
parents: 18874
diff changeset
78 if (!is_absolute_filename (dirs{i}))
0075f3fba930 dump_demos.m: Update to match new plot directory structure
Andreas Weber <andy.weber.aw@gmail.com>
parents: 18874
diff changeset
79 fullname = dir_in_loadpath (dirs{i});
0075f3fba930 dump_demos.m: Update to match new plot directory structure
Andreas Weber <andy.weber.aw@gmail.com>
parents: 18874
diff changeset
80 if (! isempty (fullname))
0075f3fba930 dump_demos.m: Update to match new plot directory structure
Andreas Weber <andy.weber.aw@gmail.com>
parents: 18874
diff changeset
81 dirs{i} = fullname;
0075f3fba930 dump_demos.m: Update to match new plot directory structure
Andreas Weber <andy.weber.aw@gmail.com>
parents: 18874
diff changeset
82 else
0075f3fba930 dump_demos.m: Update to match new plot directory structure
Andreas Weber <andy.weber.aw@gmail.com>
parents: 18874
diff changeset
83 error ("dump_demos: expecting DIRS argument to be a cell arrays of strings with directory names");
0075f3fba930 dump_demos.m: Update to match new plot directory structure
Andreas Weber <andy.weber.aw@gmail.com>
parents: 18874
diff changeset
84 endif
0075f3fba930 dump_demos.m: Update to match new plot directory structure
Andreas Weber <andy.weber.aw@gmail.com>
parents: 18874
diff changeset
85 endif
18874
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
86 d = dirs{i};
18875
0075f3fba930 dump_demos.m: Update to match new plot directory structure
Andreas Weber <andy.weber.aw@gmail.com>
parents: 18874
diff changeset
87 if (!exist (d, "dir"))
0075f3fba930 dump_demos.m: Update to match new plot directory structure
Andreas Weber <andy.weber.aw@gmail.com>
parents: 18874
diff changeset
88 error ("dump_demos: directory %s doesn't exist", d);
0075f3fba930 dump_demos.m: Update to match new plot directory structure
Andreas Weber <andy.weber.aw@gmail.com>
parents: 18874
diff changeset
89 endif
18874
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
90 dump_all_demos (d, fid, fmt);
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
91 endfor
18875
0075f3fba930 dump_demos.m: Update to match new plot directory structure
Andreas Weber <andy.weber.aw@gmail.com>
parents: 18874
diff changeset
92
18874
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
93 ## Create script ending
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
94 fprintf (fid, "end\n\n")
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
95
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
96 ## TODO - Should dump_demos() attempt to convert the demos to traditional
18875
0075f3fba930 dump_demos.m: Update to match new plot directory structure
Andreas Weber <andy.weber.aw@gmail.com>
parents: 18874
diff changeset
97 ## syntax.
18874
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
98 ## (1) oct2mat() to convert some Octave specific syntax.
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
99 ## (2) Embed sombrero(), vec(), cstrcat() and assert() in demos ?
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
100
18875
0075f3fba930 dump_demos.m: Update to match new plot directory structure
Andreas Weber <andy.weber.aw@gmail.com>
parents: 18874
diff changeset
101 ## sombrero has now a default argument which isn't supported from matlab
0075f3fba930 dump_demos.m: Update to match new plot directory structure
Andreas Weber <andy.weber.aw@gmail.com>
parents: 18874
diff changeset
102 ## http://octave.1599824.n4.nabble.com/sombrero-default-argument-matlab-compatibility-td4665016.html
0075f3fba930 dump_demos.m: Update to match new plot directory structure
Andreas Weber <andy.weber.aw@gmail.com>
parents: 18874
diff changeset
103 ## TODO: we need to change it prior running
0075f3fba930 dump_demos.m: Update to match new plot directory structure
Andreas Weber <andy.weber.aw@gmail.com>
parents: 18874
diff changeset
104 ## -function [x, y, z] = sombrero (n = 41)
0075f3fba930 dump_demos.m: Update to match new plot directory structure
Andreas Weber <andy.weber.aw@gmail.com>
parents: 18874
diff changeset
105 ## +function [x, y, z] = sombrero (n)
0075f3fba930 dump_demos.m: Update to match new plot directory structure
Andreas Weber <andy.weber.aw@gmail.com>
parents: 18874
diff changeset
106 ## +
0075f3fba930 dump_demos.m: Update to match new plot directory structure
Andreas Weber <andy.weber.aw@gmail.com>
parents: 18874
diff changeset
107 ## + if (nargin == 0)
0075f3fba930 dump_demos.m: Update to match new plot directory structure
Andreas Weber <andy.weber.aw@gmail.com>
parents: 18874
diff changeset
108 ## + n = 41;
0075f3fba930 dump_demos.m: Update to match new plot directory structure
Andreas Weber <andy.weber.aw@gmail.com>
parents: 18874
diff changeset
109 ## + endif
0075f3fba930 dump_demos.m: Update to match new plot directory structure
Andreas Weber <andy.weber.aw@gmail.com>
parents: 18874
diff changeset
110
18874
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
111 for mfile = {"sombrero"}
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
112 f = which (mfile{1});
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
113 fid2 = fopen (f);
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
114 code = char (fread (fid2));
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
115 code = oct2mat (code);
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
116 fprintf (fid, "%s", code);
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
117 fclose (fid2);
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
118 endfor
18875
0075f3fba930 dump_demos.m: Update to match new plot directory structure
Andreas Weber <andy.weber.aw@gmail.com>
parents: 18874
diff changeset
119 %~
0075f3fba930 dump_demos.m: Update to match new plot directory structure
Andreas Weber <andy.weber.aw@gmail.com>
parents: 18874
diff changeset
120 %~ fprintf (fid, "function x = vec (x)\n")
0075f3fba930 dump_demos.m: Update to match new plot directory structure
Andreas Weber <andy.weber.aw@gmail.com>
parents: 18874
diff changeset
121 %~ fprintf (fid, " x = x(:);\n")
0075f3fba930 dump_demos.m: Update to match new plot directory structure
Andreas Weber <andy.weber.aw@gmail.com>
parents: 18874
diff changeset
122 %~ fprintf (fid, "end\n")
0075f3fba930 dump_demos.m: Update to match new plot directory structure
Andreas Weber <andy.weber.aw@gmail.com>
parents: 18874
diff changeset
123 %~
0075f3fba930 dump_demos.m: Update to match new plot directory structure
Andreas Weber <andy.weber.aw@gmail.com>
parents: 18874
diff changeset
124 %~ fprintf (fid, "function str = cstrcat (varargin)\n")
0075f3fba930 dump_demos.m: Update to match new plot directory structure
Andreas Weber <andy.weber.aw@gmail.com>
parents: 18874
diff changeset
125 %~ fprintf (fid, " str = [varargin{:}];\n")
0075f3fba930 dump_demos.m: Update to match new plot directory structure
Andreas Weber <andy.weber.aw@gmail.com>
parents: 18874
diff changeset
126 %~ fprintf (fid, "end\n")
0075f3fba930 dump_demos.m: Update to match new plot directory structure
Andreas Weber <andy.weber.aw@gmail.com>
parents: 18874
diff changeset
127 %~
0075f3fba930 dump_demos.m: Update to match new plot directory structure
Andreas Weber <andy.weber.aw@gmail.com>
parents: 18874
diff changeset
128 %~ fprintf (fid, "function assert (varargin)\n")
0075f3fba930 dump_demos.m: Update to match new plot directory structure
Andreas Weber <andy.weber.aw@gmail.com>
parents: 18874
diff changeset
129 %~ fprintf (fid, "%% Do nothing.\n")
0075f3fba930 dump_demos.m: Update to match new plot directory structure
Andreas Weber <andy.weber.aw@gmail.com>
parents: 18874
diff changeset
130 %~ fprintf (fid, "end\n")
18874
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
131
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
132 ## Close script
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
133 fclose (fid);
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
134 endfunction
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
135
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
136 function dump_all_demos (directory, fid, fmt)
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
137 dirinfo = dir (fullfile (directory, "*.m"));
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
138 flist = {dirinfo.name};
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
139 ## Remove uigetdir, uigetfile, uiputfile, etc.
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
140 flist = flist(! strncmp (flist, "ui", 2));
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
141 for i = 1:numel (flist)
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
142 fun = flist{i};
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
143 fun (end-1:end) = []; # remove .m
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
144 demos = get_demos (fun);
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
145 for d = 1:numel (demos)
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
146 if (d < 10)
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
147 idx = sprintf ("0%d", d);
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
148 else
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
149 idx = sprintf ("%d", d);
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
150 end
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
151 fprintf (fid, "\ntry\n");
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
152 fprintf (fid, " %s\n\n", demos {d});
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
153 fprintf (fid, " drawnow\n");
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
154 fprintf (fid, " num_figures = get(0, 'currentfigure');\n");
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
155 fprintf (fid, " for fig = 1:num_figures\n");
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
156 fprintf (fid, " figure (fig);\n");
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
157 fprintf (fid, " name = sprintf ('%s_%s_%%d.%s', fig);\n", fun, idx, fmt);
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
158 fprintf (fid, " if (numel (dir (name)) == 0)\n");
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
159 fprintf (fid, " fprintf ('Printing ""%%s"" ... ', name);\n")
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
160 fprintf (fid, " print ('-d%s', name);\n", fmt);
18875
0075f3fba930 dump_demos.m: Update to match new plot directory structure
Andreas Weber <andy.weber.aw@gmail.com>
parents: 18874
diff changeset
161 # fprintf (fid, " pause (1);\n");
18874
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
162 fprintf (fid, " fprintf ('done\\n');\n");
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
163 fprintf (fid, " else\n");
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
164 fprintf (fid, " fprintf ('File ""%%s"" exists.\\n', name);\n")
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
165 fprintf (fid, " end\n");
18875
0075f3fba930 dump_demos.m: Update to match new plot directory structure
Andreas Weber <andy.weber.aw@gmail.com>
parents: 18874
diff changeset
166 # fprintf (fid, " drawnow ();\n");
18874
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
167 fprintf (fid, " end\n");
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
168 fprintf (fid, " close (2:num_figures)\n");
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
169 fprintf (fid, "catch\n");
18875
0075f3fba930 dump_demos.m: Update to match new plot directory structure
Andreas Weber <andy.weber.aw@gmail.com>
parents: 18874
diff changeset
170 fprintf (fid, " fprintf ('ERROR in %s_%s: %%s\\n', lasterr ());\n", fun, idx);
18874
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
171 fprintf (fid, "end\n\n");
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
172 endfor
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
173 endfor
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
174 fprintf (fid, "close all\n");
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
175 endfunction
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
176
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
177 function retval = get_demos (fun)
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
178 [code, idx] = test (fun, "grabdemo");
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
179 num_demos = length (idx) - 1;
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
180 retval = cell (1, num_demos);
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
181 ## Now split the demos into a cell array
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
182 for k = 1:num_demos
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
183 retval {k} = oct2mat (code (idx (k):idx (k+1)-1));
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
184 endfor
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
185 endfunction
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
186
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
187 function code = oct2mat (code)
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
188 ## Simple hacks to make things Matlab compatible
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
189 code = strrep (code, "%!", "%%");
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
190 code = strrep (code, "!", "~");
18875
0075f3fba930 dump_demos.m: Update to match new plot directory structure
Andreas Weber <andy.weber.aw@gmail.com>
parents: 18874
diff changeset
191 ## Simple replacing double quotes with single quotes
0075f3fba930 dump_demos.m: Update to match new plot directory structure
Andreas Weber <andy.weber.aw@gmail.com>
parents: 18874
diff changeset
192 ## causes problems with strings like 'hello "world"'
0075f3fba930 dump_demos.m: Update to match new plot directory structure
Andreas Weber <andy.weber.aw@gmail.com>
parents: 18874
diff changeset
193 #code = strrep (code, "\"", "'");
18874
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
194 code = strrep (code, "#", "%");
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
195 ## Fix the format specs for the errobar demos
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
196 code = strrep (code, "%r", "#r");
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
197 code = strrep (code, "%~", "#~");
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
198 endkeywords = {"endfor", "endif", "endwhile", "end_try_catch", ...
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
199 "endfunction", "end_unwind_protect"};
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
200 for k = 1:numel (endkeywords)
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
201 code = strrep (code, endkeywords{k}, "end");
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
202 endfor
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
203 commentkeywords = {"unwind_proect"};
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
204 for k = 1:numel (commentkeywords)
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
205 code = strrep (code, commentkeywords{k}, strcat ("%", commentkeywords{k}));
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
206 endfor
c74673161752 Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
207 endfunction