Mercurial > hg > octave-nkf
annotate scripts/plot/util/printd.m @ 20038:9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Try to trim long lines to < 80 chars.
Use '##' for single line comments.
Use '(...)' around tests for if/elseif/switch/while.
Abut cell indexing operator '{' next to variable.
Abut array indexing operator '(' next to variable.
Use space between negation operator '!' and following expression.
Use two newlines between endfunction and start of %!test or %!demo code.
Remove unnecessary parens grouping between short-circuit operators.
Remove stray extra spaces (typos) between variables and assignment operators.
Remove stray extra spaces from ends of lines.
author | Rik <rik@octave.org> |
---|---|
date | Mon, 23 Feb 2015 14:54:39 -0800 |
parents | 4197fc428c7d |
children | 777f26aa8e3e |
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" |
20038
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19898
diff
changeset
|
56 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
|
57 tempf, tempf, tempf, tempf, tempf, filename); |
16005
369b173d6c16
provide stemleaf.m and printd.m
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
diff
changeset
|
58 system (enscr); |
16006
9978c44ab12c
Style fixes on printd.m and stemleaf.m
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
16005
diff
changeset
|
59 delete ([tempf ".ps"]); |
17174
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
16933
diff
changeset
|
60 case "ps" |
16006
9978c44ab12c
Style fixes on printd.m and stemleaf.m
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
16005
diff
changeset
|
61 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
|
62 system (enscr); |
17174
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
16933
diff
changeset
|
63 case "eps" |
20038
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19898
diff
changeset
|
64 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
|
65 tempf, tempf, tempf, tempf, filename); |
16005
369b173d6c16
provide stemleaf.m and printd.m
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
diff
changeset
|
66 system (enscr); |
16006
9978c44ab12c
Style fixes on printd.m and stemleaf.m
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
16005
diff
changeset
|
67 delete ([tempf ".ps"]); |
17174
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
16933
diff
changeset
|
68 case "txt" |
16006
9978c44ab12c
Style fixes on printd.m and stemleaf.m
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
16005
diff
changeset
|
69 enscr = sprintf ("cp %s %s", tempf, filename); |
16005
369b173d6c16
provide stemleaf.m and printd.m
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
diff
changeset
|
70 system (enscr); |
17174
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
16933
diff
changeset
|
71 case {"jpg", "jpeg"} |
16006
9978c44ab12c
Style fixes on printd.m and stemleaf.m
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
16005
diff
changeset
|
72 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
|
73 system (enscr); |
369b173d6c16
provide stemleaf.m and printd.m
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
diff
changeset
|
74 otherwise |
369b173d6c16
provide stemleaf.m and printd.m
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
diff
changeset
|
75 fclose (pf); |
369b173d6c16
provide stemleaf.m and printd.m
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
diff
changeset
|
76 delete (tempf); |
16006
9978c44ab12c
Style fixes on printd.m and stemleaf.m
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
16005
diff
changeset
|
77 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
|
78 |
9978c44ab12c
Style fixes on printd.m and stemleaf.m
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
16005
diff
changeset
|
79 endswitch |
9978c44ab12c
Style fixes on printd.m and stemleaf.m
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
16005
diff
changeset
|
80 fclose (pf); |
9978c44ab12c
Style fixes on printd.m and stemleaf.m
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
16005
diff
changeset
|
81 delete (tempf); |
20038
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19898
diff
changeset
|
82 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
|
83 endfunction |
369b173d6c16
provide stemleaf.m and printd.m
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
diff
changeset
|
84 |
16828
ddac88d32d6a
Make demos in plot m-files compatible with Matlab for running comparison script.
Rik <rik@octave.org>
parents:
16180
diff
changeset
|
85 |
16005
369b173d6c16
provide stemleaf.m and printd.m
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
diff
changeset
|
86 %!demo |
19066
cafffc1b70b1
update plot demo blocks for compare_plot_demos
Andreas Weber <andy.weber.aw@gmail.com>
parents:
17572
diff
changeset
|
87 %! r2 = char ( ... |
cafffc1b70b1
update plot demo blocks for compare_plot_demos
Andreas Weber <andy.weber.aw@gmail.com>
parents:
17572
diff
changeset
|
88 %! '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
|
89 %! '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
|
90 %! ' 1 | 22118' , ... |
cafffc1b70b1
update plot demo blocks for compare_plot_demos
Andreas Weber <andy.weber.aw@gmail.com>
parents:
17572
diff
changeset
|
91 %! ' 2 | 28' , ... |
cafffc1b70b1
update plot demo blocks for compare_plot_demos
Andreas Weber <andy.weber.aw@gmail.com>
parents:
17572
diff
changeset
|
92 %! ' 3 | 98' , ... |
cafffc1b70b1
update plot demo blocks for compare_plot_demos
Andreas Weber <andy.weber.aw@gmail.com>
parents:
17572
diff
changeset
|
93 %! ' 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
|
94 %! ' 5 | 2' ); |
ddac88d32d6a
Make demos in plot m-files compatible with Matlab for running comparison script.
Rik <rik@octave.org>
parents:
16180
diff
changeset
|
95 %! 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
|
96 %! 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
|
97 %! delete ('test_p.txt'); |
16005
369b173d6c16
provide stemleaf.m and printd.m
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
diff
changeset
|
98 |
369b173d6c16
provide stemleaf.m and printd.m
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
diff
changeset
|
99 %!test |
16180
3e6d15a2a50b
Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
16006
diff
changeset
|
100 %! r2 = char ( |
3e6d15a2a50b
Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
16006
diff
changeset
|
101 %! "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
|
102 %! "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
|
103 %! " 1 | 22118" , |
3e6d15a2a50b
Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
16006
diff
changeset
|
104 %! " 2 | 28" , |
3e6d15a2a50b
Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
16006
diff
changeset
|
105 %! " 3 | 98" , |
3e6d15a2a50b
Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
16006
diff
changeset
|
106 %! " 4 | 244" , |
3e6d15a2a50b
Update stemleaf to provide new features and minor fix to printd
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
16006
diff
changeset
|
107 %! " 5 | 2" ); |
16006
9978c44ab12c
Style fixes on printd.m and stemleaf.m
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
16005
diff
changeset
|
108 %! 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
|
109 %! r4 = fileread ("test_p.txt"); |
16005
369b173d6c16
provide stemleaf.m and printd.m
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
diff
changeset
|
110 %! delete ("test_p.txt"); |
369b173d6c16
provide stemleaf.m and printd.m
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
diff
changeset
|
111 %! 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
|
112 %! assert (r4, r2); |
16005
369b173d6c16
provide stemleaf.m and printd.m
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
diff
changeset
|
113 |