comparison m-toolbox/classes/@fsdata/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.11 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 obj_struct.t0 = time(0);
35
36 if isempty(obj_struct.navs)
37 obj_struct.navs = NaN;
38 end
39
40 if isempty(obj_struct.fs)
41 obj_struct.fs = NaN;
42 end
43
44 if isempty(obj_struct.enbw)
45 obj_struct.enbw = NaN;
46 end
47
48
49 catch ME
50 disp(varargin{1});
51 throw(addCause(ME, MException('MATLAB:LTPDA','### The struct (fsdata) above is not from version 1.0')));
52 end
53
54 struct_ver = '1.9.1';
55 end
56
57 %%%%%%%%%%%%%%%%%%%%%%% Update version '1.9.1' ->'1.9.2' %%%%%%%%%%%%%%%%%%%%%%%
58
59 if utils.helper.ver2num(struct_ver) < utils.helper.ver2num(tbx_ver) && ...
60 strcmp(struct_ver, '1.9.1')
61
62 %%% update xunits
63 if ~isa(obj_struct.xunits, 'unit')
64 % Make sure we have strings for the units
65 obj_struct.xunits = char(obj_struct.xunits);
66
67 % Set default value ('empty') in 1.9.1 to an empty string to avoid warnings.
68 if strcmp(obj_struct.xunits, 'empty')
69 obj_struct.xunits = '';
70 end
71
72 % We need to fix any strange old units
73
74 %- /\surdHz -> Hz^-0.5
75 obj_struct.xunits = strrep(obj_struct.xunits, '/\surdHz', 'Hz^-0.5');
76 obj_struct.xunits = strrep(obj_struct.xunits, '/Hz', 'Hz^-1');
77 obj_struct.xunits = strrep(obj_struct.xunits, 'N/A', 'arb');
78 obj_struct.xunits = strrep(obj_struct.xunits, 'Arb', 'arb');
79 obj_struct.xunits = strrep(obj_struct.xunits, 'Hz', ' Hz^-1');
80
81 % Check X units
82 try
83 uo = unit(obj_struct.xunits);
84 catch
85 warning('!!! This file contains a fsdata object with unsupported x-units [%s]. Setting to empty.', obj_struct.xunits);
86 obj_struct.xunits = '';
87 end
88 end
89
90 %%% update yunits
91 if ~isa(obj_struct.yunits, 'unit')
92 % Make sure we have strings for the units
93 obj_struct.yunits = char(obj_struct.yunits);
94
95 % Set default value ('empty') in 1.9.1 to an empty string to avoid warnings.
96 if strcmp(obj_struct.yunits, 'empty')
97 obj_struct.yunits = '';
98 end
99
100 % We need to fix any strange old units
101
102 %- /\surdHz -> Hz^-0.5
103 obj_struct.yunits = strrep(obj_struct.yunits, '/\surdHz', 'Hz^-0.5');
104 obj_struct.yunits = strrep(obj_struct.yunits, '/Hz', 'Hz^-1');
105 obj_struct.yunits = strrep(obj_struct.yunits, 'N/A', 'arb');
106 obj_struct.yunits = strrep(obj_struct.yunits, 'Arb', 'arb');
107 obj_struct.yunits = strrep(obj_struct.yunits, 'Hz', ' Hz^-1');
108
109 % Check Y units
110 try
111 uo = unit(obj_struct.yunits);
112 catch
113 warning('!!! This file contains a fsdata object with unsupported y-units [%s]. Setting to empty.', obj_struct.yunits);
114 obj_struct.yunits = '';
115 end
116 end
117
118 struct_ver = '1.9.2';
119 end
120
121 %%%%%%%%%%%%%%%%%%%%%%% Update version '1.9.2' ->'1.9.3' %%%%%%%%%%%%%%%%%%%%%%%
122
123 if utils.helper.ver2num(struct_ver) < utils.helper.ver2num(tbx_ver) && ...
124 strcmp(struct_ver, '1.9.2')
125
126 struct_ver = '1.9.3';
127 end
128
129 %%%%%%%%%%%%%%%%%%%%%%% Update version '1.9.3' ->'1.9.4' %%%%%%%%%%%%%%%%%%%%%%%
130
131 if utils.helper.ver2num(struct_ver) < utils.helper.ver2num(tbx_ver) && ...
132 strcmp(struct_ver, '1.9.3')
133
134 struct_ver = '1.9.4';
135 end
136
137 %%%%%%%%%%%%%%%%%%%%%%% Update version '1.9.4' ->'2.0' %%%%%%%%%%%%%%%%%%%%%%%
138
139 if utils.helper.ver2num(struct_ver) < utils.helper.ver2num(tbx_ver) && ...
140 strcmp(struct_ver, '1.9.4')
141
142 struct_ver = '2.0';
143 end
144
145 %%%%%%%%%%%%%%%%%%%%%%% Update version '2.0' ->'2.0.1' %%%%%%%%%%%%%%%%%%%%%%%
146
147 if utils.helper.ver2num(struct_ver) < utils.helper.ver2num(tbx_ver) && ...
148 strcmp(struct_ver, '2.0')
149
150 struct_ver = '2.0.1';
151 end
152
153 %%%%%%%%%%%%%%%%%%%%%%% Update version '2.0.1' ->'2.1' %%%%%%%%%%%%%%%%%%%%%%%
154
155 if utils.helper.ver2num(struct_ver) < utils.helper.ver2num(tbx_ver) && ...
156 strcmp(struct_ver, '2.0.1')
157
158 struct_ver = '2.1';
159 end
160
161 varargout{1} = obj_struct;
162 end
163