read keyword value from INI file val = vb_read_inifile_keyword(fname,key) --- Input key : key word fname : file name --- Output val : keyword value (string) if val is numeric, str2num should be appried to val Masa-aki Sato 2009-07-15 Copyright (C) 2011, ATR All Rights Reserved. License : New BSD License(see VBMEG_LICENSE.txt)
0001 function val = vb_read_inifile_keyword(fname,key) 0002 % read keyword value from INI file 0003 % val = vb_read_inifile_keyword(fname,key) 0004 % --- Input 0005 % key : key word 0006 % fname : file name 0007 % --- Output 0008 % val : keyword value (string) 0009 % if val is numeric, str2num should be appried to val 0010 % 0011 % Masa-aki Sato 2009-07-15 0012 % 0013 % Copyright (C) 2011, ATR All Rights Reserved. 0014 % License : New BSD License(see VBMEG_LICENSE.txt) 0015 0016 % K = STRFIND(TEXT,PATTERN) は、文字列 TEXT の中で、文字 PATTERN が出現 0017 % する最初のインデックスを出力します。 0018 0019 val = []; 0020 0021 fid = fopen(fname,'rt'); % text mode all platforms 0022 0023 if(fid < 0), 0024 error(['Unable to open file ' fname]) 0025 end 0026 0027 % find line with keyword 0028 if isempty(key), return; end; 0029 0030 key = [key '=']; 0031 0032 while 1 0033 next_line = fgetl(fid); 0034 if ~ischar(next_line), return; end; 0035 0036 result = strfind(next_line,key); 0037 if ~isempty(result), break, end; 0038 end 0039 0040 val = sscanf(next_line(result+length(key):end),'%s'); 0041 0042 fclose(fid); 0043