Home > vbmeg > functions > common > utility > vb_read_to_keyword.m

vb_read_to_keyword

PURPOSE ^

Search keyword in text file

SYNOPSIS ^

function [fid, result, next_line] = vb_read_to_keyword(fid,key,skip)

DESCRIPTION ^

 Search keyword in text file 
  [fid, result, next_line] = vb_read_to_keyword(fid,key)
  [fid, result, next_line] = vb_read_to_keyword(fid,key,skip)
 --- Input
 fid  : file handle 
 key  : skip to the line with this key word
 skip : if this skip string is at the begging of the line, skip lines
 --- Output
 fid   : file pointer is at the next line of keyword line
         if skip is given, lines with skip string at the begging of the line
         are skiped
 next_line : line text including key
 if result is empty, key is not find
 if result > 0, result is position index of key in next_line

 Masa-aki Sato 2008-07-25

 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    [fid, result, next_line] = vb_read_to_keyword(fid,key,skip)
0002 % Search keyword in text file
0003 %  [fid, result, next_line] = vb_read_to_keyword(fid,key)
0004 %  [fid, result, next_line] = vb_read_to_keyword(fid,key,skip)
0005 % --- Input
0006 % fid  : file handle
0007 % key  : skip to the line with this key word
0008 % skip : if this skip string is at the begging of the line, skip lines
0009 % --- Output
0010 % fid   : file pointer is at the next line of keyword line
0011 %         if skip is given, lines with skip string at the begging of the line
0012 %         are skiped
0013 % next_line : line text including key
0014 % if result is empty, key is not find
0015 % if result > 0, result is position index of key in next_line
0016 %
0017 % Masa-aki Sato 2008-07-25
0018 %
0019 % Copyright (C) 2011, ATR All Rights Reserved.
0020 % License : New BSD License(see VBMEG_LICENSE.txt)
0021 
0022 % K = STRFIND(TEXT,PATTERN) は、文字列 TEXT の中で、文字 PATTERN が出現
0023 %  する最初のインデックスを出力します。
0024 
0025 result = [];
0026 if nargin < 3, skip = []; end;
0027 
0028 % find line with keyword
0029 if ~isempty(key),
0030     while 1
0031         next_line = fgetl(fid);
0032         if ~ischar(next_line), result = []; break, end;
0033         
0034         result = strfind(next_line,key);
0035         if ~isempty(result), break, end;
0036     end
0037 else
0038     next_line = fgetl(fid);
0039 end
0040 
0041 if nargin < 3, return; end
0042 
0043 % skip line with comment keyword
0044 if ~isempty(skip),
0045     while 1
0046         if ~ischar(next_line), break, end;
0047         
0048         result_s = strfind(next_line,skip);
0049         if isempty(result_s) || result_s > 1, break, end;
0050         
0051         next_line = fgetl(fid);
0052     end
0053     
0054 end

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