octave-maintainers
[Top][All Lists]
Advanced

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

Re: 'strread' and 'textread'


From: Søren Hauberg
Subject: Re: 'strread' and 'textread'
Date: Tue, 20 Oct 2009 13:56:48 +0200

tir, 20 10 2009 kl. 13:45 +0200, skrev Jaroslav Hajek:
> I pushed the changeset:
> http://hg.savannah.gnu.org/hgweb/octave/rev/31a22d48f41f

Thanks

> 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").';

Much better; thanks.

> 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 do all my work on Unix so I don't know much (anything) about the
alternative operating systems, but I get the impression that these days
a '\n' is always present when a line ends. Sometimes you just also get
extra characters like '\r'. So, I think the above code should remove the
first lines just fine, but it may leave spurious '\r' (or similar)
characters. This shouldn't matter, though, as the following code splits
into words by any white-space.

>  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).

I agree that there is little need for the option in 'strread', so I
think your change is just fine.

Soren



reply via email to

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