bugGNU Octave - Bugs: bug #53914, textread / strread incorrectly...

 
 

bug #53914: textread / strread incorrectly reads string

Submitter:  Muhali <muhali>
Submitted:  Tue 15 May 2018 07:32:43 PM UTC
   
 
Category:  Octave Function Severity:  3 - Normal
Priority:  3 - Low Item Group:  None
Status:  Confirmed Assigned to:  None
Originator Name:  Open/Closed:  * Open
Release:  * dev Operating System:  * Any
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Wed 16 May 2018 07:41:10 PM UTC, comment #3: 

The culprit is in L.422+ of strread.m

To solve this we'd need to know exactly how Matlab treats different whitespace chars in presence of %s format specifiers.

Philip Nienhuis <philipnienhuis>
Group Member
Wed 16 May 2018 08:54:21 AM UTC, comment #2: 

no problem. Go ahead lowering priority. Thanks.

Muhali <muhali>
Wed 16 May 2018 08:27:24 AM UTC, comment #1: 

Try this (FYI strread is the backend of textread):

>> strread ("#  #", "%s", "delimiter", ",", "whitespace", "")
ans =
{
  [1,1] = #  #
}


In general, when reading strings containing spaces using textread/strread/textscan, specify '"whitespace", ""' to avoid spaces being left in the whitespace (= default delimiter) collection.

Matlab r2017b does a slightly better job with strread/testread, however its textscan does the same as Octave's.
As TMW advises to not use textread/strread but invoke textscan instead I don't think we'll do much about strread.m.
I did a lot of work at strread.m some years ago, I'm afraid that fixes for this type of rare corner cases will require undue amounts of extra code.

Would you agree to just lower priority, as there's a good workaround?

Philip Nienhuis <philipnienhuis>
Group Member
Tue 15 May 2018 07:32:43 PM UTC, original submission:  

suppose the file foo.txt contains the single line

#  #

When reading the file via


a = textread ("foo.txt", "%s", "delimiter", ",")


one gets, however,

a =
{
  [1,1] = # #
}

which misses one space. When doing instead


a = textscan ("#  #", "%s", "delimiter", ",")


one correctly gets

a =
{
  [1,1] =
  {
    [1,1] = #  #
  }

}


Muhali <muhali>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by muhali (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only group members can vote.

     

    Follow 7 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2018-05-17 mtmiller Carbon-CopyRemoved 80942 -
    2018-05-17 mtmiller CategoryNone Octave Function
    2018-05-16 philipnienhuis Priority5 - Normal 3 - Low
    2018-05-16 philipnienhuis StatusNone Confirmed
        Release4.4.0 dev
        Operating SystemGNU/Linux Any
        Summarytextread incorrectly reads string textread / strread incorrectly reads string

    Back to the top

    Powered by Savane 3.13-f8d8.
    Corresponding source code