tomwalters@0
|
1 % procedure for 'aim-mat'
|
tomwalters@0
|
2 %
|
tomwalters@0
|
3 % INPUT VALUES:
|
tomwalters@0
|
4 %
|
tomwalters@0
|
5 % RETURN VALUE:
|
tomwalters@0
|
6 %
|
tomwalters@0
|
7 % mix the parts of old_struct with the parts of add_struct
|
tomwalters@0
|
8 % old entries in old_struct with identical names are overwritten with the entries
|
tomwalters@0
|
9 % from add_struct
|
tomwalters@0
|
10 % works recursive up to the second layer
|
tomwalters@0
|
11 %
|
bleeck@3
|
12 %
|
tomwalters@0
|
13 % (c) 2011, University of Southampton
|
bleeck@3
|
14 % Maintained by Stefan Bleeck (bleeck@gmail.com)
|
bleeck@3
|
15 % download of current version is on the soundsoftware site:
|
bleeck@3
|
16 % http://code.soundsoftware.ac.uk/projects/aimmat
|
bleeck@3
|
17 % documentation and everything is on http://www.acousticscale.org
|
bleeck@3
|
18
|
bleeck@3
|
19
|
tomwalters@0
|
20
|
tomwalters@0
|
21
|
tomwalters@0
|
22
|
tomwalters@0
|
23 function [new_struct,conflicts]=mixstruct(old_struct,add_struct)
|
tomwalters@0
|
24 % old_struct is the original structure
|
tomwalters@0
|
25 % add_struct is the new struct, that can have new options
|
tomwalters@0
|
26 % a warning is given, if a module doesnt exist any more
|
tomwalters@0
|
27 % and these options are removed from the parameter file.
|
tomwalters@0
|
28 %
|
tomwalters@0
|
29 % new parameters are added to the old parameters for each module
|
tomwalters@0
|
30
|
tomwalters@0
|
31
|
tomwalters@0
|
32 conflicts=[];
|
tomwalters@0
|
33 conflict_counter=1;
|
tomwalters@0
|
34
|
tomwalters@0
|
35 newcolumns=fieldnames(add_struct);
|
tomwalters@0
|
36
|
tomwalters@0
|
37 new_struct=old_struct;
|
tomwalters@0
|
38
|
tomwalters@0
|
39 for i=1:length(newcolumns)
|
tomwalters@0
|
40 curr_col=newcolumns{i};
|
tomwalters@0
|
41 if ~strcmp(curr_col,'signal')
|
tomwalters@0
|
42 if ~isfield(old_struct,curr_col) % add whole new fields from the new struct
|
tomwalters@0
|
43 est=sprintf('new_struct.%s=add_struct.%s;',curr_col,curr_col);
|
tomwalters@0
|
44 eval(est);
|
tomwalters@0
|
45 else % its already there, but not neccessarily up to date
|
tomwalters@0
|
46 eval(sprintf('old_columns=old_struct.%s;',curr_col));
|
tomwalters@0
|
47 eval(sprintf('new_columns=add_struct.%s;',curr_col));
|
tomwalters@0
|
48 old_modules=fieldnames(old_columns);
|
tomwalters@0
|
49 new_modules=fieldnames(new_columns);
|
tomwalters@0
|
50
|
tomwalters@0
|
51
|
tomwalters@0
|
52 for j=1:length(new_modules)
|
tomwalters@0
|
53 if ~isfield(old_columns,new_modules{j}) % add whole new module
|
tomwalters@0
|
54 est=sprintf('new_struct.%s.%s=new_columns.%s;',curr_col,new_modules{j},new_modules{j});
|
tomwalters@0
|
55 eval(est);
|
tomwalters@0
|
56 constr=sprintf('conflicts{%d}=''new module added: %s %s'';',conflict_counter,newcolumns{i},new_modules{j});
|
tomwalters@0
|
57 eval(constr);conflict_counter=conflict_counter+1;
|
tomwalters@0
|
58 else % both are there, but check the versions
|
tomwalters@0
|
59 if ~strcmp(newcolumns{i},'signal') && ~strcmp(newcolumns{i},'graphics')
|
tomwalters@0
|
60 ver1str=sprintf('ver1=old_struct.%s.%s.revision;',newcolumns{i},new_modules{j});
|
tomwalters@0
|
61 try % old version
|
tomwalters@0
|
62 eval(ver1str);
|
tomwalters@0
|
63 ver11=ver2num(ver1);
|
tomwalters@0
|
64 catch
|
tomwalters@0
|
65 constr=sprintf('conflicts{%d}=''old module had no revision number: module: %s.%s'';',conflict_counter,newcolumns{i},new_modules{j});
|
tomwalters@0
|
66 eval(constr);conflict_counter=conflict_counter+1;
|
tomwalters@0
|
67 % ver11='no version';
|
tomwalters@0
|
68 ver11=-1;
|
tomwalters@0
|
69 %ver12=-1;
|
tomwalters@0
|
70 end
|
tomwalters@0
|
71 ver2str=sprintf('ver2=add_struct.%s.%s.revision;',newcolumns{i},new_modules{j});
|
tomwalters@0
|
72 try % new version
|
tomwalters@0
|
73 eval(ver2str);
|
tomwalters@0
|
74 ver21=ver2num(ver2);
|
tomwalters@0
|
75 catch
|
tomwalters@0
|
76 ver2='no version';
|
tomwalters@0
|
77 constr=sprintf('conflicts{%d}=''loaded newer version on module: %s.%s (current version: no version)'';',conflict_counter,newcolumns{i},new_modules{j});
|
tomwalters@0
|
78 eval(constr);conflict_counter=conflict_counter+1;
|
tomwalters@0
|
79 end
|
tomwalters@0
|
80 % if isnumeric(ver11) && isnumeric(ver12) && isnumeric(ver21) && isnumeric(ver22)
|
tomwalters@0
|
81 if ver21>ver11 %|| (ver21==ver11 && ver22>ver12)
|
tomwalters@0
|
82 constr=sprintf('conflicts{%d}=''module %s.%s loaded with higher version number (old: %d.%d new: %d.%d)'';',conflict_counter,newcolumns{i},new_modules{j},ver11,ver12,ver21,ver22);
|
tomwalters@0
|
83 eval(constr);conflict_counter=conflict_counter+1;
|
tomwalters@0
|
84 end
|
tomwalters@0
|
85 if ver21<ver11 %|| (ver21==ver11 && ver22<ver12)
|
tomwalters@0
|
86 constr=sprintf('conflicts{%d}=''module %s.%s loaded with lower version number (old: %d.%d new: %d.%d)'';',conflict_counter,newcolumns{i},new_modules{j},ver11,ver12,ver21,ver22);
|
tomwalters@0
|
87 % constr=sprintf('conflicts{%d}=''module loaded with lower version number: module: %s.%s revision %d.%d (current version: %d.%d )'';',conflict_counter,newcolumns{i},new_modules{j},ver11,ver12,ver21,ver22);
|
tomwalters@0
|
88 eval(constr);conflict_counter=conflict_counter+1;
|
tomwalters@0
|
89 end
|
tomwalters@0
|
90 if ver21==ver11 % && ver22==ver12
|
tomwalters@0
|
91 % constr=sprintf('conflicts{%d}=''no conflict: module: %s.%s revision %d.%d '';',conflict_counter,newcolumns{i},new_modules{j},ver11,ver12);
|
tomwalters@0
|
92 % eval(constr);conflict_counter=conflict_counter+1;
|
tomwalters@0
|
93 end
|
tomwalters@0
|
94 end
|
tomwalters@0
|
95 % end
|
tomwalters@0
|
96 end
|
tomwalters@0
|
97 % next to version checking is checking all parameters. If new
|
tomwalters@0
|
98 % ones are there, add them!
|
tomwalters@0
|
99 % but only, if the module is already there
|
tomwalters@0
|
100 if isfield(old_columns,new_modules{j})
|
tomwalters@0
|
101 oldstr=sprintf('old_parameter=old_columns.%s;',new_modules{j});
|
tomwalters@0
|
102 eval(oldstr);
|
tomwalters@0
|
103 newstr=sprintf('new_parameter=fieldnames(new_columns.%s);',new_modules{j});
|
tomwalters@0
|
104 eval(newstr);
|
tomwalters@0
|
105 for k=1:length(new_parameter)
|
tomwalters@0
|
106 if ~isfield(old_parameter,new_parameter{k})
|
tomwalters@0
|
107 addstr=sprintf('new_struct.%s.%s.%s=add_struct.%s.%s.%s;',newcolumns{i},new_modules{j},new_parameter{k},newcolumns{i},new_modules{j},new_parameter{k});
|
tomwalters@0
|
108 eval(addstr);
|
tomwalters@0
|
109 valstr=sprintf('value=new_struct.%s.%s.%s;',newcolumns{i},new_modules{j},new_parameter{k});
|
tomwalters@0
|
110 eval(valstr);
|
tomwalters@0
|
111 if isnumeric(value)
|
tomwalters@0
|
112 value=num2str(value);
|
tomwalters@0
|
113 end
|
tomwalters@0
|
114 constr=sprintf('conflicts{%d}=''new parameter added to the module: %s.%s : %s=%s'';',conflict_counter,newcolumns{i},new_modules{j},new_parameter{k},value);
|
tomwalters@0
|
115 eval(constr);conflict_counter=conflict_counter+1;
|
tomwalters@0
|
116 end
|
tomwalters@0
|
117 end
|
tomwalters@0
|
118 end
|
tomwalters@0
|
119 end
|
tomwalters@0
|
120 end
|
tomwalters@0
|
121 % look for modules that have gone. These are not taken into
|
tomwalters@0
|
122 % consideration any more and deleted from the options
|
tomwalters@0
|
123 for j=1:length(old_modules)
|
tomwalters@0
|
124 if ~isfield(new_columns,old_modules{j}) % add whole new module
|
tomwalters@0
|
125 constr=sprintf('conflicts{%d}=''module was deleted: %s %s'';',conflict_counter,newcolumns{i},old_modules{j});
|
tomwalters@0
|
126 eval(constr);conflict_counter=conflict_counter+1;
|
tomwalters@0
|
127 rmstr=sprintf('new_struct.%s=rmfield(new_struct.%s,''%s'');',newcolumns{i},newcolumns{i},old_modules{j});
|
tomwalters@0
|
128 eval(rmstr);
|
tomwalters@0
|
129 end
|
tomwalters@0
|
130 end
|
tomwalters@0
|
131 end
|
tomwalters@0
|
132 end
|
tomwalters@0
|
133
|
tomwalters@0
|
134 function vernum=ver2num(ver)
|
tomwalters@0
|
135 % ver now comes in the format: '$Revision: 585 $'
|
tomwalters@0
|
136 % not 'Revision: 1.2', so there's now no dot
|
tomwalters@0
|
137 wherecolon=strfind(ver,':');
|
tomwalters@0
|
138 wheredollar=strfind(ver,'$');
|
tomwalters@0
|
139 wheredollar=wheredollar(2);
|
tomwalters@0
|
140 %wheredot=strfind(ver,'.');
|
tomwalters@0
|
141 vernum=str2num(ver(wherecolon+1:wheredollar-2));
|
tomwalters@0
|
142 %ver2=str2num(ver(wheredot+1:end-1));
|
tomwalters@0
|
143 if ~isnumeric(vernum)
|
tomwalters@0
|
144 vernum=-1;
|
tomwalters@0
|
145 end
|
tomwalters@0
|
146 %if ~isnumeric(ver2)
|
tomwalters@0
|
147 % ver2=-1;
|
tomwalters@0
|
148 %end
|
tomwalters@0
|
149
|
tomwalters@0
|
150
|