Mercurial > hg > octave-nkf
annotate scripts/plot/saveas.m @ 11523:fd0a3ac60b0e
update copyright notices
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Fri, 14 Jan 2011 05:47:45 -0500 |
parents | c776f063fefe |
children | c792872f8942 |
rev | line source |
---|---|
11523 | 1 ## Copyright (C) 2010-2011 Kai Habel |
11253 | 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 | |
19 ## -*- texinfo -*- | |
11254
31f8534eb055
Add reference to new saveas function in printed manual.
Rik <octave@nomad.inbox5.com>
parents:
11253
diff
changeset
|
20 ## @deftypefn {Function File} {} saveas (@var{h}, @var{filename}) |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
11254
diff
changeset
|
21 ## @deftypefnx {Function File} {} saveas (@var{h}, @var{filename}, @var{fmt}) |
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
11254
diff
changeset
|
22 ## Save graphic object @var{h} to the file @var{filename} in graphic |
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
11254
diff
changeset
|
23 ## format @var{fmt}. |
11253 | 24 ## |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
11254
diff
changeset
|
25 ## @var{fmt} should be one of the following formats: |
11253 | 26 ## |
27 ## @table @code | |
28 ## @item ps | |
29 ## Postscript | |
11254
31f8534eb055
Add reference to new saveas function in printed manual.
Rik <octave@nomad.inbox5.com>
parents:
11253
diff
changeset
|
30 ## |
11253 | 31 ## @item eps |
32 ## Encapsulated Postscript | |
11254
31f8534eb055
Add reference to new saveas function in printed manual.
Rik <octave@nomad.inbox5.com>
parents:
11253
diff
changeset
|
33 ## |
11253 | 34 ## @item jpg |
35 ## JPEG Image | |
11254
31f8534eb055
Add reference to new saveas function in printed manual.
Rik <octave@nomad.inbox5.com>
parents:
11253
diff
changeset
|
36 ## |
11253 | 37 ## @item png |
38 ## PNG Image | |
11254
31f8534eb055
Add reference to new saveas function in printed manual.
Rik <octave@nomad.inbox5.com>
parents:
11253
diff
changeset
|
39 ## |
11253 | 40 ## @item emf |
41 ## Enhanced Meta File | |
11254
31f8534eb055
Add reference to new saveas function in printed manual.
Rik <octave@nomad.inbox5.com>
parents:
11253
diff
changeset
|
42 ## |
11253 | 43 ## @item pdf |
44 ## Portable Document Format | |
45 ## @end table | |
46 ## | |
11254
31f8534eb055
Add reference to new saveas function in printed manual.
Rik <octave@nomad.inbox5.com>
parents:
11253
diff
changeset
|
47 ## All device formats specified in @code{print} may also be used. If |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
11254
diff
changeset
|
48 ## @var{fmt} is omitted it is extracted from the extension of @var{filename}. |
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
11254
diff
changeset
|
49 ## The default format is @code{"pdf"}. |
11253 | 50 ## |
51 ## @example | |
11254
31f8534eb055
Add reference to new saveas function in printed manual.
Rik <octave@nomad.inbox5.com>
parents:
11253
diff
changeset
|
52 ## @group |
11253 | 53 ## figure (1); |
54 ## clf (); | |
55 ## surf (peaks); | |
56 ## saveas(1, "figure1.png"); | |
11254
31f8534eb055
Add reference to new saveas function in printed manual.
Rik <octave@nomad.inbox5.com>
parents:
11253
diff
changeset
|
57 ## @end group |
11253 | 58 ## @end example |
59 ## | |
60 ## @seealso{print} | |
61 ## @end deftypefn | |
62 | |
63 ## Author: Kai Habel | |
64 | |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
11254
diff
changeset
|
65 function saveas (h, filename, fmt = "pdf") |
11253 | 66 |
67 if ((nargin != 2) && (nargin != 3)) | |
68 print_usage (); | |
69 endif | |
70 | |
71 if (ishandle (h)) | |
72 if (isfigure (h)) | |
73 fig = h; | |
74 else | |
11254
31f8534eb055
Add reference to new saveas function in printed manual.
Rik <octave@nomad.inbox5.com>
parents:
11253
diff
changeset
|
75 fig = ancestor (h, "figure"); |
11253 | 76 endif |
77 else | |
11254
31f8534eb055
Add reference to new saveas function in printed manual.
Rik <octave@nomad.inbox5.com>
parents:
11253
diff
changeset
|
78 error ("saveas: first argument H must be a graphics handle"); |
11253 | 79 endif |
80 | |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
11254
diff
changeset
|
81 if (!ischar (filename)) |
11254
31f8534eb055
Add reference to new saveas function in printed manual.
Rik <octave@nomad.inbox5.com>
parents:
11253
diff
changeset
|
82 error ("saveas: FILENAME must be a string"); |
11253 | 83 endif |
84 | |
85 if (nargin == 2) | |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
11254
diff
changeset
|
86 [~, ~, ext] = fileparts (filename); |
11253 | 87 if (!isempty (ext)) |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
11254
diff
changeset
|
88 fmt = ext(2:end); |
11253 | 89 endif |
90 endif | |
91 | |
92 if (nargin == 3) | |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
11254
diff
changeset
|
93 if (!ischar (filename)) |
11254
31f8534eb055
Add reference to new saveas function in printed manual.
Rik <octave@nomad.inbox5.com>
parents:
11253
diff
changeset
|
94 error ("saveas: EXT must be a string"); |
11253 | 95 endif |
96 | |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
11254
diff
changeset
|
97 [~, ~, ext] = fileparts (filename); |
11253 | 98 |
99 if (isempty (ext)) | |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
11254
diff
changeset
|
100 filename = strcat (filename, ".", fmt); |
11253 | 101 endif |
102 endif | |
103 | |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
11254
diff
changeset
|
104 prt_opt = strcat ("-d", tolower (fmt)); |
11253 | 105 |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
11254
diff
changeset
|
106 print (filename, prt_opt); |
11254
31f8534eb055
Add reference to new saveas function in printed manual.
Rik <octave@nomad.inbox5.com>
parents:
11253
diff
changeset
|
107 |
11253 | 108 endfunction |