[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: 'strread' and 'textread'
From: |
Jaroslav Hajek |
Subject: |
Re: 'strread' and 'textread' |
Date: |
Tue, 20 Oct 2009 13:45:58 +0200 |
On Mon, Oct 19, 2009 at 8:28 PM, Søren Hauberg <address@hidden> wrote:
> Hi All
>
> A bug that wasn't easy to fix was reported against the implementation of
> 'textread' available in the 'io' package at the Octave-Forge mailing
> list. Eric Chassande-Mottin volunteered to provide a Matlab compatible
> m-file implementation of the function, that Jaroslav and myself then
> vectorised.
>
> Since 'textread' (and its string counterpart 'strread') are part of core
> Matlab, I thought I'd suggest the code for inclusion in core Octave
> instead of the 'io' package. Attached is a changeset that adds the two
> functions.
>
> Søren
>
I pushed the changeset:
http://hg.savannah.gnu.org/hgweb/octave/rev/31a22d48f41f
I added two more modifications:
first, doing
str = char (fread (fid, "char")');
in textread is really wasteful; by default fread returns doubles.
Besides, it often fails since the results are often signed (I think
it's platform-dependent). I replaced it with
str = fread (fid, "char=>char").';
Second, I believe the following segment in strread was wrong:
## Remove header
if (header_skip > 0)
e = find (str == "\n", header_skip);
if (length (e) >= header_skip)
str = str (e (end)+1:end);
else
## We don't have enough data so we discard it all
str = "";
endif
endif
because it doesn't handle all CR, LF and CRLF endings. Handling CR and
LF is simple, but CRLF spoil the picture. I see little need for the
headerlines option in strread (and Matlab doesn't provide it either),
so I removed it and moved the support directly to textread, where
fskipl is called to do the job (and fskipl has the advantage that it
can skip lines without actually reading them into memory).
comments, suggestions?
--
RNDr. Jaroslav Hajek
computing expert & GNU Octave developer
Aeronautical Research and Test Institute (VZLU)
Prague, Czech Republic
url: www.highegg.matfyz.cz