annotate scripts/plot/util/printd.m @ 20602:af5591ef9790 stable

__gnuplot_drawnow__.m: Use "screenpixelsperinch" instead of constant value (bug #46122).
author ederag <edera@gmx.fr>
date Tue, 06 Oct 2015 11:07:10 +0200
parents 777f26aa8e3e
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
19731
4197fc428c7d maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents: 19313
diff changeset
1 ## Copyright (C) 2013-2015 Michael D. Godfrey
16005
369b173d6c16 provide stemleaf.m and printd.m
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
diff changeset
2 ##
369b173d6c16 provide stemleaf.m and printd.m
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
diff changeset
3 ## This file is part of Octave.
369b173d6c16 provide stemleaf.m and printd.m
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
diff changeset
4 ##
369b173d6c16 provide stemleaf.m and printd.m
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
diff changeset
5 ## Octave is free software; you can redistribute it and/or
369b173d6c16 provide stemleaf.m and printd.m
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
diff changeset
6 ## modify it under the terms of the GNU General Public
369b173d6c16 provide stemleaf.m and printd.m
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
diff changeset
7 ## License as published by the Free Software Foundation;
369b173d6c16 provide stemleaf.m and printd.m
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
diff changeset
8 ## either version 3 of the License, or (at your option) any
369b173d6c16 provide stemleaf.m and printd.m
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
diff changeset
9 ## later version.
369b173d6c16 provide stemleaf.m and printd.m
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
diff changeset
10 ##
369b173d6c16 provide stemleaf.m and printd.m
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
diff changeset
11 ## Octave is distributed in the hope that it will be useful,
369b173d6c16 provide stemleaf.m and printd.m
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
diff changeset
12 ## but WITHOUT ANY WARRANTY; without even the implied
369b173d6c16 provide stemleaf.m and printd.m
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
diff changeset
13 ## warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
369b173d6c16 provide stemleaf.m and printd.m
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
diff changeset
14 ## PURPOSE. See the GNU General Public License for more
369b173d6c16 provide stemleaf.m and printd.m
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
diff changeset
15 ## details.
369b173d6c16 provide stemleaf.m and printd.m
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
diff changeset
16 ##
369b173d6c16 provide stemleaf.m and printd.m
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
diff changeset
17 ## You should have received a copy of the GNU General Public
369b173d6c16 provide stemleaf.m and printd.m
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
diff changeset
18 ## License along with Octave; see the file COPYING. If not,
369b173d6c16 provide stemleaf.m and printd.m
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
diff changeset
19 ## see <http://www.gnu.org/licenses/>.
369b173d6c16 provide stemleaf.m and printd.m
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
diff changeset
20
369b173d6c16 provide stemleaf.m and printd.m
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
diff changeset
21 ## -*- texinfo -*-
369b173d6c16 provide stemleaf.m and printd.m
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
diff changeset
22 ## @deftypefn {Function File} {} printd (@var{obj}, @var{filename})
16180
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16006
diff changeset
23 ## @deftypefnx {Function File} {@var{out_file} =} printd (@dots{})
16005
369b173d6c16 provide stemleaf.m and printd.m
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
diff changeset
24 ##
20208
777f26aa8e3e doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19867
diff changeset
25 ## Convert any object acceptable to @code{disp} into the format selected by
777f26aa8e3e doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19867
diff changeset
26 ## the suffix of @var{filename}.
16005
369b173d6c16 provide stemleaf.m and printd.m
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
diff changeset
27 ##
20208
777f26aa8e3e doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19867
diff changeset
28 ## If the return argument @var{out_file} is given, the name of the created
777f26aa8e3e doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19867
diff changeset
29 ## file is returned.
777f26aa8e3e doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19867
diff changeset
30 ##
777f26aa8e3e doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19867
diff changeset
31 ## This function is intended to facilitate manipulation of the output of
777f26aa8e3e doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19867
diff changeset
32 ## functions such as @code{stemleaf}.
16005
369b173d6c16 provide stemleaf.m and printd.m
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
diff changeset
33 ## @seealso{stemleaf}
369b173d6c16 provide stemleaf.m and printd.m
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
diff changeset
34 ## @end deftypefn
369b173d6c16 provide stemleaf.m and printd.m
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
diff changeset
35
369b173d6c16 provide stemleaf.m and printd.m
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
diff changeset
36 ## Author: Michael D. Godfrey <michaeldgodfrey@gmail.com>
369b173d6c16 provide stemleaf.m and printd.m
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
diff changeset
37 ## Description: Convert objects into other file formats.
369b173d6c16 provide stemleaf.m and printd.m
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
diff changeset
38
16180
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16006
diff changeset
39 function pr_out = printd (obj, filename)
16006
9978c44ab12c Style fixes on printd.m and stemleaf.m
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 16005
diff changeset
40 ## Convert any object acceptable to disp() into various display formats.
9978c44ab12c Style fixes on printd.m and stemleaf.m
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 16005
diff changeset
41 ## obj is the input object.
9978c44ab12c Style fixes on printd.m and stemleaf.m
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 16005
diff changeset
42 ## filename is the output file (with required suffix).
16005
369b173d6c16 provide stemleaf.m and printd.m
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
diff changeset
43
16006
9978c44ab12c Style fixes on printd.m and stemleaf.m
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 16005
diff changeset
44 ## Extract .suffix from filename
9978c44ab12c Style fixes on printd.m and stemleaf.m
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 16005
diff changeset
45 if ((sufix = rindex (filename, ".")) <= 0)
9978c44ab12c Style fixes on printd.m and stemleaf.m
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 16005
diff changeset
46 error ("The output filename: %s requires a suffix.\nOptions are: pdf ps eps txt jpg jpeg", filename);
16005
369b173d6c16 provide stemleaf.m and printd.m
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
diff changeset
47 endif
369b173d6c16 provide stemleaf.m and printd.m
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
diff changeset
48 opt = substr (filename, sufix+1);
19313
da86488d3d59 Two more tmpnam -> tempname changes in core Octave.
Rik <rik@octave.org>
parents: 18910
diff changeset
49 [pf, tempf, mag] = mkstemp ("oct-XXXXXX", 1);
16006
9978c44ab12c Style fixes on printd.m and stemleaf.m
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 16005
diff changeset
50 fprintf (pf, "%s", disp (obj));
16005
369b173d6c16 provide stemleaf.m and printd.m
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
diff changeset
51 frewind (pf);
16006
9978c44ab12c Style fixes on printd.m and stemleaf.m
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 16005
diff changeset
52
9978c44ab12c Style fixes on printd.m and stemleaf.m
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 16005
diff changeset
53 ## It seems best to only use convert for image output. Its ps and pdf
9978c44ab12c Style fixes on printd.m and stemleaf.m
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 16005
diff changeset
54 ## are badly rendered.
16005
369b173d6c16 provide stemleaf.m and printd.m
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
diff changeset
55 opt = lower (opt);
16933
e39f00a32dc7 maint: Use parentheses around condition for switch(),while(),if() statements.
Rik <rik@octave.org>
parents: 16828
diff changeset
56 switch (opt)
17174
c3c1ebfaa7dc maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents: 16933
diff changeset
57 case "pdf"
19867
9fc020886ae9 maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
58 enscr = sprintf ("enscript --no-header -o %s.ps %s ; ps2pdf %s.ps %s.pdf; mv %s.pdf %s;exit", ...
16006
9978c44ab12c Style fixes on printd.m and stemleaf.m
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 16005
diff changeset
59 tempf, tempf, tempf, tempf, tempf, filename);
16005
369b173d6c16 provide stemleaf.m and printd.m
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
diff changeset
60 system (enscr);
16006
9978c44ab12c Style fixes on printd.m and stemleaf.m
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 16005
diff changeset
61 delete ([tempf ".ps"]);
17174
c3c1ebfaa7dc maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents: 16933
diff changeset
62 case "ps"
16006
9978c44ab12c Style fixes on printd.m and stemleaf.m
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 16005
diff changeset
63 enscr = sprintf ("enscript --no-header -o %s %s ; exit", filename, tempf);
16005
369b173d6c16 provide stemleaf.m and printd.m
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
diff changeset
64 system (enscr);
17174
c3c1ebfaa7dc maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents: 16933
diff changeset
65 case "eps"
19867
9fc020886ae9 maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
66 enscr = sprintf ("enscript --no-header -o %s.ps %s ; ps2eps --ignoreBB %s.ps; mv %s.eps %s; exit", ...
16006
9978c44ab12c Style fixes on printd.m and stemleaf.m
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 16005
diff changeset
67 tempf, tempf, tempf, tempf, filename);
16005
369b173d6c16 provide stemleaf.m and printd.m
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
diff changeset
68 system (enscr);
16006
9978c44ab12c Style fixes on printd.m and stemleaf.m
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 16005
diff changeset
69 delete ([tempf ".ps"]);
17174
c3c1ebfaa7dc maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents: 16933
diff changeset
70 case "txt"
16006
9978c44ab12c Style fixes on printd.m and stemleaf.m
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 16005
diff changeset
71 enscr = sprintf ("cp %s %s", tempf, filename);
16005
369b173d6c16 provide stemleaf.m and printd.m
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
diff changeset
72 system (enscr);
17174
c3c1ebfaa7dc maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents: 16933
diff changeset
73 case {"jpg", "jpeg"}
16006
9978c44ab12c Style fixes on printd.m and stemleaf.m
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 16005
diff changeset
74 enscr = sprintf ("convert -trim txt:%s jpg:%s", tempf, filename);
16005
369b173d6c16 provide stemleaf.m and printd.m
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
diff changeset
75 system (enscr);
369b173d6c16 provide stemleaf.m and printd.m
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
diff changeset
76 otherwise
369b173d6c16 provide stemleaf.m and printd.m
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
diff changeset
77 fclose (pf);
369b173d6c16 provide stemleaf.m and printd.m
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
diff changeset
78 delete (tempf);
16006
9978c44ab12c Style fixes on printd.m and stemleaf.m
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 16005
diff changeset
79 error ("Unknown conversion type: %s.\nOptions are: pdf ps eps txt jpg jpeg", opt);
9978c44ab12c Style fixes on printd.m and stemleaf.m
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 16005
diff changeset
80
9978c44ab12c Style fixes on printd.m and stemleaf.m
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 16005
diff changeset
81 endswitch
9978c44ab12c Style fixes on printd.m and stemleaf.m
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 16005
diff changeset
82 fclose (pf);
9978c44ab12c Style fixes on printd.m and stemleaf.m
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 16005
diff changeset
83 delete (tempf);
19867
9fc020886ae9 maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
84 pr_out = sprintf ("%s file %s written\n", opt, filename);
16005
369b173d6c16 provide stemleaf.m and printd.m
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
diff changeset
85 endfunction
369b173d6c16 provide stemleaf.m and printd.m
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
diff changeset
86
16828
ddac88d32d6a Make demos in plot m-files compatible with Matlab for running comparison script.
Rik <rik@octave.org>
parents: 16180
diff changeset
87
16005
369b173d6c16 provide stemleaf.m and printd.m
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
diff changeset
88 %!demo
18910
cafffc1b70b1 update plot demo blocks for compare_plot_demos
Andreas Weber <andy.weber.aw@gmail.com>
parents: 17572
diff changeset
89 %! r2 = char ( ...
cafffc1b70b1 update plot demo blocks for compare_plot_demos
Andreas Weber <andy.weber.aw@gmail.com>
parents: 17572
diff changeset
90 %! 'stem step: 10, data: unsorted.', ...
cafffc1b70b1 update plot demo blocks for compare_plot_demos
Andreas Weber <andy.weber.aw@gmail.com>
parents: 17572
diff changeset
91 %! 'Hinges: lo: 12, hi: 42' , ...
cafffc1b70b1 update plot demo blocks for compare_plot_demos
Andreas Weber <andy.weber.aw@gmail.com>
parents: 17572
diff changeset
92 %! ' 1 | 22118' , ...
cafffc1b70b1 update plot demo blocks for compare_plot_demos
Andreas Weber <andy.weber.aw@gmail.com>
parents: 17572
diff changeset
93 %! ' 2 | 28' , ...
cafffc1b70b1 update plot demo blocks for compare_plot_demos
Andreas Weber <andy.weber.aw@gmail.com>
parents: 17572
diff changeset
94 %! ' 3 | 98' , ...
cafffc1b70b1 update plot demo blocks for compare_plot_demos
Andreas Weber <andy.weber.aw@gmail.com>
parents: 17572
diff changeset
95 %! ' 4 | 244' , ...
16828
ddac88d32d6a Make demos in plot m-files compatible with Matlab for running comparison script.
Rik <rik@octave.org>
parents: 16180
diff changeset
96 %! ' 5 | 2' );
ddac88d32d6a Make demos in plot m-files compatible with Matlab for running comparison script.
Rik <rik@octave.org>
parents: 16180
diff changeset
97 %! printd (r2, 'test_p.txt');
ddac88d32d6a Make demos in plot m-files compatible with Matlab for running comparison script.
Rik <rik@octave.org>
parents: 16180
diff changeset
98 %! system ('cat test_p.txt');
ddac88d32d6a Make demos in plot m-files compatible with Matlab for running comparison script.
Rik <rik@octave.org>
parents: 16180
diff changeset
99 %! delete ('test_p.txt');
16005
369b173d6c16 provide stemleaf.m and printd.m
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
diff changeset
100
369b173d6c16 provide stemleaf.m and printd.m
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
diff changeset
101 %!test
16180
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16006
diff changeset
102 %! r2 = char (
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16006
diff changeset
103 %! "stem step: 10, data: unsorted.",
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16006
diff changeset
104 %! "Hinges: lo: 12, hi: 42" ,
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16006
diff changeset
105 %! " 1 | 22118" ,
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16006
diff changeset
106 %! " 2 | 28" ,
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16006
diff changeset
107 %! " 3 | 98" ,
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16006
diff changeset
108 %! " 4 | 244" ,
3e6d15a2a50b Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents: 16006
diff changeset
109 %! " 5 | 2" );
16006
9978c44ab12c Style fixes on printd.m and stemleaf.m
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 16005
diff changeset
110 %! printd (r2, "test_p.txt");
9978c44ab12c Style fixes on printd.m and stemleaf.m
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 16005
diff changeset
111 %! r4 = fileread ("test_p.txt");
16005
369b173d6c16 provide stemleaf.m and printd.m
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
diff changeset
112 %! delete ("test_p.txt");
369b173d6c16 provide stemleaf.m and printd.m
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
diff changeset
113 %! r2 = disp (r2);
16828
ddac88d32d6a Make demos in plot m-files compatible with Matlab for running comparison script.
Rik <rik@octave.org>
parents: 16180
diff changeset
114 %! assert (r4, r2);
16005
369b173d6c16 provide stemleaf.m and printd.m
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
diff changeset
115