Mercurial > octave
annotate libinterp/corefcn/dlmread.cc @ 31605:e88a07dec498 stable
maint: Use macros to begin/end C++ namespaces.
* oct-conf-post-public.in.h: Define two macros (OCTAVE_BEGIN_NAMESPACE,
OCTAVE_END_NAMESPACE) that can be used to start/end a namespace.
* mk-opts.pl, build-env.h, build-env.in.cc, __betainc__.cc, __contourc__.cc,
__dsearchn__.cc, __eigs__.cc, __expint__.cc, __ftp__.cc, __gammainc__.cc,
__ichol__.cc, __ilu__.cc, __isprimelarge__.cc, __lin_interpn__.cc,
__magick_read__.cc, __pchip_deriv__.cc, __qp__.cc, amd.cc, auto-shlib.cc,
auto-shlib.h, balance.cc, base-text-renderer.cc, base-text-renderer.h,
besselj.cc, bitfcns.cc, bsxfun.cc, c-file-ptr-stream.cc, c-file-ptr-stream.h,
call-stack.cc, call-stack.h, ccolamd.cc, cellfun.cc, chol.cc, colamd.cc,
colloc.cc, conv2.cc, daspk.cc, dasrt.cc, dassl.cc, data.cc, data.h, debug.cc,
defaults.cc, defaults.h, defun-int.h, defun.cc, det.cc, dirfns.cc, display.cc,
display.h, dlmread.cc, dmperm.cc, dot.cc, dynamic-ld.cc, dynamic-ld.h, eig.cc,
ellipj.cc, environment.cc, environment.h, error.cc, error.h, errwarn.h,
event-manager.cc, event-manager.h, event-queue.cc, event-queue.h, fcn-info.cc,
fcn-info.h, fft.cc, fft2.cc, fftn.cc, file-io.cc, filter.cc, find.cc,
ft-text-renderer.cc, ft-text-renderer.h, gcd.cc, getgrent.cc, getpwent.cc,
getrusage.cc, givens.cc, gl-render.cc, gl-render.h, gl2ps-print.cc,
gl2ps-print.h, graphics-toolkit.cc, graphics-toolkit.h, graphics.cc,
graphics.in.h, gsvd.cc, gtk-manager.cc, gtk-manager.h, hash.cc, help.cc,
help.h, hess.cc, hex2num.cc, hook-fcn.cc, hook-fcn.h, input.cc, input.h,
interpreter-private.cc, interpreter-private.h, interpreter.cc, interpreter.h,
inv.cc, jsondecode.cc, jsonencode.cc, kron.cc, latex-text-renderer.cc,
latex-text-renderer.h, load-path.cc, load-path.h, load-save.cc, load-save.h,
lookup.cc, ls-ascii-helper.cc, ls-ascii-helper.h, ls-oct-text.cc, ls-utils.cc,
ls-utils.h, lsode.cc, lu.cc, mappers.cc, matrix_type.cc, max.cc, mex-private.h,
mex.cc, mgorth.cc, nproc.cc, oct-fstrm.cc, oct-fstrm.h, oct-hdf5-types.cc,
oct-hdf5-types.h, oct-hist.cc, oct-hist.h, oct-iostrm.cc, oct-iostrm.h,
oct-opengl.h, oct-prcstrm.cc, oct-prcstrm.h, oct-procbuf.cc, oct-procbuf.h,
oct-process.cc, oct-process.h, oct-stdstrm.h, oct-stream.cc, oct-stream.h,
oct-strstrm.cc, oct-strstrm.h, oct-tex-lexer.in.ll, oct-tex-parser.yy,
ordqz.cc, ordschur.cc, pager.cc, pager.h, pinv.cc, pow2.cc, pr-flt-fmt.cc,
pr-output.cc, procstream.cc, procstream.h, psi.cc, qr.cc, quad.cc, quadcc.cc,
qz.cc, rand.cc, rcond.cc, regexp.cc, schur.cc, settings.cc, settings.h,
sighandlers.cc, sighandlers.h, sparse-xdiv.cc, sparse-xdiv.h, sparse-xpow.cc,
sparse-xpow.h, sparse.cc, spparms.cc, sqrtm.cc, stack-frame.cc, stack-frame.h,
stream-euler.cc, strfind.cc, strfns.cc, sub2ind.cc, svd.cc, sylvester.cc,
symbfact.cc, syminfo.cc, syminfo.h, symrcm.cc, symrec.cc, symrec.h,
symscope.cc, symscope.h, symtab.cc, symtab.h, syscalls.cc, sysdep.cc, sysdep.h,
text-engine.cc, text-engine.h, text-renderer.cc, text-renderer.h, time.cc,
toplev.cc, tril.cc, tsearch.cc, typecast.cc, url-handle-manager.cc,
url-handle-manager.h, urlwrite.cc, utils.cc, utils.h, variables.cc,
variables.h, xdiv.cc, xdiv.h, xnorm.cc, xnorm.h, xpow.cc, xpow.h,
__delaunayn__.cc, __fltk_uigetfile__.cc, __glpk__.cc, __init_fltk__.cc,
__init_gnuplot__.cc, __ode15__.cc, __voronoi__.cc, audiodevinfo.cc,
audioread.cc, convhulln.cc, fftw.cc, gzip.cc, mk-build-env-features.sh,
mk-builtins.pl, cdef-class.cc, cdef-class.h, cdef-fwd.h, cdef-manager.cc,
cdef-manager.h, cdef-method.cc, cdef-method.h, cdef-object.cc, cdef-object.h,
cdef-package.cc, cdef-package.h, cdef-property.cc, cdef-property.h,
cdef-utils.cc, cdef-utils.h, ov-base.cc, ov-base.h, ov-bool-mat.cc,
ov-builtin.h, ov-cell.cc, ov-class.cc, ov-class.h, ov-classdef.cc,
ov-classdef.h, ov-complex.cc, ov-fcn-handle.cc, ov-fcn-handle.h, ov-fcn.h,
ov-java.cc, ov-java.h, ov-mex-fcn.h, ov-null-mat.cc, ov-oncleanup.cc,
ov-struct.cc, ov-typeinfo.cc, ov-typeinfo.h, ov-usr-fcn.cc, ov-usr-fcn.h,
ov.cc, ov.h, octave.cc, octave.h, mk-ops.sh, op-b-b.cc, op-b-bm.cc,
op-b-sbm.cc, op-bm-b.cc, op-bm-bm.cc, op-bm-sbm.cc, op-cdm-cdm.cc, op-cell.cc,
op-chm.cc, op-class.cc, op-cm-cm.cc, op-cm-cs.cc, op-cm-m.cc, op-cm-s.cc,
op-cm-scm.cc, op-cm-sm.cc, op-cs-cm.cc, op-cs-cs.cc, op-cs-m.cc, op-cs-s.cc,
op-cs-scm.cc, op-cs-sm.cc, op-dm-dm.cc, op-dm-scm.cc, op-dm-sm.cc,
op-dm-template.cc, op-dms-template.cc, op-fcdm-fcdm.cc, op-fcm-fcm.cc,
op-fcm-fcs.cc, op-fcm-fm.cc, op-fcm-fs.cc, op-fcn.cc, op-fcs-fcm.cc,
op-fcs-fcs.cc, op-fcs-fm.cc, op-fcs-fs.cc, op-fdm-fdm.cc, op-fm-fcm.cc,
op-fm-fcs.cc, op-fm-fm.cc, op-fm-fs.cc, op-fs-fcm.cc, op-fs-fcs.cc,
op-fs-fm.cc, op-fs-fs.cc, op-i16-i16.cc, op-i32-i32.cc, op-i64-i64.cc,
op-i8-i8.cc, op-int-concat.cc, op-m-cm.cc, op-m-cs.cc, op-m-m.cc, op-m-s.cc,
op-m-scm.cc, op-m-sm.cc, op-mi.cc, op-pm-pm.cc, op-pm-scm.cc, op-pm-sm.cc,
op-pm-template.cc, op-range.cc, op-s-cm.cc, op-s-cs.cc, op-s-m.cc, op-s-s.cc,
op-s-scm.cc, op-s-sm.cc, op-sbm-b.cc, op-sbm-bm.cc, op-sbm-sbm.cc,
op-scm-cm.cc, op-scm-cs.cc, op-scm-m.cc, op-scm-s.cc, op-scm-scm.cc,
op-scm-sm.cc, op-sm-cm.cc, op-sm-cs.cc, op-sm-m.cc, op-sm-s.cc, op-sm-scm.cc,
op-sm-sm.cc, op-str-m.cc, op-str-s.cc, op-str-str.cc, op-struct.cc,
op-ui16-ui16.cc, op-ui32-ui32.cc, op-ui64-ui64.cc, op-ui8-ui8.cc, ops.h,
anon-fcn-validator.cc, anon-fcn-validator.h, bp-table.cc, bp-table.h,
comment-list.cc, comment-list.h, filepos.h, lex.h, lex.ll, oct-lvalue.cc,
oct-lvalue.h, oct-parse.yy, parse.h, profiler.cc, profiler.h,
pt-anon-scopes.cc, pt-anon-scopes.h, pt-arg-list.cc, pt-arg-list.h,
pt-args-block.cc, pt-args-block.h, pt-array-list.cc, pt-array-list.h,
pt-assign.cc, pt-assign.h, pt-binop.cc, pt-binop.h, pt-bp.cc, pt-bp.h,
pt-cbinop.cc, pt-cbinop.h, pt-cell.cc, pt-cell.h, pt-check.cc, pt-check.h,
pt-classdef.cc, pt-classdef.h, pt-cmd.h, pt-colon.cc, pt-colon.h, pt-const.cc,
pt-const.h, pt-decl.cc, pt-decl.h, pt-eval.cc, pt-eval.h, pt-except.cc,
pt-except.h, pt-exp.cc, pt-exp.h, pt-fcn-handle.cc, pt-fcn-handle.h, pt-id.cc,
pt-id.h, pt-idx.cc, pt-idx.h, pt-jump.h, pt-loop.cc, pt-loop.h, pt-mat.cc,
pt-mat.h, pt-misc.cc, pt-misc.h, pt-pr-code.cc, pt-pr-code.h, pt-select.cc,
pt-select.h, pt-spmd.cc, pt-spmd.h, pt-stmt.cc, pt-stmt.h, pt-tm-const.cc,
pt-tm-const.h, pt-unop.cc, pt-unop.h, pt-vm-eval.cc, pt-walk.cc, pt-walk.h,
pt.cc, pt.h, token.cc, token.h, Range.cc, Range.h, idx-vector.cc, idx-vector.h,
range-fwd.h, CollocWt.cc, CollocWt.h, aepbalance.cc, aepbalance.h, chol.cc,
chol.h, gepbalance.cc, gepbalance.h, gsvd.cc, gsvd.h, hess.cc, hess.h,
lo-mappers.cc, lo-mappers.h, lo-specfun.cc, lo-specfun.h, lu.cc, lu.h,
oct-convn.cc, oct-convn.h, oct-fftw.cc, oct-fftw.h, oct-norm.cc, oct-norm.h,
oct-rand.cc, oct-rand.h, oct-spparms.cc, oct-spparms.h, qr.cc, qr.h, qrp.cc,
qrp.h, randgamma.cc, randgamma.h, randmtzig.cc, randmtzig.h, randpoisson.cc,
randpoisson.h, schur.cc, schur.h, sparse-chol.cc, sparse-chol.h, sparse-lu.cc,
sparse-lu.h, sparse-qr.cc, sparse-qr.h, svd.cc, svd.h, child-list.cc,
child-list.h, dir-ops.cc, dir-ops.h, file-ops.cc, file-ops.h, file-stat.cc,
file-stat.h, lo-sysdep.cc, lo-sysdep.h, lo-sysinfo.cc, lo-sysinfo.h,
mach-info.cc, mach-info.h, oct-env.cc, oct-env.h, oct-group.cc, oct-group.h,
oct-password.cc, oct-password.h, oct-syscalls.cc, oct-syscalls.h, oct-time.cc,
oct-time.h, oct-uname.cc, oct-uname.h, action-container.cc, action-container.h,
base-list.h, cmd-edit.cc, cmd-edit.h, cmd-hist.cc, cmd-hist.h, f77-fcn.h,
file-info.cc, file-info.h, lo-array-errwarn.cc, lo-array-errwarn.h, lo-hash.cc,
lo-hash.h, lo-ieee.h, lo-regexp.cc, lo-regexp.h, lo-utils.cc, lo-utils.h,
oct-base64.cc, oct-base64.h, oct-glob.cc, oct-glob.h, oct-inttypes.h,
oct-mutex.cc, oct-mutex.h, oct-refcount.h, oct-shlib.cc, oct-shlib.h,
oct-sparse.cc, oct-sparse.h, oct-string.h, octave-preserve-stream-state.h,
pathsearch.cc, pathsearch.h, quit.cc, quit.h, unwind-prot.cc, unwind-prot.h,
url-transfer.cc, url-transfer.h : Use new macros to begin/end C++ namespaces.
author | Rik <rik@octave.org> |
---|---|
date | Thu, 01 Dec 2022 14:23:45 -0800 |
parents | 796f54d4ddbf |
children | aac27ad79be6 |
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 // |
30564
796f54d4ddbf
update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents:
30390
diff
changeset
|
3 // Copyright (C) 2008-2022 The Octave Project Developers |
27923
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 |
29928
2420f8f62ebe
dlmread: Improve performance on platforms with slow setlocale (bug #59702).
Markus Mützel <markus.muetzel@gmx.de>
parents:
29655
diff
changeset
|
33 #include <clocale> |
25679
4596a80cbc18
Correctly read "Name" as empty_value in dlmread (bug #54029)
Rik <rik@octave.org>
parents:
25672
diff
changeset
|
34 #include <cmath> |
7581 | 35 #include <cctype> |
36 #include <fstream> | |
10804
3d5c6b84ddaf
speed-up fixes to dlmread
Jaroslav Hajek <highegg@gmail.com>
parents:
10718
diff
changeset
|
37 #include <limits> |
7581 | 38 |
9512
56e850e3b06f
dlmread: perform tilde expansion to filename argument
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
39 #include "file-ops.h" |
7580
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
40 #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
|
41 #include "lo-sysdep.h" |
7580
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
42 |
15039
e753177cde93
maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents:
14501
diff
changeset
|
43 #include "defun.h" |
23738
8acd390d16c9
don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents:
23573
diff
changeset
|
44 #include "interpreter.h" |
10927
a9e9659e1dca
support file IDs in dlmread
Jaroslav Hajek <highegg@gmail.com>
parents:
10806
diff
changeset
|
45 #include "oct-stream.h" |
7580
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
46 #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
|
47 #include "ovl.h" |
7580
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
48 #include "utils.h" |
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
49 |
27277
db687716fed6
style fixes: generally aim to break long lines before operators, not after
John W. Eaton <jwe@octave.org>
parents:
27028
diff
changeset
|
50 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
|
51 = 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
|
52 |
31be59137160
Don't error out if RANGE specification for dlmread contains large values.
Rik <rik@octave.org>
parents:
23307
diff
changeset
|
53 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
|
54 |
7580
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
55 static bool |
10804
3d5c6b84ddaf
speed-up fixes to dlmread
Jaroslav Hajek <highegg@gmail.com>
parents:
10718
diff
changeset
|
56 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
|
57 { |
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
58 bool stat = false; |
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
59 |
7581 | 60 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
|
61 stat = true; |
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
62 else |
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
63 { |
7581 | 64 if (::isalpha (is.peek ())) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
65 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
66 col = 0; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
67 while (is && ::isalpha (is.peek ())) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
68 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
69 char ch = is.get (); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
70 col *= 26; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
71 if (ch >= 'a') |
10718
b8d76f4be94a
Fix spreadsheet style range option (bug #30183).
Rik <octave@nomad.inbox5.com>
parents:
10350
diff
changeset
|
72 col += ch - 'a' + 1; |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
73 else |
10718
b8d76f4be94a
Fix spreadsheet style range option (bug #30183).
Rik <octave@nomad.inbox5.com>
parents:
10350
diff
changeset
|
74 col += ch - 'A' + 1; |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
75 } |
21062
d9c1884d1aaa
maint: Eliminate space between variable and decrement '--' operator.
Rik <rik@octave.org>
parents:
20955
diff
changeset
|
76 col--; |
7580
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
77 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
78 if (is) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
79 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
80 is >> row; |
21062
d9c1884d1aaa
maint: Eliminate space between variable and decrement '--' operator.
Rik <rik@octave.org>
parents:
20955
diff
changeset
|
81 row--; |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
82 if (is) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
83 stat = true; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
84 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
85 } |
7580
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 |
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
88 return stat; |
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 |
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
91 static bool |
7581 | 92 parse_range_spec (const octave_value& range_spec, |
10804
3d5c6b84ddaf
speed-up fixes to dlmread
Jaroslav Hajek <highegg@gmail.com>
parents:
10718
diff
changeset
|
93 octave_idx_type& rlo, octave_idx_type& clo, |
3d5c6b84ddaf
speed-up fixes to dlmread
Jaroslav Hajek <highegg@gmail.com>
parents:
10718
diff
changeset
|
94 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
|
95 { |
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
96 bool stat = true; |
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
97 |
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
98 if (range_spec.is_string ()) |
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
99 { |
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
100 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
|
101 char ch = is.peek (); |
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
102 |
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
103 if (ch == '.' || ch == ':') |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
104 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
105 rlo = 0; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
106 clo = 0; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
107 ch = is.get (); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
108 if (ch == '.') |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
109 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
110 ch = is.get (); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
111 if (ch != '.') |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
112 stat = false; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
113 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
114 } |
7580
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
115 else |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
116 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
117 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
|
118 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
119 if (stat) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
120 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
121 ch = is.peek (); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
122 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
123 if (ch == '.' || ch == ':') |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
124 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
125 ch = is.get (); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
126 if (ch == '.') |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
127 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
128 ch = is.get (); |
20955
77f5591878bf
maint: Use '! expr' rather than '!expr' to conform to coding guidelines.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
129 if (! is || ch != '.') |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
130 stat = false; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
131 } |
7580
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
132 |
23323
31be59137160
Don't error out if RANGE specification for dlmread contains large values.
Rik <rik@octave.org>
parents:
23307
diff
changeset
|
133 rup = idx_max; |
31be59137160
Don't error out if RANGE specification for dlmread contains large values.
Rik <rik@octave.org>
parents:
23307
diff
changeset
|
134 cup = idx_max; |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
135 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
136 else |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
137 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
138 rup = rlo; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
139 cup = clo; |
20955
77f5591878bf
maint: Use '! expr' rather than '!expr' to conform to coding guidelines.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
140 if (! is || ! is.eof ()) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
141 stat = false; |
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 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
144 } |
7580
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
145 |
20955
77f5591878bf
maint: Use '! expr' rather than '!expr' to conform to coding guidelines.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
146 if (stat && is && ! is.eof ()) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
147 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
|
148 |
20955
77f5591878bf
maint: Use '! expr' rather than '!expr' to conform to coding guidelines.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
149 if (! is || ! is.eof ()) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
150 stat = false; |
7580
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
151 } |
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
152 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
|
153 { |
27028
2d36701216e9
Validate RANGE input to dlmread does not contain NaN (bug #56047).
Rik <rik@octave.org>
parents:
26376
diff
changeset
|
154 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
|
155 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
|
156 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
|
157 |
23323
31be59137160
Don't error out if RANGE specification for dlmread contains large values.
Rik <rik@octave.org>
parents:
23307
diff
changeset
|
158 // 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
|
159 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
|
160 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
|
161 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
|
162 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
|
163 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
164 else |
7580
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
165 stat = false; |
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
166 |
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
167 return stat; |
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
168 } |
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
169 |
31605
e88a07dec498
maint: Use macros to begin/end C++ namespaces.
Rik <rik@octave.org>
parents:
30564
diff
changeset
|
170 OCTAVE_BEGIN_NAMESPACE(octave) |
29958
32c3a5805893
move DEFUN and DEFMETHOD functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29928
diff
changeset
|
171 |
23738
8acd390d16c9
don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents:
23573
diff
changeset
|
172 DEFMETHOD (dlmread, interp, args, , |
8acd390d16c9
don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents:
23573
diff
changeset
|
173 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
|
174 @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
|
175 @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
|
176 @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
|
177 @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
|
178 @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
|
179 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
|
180 @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
|
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 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
|
183 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
|
184 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21733
diff
changeset
|
185 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
|
186 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
|
187 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
|
188 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21733
diff
changeset
|
189 The @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
|
190 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
|
191 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
|
192 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
|
193 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
|
194 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
|
195 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
|
196 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
|
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 @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
|
199 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
|
200 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21733
diff
changeset
|
201 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
|
202 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
|
203 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
|
204 @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
|
205 @end deftypefn */) |
7580
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
206 { |
7581 | 207 int nargin = args.length (); |
208 | |
10935
3cb4889dd6f7
support specific empty value in dlmread
Jaroslav Hajek <highegg@gmail.com>
parents:
10927
diff
changeset
|
209 double empty_value = 0.0; |
3cb4889dd6f7
support specific empty value in dlmread
Jaroslav Hajek <highegg@gmail.com>
parents:
10927
diff
changeset
|
210 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
211 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
|
212 && args(nargin-2).string_value () == "emptyvalue") |
3cb4889dd6f7
support specific empty value in dlmread
Jaroslav Hajek <highegg@gmail.com>
parents:
10927
diff
changeset
|
213 { |
3cb4889dd6f7
support specific empty value in dlmread
Jaroslav Hajek <highegg@gmail.com>
parents:
10927
diff
changeset
|
214 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
|
215 |
10935
3cb4889dd6f7
support specific empty value in dlmread
Jaroslav Hajek <highegg@gmail.com>
parents:
10927
diff
changeset
|
216 nargin -= 2; |
3cb4889dd6f7
support specific empty value in dlmread
Jaroslav Hajek <highegg@gmail.com>
parents:
10927
diff
changeset
|
217 } |
3cb4889dd6f7
support specific empty value in dlmread
Jaroslav Hajek <highegg@gmail.com>
parents:
10927
diff
changeset
|
218 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
219 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
|
220 print_usage (); |
7580
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
221 |
23457
21baad6b35c4
maint: Use C++11 nullptr rather than 0 or NULL when possible.
Rik <rik@octave.org>
parents:
23395
diff
changeset
|
222 std::istream *input = nullptr; |
11389
934ed3e07542
dlmread: simplify file name/id logic
John W. Eaton <jwe@octave.org>
parents:
10935
diff
changeset
|
223 std::ifstream input_file; |
10927
a9e9659e1dca
support file IDs in dlmread
Jaroslav Hajek <highegg@gmail.com>
parents:
10806
diff
changeset
|
224 |
a9e9659e1dca
support file IDs in dlmread
Jaroslav Hajek <highegg@gmail.com>
parents:
10806
diff
changeset
|
225 if (args(0).is_string ()) |
7580
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
226 { |
20713
2469d78a1d8b
Consistently use 'filename' rather than 'file name' throughout code base.
Rik <rik@octave.org>
parents:
20555
diff
changeset
|
227 // Filename. |
10927
a9e9659e1dca
support file IDs in dlmread
Jaroslav Hajek <highegg@gmail.com>
parents:
10806
diff
changeset
|
228 std::string fname (args(0).string_value ()); |
a9e9659e1dca
support file IDs in dlmread
Jaroslav Hajek <highegg@gmail.com>
parents:
10806
diff
changeset
|
229 |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
230 std::string tname = sys::file_ops::tilde_expand (fname); |
10927
a9e9659e1dca
support file IDs in dlmread
Jaroslav Hajek <highegg@gmail.com>
parents:
10806
diff
changeset
|
231 |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
232 tname = find_data_file_in_load_path ("dlmread", tname); |
21592
fe5ed6d7fb10
* dlmread.cc (Fdlmread): Search loadpath for file (bug #47628).
John W. Eaton <jwe@octave.org>
parents:
21362
diff
changeset
|
233 |
28467
159b6a1eb408
Use wide character overload to open file streams on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents:
27923
diff
changeset
|
234 #if defined (OCTAVE_USE_WINDOWS_API) |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
235 std::wstring wname = sys::u8_to_wstring (tname); |
28467
159b6a1eb408
Use wide character overload to open file streams on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents:
27923
diff
changeset
|
236 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
|
237 #else |
159b6a1eb408
Use wide character overload to open file streams on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents:
27923
diff
changeset
|
238 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
|
239 #endif |
11389
934ed3e07542
dlmread: simplify file name/id logic
John W. Eaton <jwe@octave.org>
parents:
10935
diff
changeset
|
240 |
934ed3e07542
dlmread: simplify file name/id logic
John W. Eaton <jwe@octave.org>
parents:
10935
diff
changeset
|
241 if (! input_file) |
20831
35241c4b696c
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20802
diff
changeset
|
242 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
|
243 |
35241c4b696c
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20802
diff
changeset
|
244 input = &input_file; |
10927
a9e9659e1dca
support file IDs in dlmread
Jaroslav Hajek <highegg@gmail.com>
parents:
10806
diff
changeset
|
245 } |
a9e9659e1dca
support file IDs in dlmread
Jaroslav Hajek <highegg@gmail.com>
parents:
10806
diff
changeset
|
246 else if (args(0).is_scalar_type ()) |
a9e9659e1dca
support file IDs in dlmread
Jaroslav Hajek <highegg@gmail.com>
parents:
10806
diff
changeset
|
247 { |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
248 stream_list& streams = interp.get_stream_list (); |
23738
8acd390d16c9
don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents:
23573
diff
changeset
|
249 |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
250 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
|
251 |
934ed3e07542
dlmread: simplify file name/id logic
John W. Eaton <jwe@octave.org>
parents:
10935
diff
changeset
|
252 input = is.input_stream (); |
934ed3e07542
dlmread: simplify file name/id logic
John W. Eaton <jwe@octave.org>
parents:
10935
diff
changeset
|
253 |
10927
a9e9659e1dca
support file IDs in dlmread
Jaroslav Hajek <highegg@gmail.com>
parents:
10806
diff
changeset
|
254 if (! input) |
20831
35241c4b696c
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20802
diff
changeset
|
255 error ("dlmread: stream FILE not open for input"); |
10927
a9e9659e1dca
support file IDs in dlmread
Jaroslav Hajek <highegg@gmail.com>
parents:
10806
diff
changeset
|
256 } |
a9e9659e1dca
support file IDs in dlmread
Jaroslav Hajek <highegg@gmail.com>
parents:
10806
diff
changeset
|
257 else |
20831
35241c4b696c
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20802
diff
changeset
|
258 error ("dlmread: FILE argument must be a string or file id"); |
7581 | 259 |
260 // Set default separator. | |
7580
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
261 std::string sep; |
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
262 if (nargin > 1) |
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
263 { |
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
264 if (args(1).is_sq_string ()) |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
265 sep = do_string_escapes (args(1).string_value ()); |
7580
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
266 else |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
267 sep = args(1).string_value (); |
7580
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
268 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
269 |
7581 | 270 // 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
|
271 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
|
272 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
|
273 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
|
274 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
|
275 if (nargin > 2) |
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
276 { |
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
277 if (nargin == 3) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
278 { |
20955
77f5591878bf
maint: Use '! expr' rather than '!expr' to conform to coding guidelines.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
279 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
|
280 error ("dlmread: error parsing RANGE"); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
281 } |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
282 else if (nargin == 4) |
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 r0 = args(2).idx_type_value (); |
3d5c6b84ddaf
speed-up fixes to dlmread
Jaroslav Hajek <highegg@gmail.com>
parents:
10718
diff
changeset
|
285 c0 = args(3).idx_type_value (); |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
286 } |
10804
3d5c6b84ddaf
speed-up fixes to dlmread
Jaroslav Hajek <highegg@gmail.com>
parents:
10718
diff
changeset
|
287 |
3d5c6b84ddaf
speed-up fixes to dlmread
Jaroslav Hajek <highegg@gmail.com>
parents:
10718
diff
changeset
|
288 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
|
289 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
|
290 |
23394
7ca04e85f9e3
maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents:
23323
diff
changeset
|
291 // 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
|
292 if (r1 < r0 || c1 < c0) |
30390
a61e1a0f6024
maint: style check C++ files in libinterp/ ahead of 7.1 release.
Rik <rik@octave.org>
parents:
29961
diff
changeset
|
293 return ovl (Matrix (0, 0)); |
7580
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
294 } |
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
295 |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
296 octave_idx_type i = 0; |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
297 octave_idx_type j = 0; |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
298 octave_idx_type r = 1; |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
299 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
|
300 // 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
|
301 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
|
302 octave_idx_type cmax = 0; |
7581 | 303 |
22666
68d5c4759783
dlmread: Return correct number of columns when line ends with separator (bug #42025).
Rik <rik@octave.org>
parents:
22657
diff
changeset
|
304 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
|
305 ComplexMatrix cdata; |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
306 |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
307 bool iscmplx = false; |
22656
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
308 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
|
309 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
|
310 |
28685
65fde9fe3b60
Strip BOM from UTF-8 encoded files in "dlmread" (bug #58813).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28628
diff
changeset
|
311 if (r0 == 0) |
65fde9fe3b60
Strip BOM from UTF-8 encoded files in "dlmread" (bug #58813).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28628
diff
changeset
|
312 { |
65fde9fe3b60
Strip BOM from UTF-8 encoded files in "dlmread" (bug #58813).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28628
diff
changeset
|
313 // Peek into stream and potentially strip Byte Order Mark (BOM) |
65fde9fe3b60
Strip BOM from UTF-8 encoded files in "dlmread" (bug #58813).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28628
diff
changeset
|
314 const char BOM[3] = {'\xEF', '\xBB', '\xBF'}; |
65fde9fe3b60
Strip BOM from UTF-8 encoded files in "dlmread" (bug #58813).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28628
diff
changeset
|
315 char buf[3]; |
65fde9fe3b60
Strip BOM from UTF-8 encoded files in "dlmread" (bug #58813).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28628
diff
changeset
|
316 int i_bom; |
65fde9fe3b60
Strip BOM from UTF-8 encoded files in "dlmread" (bug #58813).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28628
diff
changeset
|
317 bool found_bom = true; |
65fde9fe3b60
Strip BOM from UTF-8 encoded files in "dlmread" (bug #58813).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28628
diff
changeset
|
318 for (i_bom = 0; i_bom < 3; i_bom++) |
65fde9fe3b60
Strip BOM from UTF-8 encoded files in "dlmread" (bug #58813).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28628
diff
changeset
|
319 { |
65fde9fe3b60
Strip BOM from UTF-8 encoded files in "dlmread" (bug #58813).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28628
diff
changeset
|
320 char ch_p = input->peek (); |
65fde9fe3b60
Strip BOM from UTF-8 encoded files in "dlmread" (bug #58813).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28628
diff
changeset
|
321 if (ch_p == BOM[i_bom]) |
65fde9fe3b60
Strip BOM from UTF-8 encoded files in "dlmread" (bug #58813).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28628
diff
changeset
|
322 buf[i_bom] = input->get (); |
65fde9fe3b60
Strip BOM from UTF-8 encoded files in "dlmread" (bug #58813).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28628
diff
changeset
|
323 else |
65fde9fe3b60
Strip BOM from UTF-8 encoded files in "dlmread" (bug #58813).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28628
diff
changeset
|
324 { |
65fde9fe3b60
Strip BOM from UTF-8 encoded files in "dlmread" (bug #58813).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28628
diff
changeset
|
325 found_bom = false; |
65fde9fe3b60
Strip BOM from UTF-8 encoded files in "dlmread" (bug #58813).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28628
diff
changeset
|
326 break; |
65fde9fe3b60
Strip BOM from UTF-8 encoded files in "dlmread" (bug #58813).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28628
diff
changeset
|
327 } |
65fde9fe3b60
Strip BOM from UTF-8 encoded files in "dlmread" (bug #58813).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28628
diff
changeset
|
328 } |
65fde9fe3b60
Strip BOM from UTF-8 encoded files in "dlmread" (bug #58813).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28628
diff
changeset
|
329 // Put back read characters if it wasn't a BOM |
65fde9fe3b60
Strip BOM from UTF-8 encoded files in "dlmread" (bug #58813).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28628
diff
changeset
|
330 if (! found_bom) |
65fde9fe3b60
Strip BOM from UTF-8 encoded files in "dlmread" (bug #58813).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28628
diff
changeset
|
331 { |
65fde9fe3b60
Strip BOM from UTF-8 encoded files in "dlmread" (bug #58813).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28628
diff
changeset
|
332 for (int i_ret = i_bom-1; i_ret >= 0; i_ret--) |
65fde9fe3b60
Strip BOM from UTF-8 encoded files in "dlmread" (bug #58813).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28628
diff
changeset
|
333 input->putback (buf[i_ret]); |
65fde9fe3b60
Strip BOM from UTF-8 encoded files in "dlmread" (bug #58813).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28628
diff
changeset
|
334 } |
65fde9fe3b60
Strip BOM from UTF-8 encoded files in "dlmread" (bug #58813).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28628
diff
changeset
|
335 } |
65fde9fe3b60
Strip BOM from UTF-8 encoded files in "dlmread" (bug #58813).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28628
diff
changeset
|
336 |
29928
2420f8f62ebe
dlmread: Improve performance on platforms with slow setlocale (bug #59702).
Markus Mützel <markus.muetzel@gmx.de>
parents:
29655
diff
changeset
|
337 // Set "C" locale for the remainder of this function to avoid the performance |
2420f8f62ebe
dlmread: Improve performance on platforms with slow setlocale (bug #59702).
Markus Mützel <markus.muetzel@gmx.de>
parents:
29655
diff
changeset
|
338 // panelty of frequently switching the locale when reading floating point |
2420f8f62ebe
dlmread: Improve performance on platforms with slow setlocale (bug #59702).
Markus Mützel <markus.muetzel@gmx.de>
parents:
29655
diff
changeset
|
339 // values from the stream. |
2420f8f62ebe
dlmread: Improve performance on platforms with slow setlocale (bug #59702).
Markus Mützel <markus.muetzel@gmx.de>
parents:
29655
diff
changeset
|
340 char *prev_locale = std::setlocale (LC_ALL, nullptr); |
2420f8f62ebe
dlmread: Improve performance on platforms with slow setlocale (bug #59702).
Markus Mützel <markus.muetzel@gmx.de>
parents:
29655
diff
changeset
|
341 std::string old_locale (prev_locale ? prev_locale : ""); |
2420f8f62ebe
dlmread: Improve performance on platforms with slow setlocale (bug #59702).
Markus Mützel <markus.muetzel@gmx.de>
parents:
29655
diff
changeset
|
342 std::setlocale (LC_ALL, "C"); |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
343 unwind_action act |
29928
2420f8f62ebe
dlmread: Improve performance on platforms with slow setlocale (bug #59702).
Markus Mützel <markus.muetzel@gmx.de>
parents:
29655
diff
changeset
|
344 ([old_locale] () { std::setlocale (LC_ALL, old_locale.c_str ()); }); |
2420f8f62ebe
dlmread: Improve performance on platforms with slow setlocale (bug #59702).
Markus Mützel <markus.muetzel@gmx.de>
parents:
29655
diff
changeset
|
345 |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
346 std::string line; |
7581 | 347 |
23323
31be59137160
Don't error out if RANGE specification for dlmread contains large values.
Rik <rik@octave.org>
parents:
23307
diff
changeset
|
348 // 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
|
349 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
|
350 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
|
351 rcnt--; |
31be59137160
Don't error out if RANGE specification for dlmread contains large values.
Rik <rik@octave.org>
parents:
23307
diff
changeset
|
352 |
31be59137160
Don't error out if RANGE specification for dlmread contains large values.
Rik <rik@octave.org>
parents:
23307
diff
changeset
|
353 if (rcnt > 0) |
30390
a61e1a0f6024
maint: style check C++ files in libinterp/ ahead of 7.1 release.
Rik <rik@octave.org>
parents:
29961
diff
changeset
|
354 return ovl (Matrix (0, 0)); // Not enough lines in file to satisfy RANGE |
23323
31be59137160
Don't error out if RANGE specification for dlmread contains large values.
Rik <rik@octave.org>
parents:
23307
diff
changeset
|
355 else |
31be59137160
Don't error out if RANGE specification for dlmread contains large values.
Rik <rik@octave.org>
parents:
23307
diff
changeset
|
356 r1 -= r0; |
7581 | 357 |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
358 std::istringstream tmp_stream; |
7581 | 359 |
22656
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
360 // 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
|
361 while (getline (*input, line)) |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
362 { |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
363 // Skip blank lines for compatibility. |
22656
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
364 if ((! sep_is_wspace || auto_sep_is_wspace) |
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
365 && 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
|
366 continue; |
7580
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
367 |
22656
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
368 // Infer separator from file if delimiter is blank. |
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
369 if (sep.empty ()) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
370 { |
22621
e7699adac1d0
Do a better job of delimiter auto-dedection in dlmread (bug #42022).
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
371 // Skip leading whitespace. |
29654
d13d090cb03a
use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents:
29358
diff
changeset
|
372 std::size_t pos1 = line.find_first_not_of (" \t"); |
22621
e7699adac1d0
Do a better job of delimiter auto-dedection in dlmread (bug #42022).
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
373 |
22656
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
374 // For Matlab compatibility, blank delimiter should |
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
375 // correspond to whitespace (space and tab). |
29654
d13d090cb03a
use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents:
29358
diff
changeset
|
376 std::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
|
377 if (n == std::string::npos) |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
378 { |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
379 sep = " \t"; |
22656
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
380 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
|
381 } |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
382 else |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
383 { |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
384 char ch = line.at (n); |
7580
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
385 |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
386 switch (line.at (n)) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
387 { |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
388 case ' ': |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
389 case '\t': |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
390 sep = " \t"; |
22656
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
391 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
|
392 break; |
7580
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
393 |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
394 default: |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
395 sep = ch; |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
396 break; |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
397 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
398 } |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
399 } |
10804
3d5c6b84ddaf
speed-up fixes to dlmread
Jaroslav Hajek <highegg@gmail.com>
parents:
10718
diff
changeset
|
400 |
22666
68d5c4759783
dlmread: Return correct number of columns when line ends with separator (bug #42025).
Rik <rik@octave.org>
parents:
22657
diff
changeset
|
401 // 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
|
402 if (cmax == 0) |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
403 { |
29654
d13d090cb03a
use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents:
29358
diff
changeset
|
404 std::size_t pos1, pos2; |
22656
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
405 if (auto_sep_is_wspace) |
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
406 pos1 = line.find_first_not_of (" \t"); |
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
407 else |
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
408 pos1 = 0; |
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
409 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
410 do |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
411 { |
22656
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
412 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
|
413 |
22656
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
414 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
|
415 { |
22656
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
416 // 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
|
417 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
|
418 if (pos2 != std::string::npos) |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
419 pos2 -= 1; |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
420 } |
7580
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
421 |
22666
68d5c4759783
dlmread: Return correct number of columns when line ends with separator (bug #42025).
Rik <rik@octave.org>
parents:
22657
diff
changeset
|
422 // 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
|
423 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
|
424 cmax++; |
7581 | 425 |
22656
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
426 pos1 = pos2 + 1; |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
427 } |
22656
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
428 while (pos2 != std::string::npos); |
7581 | 429 |
22666
68d5c4759783
dlmread: Return correct number of columns when line ends with separator (bug #42025).
Rik <rik@octave.org>
parents:
22657
diff
changeset
|
430 // 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
|
431 // 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
|
432 if (iscmplx) |
22657
a93887d7f0da
Use EmptyValue option correctly in all instances (bug #42023).
Rik <rik@octave.org>
parents:
22656
diff
changeset
|
433 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
|
434 else |
22657
a93887d7f0da
Use EmptyValue option correctly in all instances (bug #42023).
Rik <rik@octave.org>
parents:
22656
diff
changeset
|
435 rdata.resize (rmax, cmax, empty_value); |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9512
diff
changeset
|
436 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
437 |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
438 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
|
439 j = 0; |
22656
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
440 |
29654
d13d090cb03a
use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents:
29358
diff
changeset
|
441 std::size_t pos1, pos2; |
22656
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
442 if (auto_sep_is_wspace) |
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
443 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
|
444 else |
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
445 pos1 = 0; |
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
446 |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
447 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
|
448 { |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
449 octave_quit (); |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
450 |
22656
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
451 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
|
452 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
|
453 |
22656
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
454 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
|
455 { |
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
456 // Treat consecutive separators as one. |
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
457 pos2 = line.find_first_not_of (sep, pos2); |
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
458 if (pos2 != std::string::npos) |
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
459 pos2 -= 1; |
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
460 else |
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
461 pos2 = line.length () - 1; |
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
462 } |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
463 |
22666
68d5c4759783
dlmread: Return correct number of columns when line ends with separator (bug #42025).
Rik <rik@octave.org>
parents:
22657
diff
changeset
|
464 // 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
|
465 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
|
466 break; |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
467 |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
468 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
|
469 if (r > rmax || c > cmax) |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
470 { |
22656
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
471 // 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
|
472 // 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
|
473 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
|
474 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
|
475 if (iscmplx) |
22657
a93887d7f0da
Use EmptyValue option correctly in all instances (bug #42023).
Rik <rik@octave.org>
parents:
22656
diff
changeset
|
476 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
|
477 else |
22657
a93887d7f0da
Use EmptyValue option correctly in all instances (bug #42023).
Rik <rik@octave.org>
parents:
22656
diff
changeset
|
478 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
|
479 } |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
480 |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
481 tmp_stream.str (str); |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
482 tmp_stream.clear (); |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
483 |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
484 double x = read_value<double> (tmp_stream); |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
485 if (tmp_stream) |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
486 { |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
487 if (tmp_stream.eof ()) |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
488 { |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
489 if (iscmplx) |
30390
a61e1a0f6024
maint: style check C++ files in libinterp/ ahead of 7.1 release.
Rik <rik@octave.org>
parents:
29961
diff
changeset
|
490 cdata(i, j++) = x; |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
491 else |
30390
a61e1a0f6024
maint: style check C++ files in libinterp/ ahead of 7.1 release.
Rik <rik@octave.org>
parents:
29961
diff
changeset
|
492 rdata(i, j++) = x; |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
493 } |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
494 else |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
495 { |
25874
11f63a33732e
dlmread.cc: Avoid tolower which causes problems when locale changes (bug #54622).
Rik <rik@octave.org>
parents:
25764
diff
changeset
|
496 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
|
497 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
|
498 || 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
|
499 { |
d05f688ae836
dlmread: Add support for reading pure imaginary numbers (bug #50589).
Rik <rik@octave.org>
parents:
23308
diff
changeset
|
500 // Process pure imaginary numbers. |
25686
af0b81f2ffe6
Correctly handle corner cases in dlmread.
Rik <rik@octave.org>
parents:
25679
diff
changeset
|
501 tmp_stream.get (); |
af0b81f2ffe6
Correctly handle corner cases in dlmread.
Rik <rik@octave.org>
parents:
25679
diff
changeset
|
502 next_char = tmp_stream.peek (); |
af0b81f2ffe6
Correctly handle corner cases in dlmread.
Rik <rik@octave.org>
parents:
25679
diff
changeset
|
503 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
|
504 { |
25686
af0b81f2ffe6
Correctly handle corner cases in dlmread.
Rik <rik@octave.org>
parents:
25679
diff
changeset
|
505 if (! iscmplx) |
af0b81f2ffe6
Correctly handle corner cases in dlmread.
Rik <rik@octave.org>
parents:
25679
diff
changeset
|
506 { |
af0b81f2ffe6
Correctly handle corner cases in dlmread.
Rik <rik@octave.org>
parents:
25679
diff
changeset
|
507 iscmplx = true; |
af0b81f2ffe6
Correctly handle corner cases in dlmread.
Rik <rik@octave.org>
parents:
25679
diff
changeset
|
508 cdata = ComplexMatrix (rdata); |
af0b81f2ffe6
Correctly handle corner cases in dlmread.
Rik <rik@octave.org>
parents:
25679
diff
changeset
|
509 } |
af0b81f2ffe6
Correctly handle corner cases in dlmread.
Rik <rik@octave.org>
parents:
25679
diff
changeset
|
510 |
30390
a61e1a0f6024
maint: style check C++ files in libinterp/ ahead of 7.1 release.
Rik <rik@octave.org>
parents:
29961
diff
changeset
|
511 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
|
512 } |
25686
af0b81f2ffe6
Correctly handle corner cases in dlmread.
Rik <rik@octave.org>
parents:
25679
diff
changeset
|
513 else |
af0b81f2ffe6
Correctly handle corner cases in dlmread.
Rik <rik@octave.org>
parents:
25679
diff
changeset
|
514 { |
af0b81f2ffe6
Correctly handle corner cases in dlmread.
Rik <rik@octave.org>
parents:
25679
diff
changeset
|
515 // Parsing failed, <number>i|j<extra text> |
af0b81f2ffe6
Correctly handle corner cases in dlmread.
Rik <rik@octave.org>
parents:
25679
diff
changeset
|
516 j++; // Leave data initialized to empty_value |
af0b81f2ffe6
Correctly handle corner cases in dlmread.
Rik <rik@octave.org>
parents:
25679
diff
changeset
|
517 } |
23318
d05f688ae836
dlmread: Add support for reading pure imaginary numbers (bug #50589).
Rik <rik@octave.org>
parents:
23308
diff
changeset
|
518 } |
25679
4596a80cbc18
Correctly read "Name" as empty_value in dlmread (bug #54029)
Rik <rik@octave.org>
parents:
25672
diff
changeset
|
519 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
|
520 { |
af0b81f2ffe6
Correctly handle corner cases in dlmread.
Rik <rik@octave.org>
parents:
25679
diff
changeset
|
521 // Parsing failed, <Inf|NA|NaN><extra text> |
af0b81f2ffe6
Correctly handle corner cases in dlmread.
Rik <rik@octave.org>
parents:
25679
diff
changeset
|
522 j++; // Leave data initialized to empty_value |
af0b81f2ffe6
Correctly handle corner cases in dlmread.
Rik <rik@octave.org>
parents:
25679
diff
changeset
|
523 } |
23318
d05f688ae836
dlmread: Add support for reading pure imaginary numbers (bug #50589).
Rik <rik@octave.org>
parents:
23308
diff
changeset
|
524 else |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
525 { |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
526 double y = read_value<double> (tmp_stream); |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
527 |
26349
6ec8b2eab987
dlmread.cc: Fix static analyzer detected issues (bug #55347).
Rik <rik@octave.org>
parents:
25874
diff
changeset
|
528 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
|
529 { |
d05f688ae836
dlmread: Add support for reading pure imaginary numbers (bug #50589).
Rik <rik@octave.org>
parents:
23308
diff
changeset
|
530 iscmplx = true; |
d05f688ae836
dlmread: Add support for reading pure imaginary numbers (bug #50589).
Rik <rik@octave.org>
parents:
23308
diff
changeset
|
531 cdata = ComplexMatrix (rdata); |
d05f688ae836
dlmread: Add support for reading pure imaginary numbers (bug #50589).
Rik <rik@octave.org>
parents:
23308
diff
changeset
|
532 } |
d05f688ae836
dlmread: Add support for reading pure imaginary numbers (bug #50589).
Rik <rik@octave.org>
parents:
23308
diff
changeset
|
533 |
d05f688ae836
dlmread: Add support for reading pure imaginary numbers (bug #50589).
Rik <rik@octave.org>
parents:
23308
diff
changeset
|
534 if (iscmplx) |
30390
a61e1a0f6024
maint: style check C++ files in libinterp/ ahead of 7.1 release.
Rik <rik@octave.org>
parents:
29961
diff
changeset
|
535 cdata(i, j++) = Complex (x, y); |
23318
d05f688ae836
dlmread: Add support for reading pure imaginary numbers (bug #50589).
Rik <rik@octave.org>
parents:
23308
diff
changeset
|
536 else |
30390
a61e1a0f6024
maint: style check C++ files in libinterp/ ahead of 7.1 release.
Rik <rik@octave.org>
parents:
29961
diff
changeset
|
537 rdata(i, j++) = x; |
23318
d05f688ae836
dlmread: Add support for reading pure imaginary numbers (bug #50589).
Rik <rik@octave.org>
parents:
23308
diff
changeset
|
538 } |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
539 } |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
540 } |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
541 else |
25686
af0b81f2ffe6
Correctly handle corner cases in dlmread.
Rik <rik@octave.org>
parents:
25679
diff
changeset
|
542 { |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
543 // read_value<double>() parsing failed |
25686
af0b81f2ffe6
Correctly handle corner cases in dlmread.
Rik <rik@octave.org>
parents:
25679
diff
changeset
|
544 j++; // Leave data initialized to empty_value |
af0b81f2ffe6
Correctly handle corner cases in dlmread.
Rik <rik@octave.org>
parents:
25679
diff
changeset
|
545 } |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
546 |
22656
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
547 pos1 = pos2 + 1; |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
548 } |
22656
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
549 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
|
550 |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
551 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
|
552 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
|
553 |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
554 i++; |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
555 } |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
556 |
23307
85ffe1bdd3a0
dlmread: Return empty matrix when requested range is outside data (bug #50102).
Rik <rik@octave.org>
parents:
23219
diff
changeset
|
557 // 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
|
558 if (r1 >= r) |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
559 r1 = r - 1; |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
560 if (c1 >= c) |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
561 c1 = c - 1; |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
562 |
23307
85ffe1bdd3a0
dlmread: Return empty matrix when requested range is outside data (bug #50102).
Rik <rik@octave.org>
parents:
23219
diff
changeset
|
563 if (iscmplx) |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20213
diff
changeset
|
564 { |
23307
85ffe1bdd3a0
dlmread: Return empty matrix when requested range is outside data (bug #50102).
Rik <rik@octave.org>
parents:
23219
diff
changeset
|
565 if ((i == 0 && j == 0) || (c0 > c1)) |
30390
a61e1a0f6024
maint: style check C++ files in libinterp/ ahead of 7.1 release.
Rik <rik@octave.org>
parents:
29961
diff
changeset
|
566 return ovl (ComplexMatrix (0, 0)); |
23307
85ffe1bdd3a0
dlmread: Return empty matrix when requested range is outside data (bug #50102).
Rik <rik@octave.org>
parents:
23219
diff
changeset
|
567 |
85ffe1bdd3a0
dlmread: Return empty matrix when requested range is outside data (bug #50102).
Rik <rik@octave.org>
parents:
23219
diff
changeset
|
568 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
|
569 return ovl (cdata); |
7580
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
570 } |
23307
85ffe1bdd3a0
dlmread: Return empty matrix when requested range is outside data (bug #50102).
Rik <rik@octave.org>
parents:
23219
diff
changeset
|
571 else |
85ffe1bdd3a0
dlmread: Return empty matrix when requested range is outside data (bug #50102).
Rik <rik@octave.org>
parents:
23219
diff
changeset
|
572 { |
85ffe1bdd3a0
dlmread: Return empty matrix when requested range is outside data (bug #50102).
Rik <rik@octave.org>
parents:
23219
diff
changeset
|
573 if ((i == 0 && j == 0) || (c0 > c1)) |
30390
a61e1a0f6024
maint: style check C++ files in libinterp/ ahead of 7.1 release.
Rik <rik@octave.org>
parents:
29961
diff
changeset
|
574 return ovl (Matrix (0, 0)); |
7580
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
575 |
23307
85ffe1bdd3a0
dlmread: Return empty matrix when requested range is outside data (bug #50102).
Rik <rik@octave.org>
parents:
23219
diff
changeset
|
576 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
|
577 return ovl (rdata); |
85ffe1bdd3a0
dlmread: Return empty matrix when requested range is outside data (bug #50102).
Rik <rik@octave.org>
parents:
23219
diff
changeset
|
578 } |
7580
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
579 } |
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
580 |
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
581 /* |
23307
85ffe1bdd3a0
dlmread: Return empty matrix when requested range is outside data (bug #50102).
Rik <rik@octave.org>
parents:
23219
diff
changeset
|
582 %!test |
19278
6ca096827123
Use tempname() rather than tmpnam() in core Octave.
Rik <rik@octave.org>
parents:
18112
diff
changeset
|
583 %! file = tempname (); |
23307
85ffe1bdd3a0
dlmread: Return empty matrix when requested range is outside data (bug #50102).
Rik <rik@octave.org>
parents:
23219
diff
changeset
|
584 %! unwind_protect |
22656
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
585 %! fid = fopen (file, "wt"); |
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
586 %! 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
|
587 %! fclose (fid); |
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
588 %! |
23307
85ffe1bdd3a0
dlmread: Return empty matrix when requested range is outside data (bug #50102).
Rik <rik@octave.org>
parents:
23219
diff
changeset
|
589 %! 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
|
590 %! 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
|
591 %! 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
|
592 %! 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
|
593 %! 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
|
594 %! 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
|
595 %! 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
|
596 %! 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
|
597 %! 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
|
598 %! 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
|
599 %! 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
|
600 %! unwind_protect_cleanup |
85ffe1bdd3a0
dlmread: Return empty matrix when requested range is outside data (bug #50102).
Rik <rik@octave.org>
parents:
23219
diff
changeset
|
601 %! unlink (file); |
85ffe1bdd3a0
dlmread: Return empty matrix when requested range is outside data (bug #50102).
Rik <rik@octave.org>
parents:
23219
diff
changeset
|
602 %! end_unwind_protect |
7580
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
603 |
24634
ab2321d4ba03
maint: strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
24555
diff
changeset
|
604 %!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
|
605 %! file = tempname (); |
e8cb11de9383
test: Mark certain bugs as xtest when run on Mac platforms (bug #52627).
Rik <rik@octave.org>
parents:
23738
diff
changeset
|
606 %! unwind_protect |
e8cb11de9383
test: Mark certain bugs as xtest when run on Mac platforms (bug #52627).
Rik <rik@octave.org>
parents:
23738
diff
changeset
|
607 %! 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
|
608 %! 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
|
609 %! fclose (fid); |
e8cb11de9383
test: Mark certain bugs as xtest when run on Mac platforms (bug #52627).
Rik <rik@octave.org>
parents:
23738
diff
changeset
|
610 %! |
e8cb11de9383
test: Mark certain bugs as xtest when run on Mac platforms (bug #52627).
Rik <rik@octave.org>
parents:
23738
diff
changeset
|
611 %! 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
|
612 %! 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
|
613 %! 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
|
614 %! 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
|
615 %! 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
|
616 %! 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
|
617 %! 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
|
618 %! 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
|
619 %! 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
|
620 %! 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
|
621 %! 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
|
622 %! unlink (file); |
e8cb11de9383
test: Mark certain bugs as xtest when run on Mac platforms (bug #52627).
Rik <rik@octave.org>
parents:
23738
diff
changeset
|
623 %! 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
|
624 |
29494
76269aa97398
if bug number is supplied, prefer '%!test' over '%!xtest'
John W. Eaton <jwe@octave.org>
parents:
29359
diff
changeset
|
625 %!test <47413> |
24477
e8cb11de9383
test: Mark certain bugs as xtest when run on Mac platforms (bug #52627).
Rik <rik@octave.org>
parents:
23738
diff
changeset
|
626 %! ## 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
|
627 %! if (! ismac ()), return; endif |
19278
6ca096827123
Use tempname() rather than tmpnam() in core Octave.
Rik <rik@octave.org>
parents:
18112
diff
changeset
|
628 %! file = tempname (); |
23307
85ffe1bdd3a0
dlmread: Return empty matrix when requested range is outside data (bug #50102).
Rik <rik@octave.org>
parents:
23219
diff
changeset
|
629 %! unwind_protect |
22656
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
630 %! fid = fopen (file, "wt"); |
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
631 %! 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
|
632 %! fclose (fid); |
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
633 %! |
23307
85ffe1bdd3a0
dlmread: Return empty matrix when requested range is outside data (bug #50102).
Rik <rik@octave.org>
parents:
23219
diff
changeset
|
634 %! 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
|
635 %! 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
|
636 %! 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
|
637 %! 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
|
638 %! 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
|
639 %! 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
|
640 %! 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
|
641 %! 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
|
642 %! 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
|
643 %! 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
|
644 %! unwind_protect_cleanup |
85ffe1bdd3a0
dlmread: Return empty matrix when requested range is outside data (bug #50102).
Rik <rik@octave.org>
parents:
23219
diff
changeset
|
645 %! unlink (file); |
85ffe1bdd3a0
dlmread: Return empty matrix when requested range is outside data (bug #50102).
Rik <rik@octave.org>
parents:
23219
diff
changeset
|
646 %! end_unwind_protect |
7580
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
647 |
23573
1b4f4ec53b4a
use new script to tag fixed bugs in tests
John W. Eaton <jwe@octave.org>
parents:
23572
diff
changeset
|
648 %!test <*42025> |
22656
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
649 %! file = tempname (); |
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
650 %! unwind_protect |
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
651 %! fid = fopen (file, "wt"); |
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
652 %! fwrite (fid, " \n 1 2\n11 22\n "); |
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
653 %! fclose (fid); |
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
654 %! |
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
655 %! 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
|
656 %! 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
|
657 %! 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
|
658 %! 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
|
659 %! 0, 0, 0, 0]); |
22656
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
660 %! unwind_protect_cleanup |
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
diff
changeset
|
661 %! unlink (file); |
471cc4268677
Overhaul dlmread function (bug #42023, bug #42025).
Rik <rik@octave.org>
parents:
22621
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 |
24555
0645853d12d6
test: Mark certain bugs as xtest when run on Mac platforms (bug #52627).
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
664 %!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
|
665 %! file = tempname (); |
0645853d12d6
test: Mark certain bugs as xtest when run on Mac platforms (bug #52627).
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
666 %! unwind_protect |
0645853d12d6
test: Mark certain bugs as xtest when run on Mac platforms (bug #52627).
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
667 %! 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
|
668 %! 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
|
669 %! 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
|
670 %! 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
|
671 %! 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
|
672 %! fclose (fid); |
0645853d12d6
test: Mark certain bugs as xtest when run on Mac platforms (bug #52627).
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
673 %! |
0645853d12d6
test: Mark certain bugs as xtest when run on Mac platforms (bug #52627).
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
674 %! 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
|
675 %! 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
|
676 %! 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
|
677 %! 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
|
678 %! 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
|
679 %! unlink (file); |
0645853d12d6
test: Mark certain bugs as xtest when run on Mac platforms (bug #52627).
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
680 %! 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
|
681 |
29494
76269aa97398
if bug number is supplied, prefer '%!test' over '%!xtest'
John W. Eaton <jwe@octave.org>
parents:
29359
diff
changeset
|
682 %!test <47413> |
24555
0645853d12d6
test: Mark certain bugs as xtest when run on Mac platforms (bug #52627).
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
683 %! ## 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
|
684 %! if (! ismac ()), return; endif |
23318
d05f688ae836
dlmread: Add support for reading pure imaginary numbers (bug #50589).
Rik <rik@octave.org>
parents:
23308
diff
changeset
|
685 %! file = tempname (); |
d05f688ae836
dlmread: Add support for reading pure imaginary numbers (bug #50589).
Rik <rik@octave.org>
parents:
23308
diff
changeset
|
686 %! unwind_protect |
d05f688ae836
dlmread: Add support for reading pure imaginary numbers (bug #50589).
Rik <rik@octave.org>
parents:
23308
diff
changeset
|
687 %! fid = fopen (file, "wt"); |
d05f688ae836
dlmread: Add support for reading pure imaginary numbers (bug #50589).
Rik <rik@octave.org>
parents:
23308
diff
changeset
|
688 %! 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
|
689 %! 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
|
690 %! 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
|
691 %! 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
|
692 %! fclose (fid); |
d05f688ae836
dlmread: Add support for reading pure imaginary numbers (bug #50589).
Rik <rik@octave.org>
parents:
23308
diff
changeset
|
693 %! |
d05f688ae836
dlmread: Add support for reading pure imaginary numbers (bug #50589).
Rik <rik@octave.org>
parents:
23308
diff
changeset
|
694 %! 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
|
695 %! 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
|
696 %! 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
|
697 %! 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
|
698 %! unwind_protect_cleanup |
85ffe1bdd3a0
dlmread: Return empty matrix when requested range is outside data (bug #50102).
Rik <rik@octave.org>
parents:
23219
diff
changeset
|
699 %! unlink (file); |
85ffe1bdd3a0
dlmread: Return empty matrix when requested range is outside data (bug #50102).
Rik <rik@octave.org>
parents:
23219
diff
changeset
|
700 %! end_unwind_protect |
7580
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
701 |
25672
31c0bb386bcd
Correctly read NA values in dlmread.
Rik <rik@octave.org>
parents:
25646
diff
changeset
|
702 ## NA was not properly read from a file |
31c0bb386bcd
Correctly read NA values in dlmread.
Rik <rik@octave.org>
parents:
25646
diff
changeset
|
703 %!test |
31c0bb386bcd
Correctly read NA values in dlmread.
Rik <rik@octave.org>
parents:
25646
diff
changeset
|
704 %! file = tempname (); |
31c0bb386bcd
Correctly read NA values in dlmread.
Rik <rik@octave.org>
parents:
25646
diff
changeset
|
705 %! unwind_protect |
31c0bb386bcd
Correctly read NA values in dlmread.
Rik <rik@octave.org>
parents:
25646
diff
changeset
|
706 %! fid = fopen (file, "wt"); |
31c0bb386bcd
Correctly read NA values in dlmread.
Rik <rik@octave.org>
parents:
25646
diff
changeset
|
707 %! fwrite (fid, "1,NA,3"); |
31c0bb386bcd
Correctly read NA values in dlmread.
Rik <rik@octave.org>
parents:
25646
diff
changeset
|
708 %! fclose (fid); |
31c0bb386bcd
Correctly read NA values in dlmread.
Rik <rik@octave.org>
parents:
25646
diff
changeset
|
709 %! |
31c0bb386bcd
Correctly read NA values in dlmread.
Rik <rik@octave.org>
parents:
25646
diff
changeset
|
710 %! assert (dlmread (file), [1, NA, 3]); |
31c0bb386bcd
Correctly read NA values in dlmread.
Rik <rik@octave.org>
parents:
25646
diff
changeset
|
711 %! unwind_protect_cleanup |
31c0bb386bcd
Correctly read NA values in dlmread.
Rik <rik@octave.org>
parents:
25646
diff
changeset
|
712 %! unlink (file); |
31c0bb386bcd
Correctly read NA values in dlmread.
Rik <rik@octave.org>
parents:
25646
diff
changeset
|
713 %! end_unwind_protect |
31c0bb386bcd
Correctly read NA values in dlmread.
Rik <rik@octave.org>
parents:
25646
diff
changeset
|
714 |
25686
af0b81f2ffe6
Correctly handle corner cases in dlmread.
Rik <rik@octave.org>
parents:
25679
diff
changeset
|
715 ## "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
|
716 %!test <*54029> |
4596a80cbc18
Correctly read "Name" as empty_value in dlmread (bug #54029)
Rik <rik@octave.org>
parents:
25672
diff
changeset
|
717 %! file = tempname (); |
4596a80cbc18
Correctly read "Name" as empty_value in dlmread (bug #54029)
Rik <rik@octave.org>
parents:
25672
diff
changeset
|
718 %! unwind_protect |
4596a80cbc18
Correctly read "Name" as empty_value in dlmread (bug #54029)
Rik <rik@octave.org>
parents:
25672
diff
changeset
|
719 %! fid = fopen (file, "wt"); |
4596a80cbc18
Correctly read "Name" as empty_value in dlmread (bug #54029)
Rik <rik@octave.org>
parents:
25672
diff
changeset
|
720 %! 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
|
721 %! fclose (fid); |
4596a80cbc18
Correctly read "Name" as empty_value in dlmread (bug #54029)
Rik <rik@octave.org>
parents:
25672
diff
changeset
|
722 %! |
4596a80cbc18
Correctly read "Name" as empty_value in dlmread (bug #54029)
Rik <rik@octave.org>
parents:
25672
diff
changeset
|
723 %! 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
|
724 %! unwind_protect_cleanup |
4596a80cbc18
Correctly read "Name" as empty_value in dlmread (bug #54029)
Rik <rik@octave.org>
parents:
25672
diff
changeset
|
725 %! unlink (file); |
4596a80cbc18
Correctly read "Name" as empty_value in dlmread (bug #54029)
Rik <rik@octave.org>
parents:
25672
diff
changeset
|
726 %! end_unwind_protect |
4596a80cbc18
Correctly read "Name" as empty_value in dlmread (bug #54029)
Rik <rik@octave.org>
parents:
25672
diff
changeset
|
727 |
25686
af0b81f2ffe6
Correctly handle corner cases in dlmread.
Rik <rik@octave.org>
parents:
25679
diff
changeset
|
728 ## 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
|
729 %!test |
af0b81f2ffe6
Correctly handle corner cases in dlmread.
Rik <rik@octave.org>
parents:
25679
diff
changeset
|
730 %! file = tempname (); |
af0b81f2ffe6
Correctly handle corner cases in dlmread.
Rik <rik@octave.org>
parents:
25679
diff
changeset
|
731 %! unwind_protect |
af0b81f2ffe6
Correctly handle corner cases in dlmread.
Rik <rik@octave.org>
parents:
25679
diff
changeset
|
732 %! fid = fopen (file, "wt"); |
af0b81f2ffe6
Correctly handle corner cases in dlmread.
Rik <rik@octave.org>
parents:
25679
diff
changeset
|
733 %! fwrite (fid, "1,Infinity,3"); |
af0b81f2ffe6
Correctly handle corner cases in dlmread.
Rik <rik@octave.org>
parents:
25679
diff
changeset
|
734 %! fclose (fid); |
af0b81f2ffe6
Correctly handle corner cases in dlmread.
Rik <rik@octave.org>
parents:
25679
diff
changeset
|
735 %! |
af0b81f2ffe6
Correctly handle corner cases in dlmread.
Rik <rik@octave.org>
parents:
25679
diff
changeset
|
736 %! assert (dlmread (file), [1, 0, 3]); |
af0b81f2ffe6
Correctly handle corner cases in dlmread.
Rik <rik@octave.org>
parents:
25679
diff
changeset
|
737 %! unwind_protect_cleanup |
af0b81f2ffe6
Correctly handle corner cases in dlmread.
Rik <rik@octave.org>
parents:
25679
diff
changeset
|
738 %! unlink (file); |
af0b81f2ffe6
Correctly handle corner cases in dlmread.
Rik <rik@octave.org>
parents:
25679
diff
changeset
|
739 %! end_unwind_protect |
af0b81f2ffe6
Correctly handle corner cases in dlmread.
Rik <rik@octave.org>
parents:
25679
diff
changeset
|
740 |
af0b81f2ffe6
Correctly handle corner cases in dlmread.
Rik <rik@octave.org>
parents:
25679
diff
changeset
|
741 ## Purely complex numbers with trailing garbage produced complex matrix |
af0b81f2ffe6
Correctly handle corner cases in dlmread.
Rik <rik@octave.org>
parents:
25679
diff
changeset
|
742 %!test |
af0b81f2ffe6
Correctly handle corner cases in dlmread.
Rik <rik@octave.org>
parents:
25679
diff
changeset
|
743 %! file = tempname (); |
af0b81f2ffe6
Correctly handle corner cases in dlmread.
Rik <rik@octave.org>
parents:
25679
diff
changeset
|
744 %! unwind_protect |
af0b81f2ffe6
Correctly handle corner cases in dlmread.
Rik <rik@octave.org>
parents:
25679
diff
changeset
|
745 %! fid = fopen (file, "wt"); |
af0b81f2ffe6
Correctly handle corner cases in dlmread.
Rik <rik@octave.org>
parents:
25679
diff
changeset
|
746 %! fwrite (fid, "1,2jack,3"); |
af0b81f2ffe6
Correctly handle corner cases in dlmread.
Rik <rik@octave.org>
parents:
25679
diff
changeset
|
747 %! fclose (fid); |
af0b81f2ffe6
Correctly handle corner cases in dlmread.
Rik <rik@octave.org>
parents:
25679
diff
changeset
|
748 %! |
af0b81f2ffe6
Correctly handle corner cases in dlmread.
Rik <rik@octave.org>
parents:
25679
diff
changeset
|
749 %! assert (dlmread (file), [1, 0, 3]); |
af0b81f2ffe6
Correctly handle corner cases in dlmread.
Rik <rik@octave.org>
parents:
25679
diff
changeset
|
750 %! unwind_protect_cleanup |
af0b81f2ffe6
Correctly handle corner cases in dlmread.
Rik <rik@octave.org>
parents:
25679
diff
changeset
|
751 %! unlink (file); |
af0b81f2ffe6
Correctly handle corner cases in dlmread.
Rik <rik@octave.org>
parents:
25679
diff
changeset
|
752 %! end_unwind_protect |
25679
4596a80cbc18
Correctly read "Name" as empty_value in dlmread (bug #54029)
Rik <rik@octave.org>
parents:
25672
diff
changeset
|
753 |
28685
65fde9fe3b60
Strip BOM from UTF-8 encoded files in "dlmread" (bug #58813).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28628
diff
changeset
|
754 ## Verify UTF-8 Byte Order Mark does not cause problems with reading |
65fde9fe3b60
Strip BOM from UTF-8 encoded files in "dlmread" (bug #58813).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28628
diff
changeset
|
755 %!test <*58813> |
65fde9fe3b60
Strip BOM from UTF-8 encoded files in "dlmread" (bug #58813).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28628
diff
changeset
|
756 %! file = tempname (); |
65fde9fe3b60
Strip BOM from UTF-8 encoded files in "dlmread" (bug #58813).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28628
diff
changeset
|
757 %! unwind_protect |
65fde9fe3b60
Strip BOM from UTF-8 encoded files in "dlmread" (bug #58813).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28628
diff
changeset
|
758 %! fid = fopen (file, "wt"); |
65fde9fe3b60
Strip BOM from UTF-8 encoded files in "dlmread" (bug #58813).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28628
diff
changeset
|
759 %! fwrite (fid, char ([0xEF, 0xBB, 0xBF])); # UTF-8 BOM |
65fde9fe3b60
Strip BOM from UTF-8 encoded files in "dlmread" (bug #58813).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28628
diff
changeset
|
760 %! fwrite (fid, "1,2\n3,4"); |
65fde9fe3b60
Strip BOM from UTF-8 encoded files in "dlmread" (bug #58813).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28628
diff
changeset
|
761 %! fclose (fid); |
65fde9fe3b60
Strip BOM from UTF-8 encoded files in "dlmread" (bug #58813).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28628
diff
changeset
|
762 %! |
65fde9fe3b60
Strip BOM from UTF-8 encoded files in "dlmread" (bug #58813).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28628
diff
changeset
|
763 %! assert (dlmread (file), [1, 2; 3, 4]); |
65fde9fe3b60
Strip BOM from UTF-8 encoded files in "dlmread" (bug #58813).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28628
diff
changeset
|
764 %! unwind_protect_cleanup |
65fde9fe3b60
Strip BOM from UTF-8 encoded files in "dlmread" (bug #58813).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28628
diff
changeset
|
765 %! unlink (file); |
65fde9fe3b60
Strip BOM from UTF-8 encoded files in "dlmread" (bug #58813).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28628
diff
changeset
|
766 %! end_unwind_protect |
65fde9fe3b60
Strip BOM from UTF-8 encoded files in "dlmread" (bug #58813).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28628
diff
changeset
|
767 |
7580
b4aa9ef3d3ef
Port dlmread, dlmwrite, csvread and csvwrite from octave-forge
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
768 */ |
29958
32c3a5805893
move DEFUN and DEFMETHOD functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29928
diff
changeset
|
769 |
31605
e88a07dec498
maint: Use macros to begin/end C++ namespaces.
Rik <rik@octave.org>
parents:
30564
diff
changeset
|
770 OCTAVE_END_NAMESPACE(octave) |