Mercurial > octave
annotate libinterp/corefcn/dlmread.cc @ 24477:e8cb11de9383
test: Mark certain bugs as xtest when run on Mac platforms (bug #52627).
Don't report as errors failing tests related to bug #47413.
* dlmread.cc, str2double.cc, importdata.m, io.tst:
For BIST tests that fail due to bug #47413, protect test with
"testif ; ! ismac ()" so that it is not run on Mac platforms.
Duplicate failing test code, but protect it with:
%!xtest <47413>
%! ## Same test code as above, but intended only for test statistics on Mac.
%! if (! ismac ()), return; endif
so that it is run only on Mac platforms and contributes to xtest
statistics.
author | Rik <rik@octave.org> |
---|---|
date | Wed, 27 Dec 2017 12:41:45 -0800 |
parents | 8acd390d16c9 |
children | 194eb4bd202b |
rev | line source |
---|---|
7580
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1 /* |
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2 |
23219
3ac9f9ecfae5
maint: Update copyright dates.
John W. Eaton <jwe@octave.org>
parents:
23083
diff
changeset
|
3 Copyright (C) 2008-2017 Jonathan Stickel |
10804
3d5c6b84ddaf
speed-up fixes to dlmread
Jaroslav Hajek <highegg@gmail.com>
parents:
10718
diff
changeset
|
4 Copyright (C) 2010 Jaroslav Hajek |
7580
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
5 |
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
6 This file is part of Octave. |
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
7 |
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
8 Octave is free software; you can redistribute it and/or modify it |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22676
diff
changeset
|
9 under the terms of the GNU General Public License as published by |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22676
diff
changeset
|
10 the Free Software Foundation; either version 3 of the License, or |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22676
diff
changeset
|
11 (at your option) any later version. |
7580
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
12 |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22676
diff
changeset
|
13 Octave is distributed in the hope that it will be useful, but |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22676
diff
changeset
|
14 WITHOUT ANY WARRANTY; without even the implied warranty of |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22676
diff
changeset
|
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22676
diff
changeset
|
16 GNU General Public License for more details. |
7580
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
17 |
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
18 You should have received a copy of the GNU General Public License |
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
19 along with Octave; see the file COPYING. If not, see |
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
20 <http://www.gnu.org/licenses/>. |
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
21 |
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
22 */ |
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
23 |
7581 | 24 // Adapted from previous version of dlmread.occ as authored by Kai |
25 // Habel, but core code has been completely re-written. | |
7580
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
26 |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21593
diff
changeset
|
27 #if defined (HAVE_CONFIG_H) |
21301
40de9f8f23a6
Use '#include "config.h"' rather than <config.h>.
Rik <rik@octave.org>
parents:
21200
diff
changeset
|
28 # include "config.h" |
7580
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
29 #endif |
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
30 |
7581 | 31 #include <cctype> |
32 #include <fstream> | |
10804
3d5c6b84ddaf
speed-up fixes to dlmread
Jaroslav Hajek <highegg@gmail.com>
parents:
10718
diff
changeset
|
33 #include <limits> |
7581 | 34 |
9512
56e850e3b06f
dlmread: perform tilde expansion to filename argument
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
35 #include "file-ops.h" |
7580
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
36 #include "lo-ieee.h" |
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
37 |
15039
e753177cde93
maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents:
14501
diff
changeset
|
38 #include "defun.h" |
23738
8acd390d16c9
don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents:
23573
diff
changeset
|
39 #include "interpreter.h" |
10927
a9e9659e1dca
support file IDs in dlmread
Jaroslav Hajek <highegg@gmail.com>
parents:
10806
diff
changeset
|
40 #include "oct-stream.h" |
7580
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
41 #include "error.h" |
20940
48b2ad5ee801
maint: Rename oct-obj.[cc|h] to ovl.[cc|h] for clarity.
Rik <rik@octave.org>
parents:
20918
diff
changeset
|
42 #include "ovl.h" |
7580
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
43 #include "utils.h" |
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
44 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
45 static const octave_idx_type idx_max = |
23323
31be59137160
Don't error out if RANGE specification for dlmread contains large values.
Rik <rik@octave.org>
parents:
23307
diff
changeset
|
46 std::numeric_limits<octave_idx_type>::max () - 1; |
31be59137160
Don't error out if RANGE specification for dlmread contains large values.
Rik <rik@octave.org>
parents:
23307
diff
changeset
|
47 |
31be59137160
Don't error out if RANGE specification for dlmread contains large values.
Rik <rik@octave.org>
parents:
23307
diff
changeset
|
48 static const double idx_max_dbl = double (idx_max); |
10804
3d5c6b84ddaf
speed-up fixes to dlmread
Jaroslav Hajek <highegg@gmail.com>
parents:
10718
diff
changeset
|
49 |
7580
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
50 static bool |
10804
3d5c6b84ddaf
speed-up fixes to dlmread
Jaroslav Hajek <highegg@gmail.com>
parents:
10718
diff
changeset
|
51 read_cell_spec (std::istream& is, octave_idx_type& row, octave_idx_type& col) |
7580
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
52 { |
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
53 bool stat = false; |
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
54 |
7581 | 55 if (is.peek () == std::istream::traits_type::eof ()) |
7580
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
56 stat = true; |
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
57 else |
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
58 { |
7581 | 59 if (::isalpha (is.peek ())) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
60 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
61 col = 0; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
62 while (is && ::isalpha (is.peek ())) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
63 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
64 char ch = is.get (); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
65 col *= 26; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
66 if (ch >= 'a') |
10718
b8d76f4be94a
Fix spreadsheet style range option (bug #30183).
Rik <octave@nomad.inbox5.com>
parents:
10350
diff
changeset
|
67 col += ch - 'a' + 1; |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
68 else |
10718
b8d76f4be94a
Fix spreadsheet style range option (bug #30183).
Rik <octave@nomad.inbox5.com>
parents:
10350
diff
changeset
|
69 col += ch - 'A' + 1; |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
70 } |
21062
d9c1884d1aaa
maint: Eliminate space between variable and decrement '--' operator.
Rik <rik@octave.org>
parents:
20955
diff
changeset
|
71 col--; |
7580
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
72 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
73 if (is) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
74 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
75 is >> row; |
21062
d9c1884d1aaa
maint: Eliminate space between variable and decrement '--' operator.
Rik <rik@octave.org>
parents:
20955
diff
changeset
|
76 row--; |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
77 if (is) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
78 stat = true; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
79 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
80 } |
7580
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
81 } |
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
82 |
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
83 return stat; |
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
84 } |
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
85 |
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
86 static bool |
7581 | 87 parse_range_spec (const octave_value& range_spec, |
10804
3d5c6b84ddaf
speed-up fixes to dlmread
Jaroslav Hajek <highegg@gmail.com>
parents:
10718
diff
changeset
|
88 octave_idx_type& rlo, octave_idx_type& clo, |
3d5c6b84ddaf
speed-up fixes to dlmread
Jaroslav Hajek <highegg@gmail.com>
parents:
10718
diff
changeset
|
89 octave_idx_type& rup, octave_idx_type& cup) |
7580
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
90 { |
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
91 bool stat = true; |
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
92 |
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
93 if (range_spec.is_string ()) |
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
94 { |
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
95 std::istringstream is (range_spec.string_value ()); |
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
96 char ch = is.peek (); |
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
97 |
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
98 if (ch == '.' || ch == ':') |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
99 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
100 rlo = 0; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
101 clo = 0; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
102 ch = is.get (); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
103 if (ch == '.') |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
104 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
105 ch = is.get (); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
106 if (ch != '.') |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
107 stat = false; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
108 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
109 } |
7580
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
110 else |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
111 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
112 stat = read_cell_spec (is, rlo, clo); |
7580
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
113 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
114 if (stat) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
115 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
116 ch = is.peek (); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
117 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
118 if (ch == '.' || ch == ':') |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
119 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
120 ch = is.get (); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
121 if (ch == '.') |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
122 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
123 ch = is.get (); |
20955
77f5591878bf
maint: Use '! expr' rather than '!expr' to conform to coding guidelines.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
124 if (! is || ch != '.') |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
125 stat = false; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
126 } |
7580
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
127 |
23323
31be59137160
Don't error out if RANGE specification for dlmread contains large values.
Rik <rik@octave.org>
parents:
23307
diff
changeset
|
128 rup = idx_max; |
31be59137160
Don't error out if RANGE specification for dlmread contains large values.
Rik <rik@octave.org>
parents:
23307
diff
changeset
|
129 cup = idx_max; |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
130 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
131 else |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
132 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
133 rup = rlo; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
134 cup = clo; |
20955
77f5591878bf
maint: Use '! expr' rather than '!expr' to conform to coding guidelines.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
135 if (! is || ! is.eof ()) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
136 stat = false; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
137 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
138 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
139 } |
7580
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
140 |
20955
77f5591878bf
maint: Use '! expr' rather than '!expr' to conform to coding guidelines.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
141 if (stat && is && ! is.eof ()) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
142 stat = read_cell_spec (is, rup, cup); |
7580
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
143 |
20955
77f5591878bf
maint: Use '! expr' rather than '!expr' to conform to coding guidelines.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
144 if (! is || ! is.eof ()) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
145 stat = false; |
7580
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
146 } |
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
147 else if (range_spec.is_real_matrix () && range_spec.numel () == 4) |
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
148 { |
23323
31be59137160
Don't error out if RANGE specification for dlmread contains large values.
Rik <rik@octave.org>
parents:
23307
diff
changeset
|
149 ColumnVector range (range_spec.vector_value ()); |
31be59137160
Don't error out if RANGE specification for dlmread contains large values.
Rik <rik@octave.org>
parents:
23307
diff
changeset
|
150 // double --> unsigned int avoiding any overflow |
31be59137160
Don't error out if RANGE specification for dlmread contains large values.
Rik <rik@octave.org>
parents:
23307
diff
changeset
|
151 rlo = static_cast<octave_idx_type> (std::min (range(0), idx_max_dbl)); |
31be59137160
Don't error out if RANGE specification for dlmread contains large values.
Rik <rik@octave.org>
parents:
23307
diff
changeset
|
152 clo = static_cast<octave_idx_type> (std::min (range(1), idx_max_dbl)); |
31be59137160
Don't error out if RANGE specification for dlmread contains large values.
Rik <rik@octave.org>
parents:
23307
diff
changeset
|
153 rup = static_cast<octave_idx_type> (std::min (range(2), idx_max_dbl)); |
31be59137160
Don't error out if RANGE specification for dlmread contains large values.
Rik <rik@octave.org>
parents:
23307
diff
changeset
|
154 cup = static_cast<octave_idx_type> (std::min (range(3), idx_max_dbl)); |
7580
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
155 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
156 else |
7580
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
157 stat = false; |
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
158 |
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
159 return stat; |
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
160 } |
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
161 |
23738
8acd390d16c9
don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents:
23573
diff
changeset
|
162 DEFMETHOD (dlmread, interp, args, , |
8acd390d16c9
don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents:
23573
diff
changeset
|
163 doc: /* -*- texinfo -*- |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21733
diff
changeset
|
164 @deftypefn {} {@var{data} =} dlmread (@var{file}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21733
diff
changeset
|
165 @deftypefnx {} {@var{data} =} dlmread (@var{file}, @var{sep}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21733
diff
changeset
|
166 @deftypefnx {} {@var{data} =} dlmread (@var{file}, @var{sep}, @var{r0}, @var{c0}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21733
diff
changeset
|
167 @deftypefnx {} {@var{data} =} dlmread (@var{file}, @var{sep}, @var{range}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21733
diff
changeset
|
168 @deftypefnx {} {@var{data} =} dlmread (@dots{}, "emptyvalue", @var{EMPTYVAL}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21733
diff
changeset
|
169 Read numeric data from the text file @var{file} which uses the delimiter |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21733
diff
changeset
|
170 @var{sep} between data values. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21733
diff
changeset
|
171 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21733
diff
changeset
|
172 If @var{sep} is not defined the separator between fields is determined from |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21733
diff
changeset
|
173 the file itself. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21733
diff
changeset
|
174 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21733
diff
changeset
|
175 The optional scalar arguments @var{r0} and @var{c0} define the starting row |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21733
diff
changeset
|
176 and column of the data to be read. These values are indexed from zero, |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21733
diff
changeset
|
177 i.e., the first data row corresponds to an index of zero. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21733
diff
changeset
|
178 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21733
diff
changeset
|
179 The @var{range} parameter specifies exactly which data elements are read. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21733
diff
changeset
|
180 The first form of the parameter is a 4-element vector containing the upper |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21733
diff
changeset
|
181 left and lower right corners @code{[@var{R0},@var{C0},@var{R1},@var{C1}]} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21733
diff
changeset
|
182 where the indices are zero-based. Alternatively, a spreadsheet style |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21733
diff
changeset
|
183 form such as @qcode{"A2..Q15"} or @qcode{"T1:AA5"} can be used. The |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21733
diff
changeset
|
184 lowest alphabetical index @qcode{'A'} refers to the first column. The |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21733
diff
changeset
|
185 lowest row index is 1. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21733
diff
changeset
|
186 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21733
diff
changeset
|
187 @var{file} should be a filename or a file id given by @code{fopen}. In the |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21733
diff
changeset
|
188 latter case, the file is read until end of file is reached. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21733
diff
changeset
|
189 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21733
diff
changeset
|
190 The @qcode{"emptyvalue"} option may be used to specify the value used to |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21733
diff
changeset
|
191 fill empty fields. The default is zero. Note that any non-numeric values, |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21733
diff
changeset
|
192 such as text, are also replaced by the @qcode{"emptyvalue"}. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21733
diff
changeset
|
193 @seealso{csvread, textscan, textread, dlmwrite} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21733
diff
changeset
|
194 @end deftypefn */) |
7580
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
195 { |
7581 | 196 int nargin = args.length (); |
197 | |
10935
3cb4889dd6f7
support specific empty value in dlmread
Jaroslav Hajek <highegg@gmail.com>
parents:
10927
diff
changeset
|
198 double empty_value = 0.0; |
3cb4889dd6f7
support specific empty value in dlmread
Jaroslav Hajek <highegg@gmail.com>
parents:
10927
diff
changeset
|
199 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
200 if (nargin > 2 && args(nargin-2).is_string () |
10935
3cb4889dd6f7
support specific empty value in dlmread
Jaroslav Hajek <highegg@gmail.com>
parents:
10927
diff
changeset
|
201 && args(nargin-2).string_value () == "emptyvalue") |
3cb4889dd6f7
support specific empty value in dlmread
Jaroslav Hajek <highegg@gmail.com>
parents:
10927
diff
changeset
|
202 { |
3cb4889dd6f7
support specific empty value in dlmread
Jaroslav Hajek <highegg@gmail.com>
parents:
10927
diff
changeset
|
203 empty_value = args(nargin-1).double_value (); |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
204 |
10935
3cb4889dd6f7
support specific empty value in dlmread
Jaroslav Hajek <highegg@gmail.com>
parents:
10927
diff
changeset
|
205 nargin -= 2; |
3cb4889dd6f7
support specific empty value in dlmread
Jaroslav Hajek <highegg@gmail.com>
parents:
10927
diff
changeset
|
206 } |
3cb4889dd6f7
support specific empty value in dlmread
Jaroslav Hajek <highegg@gmail.com>
parents:
10927
diff
changeset
|
207 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
208 if (nargin < 1 || nargin > 4) |
20802
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20713
diff
changeset
|
209 print_usage (); |
7580
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
210 |
23457
21baad6b35c4
maint: Use C++11 nullptr rather than 0 or NULL when possible.
Rik <rik@octave.org>
parents:
23395
diff
changeset
|
211 std::istream *input = nullptr; |
11389
934ed3e07542
dlmread: simplify file name/id logic
John W. Eaton <jwe@octave.org>
parents:
10935
diff
changeset
|
212 std::ifstream input_file; |
10927
a9e9659e1dca
support file IDs in dlmread
Jaroslav Hajek <highegg@gmail.com>
parents:
10806
diff
changeset
|
213 |
a9e9659e1dca
support file IDs in dlmread
Jaroslav Hajek <highegg@gmail.com>
parents:
10806
diff
changeset
|
214 if (args(0).is_string ()) |
7580
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
215 { |
20713
2469d78a1d8b
Consistently use 'filename' rather than 'file name' throughout code base.
Rik <rik@octave.org>
parents:
20555
diff
changeset
|
216 // Filename. |
10927
a9e9659e1dca
support file IDs in dlmread
Jaroslav Hajek <highegg@gmail.com>
parents:
10806
diff
changeset
|
217 std::string fname (args(0).string_value ()); |
a9e9659e1dca
support file IDs in dlmread
Jaroslav Hajek <highegg@gmail.com>
parents:
10806
diff
changeset
|
218 |
21733
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
219 std::string tname = octave::sys::file_ops::tilde_expand (fname); |
10927
a9e9659e1dca
support file IDs in dlmread
Jaroslav Hajek <highegg@gmail.com>
parents:
10806
diff
changeset
|
220 |
21593
e3888aa9a4d1
Restore tilde expansion for dlmread lost in fe5ed6d7fb10.
Rik <rik@octave.org>
parents:
21592
diff
changeset
|
221 tname = find_data_file_in_load_path ("dlmread", tname); |
21592
fe5ed6d7fb10
* dlmread.cc (Fdlmread): Search loadpath for file (bug #47628).
John W. Eaton <jwe@octave.org>
parents:
21362
diff
changeset
|
222 |
11389
934ed3e07542
dlmread: simplify file name/id logic
John W. Eaton <jwe@octave.org>
parents:
10935
diff
changeset
|
223 input_file.open (tname.c_str (), std::ios::in); |
934ed3e07542
dlmread: simplify file name/id logic
John W. Eaton <jwe@octave.org>
parents:
10935
diff
changeset
|
224 |
934ed3e07542
dlmread: simplify file name/id logic
John W. Eaton <jwe@octave.org>
parents:
10935
diff
changeset
|
225 if (! input_file) |
20831
35241c4b696c
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20802
diff
changeset
|
226 error ("dlmread: unable to open file '%s'", fname.c_str ()); |
35241c4b696c
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20802
diff
changeset
|
227 |
35241c4b696c
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20802
diff
changeset
|
228 input = &input_file; |
10927
a9e9659e1dca
support file IDs in dlmread
Jaroslav Hajek <highegg@gmail.com>
parents:
10806
diff
changeset
|
229 } |
a9e9659e1dca
support file IDs in dlmread
Jaroslav Hajek <highegg@gmail.com>
parents:
10806
diff
changeset
|
230 else if (args(0).is_scalar_type ()) |
a9e9659e1dca
support file IDs in dlmread
Jaroslav Hajek <highegg@gmail.com>
parents:
10806
diff
changeset
|
231 { |
23738
8acd390d16c9
don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents:
23573
diff
changeset
|
232 octave::stream_list& streams = interp.get_stream_list (); |
8acd390d16c9
don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents:
23573
diff
changeset
|
233 |
8acd390d16c9
don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents:
23573
diff
changeset
|
234 octave::stream is = streams.lookup (args(0), "dlmread"); |
11389
934ed3e07542
dlmread: simplify file name/id logic
John W. Eaton <jwe@octave.org>
parents:
10935
diff
changeset
|
235 |
934ed3e07542
dlmread: simplify file name/id logic
John W. Eaton <jwe@octave.org>
parents:
10935
diff
changeset
|
236 input = is.input_stream (); |
934ed3e07542
dlmread: simplify file name/id logic
John W. Eaton <jwe@octave.org>
parents:
10935
diff
changeset
|
237 |
10927
a9e9659e1dca
support file IDs in dlmread
Jaroslav Hajek <highegg@gmail.com>
parents:
10806
diff
changeset
|
238 if (! input) |
20831
35241c4b696c
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20802
diff
changeset
|
239 error ("dlmread: stream FILE not open for input"); |
10927
a9e9659e1dca
support file IDs in dlmread
Jaroslav Hajek <highegg@gmail.com>
parents:
10806
diff
changeset
|
240 } |
a9e9659e1dca
support file IDs in dlmread
Jaroslav Hajek <highegg@gmail.com>
parents:
10806
diff
changeset
|
241 else |
20831
35241c4b696c
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20802
diff
changeset
|
242 error ("dlmread: FILE argument must be a string or file id"); |
7581 | 243 |
244 // Set default separator. | |
7580
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
245 std::string sep; |
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
246 if (nargin > 1) |
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
247 { |
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
248 if (args(1).is_sq_string ()) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
249 sep = do_string_escapes (args(1).string_value ()); |
7580
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
250 else |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
251 sep = args(1).string_value (); |
7580
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
252 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
253 |
7581 | 254 // Take a subset if a range was given. |
18100
6a71e5030df5
Follow coding convention of defining and initializing only 1 variable per line in liboctinterp.
Rik <rik@octave.org>
parents:
17787
diff
changeset
|
255 octave_idx_type r0 = 0; |
6a71e5030df5
Follow coding convention of defining and initializing only 1 variable per line in liboctinterp.
Rik <rik@octave.org>
parents:
17787
diff
changeset
|
256 octave_idx_type c0 = 0; |
23323
31be59137160
Don't error out if RANGE specification for dlmread contains large values.
Rik <rik@octave.org>
parents:
23307
diff
changeset
|
257 octave_idx_type r1 = idx_max; |
31be59137160
Don't error out if RANGE specification for dlmread contains large values.
Rik <rik@octave.org>
parents:
23307
diff
changeset
|
258 octave_idx_type c1 = idx_max; |
7580
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
259 if (nargin > 2) |
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
260 { |
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
261 if (nargin == 3) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
262 { |
20955
77f5591878bf
maint: Use '! expr' rather than '!expr' to conform to coding guidelines.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
263 if (! parse_range_spec (args(2), r0, c0, r1, c1)) |
11553
01f703952eff
Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
264 error ("dlmread: error parsing RANGE"); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
265 } |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
266 else if (nargin == 4) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
267 { |
10804
3d5c6b84ddaf
speed-up fixes to dlmread
Jaroslav Hajek <highegg@gmail.com>
parents:
10718
diff
changeset
|
268 r0 = args(2).idx_type_value (); |
3d5c6b84ddaf
speed-up fixes to dlmread
Jaroslav Hajek <highegg@gmail.com>
parents:
10718
diff
changeset
|
269 c0 = args(3).idx_type_value (); |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
270 } |
10804
3d5c6b84ddaf
speed-up fixes to dlmread
Jaroslav Hajek <highegg@gmail.com>
parents:
10718
diff
changeset
|
271 |
3d5c6b84ddaf
speed-up fixes to dlmread
Jaroslav Hajek <highegg@gmail.com>
parents:
10718
diff
changeset
|
272 if (r0 < 0 || c0 < 0) |
11553
01f703952eff
Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
273 error ("dlmread: left & top must be positive"); |
23323
31be59137160
Don't error out if RANGE specification for dlmread contains large values.
Rik <rik@octave.org>
parents:
23307
diff
changeset
|
274 |
23394
7ca04e85f9e3
maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents:
23323
diff
changeset
|
275 // Short-circuit and return if range is empty |
23323
31be59137160
Don't error out if RANGE specification for dlmread contains large values.
Rik <rik@octave.org>
parents:
23307
diff
changeset
|
276 if (r1 < r0 || c1 < c0) |
31be59137160
Don't error out if RANGE specification for dlmread contains large values.
Rik <rik@octave.org>
parents:
23307
diff
changeset
|
277 return ovl (Matrix (0,0)); |
7580
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
278 } |
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
279 |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
280 octave_idx_type i = 0; |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
281 octave_idx_type j = 0; |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
282 octave_idx_type r = 1; |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
283 octave_idx_type c = 1; |
22666
68d5c4759783
dlmread: Return correct number of columns when line ends with separator (bug #42025).
Rik <rik@octave.org>
parents:
22657
diff
changeset
|
284 // Start with a reasonable size to avoid constant resizing of matrix. |
68d5c4759783
dlmread: Return correct number of columns when line ends with separator (bug #42025).
Rik <rik@octave.org>
parents:
22657
diff
changeset
|
285 octave_idx_type rmax = 32; |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
286 octave_idx_type cmax = 0; |
7581 | 287 |
22666
68d5c4759783
dlmread: Return correct number of columns when line ends with separator (bug #42025).
Rik <rik@octave.org>
parents:
22657
diff
changeset
|
288 Matrix rdata (rmax, cmax, empty_value); |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
289 ComplexMatrix cdata; |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
290 |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
291 bool iscmplx = false; |
22656
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
292 bool sep_is_wspace = (sep.find_first_of (" \t") != std::string::npos); |
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
293 bool auto_sep_is_wspace = false; |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
294 |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
295 std::string line; |
7581 | 296 |
23323
31be59137160
Don't error out if RANGE specification for dlmread contains large values.
Rik <rik@octave.org>
parents:
23307
diff
changeset
|
297 // Skip the r0 leading lines |
31be59137160
Don't error out if RANGE specification for dlmread contains large values.
Rik <rik@octave.org>
parents:
23307
diff
changeset
|
298 octave_idx_type rcnt = r0; |
31be59137160
Don't error out if RANGE specification for dlmread contains large values.
Rik <rik@octave.org>
parents:
23307
diff
changeset
|
299 while (rcnt > 0 && getline (*input, line)) |
31be59137160
Don't error out if RANGE specification for dlmread contains large values.
Rik <rik@octave.org>
parents:
23307
diff
changeset
|
300 rcnt--; |
31be59137160
Don't error out if RANGE specification for dlmread contains large values.
Rik <rik@octave.org>
parents:
23307
diff
changeset
|
301 |
31be59137160
Don't error out if RANGE specification for dlmread contains large values.
Rik <rik@octave.org>
parents:
23307
diff
changeset
|
302 if (rcnt > 0) |
31be59137160
Don't error out if RANGE specification for dlmread contains large values.
Rik <rik@octave.org>
parents:
23307
diff
changeset
|
303 return ovl (Matrix (0,0)); // Not enough lines in file to satisfy RANGE |
31be59137160
Don't error out if RANGE specification for dlmread contains large values.
Rik <rik@octave.org>
parents:
23307
diff
changeset
|
304 else |
31be59137160
Don't error out if RANGE specification for dlmread contains large values.
Rik <rik@octave.org>
parents:
23307
diff
changeset
|
305 r1 -= r0; |
7581 | 306 |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
307 std::istringstream tmp_stream; |
7581 | 308 |
22656
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
309 // Read the data one field at a time, growing the data matrix as needed. |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
310 while (getline (*input, line)) |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
311 { |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
312 // Skip blank lines for compatibility. |
22656
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
313 if ((! sep_is_wspace || auto_sep_is_wspace) |
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
314 && line.find_first_not_of (" \t") == std::string::npos) |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
315 continue; |
7580
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
316 |
22656
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
317 // Infer separator from file if delimiter is blank. |
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
318 if (sep.empty ()) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
319 { |
22621
e7699adac1d0
Do a better job of delimiter auto-dedection in dlmread (bug #42022).
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
320 // Skip leading whitespace. |
e7699adac1d0
Do a better job of delimiter auto-dedection in dlmread (bug #42022).
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
321 size_t pos1 = line.find_first_not_of (" \t"); |
e7699adac1d0
Do a better job of delimiter auto-dedection in dlmread (bug #42022).
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
322 |
22656
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
323 // For Matlab compatibility, blank delimiter should |
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
324 // correspond to whitespace (space and tab). |
22621
e7699adac1d0
Do a better job of delimiter auto-dedection in dlmread (bug #42022).
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
325 size_t n = line.find_first_of (",:; \t", pos1); |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
326 if (n == std::string::npos) |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
327 { |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
328 sep = " \t"; |
22656
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
329 auto_sep_is_wspace = true; |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
330 } |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
331 else |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
332 { |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
333 char ch = line.at (n); |
7580
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
334 |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
335 switch (line.at (n)) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
336 { |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
337 case ' ': |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
338 case '\t': |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
339 sep = " \t"; |
22656
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
340 auto_sep_is_wspace = true; |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
341 break; |
7580
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
342 |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
343 default: |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
344 sep = ch; |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
345 break; |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
346 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
347 } |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
348 } |
10804
3d5c6b84ddaf
speed-up fixes to dlmread
Jaroslav Hajek <highegg@gmail.com>
parents:
10718
diff
changeset
|
349 |
22666
68d5c4759783
dlmread: Return correct number of columns when line ends with separator (bug #42025).
Rik <rik@octave.org>
parents:
22657
diff
changeset
|
350 // Estimate the number of columns from first line of data. |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
351 if (cmax == 0) |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
352 { |
22656
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
353 size_t pos1, pos2; |
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
354 if (auto_sep_is_wspace) |
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
355 pos1 = line.find_first_not_of (" \t"); |
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
356 else |
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
357 pos1 = 0; |
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
358 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
359 do |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
360 { |
22656
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
361 pos2 = line.find_first_of (sep, pos1); |
7580
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
362 |
22656
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
363 if (auto_sep_is_wspace && pos2 != std::string::npos) |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
364 { |
22656
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
365 // Treat consecutive separators as one. |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
366 pos2 = line.find_first_not_of (sep, pos2); |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
367 if (pos2 != std::string::npos) |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
368 pos2 -= 1; |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
369 } |
7580
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
370 |
22666
68d5c4759783
dlmread: Return correct number of columns when line ends with separator (bug #42025).
Rik <rik@octave.org>
parents:
22657
diff
changeset
|
371 // Separator followed by EOL doesn't generate extra column |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
372 if (pos2 != std::string::npos) |
22666
68d5c4759783
dlmread: Return correct number of columns when line ends with separator (bug #42025).
Rik <rik@octave.org>
parents:
22657
diff
changeset
|
373 cmax++; |
7581 | 374 |
22656
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
375 pos1 = pos2 + 1; |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
376 } |
22656
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
377 while (pos2 != std::string::npos); |
7581 | 378 |
22666
68d5c4759783
dlmread: Return correct number of columns when line ends with separator (bug #42025).
Rik <rik@octave.org>
parents:
22657
diff
changeset
|
379 // FIXME: Should always be the case that iscmplx == false. |
68d5c4759783
dlmread: Return correct number of columns when line ends with separator (bug #42025).
Rik <rik@octave.org>
parents:
22657
diff
changeset
|
380 // Flag is initialized that way and no data has been read. |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
381 if (iscmplx) |
22657
a93887d7f0da
Use EmptyValue option correctly in all instances (bug #42023).
Rik <rik@octave.org>
parents:
22656
diff
changeset
|
382 cdata.resize (rmax, cmax, empty_value); |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
383 else |
22657
a93887d7f0da
Use EmptyValue option correctly in all instances (bug #42023).
Rik <rik@octave.org>
parents:
22656
diff
changeset
|
384 rdata.resize (rmax, cmax, empty_value); |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
385 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
386 |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
387 r = (r > i + 1 ? r : i + 1); |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
388 j = 0; |
22656
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
389 |
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
390 size_t pos1, pos2; |
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
391 if (auto_sep_is_wspace) |
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
392 pos1 = line.find_first_not_of (" \t"); // Skip leading whitespace. |
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
393 else |
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
394 pos1 = 0; |
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
395 |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
396 do |
20213
ca2da088eada
Return an empty matrix, not error, from dlmread when file is empty (bug #45156).
Rik <rik@octave.org>
parents:
20172
diff
changeset
|
397 { |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
398 octave_quit (); |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
399 |
22656
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
400 pos2 = line.find_first_of (sep, pos1); |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
401 std::string str = line.substr (pos1, pos2 - pos1); |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
402 |
22656
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
403 if (auto_sep_is_wspace && pos2 != std::string::npos) |
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
404 { |
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
405 // Treat consecutive separators as one. |
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
406 pos2 = line.find_first_not_of (sep, pos2); |
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
407 if (pos2 != std::string::npos) |
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
408 pos2 -= 1; |
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
409 else |
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
410 pos2 = line.length () - 1; |
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
411 } |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
412 |
22666
68d5c4759783
dlmread: Return correct number of columns when line ends with separator (bug #42025).
Rik <rik@octave.org>
parents:
22657
diff
changeset
|
413 // Separator followed by EOL doesn't generate extra column |
68d5c4759783
dlmread: Return correct number of columns when line ends with separator (bug #42025).
Rik <rik@octave.org>
parents:
22657
diff
changeset
|
414 if (pos2 == std::string::npos && str.empty ()) |
68d5c4759783
dlmread: Return correct number of columns when line ends with separator (bug #42025).
Rik <rik@octave.org>
parents:
22657
diff
changeset
|
415 break; |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
416 |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
417 c = (c > j + 1 ? c : j + 1); |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
418 if (r > rmax || c > cmax) |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
419 { |
22656
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
420 // Use resize_and_fill for the case of unequal length rows. |
22676
d318bc8e83ee
avoid compilation error for 64-bit indexing
John W. Eaton <jwe@octave.org>
parents:
22666
diff
changeset
|
421 // Keep rmax a power of 2. |
23306
a009a871825c
Improve performance of dlmread by pre-allocating larger array (bug #50102).
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
422 rmax = std::max (2*(r-1), rmax); |
22666
68d5c4759783
dlmread: Return correct number of columns when line ends with separator (bug #42025).
Rik <rik@octave.org>
parents:
22657
diff
changeset
|
423 cmax = std::max (c, cmax); |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
424 if (iscmplx) |
22657
a93887d7f0da
Use EmptyValue option correctly in all instances (bug #42023).
Rik <rik@octave.org>
parents:
22656
diff
changeset
|
425 cdata.resize (rmax, cmax, empty_value); |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
426 else |
22657
a93887d7f0da
Use EmptyValue option correctly in all instances (bug #42023).
Rik <rik@octave.org>
parents:
22656
diff
changeset
|
427 rdata.resize (rmax, cmax, empty_value); |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
428 } |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
429 |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
430 tmp_stream.str (str); |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
431 tmp_stream.clear (); |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
432 |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
433 double x = octave_read_double (tmp_stream); |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
434 if (tmp_stream) |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
435 { |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
436 if (tmp_stream.eof ()) |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
437 { |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
438 if (iscmplx) |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
439 cdata(i,j++) = x; |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
440 else |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
441 rdata(i,j++) = x; |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
442 } |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
443 else |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
444 { |
23318
d05f688ae836
dlmread: Add support for reading pure imaginary numbers (bug #50589).
Rik <rik@octave.org>
parents:
23308
diff
changeset
|
445 int next_char = std::tolower (tmp_stream.peek ()); |
d05f688ae836
dlmread: Add support for reading pure imaginary numbers (bug #50589).
Rik <rik@octave.org>
parents:
23308
diff
changeset
|
446 if (next_char == 'i' || next_char == 'j') |
d05f688ae836
dlmread: Add support for reading pure imaginary numbers (bug #50589).
Rik <rik@octave.org>
parents:
23308
diff
changeset
|
447 { |
d05f688ae836
dlmread: Add support for reading pure imaginary numbers (bug #50589).
Rik <rik@octave.org>
parents:
23308
diff
changeset
|
448 // Process pure imaginary numbers. |
d05f688ae836
dlmread: Add support for reading pure imaginary numbers (bug #50589).
Rik <rik@octave.org>
parents:
23308
diff
changeset
|
449 if (! iscmplx) |
d05f688ae836
dlmread: Add support for reading pure imaginary numbers (bug #50589).
Rik <rik@octave.org>
parents:
23308
diff
changeset
|
450 { |
d05f688ae836
dlmread: Add support for reading pure imaginary numbers (bug #50589).
Rik <rik@octave.org>
parents:
23308
diff
changeset
|
451 iscmplx = true; |
d05f688ae836
dlmread: Add support for reading pure imaginary numbers (bug #50589).
Rik <rik@octave.org>
parents:
23308
diff
changeset
|
452 cdata = ComplexMatrix (rdata); |
d05f688ae836
dlmread: Add support for reading pure imaginary numbers (bug #50589).
Rik <rik@octave.org>
parents:
23308
diff
changeset
|
453 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
454 |
23318
d05f688ae836
dlmread: Add support for reading pure imaginary numbers (bug #50589).
Rik <rik@octave.org>
parents:
23308
diff
changeset
|
455 cdata(i,j++) = Complex (0, x); |
d05f688ae836
dlmread: Add support for reading pure imaginary numbers (bug #50589).
Rik <rik@octave.org>
parents:
23308
diff
changeset
|
456 } |
d05f688ae836
dlmread: Add support for reading pure imaginary numbers (bug #50589).
Rik <rik@octave.org>
parents:
23308
diff
changeset
|
457 else |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
458 { |
23318
d05f688ae836
dlmread: Add support for reading pure imaginary numbers (bug #50589).
Rik <rik@octave.org>
parents:
23308
diff
changeset
|
459 double y = octave_read_double (tmp_stream); |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
460 |
23318
d05f688ae836
dlmread: Add support for reading pure imaginary numbers (bug #50589).
Rik <rik@octave.org>
parents:
23308
diff
changeset
|
461 if (! iscmplx && y != 0.) |
d05f688ae836
dlmread: Add support for reading pure imaginary numbers (bug #50589).
Rik <rik@octave.org>
parents:
23308
diff
changeset
|
462 { |
d05f688ae836
dlmread: Add support for reading pure imaginary numbers (bug #50589).
Rik <rik@octave.org>
parents:
23308
diff
changeset
|
463 iscmplx = true; |
d05f688ae836
dlmread: Add support for reading pure imaginary numbers (bug #50589).
Rik <rik@octave.org>
parents:
23308
diff
changeset
|
464 cdata = ComplexMatrix (rdata); |
d05f688ae836
dlmread: Add support for reading pure imaginary numbers (bug #50589).
Rik <rik@octave.org>
parents:
23308
diff
changeset
|
465 } |
d05f688ae836
dlmread: Add support for reading pure imaginary numbers (bug #50589).
Rik <rik@octave.org>
parents:
23308
diff
changeset
|
466 |
d05f688ae836
dlmread: Add support for reading pure imaginary numbers (bug #50589).
Rik <rik@octave.org>
parents:
23308
diff
changeset
|
467 if (iscmplx) |
d05f688ae836
dlmread: Add support for reading pure imaginary numbers (bug #50589).
Rik <rik@octave.org>
parents:
23308
diff
changeset
|
468 cdata(i,j++) = Complex (x, y); |
d05f688ae836
dlmread: Add support for reading pure imaginary numbers (bug #50589).
Rik <rik@octave.org>
parents:
23308
diff
changeset
|
469 else |
d05f688ae836
dlmread: Add support for reading pure imaginary numbers (bug #50589).
Rik <rik@octave.org>
parents:
23308
diff
changeset
|
470 rdata(i,j++) = x; |
d05f688ae836
dlmread: Add support for reading pure imaginary numbers (bug #50589).
Rik <rik@octave.org>
parents:
23308
diff
changeset
|
471 } |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
472 } |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
473 } |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
474 else if (iscmplx) |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
475 cdata(i,j++) = empty_value; |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
476 else |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
477 rdata(i,j++) = empty_value; |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
478 |
22656
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
479 pos1 = pos2 + 1; |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
480 } |
22656
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
481 while (pos2 != std::string::npos); |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
482 |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
483 if (i == r1) |
23307
85ffe1bdd3a0
dlmread: Return empty matrix when requested range is outside data (bug #50102).
Rik <rik@octave.org>
parents:
23219
diff
changeset
|
484 break; // Stop early if the desired range has been read. |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
485 |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
486 i++; |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
487 } |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
488 |
23307
85ffe1bdd3a0
dlmread: Return empty matrix when requested range is outside data (bug #50102).
Rik <rik@octave.org>
parents:
23219
diff
changeset
|
489 // Clip selection indices to actual size of data |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
490 if (r1 >= r) |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
491 r1 = r - 1; |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
492 if (c1 >= c) |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
493 c1 = c - 1; |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
494 |
23307
85ffe1bdd3a0
dlmread: Return empty matrix when requested range is outside data (bug #50102).
Rik <rik@octave.org>
parents:
23219
diff
changeset
|
495 if (iscmplx) |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
496 { |
23307
85ffe1bdd3a0
dlmread: Return empty matrix when requested range is outside data (bug #50102).
Rik <rik@octave.org>
parents:
23219
diff
changeset
|
497 if ((i == 0 && j == 0) || (c0 > c1)) |
85ffe1bdd3a0
dlmread: Return empty matrix when requested range is outside data (bug #50102).
Rik <rik@octave.org>
parents:
23219
diff
changeset
|
498 return ovl (ComplexMatrix (0,0)); |
85ffe1bdd3a0
dlmread: Return empty matrix when requested range is outside data (bug #50102).
Rik <rik@octave.org>
parents:
23219
diff
changeset
|
499 |
85ffe1bdd3a0
dlmread: Return empty matrix when requested range is outside data (bug #50102).
Rik <rik@octave.org>
parents:
23219
diff
changeset
|
500 cdata = cdata.extract (0, c0, r1, c1); |
85ffe1bdd3a0
dlmread: Return empty matrix when requested range is outside data (bug #50102).
Rik <rik@octave.org>
parents:
23219
diff
changeset
|
501 return ovl (cdata); |
7580
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
502 } |
23307
85ffe1bdd3a0
dlmread: Return empty matrix when requested range is outside data (bug #50102).
Rik <rik@octave.org>
parents:
23219
diff
changeset
|
503 else |
85ffe1bdd3a0
dlmread: Return empty matrix when requested range is outside data (bug #50102).
Rik <rik@octave.org>
parents:
23219
diff
changeset
|
504 { |
85ffe1bdd3a0
dlmread: Return empty matrix when requested range is outside data (bug #50102).
Rik <rik@octave.org>
parents:
23219
diff
changeset
|
505 if ((i == 0 && j == 0) || (c0 > c1)) |
85ffe1bdd3a0
dlmread: Return empty matrix when requested range is outside data (bug #50102).
Rik <rik@octave.org>
parents:
23219
diff
changeset
|
506 return ovl (Matrix (0,0)); |
7580
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
507 |
23307
85ffe1bdd3a0
dlmread: Return empty matrix when requested range is outside data (bug #50102).
Rik <rik@octave.org>
parents:
23219
diff
changeset
|
508 rdata = rdata.extract (0, c0, r1, c1); |
85ffe1bdd3a0
dlmread: Return empty matrix when requested range is outside data (bug #50102).
Rik <rik@octave.org>
parents:
23219
diff
changeset
|
509 return ovl (rdata); |
85ffe1bdd3a0
dlmread: Return empty matrix when requested range is outside data (bug #50102).
Rik <rik@octave.org>
parents:
23219
diff
changeset
|
510 } |
7580
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
511 } |
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
512 |
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
513 /* |
23307
85ffe1bdd3a0
dlmread: Return empty matrix when requested range is outside data (bug #50102).
Rik <rik@octave.org>
parents:
23219
diff
changeset
|
514 %!test |
19278
6ca096827123
Use tempname() rather than tmpnam() in core Octave.
Rik <rik@octave.org>
parents:
18112
diff
changeset
|
515 %! file = tempname (); |
23307
85ffe1bdd3a0
dlmread: Return empty matrix when requested range is outside data (bug #50102).
Rik <rik@octave.org>
parents:
23219
diff
changeset
|
516 %! unwind_protect |
22656
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
517 %! fid = fopen (file, "wt"); |
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
518 %! fwrite (fid, "1, 2, 3\n4, 5, 6\n7, 8, 9\n10, 11, 12"); |
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
519 %! fclose (fid); |
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
520 %! |
23307
85ffe1bdd3a0
dlmread: Return empty matrix when requested range is outside data (bug #50102).
Rik <rik@octave.org>
parents:
23219
diff
changeset
|
521 %! assert (dlmread (file), [1, 2, 3; 4, 5, 6; 7, 8, 9;10, 11, 12]); |
85ffe1bdd3a0
dlmread: Return empty matrix when requested range is outside data (bug #50102).
Rik <rik@octave.org>
parents:
23219
diff
changeset
|
522 %! assert (dlmread (file, ","), [1, 2, 3; 4, 5, 6; 7, 8, 9; 10, 11, 12]); |
85ffe1bdd3a0
dlmread: Return empty matrix when requested range is outside data (bug #50102).
Rik <rik@octave.org>
parents:
23219
diff
changeset
|
523 %! assert (dlmread (file, ",", [1, 0, 2, 1]), [4, 5; 7, 8]); |
85ffe1bdd3a0
dlmread: Return empty matrix when requested range is outside data (bug #50102).
Rik <rik@octave.org>
parents:
23219
diff
changeset
|
524 %! assert (dlmread (file, ",", "B1..C2"), [2, 3; 5, 6]); |
85ffe1bdd3a0
dlmread: Return empty matrix when requested range is outside data (bug #50102).
Rik <rik@octave.org>
parents:
23219
diff
changeset
|
525 %! assert (dlmread (file, ",", "B1:C2"), [2, 3; 5, 6]); |
85ffe1bdd3a0
dlmread: Return empty matrix when requested range is outside data (bug #50102).
Rik <rik@octave.org>
parents:
23219
diff
changeset
|
526 %! assert (dlmread (file, ",", "..C2"), [1, 2, 3; 4, 5, 6]); |
85ffe1bdd3a0
dlmread: Return empty matrix when requested range is outside data (bug #50102).
Rik <rik@octave.org>
parents:
23219
diff
changeset
|
527 %! assert (dlmread (file, ",", 0, 1), [2, 3; 5, 6; 8, 9; 11, 12]); |
85ffe1bdd3a0
dlmread: Return empty matrix when requested range is outside data (bug #50102).
Rik <rik@octave.org>
parents:
23219
diff
changeset
|
528 %! assert (dlmread (file, ",", "B1.."), [2, 3; 5, 6; 8, 9; 11, 12]); |
85ffe1bdd3a0
dlmread: Return empty matrix when requested range is outside data (bug #50102).
Rik <rik@octave.org>
parents:
23219
diff
changeset
|
529 %! assert (dlmread (file, ",", 10, 0), []); |
85ffe1bdd3a0
dlmread: Return empty matrix when requested range is outside data (bug #50102).
Rik <rik@octave.org>
parents:
23219
diff
changeset
|
530 %! assert (dlmread (file, ",", 0, 10), []); |
85ffe1bdd3a0
dlmread: Return empty matrix when requested range is outside data (bug #50102).
Rik <rik@octave.org>
parents:
23219
diff
changeset
|
531 %! fail ('dlmread (file, ",", [0 1])', "error parsing RANGE"); |
85ffe1bdd3a0
dlmread: Return empty matrix when requested range is outside data (bug #50102).
Rik <rik@octave.org>
parents:
23219
diff
changeset
|
532 %! unwind_protect_cleanup |
85ffe1bdd3a0
dlmread: Return empty matrix when requested range is outside data (bug #50102).
Rik <rik@octave.org>
parents:
23219
diff
changeset
|
533 %! unlink (file); |
85ffe1bdd3a0
dlmread: Return empty matrix when requested range is outside data (bug #50102).
Rik <rik@octave.org>
parents:
23219
diff
changeset
|
534 %! end_unwind_protect |
7580
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
535 |
24477
e8cb11de9383
test: Mark certain bugs as xtest when run on Mac platforms (bug #52627).
Rik <rik@octave.org>
parents:
23738
diff
changeset
|
536 %!testif ; ! ismac () |
e8cb11de9383
test: Mark certain bugs as xtest when run on Mac platforms (bug #52627).
Rik <rik@octave.org>
parents:
23738
diff
changeset
|
537 %! file = tempname (); |
e8cb11de9383
test: Mark certain bugs as xtest when run on Mac platforms (bug #52627).
Rik <rik@octave.org>
parents:
23738
diff
changeset
|
538 %! unwind_protect |
e8cb11de9383
test: Mark certain bugs as xtest when run on Mac platforms (bug #52627).
Rik <rik@octave.org>
parents:
23738
diff
changeset
|
539 %! fid = fopen (file, "wt"); |
e8cb11de9383
test: Mark certain bugs as xtest when run on Mac platforms (bug #52627).
Rik <rik@octave.org>
parents:
23738
diff
changeset
|
540 %! fwrite (fid, "1, 2, 3\n4+4i, 5, 6\n7, 8, 9\n10, 11, 12"); |
e8cb11de9383
test: Mark certain bugs as xtest when run on Mac platforms (bug #52627).
Rik <rik@octave.org>
parents:
23738
diff
changeset
|
541 %! fclose (fid); |
e8cb11de9383
test: Mark certain bugs as xtest when run on Mac platforms (bug #52627).
Rik <rik@octave.org>
parents:
23738
diff
changeset
|
542 %! |
e8cb11de9383
test: Mark certain bugs as xtest when run on Mac platforms (bug #52627).
Rik <rik@octave.org>
parents:
23738
diff
changeset
|
543 %! assert (dlmread (file), [1, 2, 3; 4 + 4i, 5, 6; 7, 8, 9; 10, 11, 12]); |
e8cb11de9383
test: Mark certain bugs as xtest when run on Mac platforms (bug #52627).
Rik <rik@octave.org>
parents:
23738
diff
changeset
|
544 %! assert (dlmread (file, ","), [1,2,3; 4 + 4i, 5, 6; 7, 8, 9; 10, 11, 12]); |
e8cb11de9383
test: Mark certain bugs as xtest when run on Mac platforms (bug #52627).
Rik <rik@octave.org>
parents:
23738
diff
changeset
|
545 %! assert (dlmread (file, ",", [1, 0, 2, 1]), [4 + 4i, 5; 7, 8]); |
e8cb11de9383
test: Mark certain bugs as xtest when run on Mac platforms (bug #52627).
Rik <rik@octave.org>
parents:
23738
diff
changeset
|
546 %! assert (dlmread (file, ",", "A2..B3"), [4 + 4i, 5; 7, 8]); |
e8cb11de9383
test: Mark certain bugs as xtest when run on Mac platforms (bug #52627).
Rik <rik@octave.org>
parents:
23738
diff
changeset
|
547 %! assert (dlmread (file, ",", "A2:B3"), [4 + 4i, 5; 7, 8]); |
e8cb11de9383
test: Mark certain bugs as xtest when run on Mac platforms (bug #52627).
Rik <rik@octave.org>
parents:
23738
diff
changeset
|
548 %! assert (dlmread (file, ",", "..B3"), [1, 2; 4 + 4i, 5; 7, 8]); |
e8cb11de9383
test: Mark certain bugs as xtest when run on Mac platforms (bug #52627).
Rik <rik@octave.org>
parents:
23738
diff
changeset
|
549 %! assert (dlmread (file, ",", 1, 0), [4 + 4i, 5, 6; 7, 8, 9; 10, 11, 12]); |
e8cb11de9383
test: Mark certain bugs as xtest when run on Mac platforms (bug #52627).
Rik <rik@octave.org>
parents:
23738
diff
changeset
|
550 %! assert (dlmread (file, ",", "A2.."), [4 + 4i, 5, 6; 7, 8, 9; 10, 11, 12]); |
e8cb11de9383
test: Mark certain bugs as xtest when run on Mac platforms (bug #52627).
Rik <rik@octave.org>
parents:
23738
diff
changeset
|
551 %! assert (dlmread (file, ",", 10, 0), []); |
e8cb11de9383
test: Mark certain bugs as xtest when run on Mac platforms (bug #52627).
Rik <rik@octave.org>
parents:
23738
diff
changeset
|
552 %! assert (dlmread (file, ",", 0, 10), []); |
e8cb11de9383
test: Mark certain bugs as xtest when run on Mac platforms (bug #52627).
Rik <rik@octave.org>
parents:
23738
diff
changeset
|
553 %! unwind_protect_cleanup |
e8cb11de9383
test: Mark certain bugs as xtest when run on Mac platforms (bug #52627).
Rik <rik@octave.org>
parents:
23738
diff
changeset
|
554 %! unlink (file); |
e8cb11de9383
test: Mark certain bugs as xtest when run on Mac platforms (bug #52627).
Rik <rik@octave.org>
parents:
23738
diff
changeset
|
555 %! end_unwind_protect |
e8cb11de9383
test: Mark certain bugs as xtest when run on Mac platforms (bug #52627).
Rik <rik@octave.org>
parents:
23738
diff
changeset
|
556 |
e8cb11de9383
test: Mark certain bugs as xtest when run on Mac platforms (bug #52627).
Rik <rik@octave.org>
parents:
23738
diff
changeset
|
557 %!xtest <47413> |
e8cb11de9383
test: Mark certain bugs as xtest when run on Mac platforms (bug #52627).
Rik <rik@octave.org>
parents:
23738
diff
changeset
|
558 %! ## Same test code as above, but intended only for test statistics on Mac. |
e8cb11de9383
test: Mark certain bugs as xtest when run on Mac platforms (bug #52627).
Rik <rik@octave.org>
parents:
23738
diff
changeset
|
559 %! if (! ismac ()), return; endif |
19278
6ca096827123
Use tempname() rather than tmpnam() in core Octave.
Rik <rik@octave.org>
parents:
18112
diff
changeset
|
560 %! file = tempname (); |
23307
85ffe1bdd3a0
dlmread: Return empty matrix when requested range is outside data (bug #50102).
Rik <rik@octave.org>
parents:
23219
diff
changeset
|
561 %! unwind_protect |
22656
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
562 %! fid = fopen (file, "wt"); |
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
563 %! fwrite (fid, "1, 2, 3\n4+4i, 5, 6\n7, 8, 9\n10, 11, 12"); |
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
564 %! fclose (fid); |
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
565 %! |
23307
85ffe1bdd3a0
dlmread: Return empty matrix when requested range is outside data (bug #50102).
Rik <rik@octave.org>
parents:
23219
diff
changeset
|
566 %! assert (dlmread (file), [1, 2, 3; 4 + 4i, 5, 6; 7, 8, 9; 10, 11, 12]); |
22657
a93887d7f0da
Use EmptyValue option correctly in all instances (bug #42023).
Rik <rik@octave.org>
parents:
22656
diff
changeset
|
567 %! assert (dlmread (file, ","), [1,2,3; 4 + 4i, 5, 6; 7, 8, 9; 10, 11, 12]); |
23307
85ffe1bdd3a0
dlmread: Return empty matrix when requested range is outside data (bug #50102).
Rik <rik@octave.org>
parents:
23219
diff
changeset
|
568 %! assert (dlmread (file, ",", [1, 0, 2, 1]), [4 + 4i, 5; 7, 8]); |
85ffe1bdd3a0
dlmread: Return empty matrix when requested range is outside data (bug #50102).
Rik <rik@octave.org>
parents:
23219
diff
changeset
|
569 %! assert (dlmread (file, ",", "A2..B3"), [4 + 4i, 5; 7, 8]); |
85ffe1bdd3a0
dlmread: Return empty matrix when requested range is outside data (bug #50102).
Rik <rik@octave.org>
parents:
23219
diff
changeset
|
570 %! assert (dlmread (file, ",", "A2:B3"), [4 + 4i, 5; 7, 8]); |
85ffe1bdd3a0
dlmread: Return empty matrix when requested range is outside data (bug #50102).
Rik <rik@octave.org>
parents:
23219
diff
changeset
|
571 %! assert (dlmread (file, ",", "..B3"), [1, 2; 4 + 4i, 5; 7, 8]); |
85ffe1bdd3a0
dlmread: Return empty matrix when requested range is outside data (bug #50102).
Rik <rik@octave.org>
parents:
23219
diff
changeset
|
572 %! assert (dlmread (file, ",", 1, 0), [4 + 4i, 5, 6; 7, 8, 9; 10, 11, 12]); |
85ffe1bdd3a0
dlmread: Return empty matrix when requested range is outside data (bug #50102).
Rik <rik@octave.org>
parents:
23219
diff
changeset
|
573 %! assert (dlmread (file, ",", "A2.."), [4 + 4i, 5, 6; 7, 8, 9; 10, 11, 12]); |
85ffe1bdd3a0
dlmread: Return empty matrix when requested range is outside data (bug #50102).
Rik <rik@octave.org>
parents:
23219
diff
changeset
|
574 %! assert (dlmread (file, ",", 10, 0), []); |
85ffe1bdd3a0
dlmread: Return empty matrix when requested range is outside data (bug #50102).
Rik <rik@octave.org>
parents:
23219
diff
changeset
|
575 %! assert (dlmread (file, ",", 0, 10), []); |
85ffe1bdd3a0
dlmread: Return empty matrix when requested range is outside data (bug #50102).
Rik <rik@octave.org>
parents:
23219
diff
changeset
|
576 %! unwind_protect_cleanup |
85ffe1bdd3a0
dlmread: Return empty matrix when requested range is outside data (bug #50102).
Rik <rik@octave.org>
parents:
23219
diff
changeset
|
577 %! unlink (file); |
85ffe1bdd3a0
dlmread: Return empty matrix when requested range is outside data (bug #50102).
Rik <rik@octave.org>
parents:
23219
diff
changeset
|
578 %! end_unwind_protect |
7580
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
579 |
23573
1b4f4ec53b4a
use new script to tag fixed bugs in tests
John W. Eaton <jwe@octave.org>
parents:
23572
diff
changeset
|
580 %!test <*42025> |
22656
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
581 %! file = tempname (); |
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
582 %! unwind_protect |
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
583 %! fid = fopen (file, "wt"); |
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
584 %! fwrite (fid, " \n 1 2\n11 22\n "); |
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
585 %! fclose (fid); |
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
586 %! |
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
587 %! assert (dlmread (file), [1, 2; 11, 22]); |
22666
68d5c4759783
dlmread: Return correct number of columns when line ends with separator (bug #42025).
Rik <rik@octave.org>
parents:
22657
diff
changeset
|
588 %! assert (dlmread (file, " "), [ 0, 0, 0, 0 |
68d5c4759783
dlmread: Return correct number of columns when line ends with separator (bug #42025).
Rik <rik@octave.org>
parents:
22657
diff
changeset
|
589 %! 0, 1, 2, 0 |
68d5c4759783
dlmread: Return correct number of columns when line ends with separator (bug #42025).
Rik <rik@octave.org>
parents:
22657
diff
changeset
|
590 %! 11, 22, 0, 0 |
68d5c4759783
dlmread: Return correct number of columns when line ends with separator (bug #42025).
Rik <rik@octave.org>
parents:
22657
diff
changeset
|
591 %! 0, 0, 0, 0]); |
22656
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
592 %! unwind_protect_cleanup |
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
593 %! unlink (file); |
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
594 %! end_unwind_protect |
7580
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
595 |
23573
1b4f4ec53b4a
use new script to tag fixed bugs in tests
John W. Eaton <jwe@octave.org>
parents:
23572
diff
changeset
|
596 %!test <*50589> |
23318
d05f688ae836
dlmread: Add support for reading pure imaginary numbers (bug #50589).
Rik <rik@octave.org>
parents:
23308
diff
changeset
|
597 %! file = tempname (); |
d05f688ae836
dlmread: Add support for reading pure imaginary numbers (bug #50589).
Rik <rik@octave.org>
parents:
23308
diff
changeset
|
598 %! unwind_protect |
d05f688ae836
dlmread: Add support for reading pure imaginary numbers (bug #50589).
Rik <rik@octave.org>
parents:
23308
diff
changeset
|
599 %! fid = fopen (file, "wt"); |
d05f688ae836
dlmread: Add support for reading pure imaginary numbers (bug #50589).
Rik <rik@octave.org>
parents:
23308
diff
changeset
|
600 %! fwrite (fid, "1;2;3\n"); |
d05f688ae836
dlmread: Add support for reading pure imaginary numbers (bug #50589).
Rik <rik@octave.org>
parents:
23308
diff
changeset
|
601 %! fwrite (fid, "1i;2I;3j;4J\n"); |
d05f688ae836
dlmread: Add support for reading pure imaginary numbers (bug #50589).
Rik <rik@octave.org>
parents:
23308
diff
changeset
|
602 %! fwrite (fid, "4;5;6\n"); |
d05f688ae836
dlmread: Add support for reading pure imaginary numbers (bug #50589).
Rik <rik@octave.org>
parents:
23308
diff
changeset
|
603 %! fwrite (fid, "-4i;+5I;-6j;+7J\n"); |
d05f688ae836
dlmread: Add support for reading pure imaginary numbers (bug #50589).
Rik <rik@octave.org>
parents:
23308
diff
changeset
|
604 %! fclose (fid); |
d05f688ae836
dlmread: Add support for reading pure imaginary numbers (bug #50589).
Rik <rik@octave.org>
parents:
23308
diff
changeset
|
605 %! |
d05f688ae836
dlmread: Add support for reading pure imaginary numbers (bug #50589).
Rik <rik@octave.org>
parents:
23308
diff
changeset
|
606 %! assert (dlmread (file), [1, 2, 3, 0; 1i, 2i, 3i, 4i; |
d05f688ae836
dlmread: Add support for reading pure imaginary numbers (bug #50589).
Rik <rik@octave.org>
parents:
23308
diff
changeset
|
607 %! 4, 5, 6, 0; -4i, 5i, -6i, 7i]); |
d05f688ae836
dlmread: Add support for reading pure imaginary numbers (bug #50589).
Rik <rik@octave.org>
parents:
23308
diff
changeset
|
608 %! assert (dlmread (file, "", [0 0 0 3]), [1, 2, 3]); |
d05f688ae836
dlmread: Add support for reading pure imaginary numbers (bug #50589).
Rik <rik@octave.org>
parents:
23308
diff
changeset
|
609 %! assert (dlmread (file, "", [1 0 1 3]), [1i, 2i, 3i, 4i]); |
23307
85ffe1bdd3a0
dlmread: Return empty matrix when requested range is outside data (bug #50102).
Rik <rik@octave.org>
parents:
23219
diff
changeset
|
610 %! unwind_protect_cleanup |
85ffe1bdd3a0
dlmread: Return empty matrix when requested range is outside data (bug #50102).
Rik <rik@octave.org>
parents:
23219
diff
changeset
|
611 %! unlink (file); |
85ffe1bdd3a0
dlmread: Return empty matrix when requested range is outside data (bug #50102).
Rik <rik@octave.org>
parents:
23219
diff
changeset
|
612 %! end_unwind_protect |
7580
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
613 |
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
614 */ |