annotate libinterp/corefcn/ls-mat-ascii.cc @ 21200:fcac5dbbf9ed

maint: Indent #ifdef blocks in libinterp. * builtins.h, Cell.cc, __contourc__.cc, __dispatch__.cc, __dsearchn__.cc, __ichol__.cc, __ilu__.cc, __lin_interpn__.cc, __pchip_deriv__.cc, __qp__.cc, balance.cc, besselj.cc, betainc.cc, bitfcns.cc, bsxfun.cc, c-file-ptr-stream.cc, c-file-ptr-stream.h, cellfun.cc, colloc.cc, comment-list.cc, conv2.cc, daspk.cc, dasrt.cc, dassl.cc, data.cc, debug.cc, defaults.cc, defaults.in.h, defun-dld.h, defun.cc, defun.h, det.cc, dirfns.cc, display.cc, dlmread.cc, dot.cc, dynamic-ld.cc, eig.cc, ellipj.cc, error.cc, errwarn.cc, event-queue.cc, fft.cc, fft2.cc, fftn.cc, file-io.cc, filter.cc, find.cc, gammainc.cc, gcd.cc, getgrent.cc, getpwent.cc, getrusage.cc, givens.cc, gl-render.cc, gl2ps-print.cc, graphics.cc, graphics.in.h, gripes.cc, hash.cc, help.cc, hess.cc, hex2num.cc, input.cc, inv.cc, jit-ir.cc, jit-typeinfo.cc, jit-util.cc, jit-util.h, kron.cc, load-path.cc, load-save.cc, lookup.cc, ls-ascii-helper.cc, ls-hdf5.cc, ls-mat-ascii.cc, ls-mat4.cc, ls-mat5.cc, ls-oct-binary.cc, ls-oct-text.cc, ls-oct-text.h, ls-utils.cc, ls-utils.h, lsode.cc, lu.cc, luinc.cc, mappers.cc, matrix_type.cc, max.cc, mex.h, mexproto.h, mgorth.cc, nproc.cc, oct-errno.in.cc, oct-fstrm.cc, oct-hdf5-types.cc, oct-hdf5.h, oct-hist.cc, oct-iostrm.cc, oct-lvalue.cc, oct-map.cc, oct-prcstrm.cc, oct-procbuf.cc, oct-stream.cc, oct-strstrm.cc, octave-link.cc, ordschur.cc, pager.cc, pinv.cc, pr-output.cc, procstream.cc, profiler.cc, psi.cc, pt-jit.cc, quad.cc, quadcc.cc, qz.cc, rand.cc, rcond.cc, regexp.cc, schur.cc, sighandlers.cc, sparse-xdiv.cc, sparse-xpow.cc, sparse.cc, spparms.cc, sqrtm.cc, str2double.cc, strfind.cc, strfns.cc, sub2ind.cc, svd.cc, sylvester.cc, symtab.cc, syscalls.cc, sysdep.cc, sysdep.h, time.cc, toplev.cc, tril.cc, tsearch.cc, txt-eng-ft.cc, txt-eng.cc, typecast.cc, urlwrite.cc, utils.cc, variables.cc, xdiv.cc, xnorm.cc, xpow.cc, zfstream.cc, __delaunayn__.cc, __eigs__.cc, __fltk_uigetfile__.cc, __glpk__.cc, __init_fltk__.cc, __init_gnuplot__.cc, __magick_read__.cc, __osmesa_print__.cc, __voronoi__.cc, amd.cc, audiodevinfo.cc, audioread.cc, ccolamd.cc, chol.cc, colamd.cc, convhulln.cc, dmperm.cc, fftw.cc, oct-qhull.h, qr.cc, symbfact.cc, symrcm.cc, oct-conf.in.cc, ov-base-diag.cc, ov-base-int.cc, ov-base-mat.cc, ov-base-scalar.cc, ov-base-sparse.cc, ov-base.cc, ov-bool-mat.cc, ov-bool-sparse.cc, ov-bool.cc, ov-builtin.cc, ov-cell.cc, ov-ch-mat.cc, ov-class.cc, ov-classdef.cc, ov-colon.cc, ov-complex.cc, ov-cs-list.cc, ov-cx-diag.cc, ov-cx-mat.cc, ov-cx-sparse.cc, ov-dld-fcn.cc, ov-fcn-handle.cc, ov-fcn-inline.cc, ov-fcn.cc, ov-float.cc, ov-flt-complex.cc, ov-flt-cx-diag.cc, ov-flt-cx-mat.cc, ov-flt-re-diag.cc, ov-flt-re-mat.cc, ov-int16.cc, ov-int32.cc, ov-int64.cc, ov-int8.cc, ov-java.cc, ov-lazy-idx.cc, ov-mex-fcn.cc, ov-null-mat.cc, ov-oncleanup.cc, ov-perm.cc, ov-range.cc, ov-re-diag.cc, ov-re-mat.cc, ov-re-sparse.cc, ov-scalar.cc, ov-str-mat.cc, ov-struct.cc, ov-typeinfo.cc, ov-uint16.cc, ov-uint32.cc, ov-uint64.cc, ov-uint8.cc, ov-usr-fcn.cc, ov.cc, ovl.cc, octave.cc, 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-double-conv.cc, op-fcdm-fcdm.cc, op-fcdm-fdm.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-float-conv.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-int-conv.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-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, pt-arg-list.cc, pt-array-list.cc, pt-assign.cc, pt-binop.cc, pt-bp.cc, pt-cbinop.cc, pt-cell.cc, pt-check.cc, pt-classdef.cc, pt-cmd.cc, pt-colon.cc, pt-colon.h, pt-const.cc, pt-decl.cc, pt-eval.cc, pt-except.cc, pt-exp.cc, pt-fcn-handle.cc, pt-funcall.cc, pt-id.cc, pt-idx.cc, pt-jump.cc, pt-loop.cc, pt-mat.cc, pt-misc.cc, pt-pr-code.cc, pt-select.cc, pt-stmt.cc, pt-unop.cc, pt.cc, token.cc, Array-jit.cc, Array-os.cc, Array-sym.cc, Array-tc.cc, version.cc: Indent #ifdef blocks in libinterp.
author Rik <rik@octave.org>
date Fri, 05 Feb 2016 16:29:08 -0800
parents e39e05d90788
children 40de9f8f23a6
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4634
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
1 /*
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
2
19697
4197fc428c7d maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents: 17787
diff changeset
3 Copyright (C) 1996-2015 John W. Eaton
4634
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
4
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
5 This file is part of Octave.
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
6
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
7 Octave is free software; you can redistribute it and/or modify it
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
8 under the terms of the GNU General Public License as published by the
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6856
diff changeset
9 Free Software Foundation; either version 3 of the License, or (at your
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6856
diff changeset
10 option) any later version.
4634
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
11
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
12 Octave is distributed in the hope that it will be useful, but WITHOUT
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
15 for more details.
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
16
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6856
diff changeset
18 along with Octave; see the file COPYING. If not, see
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6856
diff changeset
19 <http://www.gnu.org/licenses/>.
4634
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
20
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
21 */
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
22
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
23 #ifdef HAVE_CONFIG_H
21200
fcac5dbbf9ed maint: Indent #ifdef blocks in libinterp.
Rik <rik@octave.org>
parents: 21100
diff changeset
24 # include <config.h>
4634
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
25 #endif
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
26
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
27 #include <cfloat>
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
28 #include <cstring>
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
29 #include <cctype>
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
30
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
31 #include <fstream>
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
32 #include <iomanip>
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
33 #include <iostream>
5765
7ba9ad1fec11 [project @ 2006-04-17 05:05:15 by jwe]
jwe
parents: 5307
diff changeset
34 #include <sstream>
4634
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
35 #include <string>
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
36
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
37 #include "byte-swap.h"
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
38 #include "data-conv.h"
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
39 #include "file-ops.h"
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
40 #include "glob-match.h"
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
41 #include "lo-mappers.h"
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
42 #include "mach-info.h"
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
43 #include "oct-env.h"
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
44 #include "oct-time.h"
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
45 #include "quit.h"
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
46 #include "str-vec.h"
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
47
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
48 #include "Cell.h"
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
49 #include "defun.h"
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
50 #include "error.h"
21100
e39e05d90788 Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents: 21017
diff changeset
51 #include "errwarn.h"
4867
c7f9ea142fda [project @ 2004-04-20 19:41:11 by jwe]
jwe
parents: 4726
diff changeset
52 #include "lex.h"
4634
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
53 #include "load-save.h"
8946
e7e928088e90 fix CRLF issues with text-mode reading in windows when loading ascii data
Benjamin Lindner <lindnerb@users.sourceforge.net>
parents: 8920
diff changeset
54 #include "ls-ascii-helper.h"
e7e928088e90 fix CRLF issues with text-mode reading in windows when loading ascii data
Benjamin Lindner <lindnerb@users.sourceforge.net>
parents: 8920
diff changeset
55 #include "ls-mat-ascii.h"
20940
48b2ad5ee801 maint: Rename oct-obj.[cc|h] to ovl.[cc|h] for clarity.
Rik <rik@octave.org>
parents: 20756
diff changeset
56 #include "ovl.h"
4634
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
57 #include "oct-map.h"
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
58 #include "ov-cell.h"
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
59 #include "pager.h"
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
60 #include "pt-exp.h"
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
61 #include "sysdep.h"
20756
200ae1d650b7 propagate octave_execution_exception objects through try/catch blocks
John W. Eaton <jwe@octave.org>
parents: 20555
diff changeset
62 #include "toplev.h"
4634
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
63 #include "unwind-prot.h"
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
64 #include "utils.h"
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
65 #include "variables.h"
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
66 #include "version.h"
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
67 #include "dMatrix.h"
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
68
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
69 static std::string
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
70 get_mat_data_input_line (std::istream& is)
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
71 {
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
72 std::string retval;
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
73
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
74 bool have_data = false;
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
75
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
76 do
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
77 {
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
78 retval = "";
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
79
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
80 char c;
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
81 while (is.get (c))
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
82 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
83 if (c == '\n' || c == '\r')
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
84 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
85 is.putback (c);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
86 skip_preceeding_newline (is);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
87 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
88 }
4634
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
89
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
90 if (c == '%' || c == '#')
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
91 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
92 skip_until_newline (is, false);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
93 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
94 }
4634
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
95
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
96 if (! is.eof ())
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
97 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
98 if (! have_data && c != ' ' && c != '\t')
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
99 have_data = true;
4634
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
100
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
101 retval += c;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
102 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
103 }
4634
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
104 }
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
105 while (! (have_data || is.eof ()));
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
106
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
107 return retval;
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
108 }
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
109
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
110 static void
17183
ca5103ab0b21 check_gzip_magic before get_file_format (wrong type detection, bug #39652)
Andreas Weber <andy.weber.aw@gmail.com>
parents: 16892
diff changeset
111 get_lines_and_columns (std::istream& is,
16555
04fb96f4bea1 allow double-click in file browser to load data files
John W. Eaton <jwe@octave.org>
parents: 15467
diff changeset
112 octave_idx_type& nr, octave_idx_type& nc,
21017
93748bcaec17 maint: Replace emtpy 'std::string ()' calls with "".
Rik <rik@octave.org>
parents: 20981
diff changeset
113 const std::string& filename = "",
16555
04fb96f4bea1 allow double-click in file browser to load data files
John W. Eaton <jwe@octave.org>
parents: 15467
diff changeset
114 bool quiet = false, bool check_numeric = false)
4634
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
115 {
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
116 std::streampos pos = is.tellg ();
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
117
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
118 int file_line_number = 0;
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
119
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
120 nr = 0;
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
121 nc = 0;
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
122
20555
f90c8372b7ba eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20535
diff changeset
123 while (is)
4634
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
124 {
10142
829e69ec3110 make OCTAVE_QUIT a function
Jaroslav Hajek <highegg@gmail.com>
parents: 9469
diff changeset
125 octave_quit ();
4634
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
126
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
127 std::string buf = get_mat_data_input_line (is);
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
128
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
129 file_line_number++;
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
130
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
131 size_t beg = buf.find_first_not_of (", \t");
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
132
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
133 // If we see a CR as the last character in the buffer, we had a
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
134 // CRLF pair as the line separator. Any other CR in the text
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
135 // will not be considered as whitespace.
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
136
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
137 if (beg != std::string::npos && buf[beg] == '\r'
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
138 && beg == buf.length () - 1)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
139 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
140 // We had a blank line ending with a CRLF. Handle it the
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
141 // same as an empty line.
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
142 beg = std::string::npos;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
143 }
4634
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
144
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 4867
diff changeset
145 octave_idx_type tmp_nc = 0;
4634
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
146
8021
85184151822e fix typo in NPOS change
John W. Eaton <jwe@octave.org>
parents: 8019
diff changeset
147 while (beg != std::string::npos)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
148 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
149 tmp_nc++;
4634
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
150
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
151 size_t end = buf.find_first_of (", \t", beg);
4634
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
152
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
153 if (end != std::string::npos)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
154 {
16555
04fb96f4bea1 allow double-click in file browser to load data files
John W. Eaton <jwe@octave.org>
parents: 15467
diff changeset
155 if (check_numeric)
04fb96f4bea1 allow double-click in file browser to load data files
John W. Eaton <jwe@octave.org>
parents: 15467
diff changeset
156 {
04fb96f4bea1 allow double-click in file browser to load data files
John W. Eaton <jwe@octave.org>
parents: 15467
diff changeset
157 std::istringstream tmp_stream (buf.substr (beg, end-beg));
04fb96f4bea1 allow double-click in file browser to load data files
John W. Eaton <jwe@octave.org>
parents: 15467
diff changeset
158
04fb96f4bea1 allow double-click in file browser to load data files
John W. Eaton <jwe@octave.org>
parents: 15467
diff changeset
159 octave_read_double (tmp_stream);
04fb96f4bea1 allow double-click in file browser to load data files
John W. Eaton <jwe@octave.org>
parents: 15467
diff changeset
160
04fb96f4bea1 allow double-click in file browser to load data files
John W. Eaton <jwe@octave.org>
parents: 15467
diff changeset
161 if (tmp_stream.fail ())
04fb96f4bea1 allow double-click in file browser to load data files
John W. Eaton <jwe@octave.org>
parents: 15467
diff changeset
162 {
04fb96f4bea1 allow double-click in file browser to load data files
John W. Eaton <jwe@octave.org>
parents: 15467
diff changeset
163 if (! quiet)
04fb96f4bea1 allow double-click in file browser to load data files
John W. Eaton <jwe@octave.org>
parents: 15467
diff changeset
164 error ("load: %s: non-numeric data found near line %d",
04fb96f4bea1 allow double-click in file browser to load data files
John W. Eaton <jwe@octave.org>
parents: 15467
diff changeset
165 filename.c_str (), file_line_number);
04fb96f4bea1 allow double-click in file browser to load data files
John W. Eaton <jwe@octave.org>
parents: 15467
diff changeset
166
04fb96f4bea1 allow double-click in file browser to load data files
John W. Eaton <jwe@octave.org>
parents: 15467
diff changeset
167 nr = 0;
04fb96f4bea1 allow double-click in file browser to load data files
John W. Eaton <jwe@octave.org>
parents: 15467
diff changeset
168 nc = 0;
04fb96f4bea1 allow double-click in file browser to load data files
John W. Eaton <jwe@octave.org>
parents: 15467
diff changeset
169
04fb96f4bea1 allow double-click in file browser to load data files
John W. Eaton <jwe@octave.org>
parents: 15467
diff changeset
170 goto done;
04fb96f4bea1 allow double-click in file browser to load data files
John W. Eaton <jwe@octave.org>
parents: 15467
diff changeset
171 }
04fb96f4bea1 allow double-click in file browser to load data files
John W. Eaton <jwe@octave.org>
parents: 15467
diff changeset
172 }
04fb96f4bea1 allow double-click in file browser to load data files
John W. Eaton <jwe@octave.org>
parents: 15467
diff changeset
173
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
174 beg = buf.find_first_not_of (", \t", end);
4634
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
175
19864
17d647821d61 maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
176 if (beg == std::string::npos
17d647821d61 maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
177 || (buf[beg] == '\r' && beg == buf.length () - 1))
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
178 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
179 // We had a line with trailing spaces and
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
180 // ending with a CRLF, so this should look like EOL,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
181 // not a new colum.
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
182 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
183 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
184 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
185 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
186 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
187 }
4634
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
188
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
189 if (tmp_nc > 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
190 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
191 if (nc == 0)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
192 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
193 nc = tmp_nc;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
194 nr++;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
195 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
196 else if (nc == tmp_nc)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
197 nr++;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
198 else
16555
04fb96f4bea1 allow double-click in file browser to load data files
John W. Eaton <jwe@octave.org>
parents: 15467
diff changeset
199 {
04fb96f4bea1 allow double-click in file browser to load data files
John W. Eaton <jwe@octave.org>
parents: 15467
diff changeset
200 if (! quiet)
04fb96f4bea1 allow double-click in file browser to load data files
John W. Eaton <jwe@octave.org>
parents: 15467
diff changeset
201 error ("load: %s: inconsistent number of columns near line %d",
04fb96f4bea1 allow double-click in file browser to load data files
John W. Eaton <jwe@octave.org>
parents: 15467
diff changeset
202 filename.c_str (), file_line_number);
04fb96f4bea1 allow double-click in file browser to load data files
John W. Eaton <jwe@octave.org>
parents: 15467
diff changeset
203
04fb96f4bea1 allow double-click in file browser to load data files
John W. Eaton <jwe@octave.org>
parents: 15467
diff changeset
204 nr = 0;
04fb96f4bea1 allow double-click in file browser to load data files
John W. Eaton <jwe@octave.org>
parents: 15467
diff changeset
205 nc = 0;
04fb96f4bea1 allow double-click in file browser to load data files
John W. Eaton <jwe@octave.org>
parents: 15467
diff changeset
206
04fb96f4bea1 allow double-click in file browser to load data files
John W. Eaton <jwe@octave.org>
parents: 15467
diff changeset
207 goto done;
04fb96f4bea1 allow double-click in file browser to load data files
John W. Eaton <jwe@octave.org>
parents: 15467
diff changeset
208 }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
209 }
4634
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
210 }
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
211
16555
04fb96f4bea1 allow double-click in file browser to load data files
John W. Eaton <jwe@octave.org>
parents: 15467
diff changeset
212 if (! quiet && (nr == 0 || nc == 0))
15466
d174210ce1ec use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
213 error ("load: file '%s' seems to be empty!", filename.c_str ());
4634
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
214
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
215 done:
16555
04fb96f4bea1 allow double-click in file browser to load data files
John W. Eaton <jwe@octave.org>
parents: 15467
diff changeset
216
4634
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
217 is.clear ();
4643
ef3a14fb6847 [project @ 2003-11-22 12:25:44 by jwe]
jwe
parents: 4634
diff changeset
218 is.seekg (pos);
4634
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
219 }
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
220
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
221 // Extract a matrix from a file of numbers only.
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
222 //
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
223 // Comments are not allowed. The file should only have numeric values.
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
224 //
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
225 // Reads the file twice. Once to find the number of rows and columns,
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
226 // and once to extract the matrix.
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
227 //
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
228 // FILENAME is used for error messages.
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
229 //
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
230 // This format provides no way to tag the data as global.
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
231
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
232 std::string
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
233 read_mat_ascii_data (std::istream& is, const std::string& filename,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
234 octave_value& tc)
4634
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
235 {
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
236 std::string varname;
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
237
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
238 size_t pos = filename.rfind ('/');
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
239
8021
85184151822e fix typo in NPOS change
John W. Eaton <jwe@octave.org>
parents: 8019
diff changeset
240 if (pos != std::string::npos)
4634
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
241 varname = filename.substr (pos+1);
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
242 else
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
243 varname = filename;
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
244
4867
c7f9ea142fda [project @ 2004-04-20 19:41:11 by jwe]
jwe
parents: 4726
diff changeset
245 pos = varname.rfind ('.');
4634
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
246
8021
85184151822e fix typo in NPOS change
John W. Eaton <jwe@octave.org>
parents: 8019
diff changeset
247 if (pos != std::string::npos)
4634
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
248 varname = varname.substr (0, pos);
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
249
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
250 size_t len = varname.length ();
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
251 for (size_t i = 0; i < len; i++)
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
252 {
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
253 char c = varname[i];
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
254 if (! (isalnum (c) || c == '_'))
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
255 varname[i] = '_';
4634
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
256 }
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
257
4867
c7f9ea142fda [project @ 2004-04-20 19:41:11 by jwe]
jwe
parents: 4726
diff changeset
258 if (is_keyword (varname) || ! isalpha (varname[0]))
4634
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
259 varname.insert (0, "X");
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
260
20962
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20956
diff changeset
261 if (! valid_identifier (varname))
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20956
diff changeset
262 error ("load: unable to convert filename '%s' to valid identifier",
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20956
diff changeset
263 filename.c_str ());
4634
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
264
20962
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20956
diff changeset
265 octave_idx_type nr = 0;
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20956
diff changeset
266 octave_idx_type nc = 0;
4634
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
267
20962
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20956
diff changeset
268 int total_count = 0;
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20956
diff changeset
269
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20956
diff changeset
270 get_lines_and_columns (is, nr, nc, filename);
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20956
diff changeset
271
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20956
diff changeset
272 octave_quit ();
4634
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
273
20981
c11cea70b638 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
274 if (nr <= 0 || nc <= 0)
20962
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20956
diff changeset
275 error ("load: unable to extract matrix size from file '%s'",
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
276 filename.c_str ());
4634
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
277
20981
c11cea70b638 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
278 Matrix tmp (nr, nc);
c11cea70b638 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
279
c11cea70b638 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
280 if (nr < 1 || nc < 1)
c11cea70b638 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
281 is.clear (std::ios::badbit);
c11cea70b638 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
282 else
c11cea70b638 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
283 {
c11cea70b638 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
284 double d;
c11cea70b638 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
285 for (octave_idx_type i = 0; i < nr; i++)
c11cea70b638 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
286 {
c11cea70b638 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
287 std::string buf = get_mat_data_input_line (is);
c11cea70b638 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
288
c11cea70b638 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
289 std::istringstream tmp_stream (buf);
c11cea70b638 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
290
c11cea70b638 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
291 for (octave_idx_type j = 0; j < nc; j++)
c11cea70b638 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
292 {
c11cea70b638 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
293 octave_quit ();
c11cea70b638 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
294
c11cea70b638 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
295 d = octave_read_value<double> (tmp_stream);
c11cea70b638 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
296
c11cea70b638 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
297 if (! tmp_stream && ! tmp_stream.eof ())
c11cea70b638 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
298 error ("load: failed to read matrix from file '%s'",
c11cea70b638 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
299 filename.c_str ());
c11cea70b638 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
300
c11cea70b638 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
301 tmp.elem (i, j) = d;
c11cea70b638 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
302 total_count++;
c11cea70b638 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
303
c11cea70b638 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
304 // Skip whitespace and commas.
c11cea70b638 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
305 char c;
c11cea70b638 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
306 while (1)
c11cea70b638 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
307 {
c11cea70b638 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
308 tmp_stream >> c;
c11cea70b638 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
309
c11cea70b638 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
310 if (! tmp_stream)
c11cea70b638 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
311 break;
c11cea70b638 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
312
c11cea70b638 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
313 if (! (c == ' ' || c == '\t' || c == ','))
c11cea70b638 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
314 {
c11cea70b638 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
315 tmp_stream.putback (c);
c11cea70b638 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
316 break;
c11cea70b638 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
317 }
c11cea70b638 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
318 }
c11cea70b638 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
319
c11cea70b638 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
320 if (tmp_stream.eof ())
c11cea70b638 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
321 break;
c11cea70b638 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
322 }
c11cea70b638 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
323 }
c11cea70b638 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
324 }
c11cea70b638 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
325
c11cea70b638 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
326 if (! is && ! is.eof ())
c11cea70b638 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
327 error ("load: failed to read matrix from file '%s'",
c11cea70b638 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
328 filename.c_str ());
c11cea70b638 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
329
c11cea70b638 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
330 // FIXME: not sure this is best, but it works.
c11cea70b638 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
331
c11cea70b638 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
332 if (is.eof ())
c11cea70b638 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
333 is.clear ();
c11cea70b638 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
334
c11cea70b638 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
335 octave_idx_type expected = nr * nc;
c11cea70b638 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
336
c11cea70b638 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
337 if (expected != total_count)
c11cea70b638 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
338 error ("load: expected %d elements, found %d",
c11cea70b638 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
339 expected, total_count);
c11cea70b638 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
340
c11cea70b638 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
341 tc = tmp;
c11cea70b638 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
342
c11cea70b638 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
343 return varname;
4634
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
344 }
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
345
5938
5a3a716c257d [project @ 2006-08-18 06:06:53 by jwe]
jwe
parents: 5775
diff changeset
346 bool
5a3a716c257d [project @ 2006-08-18 06:06:53 by jwe]
jwe
parents: 5775
diff changeset
347 save_mat_ascii_data (std::ostream& os, const octave_value& val,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
348 int precision, bool tabs)
5938
5a3a716c257d [project @ 2006-08-18 06:06:53 by jwe]
jwe
parents: 5775
diff changeset
349 {
5a3a716c257d [project @ 2006-08-18 06:06:53 by jwe]
jwe
parents: 5775
diff changeset
350 bool success = true;
5a3a716c257d [project @ 2006-08-18 06:06:53 by jwe]
jwe
parents: 5775
diff changeset
351
5a3a716c257d [project @ 2006-08-18 06:06:53 by jwe]
jwe
parents: 5775
diff changeset
352 if (val.is_complex_type ())
5a3a716c257d [project @ 2006-08-18 06:06:53 by jwe]
jwe
parents: 5775
diff changeset
353 warning ("save: omitting imaginary part for ASCII file");
5a3a716c257d [project @ 2006-08-18 06:06:53 by jwe]
jwe
parents: 5775
diff changeset
354
20535
b70cc4bd8109 begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents: 19864
diff changeset
355 Matrix m;
5938
5a3a716c257d [project @ 2006-08-18 06:06:53 by jwe]
jwe
parents: 5775
diff changeset
356
20535
b70cc4bd8109 begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents: 19864
diff changeset
357 try
b70cc4bd8109 begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents: 19864
diff changeset
358 {
b70cc4bd8109 begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents: 19864
diff changeset
359 m = val.matrix_value (true);
b70cc4bd8109 begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents: 19864
diff changeset
360 }
20756
200ae1d650b7 propagate octave_execution_exception objects through try/catch blocks
John W. Eaton <jwe@octave.org>
parents: 20555
diff changeset
361 catch (const octave_execution_exception& e)
5938
5a3a716c257d [project @ 2006-08-18 06:06:53 by jwe]
jwe
parents: 5775
diff changeset
362 {
20756
200ae1d650b7 propagate octave_execution_exception objects through try/catch blocks
John W. Eaton <jwe@octave.org>
parents: 20555
diff changeset
363 recover_from_exception ();
200ae1d650b7 propagate octave_execution_exception objects through try/catch blocks
John W. Eaton <jwe@octave.org>
parents: 20555
diff changeset
364
5938
5a3a716c257d [project @ 2006-08-18 06:06:53 by jwe]
jwe
parents: 5775
diff changeset
365 success = false;
20535
b70cc4bd8109 begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents: 19864
diff changeset
366 }
5938
5a3a716c257d [project @ 2006-08-18 06:06:53 by jwe]
jwe
parents: 5775
diff changeset
367
20535
b70cc4bd8109 begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents: 19864
diff changeset
368 if (success)
5951
b2167e370f82 [project @ 2006-08-22 05:13:42 by jwe]
jwe
parents: 5938
diff changeset
369 {
b2167e370f82 [project @ 2006-08-22 05:13:42 by jwe]
jwe
parents: 5938
diff changeset
370 long old_precision = os.precision ();
b2167e370f82 [project @ 2006-08-22 05:13:42 by jwe]
jwe
parents: 5938
diff changeset
371
b2167e370f82 [project @ 2006-08-22 05:13:42 by jwe]
jwe
parents: 5938
diff changeset
372 os.precision (precision);
5938
5a3a716c257d [project @ 2006-08-18 06:06:53 by jwe]
jwe
parents: 5775
diff changeset
373
5951
b2167e370f82 [project @ 2006-08-22 05:13:42 by jwe]
jwe
parents: 5938
diff changeset
374 std::ios::fmtflags oflags
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
375 = os.flags (static_cast<std::ios::fmtflags> (std::ios::scientific));
5951
b2167e370f82 [project @ 2006-08-22 05:13:42 by jwe]
jwe
parents: 5938
diff changeset
376
8425
2e777f5135a3 support -tabs option for save -ascii
Jaroslav Hajek <highegg@gmail.com>
parents: 8021
diff changeset
377 if (tabs)
2e777f5135a3 support -tabs option for save -ascii
Jaroslav Hajek <highegg@gmail.com>
parents: 8021
diff changeset
378 {
2e777f5135a3 support -tabs option for save -ascii
Jaroslav Hajek <highegg@gmail.com>
parents: 8021
diff changeset
379 for (octave_idx_type i = 0; i < m.rows (); i++)
2e777f5135a3 support -tabs option for save -ascii
Jaroslav Hajek <highegg@gmail.com>
parents: 8021
diff changeset
380 {
2e777f5135a3 support -tabs option for save -ascii
Jaroslav Hajek <highegg@gmail.com>
parents: 8021
diff changeset
381 for (octave_idx_type j = 0; j < m.cols (); j++)
2e777f5135a3 support -tabs option for save -ascii
Jaroslav Hajek <highegg@gmail.com>
parents: 8021
diff changeset
382 {
2e777f5135a3 support -tabs option for save -ascii
Jaroslav Hajek <highegg@gmail.com>
parents: 8021
diff changeset
383 // Omit leading tabs.
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
384 if (j != 0) os << '\t';
8425
2e777f5135a3 support -tabs option for save -ascii
Jaroslav Hajek <highegg@gmail.com>
parents: 8021
diff changeset
385 octave_write_double (os, m (i, j));
2e777f5135a3 support -tabs option for save -ascii
Jaroslav Hajek <highegg@gmail.com>
parents: 8021
diff changeset
386 }
2e777f5135a3 support -tabs option for save -ascii
Jaroslav Hajek <highegg@gmail.com>
parents: 8021
diff changeset
387 os << "\n";
2e777f5135a3 support -tabs option for save -ascii
Jaroslav Hajek <highegg@gmail.com>
parents: 8021
diff changeset
388 }
2e777f5135a3 support -tabs option for save -ascii
Jaroslav Hajek <highegg@gmail.com>
parents: 8021
diff changeset
389 }
2e777f5135a3 support -tabs option for save -ascii
Jaroslav Hajek <highegg@gmail.com>
parents: 8021
diff changeset
390 else
2e777f5135a3 support -tabs option for save -ascii
Jaroslav Hajek <highegg@gmail.com>
parents: 8021
diff changeset
391 os << m;
5951
b2167e370f82 [project @ 2006-08-22 05:13:42 by jwe]
jwe
parents: 5938
diff changeset
392
b2167e370f82 [project @ 2006-08-22 05:13:42 by jwe]
jwe
parents: 5938
diff changeset
393 os.flags (oflags);
b2167e370f82 [project @ 2006-08-22 05:13:42 by jwe]
jwe
parents: 5938
diff changeset
394
b2167e370f82 [project @ 2006-08-22 05:13:42 by jwe]
jwe
parents: 5938
diff changeset
395 os.precision (old_precision);
b2167e370f82 [project @ 2006-08-22 05:13:42 by jwe]
jwe
parents: 5938
diff changeset
396 }
5938
5a3a716c257d [project @ 2006-08-18 06:06:53 by jwe]
jwe
parents: 5775
diff changeset
397
5a3a716c257d [project @ 2006-08-18 06:06:53 by jwe]
jwe
parents: 5775
diff changeset
398 return (os && success);
5a3a716c257d [project @ 2006-08-18 06:06:53 by jwe]
jwe
parents: 5775
diff changeset
399 }
16555
04fb96f4bea1 allow double-click in file browser to load data files
John W. Eaton <jwe@octave.org>
parents: 15467
diff changeset
400
04fb96f4bea1 allow double-click in file browser to load data files
John W. Eaton <jwe@octave.org>
parents: 15467
diff changeset
401 bool
17183
ca5103ab0b21 check_gzip_magic before get_file_format (wrong type detection, bug #39652)
Andreas Weber <andy.weber.aw@gmail.com>
parents: 16892
diff changeset
402 looks_like_mat_ascii_file (std::istream& is, const std::string& filename)
16555
04fb96f4bea1 allow double-click in file browser to load data files
John W. Eaton <jwe@octave.org>
parents: 15467
diff changeset
403 {
04fb96f4bea1 allow double-click in file browser to load data files
John W. Eaton <jwe@octave.org>
parents: 15467
diff changeset
404 bool retval = false;
17183
ca5103ab0b21 check_gzip_magic before get_file_format (wrong type detection, bug #39652)
Andreas Weber <andy.weber.aw@gmail.com>
parents: 16892
diff changeset
405 octave_idx_type nr = 0;
ca5103ab0b21 check_gzip_magic before get_file_format (wrong type detection, bug #39652)
Andreas Weber <andy.weber.aw@gmail.com>
parents: 16892
diff changeset
406 octave_idx_type nc = 0;
16555
04fb96f4bea1 allow double-click in file browser to load data files
John W. Eaton <jwe@octave.org>
parents: 15467
diff changeset
407
17183
ca5103ab0b21 check_gzip_magic before get_file_format (wrong type detection, bug #39652)
Andreas Weber <andy.weber.aw@gmail.com>
parents: 16892
diff changeset
408 get_lines_and_columns (is, nr, nc, filename, true, true);
ca5103ab0b21 check_gzip_magic before get_file_format (wrong type detection, bug #39652)
Andreas Weber <andy.weber.aw@gmail.com>
parents: 16892
diff changeset
409 retval = (nr != 0 && nc != 0);
16555
04fb96f4bea1 allow double-click in file browser to load data files
John W. Eaton <jwe@octave.org>
parents: 15467
diff changeset
410
04fb96f4bea1 allow double-click in file browser to load data files
John W. Eaton <jwe@octave.org>
parents: 15467
diff changeset
411 return retval;
04fb96f4bea1 allow double-click in file browser to load data files
John W. Eaton <jwe@octave.org>
parents: 15467
diff changeset
412 }