Mercurial > octave-nkf
changeset 18911: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 | cafffc1b70b1 |
children | d3276190e551 |
files | scripts/testfun/compare_plot_demos.m scripts/testfun/dump_demos.m scripts/testfun/html_compare_plot_demos.m scripts/testfun/html_plot_demos_template.html scripts/testfun/private/compare_plot_demos.m scripts/testfun/private/dump_demos.m scripts/testfun/private/html_compare_plot_demos.m scripts/testfun/private/html_plot_demos_template.html |
diffstat | 8 files changed, 595 insertions(+), 595 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/testfun/compare_plot_demos.m Sun Jun 29 13:53:50 2014 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,119 +0,0 @@ -## Copyright (C) 2012 Ben Abbott <bpabbott@mac.com> -## -## This file is part of Octave. -## -## Octave is free software; you can redistribute it and/or modify it -## under the terms of the GNU General Public License as published by -## the Free Software Foundation; either version 3 of the License, or (at -## your option) any later version. -## -## Octave is distributed in the hope that it will be useful, but -## WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -## General Public License for more details. -## -## You should have received a copy of the GNU General Public License -## along with Octave; see the file COPYING. If not, see -## <http://www.gnu.org/licenses/>. - -## -*- texinfo -*- -## @deftypefn {Function File} {} compare_plot_demos () -## -## Uses @code{dump_demos} and @code{html_compare} to produce an html -## comparison of the plot demos for each of Octave's graphics -## toolkits. -## -## A m-file names `dump_plots.m' will be created in the pwd. This function -## will be used to render and save the plot demo images. -## -## If they do not already exist, directories for each graphics toolkit -## are created. Each toolkit's directory will be populated with images -## of each plot demo in the png format. -## -## Finally, an htlm document named `compare_plot_demos.html' is produced. -## This page places each toolkits images side by side for a conventient -## comparison of the results. -## -## @deftypefnx {Function File} {} compare_plot_demos (@var{toolkits}) -## @var{toolkits} is used to specify a subset of the available graphics -## toolkits. This list may also include `matlab'. -## -## @end deftypefn - -## Author: Ben Abbott <bpabbott@mac.com> - -function compare_plot_demos (varargin) - - in.toolkits = available_graphics_toolkits (); - in.directory = "plot"; - in.fmt = "png"; - in.fcn_file = ""; - in.replace_images = false; - - for n = 1:2:numel(varargin) - if (! ischar (varargin{n})) - print_usage (); - else - in.(varargin{n}) = varargin{n+1}; - endif - endfor - - if (ischar (in.toolkits)) - in.toolkits = {in.toolkits}; - elseif (! iscellstr (in.toolkits)) - error ("compare_plot_demos: Invalid value for ""toolkits""") - endif - - if (! ischar (in.directory)) - error ("compare_plot_demos: Invalid value for ""directory""") - endif - - if (! ischar (in.fmt)) - error ("compare_plot_demos: Invalid value for ""fmt""") - endif - - if (isempty (in.fcn_file)) - in.fcn_file = sprintf ("dump_%s_demos.m", in.directory); - endif - - ## Generate "dump_plots.m" for rendering/saving the plot demo images - dump_demos ("plot", in.fcn_file, in.fmt) - - [~, fcn_name] = fileparts (in.fcn_file); - - ## Generate the plot demo images for each toolkit - cwd = pwd (); - unwind_protect - addpath (pwd); - for n = 1:numel(in.toolkits) - dirs = dir (); - dirs = dirs([dirs.isdir]); - if (! any (strcmp ({dirs.name}, in.toolkits{n}))) - mkdir (in.toolkits{n}) - endif - cd (in.toolkits{n}) - if (! isempty (dir (strcat ("*.", in.fmt))) && in.replace_images) - delete (strcat ("*.", in.fmt)) - endif - if (! strcmp (in.toolkits{n}, "matlab")) - close all - graphics_toolkit (in.toolkits{n}); - try - eval (fcn_name); - catch - fprintf ("Error running plot demos for ""%s"" toolkit\n", in.toolkits{n}) - disp (lasterror) - end_try_catch - endif - cd (cwd) - endfor - unwind_protect_cleanup - rmpath (cwd); - end_unwind_protect - - ## Generate the html comparison of the images - ## TODO - pass the toolkits{} to allow num of columns to be formated - html_compare_plot_demos ("output", "compare_plot_demos.html") - -endfunction -
--- a/scripts/testfun/dump_demos.m Sun Jun 29 13:53:50 2014 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,207 +0,0 @@ -## Copyright (C) 2010 Søren Hauberg -## -## This file is part of Octave. -## -## Octave is free software; you can redistribute it and/or modify it -## under the terms of the GNU General Public License as published by -## the Free Software Foundation; either version 3 of the License, or (at -## your option) any later version. -## -## Octave is distributed in the hope that it will be useful, but -## WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -## General Public License for more details. -## -## You should have received a copy of the GNU General Public License -## along with Octave; see the file COPYING. If not, see -## <http://www.gnu.org/licenses/>. - -## -*- texinfo -*- -## @deftypefn {Function File} {} dump_demos () -## @deftypefnx {Function File} {} dump_demos (@var{dirs}) -## @deftypefnx {Function File} {} dump_demos (@var{dirs}, @var{mfile}) -## @deftypefnx {Function File} {} dump_demos (@var{dirs}, @var{mfile}, @var{fmt}) -## Produces a script, with the name specified by @var{mfile}, containing -## the demos in the directories, @var{dirs}. The demos are assumed to produce -## graphical output, whose renderings are saved with specified format, -## @var{fmt}. -## -## The defaults for each input are; -## -## @table @samp -## @item @var{dirs} -## @code{@{"plot/appearance", "plot/draw", "plot/util"@}} -## @item @var{mfile} -## @code{"dump.m"} -## @item @var{fmt} -## @code{"png"} -## @end table -## -## For example, to produce PNG output for all demos of the functions -## in the plot directory; -## -## @example -## @group -## dump_demos plot dump.m png -## @end group -## @end example -## @seealso{fntests, test, demo} -## @end deftypefn - -## Author: Søren Hauberg <soren@hauberg.org> - -function dump_demos (dirs= {"plot/appearance", "plot/draw", "plot/util"}, output="dump.m", fmt="png") - - if (nargin > 3) - print_usage (); - endif - - if (strfind (output, ".m") != numel (output) - 1) - output = strcat (output, ".m"); - endif - - ## Create script beginning (close figures, etc.) - fid = fopen (output, "w"); - n = find (output == ".", 1, "last"); - if (isempty (n)) - n = numel (output); - else - n = n - 1; - endif - fprintf (fid, "%% DO NOT EDIT! Generated automatically by dump_demos.m\n"); - fprintf (fid, "function %s ()\n", output(1:n)); - fprintf (fid, "close all\n"); - fprintf (fid, "more off\n"); - - ## Run and print the demos in each directory - for i = 1:numel (dirs) - if (!is_absolute_filename (dirs{i})) - fullname = dir_in_loadpath (dirs{i}); - if (! isempty (fullname)) - dirs{i} = fullname; - else - error ("dump_demos: expecting DIRS argument to be a cell arrays of strings with directory names"); - endif - endif - d = dirs{i}; - if (!exist (d, "dir")) - error ("dump_demos: directory %s doesn't exist", d); - endif - dump_all_demos (d, fid, fmt); - endfor - - ## Create script ending - fprintf (fid, "end\n\n") - - ## TODO - Should dump_demos() attempt to convert the demos to traditional - ## syntax. - ## (1) oct2mat() to convert some Octave specific syntax. - ## (2) Embed sombrero(), vec(), cstrcat() and assert() in demos ? - - ## sombrero has now a default argument which isn't supported from matlab - ## http://octave.1599824.n4.nabble.com/sombrero-default-argument-matlab-compatibility-td4665016.html - ## TODO: we need to change it prior running - ## -function [x, y, z] = sombrero (n = 41) - ## +function [x, y, z] = sombrero (n) - ## + - ## + if (nargin == 0) - ## + n = 41; - ## + endif - - for mfile = {"sombrero"} - f = which (mfile{1}); - fid2 = fopen (f); - code = char (fread (fid2)); - code = oct2mat (code); - fprintf (fid, "%s", code); - fclose (fid2); - endfor -%~ - %~ fprintf (fid, "function x = vec (x)\n") - %~ fprintf (fid, " x = x(:);\n") - %~ fprintf (fid, "end\n") -%~ - %~ fprintf (fid, "function str = cstrcat (varargin)\n") - %~ fprintf (fid, " str = [varargin{:}];\n") - %~ fprintf (fid, "end\n") -%~ - %~ fprintf (fid, "function assert (varargin)\n") - %~ fprintf (fid, "%% Do nothing.\n") - %~ fprintf (fid, "end\n") - - ## Close script - fclose (fid); -endfunction - -function dump_all_demos (directory, fid, fmt) - dirinfo = dir (fullfile (directory, "*.m")); - flist = {dirinfo.name}; - ## Remove uigetdir, uigetfile, uiputfile, etc. - flist = flist(! strncmp (flist, "ui", 2)); - for i = 1:numel (flist) - fun = flist{i}; - fun (end-1:end) = []; # remove .m - demos = get_demos (fun); - for d = 1:numel (demos) - if (d < 10) - idx = sprintf ("0%d", d); - else - idx = sprintf ("%d", d); - end - fprintf (fid, "\ntry\n"); - fprintf (fid, " %s\n\n", demos {d}); - fprintf (fid, " drawnow\n"); - fprintf (fid, " num_figures = get(0, 'currentfigure');\n"); - fprintf (fid, " for fig = 1:num_figures\n"); - fprintf (fid, " figure (fig);\n"); - fprintf (fid, " name = sprintf ('%s_%s_%%d.%s', fig);\n", fun, idx, fmt); - fprintf (fid, " if (numel (dir (name)) == 0)\n"); - fprintf (fid, " fprintf ('Printing ""%%s"" ... ', name);\n") - fprintf (fid, " print ('-d%s', name);\n", fmt); -# fprintf (fid, " pause (1);\n"); - fprintf (fid, " fprintf ('done\\n');\n"); - fprintf (fid, " else\n"); - fprintf (fid, " fprintf ('File ""%%s"" exists.\\n', name);\n") - fprintf (fid, " end\n"); -# fprintf (fid, " drawnow ();\n"); - fprintf (fid, " end\n"); - fprintf (fid, " close (2:num_figures)\n"); - fprintf (fid, "catch\n"); - fprintf (fid, " fprintf ('ERROR in %s_%s: %%s\\n', lasterr ());\n", fun, idx); - fprintf (fid, "end\n\n"); - endfor - endfor - fprintf (fid, "close all\n"); -endfunction - -function retval = get_demos (fun) - [code, idx] = test (fun, "grabdemo"); - num_demos = length (idx) - 1; - retval = cell (1, num_demos); - ## Now split the demos into a cell array - for k = 1:num_demos - retval {k} = oct2mat (code (idx (k):idx (k+1)-1)); - endfor -endfunction - -function code = oct2mat (code) - ## Simple hacks to make things Matlab compatible - code = strrep (code, "%!", "%%"); - code = strrep (code, "!", "~"); - ## Simple replacing double quotes with single quotes - ## causes problems with strings like 'hello "world"' - #code = strrep (code, "\"", "'"); - code = strrep (code, "#", "%"); - ## Fix the format specs for the errobar demos - code = strrep (code, "%r", "#r"); - code = strrep (code, "%~", "#~"); - endkeywords = {"endfor", "endif", "endwhile", "end_try_catch", ... - "endfunction", "end_unwind_protect"}; - for k = 1:numel (endkeywords) - code = strrep (code, endkeywords{k}, "end"); - endfor - commentkeywords = {"unwind_proect"}; - for k = 1:numel (commentkeywords) - code = strrep (code, commentkeywords{k}, strcat ("%", commentkeywords{k})); - endfor -endfunction
--- a/scripts/testfun/html_compare_plot_demos.m Sun Jun 29 13:53:50 2014 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,179 +0,0 @@ -## Copyright (C) 2010 Ben Abbott -## -## This file is part of Octave. -## -## Octave is free software; you can redistribute it and/or modify it -## under the terms of the GNU General Public License as published by -## the Free Software Foundation; either version 3 of the License, or (at -## your option) any later version. -## -## Octave is distributed in the hope that it will be useful, but -## WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -## General Public License for more details. -## -## You should have received a copy of the GNU General Public License -## along with Octave; see the file COPYING. If not, see -## <http://www.gnu.org/licenses/>. - -## -*- texinfo -*- -## @deftypefn {Function File} {} html_compare () -## @deftypefnx {Function File} {} html_compare (@var{name}, @var{value}, @dots{}) -## -## Produces an html document to compare the plot demos produced by Octave's -## gnuplot and FLTK toolkits with those produced by Matalb. -## -## Valid property names, and their defaults, are; -## -## @table @samp -## @item date -## @code{datestr (now (), 0)} -## @item fmt -## @code{"png"} -## @item mfiles -## @code{sort (cellstr (ls ("gnuplot")))} -## @item gnuplot -## @code{sprintf ("Gnuplot %s", __gnuplot_version__ ())} -## @item matlab -## @code{"Matlab Version 7.11.0.584 (R2010b)"} -## @item octave -## @code{sprintf ("Octave %s", version)} -## @item output -## @code{"compare_plots.html"} -## @item template -## @code{"html_template.html"} -## @end table -## -## The template parameter refers to a specially formatted html file -## which accompanies this m-file script. -## -## This script may be used to generate the index.html page loaded by -## the link below. -## -## @example -## @group -## http://octave.sourceforge.net/compare_plots -## @end group -## @end example -## -## This is done by following the instructions below. -## -## @enumerate -## @item Begin by downloading a local copy of the web page. -## -## @example -## @group -## $ wget -vcr --level 1 http://octave.sourceforge.net/compare_plots/ -## @end group -## @end example -## -## @item Use @code{dump_demos} to produce the script used to produce the -## demo plots. In this example the script is @code{dump.m}. -## -## @example -## @group -## octave:1> dump_demos plot dump.m png -## @end group -## @end example -## -## @item Produce the gnuplot and fltk plots, and place them in their -## designated directories. -## -## @example -## @group -## octave:2> dump -## octave:3> movefile *.png octave.sourceforge.net/compare_plots/gnuplot/. -## octave:4> graphics_toolkit fltk -## octave:5> close all -## octave:6> dump -## octave:7> movefile *.png octave.sourceforge.net/compare_plots/fltk/. -## @end group -## @end example -## -## @item Start Matlab and edit the script @code{dump.m} to correct the -## remaining Octave specific syntax so that it will run under Matlab. -## -## @item Run @code{dump.m} under Matlab, and place the plots in the -## designated matlab directory. -## -## @example -## @group -## >> dump -## >> movefile *.png octave.sourceforge.net/compare_plots/matlab/. -## @end group -## @end example -## -## @item The web page comparing all plot demos is created by -## -## @example -## @group -## octave:8> cd octave.sourceforge.net/compare_plots -## octave:9> html_compare output index.html -## @end group -## @end example -## -## @item Finally, the new page may be loaded into your browser. -## -## @seealso{dump_demos, demo} -## @end deftypefn - -## Author: Ben Abbott <bpabbott@mac.com> - -function html_compare_plot_demos (varargin) - - ## TODO - Names of the toolkits should be input - ## Set defaults - in.date = datestr (now (), 0); - in.fmt = "png"; - in.figfiles = {}; - in.octave = sprintf ("Octave %s", version); - in.output= "compare_plots.html"; - in.template = "html_plot_demos_template.html"; - in.toolkits = {"gnuplot", "matlab", "fltk"}; - - ## Parse inputs - for n = 1:2:numel(varargin) - in.(lower(varargin{n})) = varargin{n+1}; - endfor - - for t = 1:numel(in.toolkits) - if (! isfield (in, in.toolkits{t})) - ## Column headers for the html page - in.(in.toolkits{t}) = upper (in.toolkits{t}); - endif - ## Compile a list of all files for all toolkits - if (t == 1) - in.figfiles = {dir(sprintf ("gnuplot/*.%s", in.fmt)).name}; - else - filter = sprintf ("%s/*.%s", in.toolkits{t}, in.fmt); - in.figfiles = union (in.figfiles, {dir(filter).name}); - endif - endfor - - fid = fopen (which (in.template), "r"); - template = char (fread (fid)) .'; - fclose (fid); - - template = strrep (template, "##OCTAVE##", in.octave); - template = strrep (template, "##GNUPLOT##", in.gnuplot); - template = strrep (template, "##MATLAB##", in.matlab); - - n1 = findstr (template, "<!-- ##BEGIN## -->"); - n2 = findstr (template, "<!-- ##END## -->"); - header = template(1:n1-1); - middle = template(n1+18:n2-1); - trailer = template(n2+15:end); - - fid = fopen (in.output, "w"); - unwind_protect - fputs (fid, header); - for m = 1:numel(in.figfiles) - [~, file] = fileparts (in.figfiles{m}); - fputs (fid, strrep (middle, "##PLOT##", strcat (file, ".", in.fmt))); - endfor - fputs (fid, trailer); - unwind_protect_cleanup - fclose (fid); - end_unwind_protect - -endfunction
--- a/scripts/testfun/html_plot_demos_template.html Sun Jun 29 13:53:50 2014 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,90 +0,0 @@ -<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" - "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> -<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"> - <head> - <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" /> - <meta name="date" content="##DATE##"/> - <meta name="author" content="The Octave-Forge Community" /> - <meta name="description" content="Octave-Forge is a collection of packages providing extra functionality for GNU Octave." /> - <meta name="keywords" lang="en" content="Octave-Forge, Octave, extra packages" /> - <title>Comparision of plots</title> - - <link rel="stylesheet" type="text/css" href="../octave-forge.css" /> - <script src="../fixed.js" type="text/javascript"></script> - <script src="../javascript.js" type="text/javascript"></script> - <link rel="shortcut icon" href="../favicon.ico" /> - </head> - <body onload="javascript:fix_top_menu(); javascript:show_left_menu ();"> - <div id="top-menu" class="menu"> - <table class="menu"> - - <tr> - <td style="width: 90px;" class="menu" rowspan="2"> - <a name="top"> - <img src="../oct.png" alt="Octave logo" /> - </a> - </td> - <td class="menu" style="padding-top: 0.9em;"> - <big class="menu">Octave-Forge</big><small class="menu"> - Extra packages for GNU Octave</small> - - </td> - </tr> - <tr> - <td class="menu"> - - <a href="../index.html" class="menu">Home</a> · - <a href="../packages.php" class="menu">Packages</a> · - <a href="../developers.html" class="menu">Developers</a> · - <a href="../docs.html" class="menu">Documentation</a> · - <a href="../FAQ.html" class="menu">FAQ</a> · - <a href="../bugs.html" class="menu">Bugs</a> · - <a href="../archive.html" class="menu">Mailing Lists</a> · - <a href="../links.html" class="menu">Links</a> · - <a href="http://sourceforge.net/svn/?group_id=2888" class="menu">SVN</a> - - </td> - </tr> - </table> - </div> - -<div id="content"> -<b>Select plots to show</b><br> -<form action="index.php" method="get"> - <input type="checkbox" name="gnuplot" value="1" checked/>##OCTAVE## using ##GNUPLOT## -<br/> - <input type="checkbox" name="matlab" value="1" checked/>##MATLAB## -<br/> - <input type="checkbox" name="fltk" value="1" checked/>##OCTAVE## using FLTK -<br/> - Image width: <input type="input" name="imwidth" value="600px"/> - <input type="submit" value="Update"/> -</form> - -<table border='1'> -<tr> - <th>Octave using Gnuplot -</th> - <th>Matlab -</th> - <th>Octave using FLTK -</th> -</tr> -<tr> -<!-- ##BEGIN## --> -<tr> - <td>##PLOT##<br><img src='gnuplot/##PLOT##' style='width: 600px;'></td> - <td>##PLOT##<br><img src='matlab/##PLOT##' style='width: 600px;'></td> - <td>##PLOT##<br><img src='fltk/##PLOT##' style='width: 600px;'></td> -</tr> -<!-- ##END## --> -</tr> -</table> - -<div id="sf_logo"> - <a href="http://sourceforge.net"><img src="http://sourceforge.net/sflogo.php?group_id=2888&type=1" - width="88" height="31" style="border: 0;" alt="SourceForge.net Logo"/></a> -</div> -</div> -</body> -</html> -
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/scripts/testfun/private/compare_plot_demos.m Sun Jun 29 13:58:33 2014 +0200 @@ -0,0 +1,119 @@ +## Copyright (C) 2012 Ben Abbott <bpabbott@mac.com> +## +## This file is part of Octave. +## +## Octave is free software; you can redistribute it and/or modify it +## under the terms of the GNU General Public License as published by +## the Free Software Foundation; either version 3 of the License, or (at +## your option) any later version. +## +## Octave is distributed in the hope that it will be useful, but +## WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +## General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with Octave; see the file COPYING. If not, see +## <http://www.gnu.org/licenses/>. + +## -*- texinfo -*- +## @deftypefn {Function File} {} compare_plot_demos () +## +## Uses @code{dump_demos} and @code{html_compare} to produce an html +## comparison of the plot demos for each of Octave's graphics +## toolkits. +## +## A m-file names `dump_plots.m' will be created in the pwd. This function +## will be used to render and save the plot demo images. +## +## If they do not already exist, directories for each graphics toolkit +## are created. Each toolkit's directory will be populated with images +## of each plot demo in the png format. +## +## Finally, an htlm document named `compare_plot_demos.html' is produced. +## This page places each toolkits images side by side for a conventient +## comparison of the results. +## +## @deftypefnx {Function File} {} compare_plot_demos (@var{toolkits}) +## @var{toolkits} is used to specify a subset of the available graphics +## toolkits. This list may also include `matlab'. +## +## @end deftypefn + +## Author: Ben Abbott <bpabbott@mac.com> + +function compare_plot_demos (varargin) + + in.toolkits = available_graphics_toolkits (); + in.directory = "plot"; + in.fmt = "png"; + in.fcn_file = ""; + in.replace_images = false; + + for n = 1:2:numel(varargin) + if (! ischar (varargin{n})) + print_usage (); + else + in.(varargin{n}) = varargin{n+1}; + endif + endfor + + if (ischar (in.toolkits)) + in.toolkits = {in.toolkits}; + elseif (! iscellstr (in.toolkits)) + error ("compare_plot_demos: Invalid value for ""toolkits""") + endif + + if (! ischar (in.directory)) + error ("compare_plot_demos: Invalid value for ""directory""") + endif + + if (! ischar (in.fmt)) + error ("compare_plot_demos: Invalid value for ""fmt""") + endif + + if (isempty (in.fcn_file)) + in.fcn_file = sprintf ("dump_%s_demos.m", in.directory); + endif + + ## Generate "dump_plots.m" for rendering/saving the plot demo images + dump_demos ("plot", in.fcn_file, in.fmt) + + [~, fcn_name] = fileparts (in.fcn_file); + + ## Generate the plot demo images for each toolkit + cwd = pwd (); + unwind_protect + addpath (pwd); + for n = 1:numel(in.toolkits) + dirs = dir (); + dirs = dirs([dirs.isdir]); + if (! any (strcmp ({dirs.name}, in.toolkits{n}))) + mkdir (in.toolkits{n}) + endif + cd (in.toolkits{n}) + if (! isempty (dir (strcat ("*.", in.fmt))) && in.replace_images) + delete (strcat ("*.", in.fmt)) + endif + if (! strcmp (in.toolkits{n}, "matlab")) + close all + graphics_toolkit (in.toolkits{n}); + try + eval (fcn_name); + catch + fprintf ("Error running plot demos for ""%s"" toolkit\n", in.toolkits{n}) + disp (lasterror) + end_try_catch + endif + cd (cwd) + endfor + unwind_protect_cleanup + rmpath (cwd); + end_unwind_protect + + ## Generate the html comparison of the images + ## TODO - pass the toolkits{} to allow num of columns to be formated + html_compare_plot_demos ("output", "compare_plot_demos.html") + +endfunction +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/scripts/testfun/private/dump_demos.m Sun Jun 29 13:58:33 2014 +0200 @@ -0,0 +1,207 @@ +## Copyright (C) 2010 Søren Hauberg +## +## This file is part of Octave. +## +## Octave is free software; you can redistribute it and/or modify it +## under the terms of the GNU General Public License as published by +## the Free Software Foundation; either version 3 of the License, or (at +## your option) any later version. +## +## Octave is distributed in the hope that it will be useful, but +## WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +## General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with Octave; see the file COPYING. If not, see +## <http://www.gnu.org/licenses/>. + +## -*- texinfo -*- +## @deftypefn {Function File} {} dump_demos () +## @deftypefnx {Function File} {} dump_demos (@var{dirs}) +## @deftypefnx {Function File} {} dump_demos (@var{dirs}, @var{mfile}) +## @deftypefnx {Function File} {} dump_demos (@var{dirs}, @var{mfile}, @var{fmt}) +## Produces a script, with the name specified by @var{mfile}, containing +## the demos in the directories, @var{dirs}. The demos are assumed to produce +## graphical output, whose renderings are saved with specified format, +## @var{fmt}. +## +## The defaults for each input are; +## +## @table @samp +## @item @var{dirs} +## @code{@{"plot/appearance", "plot/draw", "plot/util"@}} +## @item @var{mfile} +## @code{"dump.m"} +## @item @var{fmt} +## @code{"png"} +## @end table +## +## For example, to produce PNG output for all demos of the functions +## in the plot directory; +## +## @example +## @group +## dump_demos plot dump.m png +## @end group +## @end example +## @seealso{fntests, test, demo} +## @end deftypefn + +## Author: Søren Hauberg <soren@hauberg.org> + +function dump_demos (dirs= {"plot/appearance", "plot/draw", "plot/util"}, output="dump.m", fmt="png") + + if (nargin > 3) + print_usage (); + endif + + if (strfind (output, ".m") != numel (output) - 1) + output = strcat (output, ".m"); + endif + + ## Create script beginning (close figures, etc.) + fid = fopen (output, "w"); + n = find (output == ".", 1, "last"); + if (isempty (n)) + n = numel (output); + else + n = n - 1; + endif + fprintf (fid, "%% DO NOT EDIT! Generated automatically by dump_demos.m\n"); + fprintf (fid, "function %s ()\n", output(1:n)); + fprintf (fid, "close all\n"); + fprintf (fid, "more off\n"); + + ## Run and print the demos in each directory + for i = 1:numel (dirs) + if (!is_absolute_filename (dirs{i})) + fullname = dir_in_loadpath (dirs{i}); + if (! isempty (fullname)) + dirs{i} = fullname; + else + error ("dump_demos: expecting DIRS argument to be a cell arrays of strings with directory names"); + endif + endif + d = dirs{i}; + if (!exist (d, "dir")) + error ("dump_demos: directory %s doesn't exist", d); + endif + dump_all_demos (d, fid, fmt); + endfor + + ## Create script ending + fprintf (fid, "end\n\n") + + ## TODO - Should dump_demos() attempt to convert the demos to traditional + ## syntax. + ## (1) oct2mat() to convert some Octave specific syntax. + ## (2) Embed sombrero(), vec(), cstrcat() and assert() in demos ? + + ## sombrero has now a default argument which isn't supported from matlab + ## http://octave.1599824.n4.nabble.com/sombrero-default-argument-matlab-compatibility-td4665016.html + ## TODO: we need to change it prior running + ## -function [x, y, z] = sombrero (n = 41) + ## +function [x, y, z] = sombrero (n) + ## + + ## + if (nargin == 0) + ## + n = 41; + ## + endif + + for mfile = {"sombrero"} + f = which (mfile{1}); + fid2 = fopen (f); + code = char (fread (fid2)); + code = oct2mat (code); + fprintf (fid, "%s", code); + fclose (fid2); + endfor +%~ + %~ fprintf (fid, "function x = vec (x)\n") + %~ fprintf (fid, " x = x(:);\n") + %~ fprintf (fid, "end\n") +%~ + %~ fprintf (fid, "function str = cstrcat (varargin)\n") + %~ fprintf (fid, " str = [varargin{:}];\n") + %~ fprintf (fid, "end\n") +%~ + %~ fprintf (fid, "function assert (varargin)\n") + %~ fprintf (fid, "%% Do nothing.\n") + %~ fprintf (fid, "end\n") + + ## Close script + fclose (fid); +endfunction + +function dump_all_demos (directory, fid, fmt) + dirinfo = dir (fullfile (directory, "*.m")); + flist = {dirinfo.name}; + ## Remove uigetdir, uigetfile, uiputfile, etc. + flist = flist(! strncmp (flist, "ui", 2)); + for i = 1:numel (flist) + fun = flist{i}; + fun (end-1:end) = []; # remove .m + demos = get_demos (fun); + for d = 1:numel (demos) + if (d < 10) + idx = sprintf ("0%d", d); + else + idx = sprintf ("%d", d); + end + fprintf (fid, "\ntry\n"); + fprintf (fid, " %s\n\n", demos {d}); + fprintf (fid, " drawnow\n"); + fprintf (fid, " num_figures = get(0, 'currentfigure');\n"); + fprintf (fid, " for fig = 1:num_figures\n"); + fprintf (fid, " figure (fig);\n"); + fprintf (fid, " name = sprintf ('%s_%s_%%d.%s', fig);\n", fun, idx, fmt); + fprintf (fid, " if (numel (dir (name)) == 0)\n"); + fprintf (fid, " fprintf ('Printing ""%%s"" ... ', name);\n") + fprintf (fid, " print ('-d%s', name);\n", fmt); +# fprintf (fid, " pause (1);\n"); + fprintf (fid, " fprintf ('done\\n');\n"); + fprintf (fid, " else\n"); + fprintf (fid, " fprintf ('File ""%%s"" exists.\\n', name);\n") + fprintf (fid, " end\n"); +# fprintf (fid, " drawnow ();\n"); + fprintf (fid, " end\n"); + fprintf (fid, " close (2:num_figures)\n"); + fprintf (fid, "catch\n"); + fprintf (fid, " fprintf ('ERROR in %s_%s: %%s\\n', lasterr ());\n", fun, idx); + fprintf (fid, "end\n\n"); + endfor + endfor + fprintf (fid, "close all\n"); +endfunction + +function retval = get_demos (fun) + [code, idx] = test (fun, "grabdemo"); + num_demos = length (idx) - 1; + retval = cell (1, num_demos); + ## Now split the demos into a cell array + for k = 1:num_demos + retval {k} = oct2mat (code (idx (k):idx (k+1)-1)); + endfor +endfunction + +function code = oct2mat (code) + ## Simple hacks to make things Matlab compatible + code = strrep (code, "%!", "%%"); + code = strrep (code, "!", "~"); + ## Simple replacing double quotes with single quotes + ## causes problems with strings like 'hello "world"' + #code = strrep (code, "\"", "'"); + code = strrep (code, "#", "%"); + ## Fix the format specs for the errobar demos + code = strrep (code, "%r", "#r"); + code = strrep (code, "%~", "#~"); + endkeywords = {"endfor", "endif", "endwhile", "end_try_catch", ... + "endfunction", "end_unwind_protect"}; + for k = 1:numel (endkeywords) + code = strrep (code, endkeywords{k}, "end"); + endfor + commentkeywords = {"unwind_proect"}; + for k = 1:numel (commentkeywords) + code = strrep (code, commentkeywords{k}, strcat ("%", commentkeywords{k})); + endfor +endfunction
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/scripts/testfun/private/html_compare_plot_demos.m Sun Jun 29 13:58:33 2014 +0200 @@ -0,0 +1,179 @@ +## Copyright (C) 2010 Ben Abbott +## +## This file is part of Octave. +## +## Octave is free software; you can redistribute it and/or modify it +## under the terms of the GNU General Public License as published by +## the Free Software Foundation; either version 3 of the License, or (at +## your option) any later version. +## +## Octave is distributed in the hope that it will be useful, but +## WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +## General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with Octave; see the file COPYING. If not, see +## <http://www.gnu.org/licenses/>. + +## -*- texinfo -*- +## @deftypefn {Function File} {} html_compare () +## @deftypefnx {Function File} {} html_compare (@var{name}, @var{value}, @dots{}) +## +## Produces an html document to compare the plot demos produced by Octave's +## gnuplot and FLTK toolkits with those produced by Matalb. +## +## Valid property names, and their defaults, are; +## +## @table @samp +## @item date +## @code{datestr (now (), 0)} +## @item fmt +## @code{"png"} +## @item mfiles +## @code{sort (cellstr (ls ("gnuplot")))} +## @item gnuplot +## @code{sprintf ("Gnuplot %s", __gnuplot_version__ ())} +## @item matlab +## @code{"Matlab Version 7.11.0.584 (R2010b)"} +## @item octave +## @code{sprintf ("Octave %s", version)} +## @item output +## @code{"compare_plots.html"} +## @item template +## @code{"html_template.html"} +## @end table +## +## The template parameter refers to a specially formatted html file +## which accompanies this m-file script. +## +## This script may be used to generate the index.html page loaded by +## the link below. +## +## @example +## @group +## http://octave.sourceforge.net/compare_plots +## @end group +## @end example +## +## This is done by following the instructions below. +## +## @enumerate +## @item Begin by downloading a local copy of the web page. +## +## @example +## @group +## $ wget -vcr --level 1 http://octave.sourceforge.net/compare_plots/ +## @end group +## @end example +## +## @item Use @code{dump_demos} to produce the script used to produce the +## demo plots. In this example the script is @code{dump.m}. +## +## @example +## @group +## octave:1> dump_demos plot dump.m png +## @end group +## @end example +## +## @item Produce the gnuplot and fltk plots, and place them in their +## designated directories. +## +## @example +## @group +## octave:2> dump +## octave:3> movefile *.png octave.sourceforge.net/compare_plots/gnuplot/. +## octave:4> graphics_toolkit fltk +## octave:5> close all +## octave:6> dump +## octave:7> movefile *.png octave.sourceforge.net/compare_plots/fltk/. +## @end group +## @end example +## +## @item Start Matlab and edit the script @code{dump.m} to correct the +## remaining Octave specific syntax so that it will run under Matlab. +## +## @item Run @code{dump.m} under Matlab, and place the plots in the +## designated matlab directory. +## +## @example +## @group +## >> dump +## >> movefile *.png octave.sourceforge.net/compare_plots/matlab/. +## @end group +## @end example +## +## @item The web page comparing all plot demos is created by +## +## @example +## @group +## octave:8> cd octave.sourceforge.net/compare_plots +## octave:9> html_compare output index.html +## @end group +## @end example +## +## @item Finally, the new page may be loaded into your browser. +## +## @seealso{dump_demos, demo} +## @end deftypefn + +## Author: Ben Abbott <bpabbott@mac.com> + +function html_compare_plot_demos (varargin) + + ## TODO - Names of the toolkits should be input + ## Set defaults + in.date = datestr (now (), 0); + in.fmt = "png"; + in.figfiles = {}; + in.octave = sprintf ("Octave %s", version); + in.output= "compare_plots.html"; + in.template = "html_plot_demos_template.html"; + in.toolkits = {"gnuplot", "matlab", "fltk"}; + + ## Parse inputs + for n = 1:2:numel(varargin) + in.(lower(varargin{n})) = varargin{n+1}; + endfor + + for t = 1:numel(in.toolkits) + if (! isfield (in, in.toolkits{t})) + ## Column headers for the html page + in.(in.toolkits{t}) = upper (in.toolkits{t}); + endif + ## Compile a list of all files for all toolkits + if (t == 1) + in.figfiles = {dir(sprintf ("gnuplot/*.%s", in.fmt)).name}; + else + filter = sprintf ("%s/*.%s", in.toolkits{t}, in.fmt); + in.figfiles = union (in.figfiles, {dir(filter).name}); + endif + endfor + + fid = fopen (which (in.template), "r"); + template = char (fread (fid)) .'; + fclose (fid); + + template = strrep (template, "##OCTAVE##", in.octave); + template = strrep (template, "##GNUPLOT##", in.gnuplot); + template = strrep (template, "##MATLAB##", in.matlab); + + n1 = findstr (template, "<!-- ##BEGIN## -->"); + n2 = findstr (template, "<!-- ##END## -->"); + header = template(1:n1-1); + middle = template(n1+18:n2-1); + trailer = template(n2+15:end); + + fid = fopen (in.output, "w"); + unwind_protect + fputs (fid, header); + for m = 1:numel(in.figfiles) + [~, file] = fileparts (in.figfiles{m}); + fputs (fid, strrep (middle, "##PLOT##", strcat (file, ".", in.fmt))); + endfor + fputs (fid, trailer); + unwind_protect_cleanup + fclose (fid); + end_unwind_protect + +endfunction
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/scripts/testfun/private/html_plot_demos_template.html Sun Jun 29 13:58:33 2014 +0200 @@ -0,0 +1,90 @@ +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" + "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"> + <head> + <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" /> + <meta name="date" content="##DATE##"/> + <meta name="author" content="The Octave-Forge Community" /> + <meta name="description" content="Octave-Forge is a collection of packages providing extra functionality for GNU Octave." /> + <meta name="keywords" lang="en" content="Octave-Forge, Octave, extra packages" /> + <title>Comparision of plots</title> + + <link rel="stylesheet" type="text/css" href="../octave-forge.css" /> + <script src="../fixed.js" type="text/javascript"></script> + <script src="../javascript.js" type="text/javascript"></script> + <link rel="shortcut icon" href="../favicon.ico" /> + </head> + <body onload="javascript:fix_top_menu(); javascript:show_left_menu ();"> + <div id="top-menu" class="menu"> + <table class="menu"> + + <tr> + <td style="width: 90px;" class="menu" rowspan="2"> + <a name="top"> + <img src="../oct.png" alt="Octave logo" /> + </a> + </td> + <td class="menu" style="padding-top: 0.9em;"> + <big class="menu">Octave-Forge</big><small class="menu"> - Extra packages for GNU Octave</small> + + </td> + </tr> + <tr> + <td class="menu"> + + <a href="../index.html" class="menu">Home</a> · + <a href="../packages.php" class="menu">Packages</a> · + <a href="../developers.html" class="menu">Developers</a> · + <a href="../docs.html" class="menu">Documentation</a> · + <a href="../FAQ.html" class="menu">FAQ</a> · + <a href="../bugs.html" class="menu">Bugs</a> · + <a href="../archive.html" class="menu">Mailing Lists</a> · + <a href="../links.html" class="menu">Links</a> · + <a href="http://sourceforge.net/svn/?group_id=2888" class="menu">SVN</a> + + </td> + </tr> + </table> + </div> + +<div id="content"> +<b>Select plots to show</b><br> +<form action="index.php" method="get"> + <input type="checkbox" name="gnuplot" value="1" checked/>##OCTAVE## using ##GNUPLOT## +<br/> + <input type="checkbox" name="matlab" value="1" checked/>##MATLAB## +<br/> + <input type="checkbox" name="fltk" value="1" checked/>##OCTAVE## using FLTK +<br/> + Image width: <input type="input" name="imwidth" value="600px"/> + <input type="submit" value="Update"/> +</form> + +<table border='1'> +<tr> + <th>Octave using Gnuplot +</th> + <th>Matlab +</th> + <th>Octave using FLTK +</th> +</tr> +<tr> +<!-- ##BEGIN## --> +<tr> + <td>##PLOT##<br><img src='gnuplot/##PLOT##' style='width: 600px;'></td> + <td>##PLOT##<br><img src='matlab/##PLOT##' style='width: 600px;'></td> + <td>##PLOT##<br><img src='fltk/##PLOT##' style='width: 600px;'></td> +</tr> +<!-- ##END## --> +</tr> +</table> + +<div id="sf_logo"> + <a href="http://sourceforge.net"><img src="http://sourceforge.net/sflogo.php?group_id=2888&type=1" + width="88" height="31" style="border: 0;" alt="SourceForge.net Logo"/></a> +</div> +</div> +</body> +</html> +