-
Notifications
You must be signed in to change notification settings - Fork 0
/
phz_load.m
82 lines (71 loc) · 2.27 KB
/
phz_load.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
%PHZ_LOAD Load a PHZ structure (.phz or .mat file).
%
% USAGE
% PHZ = phz_load
% PHZ = phz_load(filename)
%
% INPUT
% (none) = A file browser will popup to select a file.
%
% filename = [string] Filename (and path) of file to load.
%
% OUTPUT
% PHZ = [struct] PHZLAB data structure.
%
% EXAMPLES
% PHZ = phz_load >> Browse computer to select a file to load.
%
% PHZ = phz_load('myfile.phz') >> Loads the file 'myfile.phz' from the
% current directory.
%
% PHZ = phz_load('myfolder/myfile.phz') >> Loads the file 'myfile.phz'
% from the folder 'myfolder'.
% Copyright (C) 2018 Gabriel A. Nespoli, gabenespoli@gmail.com
%
% This program is free software: you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation, either version 3 of the License, or
% (at your option) any later version.
%
% This program is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with this program. If not, see http://www.gnu.org/licenses/.
function PHZ = phz_load(varargin)
if nargout == 0 && nargin == 0, help phz_load, return, end
% get filename if none given
if nargin == 0
[filename,pathname] = uigetfile({'*.phz','PHZ-files (*.phz)';'*.mat','MAT-files (*.mat)'},'Select a PHZ file to load...');
if filename == 0, return, end
filename = fullfile(pathname,filename);
else
[pathname,filename,ext] = fileparts(varargin{1});
filename = fullfile(pathname,[filename,ext]);
end
% parse input
if nargin > 1
verbose = varargin{2};
else
verbose = false;
end
if ~exist(filename,'file'), error('File doesn''t exist.'), end
% load file
S = load(filename,'-mat');
name = fieldnames(S);
i = 1;
badFile = true;
while badFile
if i > length(name), rethrow(me), end %#ok<NODEF>
try
PHZ = S.(name{i});
PHZ = phz_check(PHZ,verbose);
badFile = false;
catch me %#ok<NASGU>
i = i + 1;
end
end
PHZ = phz_history(PHZ,['Loaded variable ''',name{i},''' from ''',filename,'''.'],0);
end