0001 function output_ix = vb_signal_processor_confirm_overwrite_files(data, mode)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021 if ~exist('data', 'var')
0022 error('data is a required parameter.');
0023 end
0024 if ~exist('mode', 'var')
0025 mode = 0;
0026 end
0027
0028
0029
0030
0031 output_ix = [];
0032
0033 remove_pref;
0034
0035 if mode == 2
0036 output_ix = [1:1:length(data.output_files)]';
0037 else
0038 Noutput_files = length(data.output_files);
0039
0040 for k=1:Noutput_files
0041 file = data.output_files{k};
0042 if exist(file, 'file') == 2
0043
0044
0045
0046 if mode == 1
0047
0048 write = show_dialog(file);
0049 elseif mode == 0
0050
0051 write = show_text(file);
0052 end
0053 if write
0054 output_ix = [output_ix; k];
0055 end
0056 else
0057
0058 output_ix = [output_ix; k];
0059 end
0060 end
0061 end
0062
0063 remove_pref;
0064
0065 function remove_pref
0066 if ispref('group', PREF_NAME)
0067 rmpref('group', PREF_NAME);
0068 end
0069
0070 function write = show_text(file)
0071 reply = '';
0072 while(isempty(reply))
0073 if ispref('group', PREF_NAME)
0074 reply = 'yes';
0075 else
0076 reply = input([file ' already exist. overwrite? (Yes/No/All):'], 's');
0077 end
0078 switch(lower(reply))
0079 case {'yes', 'y'}
0080 write = 1;
0081 case {'no', 'n'}
0082 write = 0;
0083 case {'all', 'a'}
0084 write = 1;
0085 setpref('group', PREF_NAME, 1);
0086 end
0087 end
0088
0089 function write = show_dialog(file)
0090
0091
0092 reply = uigetpref('group', ...
0093 PREF_NAME, ...
0094 'Confirmation', ...
0095 [file ' already exist. overwrite?'],...
0096 {'Yes', 'No'}, 'DefaultButton', 'No',...
0097 'CheckboxString', 'Apply to All');
0098
0099
0100 switch(lower(reply))
0101 case {'yes', 'y'}
0102 write = 1;
0103 case {'no', 'n'}
0104 write = 0;
0105 otherwise
0106 error('Unknown choice.');
0107 end
0108
0109 function name = PREF_NAME
0110 name = 'overwrite_megmat';
0111