annotate libinterp/corefcn/ls-mat-ascii.cc @ 26376:00f796120a6d stable

maint: Update copyright dates in all source files.
author John W. Eaton <jwe@octave.org>
date Wed, 02 Jan 2019 16:32:43 -0500
parents 7f6a50f73625
children c67501d55541
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
26376
00f796120a6d maint: Update copyright dates in all source files.
John W. Eaton <jwe@octave.org>
parents: 26164
diff changeset
3 Copyright (C) 1996-2019 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
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 23987
diff changeset
7 Octave is free software: you can redistribute it and/or modify it
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22407
diff changeset
8 under the terms of the GNU General Public License as published by
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 23987
diff changeset
9 the Free Software Foundation, either version 3 of the License, or
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22407
diff changeset
10 (at your option) any later version.
4634
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
11
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22407
diff changeset
12 Octave is distributed in the hope that it will be useful, but
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22407
diff changeset
13 WITHOUT ANY WARRANTY; without even the implied warranty of
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22407
diff changeset
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22407
diff changeset
15 GNU General Public License for more details.
4634
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
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 23987
diff changeset
19 <https://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
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
23 #if defined (HAVE_CONFIG_H)
21301
40de9f8f23a6 Use '#include "config.h"' rather than <config.h>.
Rik <rik@octave.org>
parents: 21200
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 <cctype>
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
28
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
29 #include <iomanip>
25438
cb1606f78f6b prefer <istream>, <ostream>, or <iosfwd> to <iostream> where possible
John W. Eaton <jwe@octave.org>
parents: 25392
diff changeset
30 #include <istream>
cb1606f78f6b prefer <istream>, <ostream>, or <iosfwd> to <iostream> where possible
John W. Eaton <jwe@octave.org>
parents: 25392
diff changeset
31 #include <ostream>
5765
7ba9ad1fec11 [project @ 2006-04-17 05:05:15 by jwe]
jwe
parents: 5307
diff changeset
32 #include <sstream>
4634
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
33 #include <string>
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
34
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
35 #include "byte-swap.h"
23455
73ff72d3d603 maint: Eliminate <cfloat.h> header from libinterp files
Rik <rik@octave.org>
parents: 23220
diff changeset
36 #include "dMatrix.h"
4634
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
37 #include "data-conv.h"
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
38 #include "file-ops.h"
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
39 #include "glob-match.h"
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
40 #include "lo-mappers.h"
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
41 #include "mach-info.h"
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
42 #include "oct-env.h"
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
43 #include "oct-time.h"
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
44 #include "quit.h"
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
45
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
46 #include "Cell.h"
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
47 #include "defun.h"
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
48 #include "error.h"
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
49 #include "interpreter.h"
4867
c7f9ea142fda [project @ 2004-04-20 19:41:11 by jwe]
jwe
parents: 4726
diff changeset
50 #include "lex.h"
4634
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
51 #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
52 #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
53 #include "ls-mat-ascii.h"
4634
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
54 #include "oct-map.h"
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
55 #include "ov-cell.h"
23455
73ff72d3d603 maint: Eliminate <cfloat.h> header from libinterp files
Rik <rik@octave.org>
parents: 23220
diff changeset
56 #include "ov.h"
4634
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
57 #include "pager.h"
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
58 #include "sysdep.h"
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
59 #include "utils.h"
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
60 #include "variables.h"
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
61 #include "version.h"
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
62
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
63 static std::string
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
64 get_mat_data_input_line (std::istream& is)
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
65 {
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
66 std::string retval;
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
67
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
68 bool have_data = false;
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
69
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
70 do
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 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 char c;
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
75 while (is.get (c))
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
76 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
77 if (c == '\n' || c == '\r')
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
78 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
79 is.putback (c);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
80 skip_preceeding_newline (is);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
81 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
82 }
4634
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
83
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
84 if (c == '%' || c == '#')
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
85 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
86 skip_until_newline (is, false);
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 (! is.eof ())
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 if (! have_data && c != ' ' && c != '\t')
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
93 have_data = true;
4634
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
94
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
95 retval += c;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
96 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
97 }
4634
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
98 }
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
99 while (! (have_data || is.eof ()));
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
100
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
101 return retval;
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
102 }
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
103
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
104 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
105 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
106 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
107 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
108 bool quiet = false, bool check_numeric = false)
4634
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 std::streampos pos = is.tellg ();
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
111
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
112 int file_line_number = 0;
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
113
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
114 nr = 0;
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
115 nc = 0;
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
116
20555
f90c8372b7ba eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20535
diff changeset
117 while (is)
4634
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
118 {
10142
829e69ec3110 make OCTAVE_QUIT a function
Jaroslav Hajek <highegg@gmail.com>
parents: 9469
diff changeset
119 octave_quit ();
4634
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
120
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
121 std::string buf = get_mat_data_input_line (is);
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
122
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
123 file_line_number++;
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
124
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
125 size_t beg = buf.find_first_not_of (", \t");
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 // 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
128 // 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
129 // will not be considered as whitespace.
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
130
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
131 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
132 && beg == buf.length () - 1)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
133 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
134 // 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
135 // same as an empty line.
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
136 beg = std::string::npos;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
137 }
4634
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
138
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 4867
diff changeset
139 octave_idx_type tmp_nc = 0;
4634
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
140
8021
85184151822e fix typo in NPOS change
John W. Eaton <jwe@octave.org>
parents: 8019
diff changeset
141 while (beg != std::string::npos)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
142 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
143 tmp_nc++;
4634
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
144
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
145 size_t end = buf.find_first_of (", \t", beg);
4634
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
146
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
147 if (end != std::string::npos)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
148 {
16555
04fb96f4bea1 allow double-click in file browser to load data files
John W. Eaton <jwe@octave.org>
parents: 15467
diff changeset
149 if (check_numeric)
04fb96f4bea1 allow double-click in file browser to load data files
John W. Eaton <jwe@octave.org>
parents: 15467
diff changeset
150 {
04fb96f4bea1 allow double-click in file browser to load data files
John W. Eaton <jwe@octave.org>
parents: 15467
diff changeset
151 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
152
04fb96f4bea1 allow double-click in file browser to load data files
John W. Eaton <jwe@octave.org>
parents: 15467
diff changeset
153 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
154
04fb96f4bea1 allow double-click in file browser to load data files
John W. Eaton <jwe@octave.org>
parents: 15467
diff changeset
155 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
156 {
04fb96f4bea1 allow double-click in file browser to load data files
John W. Eaton <jwe@octave.org>
parents: 15467
diff changeset
157 if (! quiet)
04fb96f4bea1 allow double-click in file browser to load data files
John W. Eaton <jwe@octave.org>
parents: 15467
diff changeset
158 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
159 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
160
04fb96f4bea1 allow double-click in file browser to load data files
John W. Eaton <jwe@octave.org>
parents: 15467
diff changeset
161 nr = 0;
04fb96f4bea1 allow double-click in file browser to load data files
John W. Eaton <jwe@octave.org>
parents: 15467
diff changeset
162 nc = 0;
04fb96f4bea1 allow double-click in file browser to load data files
John W. Eaton <jwe@octave.org>
parents: 15467
diff changeset
163
04fb96f4bea1 allow double-click in file browser to load data files
John W. Eaton <jwe@octave.org>
parents: 15467
diff changeset
164 goto done;
04fb96f4bea1 allow double-click in file browser to load data files
John W. Eaton <jwe@octave.org>
parents: 15467
diff changeset
165 }
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
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
168 beg = buf.find_first_not_of (", \t", end);
4634
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
169
19864
17d647821d61 maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
170 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
171 || (buf[beg] == '\r' && beg == buf.length () - 1))
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
172 {
23812
057a894914df Use C++11 string fcns back() and pop_back() to simplify code.
Rik <rik@octave.org>
parents: 23581
diff changeset
173 // We had a line with trailing spaces and ending with a CRLF,
057a894914df Use C++11 string fcns back() and pop_back() to simplify code.
Rik <rik@octave.org>
parents: 23581
diff changeset
174 // so this should look like EOL, not a new column.
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
175 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
176 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
177 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
178 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
179 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
180 }
4634
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
181
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
182 if (tmp_nc > 0)
10315
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 if (nc == 0)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
185 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
186 nc = tmp_nc;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
187 nr++;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
188 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
189 else if (nc == tmp_nc)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
190 nr++;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
191 else
16555
04fb96f4bea1 allow double-click in file browser to load data files
John W. Eaton <jwe@octave.org>
parents: 15467
diff changeset
192 {
04fb96f4bea1 allow double-click in file browser to load data files
John W. Eaton <jwe@octave.org>
parents: 15467
diff changeset
193 if (! quiet)
04fb96f4bea1 allow double-click in file browser to load data files
John W. Eaton <jwe@octave.org>
parents: 15467
diff changeset
194 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
195 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
196
04fb96f4bea1 allow double-click in file browser to load data files
John W. Eaton <jwe@octave.org>
parents: 15467
diff changeset
197 nr = 0;
04fb96f4bea1 allow double-click in file browser to load data files
John W. Eaton <jwe@octave.org>
parents: 15467
diff changeset
198 nc = 0;
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 goto done;
04fb96f4bea1 allow double-click in file browser to load data files
John W. Eaton <jwe@octave.org>
parents: 15467
diff changeset
201 }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
202 }
4634
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
203 }
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
204
16555
04fb96f4bea1 allow double-click in file browser to load data files
John W. Eaton <jwe@octave.org>
parents: 15467
diff changeset
205 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
206 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
207
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
208 done:
16555
04fb96f4bea1 allow double-click in file browser to load data files
John W. Eaton <jwe@octave.org>
parents: 15467
diff changeset
209
4634
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
210 is.clear ();
4643
ef3a14fb6847 [project @ 2003-11-22 12:25:44 by jwe]
jwe
parents: 4634
diff changeset
211 is.seekg (pos);
4634
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
212 }
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
213
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
214 // Extract a matrix from a file of numbers only.
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
215 //
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
216 // 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
217 //
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
218 // 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
219 // and once to extract the matrix.
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 // FILENAME is used for error messages.
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 // 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
224
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
225 std::string
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
226 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
227 octave_value& tc)
4634
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
228 {
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
229 std::string varname;
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
230
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
231 size_t pos = filename.rfind ('/');
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
232
8021
85184151822e fix typo in NPOS change
John W. Eaton <jwe@octave.org>
parents: 8019
diff changeset
233 if (pos != std::string::npos)
4634
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
234 varname = filename.substr (pos+1);
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
235 else
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
236 varname = filename;
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
237
4867
c7f9ea142fda [project @ 2004-04-20 19:41:11 by jwe]
jwe
parents: 4726
diff changeset
238 pos = varname.rfind ('.');
4634
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 = varname.substr (0, pos);
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
242
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
243 size_t len = varname.length ();
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
244 for (size_t i = 0; i < len; i++)
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
245 {
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
246 char c = varname[i];
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
247 if (! (isalnum (c) || c == '_'))
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
248 varname[i] = '_';
4634
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
26059
da2bbcf1fbcd Deprecate C++ function is_keyword in favor of iskeyword for readability.
Rik <rik@octave.org>
parents: 25646
diff changeset
251 if (octave::iskeyword (varname) || ! isalpha (varname[0]))
4634
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
252 varname.insert (0, "X");
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
253
25646
4d565baa475e move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25438
diff changeset
254 if (! octave::valid_identifier (varname))
20962
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20956
diff changeset
255 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
256 filename.c_str ());
4634
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
257
20962
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20956
diff changeset
258 octave_idx_type nr = 0;
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20956
diff changeset
259 octave_idx_type nc = 0;
4634
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
260
26164
7f6a50f73625 Silence compiler warnings about format identifier for octave_idx_type (bug #55046).
Markus Mützel <markus.muetzel@gmx.de>
parents: 26059
diff changeset
261 octave_idx_type total_count = 0;
20962
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20956
diff changeset
262
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20956
diff changeset
263 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
264
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20956
diff changeset
265 octave_quit ();
4634
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
266
20981
c11cea70b638 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
267 if (nr <= 0 || nc <= 0)
20962
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20956
diff changeset
268 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
269 filename.c_str ());
4634
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
270
20981
c11cea70b638 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
271 Matrix tmp (nr, nc);
c11cea70b638 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
272
c11cea70b638 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
273 if (nr < 1 || nc < 1)
c11cea70b638 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
274 is.clear (std::ios::badbit);
c11cea70b638 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
275 else
c11cea70b638 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
276 {
c11cea70b638 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
277 double d;
c11cea70b638 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
278 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
279 {
c11cea70b638 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
280 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
281
c11cea70b638 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
282 std::istringstream tmp_stream (buf);
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 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
285 {
c11cea70b638 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
286 octave_quit ();
c11cea70b638 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
287
c11cea70b638 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
288 d = octave_read_value<double> (tmp_stream);
c11cea70b638 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
289
c11cea70b638 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
290 if (! tmp_stream && ! tmp_stream.eof ())
c11cea70b638 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
291 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
292 filename.c_str ());
c11cea70b638 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
293
c11cea70b638 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
294 tmp.elem (i, j) = d;
c11cea70b638 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
295 total_count++;
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 // Skip whitespace and commas.
c11cea70b638 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
298 char c;
c11cea70b638 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
299 while (1)
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_stream >> c;
c11cea70b638 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
302
c11cea70b638 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
303 if (! tmp_stream)
c11cea70b638 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
304 break;
c11cea70b638 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
305
c11cea70b638 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
306 if (! (c == ' ' || c == '\t' || c == ','))
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.putback (c);
c11cea70b638 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
309 break;
c11cea70b638 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
310 }
c11cea70b638 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
311 }
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 (tmp_stream.eof ())
c11cea70b638 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
314 break;
c11cea70b638 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
315 }
c11cea70b638 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
316 }
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 if (! is && ! is.eof ())
c11cea70b638 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
320 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
321 filename.c_str ());
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 // 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
324
c11cea70b638 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
325 if (is.eof ())
c11cea70b638 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
326 is.clear ();
c11cea70b638 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
327
c11cea70b638 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
328 octave_idx_type expected = nr * nc;
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 if (expected != total_count)
26164
7f6a50f73625 Silence compiler warnings about format identifier for octave_idx_type (bug #55046).
Markus Mützel <markus.muetzel@gmx.de>
parents: 26059
diff changeset
331 error ("load: expected %" OCTAVE_IDX_TYPE_FORMAT " elements, found "
7f6a50f73625 Silence compiler warnings about format identifier for octave_idx_type (bug #55046).
Markus Mützel <markus.muetzel@gmx.de>
parents: 26059
diff changeset
332 "%" OCTAVE_IDX_TYPE_FORMAT, expected, total_count);
20981
c11cea70b638 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
333
c11cea70b638 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
334 tc = tmp;
c11cea70b638 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
335
c11cea70b638 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
336 return varname;
4634
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
337 }
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
338
5938
5a3a716c257d [project @ 2006-08-18 06:06:53 by jwe]
jwe
parents: 5775
diff changeset
339 bool
5a3a716c257d [project @ 2006-08-18 06:06:53 by jwe]
jwe
parents: 5775
diff changeset
340 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
341 int precision, bool tabs)
5938
5a3a716c257d [project @ 2006-08-18 06:06:53 by jwe]
jwe
parents: 5775
diff changeset
342 {
5a3a716c257d [project @ 2006-08-18 06:06:53 by jwe]
jwe
parents: 5775
diff changeset
343 bool success = true;
5a3a716c257d [project @ 2006-08-18 06:06:53 by jwe]
jwe
parents: 5775
diff changeset
344
23581
c3075ae020e1 maint: Deprecate is_complex_type and replace with iscomplex.
Rik <rik@octave.org>
parents: 23455
diff changeset
345 if (val.iscomplex ())
5938
5a3a716c257d [project @ 2006-08-18 06:06:53 by jwe]
jwe
parents: 5775
diff changeset
346 warning ("save: omitting imaginary part for ASCII file");
5a3a716c257d [project @ 2006-08-18 06:06:53 by jwe]
jwe
parents: 5775
diff changeset
347
23985
aa127fce67e4 doc: Document extra save options for -ascii format (bug #51898).
Rik <rik@octave.org>
parents: 23812
diff changeset
348 if (val.ndims () > 2)
23987
4d5018136313 Skip writing N-D matrix to -ascii format, rather than calling error().
Rik <rik@octave.org>
parents: 23985
diff changeset
349 {
4d5018136313 Skip writing N-D matrix to -ascii format, rather than calling error().
Rik <rik@octave.org>
parents: 23985
diff changeset
350 warning ("save: skipping variable which is not a 2-D matrix");
4d5018136313 Skip writing N-D matrix to -ascii format, rather than calling error().
Rik <rik@octave.org>
parents: 23985
diff changeset
351 return true;
4d5018136313 Skip writing N-D matrix to -ascii format, rather than calling error().
Rik <rik@octave.org>
parents: 23985
diff changeset
352 }
23985
aa127fce67e4 doc: Document extra save options for -ascii format (bug #51898).
Rik <rik@octave.org>
parents: 23812
diff changeset
353
20535
b70cc4bd8109 begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents: 19864
diff changeset
354 Matrix m;
5938
5a3a716c257d [project @ 2006-08-18 06:06:53 by jwe]
jwe
parents: 5775
diff changeset
355
20535
b70cc4bd8109 begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents: 19864
diff changeset
356 try
b70cc4bd8109 begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents: 19864
diff changeset
357 {
b70cc4bd8109 begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents: 19864
diff changeset
358 m = val.matrix_value (true);
b70cc4bd8109 begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents: 19864
diff changeset
359 }
22327
d0562b3159c7 move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
360 catch (const octave::execution_exception& e)
5938
5a3a716c257d [project @ 2006-08-18 06:06:53 by jwe]
jwe
parents: 5775
diff changeset
361 {
23110
af48d8be62b3 move recover_from_exception and atexit functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
362 octave::interpreter::recover_from_exception ();
20756
200ae1d650b7 propagate octave_execution_exception objects through try/catch blocks
John W. Eaton <jwe@octave.org>
parents: 20555
diff changeset
363
5938
5a3a716c257d [project @ 2006-08-18 06:06:53 by jwe]
jwe
parents: 5775
diff changeset
364 success = false;
20535
b70cc4bd8109 begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents: 19864
diff changeset
365 }
5938
5a3a716c257d [project @ 2006-08-18 06:06:53 by jwe]
jwe
parents: 5775
diff changeset
366
20535
b70cc4bd8109 begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents: 19864
diff changeset
367 if (success)
5951
b2167e370f82 [project @ 2006-08-22 05:13:42 by jwe]
jwe
parents: 5938
diff changeset
368 {
b2167e370f82 [project @ 2006-08-22 05:13:42 by jwe]
jwe
parents: 5938
diff changeset
369 long old_precision = os.precision ();
b2167e370f82 [project @ 2006-08-22 05:13:42 by jwe]
jwe
parents: 5938
diff changeset
370
b2167e370f82 [project @ 2006-08-22 05:13:42 by jwe]
jwe
parents: 5938
diff changeset
371 os.precision (precision);
5938
5a3a716c257d [project @ 2006-08-18 06:06:53 by jwe]
jwe
parents: 5775
diff changeset
372
5951
b2167e370f82 [project @ 2006-08-22 05:13:42 by jwe]
jwe
parents: 5938
diff changeset
373 std::ios::fmtflags oflags
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
374 = 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
375
8425
2e777f5135a3 support -tabs option for save -ascii
Jaroslav Hajek <highegg@gmail.com>
parents: 8021
diff changeset
376 if (tabs)
2e777f5135a3 support -tabs option for save -ascii
Jaroslav Hajek <highegg@gmail.com>
parents: 8021
diff changeset
377 {
2e777f5135a3 support -tabs option for save -ascii
Jaroslav Hajek <highegg@gmail.com>
parents: 8021
diff changeset
378 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
379 {
2e777f5135a3 support -tabs option for save -ascii
Jaroslav Hajek <highegg@gmail.com>
parents: 8021
diff changeset
380 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
381 {
2e777f5135a3 support -tabs option for save -ascii
Jaroslav Hajek <highegg@gmail.com>
parents: 8021
diff changeset
382 // Omit leading tabs.
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
383 if (j != 0) os << '\t';
23985
aa127fce67e4 doc: Document extra save options for -ascii format (bug #51898).
Rik <rik@octave.org>
parents: 23812
diff changeset
384 octave_write_double (os, m(i, j));
8425
2e777f5135a3 support -tabs option for save -ascii
Jaroslav Hajek <highegg@gmail.com>
parents: 8021
diff changeset
385 }
2e777f5135a3 support -tabs option for save -ascii
Jaroslav Hajek <highegg@gmail.com>
parents: 8021
diff changeset
386 os << "\n";
2e777f5135a3 support -tabs option for save -ascii
Jaroslav Hajek <highegg@gmail.com>
parents: 8021
diff changeset
387 }
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 else
2e777f5135a3 support -tabs option for save -ascii
Jaroslav Hajek <highegg@gmail.com>
parents: 8021
diff changeset
390 os << m;
5951
b2167e370f82 [project @ 2006-08-22 05:13:42 by jwe]
jwe
parents: 5938
diff changeset
391
23985
aa127fce67e4 doc: Document extra save options for -ascii format (bug #51898).
Rik <rik@octave.org>
parents: 23812
diff changeset
392 // Restore format
5951
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 os.precision (old_precision);
b2167e370f82 [project @ 2006-08-22 05:13:42 by jwe]
jwe
parents: 5938
diff changeset
395 }
5938
5a3a716c257d [project @ 2006-08-18 06:06:53 by jwe]
jwe
parents: 5775
diff changeset
396
5a3a716c257d [project @ 2006-08-18 06:06:53 by jwe]
jwe
parents: 5775
diff changeset
397 return (os && success);
5a3a716c257d [project @ 2006-08-18 06:06:53 by jwe]
jwe
parents: 5775
diff changeset
398 }
16555
04fb96f4bea1 allow double-click in file browser to load data files
John W. Eaton <jwe@octave.org>
parents: 15467
diff changeset
399
04fb96f4bea1 allow double-click in file browser to load data files
John W. Eaton <jwe@octave.org>
parents: 15467
diff changeset
400 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
401 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
402 {
04fb96f4bea1 allow double-click in file browser to load data files
John W. Eaton <jwe@octave.org>
parents: 15467
diff changeset
403 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
404 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
405 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
406
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
407 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
408 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
409
04fb96f4bea1 allow double-click in file browser to load data files
John W. Eaton <jwe@octave.org>
parents: 15467
diff changeset
410 return retval;
04fb96f4bea1 allow double-click in file browser to load data files
John W. Eaton <jwe@octave.org>
parents: 15467
diff changeset
411 }