Mercurial > octave
annotate libinterp/corefcn/dlmread.cc @ 23395:c14cf947142f
maint: Merge stable to default.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Thu, 13 Apr 2017 10:32:21 -0400 |
parents | 4adb9517d56a 7ca04e85f9e3 |
children | 21baad6b35c4 |
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" |
10927
a9e9659e1dca
support file IDs in dlmread
Jaroslav Hajek <highegg@gmail.com>
parents:
10806
diff
changeset
|
39 #include "oct-stream.h" |
7580
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
40 #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
|
41 #include "ovl.h" |
7580
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
42 #include "utils.h" |
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
43 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
44 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
|
45 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
|
46 |
31be59137160
Don't error out if RANGE specification for dlmread contains large values.
Rik <rik@octave.org>
parents:
23307
diff
changeset
|
47 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
|
48 |
7580
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
49 static bool |
10804
3d5c6b84ddaf
speed-up fixes to dlmread
Jaroslav Hajek <highegg@gmail.com>
parents:
10718
diff
changeset
|
50 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
|
51 { |
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
52 bool stat = false; |
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
53 |
7581 | 54 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
|
55 stat = true; |
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
56 else |
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
57 { |
7581 | 58 if (::isalpha (is.peek ())) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
59 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
60 col = 0; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
61 while (is && ::isalpha (is.peek ())) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
62 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
63 char ch = is.get (); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
64 col *= 26; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
65 if (ch >= 'a') |
10718
b8d76f4be94a
Fix spreadsheet style range option (bug #30183).
Rik <octave@nomad.inbox5.com>
parents:
10350
diff
changeset
|
66 col += ch - 'a' + 1; |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
67 else |
10718
b8d76f4be94a
Fix spreadsheet style range option (bug #30183).
Rik <octave@nomad.inbox5.com>
parents:
10350
diff
changeset
|
68 col += ch - 'A' + 1; |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
69 } |
21062
d9c1884d1aaa
maint: Eliminate space between variable and decrement '--' operator.
Rik <rik@octave.org>
parents:
20955
diff
changeset
|
70 col--; |
7580
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
71 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
72 if (is) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
73 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
74 is >> row; |
21062
d9c1884d1aaa
maint: Eliminate space between variable and decrement '--' operator.
Rik <rik@octave.org>
parents:
20955
diff
changeset
|
75 row--; |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
76 if (is) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
77 stat = true; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
78 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
79 } |
7580
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
80 } |
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 return stat; |
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
83 } |
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 static bool |
7581 | 86 parse_range_spec (const octave_value& range_spec, |
10804
3d5c6b84ddaf
speed-up fixes to dlmread
Jaroslav Hajek <highegg@gmail.com>
parents:
10718
diff
changeset
|
87 octave_idx_type& rlo, octave_idx_type& clo, |
3d5c6b84ddaf
speed-up fixes to dlmread
Jaroslav Hajek <highegg@gmail.com>
parents:
10718
diff
changeset
|
88 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
|
89 { |
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
90 bool stat = true; |
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
91 |
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
92 if (range_spec.is_string ()) |
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
93 { |
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
94 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
|
95 char ch = is.peek (); |
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
96 |
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
97 if (ch == '.' || ch == ':') |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
98 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
99 rlo = 0; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
100 clo = 0; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
101 ch = is.get (); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
102 if (ch == '.') |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
103 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
104 ch = is.get (); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
105 if (ch != '.') |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
106 stat = false; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
107 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
108 } |
7580
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
109 else |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
110 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
111 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
|
112 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
113 if (stat) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
114 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
115 ch = is.peek (); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
116 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
117 if (ch == '.' || ch == ':') |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
118 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
119 ch = is.get (); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
120 if (ch == '.') |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
121 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
122 ch = is.get (); |
20955
77f5591878bf
maint: Use '! expr' rather than '!expr' to conform to coding guidelines.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
123 if (! is || ch != '.') |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
124 stat = false; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
125 } |
7580
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
126 |
23323
31be59137160
Don't error out if RANGE specification for dlmread contains large values.
Rik <rik@octave.org>
parents:
23307
diff
changeset
|
127 rup = idx_max; |
31be59137160
Don't error out if RANGE specification for dlmread contains large values.
Rik <rik@octave.org>
parents:
23307
diff
changeset
|
128 cup = idx_max; |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
129 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
130 else |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
131 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
132 rup = rlo; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
133 cup = clo; |
20955
77f5591878bf
maint: Use '! expr' rather than '!expr' to conform to coding guidelines.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
134 if (! is || ! is.eof ()) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
135 stat = false; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
136 } |
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 } |
7580
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
139 |
20955
77f5591878bf
maint: Use '! expr' rather than '!expr' to conform to coding guidelines.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
140 if (stat && is && ! is.eof ()) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
141 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
|
142 |
20955
77f5591878bf
maint: Use '! expr' rather than '!expr' to conform to coding guidelines.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
143 if (! is || ! is.eof ()) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
144 stat = false; |
7580
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
145 } |
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
146 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
|
147 { |
23323
31be59137160
Don't error out if RANGE specification for dlmread contains large values.
Rik <rik@octave.org>
parents:
23307
diff
changeset
|
148 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
|
149 // 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
|
150 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
|
151 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
|
152 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
|
153 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
|
154 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
155 else |
7580
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
156 stat = false; |
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
157 |
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
158 return stat; |
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
159 } |
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
160 |
15039
e753177cde93
maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents:
14501
diff
changeset
|
161 DEFUN (dlmread, args, , |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21733
diff
changeset
|
162 doc: /* -*- texinfo -*- |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21733
diff
changeset
|
163 @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
|
164 @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
|
165 @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
|
166 @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
|
167 @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
|
168 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
|
169 @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
|
170 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21733
diff
changeset
|
171 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
|
172 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
|
173 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21733
diff
changeset
|
174 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
|
175 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
|
176 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
|
177 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21733
diff
changeset
|
178 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
|
179 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
|
180 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
|
181 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
|
182 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
|
183 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
|
184 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
|
185 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21733
diff
changeset
|
186 @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
|
187 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
|
188 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21733
diff
changeset
|
189 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
|
190 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
|
191 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
|
192 @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
|
193 @end deftypefn */) |
7580
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
194 { |
7581 | 195 int nargin = args.length (); |
196 | |
10935
3cb4889dd6f7
support specific empty value in dlmread
Jaroslav Hajek <highegg@gmail.com>
parents:
10927
diff
changeset
|
197 double empty_value = 0.0; |
3cb4889dd6f7
support specific empty value in dlmread
Jaroslav Hajek <highegg@gmail.com>
parents:
10927
diff
changeset
|
198 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
199 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
|
200 && args(nargin-2).string_value () == "emptyvalue") |
3cb4889dd6f7
support specific empty value in dlmread
Jaroslav Hajek <highegg@gmail.com>
parents:
10927
diff
changeset
|
201 { |
3cb4889dd6f7
support specific empty value in dlmread
Jaroslav Hajek <highegg@gmail.com>
parents:
10927
diff
changeset
|
202 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
|
203 |
10935
3cb4889dd6f7
support specific empty value in dlmread
Jaroslav Hajek <highegg@gmail.com>
parents:
10927
diff
changeset
|
204 nargin -= 2; |
3cb4889dd6f7
support specific empty value in dlmread
Jaroslav Hajek <highegg@gmail.com>
parents:
10927
diff
changeset
|
205 } |
3cb4889dd6f7
support specific empty value in dlmread
Jaroslav Hajek <highegg@gmail.com>
parents:
10927
diff
changeset
|
206 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
207 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
|
208 print_usage (); |
7580
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
209 |
10927
a9e9659e1dca
support file IDs in dlmread
Jaroslav Hajek <highegg@gmail.com>
parents:
10806
diff
changeset
|
210 std::istream *input = 0; |
11389
934ed3e07542
dlmread: simplify file name/id logic
John W. Eaton <jwe@octave.org>
parents:
10935
diff
changeset
|
211 std::ifstream input_file; |
10927
a9e9659e1dca
support file IDs in dlmread
Jaroslav Hajek <highegg@gmail.com>
parents:
10806
diff
changeset
|
212 |
a9e9659e1dca
support file IDs in dlmread
Jaroslav Hajek <highegg@gmail.com>
parents:
10806
diff
changeset
|
213 if (args(0).is_string ()) |
7580
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
214 { |
20713
2469d78a1d8b
Consistently use 'filename' rather than 'file name' throughout code base.
Rik <rik@octave.org>
parents:
20555
diff
changeset
|
215 // Filename. |
10927
a9e9659e1dca
support file IDs in dlmread
Jaroslav Hajek <highegg@gmail.com>
parents:
10806
diff
changeset
|
216 std::string fname (args(0).string_value ()); |
a9e9659e1dca
support file IDs in dlmread
Jaroslav Hajek <highegg@gmail.com>
parents:
10806
diff
changeset
|
217 |
21733
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
218 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
|
219 |
21593
e3888aa9a4d1
Restore tilde expansion for dlmread lost in fe5ed6d7fb10.
Rik <rik@octave.org>
parents:
21592
diff
changeset
|
220 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
|
221 |
11389
934ed3e07542
dlmread: simplify file name/id logic
John W. Eaton <jwe@octave.org>
parents:
10935
diff
changeset
|
222 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
|
223 |
934ed3e07542
dlmread: simplify file name/id logic
John W. Eaton <jwe@octave.org>
parents:
10935
diff
changeset
|
224 if (! input_file) |
20831
35241c4b696c
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20802
diff
changeset
|
225 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
|
226 |
35241c4b696c
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20802
diff
changeset
|
227 input = &input_file; |
10927
a9e9659e1dca
support file IDs in dlmread
Jaroslav Hajek <highegg@gmail.com>
parents:
10806
diff
changeset
|
228 } |
a9e9659e1dca
support file IDs in dlmread
Jaroslav Hajek <highegg@gmail.com>
parents:
10806
diff
changeset
|
229 else if (args(0).is_scalar_type ()) |
a9e9659e1dca
support file IDs in dlmread
Jaroslav Hajek <highegg@gmail.com>
parents:
10806
diff
changeset
|
230 { |
23059
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
231 octave::stream is = octave::stream_list::lookup (args(0), "dlmread"); |
11389
934ed3e07542
dlmread: simplify file name/id logic
John W. Eaton <jwe@octave.org>
parents:
10935
diff
changeset
|
232 |
934ed3e07542
dlmread: simplify file name/id logic
John W. Eaton <jwe@octave.org>
parents:
10935
diff
changeset
|
233 input = is.input_stream (); |
934ed3e07542
dlmread: simplify file name/id logic
John W. Eaton <jwe@octave.org>
parents:
10935
diff
changeset
|
234 |
10927
a9e9659e1dca
support file IDs in dlmread
Jaroslav Hajek <highegg@gmail.com>
parents:
10806
diff
changeset
|
235 if (! input) |
20831
35241c4b696c
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20802
diff
changeset
|
236 error ("dlmread: stream FILE not open for input"); |
10927
a9e9659e1dca
support file IDs in dlmread
Jaroslav Hajek <highegg@gmail.com>
parents:
10806
diff
changeset
|
237 } |
a9e9659e1dca
support file IDs in dlmread
Jaroslav Hajek <highegg@gmail.com>
parents:
10806
diff
changeset
|
238 else |
20831
35241c4b696c
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20802
diff
changeset
|
239 error ("dlmread: FILE argument must be a string or file id"); |
7581 | 240 |
241 // Set default separator. | |
7580
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
242 std::string sep; |
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
243 if (nargin > 1) |
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
244 { |
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
245 if (args(1).is_sq_string ()) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
246 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
|
247 else |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
248 sep = args(1).string_value (); |
7580
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
249 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
250 |
7581 | 251 // 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
|
252 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
|
253 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
|
254 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
|
255 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
|
256 if (nargin > 2) |
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
257 { |
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
258 if (nargin == 3) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
259 { |
20955
77f5591878bf
maint: Use '! expr' rather than '!expr' to conform to coding guidelines.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
260 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
|
261 error ("dlmread: error parsing RANGE"); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
262 } |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
263 else if (nargin == 4) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
264 { |
10804
3d5c6b84ddaf
speed-up fixes to dlmread
Jaroslav Hajek <highegg@gmail.com>
parents:
10718
diff
changeset
|
265 r0 = args(2).idx_type_value (); |
3d5c6b84ddaf
speed-up fixes to dlmread
Jaroslav Hajek <highegg@gmail.com>
parents:
10718
diff
changeset
|
266 c0 = args(3).idx_type_value (); |
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 |
3d5c6b84ddaf
speed-up fixes to dlmread
Jaroslav Hajek <highegg@gmail.com>
parents:
10718
diff
changeset
|
269 if (r0 < 0 || c0 < 0) |
11553
01f703952eff
Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
270 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
|
271 |
23394
7ca04e85f9e3
maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents:
23323
diff
changeset
|
272 // 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
|
273 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
|
274 return ovl (Matrix (0,0)); |
7580
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
275 } |
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
276 |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
277 octave_idx_type i = 0; |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
278 octave_idx_type j = 0; |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
279 octave_idx_type r = 1; |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
280 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
|
281 // 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
|
282 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
|
283 octave_idx_type cmax = 0; |
7581 | 284 |
22666
68d5c4759783
dlmread: Return correct number of columns when line ends with separator (bug #42025).
Rik <rik@octave.org>
parents:
22657
diff
changeset
|
285 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
|
286 ComplexMatrix cdata; |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
287 |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
288 bool iscmplx = false; |
22656
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
289 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
|
290 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
|
291 |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
292 std::string line; |
7581 | 293 |
23323
31be59137160
Don't error out if RANGE specification for dlmread contains large values.
Rik <rik@octave.org>
parents:
23307
diff
changeset
|
294 // 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
|
295 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
|
296 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
|
297 rcnt--; |
31be59137160
Don't error out if RANGE specification for dlmread contains large values.
Rik <rik@octave.org>
parents:
23307
diff
changeset
|
298 |
31be59137160
Don't error out if RANGE specification for dlmread contains large values.
Rik <rik@octave.org>
parents:
23307
diff
changeset
|
299 if (rcnt > 0) |
31be59137160
Don't error out if RANGE specification for dlmread contains large values.
Rik <rik@octave.org>
parents:
23307
diff
changeset
|
300 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
|
301 else |
31be59137160
Don't error out if RANGE specification for dlmread contains large values.
Rik <rik@octave.org>
parents:
23307
diff
changeset
|
302 r1 -= r0; |
7581 | 303 |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
304 std::istringstream tmp_stream; |
7581 | 305 |
22656
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
306 // 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
|
307 while (getline (*input, line)) |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
308 { |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
309 // Skip blank lines for compatibility. |
22656
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
310 if ((! sep_is_wspace || auto_sep_is_wspace) |
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
311 && 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
|
312 continue; |
7580
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
313 |
22656
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
314 // Infer separator from file if delimiter is blank. |
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
315 if (sep.empty ()) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
316 { |
22621
e7699adac1d0
Do a better job of delimiter auto-dedection in dlmread (bug #42022).
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
317 // Skip leading whitespace. |
e7699adac1d0
Do a better job of delimiter auto-dedection in dlmread (bug #42022).
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
318 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
|
319 |
22656
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
320 // For Matlab compatibility, blank delimiter should |
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
321 // 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
|
322 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
|
323 if (n == std::string::npos) |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
324 { |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
325 sep = " \t"; |
22656
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
326 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
|
327 } |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
328 else |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
329 { |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
330 char ch = line.at (n); |
7580
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
331 |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
332 switch (line.at (n)) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
333 { |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
334 case ' ': |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
335 case '\t': |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
336 sep = " \t"; |
22656
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
337 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
|
338 break; |
7580
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
339 |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
340 default: |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
341 sep = ch; |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
342 break; |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
343 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
344 } |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
345 } |
10804
3d5c6b84ddaf
speed-up fixes to dlmread
Jaroslav Hajek <highegg@gmail.com>
parents:
10718
diff
changeset
|
346 |
22666
68d5c4759783
dlmread: Return correct number of columns when line ends with separator (bug #42025).
Rik <rik@octave.org>
parents:
22657
diff
changeset
|
347 // 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
|
348 if (cmax == 0) |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
349 { |
22656
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
350 size_t pos1, pos2; |
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
351 if (auto_sep_is_wspace) |
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
352 pos1 = line.find_first_not_of (" \t"); |
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
353 else |
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
354 pos1 = 0; |
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
355 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
356 do |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
357 { |
22656
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
358 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
|
359 |
22656
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
360 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
|
361 { |
22656
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
362 // 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
|
363 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
|
364 if (pos2 != std::string::npos) |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
365 pos2 -= 1; |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
366 } |
7580
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
367 |
22666
68d5c4759783
dlmread: Return correct number of columns when line ends with separator (bug #42025).
Rik <rik@octave.org>
parents:
22657
diff
changeset
|
368 // 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
|
369 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
|
370 cmax++; |
7581 | 371 |
22656
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
372 pos1 = pos2 + 1; |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
373 } |
22656
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
374 while (pos2 != std::string::npos); |
7581 | 375 |
22666
68d5c4759783
dlmread: Return correct number of columns when line ends with separator (bug #42025).
Rik <rik@octave.org>
parents:
22657
diff
changeset
|
376 // 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
|
377 // 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
|
378 if (iscmplx) |
22657
a93887d7f0da
Use EmptyValue option correctly in all instances (bug #42023).
Rik <rik@octave.org>
parents:
22656
diff
changeset
|
379 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
|
380 else |
22657
a93887d7f0da
Use EmptyValue option correctly in all instances (bug #42023).
Rik <rik@octave.org>
parents:
22656
diff
changeset
|
381 rdata.resize (rmax, cmax, empty_value); |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
382 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
383 |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
384 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
|
385 j = 0; |
22656
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
386 |
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
387 size_t pos1, pos2; |
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
388 if (auto_sep_is_wspace) |
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
389 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
|
390 else |
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
391 pos1 = 0; |
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
392 |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
393 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
|
394 { |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
395 octave_quit (); |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
396 |
22656
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
397 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
|
398 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
|
399 |
22656
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
400 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
|
401 { |
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
402 // Treat consecutive separators as one. |
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
403 pos2 = line.find_first_not_of (sep, pos2); |
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
404 if (pos2 != std::string::npos) |
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
405 pos2 -= 1; |
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
406 else |
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
407 pos2 = line.length () - 1; |
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
408 } |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
409 |
22666
68d5c4759783
dlmread: Return correct number of columns when line ends with separator (bug #42025).
Rik <rik@octave.org>
parents:
22657
diff
changeset
|
410 // 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
|
411 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
|
412 break; |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
413 |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
414 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
|
415 if (r > rmax || c > cmax) |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
416 { |
22656
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
417 // 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
|
418 // 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
|
419 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
|
420 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
|
421 if (iscmplx) |
22657
a93887d7f0da
Use EmptyValue option correctly in all instances (bug #42023).
Rik <rik@octave.org>
parents:
22656
diff
changeset
|
422 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
|
423 else |
22657
a93887d7f0da
Use EmptyValue option correctly in all instances (bug #42023).
Rik <rik@octave.org>
parents:
22656
diff
changeset
|
424 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
|
425 } |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
426 |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
427 tmp_stream.str (str); |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
428 tmp_stream.clear (); |
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 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
|
431 if (tmp_stream) |
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 if (tmp_stream.eof ()) |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
434 { |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
435 if (iscmplx) |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
436 cdata(i,j++) = x; |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
437 else |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
438 rdata(i,j++) = x; |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
439 } |
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 { |
23318
d05f688ae836
dlmread: Add support for reading pure imaginary numbers (bug #50589).
Rik <rik@octave.org>
parents:
23308
diff
changeset
|
442 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
|
443 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
|
444 { |
d05f688ae836
dlmread: Add support for reading pure imaginary numbers (bug #50589).
Rik <rik@octave.org>
parents:
23308
diff
changeset
|
445 // Process pure imaginary numbers. |
d05f688ae836
dlmread: Add support for reading pure imaginary numbers (bug #50589).
Rik <rik@octave.org>
parents:
23308
diff
changeset
|
446 if (! iscmplx) |
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 iscmplx = true; |
d05f688ae836
dlmread: Add support for reading pure imaginary numbers (bug #50589).
Rik <rik@octave.org>
parents:
23308
diff
changeset
|
449 cdata = ComplexMatrix (rdata); |
d05f688ae836
dlmread: Add support for reading pure imaginary numbers (bug #50589).
Rik <rik@octave.org>
parents:
23308
diff
changeset
|
450 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
451 |
23318
d05f688ae836
dlmread: Add support for reading pure imaginary numbers (bug #50589).
Rik <rik@octave.org>
parents:
23308
diff
changeset
|
452 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
|
453 } |
d05f688ae836
dlmread: Add support for reading pure imaginary numbers (bug #50589).
Rik <rik@octave.org>
parents:
23308
diff
changeset
|
454 else |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
455 { |
23318
d05f688ae836
dlmread: Add support for reading pure imaginary numbers (bug #50589).
Rik <rik@octave.org>
parents:
23308
diff
changeset
|
456 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
|
457 |
23318
d05f688ae836
dlmread: Add support for reading pure imaginary numbers (bug #50589).
Rik <rik@octave.org>
parents:
23308
diff
changeset
|
458 if (! iscmplx && y != 0.) |
d05f688ae836
dlmread: Add support for reading pure imaginary numbers (bug #50589).
Rik <rik@octave.org>
parents:
23308
diff
changeset
|
459 { |
d05f688ae836
dlmread: Add support for reading pure imaginary numbers (bug #50589).
Rik <rik@octave.org>
parents:
23308
diff
changeset
|
460 iscmplx = true; |
d05f688ae836
dlmread: Add support for reading pure imaginary numbers (bug #50589).
Rik <rik@octave.org>
parents:
23308
diff
changeset
|
461 cdata = ComplexMatrix (rdata); |
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 |
d05f688ae836
dlmread: Add support for reading pure imaginary numbers (bug #50589).
Rik <rik@octave.org>
parents:
23308
diff
changeset
|
464 if (iscmplx) |
d05f688ae836
dlmread: Add support for reading pure imaginary numbers (bug #50589).
Rik <rik@octave.org>
parents:
23308
diff
changeset
|
465 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
|
466 else |
d05f688ae836
dlmread: Add support for reading pure imaginary numbers (bug #50589).
Rik <rik@octave.org>
parents:
23308
diff
changeset
|
467 rdata(i,j++) = x; |
d05f688ae836
dlmread: Add support for reading pure imaginary numbers (bug #50589).
Rik <rik@octave.org>
parents:
23308
diff
changeset
|
468 } |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
469 } |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
470 } |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
471 else if (iscmplx) |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
472 cdata(i,j++) = empty_value; |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
473 else |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
474 rdata(i,j++) = empty_value; |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
475 |
22656
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
476 pos1 = pos2 + 1; |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
477 } |
22656
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
478 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
|
479 |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
480 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
|
481 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
|
482 |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
483 i++; |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
484 } |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
485 |
23307
85ffe1bdd3a0
dlmread: Return empty matrix when requested range is outside data (bug #50102).
Rik <rik@octave.org>
parents:
23219
diff
changeset
|
486 // 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
|
487 if (r1 >= r) |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
488 r1 = r - 1; |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
489 if (c1 >= c) |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
490 c1 = c - 1; |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
491 |
23307
85ffe1bdd3a0
dlmread: Return empty matrix when requested range is outside data (bug #50102).
Rik <rik@octave.org>
parents:
23219
diff
changeset
|
492 if (iscmplx) |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
493 { |
23307
85ffe1bdd3a0
dlmread: Return empty matrix when requested range is outside data (bug #50102).
Rik <rik@octave.org>
parents:
23219
diff
changeset
|
494 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
|
495 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
|
496 |
85ffe1bdd3a0
dlmread: Return empty matrix when requested range is outside data (bug #50102).
Rik <rik@octave.org>
parents:
23219
diff
changeset
|
497 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
|
498 return ovl (cdata); |
7580
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
499 } |
23307
85ffe1bdd3a0
dlmread: Return empty matrix when requested range is outside data (bug #50102).
Rik <rik@octave.org>
parents:
23219
diff
changeset
|
500 else |
85ffe1bdd3a0
dlmread: Return empty matrix when requested range is outside data (bug #50102).
Rik <rik@octave.org>
parents:
23219
diff
changeset
|
501 { |
85ffe1bdd3a0
dlmread: Return empty matrix when requested range is outside data (bug #50102).
Rik <rik@octave.org>
parents:
23219
diff
changeset
|
502 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
|
503 return ovl (Matrix (0,0)); |
7580
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
504 |
23307
85ffe1bdd3a0
dlmread: Return empty matrix when requested range is outside data (bug #50102).
Rik <rik@octave.org>
parents:
23219
diff
changeset
|
505 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
|
506 return ovl (rdata); |
85ffe1bdd3a0
dlmread: Return empty matrix when requested range is outside data (bug #50102).
Rik <rik@octave.org>
parents:
23219
diff
changeset
|
507 } |
7580
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
508 } |
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
509 |
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
510 /* |
23307
85ffe1bdd3a0
dlmread: Return empty matrix when requested range is outside data (bug #50102).
Rik <rik@octave.org>
parents:
23219
diff
changeset
|
511 %!test |
19278
6ca096827123
Use tempname() rather than tmpnam() in core Octave.
Rik <rik@octave.org>
parents:
18112
diff
changeset
|
512 %! file = tempname (); |
23307
85ffe1bdd3a0
dlmread: Return empty matrix when requested range is outside data (bug #50102).
Rik <rik@octave.org>
parents:
23219
diff
changeset
|
513 %! unwind_protect |
22656
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
514 %! fid = fopen (file, "wt"); |
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
515 %! 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
|
516 %! fclose (fid); |
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
517 %! |
23307
85ffe1bdd3a0
dlmread: Return empty matrix when requested range is outside data (bug #50102).
Rik <rik@octave.org>
parents:
23219
diff
changeset
|
518 %! 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
|
519 %! 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
|
520 %! 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
|
521 %! 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
|
522 %! 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
|
523 %! 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
|
524 %! 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
|
525 %! 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
|
526 %! 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
|
527 %! 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
|
528 %! 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
|
529 %! unwind_protect_cleanup |
85ffe1bdd3a0
dlmread: Return empty matrix when requested range is outside data (bug #50102).
Rik <rik@octave.org>
parents:
23219
diff
changeset
|
530 %! unlink (file); |
85ffe1bdd3a0
dlmread: Return empty matrix when requested range is outside data (bug #50102).
Rik <rik@octave.org>
parents:
23219
diff
changeset
|
531 %! end_unwind_protect |
7580
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
532 |
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
533 %!test |
19278
6ca096827123
Use tempname() rather than tmpnam() in core Octave.
Rik <rik@octave.org>
parents:
18112
diff
changeset
|
534 %! file = tempname (); |
23307
85ffe1bdd3a0
dlmread: Return empty matrix when requested range is outside data (bug #50102).
Rik <rik@octave.org>
parents:
23219
diff
changeset
|
535 %! unwind_protect |
22656
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
536 %! fid = fopen (file, "wt"); |
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
537 %! 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
|
538 %! fclose (fid); |
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
539 %! |
23307
85ffe1bdd3a0
dlmread: Return empty matrix when requested range is outside data (bug #50102).
Rik <rik@octave.org>
parents:
23219
diff
changeset
|
540 %! 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
|
541 %! 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
|
542 %! 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
|
543 %! 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
|
544 %! 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
|
545 %! 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
|
546 %! 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
|
547 %! 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
|
548 %! 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
|
549 %! 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
|
550 %! unwind_protect_cleanup |
85ffe1bdd3a0
dlmread: Return empty matrix when requested range is outside data (bug #50102).
Rik <rik@octave.org>
parents:
23219
diff
changeset
|
551 %! unlink (file); |
85ffe1bdd3a0
dlmread: Return empty matrix when requested range is outside data (bug #50102).
Rik <rik@octave.org>
parents:
23219
diff
changeset
|
552 %! end_unwind_protect |
7580
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
553 |
22656
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
554 %!test <42025> |
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
555 %! file = tempname (); |
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
556 %! unwind_protect |
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
557 %! fid = fopen (file, "wt"); |
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
558 %! fwrite (fid, " \n 1 2\n11 22\n "); |
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
559 %! fclose (fid); |
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
560 %! |
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
561 %! 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
|
562 %! 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
|
563 %! 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
|
564 %! 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
|
565 %! 0, 0, 0, 0]); |
22656
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
566 %! unwind_protect_cleanup |
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
567 %! unlink (file); |
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
568 %! end_unwind_protect |
7580
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
569 |
23318
d05f688ae836
dlmread: Add support for reading pure imaginary numbers (bug #50589).
Rik <rik@octave.org>
parents:
23308
diff
changeset
|
570 %!test <50589> |
d05f688ae836
dlmread: Add support for reading pure imaginary numbers (bug #50589).
Rik <rik@octave.org>
parents:
23308
diff
changeset
|
571 %! file = tempname (); |
d05f688ae836
dlmread: Add support for reading pure imaginary numbers (bug #50589).
Rik <rik@octave.org>
parents:
23308
diff
changeset
|
572 %! unwind_protect |
d05f688ae836
dlmread: Add support for reading pure imaginary numbers (bug #50589).
Rik <rik@octave.org>
parents:
23308
diff
changeset
|
573 %! fid = fopen (file, "wt"); |
d05f688ae836
dlmread: Add support for reading pure imaginary numbers (bug #50589).
Rik <rik@octave.org>
parents:
23308
diff
changeset
|
574 %! 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
|
575 %! 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
|
576 %! 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
|
577 %! 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
|
578 %! fclose (fid); |
d05f688ae836
dlmread: Add support for reading pure imaginary numbers (bug #50589).
Rik <rik@octave.org>
parents:
23308
diff
changeset
|
579 %! |
d05f688ae836
dlmread: Add support for reading pure imaginary numbers (bug #50589).
Rik <rik@octave.org>
parents:
23308
diff
changeset
|
580 %! 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
|
581 %! 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
|
582 %! 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
|
583 %! 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
|
584 %! unwind_protect_cleanup |
85ffe1bdd3a0
dlmread: Return empty matrix when requested range is outside data (bug #50102).
Rik <rik@octave.org>
parents:
23219
diff
changeset
|
585 %! unlink (file); |
85ffe1bdd3a0
dlmread: Return empty matrix when requested range is outside data (bug #50102).
Rik <rik@octave.org>
parents:
23219
diff
changeset
|
586 %! end_unwind_protect |
7580
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
587 |
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
588 */ |