Home > vbmeg > functions > device > vb_device_make_data_dir.m

vb_device_make_data_dir

PURPOSE ^

generate default directory name for data and make it if necessary

SYNOPSIS ^

function [dir_name, real_dir] = vb_device_make_data_dir(base_file, mk_swt)

DESCRIPTION ^

 generate default directory name for data and make it if necessary
 [usage]
   [dir_name, real_dir] = vb_device_make_data_dir(base_file, mk_swt)
 [input]
   base_file : <required> base file name
             :  default directory name is derived from this file name
             :  of base_file
      mk_swt : <optional> switch to make directory [1] or 0
             :  1) make
             :  0) do not make
 [output]
    dir_name : generated directory name
    real_dir : real directory path to be able to make
 [note]

 [history]
   2011-02-18 (Sako) initial version

 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:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function [dir_name, real_dir] = vb_device_make_data_dir(base_file, mk_swt)
0002 % generate default directory name for data and make it if necessary
0003 % [usage]
0004 %   [dir_name, real_dir] = vb_device_make_data_dir(base_file, mk_swt)
0005 % [input]
0006 %   base_file : <required> base file name
0007 %             :  default directory name is derived from this file name
0008 %             :  of base_file
0009 %      mk_swt : <optional> switch to make directory [1] or 0
0010 %             :  1) make
0011 %             :  0) do not make
0012 % [output]
0013 %    dir_name : generated directory name
0014 %    real_dir : real directory path to be able to make
0015 % [note]
0016 %
0017 % [history]
0018 %   2011-02-18 (Sako) initial version
0019 %
0020 % Copyright (C) 2011, ATR All Rights Reserved.
0021 % License : New BSD License(see VBMEG_LICENSE.txt)
0022 
0023 % --- CHECK ARGUMENTS --- %
0024 if ~exist('base_file', 'var'), base_file = ''; end
0025 if ~exist('mk_swt', 'var'), mk_swt = []; end
0026 [base_file, mk_swt] = inner_check_arguments(base_file, mk_swt);
0027 
0028 % --- MAIN PROCEDURE --------------------------------------------------------- %
0029 %
0030 
0031 % --- generate directory name
0032 [fpath, fname] = vb_get_file_parts(base_file);
0033 idx = strfind(fname, '.')-1;
0034 dir_name_base = [fname(1:idx)];
0035 dir_name = ['./' dir_name_base];
0036 
0037 % --- make directory if necessary
0038 if isempty(fpath)
0039   fpath = '.';
0040 end
0041 real_dir = fullfile(fpath, dir_name_base);
0042 if mk_swt == 1 && exist(real_dir, 'dir') ~= 7
0043   vb_mkdir(real_dir);
0044 end
0045 
0046 return;
0047 %
0048 % --- END OF MAIN PROCEDURE -------------------------------------------------- %
0049 
0050 % --- INNER FUNCTIONS -------------------------------------------------------- %
0051 %
0052 % --- inner_check_arguments()
0053 %
0054 function [base_file, mk_swt] = inner_check_arguments(base_file, mk_swt)
0055 func_ = mfilename;
0056 if isempty(base_file)
0057   error('(%s) base_file is a required parameter', func_);
0058 end
0059 
0060 if isempty(mk_swt)
0061   % --- make directory if it does not exist
0062   mk_swt = 1;
0063   
0064   % --- do not make directory even if it does not exist
0065   % mk_swt = 0;
0066 end
0067 return;
0068 %
0069 % --- end of inner_check_arguments()
0070 %
0071 % --- END OF INNER FUNCTIONS ------------------------------------------------- %
0072 
0073 % --- END OF FILE --- %

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