octave-maintainers
[Top][All Lists]
Advanced

[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 14:05:48 +0200

On Tue, Oct 20, 2009 at 1:56 PM, Søren Hauberg <address@hidden> wrote:
> 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 think this is only true if you open the file in text mode (by
fopen), which textread doesn't. Surely it could, but does that work
well with fread? (I'm not sure). Alas, I work exclusively on
GNU/Linux, so I can't test either.
In any case, handling the option in textread using fskipl is both
simpler and faster...

-- 
RNDr. Jaroslav Hajek
computing expert & GNU Octave developer
Aeronautical Research and Test Institute (VZLU)
Prague, Czech Republic
url: www.highegg.matfyz.cz



reply via email to

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