Mercurial > hg > octave-lyh
annotate scripts/plot/printd.m @ 16006:9978c44ab12c
Style fixes on printd.m and stemleaf.m
* printd.m, stemleaf.m: Whitespace fixes, changing single-quoted
strings to double-quoted, use octothorpe (#) consistently for
comments instead of percentage sign (%).
author | Jordi Gutiérrez Hermoso <jordigh@octave.org> |
---|---|
date | Wed, 06 Feb 2013 11:16:37 -0500 |
parents | 369b173d6c16 |
children | 3e6d15a2a50b |
rev | line source |
---|---|
16005
369b173d6c16
provide stemleaf.m and printd.m
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
diff
changeset
|
1 ## Copyright (C) 2013 Michael D. Godfrey |
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}) |
369b173d6c16
provide stemleaf.m and printd.m
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
diff
changeset
|
23 ## |
369b173d6c16
provide stemleaf.m and printd.m
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
diff
changeset
|
24 ## Convert any object acceptable to @code{disp} into the format |
369b173d6c16
provide stemleaf.m and printd.m
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
diff
changeset
|
25 ## selected by the suffix of @var{filename}. |
369b173d6c16
provide stemleaf.m and printd.m
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
diff
changeset
|
26 ## |
369b173d6c16
provide stemleaf.m and printd.m
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
diff
changeset
|
27 ## 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
|
28 ## of functions such as @code{stemleaf}. |
369b173d6c16
provide stemleaf.m and printd.m
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
diff
changeset
|
29 ## @seealso{stemleaf} |
369b173d6c16
provide stemleaf.m and printd.m
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
diff
changeset
|
30 ## @end deftypefn |
369b173d6c16
provide stemleaf.m and printd.m
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
diff
changeset
|
31 |
369b173d6c16
provide stemleaf.m and printd.m
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
diff
changeset
|
32 ## Author: Michael D. Godfrey <michaeldgodfrey@gmail.com> |
369b173d6c16
provide stemleaf.m and printd.m
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
diff
changeset
|
33 ## Description: Convert objects into other file formats. |
369b173d6c16
provide stemleaf.m and printd.m
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
diff
changeset
|
34 |
369b173d6c16
provide stemleaf.m and printd.m
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
diff
changeset
|
35 function printd (obj, filename) |
16006
9978c44ab12c
Style fixes on printd.m and stemleaf.m
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
16005
diff
changeset
|
36 ## 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
|
37 ## 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
|
38 ## filename is the output file (with required suffix). |
16005
369b173d6c16
provide stemleaf.m and printd.m
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
diff
changeset
|
39 |
16006
9978c44ab12c
Style fixes on printd.m and stemleaf.m
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
16005
diff
changeset
|
40 ## Extract .suffix from filename |
9978c44ab12c
Style fixes on printd.m and stemleaf.m
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
16005
diff
changeset
|
41 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
|
42 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
|
43 endif |
369b173d6c16
provide stemleaf.m and printd.m
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
diff
changeset
|
44 opt = substr (filename, sufix+1); |
16006
9978c44ab12c
Style fixes on printd.m and stemleaf.m
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
16005
diff
changeset
|
45 [pf, tempf, mag] = mkstemp ("oct-XXXXXX", 1); # Safe version of tmpnam() |
9978c44ab12c
Style fixes on printd.m and stemleaf.m
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
16005
diff
changeset
|
46 fprintf (pf, "%s", disp (obj)); |
16005
369b173d6c16
provide stemleaf.m and printd.m
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
diff
changeset
|
47 frewind (pf); |
16006
9978c44ab12c
Style fixes on printd.m and stemleaf.m
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
16005
diff
changeset
|
48 |
9978c44ab12c
Style fixes on printd.m and stemleaf.m
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
16005
diff
changeset
|
49 ## 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
|
50 ## are badly rendered. |
16005
369b173d6c16
provide stemleaf.m and printd.m
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
diff
changeset
|
51 opt = lower (opt); |
369b173d6c16
provide stemleaf.m and printd.m
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
diff
changeset
|
52 switch opt |
369b173d6c16
provide stemleaf.m and printd.m
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
diff
changeset
|
53 case {"pdf"} |
369b173d6c16
provide stemleaf.m and printd.m
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
diff
changeset
|
54 enscr = sprintf ( |
16006
9978c44ab12c
Style fixes on printd.m and stemleaf.m
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
16005
diff
changeset
|
55 "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
|
56 tempf, tempf, tempf, tempf, tempf, filename); |
16005
369b173d6c16
provide stemleaf.m and printd.m
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
diff
changeset
|
57 system (enscr); |
16006
9978c44ab12c
Style fixes on printd.m and stemleaf.m
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
16005
diff
changeset
|
58 delete ([tempf ".ps"]); |
16005
369b173d6c16
provide stemleaf.m and printd.m
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
diff
changeset
|
59 case {"ps"} |
16006
9978c44ab12c
Style fixes on printd.m and stemleaf.m
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
16005
diff
changeset
|
60 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
|
61 system (enscr); |
369b173d6c16
provide stemleaf.m and printd.m
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
diff
changeset
|
62 case {"eps"} |
369b173d6c16
provide stemleaf.m and printd.m
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
diff
changeset
|
63 enscr = sprintf ( |
16006
9978c44ab12c
Style fixes on printd.m and stemleaf.m
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
16005
diff
changeset
|
64 "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
|
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"]); |
16005
369b173d6c16
provide stemleaf.m and printd.m
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
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); |
369b173d6c16
provide stemleaf.m and printd.m
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
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); |
9978c44ab12c
Style fixes on printd.m and stemleaf.m
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
16005
diff
changeset
|
82 printf ("%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 |
369b173d6c16
provide stemleaf.m and printd.m
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
diff
changeset
|
85 %!demo |
369b173d6c16
provide stemleaf.m and printd.m
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
diff
changeset
|
86 %! r2 = ["stem step: 10, data: unsorted.\nHinges: lo: 12, hi: 42\n";... |
369b173d6c16
provide stemleaf.m and printd.m
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
diff
changeset
|
87 %! " 1 | 22118";" 2 | 28";" 3 | 98";" 4 | 244";" 5 | 2"]; |
16006
9978c44ab12c
Style fixes on printd.m and stemleaf.m
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
16005
diff
changeset
|
88 %! printd (r2, "test_p.txt"); |
16005
369b173d6c16
provide stemleaf.m and printd.m
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
diff
changeset
|
89 %! system ("cat test_p.txt"); |
369b173d6c16
provide stemleaf.m and printd.m
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
diff
changeset
|
90 %! delete ("test_p.txt"); |
369b173d6c16
provide stemleaf.m and printd.m
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
diff
changeset
|
91 |
369b173d6c16
provide stemleaf.m and printd.m
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
diff
changeset
|
92 %!test |
369b173d6c16
provide stemleaf.m and printd.m
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
diff
changeset
|
93 %! r2 = ["stem step: 10, data: unsorted.\nHinges: lo: 12, hi: 42\n";... |
369b173d6c16
provide stemleaf.m and printd.m
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
diff
changeset
|
94 %! " 1 | 22118";" 2 | 28";" 3 | 98";" 4 | 244";" 5 | 2"]; |
16006
9978c44ab12c
Style fixes on printd.m and stemleaf.m
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
16005
diff
changeset
|
95 %! 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
|
96 %! r4 = fileread ("test_p.txt"); |
16005
369b173d6c16
provide stemleaf.m and printd.m
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
diff
changeset
|
97 %! delete ("test_p.txt"); |
369b173d6c16
provide stemleaf.m and printd.m
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
diff
changeset
|
98 %! r2 = disp (r2); |
369b173d6c16
provide stemleaf.m and printd.m
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
diff
changeset
|
99 %! assert (r4, r2) |
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 |