Mercurial > octave
annotate libinterp/corefcn/ls-oct-text.cc @ 28427:7a8c69c4eb55 stable
convert obsolete octave_fcn_inline object to @inline class
Use a legacy @class object to provide inline function objects instead
of using a built-in class derived from the octave_function_handle
class.
* scripts/legacy/@inline: New directory containing the following
files: argnames.m, char.m, feval.m, formula.m, inline.m, subsref.m,
vectorize.m.
* scripts/legacy/@inline/module.mk: New file.
* scripts/legacy/module.mk, scripts/module.mk: Update.
* test/inline-fcn.tst: New tests.
* test/module.mk: Update.
* ov-fcn-inline.h, ov-fcn-inline.cc: Delete. Remove all uses.
* libinterp/octave-value/module.mk: Update.
* external.txi, func.txi, octave.texi, plot.txi, quad.txi:
Eliminate discusion of inline function objects.
* fplot.m, __ezplot__.m: Use isa to identify inline objects instead of
instead of checking typeinfo.
* ov-fcn-handle.cc, ov-typeinfo.cc: Fix tests.
* ov-base.h, ov-base.cc (octave_base_value::fcn_inline_value): Delete.
* ov.h, ov.cc (octave_value::fcn_inline_value): Delete.
(octave_value::xfcn_inline_value): Delete value extractor.
* ov-class.cc, ov-class.h (octave_inline, octave_inline_fcn):
New classes that allow us to preserve the is_inline_function and
function_value methods that were previously available in the
octave_fcn_inline class.
(F__inline_ctor__): New function for final construction of inline
objects.
* ls-hdf5.cc, ls-mat5.cc, ls-oct-binary.cc, ls-oct-text.cc:
Handle loading of inline function objects from old files as special
cases. New inline function objects will be saved and loaded as
ordinary @class objects.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Mon, 23 Mar 2020 15:29:49 -0400 |
parents | bea3f8f96f7a |
children | 0a5b15007766 |
rev | line source |
---|---|
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
1 //////////////////////////////////////////////////////////////////////// |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
2 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
3 // Copyright (C) 1996-2020 The Octave Project Developers |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
4 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
5 // See the file COPYRIGHT.md in the top-level directory of this |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
6 // distribution or <https://octave.org/copyright/>. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
7 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
8 // This file is part of Octave. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
9 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
10 // Octave is free software: you can redistribute it and/or modify it |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
11 // under the terms of the GNU General Public License as published by |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
12 // the Free Software Foundation, either version 3 of the License, or |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
13 // (at your option) any later version. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
14 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
15 // Octave is distributed in the hope that it will be useful, but |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
16 // WITHOUT ANY WARRANTY; without even the implied warranty of |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
18 // GNU General Public License for more details. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
19 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
20 // You should have received a copy of the GNU General Public License |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
21 // along with Octave; see the file COPYING. If not, see |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
22 // <https://www.gnu.org/licenses/>. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
23 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
24 //////////////////////////////////////////////////////////////////////// |
4634 | 25 |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
26 #if defined (HAVE_CONFIG_H) |
21301
40de9f8f23a6
Use '#include "config.h"' rather than <config.h>.
Rik <rik@octave.org>
parents:
21200
diff
changeset
|
27 # include "config.h" |
4634 | 28 #endif |
29 | |
30 #include <cstring> | |
31 #include <cctype> | |
32 | |
33 #include <fstream> | |
34 #include <iomanip> | |
25438
cb1606f78f6b
prefer <istream>, <ostream>, or <iosfwd> to <iostream> where possible
John W. Eaton <jwe@octave.org>
parents:
25392
diff
changeset
|
35 #include <istream> |
cb1606f78f6b
prefer <istream>, <ostream>, or <iosfwd> to <iostream> where possible
John W. Eaton <jwe@octave.org>
parents:
25392
diff
changeset
|
36 #include <ostream> |
5765 | 37 #include <sstream> |
4634 | 38 #include <string> |
39 | |
40 #include "byte-swap.h" | |
41 #include "data-conv.h" | |
42 #include "file-ops.h" | |
43 #include "glob-match.h" | |
44 #include "lo-mappers.h" | |
45 #include "mach-info.h" | |
46 #include "oct-env.h" | |
47 #include "oct-time.h" | |
48 #include "quit.h" | |
49 #include "str-vec.h" | |
50 | |
51 #include "Cell.h" | |
52 #include "defun.h" | |
53 #include "error.h" | |
21100
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
21021
diff
changeset
|
54 #include "errwarn.h" |
28427
7a8c69c4eb55
convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
28179
diff
changeset
|
55 #include "interpreter.h" |
24540
46440078d73b
don't use singleton for octave_value_typeinfo
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
56 #include "interpreter-private.h" |
4634 | 57 #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
|
58 #include "ls-ascii-helper.h" |
20447
c6224b4e7774
maint: Rename instances of LS_ASCII to LS_TEXT for clarity.
Rik <rik@octave.org>
parents:
20428
diff
changeset
|
59 #include "ls-oct-text.h" |
20940
48b2ad5ee801
maint: Rename oct-obj.[cc|h] to ovl.[cc|h] for clarity.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
60 #include "ovl.h" |
4634 | 61 #include "oct-map.h" |
62 #include "ov-cell.h" | |
63 #include "pager.h" | |
64 #include "unwind-prot.h" | |
65 #include "utils.h" | |
66 #include "variables.h" | |
67 #include "version.h" | |
68 #include "dMatrix.h" | |
69 | |
23556
31b1ef1ee585
Fix Octave's -text format for saving data to make it lossless for IEEE-754 doubles.
Rik <rik@octave.org>
parents:
23470
diff
changeset
|
70 // The number of decimal digits to use when writing ASCII data. |
31b1ef1ee585
Fix Octave's -text format for saving data to make it lossless for IEEE-754 doubles.
Rik <rik@octave.org>
parents:
23470
diff
changeset
|
71 // 17 is the minimum necessary for lossless save/restore of IEEE-754 doubles. |
31b1ef1ee585
Fix Octave's -text format for saving data to make it lossless for IEEE-754 doubles.
Rik <rik@octave.org>
parents:
23470
diff
changeset
|
72 static int Vsave_precision = 17; |
4634 | 73 |
20447
c6224b4e7774
maint: Rename instances of LS_ASCII to LS_TEXT for clarity.
Rik <rik@octave.org>
parents:
20428
diff
changeset
|
74 // Functions for reading octave format text data. |
4634 | 75 |
76 // Extract a KEYWORD and its value from stream IS, returning the | |
77 // associated value in a new string. | |
78 // | |
79 // Input should look something like: | |
80 // | |
81 // [%#][ \t]*keyword[ \t]*:[ \t]*string-value[ \t]*\n | |
82 | |
83 std::string | |
4687 | 84 extract_keyword (std::istream& is, const char *keyword, const bool next_only) |
4634 | 85 { |
86 std::string retval; | |
87 | |
7744
14b841c47a5f
handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
88 int ch = is.peek (); |
14b841c47a5f
handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
89 if (next_only && ch != '%' && ch != '#') |
14b841c47a5f
handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
90 return retval; |
14b841c47a5f
handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
91 |
4634 | 92 char c; |
93 while (is.get (c)) | |
94 { | |
95 if (c == '%' || c == '#') | |
10315
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 std::ostringstream buf; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
98 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
99 while (is.get (c) && (c == ' ' || c == '\t' || c == '%' || c == '#')) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
100 ; // Skip whitespace and comment characters. |
4634 | 101 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
102 if (isalpha (c)) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
103 buf << c; |
4634 | 104 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
105 while (is.get (c) && isalpha (c)) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
106 buf << c; |
4634 | 107 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
108 std::string tmp = buf.str (); |
21021
a5b99b09f8fd
maint: Use comparison operators rather than compare() for strings.
Rik <rik@octave.org>
parents:
21017
diff
changeset
|
109 bool match = (tmp.substr (0, strlen (keyword)) == keyword); |
4634 | 110 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
111 if (match) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
112 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
113 std::ostringstream value; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
114 while (is.get (c) && (c == ' ' || c == '\t' || c == ':')) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
115 ; // Skip whitespace and the colon. |
4634 | 116 |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
117 is.putback (c); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
118 retval = read_until_newline (is, false); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
119 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
120 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
121 else if (next_only) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
122 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
123 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
124 skip_until_newline (is, false); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
125 } |
4634 | 126 } |
127 | |
128 int len = retval.length (); | |
129 | |
130 if (len > 0) | |
131 { | |
132 while (len) | |
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 c = retval[len-1]; |
4634 | 135 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
136 if (c == ' ' || c == '\t') |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
137 len--; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
138 else |
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 retval.resize (len); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
141 break; |
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 } |
4634 | 144 } |
145 | |
146 return retval; | |
147 } | |
148 | |
149 // Extract one value (scalar, matrix, string, etc.) from stream IS and | |
150 // place it in TC, returning the name of the variable. If the value | |
151 // is tagged as global in the file, return TRUE in GLOBAL. | |
152 // | |
4687 | 153 // Each type supplies its own function to load the data, and so this |
154 // function is extensible. | |
155 // | |
4634 | 156 // FILENAME is used for error messages. |
157 // | |
158 // The data is expected to be in the following format: | |
159 // | |
160 // The input file must have a header followed by some data. | |
161 // | |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
162 // All lines in the header must begin with a '#' character. |
4634 | 163 // |
164 // The header must contain a list of keyword and value pairs with the | |
165 // keyword and value separated by a colon. | |
166 // | |
167 // Keywords must appear in the following order: | |
168 // | |
169 // # name: <name> | |
170 // # type: <type> | |
171 // # <info> | |
172 // | |
4687 | 173 // Where, for the built in types are: |
4634 | 174 // |
175 // <name> : a valid identifier | |
176 // | |
177 // <type> : <typename> | |
178 // | global <typename> | |
179 // | |
180 // <typename> : scalar | |
181 // | complex scalar | |
182 // | matrix | |
183 // | complex matrix | |
4687 | 184 // | bool |
185 // | bool matrix | |
4634 | 186 // | string |
187 // | range | |
188 // | |
189 // <info> : <matrix info> | |
190 // | <string info> | |
191 // | |
192 // <matrix info> : # rows: <integer> | |
193 // : # columns: <integer> | |
194 // | |
4687 | 195 // <string info> : # elements: <integer> |
196 // : # length: <integer> (once before each string) | |
4634 | 197 // |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21724
diff
changeset
|
198 // For backward compatibility the type "string array" is treated as a |
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21724
diff
changeset
|
199 // "string" type. Also "string" can have a single element with no elements |
4687 | 200 // line such that |
201 // | |
202 // <string info> : # length: <integer> | |
4634 | 203 // |
204 // Formatted ASCII data follows the header. | |
205 // | |
206 // Example: | |
207 // | |
208 // # name: foo | |
209 // # type: matrix | |
210 // # rows: 2 | |
211 // # columns: 2 | |
212 // 2 4 | |
213 // 1 3 | |
214 // | |
215 // Example: | |
216 // | |
217 // # name: foo | |
4687 | 218 // # type: string |
4634 | 219 // # elements: 5 |
220 // # length: 4 | |
221 // this | |
222 // # length: 2 | |
223 // is | |
224 // # length: 1 | |
225 // a | |
226 // # length: 6 | |
227 // string | |
228 // # length: 5 | |
229 // array | |
230 // | |
20447
c6224b4e7774
maint: Rename instances of LS_ASCII to LS_TEXT for clarity.
Rik <rik@octave.org>
parents:
20428
diff
changeset
|
231 // FIXME: This format is fairly rigid, and doesn't allow for arbitrary comments. |
c6224b4e7774
maint: Rename instances of LS_ASCII to LS_TEXT for clarity.
Rik <rik@octave.org>
parents:
20428
diff
changeset
|
232 // Someone should fix that. It does allow arbitrary types however. |
4634 | 233 |
234 // Ugh. The signature of the compare method is not standard in older | |
235 // versions of the GNU libstdc++. Do this instead: | |
236 | |
26372
2d9ae06f621b
Fix static analyzer detected V1003 issues with expansions in macros (bug #55347).
Rik <rik@octave.org>
parents:
26164
diff
changeset
|
237 #define SUBSTRING_COMPARE_EQ(s, pos, n, t) (s.substr (pos, n) == (t)) |
4634 | 238 |
28427
7a8c69c4eb55
convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
28179
diff
changeset
|
239 static octave_value |
7a8c69c4eb55
convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
28179
diff
changeset
|
240 load_inline_fcn (std::istream& is, const std::string& filename) |
7a8c69c4eb55
convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
28179
diff
changeset
|
241 { |
7a8c69c4eb55
convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
28179
diff
changeset
|
242 int nargs; |
7a8c69c4eb55
convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
28179
diff
changeset
|
243 if (extract_keyword (is, "nargs", nargs, true)) |
7a8c69c4eb55
convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
28179
diff
changeset
|
244 { |
7a8c69c4eb55
convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
28179
diff
changeset
|
245 std::string name; |
7a8c69c4eb55
convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
28179
diff
changeset
|
246 octave_value_list args (nargs+1); |
7a8c69c4eb55
convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
28179
diff
changeset
|
247 for (int i = 0; i < nargs; i++) |
7a8c69c4eb55
convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
28179
diff
changeset
|
248 { |
7a8c69c4eb55
convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
28179
diff
changeset
|
249 std::string tmp; |
7a8c69c4eb55
convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
28179
diff
changeset
|
250 is >> tmp; |
7a8c69c4eb55
convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
28179
diff
changeset
|
251 args(i+1) = tmp; |
7a8c69c4eb55
convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
28179
diff
changeset
|
252 } |
7a8c69c4eb55
convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
28179
diff
changeset
|
253 is >> name; |
7a8c69c4eb55
convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
28179
diff
changeset
|
254 if (name == "0") |
7a8c69c4eb55
convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
28179
diff
changeset
|
255 name = ""; |
7a8c69c4eb55
convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
28179
diff
changeset
|
256 |
7a8c69c4eb55
convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
28179
diff
changeset
|
257 skip_preceeding_newline (is); |
7a8c69c4eb55
convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
28179
diff
changeset
|
258 |
7a8c69c4eb55
convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
28179
diff
changeset
|
259 std::string buf; |
7a8c69c4eb55
convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
28179
diff
changeset
|
260 |
7a8c69c4eb55
convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
28179
diff
changeset
|
261 if (is) |
7a8c69c4eb55
convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
28179
diff
changeset
|
262 { |
7a8c69c4eb55
convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
28179
diff
changeset
|
263 |
7a8c69c4eb55
convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
28179
diff
changeset
|
264 // Get a line of text whitespace characters included, |
7a8c69c4eb55
convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
28179
diff
changeset
|
265 // leaving newline in the stream. |
7a8c69c4eb55
convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
28179
diff
changeset
|
266 buf = read_until_newline (is, true); |
7a8c69c4eb55
convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
28179
diff
changeset
|
267 } |
7a8c69c4eb55
convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
28179
diff
changeset
|
268 |
7a8c69c4eb55
convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
28179
diff
changeset
|
269 if (is) |
7a8c69c4eb55
convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
28179
diff
changeset
|
270 { |
7a8c69c4eb55
convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
28179
diff
changeset
|
271 args(0) = std::string (buf); |
7a8c69c4eb55
convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
28179
diff
changeset
|
272 |
7a8c69c4eb55
convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
28179
diff
changeset
|
273 octave::interpreter& interp |
7a8c69c4eb55
convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
28179
diff
changeset
|
274 = octave::__get_interpreter__ ("load_inline_fcn"); |
7a8c69c4eb55
convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
28179
diff
changeset
|
275 |
7a8c69c4eb55
convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
28179
diff
changeset
|
276 octave_value_list tmp = interp.feval ("inline", args, 1); |
7a8c69c4eb55
convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
28179
diff
changeset
|
277 |
7a8c69c4eb55
convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
28179
diff
changeset
|
278 if (tmp.length () > 0) |
7a8c69c4eb55
convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
28179
diff
changeset
|
279 return tmp(0); |
7a8c69c4eb55
convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
28179
diff
changeset
|
280 } |
7a8c69c4eb55
convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
28179
diff
changeset
|
281 } |
7a8c69c4eb55
convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
28179
diff
changeset
|
282 |
7a8c69c4eb55
convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
28179
diff
changeset
|
283 error ("load: trouble reading ascii file '%s'", filename.c_str ()); |
7a8c69c4eb55
convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
28179
diff
changeset
|
284 } |
7a8c69c4eb55
convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
28179
diff
changeset
|
285 |
4634 | 286 std::string |
20447
c6224b4e7774
maint: Rename instances of LS_ASCII to LS_TEXT for clarity.
Rik <rik@octave.org>
parents:
20428
diff
changeset
|
287 read_text_data (std::istream& is, const std::string& filename, bool& global, |
28179
bea3f8f96f7a
Load structures with arbitrary string fieldnames (bug #50831, bug #46645).
Olaf Till <i7tiol@t-online.de>
parents:
27978
diff
changeset
|
288 octave_value& tc, octave_idx_type count, |
bea3f8f96f7a
Load structures with arbitrary string fieldnames (bug #50831, bug #46645).
Olaf Till <i7tiol@t-online.de>
parents:
27978
diff
changeset
|
289 const bool do_name_validation) |
4634 | 290 { |
291 // Read name for this entry or break on EOF. | |
292 | |
293 std::string name = extract_keyword (is, "name"); | |
294 | |
295 if (name.empty ()) | |
296 { | |
297 if (count == 0) | |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
298 error ("load: empty name keyword or no data found in file '%s'", |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
299 filename.c_str ()); |
4634 | 300 |
21017
93748bcaec17
maint: Replace emtpy 'std::string ()' calls with "".
Rik <rik@octave.org>
parents:
21014
diff
changeset
|
301 return ""; |
4634 | 302 } |
303 | |
28179
bea3f8f96f7a
Load structures with arbitrary string fieldnames (bug #50831, bug #46645).
Olaf Till <i7tiol@t-online.de>
parents:
27978
diff
changeset
|
304 if (name != CELL_ELT_TAG |
bea3f8f96f7a
Load structures with arbitrary string fieldnames (bug #50831, bug #46645).
Olaf Till <i7tiol@t-online.de>
parents:
27978
diff
changeset
|
305 && do_name_validation && ! octave::valid_identifier (name)) |
20835
14cd86258b3d
use 'invalid' instead of 'bogus' in source files
John W. Eaton <jwe@octave.org>
parents:
20831
diff
changeset
|
306 error ("load: invalid identifier '%s' found in file '%s'", |
20741
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20447
diff
changeset
|
307 name.c_str (), filename.c_str ()); |
4634 | 308 |
309 // Look for type keyword. | |
310 | |
311 std::string tag = extract_keyword (is, "type"); | |
312 | |
20981
c11cea70b638
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
313 if (tag.empty ()) |
c11cea70b638
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
314 error ("load: failed to extract keyword specifying value type"); |
4634 | 315 |
20981
c11cea70b638
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
316 std::string typ; |
c11cea70b638
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
317 size_t pos = tag.rfind (' '); |
4634 | 318 |
20981
c11cea70b638
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
319 if (pos != std::string::npos) |
c11cea70b638
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
320 { |
c11cea70b638
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
321 global = SUBSTRING_COMPARE_EQ (tag, 0, 6, "global"); |
4634 | 322 |
23450
855122b993da
maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
323 typ = (global ? tag.substr (7) : tag); |
4634 | 324 } |
325 else | |
20981
c11cea70b638
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
326 typ = tag; |
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 // Special case for backward compatibility. A small bit of cruft |
c11cea70b638
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
329 if (SUBSTRING_COMPARE_EQ (typ, 0, 12, "string array")) |
c11cea70b638
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
330 tc = charMatrix (); |
28427
7a8c69c4eb55
convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
28179
diff
changeset
|
331 else if (SUBSTRING_COMPARE_EQ (typ, 0, 15, "inline function")) |
7a8c69c4eb55
convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
28179
diff
changeset
|
332 { |
7a8c69c4eb55
convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
28179
diff
changeset
|
333 // Special case for loading old octave_inline_fcn objects. |
7a8c69c4eb55
convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
28179
diff
changeset
|
334 tc = load_inline_fcn (is, filename); |
7a8c69c4eb55
convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
28179
diff
changeset
|
335 return name; |
7a8c69c4eb55
convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
28179
diff
changeset
|
336 } |
20981
c11cea70b638
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
337 else |
24540
46440078d73b
don't use singleton for octave_value_typeinfo
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
338 { |
46440078d73b
don't use singleton for octave_value_typeinfo
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
339 octave::type_info& type_info |
46440078d73b
don't use singleton for octave_value_typeinfo
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
340 = octave::__get_type_info__ ("read_text_data"); |
46440078d73b
don't use singleton for octave_value_typeinfo
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
341 |
46440078d73b
don't use singleton for octave_value_typeinfo
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
342 tc = type_info.lookup_type (typ); |
46440078d73b
don't use singleton for octave_value_typeinfo
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
343 } |
20981
c11cea70b638
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
344 |
c11cea70b638
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
345 if (! tc.load_ascii (is)) |
c11cea70b638
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
346 error ("load: trouble reading ascii file '%s'", filename.c_str ()); |
4634 | 347 |
348 return name; | |
349 } | |
350 | |
351 // Save the data from TC along with the corresponding NAME, and global | |
352 // flag MARK_AS_GLOBAL on stream OS in the plain text format described | |
20447
c6224b4e7774
maint: Rename instances of LS_ASCII to LS_TEXT for clarity.
Rik <rik@octave.org>
parents:
20428
diff
changeset
|
353 // above for load_text_data. If NAME is empty, the name: line is not |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
354 // generated. PRECISION specifies the number of decimal digits to print. |
4634 | 355 // |
356 // Assumes ranges and strings cannot contain Inf or NaN values. | |
357 // | |
358 // Returns 1 for success and 0 for failure. | |
359 | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
360 // FIXME: should probably write the help string here too. |
4634 | 361 |
362 bool | |
20447
c6224b4e7774
maint: Rename instances of LS_ASCII to LS_TEXT for clarity.
Rik <rik@octave.org>
parents:
20428
diff
changeset
|
363 save_text_data (std::ostream& os, const octave_value& val_arg, |
23470
a41fdb801db6
use mark_global and mark_persistent consistently
John W. Eaton <jwe@octave.org>
parents:
23450
diff
changeset
|
364 const std::string& name, bool mark_global, |
20447
c6224b4e7774
maint: Rename instances of LS_ASCII to LS_TEXT for clarity.
Rik <rik@octave.org>
parents:
20428
diff
changeset
|
365 int precision) |
4634 | 366 { |
367 if (! name.empty ()) | |
368 os << "# name: " << name << "\n"; | |
369 | |
370 octave_value val = val_arg; | |
371 | |
23470
a41fdb801db6
use mark_global and mark_persistent consistently
John W. Eaton <jwe@octave.org>
parents:
23450
diff
changeset
|
372 if (mark_global) |
4687 | 373 os << "# type: global " << val.type_name () << "\n"; |
374 else | |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
375 os << "# type: " << val.type_name () << "\n"; |
4634 | 376 |
5951 | 377 if (! precision) |
378 precision = Vsave_precision; | |
379 | |
380 long old_precision = os.precision (); | |
381 os.precision (precision); | |
382 | |
26410
d644dec272ea
ls-oct-text.cc: Fix static analyzer detected V519 issue (bug #55347).
Andreas Weber <octave@josoansi.de>
parents:
26376
diff
changeset
|
383 bool success = val.save_ascii (os); |
4634 | 384 |
10417
ad29dbbc3f70
save: make that two newline characters
John W. Eaton <jwe@octave.org>
parents:
10416
diff
changeset
|
385 // Insert an extra pair of newline characters after the data so that |
ad29dbbc3f70
save: make that two newline characters
John W. Eaton <jwe@octave.org>
parents:
10416
diff
changeset
|
386 // multiple data elements may be handled separately by gnuplot (see |
ad29dbbc3f70
save: make that two newline characters
John W. Eaton <jwe@octave.org>
parents:
10416
diff
changeset
|
387 // the description of the index qualifier for the plot command in the |
ad29dbbc3f70
save: make that two newline characters
John W. Eaton <jwe@octave.org>
parents:
10416
diff
changeset
|
388 // gnuplot documentation). |
ad29dbbc3f70
save: make that two newline characters
John W. Eaton <jwe@octave.org>
parents:
10416
diff
changeset
|
389 os << "\n\n"; |
10416
f06ede00fd8f
save: separate variables by blank line in Octave text format files
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
390 |
4634 | 391 os.precision (old_precision); |
392 | |
393 return (os && success); | |
394 } | |
395 | |
396 bool | |
20447
c6224b4e7774
maint: Rename instances of LS_ASCII to LS_TEXT for clarity.
Rik <rik@octave.org>
parents:
20428
diff
changeset
|
397 save_text_data_for_plotting (std::ostream& os, const octave_value& t, |
c6224b4e7774
maint: Rename instances of LS_ASCII to LS_TEXT for clarity.
Rik <rik@octave.org>
parents:
20428
diff
changeset
|
398 const std::string& name) |
4634 | 399 { |
20447
c6224b4e7774
maint: Rename instances of LS_ASCII to LS_TEXT for clarity.
Rik <rik@octave.org>
parents:
20428
diff
changeset
|
400 return save_text_data (os, t, name, false, 6); |
4634 | 401 } |
402 | |
403 // Maybe this should be a static function in tree-plot.cc? | |
404 | |
405 // If TC is matrix, save it on stream OS in a format useful for | |
21014
b9d4c3615e89
maint: Capitalize D for dimension in messages and comments.
Rik <rik@octave.org>
parents:
20981
diff
changeset
|
406 // making a 3-D plot with gnuplot. If PARAMETRIC is TRUE, |
b9d4c3615e89
maint: Capitalize D for dimension in messages and comments.
Rik <rik@octave.org>
parents:
20981
diff
changeset
|
407 // assume a parametric 3-D plot will be generated. |
4634 | 408 |
409 bool | |
410 save_three_d (std::ostream& os, const octave_value& tc, bool parametric) | |
411 { | |
5275 | 412 octave_idx_type nr = tc.rows (); |
413 octave_idx_type nc = tc.columns (); | |
4634 | 414 |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
415 if (! tc.is_real_matrix ()) |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
416 error ("for now, I can only save real matrices in 3-D format"); |
4634 | 417 |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
418 os << "# 3-D data...\n" |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
419 << "# type: matrix\n" |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
420 << "# total rows: " << nr << "\n" |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
421 << "# total columns: " << nc << "\n"; |
6171 | 422 |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
423 long old_precision = os.precision (); |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
424 os.precision (6); |
4634 | 425 |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
426 if (parametric) |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
427 { |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
428 octave_idx_type extras = nc % 3; |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
429 if (extras) |
26164
7f6a50f73625
Silence compiler warnings about format identifier for octave_idx_type (bug #55046).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25646
diff
changeset
|
430 warning ("ignoring last %" OCTAVE_IDX_TYPE_FORMAT " columns", extras); |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
431 |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
432 Matrix tmp = tc.matrix_value (); |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
433 nr = tmp.rows (); |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
434 |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
435 for (octave_idx_type i = 0; i < nc-extras; i += 3) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
436 { |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
437 os << tmp.extract (0, i, nr-1, i+2); |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
438 if (i+3 < nc-extras) |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
439 os << "\n"; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
440 } |
4634 | 441 } |
442 else | |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
443 { |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
444 Matrix tmp = tc.matrix_value (); |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
445 nr = tmp.rows (); |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
446 |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
447 for (octave_idx_type i = 0; i < nc; i++) |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
448 { |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
449 os << tmp.extract (0, i, nr-1, i); |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
450 if (i+1 < nc) |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
451 os << "\n"; |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
452 } |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
453 } |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
454 |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
455 os.precision (old_precision); |
4634 | 456 |
26462
88dd00f48522
Fix compilation error in 73ce195bf66e.
Rik <rik@octave.org>
parents:
26460
diff
changeset
|
457 return (static_cast<bool> (os)); |
4634 | 458 } |
459 | |
5794 | 460 DEFUN (save_precision, args, nargout, |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
461 doc: /* -*- texinfo -*- |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
462 @deftypefn {} {@var{val} =} save_precision () |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
463 @deftypefnx {} {@var{old_val} =} save_precision (@var{new_val}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
464 @deftypefnx {} {} save_precision (@var{new_val}, "local") |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
465 Query or set the internal variable that specifies the number of digits to |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
466 keep when saving data in text format. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
467 |
23556
31b1ef1ee585
Fix Octave's -text format for saving data to make it lossless for IEEE-754 doubles.
Rik <rik@octave.org>
parents:
23470
diff
changeset
|
468 The default value is 17 which is the minimum necessary for the lossless saving |
31b1ef1ee585
Fix Octave's -text format for saving data to make it lossless for IEEE-754 doubles.
Rik <rik@octave.org>
parents:
23470
diff
changeset
|
469 and restoring of IEEE-754 double values; For IEEE-754 single values the minimum |
31b1ef1ee585
Fix Octave's -text format for saving data to make it lossless for IEEE-754 doubles.
Rik <rik@octave.org>
parents:
23470
diff
changeset
|
470 value is 9. If file size is a concern, it is probably better to choose a |
31b1ef1ee585
Fix Octave's -text format for saving data to make it lossless for IEEE-754 doubles.
Rik <rik@octave.org>
parents:
23470
diff
changeset
|
471 binary format for saving data rather than to reduce the precision of the saved |
31b1ef1ee585
Fix Octave's -text format for saving data to make it lossless for IEEE-754 doubles.
Rik <rik@octave.org>
parents:
23470
diff
changeset
|
472 values. |
31b1ef1ee585
Fix Octave's -text format for saving data to make it lossless for IEEE-754 doubles.
Rik <rik@octave.org>
parents:
23470
diff
changeset
|
473 |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
474 When called from inside a function with the @qcode{"local"} option, the |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
475 variable is changed locally for the function and any subroutines it calls. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
476 The original variable value is restored when exiting the function. |
23556
31b1ef1ee585
Fix Octave's -text format for saving data to make it lossless for IEEE-754 doubles.
Rik <rik@octave.org>
parents:
23470
diff
changeset
|
477 |
31b1ef1ee585
Fix Octave's -text format for saving data to make it lossless for IEEE-754 doubles.
Rik <rik@octave.org>
parents:
23470
diff
changeset
|
478 @seealso{save_default_options} |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
479 @end deftypefn */) |
4634 | 480 { |
15215
9020dddc925a
use std::numeric_limits for integer max and min values
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
481 return SET_INTERNAL_VARIABLE_WITH_LIMITS (save_precision, -1, |
9020dddc925a
use std::numeric_limits for integer max and min values
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
482 std::numeric_limits<int>::max ()); |
4634 | 483 } |