tomwalters@0: % procedure for 'aim-mat' tomwalters@0: % tomwalters@0: % INPUT VALUES: tomwalters@0: % tomwalters@0: % RETURN VALUE: tomwalters@0: % tomwalters@0: % mix the parts of old_struct with the parts of add_struct tomwalters@0: % old entries in old_struct with identical names are overwritten with the entries tomwalters@0: % from add_struct tomwalters@0: % works recursive up to the second layer tomwalters@0: % bleeck@3: % tomwalters@0: % (c) 2011, University of Southampton bleeck@3: % Maintained by Stefan Bleeck (bleeck@gmail.com) bleeck@3: % download of current version is on the soundsoftware site: bleeck@3: % http://code.soundsoftware.ac.uk/projects/aimmat bleeck@3: % documentation and everything is on http://www.acousticscale.org bleeck@3: bleeck@3: tomwalters@0: tomwalters@0: tomwalters@0: tomwalters@0: function [new_struct,conflicts]=mixstruct(old_struct,add_struct) tomwalters@0: % old_struct is the original structure tomwalters@0: % add_struct is the new struct, that can have new options tomwalters@0: % a warning is given, if a module doesnt exist any more tomwalters@0: % and these options are removed from the parameter file. tomwalters@0: % tomwalters@0: % new parameters are added to the old parameters for each module tomwalters@0: tomwalters@0: tomwalters@0: conflicts=[]; tomwalters@0: conflict_counter=1; tomwalters@0: tomwalters@0: newcolumns=fieldnames(add_struct); tomwalters@0: tomwalters@0: new_struct=old_struct; tomwalters@0: tomwalters@0: for i=1:length(newcolumns) tomwalters@0: curr_col=newcolumns{i}; tomwalters@0: if ~strcmp(curr_col,'signal') tomwalters@0: if ~isfield(old_struct,curr_col) % add whole new fields from the new struct tomwalters@0: est=sprintf('new_struct.%s=add_struct.%s;',curr_col,curr_col); tomwalters@0: eval(est); tomwalters@0: else % its already there, but not neccessarily up to date tomwalters@0: eval(sprintf('old_columns=old_struct.%s;',curr_col)); tomwalters@0: eval(sprintf('new_columns=add_struct.%s;',curr_col)); tomwalters@0: old_modules=fieldnames(old_columns); tomwalters@0: new_modules=fieldnames(new_columns); tomwalters@0: tomwalters@0: tomwalters@0: for j=1:length(new_modules) tomwalters@0: if ~isfield(old_columns,new_modules{j}) % add whole new module tomwalters@0: est=sprintf('new_struct.%s.%s=new_columns.%s;',curr_col,new_modules{j},new_modules{j}); tomwalters@0: eval(est); tomwalters@0: constr=sprintf('conflicts{%d}=''new module added: %s %s'';',conflict_counter,newcolumns{i},new_modules{j}); tomwalters@0: eval(constr);conflict_counter=conflict_counter+1; tomwalters@0: else % both are there, but check the versions tomwalters@0: if ~strcmp(newcolumns{i},'signal') && ~strcmp(newcolumns{i},'graphics') tomwalters@0: ver1str=sprintf('ver1=old_struct.%s.%s.revision;',newcolumns{i},new_modules{j}); tomwalters@0: try % old version tomwalters@0: eval(ver1str); tomwalters@0: ver11=ver2num(ver1); tomwalters@0: catch tomwalters@0: constr=sprintf('conflicts{%d}=''old module had no revision number: module: %s.%s'';',conflict_counter,newcolumns{i},new_modules{j}); tomwalters@0: eval(constr);conflict_counter=conflict_counter+1; tomwalters@0: % ver11='no version'; tomwalters@0: ver11=-1; tomwalters@0: %ver12=-1; tomwalters@0: end tomwalters@0: ver2str=sprintf('ver2=add_struct.%s.%s.revision;',newcolumns{i},new_modules{j}); tomwalters@0: try % new version tomwalters@0: eval(ver2str); tomwalters@0: ver21=ver2num(ver2); tomwalters@0: catch tomwalters@0: ver2='no version'; tomwalters@0: constr=sprintf('conflicts{%d}=''loaded newer version on module: %s.%s (current version: no version)'';',conflict_counter,newcolumns{i},new_modules{j}); tomwalters@0: eval(constr);conflict_counter=conflict_counter+1; tomwalters@0: end tomwalters@0: % if isnumeric(ver11) && isnumeric(ver12) && isnumeric(ver21) && isnumeric(ver22) tomwalters@0: if ver21>ver11 %|| (ver21==ver11 && ver22>ver12) tomwalters@0: 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: eval(constr);conflict_counter=conflict_counter+1; tomwalters@0: end tomwalters@0: if ver21