tomwalters@0: % support file for 'aim-mat' tomwalters@0: % tomwalters@0: % This external file is included as part of the 'aim-mat' distribution package bleeck@3: % (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 tomwalters@0: tomwalters@0: tomwalters@0: function new_struct=mixstruct(old_struct,add_struct) tomwalters@0: % old_struct is the original structure tomwalters@0: % add_struct is the new struct tomwalters@0: % entries that are double are overwritten by the entry in add_struct tomwalters@0: % works only for the first recursion level tomwalters@0: tomwalters@0: tomwalters@0: newstructs=fieldnames(add_struct); tomwalters@0: % copy all old stuff tomwalters@0: new_struct=old_struct; tomwalters@0: tomwalters@0: for i=1:length(newstructs) tomwalters@0: curr_str=newstructs{i}; tomwalters@0: % if ~strcmp(curr_col,'signal') tomwalters@0: % if ~isfield(old_struct,curr_str) % add whole new fields from the new struct tomwalters@0: est=sprintf('new_struct.%s=add_struct.%s;',curr_str,curr_str); 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: % end tomwalters@0: end tomwalters@0: tomwalters@0: 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: % end tomwalters@0: % end 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); tomwalters@0: % % 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,ver12]=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,ver22]=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