[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Octave-patch-tracker] [patch #8783] C++ implementation of textscan

From: Philip Nienhuis
Subject: [Octave-patch-tracker] [patch #8783] C++ implementation of textscan
Date: Thu, 25 Feb 2016 15:58:19 +0000
User-agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:43.0) Gecko/20100101 Firefox/43.0

Follow-up Comment #61, patch #8783 (project octave):

Matlab on-line help on ReturnOnError says <when textscan fails to read or
convert> "If true, textscan terminates without an error and returns all fields
read. If false, textscan terminates with an error and does not return an
output cell array."
(Hmmm..., no mention of file pointer.)

textscan.m couldn't properly implement ReturnOnError as the operation mode of
its workhorse strread.m is vastly different from that of textscan.cc. The
latter ploughs linearly trough a file, the former (strread.m) tries to parse &
convert a complete file into a rectangular cell array and then parses
IOW, textscan.m's/strread.m's behavior (largely ignoring read errors, you
assessed that correctly) shouldn't be used as a reference.
In fact, textscan.m's texinfo help says so:

(.....) As the string or file is read by columns rather than by rows, and
because textscan is fairly forgiving as regards read errors,
setting this option may have little or no actual effect.

AFAIU your suggestion (mangled by savannah's markup):
We'd have to set ReturnOnError to:
0 or false, to get default behavior (error out and return nothing);
1 or true, to stop at an error and return data as far as textscan.cc got til
that error;
2 (?), to insert something <?EmptyValue?> for the erroneous field in the
output array and try to continue reading the rest of the file.
Well, I like that suggestion.

In case of (1) it would be nice to return the file ptr position.

But Matlab help isn't clear as to what its textscan really does: option 2 or
option 3? Based on what MLr2012a does, I think it is option 2:

>> textscan ('  1   2  s', '%d', 'ReturnOnError', 0)
Error using textscan
Mismatch between file and format string.
Trouble reading integer from file (row 3u, field 1u) ==> s
>> textscan ('  1   2  s', '%d', 'ReturnOnError', 1)
ans = 
    [2x1 int32]
>> textscan ('  1   s  3', '%d', 'ReturnOnError', 1)
ans = 

As to try catch- I was thinking of how to implement it, not so much of how
textscan should work from a user perspective.


Reply to this item at:


  Message sent via/by Savannah

reply via email to

[Prev in Thread] Current Thread [Next in Thread]