Mercurial > hg > octave-lyh
comparison scripts/plot/saveas.m @ 11254:31f8534eb055
Add reference to new saveas function in printed manual.
Change saveas.m to more closely follow Octave coding standards.
author | Rik <octave@nomad.inbox5.com> |
---|---|
date | Mon, 15 Nov 2010 16:52:43 -0800 |
parents | 093c9facf0f0 |
children | c776f063fefe |
comparison
equal
deleted
inserted
replaced
11253:093c9facf0f0 | 11254:31f8534eb055 |
---|---|
15 ## You should have received a copy of the GNU General Public License | 15 ## You should have received a copy of the GNU General Public License |
16 ## along with Octave; see the file COPYING. If not, see | 16 ## along with Octave; see the file COPYING. If not, see |
17 ## <http://www.gnu.org/licenses/>. | 17 ## <http://www.gnu.org/licenses/>. |
18 | 18 |
19 ## -*- texinfo -*- | 19 ## -*- texinfo -*- |
20 ## @deftypefn {Function File} {} saveas (@var{h}, @var{file_name}) | 20 ## @deftypefn {Function File} {} saveas (@var{h}, @var{filename}) |
21 ## @deftypefnx {Function File} {} saveas (@var{h}, @var{file_name}, @var{file_ext}) | 21 ## @deftypefnx {Function File} {} saveas (@var{h}, @var{filename}, @var{ext}) |
22 ## Save the graphic object @var{h} to file @var{file_name} in graphic | 22 ## Save the graphic object @var{h} to file @var{filename} in graphic |
23 ## format @var{file_ext}. | 23 ## format @var{ext}. |
24 ## | 24 ## |
25 ## @var{file_ext} should be one of the following formats: | 25 ## @var{ext} should be one of the following formats: |
26 ## | 26 ## |
27 ## @table @code | 27 ## @table @code |
28 ## @item ps | 28 ## @item ps |
29 ## Postscript | 29 ## Postscript |
30 ## | |
30 ## @item eps | 31 ## @item eps |
31 ## Encapsulated Postscript | 32 ## Encapsulated Postscript |
33 ## | |
32 ## @item jpg | 34 ## @item jpg |
33 ## JPEG Image | 35 ## JPEG Image |
36 ## | |
34 ## @item png | 37 ## @item png |
35 ## PNG Image | 38 ## PNG Image |
39 ## | |
36 ## @item emf | 40 ## @item emf |
37 ## Enhanced Meta File | 41 ## Enhanced Meta File |
42 ## | |
38 ## @item pdf | 43 ## @item pdf |
39 ## Portable Document Format | 44 ## Portable Document Format |
40 ## @end table | 45 ## @end table |
41 ## | 46 ## |
42 ## All device formats specified in @code{print} can also be used. If @var{file_ext} | 47 ## All device formats specified in @code{print} may also be used. If |
43 ## is omitted it is extracted from @var{file_name}. The default value is | 48 ## @var{ext} is omitted it is extracted from @var{filename}. The default |
44 ## pdf. | 49 ## value is pdf. |
45 ## | 50 ## |
46 ## @example | 51 ## @example |
52 ## @group | |
47 ## figure (1); | 53 ## figure (1); |
48 ## clf (); | 54 ## clf (); |
49 ## surf (peaks); | 55 ## surf (peaks); |
50 ## saveas(1, "figure1.png"); | 56 ## saveas(1, "figure1.png"); |
57 ## @end group | |
51 ## @end example | 58 ## @end example |
52 ## | 59 ## |
53 ## @seealso{print} | 60 ## @seealso{print} |
54 ## @end deftypefn | 61 ## @end deftypefn |
55 | 62 |
63 | 70 |
64 if (ishandle (h)) | 71 if (ishandle (h)) |
65 if (isfigure (h)) | 72 if (isfigure (h)) |
66 fig = h; | 73 fig = h; |
67 else | 74 else |
68 fig = ancestor (h, "figure") | 75 fig = ancestor (h, "figure"); |
69 endif | 76 endif |
70 else | 77 else |
71 error ("first argument must be a graphics handle"); | 78 error ("saveas: first argument H must be a graphics handle"); |
72 endif | 79 endif |
73 | 80 |
74 if (!ischar(fname)) | 81 if (!ischar (fname)) |
75 error ("file_name must be a string."); | 82 error ("saveas: FILENAME must be a string"); |
76 endif | 83 endif |
77 | 84 |
78 if (nargin == 2) | 85 if (nargin == 2) |
79 [~, ~, ext] = fileparts (fname); | 86 [~, ~, ext] = fileparts (fname); |
80 if (!isempty (ext)) | 87 if (!isempty (ext)) |
82 endif | 89 endif |
83 endif | 90 endif |
84 | 91 |
85 if (nargin == 3) | 92 if (nargin == 3) |
86 if (!ischar (fname)) | 93 if (!ischar (fname)) |
87 error ("fext must be a string."); | 94 error ("saveas: EXT must be a string"); |
88 endif | 95 endif |
89 | 96 |
90 [~, ~, ext] = fileparts (fname); | 97 [~, ~, ext] = fileparts (fname); |
91 | 98 |
92 if (isempty (ext)) | 99 if (isempty (ext)) |
94 endif | 101 endif |
95 endif | 102 endif |
96 | 103 |
97 prt_opt = strcat ("-d", tolower (fext)); | 104 prt_opt = strcat ("-d", tolower (fext)); |
98 | 105 |
99 print (fname, prt_opt) | 106 print (fname, prt_opt); |
107 | |
100 endfunction | 108 endfunction |