annotate aim-mat/tools/mixstruct.m @ 4:537f939baef0 tip

various bug fixes and changed copyright message
author Stefan Bleeck <bleeck@gmail.com>
date Tue, 16 Aug 2011 14:37:17 +0100
parents 20ada0af3d7d
children
rev   line source
tomwalters@0 1 % support file for 'aim-mat'
tomwalters@0 2 %
tomwalters@0 3 % This external file is included as part of the 'aim-mat' distribution package
bleeck@3 4 % (c) 2011, University of Southampton
bleeck@3 5 % Maintained by Stefan Bleeck (bleeck@gmail.com)
bleeck@3 6 % download of current version is on the soundsoftware site:
bleeck@3 7 % http://code.soundsoftware.ac.uk/projects/aimmat
bleeck@3 8 % documentation and everything is on http://www.acousticscale.org
tomwalters@0 9
tomwalters@0 10
tomwalters@0 11 function new_struct=mixstruct(old_struct,add_struct)
tomwalters@0 12 % old_struct is the original structure
tomwalters@0 13 % add_struct is the new struct
tomwalters@0 14 % entries that are double are overwritten by the entry in add_struct
tomwalters@0 15 % works only for the first recursion level
tomwalters@0 16
tomwalters@0 17
tomwalters@0 18 newstructs=fieldnames(add_struct);
tomwalters@0 19 % copy all old stuff
tomwalters@0 20 new_struct=old_struct;
tomwalters@0 21
tomwalters@0 22 for i=1:length(newstructs)
tomwalters@0 23 curr_str=newstructs{i};
tomwalters@0 24 % if ~strcmp(curr_col,'signal')
tomwalters@0 25 % if ~isfield(old_struct,curr_str) % add whole new fields from the new struct
tomwalters@0 26 est=sprintf('new_struct.%s=add_struct.%s;',curr_str,curr_str);
tomwalters@0 27 eval(est);
tomwalters@0 28 % else % its already there, but not neccessarily up to date
tomwalters@0 29 % eval(sprintf('old_columns=old_struct.%s;',curr_col));
tomwalters@0 30 % eval(sprintf('new_columns=add_struct.%s;',curr_col));
tomwalters@0 31 % old_modules=fieldnames(old_columns);
tomwalters@0 32 % new_modules=fieldnames(new_columns);
tomwalters@0 33 % end
tomwalters@0 34 end
tomwalters@0 35
tomwalters@0 36
tomwalters@0 37
tomwalters@0 38 % for i=1:length(newcolumns)
tomwalters@0 39 % curr_col=newcolumns{i};
tomwalters@0 40 % % if ~strcmp(curr_col,'signal')
tomwalters@0 41 % if ~isfield(old_struct,curr_col) % add whole new fields from the new struct
tomwalters@0 42 % est=sprintf('new_struct.%s=add_struct.%s;',curr_col,curr_col);
tomwalters@0 43 % eval(est);
tomwalters@0 44 % else % its already there, but not neccessarily up to date
tomwalters@0 45 % eval(sprintf('old_columns=old_struct.%s;',curr_col));
tomwalters@0 46 % eval(sprintf('new_columns=add_struct.%s;',curr_col));
tomwalters@0 47 % old_modules=fieldnames(old_columns);
tomwalters@0 48 % new_modules=fieldnames(new_columns);
tomwalters@0 49 % end
tomwalters@0 50 % end
tomwalters@0 51 %
tomwalters@0 52 %
tomwalters@0 53 % for j=1:length(new_modules)
tomwalters@0 54 % if ~isfield(old_columns,new_modules{j}) % add whole new module
tomwalters@0 55 % est=sprintf('new_struct.%s.%s=new_columns.%s;',curr_col,new_modules{j},new_modules{j});
tomwalters@0 56 % eval(est);
tomwalters@0 57 % constr=sprintf('conflicts{%d}=''new module added: %s %s'';',conflict_counter,newcolumns{i},new_modules{j});
tomwalters@0 58 % eval(constr);
tomwalters@0 59 % % conflict_counter=conflict_counter+1;
tomwalters@0 60 % % else % both are there, but check the versions
tomwalters@0 61 % % % if ~strcmp(newcolumns{i},'signal') && ~strcmp(newcolumns{i},'graphics')
tomwalters@0 62 % % ver1str=sprintf('ver1=old_struct.%s.%s.revision;',newcolumns{i},new_modules{j});
tomwalters@0 63 % % try % old version
tomwalters@0 64 % % eval(ver1str);
tomwalters@0 65 % % [ver11,ver12]=ver2num(ver1);
tomwalters@0 66 % % catch
tomwalters@0 67 % % constr=sprintf('conflicts{%d}=''old module had no revision number: module: %s.%s'';',conflict_counter,newcolumns{i},new_modules{j});
tomwalters@0 68 % % eval(constr);conflict_counter=conflict_counter+1;
tomwalters@0 69 % % % ver11='no version';
tomwalters@0 70 % % ver11=-1;
tomwalters@0 71 % % ver12=-1;
tomwalters@0 72 % % end
tomwalters@0 73 % % ver2str=sprintf('ver2=add_struct.%s.%s.revision;',newcolumns{i},new_modules{j});
tomwalters@0 74 % % try % new version
tomwalters@0 75 % % eval(ver2str);
tomwalters@0 76 % % [ver21,ver22]=ver2num(ver2);
tomwalters@0 77 % % catch
tomwalters@0 78 % % ver2='no version';
tomwalters@0 79 % % constr=sprintf('conflicts{%d}=''loaded newer version on module: %s.%s (current version: no version)'';',conflict_counter,newcolumns{i},new_modules{j});
tomwalters@0 80 % % eval(constr);conflict_counter=conflict_counter+1;
tomwalters@0 81 % % end
tomwalters@0 82 % % % if isnumeric(ver11) && isnumeric(ver12) && isnumeric(ver21) && isnumeric(ver22)
tomwalters@0 83 % % if ver21>ver11 || (ver21==ver11 && ver22>ver12)
tomwalters@0 84 % % 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 85 % % eval(constr);conflict_counter=conflict_counter+1;
tomwalters@0 86 % % end
tomwalters@0 87 % % if ver21<ver11 || (ver21==ver11 && ver22<ver12)
tomwalters@0 88 % % 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 89 % % % 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 90 % % eval(constr);conflict_counter=conflict_counter+1;
tomwalters@0 91 % % end
tomwalters@0 92 % % if ver21==ver11 && ver22==ver12
tomwalters@0 93 % % % constr=sprintf('conflicts{%d}=''no conflict: module: %s.%s revision %d.%d '';',conflict_counter,newcolumns{i},new_modules{j},ver11,ver12);
tomwalters@0 94 % % % eval(constr);conflict_counter=conflict_counter+1;
tomwalters@0 95 % % end
tomwalters@0 96 % % end
tomwalters@0 97 % % end
tomwalters@0 98 % end
tomwalters@0 99 % % % next to version checking is checking all parameters. If new
tomwalters@0 100 % % % ones are there, add them!
tomwalters@0 101 % % % but only, if the module is already there
tomwalters@0 102 % % if isfield(old_columns,new_modules{j})
tomwalters@0 103 % % oldstr=sprintf('old_parameter=old_columns.%s;',new_modules{j});
tomwalters@0 104 % % eval(oldstr);
tomwalters@0 105 % % newstr=sprintf('new_parameter=fieldnames(new_columns.%s);',new_modules{j});
tomwalters@0 106 % % eval(newstr);
tomwalters@0 107 % % for k=1:length(new_parameter)
tomwalters@0 108 % % if ~isfield(old_parameter,new_parameter{k})
tomwalters@0 109 % % 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 110 % % eval(addstr);
tomwalters@0 111 % % valstr=sprintf('value=new_struct.%s.%s.%s;',newcolumns{i},new_modules{j},new_parameter{k});
tomwalters@0 112 % % eval(valstr);
tomwalters@0 113 % % if isnumeric(value)
tomwalters@0 114 % % value=num2str(value);
tomwalters@0 115 % % end
tomwalters@0 116 % % 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 117 % % eval(constr);conflict_counter=conflict_counter+1;
tomwalters@0 118 % % end
tomwalters@0 119 % % end
tomwalters@0 120 % % end
tomwalters@0 121 % end
tomwalters@0 122 % end
tomwalters@0 123 % end
tomwalters@0 124 % % end
tomwalters@0 125 %