Home > vbmeg > functions > device > eeg > brainamp > file_standardize.m

file_standardize

PURPOSE ^

FILE_STANDARDIZE: Remove all the characters that might be source of problems when in filenames.

SYNOPSIS ^

function filename = file_standardize( filename, isFullPath, repchar )

DESCRIPTION ^

 FILE_STANDARDIZE: Remove all the characters that might be source of problems when in filenames.

 USAGE:  filename = file_standardize( filename, isFullPath, repchar )
         filename = file_standardize( filename, isFullPath )
         filename = file_standardize( filename )

 INPUT:
      - filename   : name of file or full path to standardize
      - isFullPath : if 0, simple filename => remove '/' and '\'     (DEFAULT)
                     if 1, full path to filename => keep '/' and '\'
      - repchar    : replacement character (default '_');
 
 OUTPUT: 
      - filename   : standardized filename

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function filename = file_standardize( filename, isFullPath, repchar )
0002 % FILE_STANDARDIZE: Remove all the characters that might be source of problems when in filenames.
0003 %
0004 % USAGE:  filename = file_standardize( filename, isFullPath, repchar )
0005 %         filename = file_standardize( filename, isFullPath )
0006 %         filename = file_standardize( filename )
0007 %
0008 % INPUT:
0009 %      - filename   : name of file or full path to standardize
0010 %      - isFullPath : if 0, simple filename => remove '/' and '\'     (DEFAULT)
0011 %                     if 1, full path to filename => keep '/' and '\'
0012 %      - repchar    : replacement character (default '_');
0013 %
0014 % OUTPUT:
0015 %      - filename   : standardized filename
0016 
0017 % @=============================================================================
0018 % This software is part of the Brainstorm software:
0019 % http://neuroimage.usc.edu/brainstorm
0020 %
0021 % Copyright (c)2000-2013 Brainstorm by the University of Southern California
0022 % This software is distributed under the terms of the GNU General Public License
0023 % as published by the Free Software Foundation. Further details on the GPL
0024 % license can be found at http://www.gnu.org/copyleft/gpl.html.
0025 %
0026 % FOR RESEARCH PURPOSES ONLY. THE SOFTWARE IS PROVIDED "AS IS," AND THE
0027 % UNIVERSITY OF SOUTHERN CALIFORNIA AND ITS COLLABORATORS DO NOT MAKE ANY
0028 % WARRANTY, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO WARRANTIES OF
0029 % MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, NOR DO THEY ASSUME ANY
0030 % LIABILITY OR RESPONSIBILITY FOR THE USE OF THIS SOFTWARE.
0031 %
0032 % For more information type "brainstorm license" at command prompt.
0033 % =============================================================================@
0034 %
0035 % Authors: Francois Tadel, 2008
0036 
0037 if (nargin < 2)
0038     isFullPath = 0;
0039 end
0040 if (nargin < 3)
0041     repchar = '_';
0042 end
0043 
0044 intFilename = double(filename);
0045 
0046 % Tables
0047 alphaNum = double('0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-.()[]/\_@');
0048 eSpecial = 232:235;
0049 aSpecial = 224:230;
0050 cSpecial = 231;
0051 uSpecial = 249;
0052 slashes  = double('/\');
0053 
0054 % Replace all special chars
0055 intFilename(intFilename == cSpecial) = double('c');
0056 intFilename(intFilename == uSpecial) = double('u');
0057 intFilename(ismember(intFilename, eSpecial)) = double('e');
0058 intFilename(ismember(intFilename, aSpecial)) = double('a');
0059 intFilename(~ismember(intFilename, alphaNum)) = double(repchar);
0060 
0061 % Replace slashes
0062 if isFullPath
0063     intFilename(ismember(intFilename, slashes)) = filesep;
0064 else
0065     intFilename(ismember(intFilename, slashes)) = double(repchar);
0066 end
0067 
0068 filename = char(intFilename);
0069 
0070 end
0071

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