comparison scripts/testfun/private/dump_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 4c45986a278e
comparison
equal deleted inserted replaced
18924:9a5e03801d23 18925:87324260043d
28 ## 28 ##
29 ## The defaults for each input are; 29 ## The defaults for each input are;
30 ## 30 ##
31 ## @table @var 31 ## @table @var
32 ## @item @var{dirs} 32 ## @item @var{dirs}
33 ## @code{@{"plot/appearance", "plot/draw", "plot/util", "image/"@}} 33 ## @code{@{"plot/appearance", "plot/draw", "plot/util", "image"@}}
34 ## @item @var{mfile} 34 ## @item @var{mfile}
35 ## @code{"dump.m"} 35 ## @code{"dump.m"}
36 ## @item @var{fmt} 36 ## @item @var{fmt}
37 ## @code{"png"} 37 ## @code{"png"}
38 ## @end table 38 ## @end table
46 ## @seealso{fntests, test, demo} 46 ## @seealso{fntests, test, demo}
47 ## @end deftypefn 47 ## @end deftypefn
48 48
49 ## Author: Søren Hauberg <soren@hauberg.org> 49 ## Author: Søren Hauberg <soren@hauberg.org>
50 50
51 function dump_demos (dirs={"plot/appearance", "plot/draw", "plot/util", "image/"}, output="dump.m", fmt="png") 51 function dump_demos (dirs={"plot/appearance", "plot/draw", "plot/util", "image"}, output="dump_plot_demos.m", fmt="png")
52 52
53 if (nargin > 3) 53 if (nargin > 3)
54 print_usage (); 54 print_usage ();
55 endif 55 endif
56 56
69 fid = fopen (output, "w"); 69 fid = fopen (output, "w");
70 fprintf (fid, "%% DO NOT EDIT! Generated automatically by dump_demos.m\n"); 70 fprintf (fid, "%% DO NOT EDIT! Generated automatically by dump_demos.m\n");
71 fprintf (fid, "function %s ()\n", funcname); 71 fprintf (fid, "function %s ()\n", funcname);
72 fprintf (fid, "close all\n"); 72 fprintf (fid, "close all\n");
73 fprintf (fid, "more off\n"); 73 fprintf (fid, "more off\n");
74 fprintf (fid, "diary diary.log\n");
74 75
75 ## Run and print the demos in each directory 76 ## Run and print the demos in each directory
76 for i = 1:numel (dirs) 77 for i = 1:numel (dirs)
77 d = dirs{i}; 78 d = dirs{i};
78 if (! is_absolute_filename (d)) 79 if (! is_absolute_filename (d))
81 if (! exist (d, "dir")) 82 if (! exist (d, "dir"))
82 error ("dump_demos: directory %s does not exist", d); 83 error ("dump_demos: directory %s does not exist", d);
83 endif 84 endif
84 dump_all_demos (d, fid, fmt); 85 dump_all_demos (d, fid, fmt);
85 endfor 86 endfor
87
88 ## Stop and flush diary
89 fprintf (fid, "diary off\n");
86 90
87 ## Create script ending 91 ## Create script ending
88 fprintf (fid, "end\n\n") 92 fprintf (fid, "end\n\n")
89 93
90 ## Close script 94 ## Close script
104 fcn = flist{i}; 108 fcn = flist{i};
105 fcn(end-1:end) = []; # remove .m 109 fcn(end-1:end) = []; # remove .m
106 demos = get_demos (fcn); 110 demos = get_demos (fcn);
107 for d = 1:numel (demos) 111 for d = 1:numel (demos)
108 idx = sprintf ("%02d", d); 112 idx = sprintf ("%02d", d);
113 base_fn = sprintf ("%s_%s", fcn, idx);
109 fprintf (fid, "\ntry\n"); 114 fprintf (fid, "\ntry\n");
115 ## Invoke the ancient, deprecated random seed
116 ## generators, but there is an initialization mismatch with the more modern
117 ## generators reported here (https://savannah.gnu.org/bugs/?42557).
118 fprintf (fid, " rand ('seed', 1);\n");
110 fprintf (fid, " %s\n\n", demos{d}); 119 fprintf (fid, " %s\n\n", demos{d});
111 fprintf (fid, " drawnow;\n"); 120 fprintf (fid, " drawnow;\n");
112 fprintf (fid, " fig = (get (0, 'currentfigure'));\n"); 121 fprintf (fid, " fig = (get (0, 'currentfigure'));\n");
113 fprintf (fid, " if (~ isempty (fig))\n"); 122 fprintf (fid, " if (~ isempty (fig))\n");
114 fprintf (fid, " figure (fig);\n"); 123 fprintf (fid, " figure (fig);\n");
115 fprintf (fid, " name = '%s_%s.%s';\n", fcn, idx, fmt); 124 fprintf (fid, " name = '%s.%s';\n", base_fn, fmt);
116 fprintf (fid, " if (isempty (dir (name)))\n"); 125 fprintf (fid, " if (isempty (dir (name)))\n");
117 fprintf (fid, " fprintf ('Printing ""%%s"" ... ', name);\n") 126 fprintf (fid, " fprintf ('Printing ""%%s"" ... ', name);\n")
118 fprintf (fid, " print ('-d%s', name);\n", fmt); 127 fprintf (fid, " print ('-d%s', name);\n", fmt);
119 fprintf (fid, " fprintf ('done\\n');\n"); 128 fprintf (fid, " fprintf ('done\\n');\n");
120 fprintf (fid, " else\n"); 129 fprintf (fid, " else\n");
122 fprintf (fid, " end\n"); 131 fprintf (fid, " end\n");
123 fprintf (fid, " end\n"); 132 fprintf (fid, " end\n");
124 # Temporary fix for cruft accumulating in figure window. 133 # Temporary fix for cruft accumulating in figure window.
125 fprintf (fid, " close ('all');\n"); 134 fprintf (fid, " close ('all');\n");
126 fprintf (fid, "catch\n"); 135 fprintf (fid, "catch\n");
127 fprintf (fid, " fprintf ('ERROR in %s_%s: %%s\\n', lasterr ());\n", fcn, idx); 136 fprintf (fid, " fprintf ('ERROR in %s: %%s\\n', lasterr ());\n", base_fn);
137 fprintf (fid, " err_fid = fopen ('%s.err', 'w');\n", base_fn);
138 fprintf (fid, " fprintf (err_fid, '%%s', lasterr ());\n");
139 fprintf (fid, " fclose (err_fid);\n");
128 fprintf (fid, "end\n\n"); 140 fprintf (fid, "end\n\n");
129 endfor 141 endfor
130 endfor 142 endfor
131 fprintf (fid, "close all\n"); 143 fprintf (fid, "close all\n");
132 endfunction 144 endfunction