1 ## Copyright (C) 2010-2012 Kai Habel
3 ## This file is part of Octave.
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.
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.
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/>.
20 ## @deftypefn {Function File} {} saveas (@var{h}, @var{filename})
21 ## @deftypefnx {Function File} {} saveas (@var{h}, @var{filename}, @var{fmt})
22 ## Save graphic object @var{h} to the file @var{filename} in graphic
25 ## @var{fmt} should be one of the following formats:
32 ## Encapsulated Postscript
44 ## Portable Document Format
47 ## All device formats specified in @code{print} may also be used. If
48 ## @var{fmt} is omitted it is extracted from the extension of @var{filename}.
49 ## The default format is @code{"pdf"}.
55 ## saveas (1, "figure1.png");
64 function saveas (h, filename, fmt = "pdf")
66 if ((nargin != 2) && (nargin != 3))
74 fig = ancestor (h, "figure");
77 error ("saveas: first argument H must be a graphics handle");
80 if (!ischar (filename))
81 error ("saveas: FILENAME must be a string");
85 [~, ~, ext] = fileparts (filename);
92 if (!ischar (filename))
93 error ("saveas: EXT must be a string");
96 [~, ~, ext] = fileparts (filename);
99 filename = strcat (filename, ".", fmt);
103 prt_opt = strcat ("-d", tolower (fmt));
105 print (filename, prt_opt);