Mercurial > octave
annotate libinterp/corefcn/dlmread.cc @ 28467:159b6a1eb408
Use wide character overload to open file streams on Windows.
* liboctave/system/lo-sysdep.cc, liboctave/system/lo-sysdep.h (fstream,
ifstream, ofstream): Add "wrapper" functions to open file streams.
* libinterp/corefcn/__fcn__.cc (F__ftp_mput__, F__ftp_mget__),
libinterp/corefcn/debug.cc (do_dbtype),
libinterp/corefcn/help.cc (help_system::raw_help_from_docstrings_file),
libinterp/corefcn/load-save.cc (check_gzip_magic,
load_save_system::get_file_format, load_save_system::dump_octave_core,
load_save_system::load, load_save_system::save),
libinterp/corefcn/oct-hist.cc (mk_tmp_hist_file,
history_system::do_edit_history),
libinterp/corefcn/urlwrite.cc (Furlwrite),
libinterp/octave-value/ov-java.cc (read_java_opts, read_classpath_txt),
libinterp/parse-tree/oct-parse.yy (get_file_line),
liboctave/util/cmd-hist.cc (gnu_history::do_append),
liboctave/util/file-info.cc (file_info::snarf_file),
liboctave/util/url-transfer.cc (base_url_transfer::mget_directory,
base_url_transfer::mput_directory): Use new functions.
* libinterp/corefcn/dlmread.cc (dlmread): Use wide character overload for
std::ifstream::open on Windows.
* src/mkoctfile.in.cc (octave_u8_conv_to_encoding): Dummy function for
cross-compiler.
(main): Use wide character overload of std::ofstream::open on Windows.
author | Markus Mützel <markus.muetzel@gmx.de> |
---|---|
date | Fri, 12 Jun 2020 22:13:04 +0200 |
parents | bd51beb6205e |
children | 83172e1c77f2 0a5b15007766 |
rev | line source |
---|---|
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
1 //////////////////////////////////////////////////////////////////////// |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
2 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
3 // Copyright (C) 2008-2020 The Octave Project Developers |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
4 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
5 // See the file COPYRIGHT.md in the top-level directory of this |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
6 // distribution or <https://octave.org/copyright/>. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
7 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
8 // This file is part of Octave. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
9 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
10 // Octave is free software: you can redistribute it and/or modify it |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
11 // under the terms of the GNU General Public License as published by |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
12 // the Free Software Foundation, either version 3 of the License, or |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
13 // (at your option) any later version. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
14 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
15 // Octave is distributed in the hope that it will be useful, but |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
16 // WITHOUT ANY WARRANTY; without even the implied warranty of |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
18 // GNU General Public License for more details. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
19 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
20 // You should have received a copy of the GNU General Public License |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
21 // along with Octave; see the file COPYING. If not, see |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
22 // <https://www.gnu.org/licenses/>. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
23 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
24 //////////////////////////////////////////////////////////////////////// |
7580
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
25 |
7581 | 26 // Adapted from previous version of dlmread.occ as authored by Kai |
27 // 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
|
28 |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21593
diff
changeset
|
29 #if defined (HAVE_CONFIG_H) |
21301
40de9f8f23a6
Use '#include "config.h"' rather than <config.h>.
Rik <rik@octave.org>
parents:
21200
diff
changeset
|
30 # include "config.h" |
7580
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
31 #endif |
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
32 |
25679
4596a80cbc18
Correctly read "Name" as empty_value in dlmread (bug #54029)
Rik <rik@octave.org>
parents:
25672
diff
changeset
|
33 #include <cmath> |
7581 | 34 #include <cctype> |
35 #include <fstream> | |
10804
3d5c6b84ddaf
speed-up fixes to dlmread
Jaroslav Hajek <highegg@gmail.com>
parents:
10718
diff
changeset
|
36 #include <limits> |
7581 | 37 |
9512
56e850e3b06f
dlmread: perform tilde expansion to filename argument
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
38 #include "file-ops.h" |
7580
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
39 #include "lo-ieee.h" |
25548
d6050ba12c0c
Call get_ASCII_filename for std::ifstream (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25054
diff
changeset
|
40 #include "lo-sysdep.h" |
7580
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
41 |
15039
e753177cde93
maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents:
14501
diff
changeset
|
42 #include "defun.h" |
23738
8acd390d16c9
don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents:
23573
diff
changeset
|
43 #include "interpreter.h" |
10927
a9e9659e1dca
support file IDs in dlmread
Jaroslav Hajek <highegg@gmail.com>
parents:
10806
diff
changeset
|
44 #include "oct-stream.h" |
7580
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
45 #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
|
46 #include "ovl.h" |
7580
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
47 #include "utils.h" |
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
48 |
27277
db687716fed6
style fixes: generally aim to break long lines before operators, not after
John W. Eaton <jwe@octave.org>
parents:
27028
diff
changeset
|
49 static const octave_idx_type idx_max |
db687716fed6
style fixes: generally aim to break long lines before operators, not after
John W. Eaton <jwe@octave.org>
parents:
27028
diff
changeset
|
50 = std::numeric_limits<octave_idx_type>::max () - 1; |
23323
31be59137160
Don't error out if RANGE specification for dlmread contains large values.
Rik <rik@octave.org>
parents:
23307
diff
changeset
|
51 |
31be59137160
Don't error out if RANGE specification for dlmread contains large values.
Rik <rik@octave.org>
parents:
23307
diff
changeset
|
52 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
|
53 |
7580
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
54 static bool |
10804
3d5c6b84ddaf
speed-up fixes to dlmread
Jaroslav Hajek <highegg@gmail.com>
parents:
10718
diff
changeset
|
55 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
|
56 { |
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
57 bool stat = false; |
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
58 |
7581 | 59 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
|
60 stat = true; |
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
61 else |
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
62 { |
7581 | 63 if (::isalpha (is.peek ())) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
64 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
65 col = 0; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
66 while (is && ::isalpha (is.peek ())) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
67 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
68 char ch = is.get (); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
69 col *= 26; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
70 if (ch >= 'a') |
10718
b8d76f4be94a
Fix spreadsheet style range option (bug #30183).
Rik <octave@nomad.inbox5.com>
parents:
10350
diff
changeset
|
71 col += ch - 'a' + 1; |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
72 else |
10718
b8d76f4be94a
Fix spreadsheet style range option (bug #30183).
Rik <octave@nomad.inbox5.com>
parents:
10350
diff
changeset
|
73 col += ch - 'A' + 1; |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
74 } |
21062
d9c1884d1aaa
maint: Eliminate space between variable and decrement '--' operator.
Rik <rik@octave.org>
parents:
20955
diff
changeset
|
75 col--; |
7580
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
76 |
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 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
79 is >> row; |
21062
d9c1884d1aaa
maint: Eliminate space between variable and decrement '--' operator.
Rik <rik@octave.org>
parents:
20955
diff
changeset
|
80 row--; |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
81 if (is) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
82 stat = true; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
83 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
84 } |
7580
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 |
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
87 return stat; |
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
88 } |
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 static bool |
7581 | 91 parse_range_spec (const octave_value& range_spec, |
10804
3d5c6b84ddaf
speed-up fixes to dlmread
Jaroslav Hajek <highegg@gmail.com>
parents:
10718
diff
changeset
|
92 octave_idx_type& rlo, octave_idx_type& clo, |
3d5c6b84ddaf
speed-up fixes to dlmread
Jaroslav Hajek <highegg@gmail.com>
parents:
10718
diff
changeset
|
93 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
|
94 { |
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
95 bool stat = true; |
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 (range_spec.is_string ()) |
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
98 { |
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
99 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
|
100 char ch = is.peek (); |
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
101 |
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
102 if (ch == '.' || ch == ':') |
10154
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 rlo = 0; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
105 clo = 0; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
106 ch = is.get (); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
107 if (ch == '.') |
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 ch = is.get (); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
110 if (ch != '.') |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
111 stat = false; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
112 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
113 } |
7580
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
114 else |
10154
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 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
|
117 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
118 if (stat) |
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.peek (); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
121 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
122 if (ch == '.' || ch == ':') |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
123 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
124 ch = is.get (); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
125 if (ch == '.') |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
126 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
127 ch = is.get (); |
20955
77f5591878bf
maint: Use '! expr' rather than '!expr' to conform to coding guidelines.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
128 if (! is || ch != '.') |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
129 stat = false; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
130 } |
7580
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
131 |
23323
31be59137160
Don't error out if RANGE specification for dlmread contains large values.
Rik <rik@octave.org>
parents:
23307
diff
changeset
|
132 rup = idx_max; |
31be59137160
Don't error out if RANGE specification for dlmread contains large values.
Rik <rik@octave.org>
parents:
23307
diff
changeset
|
133 cup = idx_max; |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
134 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
135 else |
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 rup = rlo; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
138 cup = clo; |
20955
77f5591878bf
maint: Use '! expr' rather than '!expr' to conform to coding guidelines.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
139 if (! is || ! is.eof ()) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
140 stat = false; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
141 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
142 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
143 } |
7580
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
144 |
20955
77f5591878bf
maint: Use '! expr' rather than '!expr' to conform to coding guidelines.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
145 if (stat && is && ! is.eof ()) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
146 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
|
147 |
20955
77f5591878bf
maint: Use '! expr' rather than '!expr' to conform to coding guidelines.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
148 if (! is || ! is.eof ()) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
149 stat = false; |
7580
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
150 } |
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
151 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
|
152 { |
27028
2d36701216e9
Validate RANGE input to dlmread does not contain NaN (bug #56047).
Rik <rik@octave.org>
parents:
26376
diff
changeset
|
153 NDArray range (range_spec.array_value ()); |
2d36701216e9
Validate RANGE input to dlmread does not contain NaN (bug #56047).
Rik <rik@octave.org>
parents:
26376
diff
changeset
|
154 if (range.any_element_is_nan ()) |
2d36701216e9
Validate RANGE input to dlmread does not contain NaN (bug #56047).
Rik <rik@octave.org>
parents:
26376
diff
changeset
|
155 error ("dlmread: NaN is not a valid row or column specifier"); |
2d36701216e9
Validate RANGE input to dlmread does not contain NaN (bug #56047).
Rik <rik@octave.org>
parents:
26376
diff
changeset
|
156 |
23323
31be59137160
Don't error out if RANGE specification for dlmread contains large values.
Rik <rik@octave.org>
parents:
23307
diff
changeset
|
157 // 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
|
158 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
|
159 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
|
160 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
|
161 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
|
162 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
163 else |
7580
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
164 stat = false; |
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
165 |
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
166 return stat; |
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
167 } |
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
168 |
23738
8acd390d16c9
don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents:
23573
diff
changeset
|
169 DEFMETHOD (dlmread, interp, args, , |
8acd390d16c9
don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents:
23573
diff
changeset
|
170 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
|
171 @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
|
172 @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
|
173 @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
|
174 @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
|
175 @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
|
176 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
|
177 @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
|
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 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
|
180 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
|
181 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21733
diff
changeset
|
182 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
|
183 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
|
184 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
|
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 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
|
187 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
|
188 left and lower right corners @code{[@var{R0},@var{C0},@var{R1},@var{C1}]} |
27028
2d36701216e9
Validate RANGE input to dlmread does not contain NaN (bug #56047).
Rik <rik@octave.org>
parents:
26376
diff
changeset
|
189 where the indices are zero-based. To specify the last column---the equivalent |
2d36701216e9
Validate RANGE input to dlmread does not contain NaN (bug #56047).
Rik <rik@octave.org>
parents:
26376
diff
changeset
|
190 of @code{end} when indexing---use the specifier @code{Inf}. Alternatively, a |
2d36701216e9
Validate RANGE input to dlmread does not contain NaN (bug #56047).
Rik <rik@octave.org>
parents:
26376
diff
changeset
|
191 spreadsheet style form such as @qcode{"A2..Q15"} or @qcode{"T1:AA5"} can be |
2d36701216e9
Validate RANGE input to dlmread does not contain NaN (bug #56047).
Rik <rik@octave.org>
parents:
26376
diff
changeset
|
192 used. The lowest alphabetical index @qcode{'A'} refers to the first column. |
2d36701216e9
Validate RANGE input to dlmread does not contain NaN (bug #56047).
Rik <rik@octave.org>
parents:
26376
diff
changeset
|
193 The lowest row index is 1. |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21733
diff
changeset
|
194 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21733
diff
changeset
|
195 @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
|
196 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
|
197 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21733
diff
changeset
|
198 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
|
199 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
|
200 such as text, are also replaced by the @qcode{"emptyvalue"}. |
25764
826b45c1c427
textread.m: Make m-file a legacy function.
Rik <rik@octave.org>
parents:
25686
diff
changeset
|
201 @seealso{csvread, textscan, dlmwrite} |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21733
diff
changeset
|
202 @end deftypefn */) |
7580
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
203 { |
7581 | 204 int nargin = args.length (); |
205 | |
10935
3cb4889dd6f7
support specific empty value in dlmread
Jaroslav Hajek <highegg@gmail.com>
parents:
10927
diff
changeset
|
206 double empty_value = 0.0; |
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 > 2 && args(nargin-2).is_string () |
10935
3cb4889dd6f7
support specific empty value in dlmread
Jaroslav Hajek <highegg@gmail.com>
parents:
10927
diff
changeset
|
209 && args(nargin-2).string_value () == "emptyvalue") |
3cb4889dd6f7
support specific empty value in dlmread
Jaroslav Hajek <highegg@gmail.com>
parents:
10927
diff
changeset
|
210 { |
3cb4889dd6f7
support specific empty value in dlmread
Jaroslav Hajek <highegg@gmail.com>
parents:
10927
diff
changeset
|
211 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
|
212 |
10935
3cb4889dd6f7
support specific empty value in dlmread
Jaroslav Hajek <highegg@gmail.com>
parents:
10927
diff
changeset
|
213 nargin -= 2; |
3cb4889dd6f7
support specific empty value in dlmread
Jaroslav Hajek <highegg@gmail.com>
parents:
10927
diff
changeset
|
214 } |
3cb4889dd6f7
support specific empty value in dlmread
Jaroslav Hajek <highegg@gmail.com>
parents:
10927
diff
changeset
|
215 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
216 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
|
217 print_usage (); |
7580
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
218 |
23457
21baad6b35c4
maint: Use C++11 nullptr rather than 0 or NULL when possible.
Rik <rik@octave.org>
parents:
23395
diff
changeset
|
219 std::istream *input = nullptr; |
11389
934ed3e07542
dlmread: simplify file name/id logic
John W. Eaton <jwe@octave.org>
parents:
10935
diff
changeset
|
220 std::ifstream input_file; |
10927
a9e9659e1dca
support file IDs in dlmread
Jaroslav Hajek <highegg@gmail.com>
parents:
10806
diff
changeset
|
221 |
a9e9659e1dca
support file IDs in dlmread
Jaroslav Hajek <highegg@gmail.com>
parents:
10806
diff
changeset
|
222 if (args(0).is_string ()) |
7580
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
223 { |
20713
2469d78a1d8b
Consistently use 'filename' rather than 'file name' throughout code base.
Rik <rik@octave.org>
parents:
20555
diff
changeset
|
224 // Filename. |
10927
a9e9659e1dca
support file IDs in dlmread
Jaroslav Hajek <highegg@gmail.com>
parents:
10806
diff
changeset
|
225 std::string fname (args(0).string_value ()); |
a9e9659e1dca
support file IDs in dlmread
Jaroslav Hajek <highegg@gmail.com>
parents:
10806
diff
changeset
|
226 |
21733
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
227 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
|
228 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25604
diff
changeset
|
229 tname = octave::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
|
230 |
28467
159b6a1eb408
Use wide character overload to open file streams on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents:
27923
diff
changeset
|
231 #if defined (OCTAVE_USE_WINDOWS_API) |
159b6a1eb408
Use wide character overload to open file streams on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents:
27923
diff
changeset
|
232 std::wstring wname = octave::sys::u8_to_wstring (tname); |
159b6a1eb408
Use wide character overload to open file streams on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents:
27923
diff
changeset
|
233 input_file.open (wname.c_str (), std::ios::in); |
159b6a1eb408
Use wide character overload to open file streams on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents:
27923
diff
changeset
|
234 #else |
159b6a1eb408
Use wide character overload to open file streams on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents:
27923
diff
changeset
|
235 input_file.open (tname.c_str (), std::ios::in); |
159b6a1eb408
Use wide character overload to open file streams on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents:
27923
diff
changeset
|
236 #endif |
11389
934ed3e07542
dlmread: simplify file name/id logic
John W. Eaton <jwe@octave.org>
parents:
10935
diff
changeset
|
237 |
934ed3e07542
dlmread: simplify file name/id logic
John W. Eaton <jwe@octave.org>
parents:
10935
diff
changeset
|
238 if (! input_file) |
20831
35241c4b696c
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20802
diff
changeset
|
239 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
|
240 |
35241c4b696c
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20802
diff
changeset
|
241 input = &input_file; |
10927
a9e9659e1dca
support file IDs in dlmread
Jaroslav Hajek <highegg@gmail.com>
parents:
10806
diff
changeset
|
242 } |
a9e9659e1dca
support file IDs in dlmread
Jaroslav Hajek <highegg@gmail.com>
parents:
10806
diff
changeset
|
243 else if (args(0).is_scalar_type ()) |
a9e9659e1dca
support file IDs in dlmread
Jaroslav Hajek <highegg@gmail.com>
parents:
10806
diff
changeset
|
244 { |
23738
8acd390d16c9
don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents:
23573
diff
changeset
|
245 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
|
246 |
8acd390d16c9
don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents:
23573
diff
changeset
|
247 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
|
248 |
934ed3e07542
dlmread: simplify file name/id logic
John W. Eaton <jwe@octave.org>
parents:
10935
diff
changeset
|
249 input = is.input_stream (); |
934ed3e07542
dlmread: simplify file name/id logic
John W. Eaton <jwe@octave.org>
parents:
10935
diff
changeset
|
250 |
10927
a9e9659e1dca
support file IDs in dlmread
Jaroslav Hajek <highegg@gmail.com>
parents:
10806
diff
changeset
|
251 if (! input) |
20831
35241c4b696c
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20802
diff
changeset
|
252 error ("dlmread: stream FILE not open for input"); |
10927
a9e9659e1dca
support file IDs in dlmread
Jaroslav Hajek <highegg@gmail.com>
parents:
10806
diff
changeset
|
253 } |
a9e9659e1dca
support file IDs in dlmread
Jaroslav Hajek <highegg@gmail.com>
parents:
10806
diff
changeset
|
254 else |
20831
35241c4b696c
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20802
diff
changeset
|
255 error ("dlmread: FILE argument must be a string or file id"); |
7581 | 256 |
257 // Set default separator. | |
7580
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
258 std::string sep; |
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
259 if (nargin > 1) |
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 (args(1).is_sq_string ()) |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25604
diff
changeset
|
262 sep = octave::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
|
263 else |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
264 sep = args(1).string_value (); |
7580
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
265 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
266 |
7581 | 267 // 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
|
268 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
|
269 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
|
270 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
|
271 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
|
272 if (nargin > 2) |
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
273 { |
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
274 if (nargin == 3) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
275 { |
20955
77f5591878bf
maint: Use '! expr' rather than '!expr' to conform to coding guidelines.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
276 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
|
277 error ("dlmread: error parsing RANGE"); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
278 } |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
279 else if (nargin == 4) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
280 { |
10804
3d5c6b84ddaf
speed-up fixes to dlmread
Jaroslav Hajek <highegg@gmail.com>
parents:
10718
diff
changeset
|
281 r0 = args(2).idx_type_value (); |
3d5c6b84ddaf
speed-up fixes to dlmread
Jaroslav Hajek <highegg@gmail.com>
parents:
10718
diff
changeset
|
282 c0 = args(3).idx_type_value (); |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
283 } |
10804
3d5c6b84ddaf
speed-up fixes to dlmread
Jaroslav Hajek <highegg@gmail.com>
parents:
10718
diff
changeset
|
284 |
3d5c6b84ddaf
speed-up fixes to dlmread
Jaroslav Hajek <highegg@gmail.com>
parents:
10718
diff
changeset
|
285 if (r0 < 0 || c0 < 0) |
27028
2d36701216e9
Validate RANGE input to dlmread does not contain NaN (bug #56047).
Rik <rik@octave.org>
parents:
26376
diff
changeset
|
286 error ("dlmread: left (R0) and top (C0) 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
|
287 |
23394
7ca04e85f9e3
maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents:
23323
diff
changeset
|
288 // 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
|
289 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
|
290 return ovl (Matrix (0,0)); |
7580
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
291 } |
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
292 |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
293 octave_idx_type i = 0; |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
294 octave_idx_type j = 0; |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
295 octave_idx_type r = 1; |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
296 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
|
297 // 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
|
298 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
|
299 octave_idx_type cmax = 0; |
7581 | 300 |
22666
68d5c4759783
dlmread: Return correct number of columns when line ends with separator (bug #42025).
Rik <rik@octave.org>
parents:
22657
diff
changeset
|
301 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
|
302 ComplexMatrix cdata; |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
303 |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
304 bool iscmplx = false; |
22656
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
305 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
|
306 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
|
307 |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
308 std::string line; |
7581 | 309 |
23323
31be59137160
Don't error out if RANGE specification for dlmread contains large values.
Rik <rik@octave.org>
parents:
23307
diff
changeset
|
310 // 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
|
311 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
|
312 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
|
313 rcnt--; |
31be59137160
Don't error out if RANGE specification for dlmread contains large values.
Rik <rik@octave.org>
parents:
23307
diff
changeset
|
314 |
31be59137160
Don't error out if RANGE specification for dlmread contains large values.
Rik <rik@octave.org>
parents:
23307
diff
changeset
|
315 if (rcnt > 0) |
31be59137160
Don't error out if RANGE specification for dlmread contains large values.
Rik <rik@octave.org>
parents:
23307
diff
changeset
|
316 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
|
317 else |
31be59137160
Don't error out if RANGE specification for dlmread contains large values.
Rik <rik@octave.org>
parents:
23307
diff
changeset
|
318 r1 -= r0; |
7581 | 319 |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
320 std::istringstream tmp_stream; |
7581 | 321 |
22656
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
322 // 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
|
323 while (getline (*input, line)) |
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 // Skip blank lines for compatibility. |
22656
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
326 if ((! sep_is_wspace || auto_sep_is_wspace) |
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
327 && 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
|
328 continue; |
7580
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
329 |
22656
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
330 // Infer separator from file if delimiter is blank. |
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
331 if (sep.empty ()) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
332 { |
22621
e7699adac1d0
Do a better job of delimiter auto-dedection in dlmread (bug #42022).
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
333 // Skip leading whitespace. |
e7699adac1d0
Do a better job of delimiter auto-dedection in dlmread (bug #42022).
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
334 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
|
335 |
22656
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
336 // For Matlab compatibility, blank delimiter should |
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
337 // 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
|
338 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
|
339 if (n == std::string::npos) |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
340 { |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
341 sep = " \t"; |
22656
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
342 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
|
343 } |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
344 else |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
345 { |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
346 char ch = line.at (n); |
7580
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
347 |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
348 switch (line.at (n)) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
349 { |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
350 case ' ': |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
351 case '\t': |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
352 sep = " \t"; |
22656
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
353 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
|
354 break; |
7580
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
355 |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
356 default: |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
357 sep = ch; |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
358 break; |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
359 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
360 } |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
361 } |
10804
3d5c6b84ddaf
speed-up fixes to dlmread
Jaroslav Hajek <highegg@gmail.com>
parents:
10718
diff
changeset
|
362 |
22666
68d5c4759783
dlmread: Return correct number of columns when line ends with separator (bug #42025).
Rik <rik@octave.org>
parents:
22657
diff
changeset
|
363 // 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
|
364 if (cmax == 0) |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
365 { |
22656
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
366 size_t pos1, pos2; |
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
367 if (auto_sep_is_wspace) |
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
368 pos1 = line.find_first_not_of (" \t"); |
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
369 else |
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
370 pos1 = 0; |
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
371 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
372 do |
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 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
|
375 |
22656
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
376 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
|
377 { |
22656
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
378 // 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
|
379 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
|
380 if (pos2 != std::string::npos) |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
381 pos2 -= 1; |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
382 } |
7580
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
383 |
22666
68d5c4759783
dlmread: Return correct number of columns when line ends with separator (bug #42025).
Rik <rik@octave.org>
parents:
22657
diff
changeset
|
384 // 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
|
385 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
|
386 cmax++; |
7581 | 387 |
22656
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
388 pos1 = pos2 + 1; |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
389 } |
22656
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
390 while (pos2 != std::string::npos); |
7581 | 391 |
22666
68d5c4759783
dlmread: Return correct number of columns when line ends with separator (bug #42025).
Rik <rik@octave.org>
parents:
22657
diff
changeset
|
392 // 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
|
393 // 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
|
394 if (iscmplx) |
22657
a93887d7f0da
Use EmptyValue option correctly in all instances (bug #42023).
Rik <rik@octave.org>
parents:
22656
diff
changeset
|
395 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
|
396 else |
22657
a93887d7f0da
Use EmptyValue option correctly in all instances (bug #42023).
Rik <rik@octave.org>
parents:
22656
diff
changeset
|
397 rdata.resize (rmax, cmax, empty_value); |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
398 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
399 |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
400 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
|
401 j = 0; |
22656
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
402 |
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
403 size_t pos1, pos2; |
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
404 if (auto_sep_is_wspace) |
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
405 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
|
406 else |
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
407 pos1 = 0; |
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 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
|
410 { |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
411 octave_quit (); |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
412 |
22656
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
413 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
|
414 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
|
415 |
22656
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
416 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
|
417 { |
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
418 // Treat consecutive separators as one. |
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
419 pos2 = line.find_first_not_of (sep, pos2); |
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
420 if (pos2 != std::string::npos) |
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
421 pos2 -= 1; |
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
422 else |
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
423 pos2 = line.length () - 1; |
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
424 } |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
425 |
22666
68d5c4759783
dlmread: Return correct number of columns when line ends with separator (bug #42025).
Rik <rik@octave.org>
parents:
22657
diff
changeset
|
426 // 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
|
427 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
|
428 break; |
20555
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 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
|
431 if (r > rmax || c > cmax) |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
432 { |
22656
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
433 // 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
|
434 // 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
|
435 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
|
436 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
|
437 if (iscmplx) |
22657
a93887d7f0da
Use EmptyValue option correctly in all instances (bug #42023).
Rik <rik@octave.org>
parents:
22656
diff
changeset
|
438 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
|
439 else |
22657
a93887d7f0da
Use EmptyValue option correctly in all instances (bug #42023).
Rik <rik@octave.org>
parents:
22656
diff
changeset
|
440 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
|
441 } |
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 tmp_stream.str (str); |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
444 tmp_stream.clear (); |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
445 |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
446 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
|
447 if (tmp_stream) |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
448 { |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
449 if (tmp_stream.eof ()) |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
450 { |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
451 if (iscmplx) |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
452 cdata(i,j++) = x; |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
453 else |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
454 rdata(i,j++) = x; |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
455 } |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
456 else |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
457 { |
25874
11f63a33732e
dlmread.cc: Avoid tolower which causes problems when locale changes (bug #54622).
Rik <rik@octave.org>
parents:
25764
diff
changeset
|
458 int next_char = tmp_stream.peek (); |
11f63a33732e
dlmread.cc: Avoid tolower which causes problems when locale changes (bug #54622).
Rik <rik@octave.org>
parents:
25764
diff
changeset
|
459 if (next_char == 'i' || next_char == 'j' |
11f63a33732e
dlmread.cc: Avoid tolower which causes problems when locale changes (bug #54622).
Rik <rik@octave.org>
parents:
25764
diff
changeset
|
460 || next_char == 'I' || next_char == 'J') |
23318
d05f688ae836
dlmread: Add support for reading pure imaginary numbers (bug #50589).
Rik <rik@octave.org>
parents:
23308
diff
changeset
|
461 { |
d05f688ae836
dlmread: Add support for reading pure imaginary numbers (bug #50589).
Rik <rik@octave.org>
parents:
23308
diff
changeset
|
462 // Process pure imaginary numbers. |
25686
af0b81f2ffe6
Correctly handle corner cases in dlmread.
Rik <rik@octave.org>
parents:
25679
diff
changeset
|
463 tmp_stream.get (); |
af0b81f2ffe6
Correctly handle corner cases in dlmread.
Rik <rik@octave.org>
parents:
25679
diff
changeset
|
464 next_char = tmp_stream.peek (); |
af0b81f2ffe6
Correctly handle corner cases in dlmread.
Rik <rik@octave.org>
parents:
25679
diff
changeset
|
465 if (next_char == std::istringstream::traits_type::eof ()) |
23318
d05f688ae836
dlmread: Add support for reading pure imaginary numbers (bug #50589).
Rik <rik@octave.org>
parents:
23308
diff
changeset
|
466 { |
25686
af0b81f2ffe6
Correctly handle corner cases in dlmread.
Rik <rik@octave.org>
parents:
25679
diff
changeset
|
467 if (! iscmplx) |
af0b81f2ffe6
Correctly handle corner cases in dlmread.
Rik <rik@octave.org>
parents:
25679
diff
changeset
|
468 { |
af0b81f2ffe6
Correctly handle corner cases in dlmread.
Rik <rik@octave.org>
parents:
25679
diff
changeset
|
469 iscmplx = true; |
af0b81f2ffe6
Correctly handle corner cases in dlmread.
Rik <rik@octave.org>
parents:
25679
diff
changeset
|
470 cdata = ComplexMatrix (rdata); |
af0b81f2ffe6
Correctly handle corner cases in dlmread.
Rik <rik@octave.org>
parents:
25679
diff
changeset
|
471 } |
af0b81f2ffe6
Correctly handle corner cases in dlmread.
Rik <rik@octave.org>
parents:
25679
diff
changeset
|
472 |
af0b81f2ffe6
Correctly handle corner cases in dlmread.
Rik <rik@octave.org>
parents:
25679
diff
changeset
|
473 cdata(i,j++) = Complex (0, x); |
23318
d05f688ae836
dlmread: Add support for reading pure imaginary numbers (bug #50589).
Rik <rik@octave.org>
parents:
23308
diff
changeset
|
474 } |
25686
af0b81f2ffe6
Correctly handle corner cases in dlmread.
Rik <rik@octave.org>
parents:
25679
diff
changeset
|
475 else |
af0b81f2ffe6
Correctly handle corner cases in dlmread.
Rik <rik@octave.org>
parents:
25679
diff
changeset
|
476 { |
af0b81f2ffe6
Correctly handle corner cases in dlmread.
Rik <rik@octave.org>
parents:
25679
diff
changeset
|
477 // Parsing failed, <number>i|j<extra text> |
af0b81f2ffe6
Correctly handle corner cases in dlmread.
Rik <rik@octave.org>
parents:
25679
diff
changeset
|
478 j++; // Leave data initialized to empty_value |
af0b81f2ffe6
Correctly handle corner cases in dlmread.
Rik <rik@octave.org>
parents:
25679
diff
changeset
|
479 } |
23318
d05f688ae836
dlmread: Add support for reading pure imaginary numbers (bug #50589).
Rik <rik@octave.org>
parents:
23308
diff
changeset
|
480 } |
25679
4596a80cbc18
Correctly read "Name" as empty_value in dlmread (bug #54029)
Rik <rik@octave.org>
parents:
25672
diff
changeset
|
481 else if (std::isalpha (next_char) && ! std::isfinite (x)) |
25686
af0b81f2ffe6
Correctly handle corner cases in dlmread.
Rik <rik@octave.org>
parents:
25679
diff
changeset
|
482 { |
af0b81f2ffe6
Correctly handle corner cases in dlmread.
Rik <rik@octave.org>
parents:
25679
diff
changeset
|
483 // Parsing failed, <Inf|NA|NaN><extra text> |
af0b81f2ffe6
Correctly handle corner cases in dlmread.
Rik <rik@octave.org>
parents:
25679
diff
changeset
|
484 j++; // Leave data initialized to empty_value |
af0b81f2ffe6
Correctly handle corner cases in dlmread.
Rik <rik@octave.org>
parents:
25679
diff
changeset
|
485 } |
23318
d05f688ae836
dlmread: Add support for reading pure imaginary numbers (bug #50589).
Rik <rik@octave.org>
parents:
23308
diff
changeset
|
486 else |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
487 { |
23318
d05f688ae836
dlmread: Add support for reading pure imaginary numbers (bug #50589).
Rik <rik@octave.org>
parents:
23308
diff
changeset
|
488 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
|
489 |
26349
6ec8b2eab987
dlmread.cc: Fix static analyzer detected issues (bug #55347).
Rik <rik@octave.org>
parents:
25874
diff
changeset
|
490 if (! iscmplx && y != 0.0) |
23318
d05f688ae836
dlmread: Add support for reading pure imaginary numbers (bug #50589).
Rik <rik@octave.org>
parents:
23308
diff
changeset
|
491 { |
d05f688ae836
dlmread: Add support for reading pure imaginary numbers (bug #50589).
Rik <rik@octave.org>
parents:
23308
diff
changeset
|
492 iscmplx = true; |
d05f688ae836
dlmread: Add support for reading pure imaginary numbers (bug #50589).
Rik <rik@octave.org>
parents:
23308
diff
changeset
|
493 cdata = ComplexMatrix (rdata); |
d05f688ae836
dlmread: Add support for reading pure imaginary numbers (bug #50589).
Rik <rik@octave.org>
parents:
23308
diff
changeset
|
494 } |
d05f688ae836
dlmread: Add support for reading pure imaginary numbers (bug #50589).
Rik <rik@octave.org>
parents:
23308
diff
changeset
|
495 |
d05f688ae836
dlmread: Add support for reading pure imaginary numbers (bug #50589).
Rik <rik@octave.org>
parents:
23308
diff
changeset
|
496 if (iscmplx) |
d05f688ae836
dlmread: Add support for reading pure imaginary numbers (bug #50589).
Rik <rik@octave.org>
parents:
23308
diff
changeset
|
497 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
|
498 else |
d05f688ae836
dlmread: Add support for reading pure imaginary numbers (bug #50589).
Rik <rik@octave.org>
parents:
23308
diff
changeset
|
499 rdata(i,j++) = x; |
d05f688ae836
dlmread: Add support for reading pure imaginary numbers (bug #50589).
Rik <rik@octave.org>
parents:
23308
diff
changeset
|
500 } |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
501 } |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
502 } |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
503 else |
25686
af0b81f2ffe6
Correctly handle corner cases in dlmread.
Rik <rik@octave.org>
parents:
25679
diff
changeset
|
504 { |
af0b81f2ffe6
Correctly handle corner cases in dlmread.
Rik <rik@octave.org>
parents:
25679
diff
changeset
|
505 // octave_read_double() parsing failed |
af0b81f2ffe6
Correctly handle corner cases in dlmread.
Rik <rik@octave.org>
parents:
25679
diff
changeset
|
506 j++; // Leave data initialized to empty_value |
af0b81f2ffe6
Correctly handle corner cases in dlmread.
Rik <rik@octave.org>
parents:
25679
diff
changeset
|
507 } |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
508 |
22656
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
509 pos1 = pos2 + 1; |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
510 } |
22656
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
511 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
|
512 |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
513 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
|
514 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
|
515 |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
516 i++; |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
517 } |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
518 |
23307
85ffe1bdd3a0
dlmread: Return empty matrix when requested range is outside data (bug #50102).
Rik <rik@octave.org>
parents:
23219
diff
changeset
|
519 // 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
|
520 if (r1 >= r) |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
521 r1 = r - 1; |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
522 if (c1 >= c) |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
523 c1 = c - 1; |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
524 |
23307
85ffe1bdd3a0
dlmread: Return empty matrix when requested range is outside data (bug #50102).
Rik <rik@octave.org>
parents:
23219
diff
changeset
|
525 if (iscmplx) |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
526 { |
23307
85ffe1bdd3a0
dlmread: Return empty matrix when requested range is outside data (bug #50102).
Rik <rik@octave.org>
parents:
23219
diff
changeset
|
527 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
|
528 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
|
529 |
85ffe1bdd3a0
dlmread: Return empty matrix when requested range is outside data (bug #50102).
Rik <rik@octave.org>
parents:
23219
diff
changeset
|
530 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
|
531 return ovl (cdata); |
7580
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
532 } |
23307
85ffe1bdd3a0
dlmread: Return empty matrix when requested range is outside data (bug #50102).
Rik <rik@octave.org>
parents:
23219
diff
changeset
|
533 else |
85ffe1bdd3a0
dlmread: Return empty matrix when requested range is outside data (bug #50102).
Rik <rik@octave.org>
parents:
23219
diff
changeset
|
534 { |
85ffe1bdd3a0
dlmread: Return empty matrix when requested range is outside data (bug #50102).
Rik <rik@octave.org>
parents:
23219
diff
changeset
|
535 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
|
536 return ovl (Matrix (0,0)); |
7580
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
537 |
23307
85ffe1bdd3a0
dlmread: Return empty matrix when requested range is outside data (bug #50102).
Rik <rik@octave.org>
parents:
23219
diff
changeset
|
538 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
|
539 return ovl (rdata); |
85ffe1bdd3a0
dlmread: Return empty matrix when requested range is outside data (bug #50102).
Rik <rik@octave.org>
parents:
23219
diff
changeset
|
540 } |
7580
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
541 } |
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
542 |
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
543 /* |
23307
85ffe1bdd3a0
dlmread: Return empty matrix when requested range is outside data (bug #50102).
Rik <rik@octave.org>
parents:
23219
diff
changeset
|
544 %!test |
19278
6ca096827123
Use tempname() rather than tmpnam() in core Octave.
Rik <rik@octave.org>
parents:
18112
diff
changeset
|
545 %! file = tempname (); |
23307
85ffe1bdd3a0
dlmread: Return empty matrix when requested range is outside data (bug #50102).
Rik <rik@octave.org>
parents:
23219
diff
changeset
|
546 %! unwind_protect |
22656
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
547 %! fid = fopen (file, "wt"); |
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
548 %! 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
|
549 %! fclose (fid); |
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
550 %! |
23307
85ffe1bdd3a0
dlmread: Return empty matrix when requested range is outside data (bug #50102).
Rik <rik@octave.org>
parents:
23219
diff
changeset
|
551 %! 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
|
552 %! 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
|
553 %! 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
|
554 %! 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
|
555 %! 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
|
556 %! 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
|
557 %! 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
|
558 %! 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
|
559 %! 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
|
560 %! 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
|
561 %! 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
|
562 %! unwind_protect_cleanup |
85ffe1bdd3a0
dlmread: Return empty matrix when requested range is outside data (bug #50102).
Rik <rik@octave.org>
parents:
23219
diff
changeset
|
563 %! unlink (file); |
85ffe1bdd3a0
dlmread: Return empty matrix when requested range is outside data (bug #50102).
Rik <rik@octave.org>
parents:
23219
diff
changeset
|
564 %! end_unwind_protect |
7580
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
565 |
24634
ab2321d4ba03
maint: strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
24555
diff
changeset
|
566 %!testif ; ! ismac () |
24477
e8cb11de9383
test: Mark certain bugs as xtest when run on Mac platforms (bug #52627).
Rik <rik@octave.org>
parents:
23738
diff
changeset
|
567 %! file = tempname (); |
e8cb11de9383
test: Mark certain bugs as xtest when run on Mac platforms (bug #52627).
Rik <rik@octave.org>
parents:
23738
diff
changeset
|
568 %! unwind_protect |
e8cb11de9383
test: Mark certain bugs as xtest when run on Mac platforms (bug #52627).
Rik <rik@octave.org>
parents:
23738
diff
changeset
|
569 %! 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
|
570 %! 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
|
571 %! fclose (fid); |
e8cb11de9383
test: Mark certain bugs as xtest when run on Mac platforms (bug #52627).
Rik <rik@octave.org>
parents:
23738
diff
changeset
|
572 %! |
e8cb11de9383
test: Mark certain bugs as xtest when run on Mac platforms (bug #52627).
Rik <rik@octave.org>
parents:
23738
diff
changeset
|
573 %! 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
|
574 %! 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
|
575 %! 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
|
576 %! 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
|
577 %! 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
|
578 %! 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
|
579 %! 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
|
580 %! 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
|
581 %! 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
|
582 %! 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
|
583 %! 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
|
584 %! unlink (file); |
e8cb11de9383
test: Mark certain bugs as xtest when run on Mac platforms (bug #52627).
Rik <rik@octave.org>
parents:
23738
diff
changeset
|
585 %! 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
|
586 |
e8cb11de9383
test: Mark certain bugs as xtest when run on Mac platforms (bug #52627).
Rik <rik@octave.org>
parents:
23738
diff
changeset
|
587 %!xtest <47413> |
e8cb11de9383
test: Mark certain bugs as xtest when run on Mac platforms (bug #52627).
Rik <rik@octave.org>
parents:
23738
diff
changeset
|
588 %! ## 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
|
589 %! if (! ismac ()), return; endif |
19278
6ca096827123
Use tempname() rather than tmpnam() in core Octave.
Rik <rik@octave.org>
parents:
18112
diff
changeset
|
590 %! file = tempname (); |
23307
85ffe1bdd3a0
dlmread: Return empty matrix when requested range is outside data (bug #50102).
Rik <rik@octave.org>
parents:
23219
diff
changeset
|
591 %! unwind_protect |
22656
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
592 %! fid = fopen (file, "wt"); |
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
593 %! 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
|
594 %! fclose (fid); |
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
595 %! |
23307
85ffe1bdd3a0
dlmread: Return empty matrix when requested range is outside data (bug #50102).
Rik <rik@octave.org>
parents:
23219
diff
changeset
|
596 %! 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
|
597 %! 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
|
598 %! 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
|
599 %! 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
|
600 %! 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
|
601 %! 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
|
602 %! 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
|
603 %! 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
|
604 %! 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
|
605 %! 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
|
606 %! unwind_protect_cleanup |
85ffe1bdd3a0
dlmread: Return empty matrix when requested range is outside data (bug #50102).
Rik <rik@octave.org>
parents:
23219
diff
changeset
|
607 %! unlink (file); |
85ffe1bdd3a0
dlmread: Return empty matrix when requested range is outside data (bug #50102).
Rik <rik@octave.org>
parents:
23219
diff
changeset
|
608 %! end_unwind_protect |
7580
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
609 |
23573
1b4f4ec53b4a
use new script to tag fixed bugs in tests
John W. Eaton <jwe@octave.org>
parents:
23572
diff
changeset
|
610 %!test <*42025> |
22656
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
611 %! file = tempname (); |
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
612 %! unwind_protect |
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
613 %! fid = fopen (file, "wt"); |
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
614 %! fwrite (fid, " \n 1 2\n11 22\n "); |
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
615 %! fclose (fid); |
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
616 %! |
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
617 %! 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
|
618 %! 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
|
619 %! 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
|
620 %! 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
|
621 %! 0, 0, 0, 0]); |
22656
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
622 %! unwind_protect_cleanup |
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
623 %! unlink (file); |
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
624 %! end_unwind_protect |
7580
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
625 |
24555
0645853d12d6
test: Mark certain bugs as xtest when run on Mac platforms (bug #52627).
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
626 %!testif ; ! ismac () <*50589> |
0645853d12d6
test: Mark certain bugs as xtest when run on Mac platforms (bug #52627).
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
627 %! file = tempname (); |
0645853d12d6
test: Mark certain bugs as xtest when run on Mac platforms (bug #52627).
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
628 %! unwind_protect |
0645853d12d6
test: Mark certain bugs as xtest when run on Mac platforms (bug #52627).
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
629 %! fid = fopen (file, "wt"); |
0645853d12d6
test: Mark certain bugs as xtest when run on Mac platforms (bug #52627).
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
630 %! fwrite (fid, "1;2;3\n"); |
0645853d12d6
test: Mark certain bugs as xtest when run on Mac platforms (bug #52627).
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
631 %! fwrite (fid, "1i;2I;3j;4J\n"); |
0645853d12d6
test: Mark certain bugs as xtest when run on Mac platforms (bug #52627).
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
632 %! fwrite (fid, "4;5;6\n"); |
0645853d12d6
test: Mark certain bugs as xtest when run on Mac platforms (bug #52627).
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
633 %! fwrite (fid, "-4i;+5I;-6j;+7J\n"); |
0645853d12d6
test: Mark certain bugs as xtest when run on Mac platforms (bug #52627).
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
634 %! fclose (fid); |
0645853d12d6
test: Mark certain bugs as xtest when run on Mac platforms (bug #52627).
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
635 %! |
0645853d12d6
test: Mark certain bugs as xtest when run on Mac platforms (bug #52627).
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
636 %! assert (dlmread (file), [1, 2, 3, 0; 1i, 2i, 3i, 4i; |
0645853d12d6
test: Mark certain bugs as xtest when run on Mac platforms (bug #52627).
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
637 %! 4, 5, 6, 0; -4i, 5i, -6i, 7i]); |
0645853d12d6
test: Mark certain bugs as xtest when run on Mac platforms (bug #52627).
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
638 %! assert (dlmread (file, "", [0 0 0 3]), [1, 2, 3]); |
0645853d12d6
test: Mark certain bugs as xtest when run on Mac platforms (bug #52627).
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
639 %! assert (dlmread (file, "", [1 0 1 3]), [1i, 2i, 3i, 4i]); |
0645853d12d6
test: Mark certain bugs as xtest when run on Mac platforms (bug #52627).
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
640 %! unwind_protect_cleanup |
0645853d12d6
test: Mark certain bugs as xtest when run on Mac platforms (bug #52627).
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
641 %! unlink (file); |
0645853d12d6
test: Mark certain bugs as xtest when run on Mac platforms (bug #52627).
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
642 %! end_unwind_protect |
0645853d12d6
test: Mark certain bugs as xtest when run on Mac platforms (bug #52627).
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
643 |
0645853d12d6
test: Mark certain bugs as xtest when run on Mac platforms (bug #52627).
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
644 %!xtest <47413> |
0645853d12d6
test: Mark certain bugs as xtest when run on Mac platforms (bug #52627).
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
645 %! ## Same test code as above, but intended only for test statistics on Mac. |
0645853d12d6
test: Mark certain bugs as xtest when run on Mac platforms (bug #52627).
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
646 %! if (! ismac ()), return; endif |
23318
d05f688ae836
dlmread: Add support for reading pure imaginary numbers (bug #50589).
Rik <rik@octave.org>
parents:
23308
diff
changeset
|
647 %! file = tempname (); |
d05f688ae836
dlmread: Add support for reading pure imaginary numbers (bug #50589).
Rik <rik@octave.org>
parents:
23308
diff
changeset
|
648 %! unwind_protect |
d05f688ae836
dlmread: Add support for reading pure imaginary numbers (bug #50589).
Rik <rik@octave.org>
parents:
23308
diff
changeset
|
649 %! fid = fopen (file, "wt"); |
d05f688ae836
dlmread: Add support for reading pure imaginary numbers (bug #50589).
Rik <rik@octave.org>
parents:
23308
diff
changeset
|
650 %! 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
|
651 %! 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
|
652 %! 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
|
653 %! 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
|
654 %! fclose (fid); |
d05f688ae836
dlmread: Add support for reading pure imaginary numbers (bug #50589).
Rik <rik@octave.org>
parents:
23308
diff
changeset
|
655 %! |
d05f688ae836
dlmread: Add support for reading pure imaginary numbers (bug #50589).
Rik <rik@octave.org>
parents:
23308
diff
changeset
|
656 %! 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
|
657 %! 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
|
658 %! 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
|
659 %! 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
|
660 %! unwind_protect_cleanup |
85ffe1bdd3a0
dlmread: Return empty matrix when requested range is outside data (bug #50102).
Rik <rik@octave.org>
parents:
23219
diff
changeset
|
661 %! unlink (file); |
85ffe1bdd3a0
dlmread: Return empty matrix when requested range is outside data (bug #50102).
Rik <rik@octave.org>
parents:
23219
diff
changeset
|
662 %! end_unwind_protect |
7580
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
663 |
25672
31c0bb386bcd
Correctly read NA values in dlmread.
Rik <rik@octave.org>
parents:
25646
diff
changeset
|
664 ## NA was not properly read from a file |
31c0bb386bcd
Correctly read NA values in dlmread.
Rik <rik@octave.org>
parents:
25646
diff
changeset
|
665 %!test |
31c0bb386bcd
Correctly read NA values in dlmread.
Rik <rik@octave.org>
parents:
25646
diff
changeset
|
666 %! file = tempname (); |
31c0bb386bcd
Correctly read NA values in dlmread.
Rik <rik@octave.org>
parents:
25646
diff
changeset
|
667 %! unwind_protect |
31c0bb386bcd
Correctly read NA values in dlmread.
Rik <rik@octave.org>
parents:
25646
diff
changeset
|
668 %! fid = fopen (file, "wt"); |
31c0bb386bcd
Correctly read NA values in dlmread.
Rik <rik@octave.org>
parents:
25646
diff
changeset
|
669 %! fwrite (fid, "1,NA,3"); |
31c0bb386bcd
Correctly read NA values in dlmread.
Rik <rik@octave.org>
parents:
25646
diff
changeset
|
670 %! fclose (fid); |
31c0bb386bcd
Correctly read NA values in dlmread.
Rik <rik@octave.org>
parents:
25646
diff
changeset
|
671 %! |
31c0bb386bcd
Correctly read NA values in dlmread.
Rik <rik@octave.org>
parents:
25646
diff
changeset
|
672 %! assert (dlmread (file), [1, NA, 3]); |
31c0bb386bcd
Correctly read NA values in dlmread.
Rik <rik@octave.org>
parents:
25646
diff
changeset
|
673 %! unwind_protect_cleanup |
31c0bb386bcd
Correctly read NA values in dlmread.
Rik <rik@octave.org>
parents:
25646
diff
changeset
|
674 %! unlink (file); |
31c0bb386bcd
Correctly read NA values in dlmread.
Rik <rik@octave.org>
parents:
25646
diff
changeset
|
675 %! end_unwind_protect |
31c0bb386bcd
Correctly read NA values in dlmread.
Rik <rik@octave.org>
parents:
25646
diff
changeset
|
676 |
25686
af0b81f2ffe6
Correctly handle corner cases in dlmread.
Rik <rik@octave.org>
parents:
25679
diff
changeset
|
677 ## "Name" was read as NA rather than parse error |
25679
4596a80cbc18
Correctly read "Name" as empty_value in dlmread (bug #54029)
Rik <rik@octave.org>
parents:
25672
diff
changeset
|
678 %!test <*54029> |
4596a80cbc18
Correctly read "Name" as empty_value in dlmread (bug #54029)
Rik <rik@octave.org>
parents:
25672
diff
changeset
|
679 %! file = tempname (); |
4596a80cbc18
Correctly read "Name" as empty_value in dlmread (bug #54029)
Rik <rik@octave.org>
parents:
25672
diff
changeset
|
680 %! unwind_protect |
4596a80cbc18
Correctly read "Name" as empty_value in dlmread (bug #54029)
Rik <rik@octave.org>
parents:
25672
diff
changeset
|
681 %! fid = fopen (file, "wt"); |
4596a80cbc18
Correctly read "Name" as empty_value in dlmread (bug #54029)
Rik <rik@octave.org>
parents:
25672
diff
changeset
|
682 %! fwrite (fid, "NaNe,bNa,Name,c\n1,NaN,3,Inftest\n-Inf,6,NA,8"); |
4596a80cbc18
Correctly read "Name" as empty_value in dlmread (bug #54029)
Rik <rik@octave.org>
parents:
25672
diff
changeset
|
683 %! fclose (fid); |
4596a80cbc18
Correctly read "Name" as empty_value in dlmread (bug #54029)
Rik <rik@octave.org>
parents:
25672
diff
changeset
|
684 %! |
4596a80cbc18
Correctly read "Name" as empty_value in dlmread (bug #54029)
Rik <rik@octave.org>
parents:
25672
diff
changeset
|
685 %! assert (dlmread (file), [0, 0, 0, 0; 1, NaN, 3, 0; -Inf, 6, NA, 8]); |
4596a80cbc18
Correctly read "Name" as empty_value in dlmread (bug #54029)
Rik <rik@octave.org>
parents:
25672
diff
changeset
|
686 %! unwind_protect_cleanup |
4596a80cbc18
Correctly read "Name" as empty_value in dlmread (bug #54029)
Rik <rik@octave.org>
parents:
25672
diff
changeset
|
687 %! unlink (file); |
4596a80cbc18
Correctly read "Name" as empty_value in dlmread (bug #54029)
Rik <rik@octave.org>
parents:
25672
diff
changeset
|
688 %! end_unwind_protect |
4596a80cbc18
Correctly read "Name" as empty_value in dlmread (bug #54029)
Rik <rik@octave.org>
parents:
25672
diff
changeset
|
689 |
25686
af0b81f2ffe6
Correctly handle corner cases in dlmread.
Rik <rik@octave.org>
parents:
25679
diff
changeset
|
690 ## Infinity incorrectly changed matrix to complex, rather than parse error |
af0b81f2ffe6
Correctly handle corner cases in dlmread.
Rik <rik@octave.org>
parents:
25679
diff
changeset
|
691 %!test |
af0b81f2ffe6
Correctly handle corner cases in dlmread.
Rik <rik@octave.org>
parents:
25679
diff
changeset
|
692 %! file = tempname (); |
af0b81f2ffe6
Correctly handle corner cases in dlmread.
Rik <rik@octave.org>
parents:
25679
diff
changeset
|
693 %! unwind_protect |
af0b81f2ffe6
Correctly handle corner cases in dlmread.
Rik <rik@octave.org>
parents:
25679
diff
changeset
|
694 %! fid = fopen (file, "wt"); |
af0b81f2ffe6
Correctly handle corner cases in dlmread.
Rik <rik@octave.org>
parents:
25679
diff
changeset
|
695 %! fwrite (fid, "1,Infinity,3"); |
af0b81f2ffe6
Correctly handle corner cases in dlmread.
Rik <rik@octave.org>
parents:
25679
diff
changeset
|
696 %! fclose (fid); |
af0b81f2ffe6
Correctly handle corner cases in dlmread.
Rik <rik@octave.org>
parents:
25679
diff
changeset
|
697 %! |
af0b81f2ffe6
Correctly handle corner cases in dlmread.
Rik <rik@octave.org>
parents:
25679
diff
changeset
|
698 %! assert (dlmread (file), [1, 0, 3]); |
af0b81f2ffe6
Correctly handle corner cases in dlmread.
Rik <rik@octave.org>
parents:
25679
diff
changeset
|
699 %! unwind_protect_cleanup |
af0b81f2ffe6
Correctly handle corner cases in dlmread.
Rik <rik@octave.org>
parents:
25679
diff
changeset
|
700 %! unlink (file); |
af0b81f2ffe6
Correctly handle corner cases in dlmread.
Rik <rik@octave.org>
parents:
25679
diff
changeset
|
701 %! end_unwind_protect |
af0b81f2ffe6
Correctly handle corner cases in dlmread.
Rik <rik@octave.org>
parents:
25679
diff
changeset
|
702 |
af0b81f2ffe6
Correctly handle corner cases in dlmread.
Rik <rik@octave.org>
parents:
25679
diff
changeset
|
703 ## Purely complex numbers with trailing garbage produced complex matrix |
af0b81f2ffe6
Correctly handle corner cases in dlmread.
Rik <rik@octave.org>
parents:
25679
diff
changeset
|
704 %!test |
af0b81f2ffe6
Correctly handle corner cases in dlmread.
Rik <rik@octave.org>
parents:
25679
diff
changeset
|
705 %! file = tempname (); |
af0b81f2ffe6
Correctly handle corner cases in dlmread.
Rik <rik@octave.org>
parents:
25679
diff
changeset
|
706 %! unwind_protect |
af0b81f2ffe6
Correctly handle corner cases in dlmread.
Rik <rik@octave.org>
parents:
25679
diff
changeset
|
707 %! fid = fopen (file, "wt"); |
af0b81f2ffe6
Correctly handle corner cases in dlmread.
Rik <rik@octave.org>
parents:
25679
diff
changeset
|
708 %! fwrite (fid, "1,2jack,3"); |
af0b81f2ffe6
Correctly handle corner cases in dlmread.
Rik <rik@octave.org>
parents:
25679
diff
changeset
|
709 %! fclose (fid); |
af0b81f2ffe6
Correctly handle corner cases in dlmread.
Rik <rik@octave.org>
parents:
25679
diff
changeset
|
710 %! |
af0b81f2ffe6
Correctly handle corner cases in dlmread.
Rik <rik@octave.org>
parents:
25679
diff
changeset
|
711 %! assert (dlmread (file), [1, 0, 3]); |
af0b81f2ffe6
Correctly handle corner cases in dlmread.
Rik <rik@octave.org>
parents:
25679
diff
changeset
|
712 %! unwind_protect_cleanup |
af0b81f2ffe6
Correctly handle corner cases in dlmread.
Rik <rik@octave.org>
parents:
25679
diff
changeset
|
713 %! unlink (file); |
af0b81f2ffe6
Correctly handle corner cases in dlmread.
Rik <rik@octave.org>
parents:
25679
diff
changeset
|
714 %! end_unwind_protect |
25679
4596a80cbc18
Correctly read "Name" as empty_value in dlmread (bug #54029)
Rik <rik@octave.org>
parents:
25672
diff
changeset
|
715 |
7580
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
716 */ |