Skip to content
Snippets Groups Projects
Commit 14eebd02 authored by Laura Nervo's avatar Laura Nervo Committed by Nicola Vigano
Browse files

gtAddMatFile : general header formatting and use of GtConditionalOutput(false)


Signed-off-by: default avatarLaura Nervo <laura.nervo@esrf.fr>

git-svn-id: https://svn.code.sf.net/p/dct/code/trunk@442 4c865b51-4357-4376-afb4-474e03ccb993
parent 33580f3a
No related branches found
No related tags found
No related merge requests found
function [updateFile,emptyFile] = gtAddMatFile(existingFile,addedFile,update,missing,addall,empty) function [updateFile,emptyFile] = gtAddMatFile(existingFile,addedFile,update,missing,addall,empty)
% GTADDMATFILE Merges, adds or updates fields between .mat files % GTADDMATFILE Merges, adds or updates fields between .mat files
% updateFile = gtAddMatFile(existingFile,newFile,update,missing,addall,empty) % [updateFile,emptyFile] = gtAddMatFile(existingFile,addedFile,update,missing,addall,empty)
% --------------------------------------------------------------------------- % -----------------------------------------------------------------------------------------
% %
% INPUT: % INPUT:
% existingFile = to be updated/modified <struct> % existingFile = to be updated/modified <struct>
% addedfile = to be added to the 'existingFile' <struct> % addedfile = to be added to the 'existingFile' <struct>
% update = flag to update each of the existing fields in 'existingFile' by double-checking {false} % update = flag to update each of the existing fields in 'existingFile' by double-checking {false}
% missing = flag to add missing fields in 'existingFile' from 'newFile' {false} % missing = flag to add missing fields in 'existingFile' from 'newFile' {false}
% addall = flag to add all the fields of 'newFile' to 'existingFile' without a double-check {false} % addall = flag to add all the fields of 'addedFile' to 'existingFile' without a double-check {false}
% empty = flag to check empty fields {false} % empty = flag to check empty fields {false}
% %
% OUTPUT: % OUTPUT:
% updateFile = the resulting structure % updateFile = the resulting structure
% % emptyFile = list of empty fields
% %
% Version 004 25/04/2021 by LNervo % Version 004 25/04/2021 by LNervo
% Add flag 'empty' % Add flag 'empty'
...@@ -24,6 +24,9 @@ function [updateFile,emptyFile] = gtAddMatFile(existingFile,addedFile,update,mis ...@@ -24,6 +24,9 @@ function [updateFile,emptyFile] = gtAddMatFile(existingFile,addedFile,update,mis
% FUNCTIONS CALLED: % FUNCTIONS CALLED:
% --none-- % --none--
debug = false;
out = GtConditionalOutput(debug);
if ~exist('update','var') || isempty(update) if ~exist('update','var') || isempty(update)
update=false; update=false;
end end
...@@ -42,17 +45,17 @@ existnames = fieldnames(existingFile); % from the existing structure to be modif ...@@ -42,17 +45,17 @@ existnames = fieldnames(existingFile); % from the existing structure to be modif
for i=1:length(names) for i=1:length(names)
if ~isfield(existingFile,names{i}) && ~isfield(existingFile,lower(names{i})) % is not a field of 'existingFile' if ~isfield(existingFile,names{i}) && ~isfield(existingFile,lower(names{i})) % is not a field of 'existingFile'
disp(['>>> ' names{i} ' is not a field... It will be SKIPPED... <<<']) out.odisp(['>>> ' names{i} ' is not a field... It will be SKIPPED... <<<'])
if missing && ~addall if missing && ~addall
variable=names{i}; variable=names{i};
disp(['--> ' variable ' <--']) out.odisp(['--> ' variable ' <--'])
check=inputwdefault('Do you want to add this field? [y/n]','n'); check=inputwdefault('Do you want to add this field? [y/n]','n');
if strcmpi(check,'y') if strcmpi(check,'y')
disp(['added field: ' names{i}]) out.odisp(['added field: ' names{i}])
existingFile.(names{i})=addedFile.(names{i}); existingFile.(names{i})=addedFile.(names{i});
end end
elseif missing || addall elseif missing || addall
disp(['added field: ' names{i}]) out.odisp(['added field: ' names{i}])
existingFile.(names{i})=addedFile.(names{i}); existingFile.(names{i})=addedFile.(names{i});
end end
end end
...@@ -67,17 +70,17 @@ for i=1:length(names) ...@@ -67,17 +70,17 @@ for i=1:length(names)
if ~ischar(newvalue) if ~ischar(newvalue)
newvalue=num2str(newvalue); newvalue=num2str(newvalue);
end end
disp(['--> ' variable ' <--']) out.odisp(['--> ' variable ' <--'])
disp('old: ') out.odisp('old: ')
disp(oldvalue) out.odisp(oldvalue)
disp('new: ') out.odisp('new: ')
disp(newvalue) out.odisp(newvalue)
check=inputwdefault('Are you sure to replace it with the new value? [y/n]','n'); check=inputwdefault('Are you sure to replace it with the new value? [y/n]','n');
else else
disp(['--> ' names{i} ' <--']) out.odisp(['--> ' names{i} ' <--'])
check=inputwdefault('Are those the same thing? [y/n]','n'); check=inputwdefault('Are those the same thing? [y/n]','n');
if strcmpi(check,'y') if strcmpi(check,'y')
disp(['updated field: ' variable ' with field: ' names{i}]) out.odisp(['updated field: ' variable ' with field: ' names{i}])
existingFile.(variable)=addedFile.(names{i}); existingFile.(variable)=addedFile.(names{i});
end end
end end
...@@ -94,21 +97,21 @@ for i=1:length(names) ...@@ -94,21 +97,21 @@ for i=1:length(names)
newvalue=num2str(newvalue); newvalue=num2str(newvalue);
end end
if ~isequal(newvalue,oldvalue) if ~isequal(newvalue,oldvalue)
disp(['--> ' variable ' <--']) out.odisp(['--> ' variable ' <--'])
disp('old: ') out.odisp('old: ')
disp(oldvalue) out.odisp(oldvalue)
disp('new: ') out.odisp('new: ')
disp(newvalue) out.odisp(newvalue)
check=inputwdefault('Do you want to replace it with the new value? [y/n]','n'); check=inputwdefault('Do you want to replace it with the new value? [y/n]','n');
if strcmpi(check,'y') if strcmpi(check,'y')
disp(['replaced field: ' names{i}]) out.odisp(['replaced field: ' names{i}])
existingFile.(names{i})=addedFile.(names{i}); existingFile.(names{i})=addedFile.(names{i});
end end
end end
else else
disp(['updated field: ' names{i}]) out.odisp(['updated field: ' names{i}])
existingFile.(names{i})=addedFile.(names{i}); existingFile.(names{i})=addedFile.(names{i});
end end
end end
...@@ -118,13 +121,13 @@ list_empty=[]; ...@@ -118,13 +121,13 @@ list_empty=[];
if empty % check empty fields if empty % check empty fields
for j=1:length(existnames) for j=1:length(existnames)
if isempty(existingFile.(existnames{j})) if isempty(existingFile.(existnames{j}))
disp(['^^^ ' existnames{j} ' is empty ^^^']) out.odisp(['^^^ ' existnames{j} ' is empty ^^^'])
list_empty.(existnames{j})=existingFile.(existnames{j}); list_empty.(existnames{j})=existingFile.(existnames{j});
end end
end end
emptyFile=list_empty; emptyFile=list_empty;
disp('Empty fields:') out.odisp('Empty fields:')
disp(emptyFile) out.odisp(emptyFile)
end end
updateFile=existingFile; updateFile=existingFile;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment