Home > vbmeg > functions > gui > preAnalysis > meeg_processor > signal_processor > vb_signal_processor_confirm_output_dir.m

vb_signal_processor_confirm_output_dir

PURPOSE ^

Confirm the existance of output directory.

SYNOPSIS ^

function [is_ready] = vb_signal_processor_confirm_output_dir(data, mode)

DESCRIPTION ^

 Confirm the existance of output directory.
 [USAGE]
    [is_ready] = vb_signal_processor_confirm_output_dir(data);
 [IN]
    data : Application data.
    mode : confirm making directory or not.
           = 0 : by text.
           = 1 : by dialog.
           = 2 : Yes.

 [OUT]
    is_ready : output directory is ready or not. [Boolean]
               = true: ready, false: not ready.
               the flag also be false when the user 
               choose "not to create directory'.

 Copyright (C) 2011, ATR All Rights Reserved.
 License : New BSD License(see VBMEG_LICENSE.txt)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [is_ready] = vb_signal_processor_confirm_output_dir(data, mode)
0002 % Confirm the existance of output directory.
0003 % [USAGE]
0004 %    [is_ready] = vb_signal_processor_confirm_output_dir(data);
0005 % [IN]
0006 %    data : Application data.
0007 %    mode : confirm making directory or not.
0008 %           = 0 : by text.
0009 %           = 1 : by dialog.
0010 %           = 2 : Yes.
0011 %
0012 % [OUT]
0013 %    is_ready : output directory is ready or not. [Boolean]
0014 %               = true: ready, false: not ready.
0015 %               the flag also be false when the user
0016 %               choose "not to create directory'.
0017 %
0018 % Copyright (C) 2011, ATR All Rights Reserved.
0019 % License : New BSD License(see VBMEG_LICENSE.txt)
0020 
0021 %
0022 % --- Previous check
0023 %
0024 if ~exist('data', 'var')
0025     error('data is a required parameter.');
0026 end
0027 if ~exist('mode', 'var')
0028     error('mode is a required parameter.');
0029 end
0030 
0031 %
0032 % --- Main Procedure
0033 %
0034 % Get list of output directories.
0035 outdir_list = vb_signal_processor_get_output_dir_list(data);
0036 
0037 % Check existance of output directories
0038 ix_not_exist = [];
0039 for k=1:length(outdir_list)
0040     if exist(outdir_list{k}, 'dir') ~= 7
0041         ix_not_exist = [ix_not_exist; k];
0042     end
0043 end
0044 
0045 % Confirm to make directory or not?
0046 if ~isempty(ix_not_exist)
0047     if mode == 0
0048        reply = '';
0049        while(isempty(reply))
0050            for k=1:length(ix_not_exist)
0051                fprintf('%s\n', outdir_list{ix_not_exist(k)});
0052            end
0053            reply = input('does not exist. create? (Yes/No):', 's');
0054            switch(lower(reply))
0055                case {'no', 'n'}
0056                    is_ready = false;
0057                    return;
0058            end
0059         end
0060     elseif mode == 1
0061         dlgTitle = 'Those directories will be created. OK?';
0062         [selection, IsOK] = listdlg('Name', dlgTitle, ...
0063                                     'SelectionMode', 'single', ...
0064                                     'ListString', outdir_list(ix_not_exist), ...
0065                                     'ListSize', [300, 300]);
0066         if ~IsOK
0067             is_ready = false;
0068             return;
0069         end
0070     elseif mode == 2
0071         % Do nothing
0072     else
0073         error('Unknown mode was specified.');
0074     end
0075 
0076     % Make directory
0077     for k=1:length(ix_not_exist)
0078         d_ = outdir_list{ix_not_exist(k)};
0079         result = vb_mkdir(d_);
0080         if result == false
0081             errmsg = sprintf('Failed to create directory : %s', d_);
0082             if mode == 1
0083                 h = errordlg(errmsg, 'Create directory');
0084             end
0085             error(errmsg);
0086         end
0087     end
0088 end
0089 
0090 is_ready = true;

Generated on Mon 22-May-2023 06:53:56 by m2html © 2005