Discussion:
textread error handling
Fritz Sonnichsen
2018-11-01 17:39:32 UTC
Permalink
This happens a lot--I read in a large (200,000 lines) file generated
from a serial port and a few records are "glitched".  textread aborts
producing messages like:

warning: strread: unable to parse text or file with given format string
warning: called from
    strread at line 713 column 7
    textread at line 249 column 31
    drift at line 9 column 40
error: some elements undefined in return list
error: called from
    textread at line 249 column 31
    drift at line 9 column 40

I want textread to handle the error and continue. I can deal with
corrupted data in the returned arrays from there. Of worse case, I would
at least like textread to report which record it stopped on so I can
look into it.

I didn't see an option for this in the doc. Did I miss it?

Th
Ian McCallion
2018-11-01 18:30:49 UTC
Permalink
Just a thought, does textscan leave the opened file positioned at the start of the glitch?

If so at least you can see the erroneous data using a different file function, eg fileread.

Cheers... Ian
Post by Fritz Sonnichsen
This happens a lot--I read in a large (200,000 lines) file generated
from a serial port and a few records are "glitched".  textread aborts
warning: strread: unable to parse text or file with given format string
warning: called from
    strread at line 713 column 7
    textread at line 249 column 31
    drift at line 9 column 40
error: some elements undefined in return list
error: called from
    textread at line 249 column 31
    drift at line 9 column 40
I want textread to handle the error and continue. I can deal with
corrupted data in the returned arrays from there. Of worse case, I would
at least like textread to report which record it stopped on so I can
look into it.
I didn't see an option for this in the doc. Did I miss it?
Thanks
Fritz
Fritz Sonnichsen
2018-11-02 17:03:43 UTC
Permalink
Ian
  at your suggestion,  I converted from textread to textscan and the
dataset if loaded just fine. So I am not sure why textread keeps
failing-at any rate I am content to use textscan going forward. Thanks
for your suggestion
fritz
Post by Ian McCallion
Just a thought, does textscan leave the opened file positioned at the start of the glitch?
If so at least you can see the erroneous data using a different file function, eg fileread.
Cheers... Ian
This happens a lot--I read in a large (200,000 lines) file generated
from a serial port and a few records are "glitched".  textread aborts
warning: strread: unable to parse text or file with given format string
warning: called from
    strread at line 713 column 7
    textread at line 249 column 31
    drift at line 9 column 40
error: some elements undefined in return list
error: called from
    textread at line 249 column 31
    drift at line 9 column 40
I want textread to handle the error and continue. I can deal with
corrupted data in the returned arrays from there. Of worse case, I would
at least like textread to report which record it stopped on so I can
look into it.
I didn't see an option for this in the doc. Did I miss it?
Thanks
Fritz
Ian McCallion
2018-11-02 17:10:05 UTC
Permalink
:-)
Ian
at your suggestion, I converted from textread to textscan and the dataset if loaded just fine. So I am not sure why textread keeps failing-at any rate I am content to use textscan going forward. Thanks for your suggestion
fritz
Just a thought, does textscan leave the opened file positioned at the start of the glitch?
If so at least you can see the erroneous data using a different file function, eg fileread.
Cheers... Ian
Post by Fritz Sonnichsen
This happens a lot--I read in a large (200,000 lines) file generated
from a serial port and a few records are "glitched". textread aborts
warning: strread: unable to parse text or file with given format string
warning: called from
strread at line 713 column 7
textread at line 249 column 31
drift at line 9 column 40
error: some elements undefined in return list
error: called from
textread at line 249 column 31
drift at line 9 column 40
I want textread to handle the error and continue. I can deal with
corrupted data in the returned arrays from there. Of worse case, I would
at least like textread to report which record it stopped on so I can
look into it.
I didn't see an option for this in the doc. Did I miss it?
Thanks
Fritz
Loading...