annotate scripts/plot/util/hgload.m @ 29359:7854d5752dd2

maint: merge stable to default.
author John W. Eaton <jwe@octave.org>
date Wed, 10 Feb 2021 10:10:40 -0500
parents 90fea9cc9caa 0a5b15007766
children 796f54d4ddbf
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
1 ########################################################################
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
2 ##
29358
0a5b15007766 update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
3 ## Copyright (C) 2014-2021 The Octave Project Developers
27918
b442ec6dda5c use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents: 27743
diff changeset
4 ##
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
5 ## See the file COPYRIGHT.md in the top-level directory of this
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
6 ## distribution or <https://octave.org/copyright/>.
18580
13c80c3e9660 Add new functions hgsave and hgload (bug #39532).
Massimiliano Fasi <mogrob.sanit@gmail.com> and Rik <rik@octave.org>
parents:
diff changeset
7 ##
13c80c3e9660 Add new functions hgsave and hgload (bug #39532).
Massimiliano Fasi <mogrob.sanit@gmail.com> and Rik <rik@octave.org>
parents:
diff changeset
8 ## This file is part of Octave.
13c80c3e9660 Add new functions hgsave and hgload (bug #39532).
Massimiliano Fasi <mogrob.sanit@gmail.com> and Rik <rik@octave.org>
parents:
diff changeset
9 ##
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 23220
diff changeset
10 ## Octave is free software: you can redistribute it and/or modify it
18580
13c80c3e9660 Add new functions hgsave and hgload (bug #39532).
Massimiliano Fasi <mogrob.sanit@gmail.com> and Rik <rik@octave.org>
parents:
diff changeset
11 ## under the terms of the GNU General Public License as published by
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 23220
diff changeset
12 ## the Free Software Foundation, either version 3 of the License, or
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22323
diff changeset
13 ## (at your option) any later version.
18580
13c80c3e9660 Add new functions hgsave and hgload (bug #39532).
Massimiliano Fasi <mogrob.sanit@gmail.com> and Rik <rik@octave.org>
parents:
diff changeset
14 ##
13c80c3e9660 Add new functions hgsave and hgload (bug #39532).
Massimiliano Fasi <mogrob.sanit@gmail.com> and Rik <rik@octave.org>
parents:
diff changeset
15 ## Octave is distributed in the hope that it will be useful, but
13c80c3e9660 Add new functions hgsave and hgload (bug #39532).
Massimiliano Fasi <mogrob.sanit@gmail.com> and Rik <rik@octave.org>
parents:
diff changeset
16 ## WITHOUT ANY WARRANTY; without even the implied warranty of
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22323
diff changeset
17 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22323
diff changeset
18 ## GNU General Public License for more details.
18580
13c80c3e9660 Add new functions hgsave and hgload (bug #39532).
Massimiliano Fasi <mogrob.sanit@gmail.com> and Rik <rik@octave.org>
parents:
diff changeset
19 ##
13c80c3e9660 Add new functions hgsave and hgload (bug #39532).
Massimiliano Fasi <mogrob.sanit@gmail.com> and Rik <rik@octave.org>
parents:
diff changeset
20 ## You should have received a copy of the GNU General Public License
13c80c3e9660 Add new functions hgsave and hgload (bug #39532).
Massimiliano Fasi <mogrob.sanit@gmail.com> and Rik <rik@octave.org>
parents:
diff changeset
21 ## along with Octave; see the file COPYING. If not, see
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 23220
diff changeset
22 ## <https://www.gnu.org/licenses/>.
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
23 ##
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
24 ########################################################################
18580
13c80c3e9660 Add new functions hgsave and hgload (bug #39532).
Massimiliano Fasi <mogrob.sanit@gmail.com> and Rik <rik@octave.org>
parents:
diff changeset
25
13c80c3e9660 Add new functions hgsave and hgload (bug #39532).
Massimiliano Fasi <mogrob.sanit@gmail.com> and Rik <rik@octave.org>
parents:
diff changeset
26 ## -*- texinfo -*-
25975
9fdc4c435a15 Touchups to cset c9ae077dedd1.
Rik <rik@octave.org>
parents: 25973
diff changeset
27 ## @deftypefn {} {@var{h} =} hgload (@var{filename})
25973
c9ae077dedd1 New function openfig.m (bug #44670)
Guillaume Flandin <guillaume.offline@gmail.com>
parents: 25054
diff changeset
28 ## @deftypefnx {} {[@var{h}, @var{old_prop}] =} hgload (@var{filename}, @var{prop_struct})
25989
0ab70de0348e Allow loading and saving of multiple graphic handles in a single file (bug #54924).
Guillaume Flandin <guillaume.offline@gmail.com>
parents: 25975
diff changeset
29 ## Load the graphics objects in @var{filename} into a vector of graphics
0ab70de0348e Allow loading and saving of multiple graphic handles in a single file (bug #54924).
Guillaume Flandin <guillaume.offline@gmail.com>
parents: 25975
diff changeset
30 ## handles @var{h}.
18580
13c80c3e9660 Add new functions hgsave and hgload (bug #39532).
Massimiliano Fasi <mogrob.sanit@gmail.com> and Rik <rik@octave.org>
parents:
diff changeset
31 ##
13c80c3e9660 Add new functions hgsave and hgload (bug #39532).
Massimiliano Fasi <mogrob.sanit@gmail.com> and Rik <rik@octave.org>
parents:
diff changeset
32 ## If @var{filename} has no extension, Octave will try to find the file with
25989
0ab70de0348e Allow loading and saving of multiple graphic handles in a single file (bug #54924).
Guillaume Flandin <guillaume.offline@gmail.com>
parents: 25975
diff changeset
33 ## and without the default extension @file{.ofig}.
25973
c9ae077dedd1 New function openfig.m (bug #44670)
Guillaume Flandin <guillaume.offline@gmail.com>
parents: 25054
diff changeset
34 ##
c9ae077dedd1 New function openfig.m (bug #44670)
Guillaume Flandin <guillaume.offline@gmail.com>
parents: 25054
diff changeset
35 ## If provided, the elements of structure @var{prop_struct} will be used to
25989
0ab70de0348e Allow loading and saving of multiple graphic handles in a single file (bug #54924).
Guillaume Flandin <guillaume.offline@gmail.com>
parents: 25975
diff changeset
36 ## override the properties of top-level objects stored in @var{filename}, and
0ab70de0348e Allow loading and saving of multiple graphic handles in a single file (bug #54924).
Guillaume Flandin <guillaume.offline@gmail.com>
parents: 25975
diff changeset
37 ## the saved values from @var{filename} will be stored in @var{old_prop}.
0ab70de0348e Allow loading and saving of multiple graphic handles in a single file (bug #54924).
Guillaume Flandin <guillaume.offline@gmail.com>
parents: 25975
diff changeset
38 ## @var{old_prop} is a cell array matching the size of @var{h}; each cell
0ab70de0348e Allow loading and saving of multiple graphic handles in a single file (bug #54924).
Guillaume Flandin <guillaume.offline@gmail.com>
parents: 25975
diff changeset
39 ## contains a structure of the existing property names and values before being
0ab70de0348e Allow loading and saving of multiple graphic handles in a single file (bug #54924).
Guillaume Flandin <guillaume.offline@gmail.com>
parents: 25975
diff changeset
40 ## overridden.
25973
c9ae077dedd1 New function openfig.m (bug #44670)
Guillaume Flandin <guillaume.offline@gmail.com>
parents: 25054
diff changeset
41 ##
c9ae077dedd1 New function openfig.m (bug #44670)
Guillaume Flandin <guillaume.offline@gmail.com>
parents: 25054
diff changeset
42 ## @seealso{openfig, hgsave, struct2hdl}
18580
13c80c3e9660 Add new functions hgsave and hgload (bug #39532).
Massimiliano Fasi <mogrob.sanit@gmail.com> and Rik <rik@octave.org>
parents:
diff changeset
43 ## @end deftypefn
13c80c3e9660 Add new functions hgsave and hgload (bug #39532).
Massimiliano Fasi <mogrob.sanit@gmail.com> and Rik <rik@octave.org>
parents:
diff changeset
44
25973
c9ae077dedd1 New function openfig.m (bug #44670)
Guillaume Flandin <guillaume.offline@gmail.com>
parents: 25054
diff changeset
45 function [h, old_prop] = hgload (filename, prop_struct = struct ())
18580
13c80c3e9660 Add new functions hgsave and hgload (bug #39532).
Massimiliano Fasi <mogrob.sanit@gmail.com> and Rik <rik@octave.org>
parents:
diff changeset
46
25989
0ab70de0348e Allow loading and saving of multiple graphic handles in a single file (bug #54924).
Guillaume Flandin <guillaume.offline@gmail.com>
parents: 25975
diff changeset
47 ## Check number of input arguments
28789
28de41192f3c Eliminate unneeded verification of nargin, nargout in m-files.
Rik <rik@octave.org>
parents: 27923
diff changeset
48 if (nargin == 0)
18580
13c80c3e9660 Add new functions hgsave and hgload (bug #39532).
Massimiliano Fasi <mogrob.sanit@gmail.com> and Rik <rik@octave.org>
parents:
diff changeset
49 print_usage ();
13c80c3e9660 Add new functions hgsave and hgload (bug #39532).
Massimiliano Fasi <mogrob.sanit@gmail.com> and Rik <rik@octave.org>
parents:
diff changeset
50 endif
18599
348f67886dc4 hgload.m: Check for file with .ofig extension before bare file name (bug #41978).
Rik <rik@octave.org>
parents: 18596
diff changeset
51
25989
0ab70de0348e Allow loading and saving of multiple graphic handles in a single file (bug #54924).
Guillaume Flandin <guillaume.offline@gmail.com>
parents: 25975
diff changeset
52 ## Check type of second input argument
0ab70de0348e Allow loading and saving of multiple graphic handles in a single file (bug #54924).
Guillaume Flandin <guillaume.offline@gmail.com>
parents: 25975
diff changeset
53 if (! isstruct (prop_struct))
25975
9fdc4c435a15 Touchups to cset c9ae077dedd1.
Rik <rik@octave.org>
parents: 25973
diff changeset
54 error ("hgload: PROP_STRUCT must be a struct");
25973
c9ae077dedd1 New function openfig.m (bug #44670)
Guillaume Flandin <guillaume.offline@gmail.com>
parents: 25054
diff changeset
55 endif
c9ae077dedd1 New function openfig.m (bug #44670)
Guillaume Flandin <guillaume.offline@gmail.com>
parents: 25054
diff changeset
56
18580
13c80c3e9660 Add new functions hgsave and hgload (bug #39532).
Massimiliano Fasi <mogrob.sanit@gmail.com> and Rik <rik@octave.org>
parents:
diff changeset
57 ## Check file existence
18599
348f67886dc4 hgload.m: Check for file with .ofig extension before bare file name (bug #41978).
Rik <rik@octave.org>
parents: 18596
diff changeset
58 [~, ~, ext] = fileparts (filename);
348f67886dc4 hgload.m: Check for file with .ofig extension before bare file name (bug #41978).
Rik <rik@octave.org>
parents: 18596
diff changeset
59 if (isempty (ext))
348f67886dc4 hgload.m: Check for file with .ofig extension before bare file name (bug #41978).
Rik <rik@octave.org>
parents: 18596
diff changeset
60 if (! isempty (file_in_loadpath ([filename ".ofig"])))
18580
13c80c3e9660 Add new functions hgsave and hgload (bug #39532).
Massimiliano Fasi <mogrob.sanit@gmail.com> and Rik <rik@octave.org>
parents:
diff changeset
61 filename = [filename ".ofig"];
18599
348f67886dc4 hgload.m: Check for file with .ofig extension before bare file name (bug #41978).
Rik <rik@octave.org>
parents: 18596
diff changeset
62 elseif (isempty (file_in_loadpath (filename)))
348f67886dc4 hgload.m: Check for file with .ofig extension before bare file name (bug #41978).
Rik <rik@octave.org>
parents: 18596
diff changeset
63 error ("hgload: unable to locate file %s", filename);
18580
13c80c3e9660 Add new functions hgsave and hgload (bug #39532).
Massimiliano Fasi <mogrob.sanit@gmail.com> and Rik <rik@octave.org>
parents:
diff changeset
64 endif
18599
348f67886dc4 hgload.m: Check for file with .ofig extension before bare file name (bug #41978).
Rik <rik@octave.org>
parents: 18596
diff changeset
65 else
18596
70d9db29db6f hgload.m: Correctly find filenames with .ofig extension.
Rik <rik@octave.org>
parents: 18581
diff changeset
66 if (isempty (file_in_loadpath (filename)))
18580
13c80c3e9660 Add new functions hgsave and hgload (bug #39532).
Massimiliano Fasi <mogrob.sanit@gmail.com> and Rik <rik@octave.org>
parents:
diff changeset
67 error ("hgload: unable to locate file %s", filename);
13c80c3e9660 Add new functions hgsave and hgload (bug #39532).
Massimiliano Fasi <mogrob.sanit@gmail.com> and Rik <rik@octave.org>
parents:
diff changeset
68 endif
13c80c3e9660 Add new functions hgsave and hgload (bug #39532).
Massimiliano Fasi <mogrob.sanit@gmail.com> and Rik <rik@octave.org>
parents:
diff changeset
69 endif
19597
db92e7e28e1f strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 18679
diff changeset
70
25973
c9ae077dedd1 New function openfig.m (bug #44670)
Guillaume Flandin <guillaume.offline@gmail.com>
parents: 25054
diff changeset
71 ## Load the handle structure
c9ae077dedd1 New function openfig.m (bug #44670)
Guillaume Flandin <guillaume.offline@gmail.com>
parents: 25054
diff changeset
72 hgs = {"s_oct40", "hgS_050200", "hgS_070000"};
c9ae077dedd1 New function openfig.m (bug #44670)
Guillaume Flandin <guillaume.offline@gmail.com>
parents: 25054
diff changeset
73 hg = load (filename);
27704
d30fcff9bad3 * hgload.m: Map "applicationdata" to "__appdata__" for Matlab compatibility (bug #57212).
Markus Mützel <markus.muetzel@gmx.de>
parents: 26376
diff changeset
74 fig_file_version = isfield (hg, hgs);
27705
6c2a56c39c5d hgload.m: Small changes for Octave coding conventions.
Rik <rik@octave.org>
parents: 27704
diff changeset
75 if (nnz (fig_file_version) != 1)
18581
70cff922a42d hgload.m: Change wording of error message for more clarity.
Rik <rik@octave.org>
parents: 18580
diff changeset
76 error ("hgload: could not load hgsave-formatted object in file %s", filename);
25973
c9ae077dedd1 New function openfig.m (bug #44670)
Guillaume Flandin <guillaume.offline@gmail.com>
parents: 25054
diff changeset
77 endif
27705
6c2a56c39c5d hgload.m: Small changes for Octave coding conventions.
Rik <rik@octave.org>
parents: 27704
diff changeset
78 hg = hg.(hgs{fig_file_version});
18580
13c80c3e9660 Add new functions hgsave and hgload (bug #39532).
Massimiliano Fasi <mogrob.sanit@gmail.com> and Rik <rik@octave.org>
parents:
diff changeset
79
25989
0ab70de0348e Allow loading and saving of multiple graphic handles in a single file (bug #54924).
Guillaume Flandin <guillaume.offline@gmail.com>
parents: 25975
diff changeset
80 ## Override properties of top-level objects
0ab70de0348e Allow loading and saving of multiple graphic handles in a single file (bug #54924).
Guillaume Flandin <guillaume.offline@gmail.com>
parents: 25975
diff changeset
81 calc_old_prop = false;
0ab70de0348e Allow loading and saving of multiple graphic handles in a single file (bug #54924).
Guillaume Flandin <guillaume.offline@gmail.com>
parents: 25975
diff changeset
82 if (isargout (2))
0ab70de0348e Allow loading and saving of multiple graphic handles in a single file (bug #54924).
Guillaume Flandin <guillaume.offline@gmail.com>
parents: 25975
diff changeset
83 calc_old_prop = true;
0ab70de0348e Allow loading and saving of multiple graphic handles in a single file (bug #54924).
Guillaume Flandin <guillaume.offline@gmail.com>
parents: 25975
diff changeset
84 old_prop = repmat ({[]}, 1, numel (hg));
0ab70de0348e Allow loading and saving of multiple graphic handles in a single file (bug #54924).
Guillaume Flandin <guillaume.offline@gmail.com>
parents: 25975
diff changeset
85 endif
25973
c9ae077dedd1 New function openfig.m (bug #44670)
Guillaume Flandin <guillaume.offline@gmail.com>
parents: 25054
diff changeset
86 fn_new = fieldnames (prop_struct);
25989
0ab70de0348e Allow loading and saving of multiple graphic handles in a single file (bug #54924).
Guillaume Flandin <guillaume.offline@gmail.com>
parents: 25975
diff changeset
87 if (! isempty (fn_new))
0ab70de0348e Allow loading and saving of multiple graphic handles in a single file (bug #54924).
Guillaume Flandin <guillaume.offline@gmail.com>
parents: 25975
diff changeset
88 for i = 1:numel (hg)
0ab70de0348e Allow loading and saving of multiple graphic handles in a single file (bug #54924).
Guillaume Flandin <guillaume.offline@gmail.com>
parents: 25975
diff changeset
89 fn_old = fieldnames (hg(i).properties);
0ab70de0348e Allow loading and saving of multiple graphic handles in a single file (bug #54924).
Guillaume Flandin <guillaume.offline@gmail.com>
parents: 25975
diff changeset
90 for j = 1:numel (fn_new)
0ab70de0348e Allow loading and saving of multiple graphic handles in a single file (bug #54924).
Guillaume Flandin <guillaume.offline@gmail.com>
parents: 25975
diff changeset
91 idx = ismember (tolower (fn_old), tolower (fn_new{j}));
0ab70de0348e Allow loading and saving of multiple graphic handles in a single file (bug #54924).
Guillaume Flandin <guillaume.offline@gmail.com>
parents: 25975
diff changeset
92 if (any (idx))
0ab70de0348e Allow loading and saving of multiple graphic handles in a single file (bug #54924).
Guillaume Flandin <guillaume.offline@gmail.com>
parents: 25975
diff changeset
93 if (calc_old_prop)
0ab70de0348e Allow loading and saving of multiple graphic handles in a single file (bug #54924).
Guillaume Flandin <guillaume.offline@gmail.com>
parents: 25975
diff changeset
94 old_prop{i}.(fn_new{j}) = hg(i).properties.(fn_old{idx});
0ab70de0348e Allow loading and saving of multiple graphic handles in a single file (bug #54924).
Guillaume Flandin <guillaume.offline@gmail.com>
parents: 25975
diff changeset
95 endif
0ab70de0348e Allow loading and saving of multiple graphic handles in a single file (bug #54924).
Guillaume Flandin <guillaume.offline@gmail.com>
parents: 25975
diff changeset
96 hg(i).properties.(fn_old{idx}) = prop_struct.(fn_new{j});
0ab70de0348e Allow loading and saving of multiple graphic handles in a single file (bug #54924).
Guillaume Flandin <guillaume.offline@gmail.com>
parents: 25975
diff changeset
97 endif
0ab70de0348e Allow loading and saving of multiple graphic handles in a single file (bug #54924).
Guillaume Flandin <guillaume.offline@gmail.com>
parents: 25975
diff changeset
98 endfor
0ab70de0348e Allow loading and saving of multiple graphic handles in a single file (bug #54924).
Guillaume Flandin <guillaume.offline@gmail.com>
parents: 25975
diff changeset
99 endfor
0ab70de0348e Allow loading and saving of multiple graphic handles in a single file (bug #54924).
Guillaume Flandin <guillaume.offline@gmail.com>
parents: 25975
diff changeset
100 endif
27705
6c2a56c39c5d hgload.m: Small changes for Octave coding conventions.
Rik <rik@octave.org>
parents: 27704
diff changeset
101
25973
c9ae077dedd1 New function openfig.m (bug #44670)
Guillaume Flandin <guillaume.offline@gmail.com>
parents: 25054
diff changeset
102 ## Build the graphics handle object
25989
0ab70de0348e Allow loading and saving of multiple graphic handles in a single file (bug #54924).
Guillaume Flandin <guillaume.offline@gmail.com>
parents: 25975
diff changeset
103 h = zeros (1, numel (hg));
0ab70de0348e Allow loading and saving of multiple graphic handles in a single file (bug #54924).
Guillaume Flandin <guillaume.offline@gmail.com>
parents: 25975
diff changeset
104 for i = 1:numel (hg)
0ab70de0348e Allow loading and saving of multiple graphic handles in a single file (bug #54924).
Guillaume Flandin <guillaume.offline@gmail.com>
parents: 25975
diff changeset
105 h(i) = struct2hdl (hg(i));
0ab70de0348e Allow loading and saving of multiple graphic handles in a single file (bug #54924).
Guillaume Flandin <guillaume.offline@gmail.com>
parents: 25975
diff changeset
106 endfor
19597
db92e7e28e1f strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 18679
diff changeset
107
18580
13c80c3e9660 Add new functions hgsave and hgload (bug #39532).
Massimiliano Fasi <mogrob.sanit@gmail.com> and Rik <rik@octave.org>
parents:
diff changeset
108 endfunction
13c80c3e9660 Add new functions hgsave and hgload (bug #39532).
Massimiliano Fasi <mogrob.sanit@gmail.com> and Rik <rik@octave.org>
parents:
diff changeset
109
13c80c3e9660 Add new functions hgsave and hgload (bug #39532).
Massimiliano Fasi <mogrob.sanit@gmail.com> and Rik <rik@octave.org>
parents:
diff changeset
110
13c80c3e9660 Add new functions hgsave and hgload (bug #39532).
Massimiliano Fasi <mogrob.sanit@gmail.com> and Rik <rik@octave.org>
parents:
diff changeset
111 ## Functional test for hgload/hgsave pair is in hgsave.m
13c80c3e9660 Add new functions hgsave and hgload (bug #39532).
Massimiliano Fasi <mogrob.sanit@gmail.com> and Rik <rik@octave.org>
parents:
diff changeset
112
25989
0ab70de0348e Allow loading and saving of multiple graphic handles in a single file (bug #54924).
Guillaume Flandin <guillaume.offline@gmail.com>
parents: 25975
diff changeset
113 ## Test overriding saved properties with second input
25973
c9ae077dedd1 New function openfig.m (bug #44670)
Guillaume Flandin <guillaume.offline@gmail.com>
parents: 25054
diff changeset
114 %!test
c9ae077dedd1 New function openfig.m (bug #44670)
Guillaume Flandin <guillaume.offline@gmail.com>
parents: 25054
diff changeset
115 %! unwind_protect
25989
0ab70de0348e Allow loading and saving of multiple graphic handles in a single file (bug #54924).
Guillaume Flandin <guillaume.offline@gmail.com>
parents: 25975
diff changeset
116 %! h1 = figure ("visible", "off");
0ab70de0348e Allow loading and saving of multiple graphic handles in a single file (bug #54924).
Guillaume Flandin <guillaume.offline@gmail.com>
parents: 25975
diff changeset
117 %! col = get (h1, "color");
25973
c9ae077dedd1 New function openfig.m (bug #44670)
Guillaume Flandin <guillaume.offline@gmail.com>
parents: 25054
diff changeset
118 %! ftmp = [tempname() ".ofig"];
c9ae077dedd1 New function openfig.m (bug #44670)
Guillaume Flandin <guillaume.offline@gmail.com>
parents: 25054
diff changeset
119 %! hgsave (h1, ftmp);
c9ae077dedd1 New function openfig.m (bug #44670)
Guillaume Flandin <guillaume.offline@gmail.com>
parents: 25054
diff changeset
120 %! close (h1);
c9ae077dedd1 New function openfig.m (bug #44670)
Guillaume Flandin <guillaume.offline@gmail.com>
parents: 25054
diff changeset
121 %! [h2, old] = hgload (ftmp);
c9ae077dedd1 New function openfig.m (bug #44670)
Guillaume Flandin <guillaume.offline@gmail.com>
parents: 25054
diff changeset
122 %! assert (old, {[]});
25989
0ab70de0348e Allow loading and saving of multiple graphic handles in a single file (bug #54924).
Guillaume Flandin <guillaume.offline@gmail.com>
parents: 25975
diff changeset
123 %! [h3, old] = hgload (ftmp, struct ("color", [1 0 0]));
0ab70de0348e Allow loading and saving of multiple graphic handles in a single file (bug #54924).
Guillaume Flandin <guillaume.offline@gmail.com>
parents: 25975
diff changeset
124 %! assert (get (h3, "color"), [1 0 0]);
25973
c9ae077dedd1 New function openfig.m (bug #44670)
Guillaume Flandin <guillaume.offline@gmail.com>
parents: 25054
diff changeset
125 %! assert (iscell (old) && numel (old) == 1);
25989
0ab70de0348e Allow loading and saving of multiple graphic handles in a single file (bug #54924).
Guillaume Flandin <guillaume.offline@gmail.com>
parents: 25975
diff changeset
126 %! assert (isstruct (old{1}) && isfield (old{1}, "color"));
0ab70de0348e Allow loading and saving of multiple graphic handles in a single file (bug #54924).
Guillaume Flandin <guillaume.offline@gmail.com>
parents: 25975
diff changeset
127 %! assert (old{1}.color, col);
25973
c9ae077dedd1 New function openfig.m (bug #44670)
Guillaume Flandin <guillaume.offline@gmail.com>
parents: 25054
diff changeset
128 %! unwind_protect_cleanup
c9ae077dedd1 New function openfig.m (bug #44670)
Guillaume Flandin <guillaume.offline@gmail.com>
parents: 25054
diff changeset
129 %! unlink (ftmp);
c9ae077dedd1 New function openfig.m (bug #44670)
Guillaume Flandin <guillaume.offline@gmail.com>
parents: 25054
diff changeset
130 %! try, close (h1); end_try_catch
c9ae077dedd1 New function openfig.m (bug #44670)
Guillaume Flandin <guillaume.offline@gmail.com>
parents: 25054
diff changeset
131 %! try, close (h2); end_try_catch
c9ae077dedd1 New function openfig.m (bug #44670)
Guillaume Flandin <guillaume.offline@gmail.com>
parents: 25054
diff changeset
132 %! try, close (h3); end_try_catch
c9ae077dedd1 New function openfig.m (bug #44670)
Guillaume Flandin <guillaume.offline@gmail.com>
parents: 25054
diff changeset
133 %! end_unwind_protect
25989
0ab70de0348e Allow loading and saving of multiple graphic handles in a single file (bug #54924).
Guillaume Flandin <guillaume.offline@gmail.com>
parents: 25975
diff changeset
134
0ab70de0348e Allow loading and saving of multiple graphic handles in a single file (bug #54924).
Guillaume Flandin <guillaume.offline@gmail.com>
parents: 25975
diff changeset
135 ## Test input validation
28896
90fea9cc9caa test: Add expected error message <Invalid call> to BIST tests for nargin.
Rik <rik@octave.org>
parents: 28789
diff changeset
136 %!error <Invalid call> hgload ()
25989
0ab70de0348e Allow loading and saving of multiple graphic handles in a single file (bug #54924).
Guillaume Flandin <guillaume.offline@gmail.com>
parents: 25975
diff changeset
137 %!error <PROP_STRUCT must be a struct> hgload (1, {})
0ab70de0348e Allow loading and saving of multiple graphic handles in a single file (bug #54924).
Guillaume Flandin <guillaume.offline@gmail.com>
parents: 25975
diff changeset
138 %!error <unable to locate file> hgload ("%%_A_REALLY_UNLIKELY_FILENAME_%%")
0ab70de0348e Allow loading and saving of multiple graphic handles in a single file (bug #54924).
Guillaume Flandin <guillaume.offline@gmail.com>
parents: 25975
diff changeset
139 %!error <unable to locate file> hgload ("%%_A_REALLY_UNLIKELY_FILENAME_%%.fig")