comparison m-toolbox/classes/@xydata/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.9 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 obj_struct.xunits = strrep(obj_struct.xunits, 'N/A', 'arb');
59 obj_struct.xunits = strrep(obj_struct.xunits, 'Arb', 'arb');
60
61 % Check X units
62 try
63 uo = unit(obj_struct.xunits);
64 catch
65 warning('!!! This file contains a fsdata object with unsupported x-units [%s]. Setting to empty.', obj_struct.xunits);
66 obj_struct.xunits = '';
67 end
68 end
69
70 %%% update yunits
71 if ~isa(obj_struct.yunits, 'unit')
72 % Make sure we have strings for the units
73 obj_struct.yunits = char(obj_struct.yunits);
74
75 % Set default value ('empty') in 1.9.1 to an empty string to avoid warnings.
76 if strcmp(obj_struct.yunits, 'empty')
77 obj_struct.yunits = '';
78 end
79
80 % We need to fix any strange old units
81 obj_struct.yunits = strrep(obj_struct.yunits, 'N/A', 'arb');
82 obj_struct.yunits = strrep(obj_struct.yunits, 'Arb', 'arb');
83
84 % Check Y units
85 try
86 uo = unit(obj_struct.yunits);
87 catch
88 warning('!!! This file contains a fsdata object with unsupported y-units [%s]. Setting to empty.', obj_struct.yunits);
89 obj_struct.yunits = '';
90 end
91 end
92
93 struct_ver = '1.9.2';
94 end
95
96 %%%%%%%%%%%%%%%%%%%%%%% Update version '1.9.2' ->'1.9.3' %%%%%%%%%%%%%%%%%%%%%%%
97
98 if utils.helper.ver2num(struct_ver) < utils.helper.ver2num(tbx_ver) && ...
99 strcmp(struct_ver, '1.9.2')
100
101 struct_ver = '1.9.3';
102 end
103
104 %%%%%%%%%%%%%%%%%%%%%%% Update version '1.9.3' ->'1.9.4' %%%%%%%%%%%%%%%%%%%%%%%
105
106 if utils.helper.ver2num(struct_ver) < utils.helper.ver2num(tbx_ver) && ...
107 strcmp(struct_ver, '1.9.3')
108
109 struct_ver = '1.9.4';
110 end
111
112 %%%%%%%%%%%%%%%%%%%%%%% Update version '1.9.4' ->'2.0' %%%%%%%%%%%%%%%%%%%%%%%
113
114 if utils.helper.ver2num(struct_ver) < utils.helper.ver2num(tbx_ver) && ...
115 strcmp(struct_ver, '1.9.4')
116
117 struct_ver = '2.0';
118 end
119
120 %%%%%%%%%%%%%%%%%%%%%%% Update version '2.0' ->'2.0.1' %%%%%%%%%%%%%%%%%%%%%%%
121
122 if utils.helper.ver2num(struct_ver) < utils.helper.ver2num(tbx_ver) && ...
123 strcmp(struct_ver, '2.0')
124
125 struct_ver = '2.0.1';
126 end
127
128 %%%%%%%%%%%%%%%%%%%%%%% Update version '2.0.1' ->'2.1' %%%%%%%%%%%%%%%%%%%%%%%
129
130 if utils.helper.ver2num(struct_ver) < utils.helper.ver2num(tbx_ver) && ...
131 strcmp(struct_ver, '2.0.1')
132
133 struct_ver = '2.1';
134 end
135
136 varargout{1} = obj_struct;
137 end
138