[Index for tmp_for_tar/imgio] [Return to Master Index]

getNonComment

(tmp_for_tar/imgio/getNonComment.m)


Function Synopsis

[currentToken, c] = getNonComment(fid, commentChar)

Help text

 [currentToken, c] = getNonComment(fid, commentChar) - Read a token

 Read first token from current position in file fid, discarding comments.
 A token is any string of non-space text characters (ascii>=33). A comment
 is an occurence of <commentChar> followed by any number of text
 chararacters (ascii>=32).

 fid          : File ID.
 commentChar  : Character which begins a comment.        Default = "#"

 currentToken : The token without the comment.
 c            : The last read character (which is a non-text character,
                e.g. a newline)

 Modified: Etienne Grossmann 2001/02/06
 Created: 7.8.98.
 Version: 1.0



Cross-Reference Information

This function is called by

Listing of function file tmp_for_tar/imgio/getNonComment.m

## [currentToken, c] = getNonComment(fid, commentChar) - Read a token
##
## Read first token from current position in file fid, discarding comments.
## A token is any string of non-space text characters (ascii>=33). A comment
## is an occurence of <commentChar> followed by any number of text
## chararacters (ascii>=32).
##
## fid          : File ID.
## commentChar  : Character which begins a comment.        Default = "#"
##
## currentToken : The token without the comment.
## c            : The last read character (which is a non-text character,
##                e.g. a newline)
##

## Copyright (C) 1998 Ariel Tankus
## 
## This program is free software.
## This file is part of the Image Processing Toolbox for Octave
##
## This program is free software; you can redistribute it and/or
## modify it under the terms of the GNU General Public License
## as published by the Free Software Foundation; either version 2
## of the License, or (at your option) any later version.
## 
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
## GNU General Public License for more details.
## 
## You should have received a copy of the GNU General Public License
## along with this program; if not, write to the Free Software
## Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

## Author: Ariel Tankus <arielt@math.tau.ac.il>
## Modified: Etienne Grossmann 2001/02/06
## Created: 7.8.98.
## Version: 1.0

function [currentToken, c] = getNonComment(fid, commentChar)

  if (nargin < 2)
    commentChar = '#';
  end

  newlineChar = setstr(10);
  currentToken = '';

  done = 0;			# Etienne's sluggish code. 2001/2/6
				# fscanf (fid, " %s", "C") seems broken.
  a = 0;
  while isempty (currentToken)
    while a <= 32		# Skip any non-text
      if a < 32, in_comment = 0; end
      c = fscanf (fid, "%c",1);	# Read chars one by one
      a = toascii (c);
      ## if a<=32, printf("-%i\n",a); else printf("-%s\n",c); end
    end
    
    while a > 32		# Read until next non-text

				# Don't get comments
      if c == commentChar, in_comment = 1; end

      if ! in_comment, currentToken = [currentToken, c]; end
      
      c = fscanf (fid, "%c", 1);
      a = toascii (c);
      ## if a<=32, printf(" %i\n",a); else printf(" %s\n",c); end
    end
  end
  fseek (fid, -1, SEEK_CUR);

  ## currentToken
  return			# End of Etienne's code

  while (length(currentToken) == 0)

    currentToken = fscanf(fid, ' %s', "C");
    ## delete comment
    commentStart = index(currentToken, commentChar);
    if (commentStart ~= 0)

      ## comment found
      currentToken = currentToken(1:(commentStart-1));

      ## skip to end-of-line
      ch = fscanf(fid, '%c', "C");
      while (ch ~= newlineChar)
        ch = fscanf(fid, '%c', "C");
      end

    end

  end

endfunction

Produced by oct2html on Sat Sep 14 9:47:03 2002
Cross-Directory links are: ON