Mercurial > octave-nkf
annotate doc/interpreter/interpimages.m @ 20351:d8992a16643c
doc: Clean up m-files which generate images for Manual.
* geometryimages.m, interpimages.m, plotimages.m, sparseimages.m,
splineimages.m: Use the same style throughout the mi-files.
Obey Octave coding conventions.
author | Rik <rik@octave.org> |
---|---|
date | Thu, 09 Jul 2015 21:38:57 -0700 |
parents | c3c1fb44f9b5 |
children | b439ccc9a162 |
rev | line source |
---|---|
19731
4197fc428c7d
maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents:
19627
diff
changeset
|
1 ## Copyright (C) 2007-2015 David Bateman |
7018 | 2 ## |
3 ## This file is part of Octave. | |
4 ## | |
5 ## Octave is free software; you can redistribute it and/or modify it | |
6 ## under the terms of the GNU General Public License as published by | |
7 ## the Free Software Foundation; either version 3 of the License, or (at | |
8 ## your option) any later version. | |
9 ## | |
10 ## Octave is distributed in the hope that it will be useful, but | |
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 ## General Public License for more details. | |
14 ## | |
15 ## You should have received a copy of the GNU General Public License | |
16 ## along with Octave; see the file COPYING. If not, see | |
17 ## <http://www.gnu.org/licenses/>. | |
18 | |
20342
c3c1fb44f9b5
eliminate recursive make invocations in doc directory tree
John W. Eaton <jwe@octave.org>
parents:
19751
diff
changeset
|
19 function interpimages (d, nm, typ) |
19751
606b05352351
Backout cset 59ad278cfb98, use gnuplot for building doc images.
Rik <rik@octave.org>
parents:
19742
diff
changeset
|
20 graphics_toolkit ("gnuplot"); |
9912
e9fe12c1b0c0
Set default papersize to the desired imagesize
Rik <rdrider0-list@yahoo.com>
parents:
9298
diff
changeset
|
21 set_print_size (); |
e9fe12c1b0c0
Set default papersize to the desired imagesize
Rik <rdrider0-list@yahoo.com>
parents:
9298
diff
changeset
|
22 hide_output (); |
20351
d8992a16643c
doc: Clean up m-files which generate images for Manual.
Rik <rik@octave.org>
parents:
20342
diff
changeset
|
23 outfile = fullfile (d, [nm "." typ]); |
7257 | 24 if (strcmp (typ, "png")) |
25 set (0, "defaulttextfontname", "*"); | |
26 endif | |
9914
e76d8c767584
Switch to color output for PostScript documentation images
Rik <rdrider0-list@yahoo.com>
parents:
9912
diff
changeset
|
27 if (strcmp (typ, "eps")) |
e76d8c767584
Switch to color output for PostScript documentation images
Rik <rdrider0-list@yahoo.com>
parents:
9912
diff
changeset
|
28 d_typ = "-depsc2"; |
e76d8c767584
Switch to color output for PostScript documentation images
Rik <rdrider0-list@yahoo.com>
parents:
9912
diff
changeset
|
29 else |
16994
333243133364
Use matrix concatenation for strings, rather than cstrcat(), for clarity and performance.
Rik <rik@octave.org>
parents:
14138
diff
changeset
|
30 d_typ = ["-d", typ]; |
9914
e76d8c767584
Switch to color output for PostScript documentation images
Rik <rdrider0-list@yahoo.com>
parents:
9912
diff
changeset
|
31 endif |
9912
e9fe12c1b0c0
Set default papersize to the desired imagesize
Rik <rdrider0-list@yahoo.com>
parents:
9298
diff
changeset
|
32 |
7262 | 33 if (strcmp (typ, "txt")) |
20342
c3c1fb44f9b5
eliminate recursive make invocations in doc directory tree
John W. Eaton <jwe@octave.org>
parents:
19751
diff
changeset
|
34 image_as_txt (d, nm); |
7262 | 35 elseif (strcmp (nm, "interpft")) |
6721 | 36 t = 0 : 0.3 : pi; dt = t(2)-t(1); |
37 n = length (t); k = 100; | |
38 ti = t(1) + [0 : k-1]*dt*n/k; | |
39 y = sin (4*t + 0.3) .* cos (3*t - 0.1); | |
40 yp = sin (4*ti + 0.3) .* cos (3*ti - 0.1); | |
17504
8b692d9ea54e
Use Octave coding conventions for m-files which generate images for manual.
Rik <rik@octave.org>
parents:
16994
diff
changeset
|
41 plot (ti, yp, "g", ti, interp1 (t, y, ti, "spline"), "b", ... |
8b692d9ea54e
Use Octave coding conventions for m-files which generate images for manual.
Rik <rik@octave.org>
parents:
16994
diff
changeset
|
42 ti, interpft (y, k), "c", t, y, "r+"); |
8b692d9ea54e
Use Octave coding conventions for m-files which generate images for manual.
Rik <rik@octave.org>
parents:
16994
diff
changeset
|
43 legend ("sin(4t+0.3)cos(3t-0.1)", "spline", "interpft", "data"); |
20342
c3c1fb44f9b5
eliminate recursive make invocations in doc directory tree
John W. Eaton <jwe@octave.org>
parents:
19751
diff
changeset
|
44 print (outfile, d_typ); |
6721 | 45 elseif (strcmp (nm, "interpn")) |
46 x = y = z = -1:1; | |
47 f = @(x,y,z) x.^2 - y - z.^2; | |
48 [xx, yy, zz] = meshgrid (x, y, z); | |
49 v = f (xx,yy,zz); | |
50 xi = yi = zi = -1:0.1:1; | |
51 [xxi, yyi, zzi] = ndgrid (xi, yi, zi); | |
17504
8b692d9ea54e
Use Octave coding conventions for m-files which generate images for manual.
Rik <rik@octave.org>
parents:
16994
diff
changeset
|
52 vi = interpn (x, y, z, v, xxi, yyi, zzi, "spline"); |
6723 | 53 mesh (zi, yi, squeeze (vi(1,:,:))); |
20342
c3c1fb44f9b5
eliminate recursive make invocations in doc directory tree
John W. Eaton <jwe@octave.org>
parents:
19751
diff
changeset
|
54 print (outfile, d_typ); |
6743 | 55 elseif (strcmp (nm, "interpderiv1")) |
56 t = -2:2; | |
57 dt = 1; | |
58 ti =-2:0.025:2; | |
59 dti = 0.025; | |
17504
8b692d9ea54e
Use Octave coding conventions for m-files which generate images for manual.
Rik <rik@octave.org>
parents:
16994
diff
changeset
|
60 y = sign (t); |
8b692d9ea54e
Use Octave coding conventions for m-files which generate images for manual.
Rik <rik@octave.org>
parents:
16994
diff
changeset
|
61 ys = interp1 (t,y,ti,"spline"); |
8b692d9ea54e
Use Octave coding conventions for m-files which generate images for manual.
Rik <rik@octave.org>
parents:
16994
diff
changeset
|
62 yp = interp1 (t,y,ti,"pchip"); |
8b692d9ea54e
Use Octave coding conventions for m-files which generate images for manual.
Rik <rik@octave.org>
parents:
16994
diff
changeset
|
63 plot (ti, ys,"r-", ti, yp,"g-"); |
8b692d9ea54e
Use Octave coding conventions for m-files which generate images for manual.
Rik <rik@octave.org>
parents:
16994
diff
changeset
|
64 legend ("spline","pchip", 4); |
20342
c3c1fb44f9b5
eliminate recursive make invocations in doc directory tree
John W. Eaton <jwe@octave.org>
parents:
19751
diff
changeset
|
65 print (outfile, d_typ); |
6743 | 66 elseif (strcmp (nm, "interpderiv2")) |
67 t = -2:2; | |
68 dt = 1; | |
69 ti =-2:0.025:2; | |
70 dti = 0.025; | |
17504
8b692d9ea54e
Use Octave coding conventions for m-files which generate images for manual.
Rik <rik@octave.org>
parents:
16994
diff
changeset
|
71 y = sign (t); |
8b692d9ea54e
Use Octave coding conventions for m-files which generate images for manual.
Rik <rik@octave.org>
parents:
16994
diff
changeset
|
72 ddys = diff (diff (interp1 (t,y,ti,"spline"))./dti)./dti; |
8b692d9ea54e
Use Octave coding conventions for m-files which generate images for manual.
Rik <rik@octave.org>
parents:
16994
diff
changeset
|
73 ddyp = diff (diff (interp1 (t,y,ti,"pchip"))./dti)./dti; |
8b692d9ea54e
Use Octave coding conventions for m-files which generate images for manual.
Rik <rik@octave.org>
parents:
16994
diff
changeset
|
74 plot (ti(2:end-1),ddys,"r*", ti(2:end-1),ddyp,"g+"); |
8b692d9ea54e
Use Octave coding conventions for m-files which generate images for manual.
Rik <rik@octave.org>
parents:
16994
diff
changeset
|
75 legend ("spline", "pchip"); |
20342
c3c1fb44f9b5
eliminate recursive make invocations in doc directory tree
John W. Eaton <jwe@octave.org>
parents:
19751
diff
changeset
|
76 print (outfile, d_typ); |
6721 | 77 endif |
19627
446c46af4b42
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
78 hide_output (); |
9912
e9fe12c1b0c0
Set default papersize to the desired imagesize
Rik <rdrider0-list@yahoo.com>
parents:
9298
diff
changeset
|
79 endfunction |
e9fe12c1b0c0
Set default papersize to the desired imagesize
Rik <rdrider0-list@yahoo.com>
parents:
9298
diff
changeset
|
80 |
e9fe12c1b0c0
Set default papersize to the desired imagesize
Rik <rdrider0-list@yahoo.com>
parents:
9298
diff
changeset
|
81 function set_print_size () |
e9fe12c1b0c0
Set default papersize to the desired imagesize
Rik <rdrider0-list@yahoo.com>
parents:
9298
diff
changeset
|
82 image_size = [5.0, 3.5]; # in inches, 16:9 format |
e9fe12c1b0c0
Set default papersize to the desired imagesize
Rik <rdrider0-list@yahoo.com>
parents:
9298
diff
changeset
|
83 border = 0; # For postscript use 50/72 |
e9fe12c1b0c0
Set default papersize to the desired imagesize
Rik <rdrider0-list@yahoo.com>
parents:
9298
diff
changeset
|
84 set (0, "defaultfigurepapertype", "<custom>"); |
e9fe12c1b0c0
Set default papersize to the desired imagesize
Rik <rdrider0-list@yahoo.com>
parents:
9298
diff
changeset
|
85 set (0, "defaultfigurepaperorientation", "landscape"); |
e9fe12c1b0c0
Set default papersize to the desired imagesize
Rik <rdrider0-list@yahoo.com>
parents:
9298
diff
changeset
|
86 set (0, "defaultfigurepapersize", image_size + 2*border); |
e9fe12c1b0c0
Set default papersize to the desired imagesize
Rik <rdrider0-list@yahoo.com>
parents:
9298
diff
changeset
|
87 set (0, "defaultfigurepaperposition", [border, border, image_size]); |
6721 | 88 endfunction |
89 | |
90 ## Use this function before plotting commands and after every call to | |
91 ## print since print() resets output to stdout (unfortunately, gnpulot | |
92 ## can't pop output as it can the terminal type). | |
9912
e9fe12c1b0c0
Set default papersize to the desired imagesize
Rik <rdrider0-list@yahoo.com>
parents:
9298
diff
changeset
|
93 function hide_output () |
20351
d8992a16643c
doc: Clean up m-files which generate images for Manual.
Rik <rik@octave.org>
parents:
20342
diff
changeset
|
94 hf = figure (1); |
d8992a16643c
doc: Clean up m-files which generate images for Manual.
Rik <rik@octave.org>
parents:
20342
diff
changeset
|
95 set (hf, "visible", "off"); |
6721 | 96 endfunction |
7262 | 97 |
98 ## generate something for the texinfo @image command to process | |
20351
d8992a16643c
doc: Clean up m-files which generate images for Manual.
Rik <rik@octave.org>
parents:
20342
diff
changeset
|
99 function image_as_txt (d, nm) |
d8992a16643c
doc: Clean up m-files which generate images for Manual.
Rik <rik@octave.org>
parents:
20342
diff
changeset
|
100 fid = fopen (fullfile (d, [nm ".txt"]), "wt"); |
7262 | 101 fputs (fid, "\n"); |
102 fputs (fid, "+---------------------------------+\n"); | |
103 fputs (fid, "| Image unavailable in text mode. |\n"); | |
104 fputs (fid, "+---------------------------------+\n"); | |
105 fclose (fid); | |
106 endfunction | |
17504
8b692d9ea54e
Use Octave coding conventions for m-files which generate images for manual.
Rik <rik@octave.org>
parents:
16994
diff
changeset
|
107 |