Mercurial > hg > octave-nkf
annotate scripts/io/strread.m @ 17336:b81b9d079515
Use '##' for comments which stand alone on a line.
* libinterp/corefcn/besselj.cc, libinterp/corefcn/conv2.cc,
libinterp/corefcn/pinv.cc, libinterp/corefcn/rand.cc,
libinterp/corefcn/regexp.cc, libinterp/corefcn/sqrtm.cc,
libinterp/dldfcn/qr.cc, libinterp/parse-tree/pt-eval.cc,
scripts/general/cplxpair.m, scripts/general/repmat.m, scripts/help/doc.m,
scripts/help/doc_cache_create.m, scripts/image/colorcube.m,
scripts/image/hsv2rgb.m, scripts/image/image.m, scripts/io/strread.m,
scripts/io/textscan.m, scripts/miscellaneous/bzip2.m,
scripts/miscellaneous/edit.m, scripts/miscellaneous/gzip.m,
scripts/optimization/__all_opts__.m, scripts/optimization/fminbnd.m,
scripts/optimization/sqp.m, scripts/pkg/private/get_forge_pkg.m,
scripts/plot/area.m, scripts/plot/stemleaf.m, scripts/plot/surfc.m,
scripts/plot/uiresume.m, scripts/plot/zlabel.m, scripts/polynomial/mkpp.m,
scripts/polynomial/ppval.m, scripts/set/intersect.m, scripts/signal/freqz.m,
scripts/sparse/pcg.m, scripts/sparse/pcr.m, scripts/sparse/svds.m,
scripts/sparse/treelayout.m, scripts/specfun/ellipke.m,
scripts/special-matrix/toeplitz.m, scripts/strings/dec2base.m,
scripts/strings/strsplit.m, scripts/testfun/test.m, test/build-sparse-tests.sh,
test/index.tst, test/system.tst:
Use '##' for comments which stand alone on a line.
author | Rik <rik@octave.org> |
---|---|
date | Wed, 28 Aug 2013 08:27:38 -0700 |
parents | bc924baa2c4e |
children | 1c89599167a6 |
rev | line source |
---|---|
14138
72c96de7a403
maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents:
14119
diff
changeset
|
1 ## Copyright (C) 2009-2012 Eric Chassande-Mottin, CNRS (France) |
14582
e97ec01d4157
Correct assignment to wrong variable f headerlines processing
Alexander Graf <a.graf@fz-juelich.de>
parents:
14497
diff
changeset
|
2 ## Parts Copyright (C) 2012 Philip Nienhuis |
9746
31a22d48f41f
scripts/io/strread.m scripts/io/textread.m: new functions
Soren Hauberg <hauberg@gmail.com>
parents:
diff
changeset
|
3 ## |
11104 | 4 ## This file is part of Octave. |
9746
31a22d48f41f
scripts/io/strread.m scripts/io/textread.m: new functions
Soren Hauberg <hauberg@gmail.com>
parents:
diff
changeset
|
5 ## |
11104 | 6 ## Octave is free software; you can redistribute it and/or modify it |
7 ## under the terms of the GNU General Public License as published by | |
8 ## the Free Software Foundation; either version 3 of the License, or (at | |
9 ## your option) any later version. | |
10 ## | |
11 ## Octave is distributed in the hope that it will be useful, but | |
12 ## WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 ## General Public License for more details. | |
9746
31a22d48f41f
scripts/io/strread.m scripts/io/textread.m: new functions
Soren Hauberg <hauberg@gmail.com>
parents:
diff
changeset
|
15 ## |
31a22d48f41f
scripts/io/strread.m scripts/io/textread.m: new functions
Soren Hauberg <hauberg@gmail.com>
parents:
diff
changeset
|
16 ## You should have received a copy of the GNU General Public License |
11104 | 17 ## along with Octave; see the file COPYING. If not, see |
9746
31a22d48f41f
scripts/io/strread.m scripts/io/textread.m: new functions
Soren Hauberg <hauberg@gmail.com>
parents:
diff
changeset
|
18 ## <http://www.gnu.org/licenses/>. |
31a22d48f41f
scripts/io/strread.m scripts/io/textread.m: new functions
Soren Hauberg <hauberg@gmail.com>
parents:
diff
changeset
|
19 |
31a22d48f41f
scripts/io/strread.m scripts/io/textread.m: new functions
Soren Hauberg <hauberg@gmail.com>
parents:
diff
changeset
|
20 ## -*- texinfo -*- |
10793
be55736a0783
Grammarcheck the documentation from m-files.
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
21 ## @deftypefn {Function File} {[@var{a}, @dots{}] =} strread (@var{str}) |
be55736a0783
Grammarcheck the documentation from m-files.
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
22 ## @deftypefnx {Function File} {[@var{a}, @dots{}] =} strread (@var{str}, @var{format}) |
12866
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
23 ## @deftypefnx {Function File} {[@var{a}, @dots{}] =} strread (@var{str}, @var{format}, @var{format_repeat}) |
11150 | 24 ## @deftypefnx {Function File} {[@var{a}, @dots{}] =} strread (@var{str}, @var{format}, @var{prop1}, @var{value1}, @dots{}) |
12866
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
25 ## @deftypefnx {Function File} {[@var{a}, @dots{}] =} strread (@var{str}, @var{format}, @var{format_repeat}, @var{prop1}, @var{value1}, @dots{}) |
9746
31a22d48f41f
scripts/io/strread.m scripts/io/textread.m: new functions
Soren Hauberg <hauberg@gmail.com>
parents:
diff
changeset
|
26 ## Read data from a string. |
31a22d48f41f
scripts/io/strread.m scripts/io/textread.m: new functions
Soren Hauberg <hauberg@gmail.com>
parents:
diff
changeset
|
27 ## |
31a22d48f41f
scripts/io/strread.m scripts/io/textread.m: new functions
Soren Hauberg <hauberg@gmail.com>
parents:
diff
changeset
|
28 ## The string @var{str} is split into words that are repeatedly matched to the |
10793
be55736a0783
Grammarcheck the documentation from m-files.
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
29 ## specifiers in @var{format}. The first word is matched to the first |
12879
c3b305e7e59f
maint: Reverse previous changeset 875c735c0929
Rik <octave@nomad.inbox5.com>
parents:
12878
diff
changeset
|
30 ## specifier, the second to the second specifier and so forth. If there are |
c3b305e7e59f
maint: Reverse previous changeset 875c735c0929
Rik <octave@nomad.inbox5.com>
parents:
12878
diff
changeset
|
31 ## more words than specifiers, the process is repeated until all words have |
c3b305e7e59f
maint: Reverse previous changeset 875c735c0929
Rik <octave@nomad.inbox5.com>
parents:
12878
diff
changeset
|
32 ## been processed. |
9746
31a22d48f41f
scripts/io/strread.m scripts/io/textread.m: new functions
Soren Hauberg <hauberg@gmail.com>
parents:
diff
changeset
|
33 ## |
10793
be55736a0783
Grammarcheck the documentation from m-files.
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
34 ## The string @var{format} describes how the words in @var{str} should be |
be55736a0783
Grammarcheck the documentation from m-files.
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
35 ## parsed. |
9746
31a22d48f41f
scripts/io/strread.m scripts/io/textread.m: new functions
Soren Hauberg <hauberg@gmail.com>
parents:
diff
changeset
|
36 ## It may contain any combination of the following specifiers: |
14327
4d917a6a858b
doc: Use Octave coding conventions in @example blocks of docstrings.
Rik <octave@nomad.inbox5.com>
parents:
14317
diff
changeset
|
37 ## |
9746
31a22d48f41f
scripts/io/strread.m scripts/io/textread.m: new functions
Soren Hauberg <hauberg@gmail.com>
parents:
diff
changeset
|
38 ## @table @code |
31a22d48f41f
scripts/io/strread.m scripts/io/textread.m: new functions
Soren Hauberg <hauberg@gmail.com>
parents:
diff
changeset
|
39 ## @item %s |
31a22d48f41f
scripts/io/strread.m scripts/io/textread.m: new functions
Soren Hauberg <hauberg@gmail.com>
parents:
diff
changeset
|
40 ## The word is parsed as a string. |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
41 ## |
16094
8899c785cc99
doc: Fix warnings associated with Texinfo 5.0 (bug #38392)
Rik <rik@octave.org>
parents:
15855
diff
changeset
|
42 ## @item %f |
12914
ac00ae83ea2e
More compatibility improvements for textscan and strread
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12891
diff
changeset
|
43 ## @itemx %n |
ac00ae83ea2e
More compatibility improvements for textscan and strread
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12891
diff
changeset
|
44 ## The word is parsed as a number and converted to double. |
ac00ae83ea2e
More compatibility improvements for textscan and strread
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12891
diff
changeset
|
45 ## |
12891
f5a3f77d51aa
strread.m, textscan.m: More Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12879
diff
changeset
|
46 ## @item %d |
12866
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
47 ## @itemx %u |
12914
ac00ae83ea2e
More compatibility improvements for textscan and strread
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12891
diff
changeset
|
48 ## The word is parsed as a number and converted to int32. |
12866
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
49 ## |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
50 ## @item %*', '%*f', '%*s |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
51 ## The word is skipped. |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
52 ## |
12866
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
53 ## For %s and %d, %f, %n, %u and the associated %*s @dots{} specifiers an |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
54 ## optional width can be specified as %Ns, etc. where N is an integer > 1. |
12914
ac00ae83ea2e
More compatibility improvements for textscan and strread
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12891
diff
changeset
|
55 ## For %f, format specifiers like %N.Mf are allowed. |
12866
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
56 ## |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
57 ## @item literals |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
58 ## In addition the format may contain literal character strings; these will be |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
59 ## skipped during reading. |
9746
31a22d48f41f
scripts/io/strread.m scripts/io/textread.m: new functions
Soren Hauberg <hauberg@gmail.com>
parents:
diff
changeset
|
60 ## @end table |
31a22d48f41f
scripts/io/strread.m scripts/io/textread.m: new functions
Soren Hauberg <hauberg@gmail.com>
parents:
diff
changeset
|
61 ## |
31a22d48f41f
scripts/io/strread.m scripts/io/textread.m: new functions
Soren Hauberg <hauberg@gmail.com>
parents:
diff
changeset
|
62 ## Parsed word corresponding to the first specifier are returned in the first |
31a22d48f41f
scripts/io/strread.m scripts/io/textread.m: new functions
Soren Hauberg <hauberg@gmail.com>
parents:
diff
changeset
|
63 ## output argument and likewise for the rest of the specifiers. |
31a22d48f41f
scripts/io/strread.m scripts/io/textread.m: new functions
Soren Hauberg <hauberg@gmail.com>
parents:
diff
changeset
|
64 ## |
10793
be55736a0783
Grammarcheck the documentation from m-files.
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
65 ## By default, @var{format} is @t{"%f"}, meaning that numbers are read from |
12866
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
66 ## @var{str}. This will do if @var{str} contains only numeric fields. |
9746
31a22d48f41f
scripts/io/strread.m scripts/io/textread.m: new functions
Soren Hauberg <hauberg@gmail.com>
parents:
diff
changeset
|
67 ## |
31a22d48f41f
scripts/io/strread.m scripts/io/textread.m: new functions
Soren Hauberg <hauberg@gmail.com>
parents:
diff
changeset
|
68 ## For example, the string |
31a22d48f41f
scripts/io/strread.m scripts/io/textread.m: new functions
Soren Hauberg <hauberg@gmail.com>
parents:
diff
changeset
|
69 ## |
31a22d48f41f
scripts/io/strread.m scripts/io/textread.m: new functions
Soren Hauberg <hauberg@gmail.com>
parents:
diff
changeset
|
70 ## @example |
31a22d48f41f
scripts/io/strread.m scripts/io/textread.m: new functions
Soren Hauberg <hauberg@gmail.com>
parents:
diff
changeset
|
71 ## @group |
31a22d48f41f
scripts/io/strread.m scripts/io/textread.m: new functions
Soren Hauberg <hauberg@gmail.com>
parents:
diff
changeset
|
72 ## @var{str} = "\ |
31a22d48f41f
scripts/io/strread.m scripts/io/textread.m: new functions
Soren Hauberg <hauberg@gmail.com>
parents:
diff
changeset
|
73 ## Bunny Bugs 5.5\n\ |
31a22d48f41f
scripts/io/strread.m scripts/io/textread.m: new functions
Soren Hauberg <hauberg@gmail.com>
parents:
diff
changeset
|
74 ## Duck Daffy -7.5e-5\n\ |
31a22d48f41f
scripts/io/strread.m scripts/io/textread.m: new functions
Soren Hauberg <hauberg@gmail.com>
parents:
diff
changeset
|
75 ## Penguin Tux 6" |
31a22d48f41f
scripts/io/strread.m scripts/io/textread.m: new functions
Soren Hauberg <hauberg@gmail.com>
parents:
diff
changeset
|
76 ## @end group |
31a22d48f41f
scripts/io/strread.m scripts/io/textread.m: new functions
Soren Hauberg <hauberg@gmail.com>
parents:
diff
changeset
|
77 ## @end example |
31a22d48f41f
scripts/io/strread.m scripts/io/textread.m: new functions
Soren Hauberg <hauberg@gmail.com>
parents:
diff
changeset
|
78 ## |
10846
a4f482e66b65
Grammarcheck more of the documentation.
Rik <octave@nomad.inbox5.com>
parents:
10821
diff
changeset
|
79 ## @noindent |
9746
31a22d48f41f
scripts/io/strread.m scripts/io/textread.m: new functions
Soren Hauberg <hauberg@gmail.com>
parents:
diff
changeset
|
80 ## can be read using |
31a22d48f41f
scripts/io/strread.m scripts/io/textread.m: new functions
Soren Hauberg <hauberg@gmail.com>
parents:
diff
changeset
|
81 ## |
31a22d48f41f
scripts/io/strread.m scripts/io/textread.m: new functions
Soren Hauberg <hauberg@gmail.com>
parents:
diff
changeset
|
82 ## @example |
31a22d48f41f
scripts/io/strread.m scripts/io/textread.m: new functions
Soren Hauberg <hauberg@gmail.com>
parents:
diff
changeset
|
83 ## [@var{a}, @var{b}, @var{c}] = strread (@var{str}, "%s %s %f"); |
31a22d48f41f
scripts/io/strread.m scripts/io/textread.m: new functions
Soren Hauberg <hauberg@gmail.com>
parents:
diff
changeset
|
84 ## @end example |
31a22d48f41f
scripts/io/strread.m scripts/io/textread.m: new functions
Soren Hauberg <hauberg@gmail.com>
parents:
diff
changeset
|
85 ## |
12866
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
86 ## Optional numeric argument @var{format_repeat} can be used for |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
87 ## limiting the number of items read: |
14327
4d917a6a858b
doc: Use Octave coding conventions in @example blocks of docstrings.
Rik <octave@nomad.inbox5.com>
parents:
14317
diff
changeset
|
88 ## |
12866
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
89 ## @table @asis |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
90 ## @item -1 |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
91 ## (default) read all of the string until the end. |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
92 ## |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
93 ## @item N |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
94 ## Read N times @var{nargout} items. 0 (zero) is an acceptable |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
95 ## value for @var{format_repeat}. |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
96 ## @end table |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
97 ## |
11575
d6619410e79c
Spellcheck documentation before 3.4 release.
Rik <octave@nomad.inbox5.com>
parents:
11564
diff
changeset
|
98 ## The behavior of @code{strread} can be changed via property-value |
11147
a81994607ca0
document textscan and textread
John W. Eaton <jwe@octave.org>
parents:
11127
diff
changeset
|
99 ## pairs. The following properties are recognized: |
a81994607ca0
document textscan and textread
John W. Eaton <jwe@octave.org>
parents:
11127
diff
changeset
|
100 ## |
11595
5ec6aa05638d
Prevent doubled quotes around @table items in Info.
Rik <octave@nomad.inbox5.com>
parents:
11589
diff
changeset
|
101 ## @table @asis |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
16933
diff
changeset
|
102 ## @item @qcode{"commentstyle"} |
9746
31a22d48f41f
scripts/io/strread.m scripts/io/textread.m: new functions
Soren Hauberg <hauberg@gmail.com>
parents:
diff
changeset
|
103 ## Parts of @var{str} are considered comments and will be skipped. |
31a22d48f41f
scripts/io/strread.m scripts/io/textread.m: new functions
Soren Hauberg <hauberg@gmail.com>
parents:
diff
changeset
|
104 ## @var{value} is the comment style and can be any of the following. |
14366
b76f0740940e
doc: Periodic grammar check of documentation.
Rik <octave@nomad.inbox5.com>
parents:
14363
diff
changeset
|
105 ## |
9746
31a22d48f41f
scripts/io/strread.m scripts/io/textread.m: new functions
Soren Hauberg <hauberg@gmail.com>
parents:
diff
changeset
|
106 ## @itemize |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
16933
diff
changeset
|
107 ## @item @qcode{"shell"} |
12891
f5a3f77d51aa
strread.m, textscan.m: More Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12879
diff
changeset
|
108 ## Everything from @code{#} characters to the nearest end-of-line is skipped. |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
109 ## |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
16933
diff
changeset
|
110 ## @item @qcode{"c"} |
9746
31a22d48f41f
scripts/io/strread.m scripts/io/textread.m: new functions
Soren Hauberg <hauberg@gmail.com>
parents:
diff
changeset
|
111 ## Everything between @code{/*} and @code{*/} is skipped. |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
112 ## |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
16933
diff
changeset
|
113 ## @item @qcode{"c++"} |
12891
f5a3f77d51aa
strread.m, textscan.m: More Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12879
diff
changeset
|
114 ## Everything from @code{//} characters to the nearest end-of-line is skipped. |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
115 ## |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
16933
diff
changeset
|
116 ## @item @qcode{"matlab"} |
12891
f5a3f77d51aa
strread.m, textscan.m: More Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12879
diff
changeset
|
117 ## Everything from @code{%} characters to the nearest end-of-line is skipped. |
12866
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
118 ## |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
119 ## @item user-supplied. Two options: |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
120 ## (1) One string, or 1x1 cell string: Skip everything to the right of it; |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
121 ## (2) 2x1 cell string array: Everything between the left and right strings |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
122 ## is skipped. |
9746
31a22d48f41f
scripts/io/strread.m scripts/io/textread.m: new functions
Soren Hauberg <hauberg@gmail.com>
parents:
diff
changeset
|
123 ## @end itemize |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
124 ## |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
16933
diff
changeset
|
125 ## @item @qcode{"delimiter"} |
13141
e81ddf9cacd5
maint: untabify and remove trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
12940
diff
changeset
|
126 ## Any character in @var{value} will be used to split @var{str} into words |
12866
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
127 ## (default value = any whitespace). |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
128 ## |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
16933
diff
changeset
|
129 ## @item @qcode{"emptyvalue"}: |
14096
153581342e47
Always separate numeric fields by whitespace too; gracefully catch too wide literals & fixed width format conversion specifiers
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
13715
diff
changeset
|
130 ## Value to return for empty numeric values in non-whitespace delimited data. |
14119
94e2a76f1e5a
doc: Final grammarcheck and spellcheck before 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents:
14096
diff
changeset
|
131 ## The default is NaN@. When the data type does not support NaN |
14096
153581342e47
Always separate numeric fields by whitespace too; gracefully catch too wide literals & fixed width format conversion specifiers
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
13715
diff
changeset
|
132 ## (int32 for example), then default is zero. |
12866
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
133 ## |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
16933
diff
changeset
|
134 ## @item @qcode{"multipledelimsasone"} |
12891
f5a3f77d51aa
strread.m, textscan.m: More Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12879
diff
changeset
|
135 ## Treat a series of consecutive delimiters, without whitespace in between, |
13141
e81ddf9cacd5
maint: untabify and remove trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
12940
diff
changeset
|
136 ## as a single delimiter. Consecutive delimiter series need not be vertically |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
16933
diff
changeset
|
137 ## @qcode{"aligned"}. |
12891
f5a3f77d51aa
strread.m, textscan.m: More Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12879
diff
changeset
|
138 ## |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
16933
diff
changeset
|
139 ## @item @qcode{"treatasempty"} |
12866
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
140 ## Treat single occurrences (surrounded by delimiters or whitespace) of the |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
141 ## string(s) in @var{value} as missing values. |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
142 ## |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
16933
diff
changeset
|
143 ## @item @qcode{"returnonerror"} |
12866
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
144 ## If @var{value} true (1, default), ignore read errors and return normally. |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
145 ## If false (0), return an error. |
12891
f5a3f77d51aa
strread.m, textscan.m: More Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12879
diff
changeset
|
146 ## |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
16933
diff
changeset
|
147 ## @item @qcode{"whitespace"} |
12891
f5a3f77d51aa
strread.m, textscan.m: More Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12879
diff
changeset
|
148 ## Any character in @var{value} will be interpreted as whitespace and |
f5a3f77d51aa
strread.m, textscan.m: More Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12879
diff
changeset
|
149 ## trimmed; the string defining whitespace must be enclosed in double |
f5a3f77d51aa
strread.m, textscan.m: More Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12879
diff
changeset
|
150 ## quotes for proper processing of special characters like \t. |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
16933
diff
changeset
|
151 ## The default value for whitespace = @qcode{" \b\r\n\t"} (note the space). |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
16933
diff
changeset
|
152 ## Unless whitespace is set to '' (empty) AND at least one @qcode{"%s"} format |
14096
153581342e47
Always separate numeric fields by whitespace too; gracefully catch too wide literals & fixed width format conversion specifiers
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
13715
diff
changeset
|
153 ## conversion specifier is supplied, a space is always part of whitespace. |
13141
e81ddf9cacd5
maint: untabify and remove trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
12940
diff
changeset
|
154 ## |
11150 | 155 ## @end table |
9746
31a22d48f41f
scripts/io/strread.m scripts/io/textread.m: new functions
Soren Hauberg <hauberg@gmail.com>
parents:
diff
changeset
|
156 ## |
14799
21197c43f984
Better Matlab compatibility of textscan, bugs #36356 and #36392
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14582
diff
changeset
|
157 ## When the number of words in @var{str} doesn't match an exact multiple |
21197c43f984
Better Matlab compatibility of textscan, bugs #36356 and #36392
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14582
diff
changeset
|
158 ## of the number of format conversion specifiers, strread's behavior |
21197c43f984
Better Matlab compatibility of textscan, bugs #36356 and #36392
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14582
diff
changeset
|
159 ## depends on the last character of @var{str}: |
21197c43f984
Better Matlab compatibility of textscan, bugs #36356 and #36392
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14582
diff
changeset
|
160 ## |
21197c43f984
Better Matlab compatibility of textscan, bugs #36356 and #36392
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14582
diff
changeset
|
161 ## @table @asis |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
16933
diff
changeset
|
162 ## @item last character = @qcode{"\n"} |
14799
21197c43f984
Better Matlab compatibility of textscan, bugs #36356 and #36392
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14582
diff
changeset
|
163 ## Data columns are padded with empty fields or Nan so that all columns |
21197c43f984
Better Matlab compatibility of textscan, bugs #36356 and #36392
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14582
diff
changeset
|
164 ## have equal length |
21197c43f984
Better Matlab compatibility of textscan, bugs #36356 and #36392
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14582
diff
changeset
|
165 ## |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
16933
diff
changeset
|
166 ## @item last character is not @qcode{"\n"} |
14799
21197c43f984
Better Matlab compatibility of textscan, bugs #36356 and #36392
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14582
diff
changeset
|
167 ## Data columns are not padded; strread returns columns of unequal length |
21197c43f984
Better Matlab compatibility of textscan, bugs #36356 and #36392
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14582
diff
changeset
|
168 ## |
21197c43f984
Better Matlab compatibility of textscan, bugs #36356 and #36392
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14582
diff
changeset
|
169 ## @end table |
21197c43f984
Better Matlab compatibility of textscan, bugs #36356 and #36392
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14582
diff
changeset
|
170 ## |
14853
72b8b39e12be
doc: Periodic grammarcheck of documentation.
Rik <octave@nomad.inbox5.com>
parents:
14835
diff
changeset
|
171 ## @seealso{textscan, textread, load, dlmread, fscanf} |
9746
31a22d48f41f
scripts/io/strread.m scripts/io/textread.m: new functions
Soren Hauberg <hauberg@gmail.com>
parents:
diff
changeset
|
172 ## @end deftypefn |
31a22d48f41f
scripts/io/strread.m scripts/io/textread.m: new functions
Soren Hauberg <hauberg@gmail.com>
parents:
diff
changeset
|
173 |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
11343
diff
changeset
|
174 function varargout = strread (str, format = "%f", varargin) |
12866
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
175 |
9746
31a22d48f41f
scripts/io/strread.m scripts/io/textread.m: new functions
Soren Hauberg <hauberg@gmail.com>
parents:
diff
changeset
|
176 ## Check input |
31a22d48f41f
scripts/io/strread.m scripts/io/textread.m: new functions
Soren Hauberg <hauberg@gmail.com>
parents:
diff
changeset
|
177 if (nargin < 1) |
31a22d48f41f
scripts/io/strread.m scripts/io/textread.m: new functions
Soren Hauberg <hauberg@gmail.com>
parents:
diff
changeset
|
178 print_usage (); |
31a22d48f41f
scripts/io/strread.m scripts/io/textread.m: new functions
Soren Hauberg <hauberg@gmail.com>
parents:
diff
changeset
|
179 endif |
14497
9fc75cdf61ab
strread.m: Trap empty string input (bug #35999)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14366
diff
changeset
|
180 |
9fc75cdf61ab
strread.m: Trap empty string input (bug #35999)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14366
diff
changeset
|
181 if (isempty (str)) |
9fc75cdf61ab
strread.m: Trap empty string input (bug #35999)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14366
diff
changeset
|
182 ## Return empty args (no match), rather than raising an error |
9fc75cdf61ab
strread.m: Trap empty string input (bug #35999)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14366
diff
changeset
|
183 varargout = cell (1, nargout); |
9fc75cdf61ab
strread.m: Trap empty string input (bug #35999)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14366
diff
changeset
|
184 return; |
9fc75cdf61ab
strread.m: Trap empty string input (bug #35999)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14366
diff
changeset
|
185 endif |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
186 |
12866
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
187 if (isempty (format)) |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
188 format = "%f"; |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
189 endif |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
190 |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
191 if (! ischar (str) || ! ischar (format)) |
11472
1740012184f9
Use uppercase for variable names in error() strings to match Info documentation. Only m-files done.
Rik <octave@nomad.inbox5.com>
parents:
11469
diff
changeset
|
192 error ("strread: STR and FORMAT arguments must be strings"); |
9746
31a22d48f41f
scripts/io/strread.m scripts/io/textread.m: new functions
Soren Hauberg <hauberg@gmail.com>
parents:
diff
changeset
|
193 endif |
31a22d48f41f
scripts/io/strread.m scripts/io/textread.m: new functions
Soren Hauberg <hauberg@gmail.com>
parents:
diff
changeset
|
194 |
12891
f5a3f77d51aa
strread.m, textscan.m: More Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12879
diff
changeset
|
195 ## Parse format string to compare number of conversion fields and nargout |
f5a3f77d51aa
strread.m, textscan.m: More Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12879
diff
changeset
|
196 nfields = length (strfind (format, "%")) - length (strfind (format, "%*")); |
f5a3f77d51aa
strread.m, textscan.m: More Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12879
diff
changeset
|
197 ## If str only has numeric fields, a (default) format ("%f") will do. |
f5a3f77d51aa
strread.m, textscan.m: More Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12879
diff
changeset
|
198 ## Otherwise: |
f5a3f77d51aa
strread.m, textscan.m: More Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12879
diff
changeset
|
199 if ((max (nargout, 1) != nfields) && ! strcmp (format, "%f")) |
f5a3f77d51aa
strread.m, textscan.m: More Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12879
diff
changeset
|
200 error ("strread: the number of output variables must match that specified by FORMAT"); |
f5a3f77d51aa
strread.m, textscan.m: More Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12879
diff
changeset
|
201 endif |
f5a3f77d51aa
strread.m, textscan.m: More Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12879
diff
changeset
|
202 |
12866
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
203 ## Check for format string repeat count |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
204 format_repeat_count = -1; |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
205 if (nargin > 2 && isnumeric (varargin{1})) |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
206 if (varargin{1} >= 0) |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
207 format_repeat_count = varargin{1}; |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
208 endif |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
209 if (nargin > 3) |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
210 varargin = varargin(2:end); |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
211 else |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
212 varargin = {}; |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
213 endif |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
214 endif |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
215 |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
216 ## Parse options. First initialize defaults |
9746
31a22d48f41f
scripts/io/strread.m scripts/io/textread.m: new functions
Soren Hauberg <hauberg@gmail.com>
parents:
diff
changeset
|
217 comment_flag = false; |
12891
f5a3f77d51aa
strread.m, textscan.m: More Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12879
diff
changeset
|
218 delimiter_str = ""; |
f5a3f77d51aa
strread.m, textscan.m: More Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12879
diff
changeset
|
219 empty_str = ""; |
f5a3f77d51aa
strread.m, textscan.m: More Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12879
diff
changeset
|
220 eol_char = ""; |
f5a3f77d51aa
strread.m, textscan.m: More Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12879
diff
changeset
|
221 err_action = 0; |
f5a3f77d51aa
strread.m, textscan.m: More Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12879
diff
changeset
|
222 mult_dlms_s1 = false; |
12866
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
223 numeric_fill_value = NaN; |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
224 white_spaces = " \b\r\n\t"; |
9746
31a22d48f41f
scripts/io/strread.m scripts/io/textread.m: new functions
Soren Hauberg <hauberg@gmail.com>
parents:
diff
changeset
|
225 for n = 1:2:length (varargin) |
12866
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
226 switch (lower (varargin{n})) |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
227 case "bufsize" |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
228 ## We could synthesize this, but that just seems weird... |
14835
821708f96efd
strread.m: more robust word parsing and style improvements
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14802
diff
changeset
|
229 warning ("strread: property 'bufsize' is not implemented"); |
9746
31a22d48f41f
scripts/io/strread.m scripts/io/textread.m: new functions
Soren Hauberg <hauberg@gmail.com>
parents:
diff
changeset
|
230 case "commentstyle" |
31a22d48f41f
scripts/io/strread.m scripts/io/textread.m: new functions
Soren Hauberg <hauberg@gmail.com>
parents:
diff
changeset
|
231 comment_flag = true; |
12866
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
232 switch (lower (varargin{n+1})) |
9746
31a22d48f41f
scripts/io/strread.m scripts/io/textread.m: new functions
Soren Hauberg <hauberg@gmail.com>
parents:
diff
changeset
|
233 case "c" |
12866
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
234 [comment_start, comment_end] = deal ("/*", "*/"); |
9746
31a22d48f41f
scripts/io/strread.m scripts/io/textread.m: new functions
Soren Hauberg <hauberg@gmail.com>
parents:
diff
changeset
|
235 case "c++" |
12891
f5a3f77d51aa
strread.m, textscan.m: More Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12879
diff
changeset
|
236 [comment_start, comment_end] = deal ("//", "eol_char"); |
9746
31a22d48f41f
scripts/io/strread.m scripts/io/textread.m: new functions
Soren Hauberg <hauberg@gmail.com>
parents:
diff
changeset
|
237 case "shell" |
12891
f5a3f77d51aa
strread.m, textscan.m: More Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12879
diff
changeset
|
238 [comment_start, comment_end] = deal ("#" , "eol_char"); |
9746
31a22d48f41f
scripts/io/strread.m scripts/io/textread.m: new functions
Soren Hauberg <hauberg@gmail.com>
parents:
diff
changeset
|
239 case "matlab" |
12891
f5a3f77d51aa
strread.m, textscan.m: More Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12879
diff
changeset
|
240 [comment_start, comment_end] = deal ("%" , "eol_char"); |
9746
31a22d48f41f
scripts/io/strread.m scripts/io/textread.m: new functions
Soren Hauberg <hauberg@gmail.com>
parents:
diff
changeset
|
241 otherwise |
12866
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
242 if (ischar (varargin{n+1}) || |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
243 (numel (varargin{n+1}) == 1 && iscellstr (varargin{n+1}))) |
12891
f5a3f77d51aa
strread.m, textscan.m: More Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12879
diff
changeset
|
244 [comment_start, comment_end] = deal (char (varargin{n+1}), "eol_char"); |
12866
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
245 elseif (iscellstr (varargin{n+1}) && numel (varargin{n+1}) == 2) |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
246 [comment_start, comment_end] = deal (varargin{n+1}{:}); |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
247 else |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
248 ## FIXME - a user may have numeric values specified: {'//', 7} |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
249 ## this will lead to an error in the warning message |
13141
e81ddf9cacd5
maint: untabify and remove trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
12940
diff
changeset
|
250 error ("strread: unknown or unrecognized comment style '%s'", |
12866
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
251 varargin{n+1}); |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
252 endif |
9746
31a22d48f41f
scripts/io/strread.m scripts/io/textread.m: new functions
Soren Hauberg <hauberg@gmail.com>
parents:
diff
changeset
|
253 endswitch |
31a22d48f41f
scripts/io/strread.m scripts/io/textread.m: new functions
Soren Hauberg <hauberg@gmail.com>
parents:
diff
changeset
|
254 case "delimiter" |
12866
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
255 delimiter_str = varargin{n+1}; |
14096
153581342e47
Always separate numeric fields by whitespace too; gracefully catch too wide literals & fixed width format conversion specifiers
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
13715
diff
changeset
|
256 if (strcmp (typeinfo (delimiter_str), "sq_string")) |
13715
f8eca611e18f
When single-quoted, the strread() "delimiter", "endofline", and "whitespace"
Ben Abbott <bpabbott@mac.com>
parents:
13176
diff
changeset
|
257 delimiter_str = do_string_escapes (delimiter_str); |
f8eca611e18f
When single-quoted, the strread() "delimiter", "endofline", and "whitespace"
Ben Abbott <bpabbott@mac.com>
parents:
13176
diff
changeset
|
258 endif |
9746
31a22d48f41f
scripts/io/strread.m scripts/io/textread.m: new functions
Soren Hauberg <hauberg@gmail.com>
parents:
diff
changeset
|
259 case "emptyvalue" |
12866
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
260 numeric_fill_value = varargin{n+1}; |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
261 case "expchars" |
14835
821708f96efd
strread.m: more robust word parsing and style improvements
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14802
diff
changeset
|
262 warning ("strread: property 'expchars' is not implemented"); |
9746
31a22d48f41f
scripts/io/strread.m scripts/io/textread.m: new functions
Soren Hauberg <hauberg@gmail.com>
parents:
diff
changeset
|
263 case "whitespace" |
12866
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
264 white_spaces = varargin{n+1}; |
14096
153581342e47
Always separate numeric fields by whitespace too; gracefully catch too wide literals & fixed width format conversion specifiers
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
13715
diff
changeset
|
265 if (strcmp (typeinfo (white_spaces), "sq_string")) |
13715
f8eca611e18f
When single-quoted, the strread() "delimiter", "endofline", and "whitespace"
Ben Abbott <bpabbott@mac.com>
parents:
13176
diff
changeset
|
266 white_spaces = do_string_escapes (white_spaces); |
f8eca611e18f
When single-quoted, the strread() "delimiter", "endofline", and "whitespace"
Ben Abbott <bpabbott@mac.com>
parents:
13176
diff
changeset
|
267 endif |
12866
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
268 ## The following parameters are specific to textscan and textread |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
269 case "endofline" |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
270 eol_char = varargin{n+1}; |
14096
153581342e47
Always separate numeric fields by whitespace too; gracefully catch too wide literals & fixed width format conversion specifiers
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
13715
diff
changeset
|
271 if (strcmp (typeinfo (eol_char), "sq_string")) |
13715
f8eca611e18f
When single-quoted, the strread() "delimiter", "endofline", and "whitespace"
Ben Abbott <bpabbott@mac.com>
parents:
13176
diff
changeset
|
272 eol_char = do_string_escapes (eol_char); |
f8eca611e18f
When single-quoted, the strread() "delimiter", "endofline", and "whitespace"
Ben Abbott <bpabbott@mac.com>
parents:
13176
diff
changeset
|
273 endif |
12866
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
274 case "returnonerror" |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
275 err_action = varargin{n+1}; |
12891
f5a3f77d51aa
strread.m, textscan.m: More Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12879
diff
changeset
|
276 case "multipledelimsasone" |
f5a3f77d51aa
strread.m, textscan.m: More Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12879
diff
changeset
|
277 mult_dlms_s1 = varargin{n+1}; |
12866
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
278 case "treatasempty" |
12879
c3b305e7e59f
maint: Reverse previous changeset 875c735c0929
Rik <octave@nomad.inbox5.com>
parents:
12878
diff
changeset
|
279 if (iscellstr (varargin{n+1})) |
c3b305e7e59f
maint: Reverse previous changeset 875c735c0929
Rik <octave@nomad.inbox5.com>
parents:
12878
diff
changeset
|
280 empty_str = varargin{n+1}; |
c3b305e7e59f
maint: Reverse previous changeset 875c735c0929
Rik <octave@nomad.inbox5.com>
parents:
12878
diff
changeset
|
281 elseif (ischar (varargin{n+1})) |
c3b305e7e59f
maint: Reverse previous changeset 875c735c0929
Rik <octave@nomad.inbox5.com>
parents:
12878
diff
changeset
|
282 empty_str = varargin(n+1); |
c3b305e7e59f
maint: Reverse previous changeset 875c735c0929
Rik <octave@nomad.inbox5.com>
parents:
12878
diff
changeset
|
283 else |
14835
821708f96efd
strread.m: more robust word parsing and style improvements
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14802
diff
changeset
|
284 error ("strread: 'treatasempty' value must be string or cellstr"); |
12866
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
285 endif |
9746
31a22d48f41f
scripts/io/strread.m scripts/io/textread.m: new functions
Soren Hauberg <hauberg@gmail.com>
parents:
diff
changeset
|
286 otherwise |
14835
821708f96efd
strread.m: more robust word parsing and style improvements
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14802
diff
changeset
|
287 warning ("strread: unknown property '%s'", varargin{n}); |
9746
31a22d48f41f
scripts/io/strread.m scripts/io/textread.m: new functions
Soren Hauberg <hauberg@gmail.com>
parents:
diff
changeset
|
288 endswitch |
31a22d48f41f
scripts/io/strread.m scripts/io/textread.m: new functions
Soren Hauberg <hauberg@gmail.com>
parents:
diff
changeset
|
289 endfor |
31a22d48f41f
scripts/io/strread.m scripts/io/textread.m: new functions
Soren Hauberg <hauberg@gmail.com>
parents:
diff
changeset
|
290 |
12891
f5a3f77d51aa
strread.m, textscan.m: More Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12879
diff
changeset
|
291 ## First parse of FORMAT |
12866
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
292 if (strcmpi (strtrim (format), "%f")) |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
293 ## Default format specified. Expand it (to desired nargout) |
16306
4a3b6a80db2e
strread.m: fix division by zero when called with no output args; test added
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
16094
diff
changeset
|
294 fmt_words = cell (max (nargout, 1), 1); |
4a3b6a80db2e
strread.m: fix division by zero when called with no output args; test added
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
16094
diff
changeset
|
295 fmt_words (1:max (nargout, 1)) = format; |
12866
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
296 else |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
297 ## Determine the number of words per line as a first guess. Forms |
12891
f5a3f77d51aa
strread.m, textscan.m: More Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12879
diff
changeset
|
298 ## like %f<literal>) (w/o delimiter in between) are fixed further on |
12866
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
299 format = strrep (format, "%", " %"); |
14835
821708f96efd
strread.m: more robust word parsing and style improvements
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14802
diff
changeset
|
300 fmt_words = regexp (format, '[^ ]+', "match"); |
821708f96efd
strread.m: more robust word parsing and style improvements
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14802
diff
changeset
|
301 |
821708f96efd
strread.m: more robust word parsing and style improvements
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14802
diff
changeset
|
302 ## Find position of conversion specifiers (they start with %) |
821708f96efd
strread.m: more robust word parsing and style improvements
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14802
diff
changeset
|
303 idy2 = find (! cellfun ("isempty", regexp (fmt_words, '^%'))); |
14802
d5aee269b770
strread.m: catch unsupported ML format specifiers (bug #36464)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14800
diff
changeset
|
304 |
d5aee269b770
strread.m: catch unsupported ML format specifiers (bug #36464)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14800
diff
changeset
|
305 ## Check for unsupported format specifiers |
d5aee269b770
strread.m: catch unsupported ML format specifiers (bug #36464)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14800
diff
changeset
|
306 errpat = '(\[.*\]|[cq]|[nfdu]8|[nfdu]16|[nfdu]32|[nfdu]64)'; |
d5aee269b770
strread.m: catch unsupported ML format specifiers (bug #36464)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14800
diff
changeset
|
307 if (! all (cellfun ("isempty", regexp (fmt_words(idy2), errpat)))) |
d5aee269b770
strread.m: catch unsupported ML format specifiers (bug #36464)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14800
diff
changeset
|
308 error ("strread: %q, %c, %[] or bit width format specifiers are not supported yet."); |
d5aee269b770
strread.m: catch unsupported ML format specifiers (bug #36464)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14800
diff
changeset
|
309 endif |
d5aee269b770
strread.m: catch unsupported ML format specifiers (bug #36464)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14800
diff
changeset
|
310 |
14835
821708f96efd
strread.m: more robust word parsing and style improvements
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14802
diff
changeset
|
311 ## Format conversion specifiers following literals w/o space/delim |
821708f96efd
strread.m: more robust word parsing and style improvements
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14802
diff
changeset
|
312 ## in between are separate now. Separate those w trailing literals |
12866
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
313 a = strfind (fmt_words(idy2), "%"); |
14835
821708f96efd
strread.m: more robust word parsing and style improvements
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14802
diff
changeset
|
314 b = regexp (fmt_words(idy2), '[nfdus]', "end"); |
12866
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
315 for jj = 1:numel (a) |
14835
821708f96efd
strread.m: more robust word parsing and style improvements
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14802
diff
changeset
|
316 ## From right to left to avoid losing track |
12866
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
317 ii = numel (a) - jj + 1; |
16571
4d8462fe15b9
strread.m: catch unknown format specifiers (bug #38834)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
16412
diff
changeset
|
318 ## Check for illegal format specifiers |
4d8462fe15b9
strread.m: catch unknown format specifiers (bug #38834)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
16412
diff
changeset
|
319 if (isempty (b{ii})) |
4d8462fe15b9
strread.m: catch unknown format specifiers (bug #38834)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
16412
diff
changeset
|
320 error ("strread: unknown format specifier #%d ('%s')\n", |
4d8462fe15b9
strread.m: catch unknown format specifiers (bug #38834)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
16412
diff
changeset
|
321 ii, fmt_words{idy2(ii)}); |
4d8462fe15b9
strread.m: catch unknown format specifiers (bug #38834)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
16412
diff
changeset
|
322 endif |
12866
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
323 if (! (length (fmt_words{idy2(ii)}) == b{ii}(1))) |
14835
821708f96efd
strread.m: more robust word parsing and style improvements
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14802
diff
changeset
|
324 ## Split fmt_words(ii) into % conv specifier and trailing literal |
12866
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
325 fmt_words(idy2(ii)+1 : end+1) = fmt_words(idy2(ii) : end); |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
326 fmt_words{idy2(ii)} = fmt_words{idy2(ii)}(a{ii} : b{ii}(1)); |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
327 fmt_words{idy2(ii)+1} = fmt_words{idy2(ii)+1}(b{ii}+1:end); |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
328 endif |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
329 endfor |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
330 endif |
11127
64728cd28d7a
strread.m: Improve compatibility with Matlab.
Ben Abbott <bpabbott@mac.com>
parents:
11120
diff
changeset
|
331 num_words_per_line = numel (fmt_words); |
12866
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
332 |
12891
f5a3f77d51aa
strread.m, textscan.m: More Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12879
diff
changeset
|
333 ## Special handling for CRLF EOL character in str |
f5a3f77d51aa
strread.m, textscan.m: More Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12879
diff
changeset
|
334 if (! isempty (eol_char) && strcmp (eol_char, "\r\n")) |
f5a3f77d51aa
strread.m, textscan.m: More Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12879
diff
changeset
|
335 ## Strip CR from CRLF sequences |
f5a3f77d51aa
strread.m, textscan.m: More Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12879
diff
changeset
|
336 str = strrep (str, "\r\n", "\n"); |
f5a3f77d51aa
strread.m, textscan.m: More Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12879
diff
changeset
|
337 ## CR serves no further purpose in function |
f5a3f77d51aa
strread.m, textscan.m: More Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12879
diff
changeset
|
338 eol_char = "\n"; |
12866
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
339 endif |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
340 |
12891
f5a3f77d51aa
strread.m, textscan.m: More Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12879
diff
changeset
|
341 ## Remove comments in str |
f5a3f77d51aa
strread.m, textscan.m: More Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12879
diff
changeset
|
342 if (comment_flag) |
f5a3f77d51aa
strread.m, textscan.m: More Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12879
diff
changeset
|
343 ## Expand 'eol_char' here, after option processing which may have set value |
14835
821708f96efd
strread.m: more robust word parsing and style improvements
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14802
diff
changeset
|
344 comment_end = regexprep (comment_end, "eol_char", eol_char); |
12891
f5a3f77d51aa
strread.m, textscan.m: More Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12879
diff
changeset
|
345 cstart = strfind (str, comment_start); |
f5a3f77d51aa
strread.m, textscan.m: More Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12879
diff
changeset
|
346 cstop = strfind (str, comment_end); |
f5a3f77d51aa
strread.m, textscan.m: More Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12879
diff
changeset
|
347 ## Treat end of string as additional comment stop |
f5a3f77d51aa
strread.m, textscan.m: More Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12879
diff
changeset
|
348 if (isempty (cstop) || cstop(end) != length (str)) |
f5a3f77d51aa
strread.m, textscan.m: More Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12879
diff
changeset
|
349 cstop(end+1) = length (str); |
f5a3f77d51aa
strread.m, textscan.m: More Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12879
diff
changeset
|
350 endif |
f5a3f77d51aa
strread.m, textscan.m: More Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12879
diff
changeset
|
351 if (! isempty (cstart)) |
f5a3f77d51aa
strread.m, textscan.m: More Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12879
diff
changeset
|
352 ## Ignore nested openers. |
f5a3f77d51aa
strread.m, textscan.m: More Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12879
diff
changeset
|
353 [idx, cidx] = unique (lookup (cstop, cstart), "first"); |
f5a3f77d51aa
strread.m, textscan.m: More Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12879
diff
changeset
|
354 if (idx(end) == length (cstop)) |
f5a3f77d51aa
strread.m, textscan.m: More Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12879
diff
changeset
|
355 cidx(end) = []; # Drop the last one if orphaned. |
f5a3f77d51aa
strread.m, textscan.m: More Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12879
diff
changeset
|
356 endif |
f5a3f77d51aa
strread.m, textscan.m: More Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12879
diff
changeset
|
357 cstart = cstart(cidx); |
f5a3f77d51aa
strread.m, textscan.m: More Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12879
diff
changeset
|
358 endif |
f5a3f77d51aa
strread.m, textscan.m: More Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12879
diff
changeset
|
359 if (! isempty (cstop)) |
f5a3f77d51aa
strread.m, textscan.m: More Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12879
diff
changeset
|
360 ## Ignore nested closers. |
f5a3f77d51aa
strread.m, textscan.m: More Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12879
diff
changeset
|
361 [idx, cidx] = unique (lookup (cstart, cstop), "first"); |
f5a3f77d51aa
strread.m, textscan.m: More Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12879
diff
changeset
|
362 if (idx(1) == 0) |
f5a3f77d51aa
strread.m, textscan.m: More Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12879
diff
changeset
|
363 cidx(1) = []; # Drop the first one if orphaned. |
f5a3f77d51aa
strread.m, textscan.m: More Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12879
diff
changeset
|
364 endif |
f5a3f77d51aa
strread.m, textscan.m: More Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12879
diff
changeset
|
365 cstop = cstop(cidx); |
f5a3f77d51aa
strread.m, textscan.m: More Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12879
diff
changeset
|
366 endif |
f5a3f77d51aa
strread.m, textscan.m: More Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12879
diff
changeset
|
367 len = length (str); |
f5a3f77d51aa
strread.m, textscan.m: More Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12879
diff
changeset
|
368 c2len = length (comment_end); |
f5a3f77d51aa
strread.m, textscan.m: More Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12879
diff
changeset
|
369 str = cellslices (str, [1, cstop + c2len], [cstart - 1, len]); |
f5a3f77d51aa
strread.m, textscan.m: More Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12879
diff
changeset
|
370 str = [str{:}]; |
f5a3f77d51aa
strread.m, textscan.m: More Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12879
diff
changeset
|
371 endif |
f5a3f77d51aa
strread.m, textscan.m: More Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12879
diff
changeset
|
372 |
f5a3f77d51aa
strread.m, textscan.m: More Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12879
diff
changeset
|
373 if (! isempty (white_spaces)) |
14835
821708f96efd
strread.m: more robust word parsing and style improvements
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14802
diff
changeset
|
374 ## For numeric fields, whitespace is always a delimiter, but not for text |
821708f96efd
strread.m: more robust word parsing and style improvements
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14802
diff
changeset
|
375 ## fields |
14096
153581342e47
Always separate numeric fields by whitespace too; gracefully catch too wide literals & fixed width format conversion specifiers
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
13715
diff
changeset
|
376 if (isempty (strfind (format, "%s"))) |
153581342e47
Always separate numeric fields by whitespace too; gracefully catch too wide literals & fixed width format conversion specifiers
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
13715
diff
changeset
|
377 ## Add whitespace to delimiter set |
153581342e47
Always separate numeric fields by whitespace too; gracefully catch too wide literals & fixed width format conversion specifiers
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
13715
diff
changeset
|
378 delimiter_str = unique ([white_spaces delimiter_str]); |
153581342e47
Always separate numeric fields by whitespace too; gracefully catch too wide literals & fixed width format conversion specifiers
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
13715
diff
changeset
|
379 else |
153581342e47
Always separate numeric fields by whitespace too; gracefully catch too wide literals & fixed width format conversion specifiers
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
13715
diff
changeset
|
380 ## Remove any delimiter chars from white_spaces list |
153581342e47
Always separate numeric fields by whitespace too; gracefully catch too wide literals & fixed width format conversion specifiers
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
13715
diff
changeset
|
381 white_spaces = setdiff (white_spaces, delimiter_str); |
153581342e47
Always separate numeric fields by whitespace too; gracefully catch too wide literals & fixed width format conversion specifiers
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
13715
diff
changeset
|
382 endif |
12891
f5a3f77d51aa
strread.m, textscan.m: More Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12879
diff
changeset
|
383 endif |
12866
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
384 if (isempty (delimiter_str)) |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
385 delimiter_str = " "; |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
386 endif |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
387 if (! isempty (eol_char)) |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
388 ## Add eol_char to delimiter collection |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
389 delimiter_str = unique ([delimiter_str eol_char]); |
12891
f5a3f77d51aa
strread.m, textscan.m: More Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12879
diff
changeset
|
390 ## .. and remove it from whitespace collection |
f5a3f77d51aa
strread.m, textscan.m: More Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12879
diff
changeset
|
391 white_spaces = strrep (white_spaces, eol_char, ''); |
12866
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
392 endif |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
393 |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
394 pad_out = 0; |
12891
f5a3f77d51aa
strread.m, textscan.m: More Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12879
diff
changeset
|
395 ## Trim whitespace if needed |
12866
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
396 if (! isempty (white_spaces)) |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
397 ## Check if trailing "\n" might signal padding output arrays to equal size |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
398 ## before it is trimmed away below |
13141
e81ddf9cacd5
maint: untabify and remove trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
12940
diff
changeset
|
399 if ((str(end) == 10) && (nargout > 1)) |
12866
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
400 pad_out = 1; |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
401 endif |
14096
153581342e47
Always separate numeric fields by whitespace too; gracefully catch too wide literals & fixed width format conversion specifiers
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
13715
diff
changeset
|
402 ## Condense all repeated whitespace into one single space |
153581342e47
Always separate numeric fields by whitespace too; gracefully catch too wide literals & fixed width format conversion specifiers
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
13715
diff
changeset
|
403 ## FIXME: this will also fold repeated whitespace in a char field |
153581342e47
Always separate numeric fields by whitespace too; gracefully catch too wide literals & fixed width format conversion specifiers
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
13715
diff
changeset
|
404 rxp_wsp = sprintf ("[%s]+", white_spaces); |
153581342e47
Always separate numeric fields by whitespace too; gracefully catch too wide literals & fixed width format conversion specifiers
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
13715
diff
changeset
|
405 str = regexprep (str, rxp_wsp, ' '); |
153581342e47
Always separate numeric fields by whitespace too; gracefully catch too wide literals & fixed width format conversion specifiers
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
13715
diff
changeset
|
406 ## Remove possible leading space at string |
153581342e47
Always separate numeric fields by whitespace too; gracefully catch too wide literals & fixed width format conversion specifiers
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
13715
diff
changeset
|
407 if (str(1) == 32) |
153581342e47
Always separate numeric fields by whitespace too; gracefully catch too wide literals & fixed width format conversion specifiers
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
13715
diff
changeset
|
408 str = str(2:end); |
153581342e47
Always separate numeric fields by whitespace too; gracefully catch too wide literals & fixed width format conversion specifiers
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
13715
diff
changeset
|
409 endif |
153581342e47
Always separate numeric fields by whitespace too; gracefully catch too wide literals & fixed width format conversion specifiers
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
13715
diff
changeset
|
410 ## Check for single delimiter followed/preceded by whitespace |
153581342e47
Always separate numeric fields by whitespace too; gracefully catch too wide literals & fixed width format conversion specifiers
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
13715
diff
changeset
|
411 if (! isempty (delimiter_str)) |
153581342e47
Always separate numeric fields by whitespace too; gracefully catch too wide literals & fixed width format conversion specifiers
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
13715
diff
changeset
|
412 dlmstr = setdiff (delimiter_str, " "); |
15263
2136343014d5
bug #37023 (wrong reading of lines starting and/or ending with whitespace)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14868
diff
changeset
|
413 if (! isempty (dlmstr)) |
2136343014d5
bug #37023 (wrong reading of lines starting and/or ending with whitespace)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14868
diff
changeset
|
414 rxp_dlmwsp = sprintf ('( [%s] | [%s]|[%s] )', dlmstr, dlmstr, dlmstr); |
2136343014d5
bug #37023 (wrong reading of lines starting and/or ending with whitespace)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14868
diff
changeset
|
415 str = regexprep (str, rxp_dlmwsp, delimiter_str(1)); |
2136343014d5
bug #37023 (wrong reading of lines starting and/or ending with whitespace)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14868
diff
changeset
|
416 endif |
14096
153581342e47
Always separate numeric fields by whitespace too; gracefully catch too wide literals & fixed width format conversion specifiers
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
13715
diff
changeset
|
417 endif |
14835
821708f96efd
strread.m: more robust word parsing and style improvements
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14802
diff
changeset
|
418 ## Wipe leading and trailing whitespace on each line (it may be |
821708f96efd
strread.m: more robust word parsing and style improvements
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14802
diff
changeset
|
419 ## delimiter too) |
12914
ac00ae83ea2e
More compatibility improvements for textscan and strread
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12891
diff
changeset
|
420 ## FIXME: Double strrep on str is enormously expensive of CPU time. |
ac00ae83ea2e
More compatibility improvements for textscan and strread
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12891
diff
changeset
|
421 ## Can this be eliminated |
ac00ae83ea2e
More compatibility improvements for textscan and strread
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12891
diff
changeset
|
422 if (! isempty (eol_char)) |
ac00ae83ea2e
More compatibility improvements for textscan and strread
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12891
diff
changeset
|
423 str = strrep (str, [eol_char " "], eol_char); |
ac00ae83ea2e
More compatibility improvements for textscan and strread
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12891
diff
changeset
|
424 str = strrep (str, [" " eol_char], eol_char); |
ac00ae83ea2e
More compatibility improvements for textscan and strread
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12891
diff
changeset
|
425 endif |
12866
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
426 endif |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
427 |
9746
31a22d48f41f
scripts/io/strread.m scripts/io/textread.m: new functions
Soren Hauberg <hauberg@gmail.com>
parents:
diff
changeset
|
428 ## Split 'str' into words |
12914
ac00ae83ea2e
More compatibility improvements for textscan and strread
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12891
diff
changeset
|
429 words = split_by (str, delimiter_str, mult_dlms_s1, eol_char); |
12866
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
430 if (! isempty (white_spaces)) |
14835
821708f96efd
strread.m: more robust word parsing and style improvements
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14802
diff
changeset
|
431 ## Trim leading and trailing 'white_spaces'. All whitespace has |
821708f96efd
strread.m: more robust word parsing and style improvements
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14802
diff
changeset
|
432 ## been converted to space above |
12866
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
433 words = strtrim (words); |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
434 endif |
9746
31a22d48f41f
scripts/io/strread.m scripts/io/textread.m: new functions
Soren Hauberg <hauberg@gmail.com>
parents:
diff
changeset
|
435 num_words = numel (words); |
14835
821708f96efd
strread.m: more robust word parsing and style improvements
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14802
diff
changeset
|
436 ## First guess at nr. of lines in file (ignoring leading/trailing literals) |
12879
c3b305e7e59f
maint: Reverse previous changeset 875c735c0929
Rik <octave@nomad.inbox5.com>
parents:
12878
diff
changeset
|
437 num_lines = ceil (num_words / num_words_per_line); |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
438 |
12866
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
439 ## Replace TreatAsEmpty char sequences by empty strings |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
440 if (! isempty (empty_str)) |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
441 for ii = 1:numel (empty_str) |
14213
a022c04f68cc
Replace to-be-deprecated strmatch occurrences with alternate code.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
442 idz = strncmp (empty_str{ii}, words, length (empty_str{ii})); |
12866
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
443 words(idz) = {""}; |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
444 endfor |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
445 endif |
13141
e81ddf9cacd5
maint: untabify and remove trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
12940
diff
changeset
|
446 |
14096
153581342e47
Always separate numeric fields by whitespace too; gracefully catch too wide literals & fixed width format conversion specifiers
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
13715
diff
changeset
|
447 ## fmt_words has been split properly now, but words{} has only been split on |
14835
821708f96efd
strread.m: more robust word parsing and style improvements
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14802
diff
changeset
|
448 ## delimiter positions. As numeric fields can also be separated by |
821708f96efd
strread.m: more robust word parsing and style improvements
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14802
diff
changeset
|
449 ## whitespace, more splits may be needed. |
14096
153581342e47
Always separate numeric fields by whitespace too; gracefully catch too wide literals & fixed width format conversion specifiers
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
13715
diff
changeset
|
450 ## We also don't know the number of lines (as EndOfLine may have been set to |
153581342e47
Always separate numeric fields by whitespace too; gracefully catch too wide literals & fixed width format conversion specifiers
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
13715
diff
changeset
|
451 ## "" (empty) by the caller). |
153581342e47
Always separate numeric fields by whitespace too; gracefully catch too wide literals & fixed width format conversion specifiers
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
13715
diff
changeset
|
452 ## |
153581342e47
Always separate numeric fields by whitespace too; gracefully catch too wide literals & fixed width format conversion specifiers
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
13715
diff
changeset
|
453 ## We also may have to cope with 3 cases as far as literals go: |
12866
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
454 ## A: Trailing literals (%f<literal>) w/o delimiter in between. |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
455 ## B: Leading literals (<literal>%f) w/o delimiter in between. |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
456 ## C. Skipping leftover parts of specified skip fields (%*N ) |
14096
153581342e47
Always separate numeric fields by whitespace too; gracefully catch too wide literals & fixed width format conversion specifiers
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
13715
diff
changeset
|
457 ## Some words columns may have to be split further to fix these. |
14835
821708f96efd
strread.m: more robust word parsing and style improvements
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14802
diff
changeset
|
458 ## To find out, we'll match fmt_words to the words array to see what |
821708f96efd
strread.m: more robust word parsing and style improvements
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14802
diff
changeset
|
459 ## needs to be done. fwptr tracks which {fmt_words}# starts in what {words}# |
12866
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
460 |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
461 ## Find indices and pointers to possible literals in fmt_words |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
462 idf = cellfun ("isempty", strfind (fmt_words, "%")); |
12891
f5a3f77d51aa
strread.m, textscan.m: More Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12879
diff
changeset
|
463 ## Find indices and pointers to conversion specifiers with fixed width |
f5a3f77d51aa
strread.m, textscan.m: More Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12879
diff
changeset
|
464 idg = ! cellfun ("isempty", regexp (fmt_words, '%\*?\d')); |
13141
e81ddf9cacd5
maint: untabify and remove trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
12940
diff
changeset
|
465 idy = find (idf | idg); |
14096
153581342e47
Always separate numeric fields by whitespace too; gracefully catch too wide literals & fixed width format conversion specifiers
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
13715
diff
changeset
|
466 ## Find indices to numeric conversion specifiers |
14835
821708f96efd
strread.m: more robust word parsing and style improvements
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14802
diff
changeset
|
467 idn = ! cellfun ("isempty", regexp (fmt_words, '%[dnfu]')); |
12866
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
468 |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
469 ## If needed, split up columns in three steps: |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
470 if (! isempty (idy)) |
13141
e81ddf9cacd5
maint: untabify and remove trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
12940
diff
changeset
|
471 ## Try-catch because complexity of strings to read can be infinite |
14096
153581342e47
Always separate numeric fields by whitespace too; gracefully catch too wide literals & fixed width format conversion specifiers
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
13715
diff
changeset
|
472 try |
12866
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
473 |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
474 ## 1. Assess "period" in the split-up words array ( < num_words_per_line). |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
475 ## Could be done using EndOfLine but that prohibits EndOfLine = "" option. |
12914
ac00ae83ea2e
More compatibility improvements for textscan and strread
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12891
diff
changeset
|
476 ## Alternative below goes by simply parsing a first grab of words |
14835
821708f96efd
strread.m: more robust word parsing and style improvements
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14802
diff
changeset
|
477 ## and matching fmt_words to words until the fmt_words array is exhausted. |
821708f96efd
strread.m: more robust word parsing and style improvements
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14802
diff
changeset
|
478 ## iwrd: ptr to current analyzed word; iwrdp: ptr to pos before analyzed char |
821708f96efd
strread.m: more robust word parsing and style improvements
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14802
diff
changeset
|
479 iwrd = 1; iwrdp = 0; iwrdl = length (words{1}); |
821708f96efd
strread.m: more robust word parsing and style improvements
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14802
diff
changeset
|
480 fwptr = zeros (1, numel (fmt_words)); |
14800
a922f768ee09
textscan, strread: improved ML compatibility (bug 36398)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14799
diff
changeset
|
481 ii = 1; |
16933
e39f00a32dc7
maint: Use parentheses around condition for switch(),while(),if() statements.
Rik <rik@octave.org>
parents:
16724
diff
changeset
|
482 while (ii <= numel (fmt_words)) |
12891
f5a3f77d51aa
strread.m, textscan.m: More Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12879
diff
changeset
|
483 |
14317
7dee2bb231c1
strread.m: Fix missing semicolon and unnecessary "unable to parse" messages (Bug #35418).
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14138
diff
changeset
|
484 nxt_wrd = 0; |
14835
821708f96efd
strread.m: more robust word parsing and style improvements
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14802
diff
changeset
|
485 ## Keep track of which words nr. every fmt_words{} is (starts) in. |
821708f96efd
strread.m: more robust word parsing and style improvements
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14802
diff
changeset
|
486 fwptr(ii) = iwrd; |
14317
7dee2bb231c1
strread.m: Fix missing semicolon and unnecessary "unable to parse" messages (Bug #35418).
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14138
diff
changeset
|
487 |
12891
f5a3f77d51aa
strread.m, textscan.m: More Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12879
diff
changeset
|
488 if (idf(ii)) |
f5a3f77d51aa
strread.m, textscan.m: More Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12879
diff
changeset
|
489 ## Literal expected |
f5a3f77d51aa
strread.m, textscan.m: More Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12879
diff
changeset
|
490 if (isempty (strfind (fmt_words{ii}, words(iwrd)))) |
f5a3f77d51aa
strread.m, textscan.m: More Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12879
diff
changeset
|
491 ## Not found in current word; supposed to be in next word |
14317
7dee2bb231c1
strread.m: Fix missing semicolon and unnecessary "unable to parse" messages (Bug #35418).
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14138
diff
changeset
|
492 nxt_wrd = 1; |
12891
f5a3f77d51aa
strread.m, textscan.m: More Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12879
diff
changeset
|
493 else |
f5a3f77d51aa
strread.m, textscan.m: More Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12879
diff
changeset
|
494 ## Found it in current word. Subtract literal length |
f5a3f77d51aa
strread.m, textscan.m: More Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12879
diff
changeset
|
495 iwrdp += length (fmt_words{ii}); |
f5a3f77d51aa
strread.m, textscan.m: More Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12879
diff
changeset
|
496 if (iwrdp > iwrdl) |
f5a3f77d51aa
strread.m, textscan.m: More Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12879
diff
changeset
|
497 ## Parse error. Literal extends beyond delimiter (word boundary) |
14096
153581342e47
Always separate numeric fields by whitespace too; gracefully catch too wide literals & fixed width format conversion specifiers
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
13715
diff
changeset
|
498 warning ("strread: literal '%s' (fmt spec # %d) does not match data", ... |
153581342e47
Always separate numeric fields by whitespace too; gracefully catch too wide literals & fixed width format conversion specifiers
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
13715
diff
changeset
|
499 fmt_words{ii}, ii); |
153581342e47
Always separate numeric fields by whitespace too; gracefully catch too wide literals & fixed width format conversion specifiers
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
13715
diff
changeset
|
500 ## Word assumed to be completely "used up". Next word |
14317
7dee2bb231c1
strread.m: Fix missing semicolon and unnecessary "unable to parse" messages (Bug #35418).
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14138
diff
changeset
|
501 nxt_wrd = 1; |
12891
f5a3f77d51aa
strread.m, textscan.m: More Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12879
diff
changeset
|
502 elseif (iwrdp == iwrdl) |
f5a3f77d51aa
strread.m, textscan.m: More Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12879
diff
changeset
|
503 ## Word completely "used up". Next word |
14317
7dee2bb231c1
strread.m: Fix missing semicolon and unnecessary "unable to parse" messages (Bug #35418).
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14138
diff
changeset
|
504 nxt_wrd = 1; |
12891
f5a3f77d51aa
strread.m, textscan.m: More Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12879
diff
changeset
|
505 endif |
f5a3f77d51aa
strread.m, textscan.m: More Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12879
diff
changeset
|
506 endif |
f5a3f77d51aa
strread.m, textscan.m: More Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12879
diff
changeset
|
507 |
f5a3f77d51aa
strread.m, textscan.m: More Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12879
diff
changeset
|
508 elseif (idg(ii)) |
f5a3f77d51aa
strread.m, textscan.m: More Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12879
diff
changeset
|
509 ## Fixed width specifier (%N or %*N): read just a part of word |
14835
821708f96efd
strread.m: more robust word parsing and style improvements
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14802
diff
changeset
|
510 sw = regexp (fmt_words{ii}, '\d', "once"); |
821708f96efd
strread.m: more robust word parsing and style improvements
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14802
diff
changeset
|
511 ew = regexp (fmt_words{ii}, '[nfuds]') - 1; |
821708f96efd
strread.m: more robust word parsing and style improvements
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14802
diff
changeset
|
512 iwrdp += floor (str2double (fmt_words{ii}(sw:ew))); |
14317
7dee2bb231c1
strread.m: Fix missing semicolon and unnecessary "unable to parse" messages (Bug #35418).
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14138
diff
changeset
|
513 if (iwrdp > iwrdl) |
7dee2bb231c1
strread.m: Fix missing semicolon and unnecessary "unable to parse" messages (Bug #35418).
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14138
diff
changeset
|
514 ## Match error. Field extends beyond word boundary. |
7dee2bb231c1
strread.m: Fix missing semicolon and unnecessary "unable to parse" messages (Bug #35418).
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14138
diff
changeset
|
515 warning ... |
7dee2bb231c1
strread.m: Fix missing semicolon and unnecessary "unable to parse" messages (Bug #35418).
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14138
diff
changeset
|
516 ("strread: field width '%s' (fmt spec # %d) extends beyond actual word limit", ... |
7dee2bb231c1
strread.m: Fix missing semicolon and unnecessary "unable to parse" messages (Bug #35418).
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14138
diff
changeset
|
517 fmt_words{ii}, ii); |
7dee2bb231c1
strread.m: Fix missing semicolon and unnecessary "unable to parse" messages (Bug #35418).
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14138
diff
changeset
|
518 ## Assume word to be completely "used up". Next word |
7dee2bb231c1
strread.m: Fix missing semicolon and unnecessary "unable to parse" messages (Bug #35418).
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14138
diff
changeset
|
519 nxt_wrd = 1; |
7dee2bb231c1
strread.m: Fix missing semicolon and unnecessary "unable to parse" messages (Bug #35418).
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14138
diff
changeset
|
520 elseif (iwrdp == iwrdl) |
7dee2bb231c1
strread.m: Fix missing semicolon and unnecessary "unable to parse" messages (Bug #35418).
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14138
diff
changeset
|
521 ## Word completely "used up". Next word |
7dee2bb231c1
strread.m: Fix missing semicolon and unnecessary "unable to parse" messages (Bug #35418).
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14138
diff
changeset
|
522 nxt_wrd = 1; |
7dee2bb231c1
strread.m: Fix missing semicolon and unnecessary "unable to parse" messages (Bug #35418).
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14138
diff
changeset
|
523 endif |
13141
e81ddf9cacd5
maint: untabify and remove trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
12940
diff
changeset
|
524 |
12891
f5a3f77d51aa
strread.m, textscan.m: More Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12879
diff
changeset
|
525 else |
f5a3f77d51aa
strread.m, textscan.m: More Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12879
diff
changeset
|
526 ## A simple format conv. specifier. Either (1) uses rest of word, or |
f5a3f77d51aa
strread.m, textscan.m: More Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12879
diff
changeset
|
527 ## (2) is squeezed between current iwrdp and next literal, or (3) uses |
f5a3f77d51aa
strread.m, textscan.m: More Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12879
diff
changeset
|
528 ## next word. (3) is already taken care of. So just check (1) & (2) |
f5a3f77d51aa
strread.m, textscan.m: More Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12879
diff
changeset
|
529 if (ii < numel (fmt_words) && idf(ii+1)) |
f5a3f77d51aa
strread.m, textscan.m: More Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12879
diff
changeset
|
530 ## Next fmt_word is a literal... |
f5a3f77d51aa
strread.m, textscan.m: More Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12879
diff
changeset
|
531 if (! index (words{iwrd}(iwrdp+1:end), fmt_words{ii+1})) |
f5a3f77d51aa
strread.m, textscan.m: More Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12879
diff
changeset
|
532 ## ...but not found in current word => field uses rest of word |
14317
7dee2bb231c1
strread.m: Fix missing semicolon and unnecessary "unable to parse" messages (Bug #35418).
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14138
diff
changeset
|
533 nxt_wrd = 1; |
12891
f5a3f77d51aa
strread.m, textscan.m: More Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12879
diff
changeset
|
534 else |
f5a3f77d51aa
strread.m, textscan.m: More Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12879
diff
changeset
|
535 ## ..or it IS found. Add inferred width of current conversion field |
f5a3f77d51aa
strread.m, textscan.m: More Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12879
diff
changeset
|
536 iwrdp += index (words{iwrd}(iwrdp+1:end), fmt_words{ii+1}) - 1; |
f5a3f77d51aa
strread.m, textscan.m: More Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12879
diff
changeset
|
537 endif |
15263
2136343014d5
bug #37023 (wrong reading of lines starting and/or ending with whitespace)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14868
diff
changeset
|
538 elseif (iwrdp <= iwrdl) |
12891
f5a3f77d51aa
strread.m, textscan.m: More Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12879
diff
changeset
|
539 ## No bordering literal to the right => field occupies (rest of) word |
14317
7dee2bb231c1
strread.m: Fix missing semicolon and unnecessary "unable to parse" messages (Bug #35418).
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14138
diff
changeset
|
540 nxt_wrd = 1; |
12891
f5a3f77d51aa
strread.m, textscan.m: More Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12879
diff
changeset
|
541 endif |
f5a3f77d51aa
strread.m, textscan.m: More Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12879
diff
changeset
|
542 |
12866
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
543 endif |
14317
7dee2bb231c1
strread.m: Fix missing semicolon and unnecessary "unable to parse" messages (Bug #35418).
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14138
diff
changeset
|
544 |
7dee2bb231c1
strread.m: Fix missing semicolon and unnecessary "unable to parse" messages (Bug #35418).
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14138
diff
changeset
|
545 if (nxt_wrd) |
7dee2bb231c1
strread.m: Fix missing semicolon and unnecessary "unable to parse" messages (Bug #35418).
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14138
diff
changeset
|
546 ++iwrd; iwrdp = 0; |
14800
a922f768ee09
textscan, strread: improved ML compatibility (bug 36398)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14799
diff
changeset
|
547 if (iwrd > numel (words)) |
a922f768ee09
textscan, strread: improved ML compatibility (bug 36398)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14799
diff
changeset
|
548 ## Apparently EOF; assume incomplete row already at L.1 of data |
a922f768ee09
textscan, strread: improved ML compatibility (bug 36398)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14799
diff
changeset
|
549 ii = numel (fmt_words); |
14835
821708f96efd
strread.m: more robust word parsing and style improvements
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14802
diff
changeset
|
550 elseif (ii < numel (fmt_words) && iwrd <= numel (words)) |
14317
7dee2bb231c1
strread.m: Fix missing semicolon and unnecessary "unable to parse" messages (Bug #35418).
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14138
diff
changeset
|
551 iwrdl = length (words{iwrd}); |
7dee2bb231c1
strread.m: Fix missing semicolon and unnecessary "unable to parse" messages (Bug #35418).
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14138
diff
changeset
|
552 endif |
7dee2bb231c1
strread.m: Fix missing semicolon and unnecessary "unable to parse" messages (Bug #35418).
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14138
diff
changeset
|
553 endif |
14835
821708f96efd
strread.m: more robust word parsing and style improvements
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14802
diff
changeset
|
554 |
14800
a922f768ee09
textscan, strread: improved ML compatibility (bug 36398)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14799
diff
changeset
|
555 ++ii; |
14317
7dee2bb231c1
strread.m: Fix missing semicolon and unnecessary "unable to parse" messages (Bug #35418).
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14138
diff
changeset
|
556 |
14800
a922f768ee09
textscan, strread: improved ML compatibility (bug 36398)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14799
diff
changeset
|
557 endwhile |
12891
f5a3f77d51aa
strread.m, textscan.m: More Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12879
diff
changeset
|
558 ## Done |
12940
3509cf60d1f6
strread.m: %Ns conversion format now honors user specified width (Bug #33950).
Philip Nienhuis <prnienhuis@@users.sf.net>
parents:
12931
diff
changeset
|
559 words_period = max (iwrd - 1, 1); |
12879
c3b305e7e59f
maint: Reverse previous changeset 875c735c0929
Rik <octave@nomad.inbox5.com>
parents:
12878
diff
changeset
|
560 num_lines = ceil (num_words / words_period); |
12866
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
561 |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
562 ## 2. Pad words array so that it can be reshaped |
14835
821708f96efd
strread.m: more robust word parsing and style improvements
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14802
diff
changeset
|
563 num_words_padded = num_lines * words_period - num_words; |
12866
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
564 if (num_words_padded) |
13141
e81ddf9cacd5
maint: untabify and remove trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
12940
diff
changeset
|
565 words = [words'; cell(num_words_padded, 1)]; |
12866
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
566 endif |
14835
821708f96efd
strread.m: more robust word parsing and style improvements
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14802
diff
changeset
|
567 words = reshape (words, words_period, num_lines); |
12866
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
568 |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
569 ## 3. Do the column splitting on rectangular words array |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
570 icol = 1; ii = 1; # icol = current column, ii = current fmt_word |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
571 while (ii <= num_words_per_line) |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
572 |
12891
f5a3f77d51aa
strread.m, textscan.m: More Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12879
diff
changeset
|
573 ## Check if fmt_words(ii) contains a literal or fixed-width |
14868
5d3a684236b0
maint: Use Octave coding conventions for cuddling parentheses in scripts directory
Rik <octave@nomad.inbox5.com>
parents:
14853
diff
changeset
|
574 if ((idf(ii) || idg(ii)) && (rows (words) < num_words_per_line)) |
12891
f5a3f77d51aa
strread.m, textscan.m: More Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12879
diff
changeset
|
575 if (idf(ii)) |
f5a3f77d51aa
strread.m, textscan.m: More Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12879
diff
changeset
|
576 s = strfind (words(icol, 1), fmt_words{ii}); |
12914
ac00ae83ea2e
More compatibility improvements for textscan and strread
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12891
diff
changeset
|
577 if (isempty (s{:})) |
12891
f5a3f77d51aa
strread.m, textscan.m: More Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12879
diff
changeset
|
578 error ("strread: Literal '%s' not found in column %d", fmt_words{ii}, icol); |
f5a3f77d51aa
strread.m, textscan.m: More Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12879
diff
changeset
|
579 endif |
f5a3f77d51aa
strread.m, textscan.m: More Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12879
diff
changeset
|
580 s = s{:}(1); |
f5a3f77d51aa
strread.m, textscan.m: More Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12879
diff
changeset
|
581 e = s(1) + length (fmt_words{ii}) - 1; |
f5a3f77d51aa
strread.m, textscan.m: More Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12879
diff
changeset
|
582 endif |
f5a3f77d51aa
strread.m, textscan.m: More Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12879
diff
changeset
|
583 if (! strcmp (fmt_words{ii}, words{icol, 1})) |
f5a3f77d51aa
strread.m, textscan.m: More Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12879
diff
changeset
|
584 ## Column doesn't exactly match literal => split needed. Insert a column |
13141
e81ddf9cacd5
maint: untabify and remove trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
12940
diff
changeset
|
585 words(icol+1:end+1, :) = words(icol:end, :); |
12891
f5a3f77d51aa
strread.m, textscan.m: More Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12879
diff
changeset
|
586 ## Watch out for empty cells |
f5a3f77d51aa
strread.m, textscan.m: More Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12879
diff
changeset
|
587 jptr = find (! cellfun ("isempty", words(icol, :))); |
12866
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
588 |
12891
f5a3f77d51aa
strread.m, textscan.m: More Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12879
diff
changeset
|
589 ## Distinguish leading or trailing literals |
f5a3f77d51aa
strread.m, textscan.m: More Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12879
diff
changeset
|
590 if (! idg(ii) && ! isempty (s) && s(1) == 1) |
f5a3f77d51aa
strread.m, textscan.m: More Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12879
diff
changeset
|
591 ## Leading literal. Assign literal to icol, paste rest in icol + 1 |
f5a3f77d51aa
strread.m, textscan.m: More Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12879
diff
changeset
|
592 ## Apply only to those cells that do have something beyond literal |
14868
5d3a684236b0
maint: Use Octave coding conventions for cuddling parentheses in scripts directory
Rik <octave@nomad.inbox5.com>
parents:
14853
diff
changeset
|
593 jptr = find (cellfun ("length", words(icol+1, jptr), ... |
5d3a684236b0
maint: Use Octave coding conventions for cuddling parentheses in scripts directory
Rik <octave@nomad.inbox5.com>
parents:
14853
diff
changeset
|
594 "UniformOutput", false) > e(1)); |
12891
f5a3f77d51aa
strread.m, textscan.m: More Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12879
diff
changeset
|
595 words(icol+1, :) = {""}; |
f5a3f77d51aa
strread.m, textscan.m: More Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12879
diff
changeset
|
596 words(icol+1, jptr) = cellfun ... |
14868
5d3a684236b0
maint: Use Octave coding conventions for cuddling parentheses in scripts directory
Rik <octave@nomad.inbox5.com>
parents:
14853
diff
changeset
|
597 (@(x) substr (x, e(1)+1, length (x) - e(1)), words(icol, jptr), ... |
12891
f5a3f77d51aa
strread.m, textscan.m: More Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12879
diff
changeset
|
598 "UniformOutput", false); |
f5a3f77d51aa
strread.m, textscan.m: More Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12879
diff
changeset
|
599 words(icol, jptr) = fmt_words{ii}; |
14835
821708f96efd
strread.m: more robust word parsing and style improvements
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14802
diff
changeset
|
600 fwptr = [fwptr(1:ii) (++fwptr(ii+1:end))]; |
12866
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
601 |
12891
f5a3f77d51aa
strread.m, textscan.m: More Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12879
diff
changeset
|
602 else |
f5a3f77d51aa
strread.m, textscan.m: More Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12879
diff
changeset
|
603 if (! idg(ii) && ! isempty (strfind (fmt_words{ii-1}, "%s"))) |
12866
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
604 ## Trailing literal. If preceding format == '%s' this is an error |
15855
4294430ef736
strread: make warning mesage more tractable
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
15844
diff
changeset
|
605 warning ... |
4294430ef736
strread: make warning mesage more tractable
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
15844
diff
changeset
|
606 ("strread: ambiguous '%s' specifier next to literal in column %d", icol); |
12891
f5a3f77d51aa
strread.m, textscan.m: More Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12879
diff
changeset
|
607 elseif (idg(ii)) |
f5a3f77d51aa
strread.m, textscan.m: More Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12879
diff
changeset
|
608 ## Current field = fixed width. Strip into icol, rest in icol+1 |
14835
821708f96efd
strread.m: more robust word parsing and style improvements
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14802
diff
changeset
|
609 sw = regexp (fmt_words{ii}, '\d', "once"); |
821708f96efd
strread.m: more robust word parsing and style improvements
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14802
diff
changeset
|
610 ew = regexp (fmt_words{ii}, '[nfuds]') - 1; |
821708f96efd
strread.m: more robust word parsing and style improvements
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14802
diff
changeset
|
611 wdth = floor (str2double (fmt_words{ii}(sw:ew))); |
12891
f5a3f77d51aa
strread.m, textscan.m: More Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12879
diff
changeset
|
612 words(icol+1, jptr) = cellfun (@(x) x(wdth+1:end), |
13141
e81ddf9cacd5
maint: untabify and remove trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
12940
diff
changeset
|
613 words(icol,jptr), "UniformOutput", false); |
14835
821708f96efd
strread.m: more robust word parsing and style improvements
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14802
diff
changeset
|
614 if (isempty ([words(icol+1, :){:}])) |
821708f96efd
strread.m: more robust word parsing and style improvements
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14802
diff
changeset
|
615 ## Apparently split wasn't needed as turns out to cover |
821708f96efd
strread.m: more robust word parsing and style improvements
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14802
diff
changeset
|
616 ## entire column. So delete column again |
821708f96efd
strread.m: more robust word parsing and style improvements
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14802
diff
changeset
|
617 words(icol+1, :) = []; |
821708f96efd
strread.m: more robust word parsing and style improvements
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14802
diff
changeset
|
618 else |
821708f96efd
strread.m: more robust word parsing and style improvements
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14802
diff
changeset
|
619 words(icol, jptr) = strtrunc (words(icol, jptr), wdth); |
821708f96efd
strread.m: more robust word parsing and style improvements
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14802
diff
changeset
|
620 fwptr = [fwptr(1:ii) (++fwptr(ii+1:end))]; |
821708f96efd
strread.m: more robust word parsing and style improvements
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14802
diff
changeset
|
621 endif |
12891
f5a3f77d51aa
strread.m, textscan.m: More Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12879
diff
changeset
|
622 else |
f5a3f77d51aa
strread.m, textscan.m: More Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12879
diff
changeset
|
623 ## FIXME: this assumes char(254)/char(255) won't occur in input! |
f5a3f77d51aa
strread.m, textscan.m: More Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12879
diff
changeset
|
624 clear wrds; |
f5a3f77d51aa
strread.m, textscan.m: More Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12879
diff
changeset
|
625 wrds(1:2:2*numel (words(icol, jptr))) = ... |
f5a3f77d51aa
strread.m, textscan.m: More Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12879
diff
changeset
|
626 strrep (words(icol, jptr), fmt_words{ii}, ... |
f5a3f77d51aa
strread.m, textscan.m: More Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12879
diff
changeset
|
627 [char(255) char(254)]); |
14868
5d3a684236b0
maint: Use Octave coding conventions for cuddling parentheses in scripts directory
Rik <octave@nomad.inbox5.com>
parents:
14853
diff
changeset
|
628 wrds(2:2:2*numel (words(icol, jptr))-1) = char (255); |
16724
b7667fcb9fbc
Substitute ostrsplit() for strsplit().
Ben Abbott <bpabbott@mac.com>
parents:
16571
diff
changeset
|
629 wrds = ostrsplit ([wrds{:}], char (255)); |
12891
f5a3f77d51aa
strread.m, textscan.m: More Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12879
diff
changeset
|
630 words(icol, jptr) = ... |
14868
5d3a684236b0
maint: Use Octave coding conventions for cuddling parentheses in scripts directory
Rik <octave@nomad.inbox5.com>
parents:
14853
diff
changeset
|
631 wrds(find (cellfun ("isempty", strfind (wrds, char (254))))); |
5d3a684236b0
maint: Use Octave coding conventions for cuddling parentheses in scripts directory
Rik <octave@nomad.inbox5.com>
parents:
14853
diff
changeset
|
632 wrds(find (cellfun ("isempty", strfind (wrds, char (254))))) ... |
5d3a684236b0
maint: Use Octave coding conventions for cuddling parentheses in scripts directory
Rik <octave@nomad.inbox5.com>
parents:
14853
diff
changeset
|
633 = char (255); |
16724
b7667fcb9fbc
Substitute ostrsplit() for strsplit().
Ben Abbott <bpabbott@mac.com>
parents:
16571
diff
changeset
|
634 words(icol+1, jptr) = ostrsplit (strrep ([wrds{2:end}], ... |
b7667fcb9fbc
Substitute ostrsplit() for strsplit().
Ben Abbott <bpabbott@mac.com>
parents:
16571
diff
changeset
|
635 char (254), fmt_words{ii}), char (255)); |
12866
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
636 ## Former trailing literal may now be leading for next specifier |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
637 --ii; |
14835
821708f96efd
strread.m: more robust word parsing and style improvements
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14802
diff
changeset
|
638 fwptr = [fwptr(1:ii) (++fwptr(ii+1:end))]; |
12866
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
639 endif |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
640 endif |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
641 endif |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
642 |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
643 else |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
644 ## Conv. specifier. Peek if next fmt_word needs split from current column |
14096
153581342e47
Always separate numeric fields by whitespace too; gracefully catch too wide literals & fixed width format conversion specifiers
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
13715
diff
changeset
|
645 if (ii < num_words_per_line) |
14835
821708f96efd
strread.m: more robust word parsing and style improvements
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14802
diff
changeset
|
646 if (fwptr(ii) == fwptr(ii+1)) |
12866
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
647 --icol; |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
648 endif |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
649 endif |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
650 endif |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
651 ## Next fmt_word, next column |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
652 ++ii; ++icol; |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
653 endwhile |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
654 |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
655 ## Done. Reshape words back into 1 long vector and strip padded empty words |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
656 words = reshape (words, 1, numel (words))(1 : end-num_words_padded); |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
657 |
14096
153581342e47
Always separate numeric fields by whitespace too; gracefully catch too wide literals & fixed width format conversion specifiers
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
13715
diff
changeset
|
658 catch |
153581342e47
Always separate numeric fields by whitespace too; gracefully catch too wide literals & fixed width format conversion specifiers
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
13715
diff
changeset
|
659 warning ("strread: unable to parse text or file with given format string"); |
153581342e47
Always separate numeric fields by whitespace too; gracefully catch too wide literals & fixed width format conversion specifiers
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
13715
diff
changeset
|
660 return; |
12866
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
661 |
14096
153581342e47
Always separate numeric fields by whitespace too; gracefully catch too wide literals & fixed width format conversion specifiers
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
13715
diff
changeset
|
662 end_try_catch |
12866
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
663 endif |
13141
e81ddf9cacd5
maint: untabify and remove trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
12940
diff
changeset
|
664 |
12866
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
665 ## For each specifier, process corresponding column |
9746
31a22d48f41f
scripts/io/strread.m scripts/io/textread.m: new functions
Soren Hauberg <hauberg@gmail.com>
parents:
diff
changeset
|
666 k = 1; |
11127
64728cd28d7a
strread.m: Improve compatibility with Matlab.
Ben Abbott <bpabbott@mac.com>
parents:
11120
diff
changeset
|
667 for m = 1:num_words_per_line |
12866
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
668 try |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
669 if (format_repeat_count < 0) |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
670 data = words(m:num_words_per_line:end); |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
671 elseif (format_repeat_count == 0) |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
672 data = {}; |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
673 else |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
674 lastline = ... |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
675 min (num_words_per_line * format_repeat_count + m - 1, numel (words)); |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
676 data = words(m:num_words_per_line:lastline); |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
677 endif |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
678 |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
679 ## Map to format |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
680 ## FIXME - add support for formats like "<%s>", "%[a-zA-Z]" |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
681 ## Someone with regexp experience is needed. |
16933
e39f00a32dc7
maint: Use parentheses around condition for switch(),while(),if() statements.
Rik <rik@octave.org>
parents:
16724
diff
changeset
|
682 switch (fmt_words{m}(1:min (2, length (fmt_words{m})))) |
12866
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
683 case "%s" |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
684 if (pad_out) |
13141
e81ddf9cacd5
maint: untabify and remove trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
12940
diff
changeset
|
685 data(end+1:num_lines) = {""}; |
12866
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
686 endif |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
687 varargout{k} = data'; |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
688 k++; |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
689 case {"%d", "%u", "%f", "%n"} |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
690 n = cellfun ("isempty", data); |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
691 ### FIXME - erroneously formatted data lead to NaN, not an error |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
692 data = str2double (data); |
12914
ac00ae83ea2e
More compatibility improvements for textscan and strread
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12891
diff
changeset
|
693 if (! isempty (regexp (fmt_words{m}, "%[du]"))) |
13141
e81ddf9cacd5
maint: untabify and remove trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
12940
diff
changeset
|
694 ## Cast to integer |
12914
ac00ae83ea2e
More compatibility improvements for textscan and strread
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12891
diff
changeset
|
695 ## FIXME: NaNs will be transformed into zeros |
ac00ae83ea2e
More compatibility improvements for textscan and strread
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12891
diff
changeset
|
696 data = int32 (data); |
13176
9b8e786bbf3c
maint: use specific endif, endfor tokens instead of simple end
John W. Eaton <jwe@octave.org>
parents:
13141
diff
changeset
|
697 endif |
12866
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
698 data(n) = numeric_fill_value; |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
699 if (pad_out) |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
700 data(end+1:num_lines) = numeric_fill_value; |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
701 endif |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
702 varargout{k} = data.'; |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
703 k++; |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
704 case {"%0", "%1", "%2", "%3", "%4", "%5", "%6", "%7", "%8", "%9"} |
14835
821708f96efd
strread.m: more robust word parsing and style improvements
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14802
diff
changeset
|
705 sw = regexp (fmt_words{m}, '\d', "once"); |
821708f96efd
strread.m: more robust word parsing and style improvements
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14802
diff
changeset
|
706 ew = regexp (fmt_words{m}, '[nfudsq]') - 1; |
16724
b7667fcb9fbc
Substitute ostrsplit() for strsplit().
Ben Abbott <bpabbott@mac.com>
parents:
16571
diff
changeset
|
707 nfmt = ostrsplit (fmt_words{m}(2:ew), "."); |
12873
e8c8e118a1e6
Small touchups to textscan and strread revamp
Rik <octave@nomad.inbox5.com>
parents:
12866
diff
changeset
|
708 swidth = str2double (nfmt{1}); |
16933
e39f00a32dc7
maint: Use parentheses around condition for switch(),while(),if() statements.
Rik <rik@octave.org>
parents:
16724
diff
changeset
|
709 switch (fmt_words{m}(ew+1)) |
14835
821708f96efd
strread.m: more robust word parsing and style improvements
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14802
diff
changeset
|
710 case {"d", "u", "f", "n"} |
12866
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
711 n = cellfun ("isempty", data); |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
712 ### FIXME - erroneously formatted data lead to NaN, not an error |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
713 ### => ReturnOnError can't be implemented for numeric data |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
714 data = str2double (strtrunc (data, swidth)); |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
715 data(n) = numeric_fill_value; |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
716 if (pad_out) |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
717 data(end+1:num_lines) = numeric_fill_value; |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
718 endif |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
719 if (numel (nfmt) > 1) |
12873
e8c8e118a1e6
Small touchups to textscan and strread revamp
Rik <octave@nomad.inbox5.com>
parents:
12866
diff
changeset
|
720 sprec = str2double (nfmt{2}); |
12866
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
721 data = 10^-sprec * round (10^sprec * data); |
12914
ac00ae83ea2e
More compatibility improvements for textscan and strread
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12891
diff
changeset
|
722 elseif (! isempty (regexp (fmt_words{m}, "[du]"))) |
13141
e81ddf9cacd5
maint: untabify and remove trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
12940
diff
changeset
|
723 ## Cast to integer |
12914
ac00ae83ea2e
More compatibility improvements for textscan and strread
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12891
diff
changeset
|
724 ## FIXME: NaNs will be transformed into zeros |
ac00ae83ea2e
More compatibility improvements for textscan and strread
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12891
diff
changeset
|
725 data = int32 (data); |
13176
9b8e786bbf3c
maint: use specific endif, endfor tokens instead of simple end
John W. Eaton <jwe@octave.org>
parents:
13141
diff
changeset
|
726 endif |
12866
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
727 varargout{k} = data.'; |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
728 k++; |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
729 case "s" |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
730 if (pad_out) |
14317
7dee2bb231c1
strread.m: Fix missing semicolon and unnecessary "unable to parse" messages (Bug #35418).
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14138
diff
changeset
|
731 data(end+1:num_lines) = {""}; |
12866
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
732 endif |
12940
3509cf60d1f6
strread.m: %Ns conversion format now honors user specified width (Bug #33950).
Philip Nienhuis <prnienhuis@@users.sf.net>
parents:
12931
diff
changeset
|
733 varargout{k} = strtrunc (data, swidth)'; |
12866
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
734 k++; |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
735 otherwise |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
736 endswitch |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
737 case {"%*", "%*s"} |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
738 ## skip the word |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
739 otherwise |
12891
f5a3f77d51aa
strread.m, textscan.m: More Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12879
diff
changeset
|
740 ## Ensure descriptive content is consistent. |
f5a3f77d51aa
strread.m, textscan.m: More Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12879
diff
changeset
|
741 ## Test made a bit lax to accomodate for incomplete last lines |
f5a3f77d51aa
strread.m, textscan.m: More Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12879
diff
changeset
|
742 n = find (! cellfun ("isempty", data)); |
f5a3f77d51aa
strread.m, textscan.m: More Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12879
diff
changeset
|
743 if (numel (unique (data(n))) > 1 |
12866
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
744 || ! strcmpi (unique (data), fmt_words{m})) |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
745 error ("strread: FORMAT does not match data"); |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
746 endif |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
747 endswitch |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
748 catch |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
749 ## As strread processes columnwise, ML-compatible error processing |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
750 ## (row after row) is not feasible. In addition Octave sets unrecognizable |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
751 ## numbers to NaN w/o error. But maybe Octave is better in this respect. |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
752 if (err_action) |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
753 ## Just try the next column where ML bails out |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
754 else |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
755 rethrow (lasterror); |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
756 endif |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
757 end_try_catch |
9746
31a22d48f41f
scripts/io/strread.m scripts/io/textread.m: new functions
Soren Hauberg <hauberg@gmail.com>
parents:
diff
changeset
|
758 endfor |
12866
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
759 |
9746
31a22d48f41f
scripts/io/strread.m scripts/io/textread.m: new functions
Soren Hauberg <hauberg@gmail.com>
parents:
diff
changeset
|
760 endfunction |
31a22d48f41f
scripts/io/strread.m scripts/io/textread.m: new functions
Soren Hauberg <hauberg@gmail.com>
parents:
diff
changeset
|
761 |
12914
ac00ae83ea2e
More compatibility improvements for textscan and strread
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12891
diff
changeset
|
762 function out = split_by (text, sep, mult_dlms_s1, eol_char) |
12891
f5a3f77d51aa
strread.m, textscan.m: More Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12879
diff
changeset
|
763 |
f5a3f77d51aa
strread.m, textscan.m: More Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12879
diff
changeset
|
764 ## Check & if needed, process MultipleDelimsAsOne parameter |
f5a3f77d51aa
strread.m, textscan.m: More Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12879
diff
changeset
|
765 if (mult_dlms_s1) |
f5a3f77d51aa
strread.m, textscan.m: More Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12879
diff
changeset
|
766 mult_dlms_s1 = true; |
12914
ac00ae83ea2e
More compatibility improvements for textscan and strread
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12891
diff
changeset
|
767 ## FIXME: Should re-implement strsplit() function here in order |
ac00ae83ea2e
More compatibility improvements for textscan and strread
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12891
diff
changeset
|
768 ## to avoid strrep on megabytes of data. |
14096
153581342e47
Always separate numeric fields by whitespace too; gracefully catch too wide literals & fixed width format conversion specifiers
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
13715
diff
changeset
|
769 ## If \n is in sep collection we need to enclose it in text |
12891
f5a3f77d51aa
strread.m, textscan.m: More Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12879
diff
changeset
|
770 ## to avoid it being included in consecutive delim series |
14096
153581342e47
Always separate numeric fields by whitespace too; gracefully catch too wide literals & fixed width format conversion specifiers
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
13715
diff
changeset
|
771 enchr = ' '; |
153581342e47
Always separate numeric fields by whitespace too; gracefully catch too wide literals & fixed width format conversion specifiers
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
13715
diff
changeset
|
772 ## However watch out if eol_char is also in delimiters |
14868
5d3a684236b0
maint: Use Octave coding conventions for cuddling parentheses in scripts directory
Rik <octave@nomad.inbox5.com>
parents:
14853
diff
changeset
|
773 if (index (sep, eol_char)); enchr = char (255); endif |
14096
153581342e47
Always separate numeric fields by whitespace too; gracefully catch too wide literals & fixed width format conversion specifiers
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
13715
diff
changeset
|
774 text = strrep (text, eol_char, [enchr eol_char enchr]); |
12891
f5a3f77d51aa
strread.m, textscan.m: More Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12879
diff
changeset
|
775 else |
f5a3f77d51aa
strread.m, textscan.m: More Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12879
diff
changeset
|
776 mult_dlms_s1 = false; |
f5a3f77d51aa
strread.m, textscan.m: More Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12879
diff
changeset
|
777 endif |
f5a3f77d51aa
strread.m, textscan.m: More Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12879
diff
changeset
|
778 |
f5a3f77d51aa
strread.m, textscan.m: More Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12879
diff
changeset
|
779 ## Split text string along delimiters |
16724
b7667fcb9fbc
Substitute ostrsplit() for strsplit().
Ben Abbott <bpabbott@mac.com>
parents:
16571
diff
changeset
|
780 out = ostrsplit (text, sep, mult_dlms_s1); |
14868
5d3a684236b0
maint: Use Octave coding conventions for cuddling parentheses in scripts directory
Rik <octave@nomad.inbox5.com>
parents:
14853
diff
changeset
|
781 if (index (sep, eol_char)); out = strrep (out, char (255), ''); endif |
12891
f5a3f77d51aa
strread.m, textscan.m: More Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12879
diff
changeset
|
782 ## In case of trailing delimiter, strip stray last empty word |
12914
ac00ae83ea2e
More compatibility improvements for textscan and strread
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12891
diff
changeset
|
783 if (!isempty (out) && any (sep == text(end))) |
12891
f5a3f77d51aa
strread.m, textscan.m: More Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12879
diff
changeset
|
784 out(end) = []; |
f5a3f77d51aa
strread.m, textscan.m: More Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12879
diff
changeset
|
785 endif |
13141
e81ddf9cacd5
maint: untabify and remove trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
12940
diff
changeset
|
786 |
12891
f5a3f77d51aa
strread.m, textscan.m: More Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12879
diff
changeset
|
787 ## Empty cells converted to empty cellstrings. |
12866
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
788 out(cellfun ("isempty", out)) = {""}; |
12891
f5a3f77d51aa
strread.m, textscan.m: More Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12879
diff
changeset
|
789 |
9746
31a22d48f41f
scripts/io/strread.m scripts/io/textread.m: new functions
Soren Hauberg <hauberg@gmail.com>
parents:
diff
changeset
|
790 endfunction |
31a22d48f41f
scripts/io/strread.m scripts/io/textread.m: new functions
Soren Hauberg <hauberg@gmail.com>
parents:
diff
changeset
|
791 |
12866
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
792 |
9746
31a22d48f41f
scripts/io/strread.m scripts/io/textread.m: new functions
Soren Hauberg <hauberg@gmail.com>
parents:
diff
changeset
|
793 %!test |
11343
5e5c513ea4c5
strread.m: Don't require space between format specifiers.
Ben Abbott <bpabbott@mac.com>
parents:
11150
diff
changeset
|
794 %! [a, b] = strread ("1 2", "%f%f"); |
12914
ac00ae83ea2e
More compatibility improvements for textscan and strread
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12891
diff
changeset
|
795 %! assert (a, 1); |
ac00ae83ea2e
More compatibility improvements for textscan and strread
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12891
diff
changeset
|
796 %! assert (b, 2); |
9746
31a22d48f41f
scripts/io/strread.m scripts/io/textread.m: new functions
Soren Hauberg <hauberg@gmail.com>
parents:
diff
changeset
|
797 |
31a22d48f41f
scripts/io/strread.m scripts/io/textread.m: new functions
Soren Hauberg <hauberg@gmail.com>
parents:
diff
changeset
|
798 %!test |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14335
diff
changeset
|
799 %! str = ""; |
9746
31a22d48f41f
scripts/io/strread.m scripts/io/textread.m: new functions
Soren Hauberg <hauberg@gmail.com>
parents:
diff
changeset
|
800 %! a = rand (10, 1); |
12866
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
801 %! b = char (randi ([65, 85], 10, 1)); |
9746
31a22d48f41f
scripts/io/strread.m scripts/io/textread.m: new functions
Soren Hauberg <hauberg@gmail.com>
parents:
diff
changeset
|
802 %! for k = 1:10 |
14835
821708f96efd
strread.m: more robust word parsing and style improvements
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14802
diff
changeset
|
803 %! str = sprintf ("%s %.6f %s\n", str, a(k), b(k)); |
9746
31a22d48f41f
scripts/io/strread.m scripts/io/textread.m: new functions
Soren Hauberg <hauberg@gmail.com>
parents:
diff
changeset
|
804 %! endfor |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14335
diff
changeset
|
805 %! [aa, bb] = strread (str, "%f %s"); |
15844
8f0d07f8390b
Fix assertions with "observed" and "expected" out of order.
Ben Abbott <bpabbott@mac.com>
parents:
15263
diff
changeset
|
806 %! assert (aa, a, 1e-6); |
8f0d07f8390b
Fix assertions with "observed" and "expected" out of order.
Ben Abbott <bpabbott@mac.com>
parents:
15263
diff
changeset
|
807 %! assert (bb, cellstr (b)); |
9746
31a22d48f41f
scripts/io/strread.m scripts/io/textread.m: new functions
Soren Hauberg <hauberg@gmail.com>
parents:
diff
changeset
|
808 |
31a22d48f41f
scripts/io/strread.m scripts/io/textread.m: new functions
Soren Hauberg <hauberg@gmail.com>
parents:
diff
changeset
|
809 %!test |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14335
diff
changeset
|
810 %! str = ""; |
9746
31a22d48f41f
scripts/io/strread.m scripts/io/textread.m: new functions
Soren Hauberg <hauberg@gmail.com>
parents:
diff
changeset
|
811 %! a = rand (10, 1); |
12866
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
812 %! b = char (randi ([65, 85], 10, 1)); |
9746
31a22d48f41f
scripts/io/strread.m scripts/io/textread.m: new functions
Soren Hauberg <hauberg@gmail.com>
parents:
diff
changeset
|
813 %! for k = 1:10 |
14835
821708f96efd
strread.m: more robust word parsing and style improvements
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14802
diff
changeset
|
814 %! str = sprintf ("%s %.6f %s\n", str, a(k), b(k)); |
9746
31a22d48f41f
scripts/io/strread.m scripts/io/textread.m: new functions
Soren Hauberg <hauberg@gmail.com>
parents:
diff
changeset
|
815 %! endfor |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14335
diff
changeset
|
816 %! aa = strread (str, "%f %*s"); |
15844
8f0d07f8390b
Fix assertions with "observed" and "expected" out of order.
Ben Abbott <bpabbott@mac.com>
parents:
15263
diff
changeset
|
817 %! assert (aa, a, 1e-6); |
9746
31a22d48f41f
scripts/io/strread.m scripts/io/textread.m: new functions
Soren Hauberg <hauberg@gmail.com>
parents:
diff
changeset
|
818 |
31a22d48f41f
scripts/io/strread.m scripts/io/textread.m: new functions
Soren Hauberg <hauberg@gmail.com>
parents:
diff
changeset
|
819 %!test |
14835
821708f96efd
strread.m: more robust word parsing and style improvements
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14802
diff
changeset
|
820 %! str = sprintf ("/* this is\nacomment*/ 1 2 3"); |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14335
diff
changeset
|
821 %! a = strread (str, "%f", "commentstyle", "c"); |
9746
31a22d48f41f
scripts/io/strread.m scripts/io/textread.m: new functions
Soren Hauberg <hauberg@gmail.com>
parents:
diff
changeset
|
822 %! assert (a, [1; 2; 3]); |
31a22d48f41f
scripts/io/strread.m scripts/io/textread.m: new functions
Soren Hauberg <hauberg@gmail.com>
parents:
diff
changeset
|
823 |
11127
64728cd28d7a
strread.m: Improve compatibility with Matlab.
Ben Abbott <bpabbott@mac.com>
parents:
11120
diff
changeset
|
824 %!test |
12914
ac00ae83ea2e
More compatibility improvements for textscan and strread
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12891
diff
changeset
|
825 %! str = "# comment\n# comment\n1 2 3"; |
14835
821708f96efd
strread.m: more robust word parsing and style improvements
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14802
diff
changeset
|
826 %! [a, b] = strread (str, "%n %s", "commentstyle", "shell", "endofline", "\n"); |
12914
ac00ae83ea2e
More compatibility improvements for textscan and strread
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12891
diff
changeset
|
827 %! assert (a, [1; 3]); |
ac00ae83ea2e
More compatibility improvements for textscan and strread
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12891
diff
changeset
|
828 %! assert (b, {"2"}); |
ac00ae83ea2e
More compatibility improvements for textscan and strread
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12891
diff
changeset
|
829 |
ac00ae83ea2e
More compatibility improvements for textscan and strread
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12891
diff
changeset
|
830 %!test |
11127
64728cd28d7a
strread.m: Improve compatibility with Matlab.
Ben Abbott <bpabbott@mac.com>
parents:
11120
diff
changeset
|
831 %! str = sprintf ("Tom 100 miles/hr\nDick 90 miles/hr\nHarry 80 miles/hr"); |
64728cd28d7a
strread.m: Improve compatibility with Matlab.
Ben Abbott <bpabbott@mac.com>
parents:
11120
diff
changeset
|
832 %! fmt = "%s %f miles/hr"; |
64728cd28d7a
strread.m: Improve compatibility with Matlab.
Ben Abbott <bpabbott@mac.com>
parents:
11120
diff
changeset
|
833 %! c = cell (1, 2); |
64728cd28d7a
strread.m: Improve compatibility with Matlab.
Ben Abbott <bpabbott@mac.com>
parents:
11120
diff
changeset
|
834 %! [c{:}] = strread (str, fmt); |
64728cd28d7a
strread.m: Improve compatibility with Matlab.
Ben Abbott <bpabbott@mac.com>
parents:
11120
diff
changeset
|
835 %! assert (c{1}, {"Tom"; "Dick"; "Harry"}) |
64728cd28d7a
strread.m: Improve compatibility with Matlab.
Ben Abbott <bpabbott@mac.com>
parents:
11120
diff
changeset
|
836 %! assert (c{2}, [100; 90; 80]) |
64728cd28d7a
strread.m: Improve compatibility with Matlab.
Ben Abbott <bpabbott@mac.com>
parents:
11120
diff
changeset
|
837 |
64728cd28d7a
strread.m: Improve compatibility with Matlab.
Ben Abbott <bpabbott@mac.com>
parents:
11120
diff
changeset
|
838 %!test |
64728cd28d7a
strread.m: Improve compatibility with Matlab.
Ben Abbott <bpabbott@mac.com>
parents:
11120
diff
changeset
|
839 %! a = strread ("a b c, d e, , f", "%s", "delimiter", ","); |
64728cd28d7a
strread.m: Improve compatibility with Matlab.
Ben Abbott <bpabbott@mac.com>
parents:
11120
diff
changeset
|
840 %! assert (a, {"a b c"; "d e"; ""; "f"}); |
64728cd28d7a
strread.m: Improve compatibility with Matlab.
Ben Abbott <bpabbott@mac.com>
parents:
11120
diff
changeset
|
841 |
12866
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
842 %!test |
17336
b81b9d079515
Use '##' for comments which stand alone on a line.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
843 %! ## Bug #33536 |
12866
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
844 %! [a, b, c] = strread ("1,,2", "%s%s%s", "delimiter", ","); |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14335
diff
changeset
|
845 %! assert (a{1}, "1"); |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14335
diff
changeset
|
846 %! assert (b{1}, ""); |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14335
diff
changeset
|
847 %! assert (c{1}, "2"); |
12866
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
848 |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
849 %!test |
17336
b81b9d079515
Use '##' for comments which stand alone on a line.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
850 %! ## Bug #33536 |
12891
f5a3f77d51aa
strread.m, textscan.m: More Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12879
diff
changeset
|
851 %! a = strread ("[SomeText]", "[%s", "delimiter", "]"); |
f5a3f77d51aa
strread.m, textscan.m: More Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12879
diff
changeset
|
852 %! assert (a{1}, "SomeText"); |
12866
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
853 |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
854 %!test |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
855 %! dat = "Data file.\r\n= = = = =\r\nCOMPANY : <Company name>\r\n"; |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14335
diff
changeset
|
856 %! a = strread (dat, "%s", "delimiter", "\n", "whitespace", "", "endofline", "\r\n"); |
12866
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
857 %! assert (a{2}, "= = = = ="); |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
858 %! assert (double (a{3}(end-5:end)), [32 110 97 109 101 62]); |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
859 |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
860 %!test |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14335
diff
changeset
|
861 %! [a, b, c, d] = strread ("1,2,3,,5,6", "%d%f%d%f", "delimiter", ","); |
12914
ac00ae83ea2e
More compatibility improvements for textscan and strread
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12891
diff
changeset
|
862 %! assert (c, int32 (3)); |
12866
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
863 %! assert (d, NaN); |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
864 |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
865 %!test |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14335
diff
changeset
|
866 %! [a, b, c, d] = strread ("1,2,3,,5,6\n", "%d%d%f%d", "delimiter", ","); |
12866
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
867 %! assert (c, [3; NaN]); |
12914
ac00ae83ea2e
More compatibility improvements for textscan and strread
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12891
diff
changeset
|
868 %! assert (d, int32 ([0; 0])); |
12866
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
869 |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
870 %!test |
17336
b81b9d079515
Use '##' for comments which stand alone on a line.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
871 %! ## Default format (= %f) |
12866
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
872 %1 [a, b, c] = strread ("0.12 0.234 0.3567"); |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
873 %1 assert (a, 0.12); |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
874 %1 assert (b, 0.234); |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
875 %1 assert (c, 0.3567); |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
876 |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
877 %!test |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14335
diff
changeset
|
878 %! [a, b] = strread ("0.41 8.24 3.57 6.24 9.27", "%f%f", 2, "delimiter", " "); |
12866
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
879 %1 assert (a, [0.41; 3.57]); |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
880 |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
881 %!test |
17336
b81b9d079515
Use '##' for comments which stand alone on a line.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
882 %! ## TreatAsEmpty |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14335
diff
changeset
|
883 %! [a, b, c, d] = strread ("1,2,3,NN,5,6\n", "%d%d%d%f", "delimiter", ",", "TreatAsEmpty", "NN"); |
12914
ac00ae83ea2e
More compatibility improvements for textscan and strread
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12891
diff
changeset
|
884 %! assert (c, int32 ([3; 0])); |
12866
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
885 %! assert (d, [NaN; NaN]); |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
886 |
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
887 %!test |
17336
b81b9d079515
Use '##' for comments which stand alone on a line.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
888 %! ## No delimiters at all besides EOL. Plain reading numbers & strings |
12866
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
889 %! str = "Text1Text2Text\nText398Text4Text\nText57Text"; |
14096
153581342e47
Always separate numeric fields by whitespace too; gracefully catch too wide literals & fixed width format conversion specifiers
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
13715
diff
changeset
|
890 %! [a, b] = strread (str, "Text%dText%1sText"); |
153581342e47
Always separate numeric fields by whitespace too; gracefully catch too wide literals & fixed width format conversion specifiers
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
13715
diff
changeset
|
891 %! assert (a, int32 ([1; 398; 57])); |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14335
diff
changeset
|
892 %! assert (b(1:2), {"2"; "4"}); |
14096
153581342e47
Always separate numeric fields by whitespace too; gracefully catch too wide literals & fixed width format conversion specifiers
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
13715
diff
changeset
|
893 %! assert (isempty (b{3}), true); |
12866
fe6e2afcd9ee
Revamp strread, textscan, textread functions for Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12469
diff
changeset
|
894 |
12891
f5a3f77d51aa
strread.m, textscan.m: More Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12879
diff
changeset
|
895 %% MultipleDelimsAsOne |
f5a3f77d51aa
strread.m, textscan.m: More Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12879
diff
changeset
|
896 %!test |
f5a3f77d51aa
strread.m, textscan.m: More Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12879
diff
changeset
|
897 %! str = "11, 12, 13,, 15\n21,, 23, 24, 25\n,, 33, 34, 35"; |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14335
diff
changeset
|
898 %! [a b c d] = strread (str, "%f %f %f %f", "delimiter", ",", "multipledelimsasone", 1, "endofline", "\n"); |
12891
f5a3f77d51aa
strread.m, textscan.m: More Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12879
diff
changeset
|
899 %! assert (a', [11, 21, NaN]); |
f5a3f77d51aa
strread.m, textscan.m: More Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12879
diff
changeset
|
900 %! assert (b', [12, 23, 33]); |
f5a3f77d51aa
strread.m, textscan.m: More Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12879
diff
changeset
|
901 %! assert (c', [13, 24, 34]); |
f5a3f77d51aa
strread.m, textscan.m: More Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12879
diff
changeset
|
902 %! assert (d', [15, 25, 35]); |
f5a3f77d51aa
strread.m, textscan.m: More Matlab compatability
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
12879
diff
changeset
|
903 |
13715
f8eca611e18f
When single-quoted, the strread() "delimiter", "endofline", and "whitespace"
Ben Abbott <bpabbott@mac.com>
parents:
13176
diff
changeset
|
904 %% delimiter as sq_string and dq_string |
14096
153581342e47
Always separate numeric fields by whitespace too; gracefully catch too wide literals & fixed width format conversion specifiers
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
13715
diff
changeset
|
905 %!test |
13715
f8eca611e18f
When single-quoted, the strread() "delimiter", "endofline", and "whitespace"
Ben Abbott <bpabbott@mac.com>
parents:
13176
diff
changeset
|
906 %! assert (strread ("1\n2\n3", "%d", "delimiter", "\n"), |
f8eca611e18f
When single-quoted, the strread() "delimiter", "endofline", and "whitespace"
Ben Abbott <bpabbott@mac.com>
parents:
13176
diff
changeset
|
907 %! strread ("1\n2\n3", "%d", "delimiter", '\n')) |
f8eca611e18f
When single-quoted, the strread() "delimiter", "endofline", and "whitespace"
Ben Abbott <bpabbott@mac.com>
parents:
13176
diff
changeset
|
908 |
f8eca611e18f
When single-quoted, the strread() "delimiter", "endofline", and "whitespace"
Ben Abbott <bpabbott@mac.com>
parents:
13176
diff
changeset
|
909 %% whitespace as sq_string and dq_string |
14096
153581342e47
Always separate numeric fields by whitespace too; gracefully catch too wide literals & fixed width format conversion specifiers
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
13715
diff
changeset
|
910 %!test |
13715
f8eca611e18f
When single-quoted, the strread() "delimiter", "endofline", and "whitespace"
Ben Abbott <bpabbott@mac.com>
parents:
13176
diff
changeset
|
911 %! assert (strread ("1\b2\r3\b4\t5", "%d", "whitespace", "\b\r\n\t"), |
f8eca611e18f
When single-quoted, the strread() "delimiter", "endofline", and "whitespace"
Ben Abbott <bpabbott@mac.com>
parents:
13176
diff
changeset
|
912 %! strread ("1\b2\r3\b4\t5", "%d", "whitespace", '\b\r\n\t')) |
14096
153581342e47
Always separate numeric fields by whitespace too; gracefully catch too wide literals & fixed width format conversion specifiers
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
13715
diff
changeset
|
913 |
153581342e47
Always separate numeric fields by whitespace too; gracefully catch too wide literals & fixed width format conversion specifiers
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
13715
diff
changeset
|
914 %!test |
153581342e47
Always separate numeric fields by whitespace too; gracefully catch too wide literals & fixed width format conversion specifiers
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
13715
diff
changeset
|
915 %! str = "0.31 0.86 0.94\n 0.60 0.72 0.87"; |
153581342e47
Always separate numeric fields by whitespace too; gracefully catch too wide literals & fixed width format conversion specifiers
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
13715
diff
changeset
|
916 %! fmt = "%f %f %f"; |
153581342e47
Always separate numeric fields by whitespace too; gracefully catch too wide literals & fixed width format conversion specifiers
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
13715
diff
changeset
|
917 %! args = {"delimiter", " ", "endofline", "\n", "whitespace", " "}; |
153581342e47
Always separate numeric fields by whitespace too; gracefully catch too wide literals & fixed width format conversion specifiers
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
13715
diff
changeset
|
918 %! [a, b, c] = strread (str, fmt, args {:}); |
153581342e47
Always separate numeric fields by whitespace too; gracefully catch too wide literals & fixed width format conversion specifiers
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
13715
diff
changeset
|
919 %! assert (a, [0.31; 0.60], 0.01) |
153581342e47
Always separate numeric fields by whitespace too; gracefully catch too wide literals & fixed width format conversion specifiers
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
13715
diff
changeset
|
920 %! assert (b, [0.86; 0.72], 0.01) |
153581342e47
Always separate numeric fields by whitespace too; gracefully catch too wide literals & fixed width format conversion specifiers
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
13715
diff
changeset
|
921 %! assert (c, [0.94; 0.87], 0.01) |
153581342e47
Always separate numeric fields by whitespace too; gracefully catch too wide literals & fixed width format conversion specifiers
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
13715
diff
changeset
|
922 |
153581342e47
Always separate numeric fields by whitespace too; gracefully catch too wide literals & fixed width format conversion specifiers
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
13715
diff
changeset
|
923 %!test |
153581342e47
Always separate numeric fields by whitespace too; gracefully catch too wide literals & fixed width format conversion specifiers
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
13715
diff
changeset
|
924 %! str = "0.31,0.86,0.94\n0.60,0.72,0.87"; |
153581342e47
Always separate numeric fields by whitespace too; gracefully catch too wide literals & fixed width format conversion specifiers
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
13715
diff
changeset
|
925 %! fmt = "%f %f %f"; |
153581342e47
Always separate numeric fields by whitespace too; gracefully catch too wide literals & fixed width format conversion specifiers
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
13715
diff
changeset
|
926 %! args = {"delimiter", ",", "endofline", "\n", "whitespace", " "}; |
153581342e47
Always separate numeric fields by whitespace too; gracefully catch too wide literals & fixed width format conversion specifiers
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
13715
diff
changeset
|
927 %! [a, b, c] = strread (str, fmt, args {:}); |
153581342e47
Always separate numeric fields by whitespace too; gracefully catch too wide literals & fixed width format conversion specifiers
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
13715
diff
changeset
|
928 %! assert (a, [0.31; 0.60], 0.01) |
153581342e47
Always separate numeric fields by whitespace too; gracefully catch too wide literals & fixed width format conversion specifiers
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
13715
diff
changeset
|
929 %! assert (b, [0.86; 0.72], 0.01) |
153581342e47
Always separate numeric fields by whitespace too; gracefully catch too wide literals & fixed width format conversion specifiers
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
13715
diff
changeset
|
930 %! assert (c, [0.94; 0.87], 0.01) |
153581342e47
Always separate numeric fields by whitespace too; gracefully catch too wide literals & fixed width format conversion specifiers
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
13715
diff
changeset
|
931 |
153581342e47
Always separate numeric fields by whitespace too; gracefully catch too wide literals & fixed width format conversion specifiers
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
13715
diff
changeset
|
932 %!test |
153581342e47
Always separate numeric fields by whitespace too; gracefully catch too wide literals & fixed width format conversion specifiers
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
13715
diff
changeset
|
933 %! str = "0.31 0.86 0.94\n 0.60 0.72 0.87"; |
153581342e47
Always separate numeric fields by whitespace too; gracefully catch too wide literals & fixed width format conversion specifiers
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
13715
diff
changeset
|
934 %! fmt = "%f %f %f"; |
153581342e47
Always separate numeric fields by whitespace too; gracefully catch too wide literals & fixed width format conversion specifiers
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
13715
diff
changeset
|
935 %! args = {"delimiter", ",", "endofline", "\n", "whitespace", " "}; |
153581342e47
Always separate numeric fields by whitespace too; gracefully catch too wide literals & fixed width format conversion specifiers
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
13715
diff
changeset
|
936 %! [a, b, c] = strread (str, fmt, args {:}); |
153581342e47
Always separate numeric fields by whitespace too; gracefully catch too wide literals & fixed width format conversion specifiers
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
13715
diff
changeset
|
937 %! assert (a, [0.31; 0.60], 0.01) |
153581342e47
Always separate numeric fields by whitespace too; gracefully catch too wide literals & fixed width format conversion specifiers
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
13715
diff
changeset
|
938 %! assert (b, [0.86; 0.72], 0.01) |
153581342e47
Always separate numeric fields by whitespace too; gracefully catch too wide literals & fixed width format conversion specifiers
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
13715
diff
changeset
|
939 %! assert (c, [0.94; 0.87], 0.01) |
153581342e47
Always separate numeric fields by whitespace too; gracefully catch too wide literals & fixed width format conversion specifiers
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
13715
diff
changeset
|
940 |
153581342e47
Always separate numeric fields by whitespace too; gracefully catch too wide literals & fixed width format conversion specifiers
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
13715
diff
changeset
|
941 %!test |
153581342e47
Always separate numeric fields by whitespace too; gracefully catch too wide literals & fixed width format conversion specifiers
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
13715
diff
changeset
|
942 %! str = "0.31, 0.86, 0.94\n 0.60, 0.72, 0.87"; |
153581342e47
Always separate numeric fields by whitespace too; gracefully catch too wide literals & fixed width format conversion specifiers
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
13715
diff
changeset
|
943 %! fmt = "%f %f %f"; |
153581342e47
Always separate numeric fields by whitespace too; gracefully catch too wide literals & fixed width format conversion specifiers
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
13715
diff
changeset
|
944 %! args = {"delimiter", ",", "endofline", "\n", "whitespace", " "}; |
153581342e47
Always separate numeric fields by whitespace too; gracefully catch too wide literals & fixed width format conversion specifiers
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
13715
diff
changeset
|
945 %! [a, b, c] = strread (str, fmt, args {:}); |
153581342e47
Always separate numeric fields by whitespace too; gracefully catch too wide literals & fixed width format conversion specifiers
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
13715
diff
changeset
|
946 %! assert (a, [0.31; 0.60], 0.01) |
153581342e47
Always separate numeric fields by whitespace too; gracefully catch too wide literals & fixed width format conversion specifiers
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
13715
diff
changeset
|
947 %! assert (b, [0.86; 0.72], 0.01) |
153581342e47
Always separate numeric fields by whitespace too; gracefully catch too wide literals & fixed width format conversion specifiers
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
13715
diff
changeset
|
948 %! assert (c, [0.94; 0.87], 0.01) |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14335
diff
changeset
|
949 |
14497
9fc75cdf61ab
strread.m: Trap empty string input (bug #35999)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14366
diff
changeset
|
950 %!test |
14835
821708f96efd
strread.m: more robust word parsing and style improvements
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14802
diff
changeset
|
951 %! [a, b] = strread (["Empty 1" char(10)], "Empty%s %f"); |
14800
a922f768ee09
textscan, strread: improved ML compatibility (bug 36398)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14799
diff
changeset
|
952 %! assert (a{1}, '1'); |
a922f768ee09
textscan, strread: improved ML compatibility (bug 36398)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14799
diff
changeset
|
953 %! assert (b, NaN); |
a922f768ee09
textscan, strread: improved ML compatibility (bug 36398)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14799
diff
changeset
|
954 |
a922f768ee09
textscan, strread: improved ML compatibility (bug 36398)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14799
diff
changeset
|
955 %!test |
14835
821708f96efd
strread.m: more robust word parsing and style improvements
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14802
diff
changeset
|
956 %! [a, b] = strread (["Empty" char(10)], "Empty%f %f"); |
14800
a922f768ee09
textscan, strread: improved ML compatibility (bug 36398)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14799
diff
changeset
|
957 %! assert (a, NaN); |
a922f768ee09
textscan, strread: improved ML compatibility (bug 36398)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14799
diff
changeset
|
958 %! assert (b, NaN); |
a922f768ee09
textscan, strread: improved ML compatibility (bug 36398)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14799
diff
changeset
|
959 |
a922f768ee09
textscan, strread: improved ML compatibility (bug 36398)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14799
diff
changeset
|
960 %!test |
17336
b81b9d079515
Use '##' for comments which stand alone on a line.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
961 %! ## Bug #35999 |
14497
9fc75cdf61ab
strread.m: Trap empty string input (bug #35999)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14366
diff
changeset
|
962 %! [a, b, c] = strread ("", "%f"); |
9fc75cdf61ab
strread.m: Trap empty string input (bug #35999)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14366
diff
changeset
|
963 %! assert (isempty (a)); |
9fc75cdf61ab
strread.m: Trap empty string input (bug #35999)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14366
diff
changeset
|
964 %! assert (isempty (b)); |
9fc75cdf61ab
strread.m: Trap empty string input (bug #35999)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14366
diff
changeset
|
965 %! assert (isempty (c)); |
9fc75cdf61ab
strread.m: Trap empty string input (bug #35999)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14366
diff
changeset
|
966 |
15263
2136343014d5
bug #37023 (wrong reading of lines starting and/or ending with whitespace)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14868
diff
changeset
|
967 %!test |
17336
b81b9d079515
Use '##' for comments which stand alone on a line.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
968 %! ## bug #37023 |
15263
2136343014d5
bug #37023 (wrong reading of lines starting and/or ending with whitespace)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14868
diff
changeset
|
969 %! [a, b] = strread (" 1. 1 \n 2 3 \n", "%f %f", "endofline", "\n"); |
2136343014d5
bug #37023 (wrong reading of lines starting and/or ending with whitespace)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14868
diff
changeset
|
970 %! assert (a, [1; 2], 1e-15); |
2136343014d5
bug #37023 (wrong reading of lines starting and/or ending with whitespace)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14868
diff
changeset
|
971 %! assert (b, [1; 3], 1e-15); |
2136343014d5
bug #37023 (wrong reading of lines starting and/or ending with whitespace)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14868
diff
changeset
|
972 |
16306
4a3b6a80db2e
strread.m: fix division by zero when called with no output args; test added
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
16094
diff
changeset
|
973 %% Test for no output arg (interactive use) |
4a3b6a80db2e
strread.m: fix division by zero when called with no output args; test added
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
16094
diff
changeset
|
974 %!test |
4a3b6a80db2e
strread.m: fix division by zero when called with no output args; test added
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
16094
diff
changeset
|
975 %! assert (strread (",2,,4\n5,,7,", "", "delimiter", ","), [NaN; 2; NaN; 4; 5; NaN; 7]); |
4a3b6a80db2e
strread.m: fix division by zero when called with no output args; test added
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
16094
diff
changeset
|
976 |
14802
d5aee269b770
strread.m: catch unsupported ML format specifiers (bug #36464)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14800
diff
changeset
|
977 %% Unsupported format specifiers |
d5aee269b770
strread.m: catch unsupported ML format specifiers (bug #36464)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14800
diff
changeset
|
978 %!test |
14835
821708f96efd
strread.m: more robust word parsing and style improvements
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14802
diff
changeset
|
979 %!error <format specifiers are not supported> strread ("a", "%c") |
821708f96efd
strread.m: more robust word parsing and style improvements
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14802
diff
changeset
|
980 %!error <format specifiers are not supported> strread ("a", "%*c %d") |
821708f96efd
strread.m: more robust word parsing and style improvements
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14802
diff
changeset
|
981 %!error <format specifiers are not supported> strread ("a", "%q") |
821708f96efd
strread.m: more robust word parsing and style improvements
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14802
diff
changeset
|
982 %!error <format specifiers are not supported> strread ("a", "%*q %d") |
821708f96efd
strread.m: more robust word parsing and style improvements
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14802
diff
changeset
|
983 %!error <format specifiers are not supported> strread ("a", "%[a]") |
821708f96efd
strread.m: more robust word parsing and style improvements
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14802
diff
changeset
|
984 %!error <format specifiers are not supported> strread ("a", "%*[a] %d") |
821708f96efd
strread.m: more robust word parsing and style improvements
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14802
diff
changeset
|
985 %!error <format specifiers are not supported> strread ("a", "%[^a]") |
821708f96efd
strread.m: more robust word parsing and style improvements
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14802
diff
changeset
|
986 %!error <format specifiers are not supported> strread ("a", "%*[^a] %d") |
821708f96efd
strread.m: more robust word parsing and style improvements
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14802
diff
changeset
|
987 %!error <format specifiers are not supported> strread ("a", "%d8") |
821708f96efd
strread.m: more robust word parsing and style improvements
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14802
diff
changeset
|
988 %!error <format specifiers are not supported> strread ("a", "%*d8 %s") |
821708f96efd
strread.m: more robust word parsing and style improvements
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14802
diff
changeset
|
989 %!error <format specifiers are not supported> strread ("a", "%f64") |
821708f96efd
strread.m: more robust word parsing and style improvements
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14802
diff
changeset
|
990 %!error <format specifiers are not supported> strread ("a", "%*f64 %s") |
821708f96efd
strread.m: more robust word parsing and style improvements
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14802
diff
changeset
|
991 %!error <format specifiers are not supported> strread ("a", "%u32") |
821708f96efd
strread.m: more robust word parsing and style improvements
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14802
diff
changeset
|
992 %!error <format specifiers are not supported> strread ("a", "%*u32 %d") |
16571
4d8462fe15b9
strread.m: catch unknown format specifiers (bug #38834)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
16412
diff
changeset
|
993 |
4d8462fe15b9
strread.m: catch unknown format specifiers (bug #38834)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
16412
diff
changeset
|
994 %% Illegal format specifiers |
4d8462fe15b9
strread.m: catch unknown format specifiers (bug #38834)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
16412
diff
changeset
|
995 %!test |
4d8462fe15b9
strread.m: catch unknown format specifiers (bug #38834)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
16412
diff
changeset
|
996 %!error <unknown format specifier> strread ("1.0", "%z") |