Mercurial > hg > octave-nkf
annotate scripts/plot/util/printd.m @ 19898:4197fc428c7d
maint: Update copyright notices for 2015.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Wed, 11 Feb 2015 14:19:08 -0500 |
parents | da86488d3d59 |
children | 9fc020886ae9 |
rev | line source |
---|---|
19898
4197fc428c7d
maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents:
19471
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 ## |
369b173d6c16
provide stemleaf.m and printd.m
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
diff
changeset
|
25 ## Convert any object acceptable to @code{disp} into the format |
16180
3e6d15a2a50b
Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
16006
diff
changeset
|
26 ## selected by the suffix of @var{filename}. If the return argument |
3e6d15a2a50b
Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
16006
diff
changeset
|
27 ## @var{out_file} is given, the name of the created file is returned. |
16005
369b173d6c16
provide stemleaf.m and printd.m
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
diff
changeset
|
28 ## |
369b173d6c16
provide stemleaf.m and printd.m
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
diff
changeset
|
29 ## This function is intended to facilitate manipulation of the output |
369b173d6c16
provide stemleaf.m and printd.m
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
diff
changeset
|
30 ## of functions such as @code{stemleaf}. |
369b173d6c16
provide stemleaf.m and printd.m
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
diff
changeset
|
31 ## @seealso{stemleaf} |
369b173d6c16
provide stemleaf.m and printd.m
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
diff
changeset
|
32 ## @end deftypefn |
369b173d6c16
provide stemleaf.m and printd.m
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
diff
changeset
|
33 |
369b173d6c16
provide stemleaf.m and printd.m
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
diff
changeset
|
34 ## Author: Michael D. Godfrey <michaeldgodfrey@gmail.com> |
369b173d6c16
provide stemleaf.m and printd.m
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
diff
changeset
|
35 ## Description: Convert objects into other file formats. |
369b173d6c16
provide stemleaf.m and printd.m
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
diff
changeset
|
36 |
16180
3e6d15a2a50b
Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
16006
diff
changeset
|
37 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
|
38 ## 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
|
39 ## 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
|
40 ## filename is the output file (with required suffix). |
16005
369b173d6c16
provide stemleaf.m and printd.m
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
diff
changeset
|
41 |
16006
9978c44ab12c
Style fixes on printd.m and stemleaf.m
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
16005
diff
changeset
|
42 ## Extract .suffix from filename |
9978c44ab12c
Style fixes on printd.m and stemleaf.m
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
16005
diff
changeset
|
43 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
|
44 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
|
45 endif |
369b173d6c16
provide stemleaf.m and printd.m
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
diff
changeset
|
46 opt = substr (filename, sufix+1); |
19471
da86488d3d59
Two more tmpnam -> tempname changes in core Octave.
Rik <rik@octave.org>
parents:
19066
diff
changeset
|
47 [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
|
48 fprintf (pf, "%s", disp (obj)); |
16005
369b173d6c16
provide stemleaf.m and printd.m
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
diff
changeset
|
49 frewind (pf); |
16006
9978c44ab12c
Style fixes on printd.m and stemleaf.m
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
16005
diff
changeset
|
50 |
9978c44ab12c
Style fixes on printd.m and stemleaf.m
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
16005
diff
changeset
|
51 ## 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
|
52 ## are badly rendered. |
16005
369b173d6c16
provide stemleaf.m and printd.m
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
diff
changeset
|
53 opt = lower (opt); |
16933
e39f00a32dc7
maint: Use parentheses around condition for switch(),while(),if() statements.
Rik <rik@octave.org>
parents:
16828
diff
changeset
|
54 switch (opt) |
17174
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
16933
diff
changeset
|
55 case "pdf" |
16005
369b173d6c16
provide stemleaf.m and printd.m
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
diff
changeset
|
56 enscr = sprintf ( |
16006
9978c44ab12c
Style fixes on printd.m and stemleaf.m
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
16005
diff
changeset
|
57 "enscript --no-header -o %s.ps %s ; ps2pdf %s.ps %s.pdf; mv %s.pdf %s;exit",... |
9978c44ab12c
Style fixes on printd.m and stemleaf.m
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
16005
diff
changeset
|
58 tempf, tempf, tempf, tempf, tempf, filename); |
16005
369b173d6c16
provide stemleaf.m and printd.m
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
diff
changeset
|
59 system (enscr); |
16006
9978c44ab12c
Style fixes on printd.m and stemleaf.m
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
16005
diff
changeset
|
60 delete ([tempf ".ps"]); |
17174
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
16933
diff
changeset
|
61 case "ps" |
16006
9978c44ab12c
Style fixes on printd.m and stemleaf.m
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
16005
diff
changeset
|
62 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
|
63 system (enscr); |
17174
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
16933
diff
changeset
|
64 case "eps" |
16005
369b173d6c16
provide stemleaf.m and printd.m
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
diff
changeset
|
65 enscr = sprintf ( |
16006
9978c44ab12c
Style fixes on printd.m and stemleaf.m
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
16005
diff
changeset
|
66 "enscript --no-header -o %s.ps %s ; ps2eps --ignoreBB %s.ps; mv %s.eps %s; exit",... |
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); |
16180
3e6d15a2a50b
Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
16006
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 |
19066
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 |