comparison m-toolbox/classes/@xyzdata/update_struct.m @ 0:f0afece42f48

Import.
author Daniele Nicolodi <nicolodi@science.unitn.it>
date Wed, 23 Nov 2011 19:22:13 +0100
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:f0afece42f48
1 % UPDATE_STRUCT update the input structure to the current ltpda version
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3 %
4 % FUNCTION: update_struct
5 %
6 % DESCRIPTION: UPDATE_STRUCT update the input structure to the current
7 % ltpda version
8 %
9 % CALL: obj_struct = update_struct(obj_struct, version_str);
10 %
11 % VERSION: $Id: update_struct.m,v 1.8 2011/03/28 18:04:44 ingo Exp $
12 %
13 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
14
15 function varargout = update_struct(varargin)
16
17 obj_struct = varargin{1};
18 struct_ver = varargin{2};
19
20 % get the version of the current toolbox
21 tbx_ver = strtok(getappdata(0, 'ltpda_version'));
22
23 % get only the version string without the MATLAB version
24 struct_ver = strtok(struct_ver);
25
26 %%%%%%%%%%%%%%%%%%%%%%% Update version '1.0 -> 1.9.1' %%%%%%%%%%%%%%%%%%%%%%%
27
28 if utils.helper.ver2num(struct_ver) < utils.helper.ver2num(tbx_ver) && ...
29 strcmp(struct_ver, '1.0')
30
31 try
32 % obj_struct = rmfield(obj_struct, 'name');
33 % obj_struct = rmfield(obj_struct, 'created');
34 catch ME
35 disp(varargin{1});
36 throw(addCause(ME, MException('MATLAB:LTPDA','### The struct (fsdata) above is not from version 1.0')));
37 end
38
39 struct_ver = '1.9.1';
40 end
41
42 %%%%%%%%%%%%%%%%%%%%%%% Update version '1.9.1' ->'1.9.2' %%%%%%%%%%%%%%%%%%%%%%%
43
44 if utils.helper.ver2num(struct_ver) < utils.helper.ver2num(tbx_ver) && ...
45 strcmp(struct_ver, '1.9.1')
46
47 %%% update xunits
48 if ~isa(obj_struct.xunits, 'unit')
49 % Make sure we have strings for the units
50 obj_struct.xunits = char(obj_struct.xunits);
51
52 % Set default value ('empty') in 1.9.1 to an empty string to avoid warnings.
53 if strcmp(obj_struct.xunits, 'empty')
54 obj_struct.xunits = '';
55 end
56
57 % We need to fix any strange old units
58
59 %- /\surdHz -> Hz^-0.5
60 obj_struct.xunits = strrep(obj_struct.xunits, '/\surdHz', 'Hz^-0.5');
61 obj_struct.xunits = strrep(obj_struct.xunits, '/Hz', 'Hz^-1');
62 obj_struct.xunits = strrep(obj_struct.xunits, 'N/A', 'arb');
63 obj_struct.xunits = strrep(obj_struct.xunits, 'Arb', 'arb');
64 obj_struct.xunits = strrep(obj_struct.xunits, 'Hz', ' Hz^-1');
65
66 % Check X units
67 try
68 uo = unit(obj_struct.xunits);
69 catch
70 warning('!!! This file contains a fsdata object with unsupported x-units [%s]. Setting to empty.', obj_struct.xunits);
71 obj_struct.xunits = '';
72 end
73 end
74
75 %%% update yunits
76 if ~isa(obj_struct.yunits, 'unit')
77 % Make sure we have strings for the units
78 obj_struct.yunits = char(obj_struct.yunits);
79
80 % Set default value ('empty') in 1.9.1 to an empty string to avoid warnings.
81 if strcmp(obj_struct.yunits, 'empty')
82 obj_struct.yunits = '';
83 end
84
85 % We need to fix any strange old units
86
87 %- /\surdHz -> Hz^-0.5
88 obj_struct.yunits = strrep(obj_struct.yunits, '/\surdHz', 'Hz^-0.5');
89 obj_struct.yunits = strrep(obj_struct.yunits, '/Hz', 'Hz^-1');
90 obj_struct.yunits = strrep(obj_struct.yunits, 'N/A', 'arb');
91 obj_struct.yunits = strrep(obj_struct.yunits, 'Arb', 'arb');
92 obj_struct.yunits = strrep(obj_struct.yunits, 'Hz', ' Hz^-1');
93
94 % Check Y units
95 try
96 uo = unit(obj_struct.yunits);
97 catch
98 warning('!!! This file contains a fsdata object with unsupported y-units [%s]. Setting to empty.', obj_struct.yunits);
99 obj_struct.yunits = '';
100 end
101 end
102
103 %%% update zunits
104 if ~isa(obj_struct.zunits, 'unit')
105 % Make sure we have strings for the units
106 obj_struct.zunits = char(obj_struct.zunits);
107
108 % Set default value ('empty') in 1.9.1 to an empty string to avoid warnings.
109 if strcmp(obj_struct.zunits, 'empty')
110 obj_struct.zunits = '';
111 end
112
113 % We need to fix any strange old units
114
115 %- /\surdHz -> Hz^-0.5
116 obj_struct.zunits = strrep(obj_struct.zunits, '/\surdHz', 'Hz^-0.5');
117 obj_struct.zunits = strrep(obj_struct.zunits, '/Hz', 'Hz^-1');
118 obj_struct.zunits = strrep(obj_struct.zunits, 'N/A', 'arb');
119 obj_struct.zunits = strrep(obj_struct.zunits, 'Arb', 'arb');
120 obj_struct.zunits = strrep(obj_struct.zunits, 'Hz', ' Hz^-1');
121
122 % Check Y units
123 try
124 uo = unit(obj_struct.zunits);
125 catch
126 warning('!!! This file contains a fsdata object with unsupported y-units [%s]. Setting to empty.', obj_struct.zunits);
127 obj_struct.zunits = '';
128 end
129 end
130
131 struct_ver = '1.9.2';
132 end
133
134 %%%%%%%%%%%%%%%%%%%%%%% Update version '1.9.2' ->'1.9.3' %%%%%%%%%%%%%%%%%%%%%%%
135
136 if utils.helper.ver2num(struct_ver) < utils.helper.ver2num(tbx_ver) && ...
137 strcmp(struct_ver, '1.9.2')
138
139 struct_ver = '1.9.3';
140 end
141
142 %%%%%%%%%%%%%%%%%%%%%%% Update version '1.9.3' ->'1.9.4' %%%%%%%%%%%%%%%%%%%%%%%
143
144 if utils.helper.ver2num(struct_ver) < utils.helper.ver2num(tbx_ver) && ...
145 strcmp(struct_ver, '1.9.3')
146
147 struct_ver = '1.9.4';
148 end
149
150 %%%%%%%%%%%%%%%%%%%%%%% Update version '1.9.4' ->'2.0' %%%%%%%%%%%%%%%%%%%%%%%
151
152 if utils.helper.ver2num(struct_ver) < utils.helper.ver2num(tbx_ver) && ...
153 strcmp(struct_ver, '1.9.4')
154
155 struct_ver = '2.0';
156 end
157
158 %%%%%%%%%%%%%%%%%%%%%%% Update version '2.0' ->'2.0.1' %%%%%%%%%%%%%%%%%%%%%%%
159
160 if utils.helper.ver2num(struct_ver) < utils.helper.ver2num(tbx_ver) && ...
161 strcmp(struct_ver, '2.0')
162
163 struct_ver = '2.0.1';
164 end
165
166 %%%%%%%%%%%%%%%%%%%%%%% Update version '2.0.1' ->'2.1' %%%%%%%%%%%%%%%%%%%%%%%
167
168 if utils.helper.ver2num(struct_ver) < utils.helper.ver2num(tbx_ver) && ...
169 strcmp(struct_ver, '2.0.1')
170
171 struct_ver = '2.1';
172 end
173
174 varargout{1} = obj_struct;
175 end
176