Mercurial > octave
annotate libinterp/corefcn/load-save.cc @ 23047:97a9fd0af57b stable
doc: Don't use @code in @deftypefn because it expands badly in plain text format.
* load-save.cc (Fsave): Remove @code from around "-" option. Use @qcode instead around "v1", "v2" arguments. Use commas to separate arguments in functional calling form.
* help.m: Remove @code from around "." and "--help" options.
author | Rik <rik@octave.org> |
---|---|
date | Sun, 15 Jan 2017 08:07:31 -0800 |
parents | 34ce5be04942 |
children | 6e9f4f6283b7 e9a0469dedd9 |
rev | line source |
---|---|
6763 | 1 /* |
604 | 2 |
22323
bac0d6f07a3e
maint: Update copyright notices for 2016.
John W. Eaton <jwe@octave.org>
parents:
22173
diff
changeset
|
3 Copyright (C) 1994-2016 John W. Eaton |
604 | 4 |
5 This file is part of Octave. | |
6 | |
7 Octave is free software; you can redistribute it and/or modify it | |
8 under the terms of the GNU General Public License as published by the | |
7016 | 9 Free Software Foundation; either version 3 of the License, or (at your |
10 option) any later version. | |
604 | 11 |
12 Octave is distributed in the hope that it will be useful, but WITHOUT | |
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
15 for more details. | |
16 | |
17 You should have received a copy of the GNU General Public License | |
7016 | 18 along with Octave; see the file COPYING. If not, see |
19 <http://www.gnu.org/licenses/>. | |
604 | 20 |
21 */ | |
22 | |
3911 | 23 // Author: John W. Eaton. |
24 // HDF5 support by Steven G. Johnson <stevenj@alum.mit.edu> | |
25 // Matlab v5 support by James R. Van Zandt <jrv@vanzandt.mv.com> | |
3687 | 26 |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21691
diff
changeset
|
27 #if defined (HAVE_CONFIG_H) |
21301
40de9f8f23a6
Use '#include "config.h"' rather than <config.h>.
Rik <rik@octave.org>
parents:
21200
diff
changeset
|
28 # include "config.h" |
604 | 29 #endif |
30 | |
1343 | 31 #include <cfloat> |
32 #include <cstring> | |
33 #include <cctype> | |
34 | |
4249 | 35 #include <fstream> |
3503 | 36 #include <iomanip> |
37 #include <iostream> | |
5765 | 38 #include <sstream> |
1728 | 39 #include <string> |
40 | |
1961 | 41 #include "byte-swap.h" |
42 #include "data-conv.h" | |
2926 | 43 #include "file-ops.h" |
6159 | 44 #include "file-stat.h" |
2926 | 45 #include "glob-match.h" |
2890 | 46 #include "lo-mappers.h" |
2318 | 47 #include "mach-info.h" |
3185 | 48 #include "oct-env.h" |
21888
00f1249f2483
create wrappers for some gnulib functions
John W. Eaton <jwe@octave.org>
parents:
21835
diff
changeset
|
49 #include "oct-locbuf.h" |
3258 | 50 #include "oct-time.h" |
4171 | 51 #include "quit.h" |
1755 | 52 #include "str-vec.h" |
21888
00f1249f2483
create wrappers for some gnulib functions
John W. Eaton <jwe@octave.org>
parents:
21835
diff
changeset
|
53 #include "strftime-wrapper.h" |
1755 | 54 |
4332 | 55 #include "Cell.h" |
1352 | 56 #include "defun.h" |
604 | 57 #include "error.h" |
21100
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
21040
diff
changeset
|
58 #include "errwarn.h" |
6159 | 59 #include "load-path.h" |
1352 | 60 #include "load-save.h" |
20264
bfe66db8addb
don't include hdf5.h or use HDF5 typedefs in public header files (bug #43180)
John W. Eaton <jwe@octave.org>
parents:
20232
diff
changeset
|
61 #include "oct-hdf5.h" |
20940
48b2ad5ee801
maint: Rename oct-obj.[cc|h] to ovl.[cc|h] for clarity.
Rik <rik@octave.org>
parents:
20939
diff
changeset
|
62 #include "ovl.h" |
3687 | 63 #include "oct-map.h" |
4332 | 64 #include "ov-cell.h" |
1352 | 65 #include "pager.h" |
1750 | 66 #include "pt-exp.h" |
1352 | 67 #include "symtab.h" |
68 #include "sysdep.h" | |
69 #include "unwind-prot.h" | |
604 | 70 #include "utils.h" |
2371 | 71 #include "variables.h" |
3185 | 72 #include "version.h" |
3688 | 73 #include "dMatrix.h" |
74 | |
4633 | 75 #include "ls-hdf5.h" |
76 #include "ls-mat-ascii.h" | |
77 #include "ls-mat4.h" | |
78 #include "ls-mat5.h" | |
20447
c6224b4e7774
maint: Rename instances of LS_ASCII to LS_TEXT for clarity.
Rik <rik@octave.org>
parents:
20443
diff
changeset
|
79 #include "ls-oct-text.h" |
4633 | 80 #include "ls-oct-binary.h" |
3688 | 81 |
10309 | 82 // Remove gnulib definitions, if any. |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21691
diff
changeset
|
83 #if defined (close) |
21200
fcac5dbbf9ed
maint: Indent #ifdef blocks in libinterp.
Rik <rik@octave.org>
parents:
21118
diff
changeset
|
84 # undef close |
10309 | 85 #endif |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21691
diff
changeset
|
86 #if defined (open) |
21200
fcac5dbbf9ed
maint: Indent #ifdef blocks in libinterp.
Rik <rik@octave.org>
parents:
21118
diff
changeset
|
87 # undef open |
5269 | 88 #endif |
89 | |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21691
diff
changeset
|
90 #if defined (HAVE_ZLIB) |
21200
fcac5dbbf9ed
maint: Indent #ifdef blocks in libinterp.
Rik <rik@octave.org>
parents:
21118
diff
changeset
|
91 # include "zfstream.h" |
10305
d6cdf08d0424
load-save.cc: avoid gnulib definition of close
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
92 #endif |
d6cdf08d0424
load-save.cc: avoid gnulib definition of close
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
93 |
14889
577df411e0c7
rename octave-core file to octave-workspace
John W. Eaton <jwe@octave.org>
parents:
14861
diff
changeset
|
94 // Write octave-workspace file if Octave crashes or is killed by a signal. |
5794 | 95 static bool Vcrash_dumps_octave_core = true; |
3189 | 96 |
4791 | 97 // The maximum amount of memory (in kilobytes) that we will attempt to |
98 // write to the Octave core file. | |
5794 | 99 static double Voctave_core_file_limit = -1.0; |
4791 | 100 |
101 // The name of the Octave core file. | |
14889
577df411e0c7
rename octave-core file to octave-workspace
John W. Eaton <jwe@octave.org>
parents:
14861
diff
changeset
|
102 static std::string Voctave_core_file_name = "octave-workspace"; |
4791 | 103 |
3687 | 104 // The default output format. May be one of "binary", "text", |
105 // "mat-binary", or "hdf5". | |
16875
b04ae15530fc
Rename default_save_options() to save_default_options().
Rik <rik@octave.org>
parents:
16555
diff
changeset
|
106 static std::string Vsave_default_options = "-text"; |
2194 | 107 |
5284 | 108 // The output format for Octave core files. |
5794 | 109 static std::string Voctave_core_file_options = "-binary"; |
110 | |
111 static std::string | |
112 default_save_header_format (void) | |
113 { | |
114 return | |
115 std::string ("# Created by Octave " OCTAVE_VERSION | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
116 ", %a %b %d %H:%M:%S %Y %Z <") |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21730
diff
changeset
|
117 + octave::sys::env::get_user_name () |
5794 | 118 + std::string ("@") |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21730
diff
changeset
|
119 + octave::sys::env::get_host_name () |
5794 | 120 + std::string (">"); |
121 } | |
4788 | 122 |
3709 | 123 // The format string for the comment line at the top of text-format |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14268
diff
changeset
|
124 // save files. Passed to strftime. Should begin with '#' and contain |
3709 | 125 // no newline characters. |
5794 | 126 static std::string Vsave_header_format_string = default_save_header_format (); |
3709 | 127 |
21040
3e7cfee5f786
maint: Rename attributes GCC_ATTR_XXX to OCTAVE_XXX.
Rik <rik@octave.org>
parents:
21029
diff
changeset
|
128 OCTAVE_NORETURN static |
21029
e3b3bb522d62
maint: Move GCC_ attributes to start of declaration for future compatibility.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
129 void |
21102
dfcb9d74b253
Rename local gripe_XXX functions to err_XXX or warn_XXX.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
130 err_file_open (const std::string& fcn, const std::string& file) |
5369 | 131 { |
132 if (fcn == "load") | |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14268
diff
changeset
|
133 error ("%s: unable to open input file '%s'", fcn.c_str (), file.c_str ()); |
5369 | 134 else if (fcn == "save") |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14268
diff
changeset
|
135 error ("%s: unable to open output file '%s'", fcn.c_str (), file.c_str ()); |
5369 | 136 else |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14268
diff
changeset
|
137 error ("%s: unable to open file '%s'", fcn.c_str (), file.c_str ()); |
5369 | 138 } |
139 | |
7336 | 140 // Install a variable with name NAME and the value VAL in the |
141 // symbol table. If GLOBAL is TRUE, make the variable global. | |
604 | 142 |
143 static void | |
7336 | 144 install_loaded_variable (const std::string& name, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
145 const octave_value& val, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
146 bool global, const std::string& /*doc*/) |
604 | 147 { |
148 if (global) | |
149 { | |
16442
302157614308
deprecate symbol_table::varref functions
John W. Eaton <jwe@octave.org>
parents:
15571
diff
changeset
|
150 symbol_table::clear (name); |
302157614308
deprecate symbol_table::varref functions
John W. Eaton <jwe@octave.org>
parents:
15571
diff
changeset
|
151 symbol_table::mark_global (name); |
302157614308
deprecate symbol_table::varref functions
John W. Eaton <jwe@octave.org>
parents:
15571
diff
changeset
|
152 symbol_table::global_assign (name, val); |
604 | 153 } |
154 else | |
16442
302157614308
deprecate symbol_table::varref functions
John W. Eaton <jwe@octave.org>
parents:
15571
diff
changeset
|
155 symbol_table::assign (name, val); |
604 | 156 } |
157 | |
3019 | 158 // Return TRUE if NAME matches one of the given globbing PATTERNS. |
604 | 159 |
3013 | 160 static bool |
3769 | 161 matches_patterns (const string_vector& patterns, int pat_idx, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
162 int num_pat, const std::string& name) |
604 | 163 { |
1755 | 164 for (int i = pat_idx; i < num_pat; i++) |
604 | 165 { |
1792 | 166 glob_match pattern (patterns[i]); |
3013 | 167 |
1792 | 168 if (pattern.match (name)) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
169 return true; |
604 | 170 } |
3688 | 171 |
3013 | 172 return false; |
604 | 173 } |
174 | |
4329 | 175 int |
3523 | 176 read_binary_file_header (std::istream& is, bool& swap, |
21739
c4ab2e54f100
use namespace for oct_mach_info class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
177 octave::mach_info::float_format& flt_fmt, bool quiet) |
604 | 178 { |
3552 | 179 const int magic_len = 10; |
180 char magic[magic_len+1]; | |
5760 | 181 is.read (magic, magic_len); |
604 | 182 magic[magic_len] = '\0'; |
3688 | 183 |
604 | 184 if (strncmp (magic, "Octave-1-L", magic_len) == 0) |
21739
c4ab2e54f100
use namespace for oct_mach_info class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
185 swap = octave::mach_info::words_big_endian (); |
604 | 186 else if (strncmp (magic, "Octave-1-B", magic_len) == 0) |
21739
c4ab2e54f100
use namespace for oct_mach_info class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
187 swap = ! octave::mach_info::words_big_endian (); |
604 | 188 else |
189 { | |
190 if (! quiet) | |
22173
8de49f15e182
doc: Fix "doubled words" typos (\b(\w+)\s+\1\b)
Andreas Weber <andy.weber.aw@gmail.com>
parents:
21972
diff
changeset
|
191 error ("load: unable to read binary file"); |
20831
35241c4b696c
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20801
diff
changeset
|
192 |
604 | 193 return -1; |
194 } | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
195 |
604 | 196 char tmp = 0; |
5760 | 197 is.read (&tmp, 1); |
604 | 198 |
2318 | 199 flt_fmt = mopt_digit_to_float_format (tmp); |
200 | |
21739
c4ab2e54f100
use namespace for oct_mach_info class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
201 if (flt_fmt == octave::mach_info::flt_fmt_unknown) |
604 | 202 { |
203 if (! quiet) | |
204 error ("load: unrecognized binary format!"); | |
3688 | 205 |
604 | 206 return -1; |
207 } | |
208 | |
209 return 0; | |
210 } | |
211 | |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21691
diff
changeset
|
212 #if defined (HAVE_ZLIB) |
5269 | 213 static bool |
214 check_gzip_magic (const std::string& fname) | |
215 { | |
216 bool retval = false; | |
21972
d31e0f704d0b
Open files in binary mode when testing file format (bug #48201).
Rik <rik@octave.org>
parents:
21966
diff
changeset
|
217 |
d31e0f704d0b
Open files in binary mode when testing file format (bug #48201).
Rik <rik@octave.org>
parents:
21966
diff
changeset
|
218 std::ifstream file (fname.c_str (), std::ios::in | std::ios::binary); |
5269 | 219 OCTAVE_LOCAL_BUFFER (unsigned char, magic, 2); |
220 | |
19864
17d647821d61
maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents:
19817
diff
changeset
|
221 if (file.read (reinterpret_cast<char *> (magic), 2) && magic[0] == 0x1f |
17d647821d61
maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents:
19817
diff
changeset
|
222 && magic[1] == 0x8b) |
5269 | 223 retval = true; |
224 | |
225 file.close (); | |
226 return retval; | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
227 } |
5269 | 228 #endif |
229 | |
604 | 230 static load_save_format |
6625 | 231 get_file_format (std::istream& file, const std::string& filename) |
604 | 232 { |
233 load_save_format retval = LS_UNKNOWN; | |
234 | |
21739
c4ab2e54f100
use namespace for oct_mach_info class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
235 octave::mach_info::float_format flt_fmt = octave::mach_info::flt_fmt_unknown; |
604 | 236 |
3019 | 237 bool swap = false; |
238 | |
239 if (read_binary_file_header (file, swap, flt_fmt, true) == 0) | |
604 | 240 retval = LS_BINARY; |
241 else | |
242 { | |
6202 | 243 file.clear (); |
3538 | 244 file.seekg (0, std::ios::beg); |
604 | 245 |
5828 | 246 int32_t mopt, nr, nc, imag, len; |
1180 | 247 |
16555
04fb96f4bea1
allow double-click in file browser to load data files
John W. Eaton <jwe@octave.org>
parents:
16442
diff
changeset
|
248 int err = read_mat_file_header (file, swap, mopt, nr, nc, imag, len, |
04fb96f4bea1
allow double-click in file browser to load data files
John W. Eaton <jwe@octave.org>
parents:
16442
diff
changeset
|
249 true); |
1180 | 250 |
251 if (! err) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
252 retval = LS_MAT_BINARY; |
604 | 253 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
254 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
255 file.clear (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
256 file.seekg (0, std::ios::beg); |
604 | 257 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
258 err = read_mat5_binary_file_header (file, swap, true, filename); |
3688 | 259 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
260 if (! err) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
261 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
262 file.clear (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
263 file.seekg (0, std::ios::beg); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
264 retval = LS_MAT5_BINARY; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
265 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
266 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
267 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
268 file.clear (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
269 file.seekg (0, std::ios::beg); |
3688 | 270 |
18853
9a70705dc616
Check for name and type keyword to return as an octave ascii data file (Bug #42586)
John Donoghue <john.donoghue@ieee.org>
parents:
18442
diff
changeset
|
271 std::string name_val = extract_keyword (file, "name"); |
9a70705dc616
Check for name and type keyword to return as an octave ascii data file (Bug #42586)
John Donoghue <john.donoghue@ieee.org>
parents:
18442
diff
changeset
|
272 std::string type_val = extract_keyword (file, "type"); |
4171 | 273 |
18853
9a70705dc616
Check for name and type keyword to return as an octave ascii data file (Bug #42586)
John Donoghue <john.donoghue@ieee.org>
parents:
18442
diff
changeset
|
274 if (name_val.empty () != true && type_val.empty () != true) |
20447
c6224b4e7774
maint: Rename instances of LS_ASCII to LS_TEXT for clarity.
Rik <rik@octave.org>
parents:
20443
diff
changeset
|
275 retval = LS_TEXT; |
17183
ca5103ab0b21
check_gzip_magic before get_file_format (wrong type detection, bug #39652)
Andreas Weber <andy.weber.aw@gmail.com>
parents:
17170
diff
changeset
|
276 else |
ca5103ab0b21
check_gzip_magic before get_file_format (wrong type detection, bug #39652)
Andreas Weber <andy.weber.aw@gmail.com>
parents:
17170
diff
changeset
|
277 { |
ca5103ab0b21
check_gzip_magic before get_file_format (wrong type detection, bug #39652)
Andreas Weber <andy.weber.aw@gmail.com>
parents:
17170
diff
changeset
|
278 file.clear (); |
ca5103ab0b21
check_gzip_magic before get_file_format (wrong type detection, bug #39652)
Andreas Weber <andy.weber.aw@gmail.com>
parents:
17170
diff
changeset
|
279 file.seekg (0, std::ios::beg); |
ca5103ab0b21
check_gzip_magic before get_file_format (wrong type detection, bug #39652)
Andreas Weber <andy.weber.aw@gmail.com>
parents:
17170
diff
changeset
|
280 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17755
diff
changeset
|
281 // FIXME: looks_like_mat_ascii_file does not check to see |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17755
diff
changeset
|
282 // whether the file contains numbers. It just skips comments |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17755
diff
changeset
|
283 // and checks for the same number of words on each line. We |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17755
diff
changeset
|
284 // may need a better check here. The best way to do that |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17755
diff
changeset
|
285 // might be just to try to read the file and see if it works. |
17183
ca5103ab0b21
check_gzip_magic before get_file_format (wrong type detection, bug #39652)
Andreas Weber <andy.weber.aw@gmail.com>
parents:
17170
diff
changeset
|
286 |
ca5103ab0b21
check_gzip_magic before get_file_format (wrong type detection, bug #39652)
Andreas Weber <andy.weber.aw@gmail.com>
parents:
17170
diff
changeset
|
287 if (looks_like_mat_ascii_file (file, filename)) |
ca5103ab0b21
check_gzip_magic before get_file_format (wrong type detection, bug #39652)
Andreas Weber <andy.weber.aw@gmail.com>
parents:
17170
diff
changeset
|
288 retval = LS_MAT_ASCII; |
ca5103ab0b21
check_gzip_magic before get_file_format (wrong type detection, bug #39652)
Andreas Weber <andy.weber.aw@gmail.com>
parents:
17170
diff
changeset
|
289 } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
290 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
291 } |
604 | 292 } |
293 | |
5269 | 294 return retval; |
295 } | |
5977 | 296 |
5269 | 297 static load_save_format |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
298 get_file_format (const std::string& fname, const std::string& orig_fname, |
16555
04fb96f4bea1
allow double-click in file browser to load data files
John W. Eaton <jwe@octave.org>
parents:
16442
diff
changeset
|
299 bool &use_zlib, bool quiet = false) |
5269 | 300 { |
301 load_save_format retval = LS_UNKNOWN; | |
302 | |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21691
diff
changeset
|
303 #if defined (HAVE_HDF5) |
5269 | 304 // check this before we open the file |
305 if (H5Fis_hdf5 (fname.c_str ()) > 0) | |
306 return LS_HDF5; | |
20945
9d9270e2f98f
eliminate comments after preprocessor conditionals
John W. Eaton <jwe@octave.org>
parents:
20940
diff
changeset
|
307 #endif |
604 | 308 |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21691
diff
changeset
|
309 #if defined (HAVE_ZLIB) |
17183
ca5103ab0b21
check_gzip_magic before get_file_format (wrong type detection, bug #39652)
Andreas Weber <andy.weber.aw@gmail.com>
parents:
17170
diff
changeset
|
310 use_zlib = check_gzip_magic (fname); |
ca5103ab0b21
check_gzip_magic before get_file_format (wrong type detection, bug #39652)
Andreas Weber <andy.weber.aw@gmail.com>
parents:
17170
diff
changeset
|
311 #else |
5269 | 312 use_zlib = false; |
5977 | 313 #endif |
5269 | 314 |
17183
ca5103ab0b21
check_gzip_magic before get_file_format (wrong type detection, bug #39652)
Andreas Weber <andy.weber.aw@gmail.com>
parents:
17170
diff
changeset
|
315 if (! use_zlib) |
ca5103ab0b21
check_gzip_magic before get_file_format (wrong type detection, bug #39652)
Andreas Weber <andy.weber.aw@gmail.com>
parents:
17170
diff
changeset
|
316 { |
21972
d31e0f704d0b
Open files in binary mode when testing file format (bug #48201).
Rik <rik@octave.org>
parents:
21966
diff
changeset
|
317 std::ifstream file (fname.c_str (), std::ios::in | std::ios::binary); |
17183
ca5103ab0b21
check_gzip_magic before get_file_format (wrong type detection, bug #39652)
Andreas Weber <andy.weber.aw@gmail.com>
parents:
17170
diff
changeset
|
318 if (file) |
ca5103ab0b21
check_gzip_magic before get_file_format (wrong type detection, bug #39652)
Andreas Weber <andy.weber.aw@gmail.com>
parents:
17170
diff
changeset
|
319 { |
ca5103ab0b21
check_gzip_magic before get_file_format (wrong type detection, bug #39652)
Andreas Weber <andy.weber.aw@gmail.com>
parents:
17170
diff
changeset
|
320 retval = get_file_format (file, orig_fname); |
ca5103ab0b21
check_gzip_magic before get_file_format (wrong type detection, bug #39652)
Andreas Weber <andy.weber.aw@gmail.com>
parents:
17170
diff
changeset
|
321 file.close (); |
ca5103ab0b21
check_gzip_magic before get_file_format (wrong type detection, bug #39652)
Andreas Weber <andy.weber.aw@gmail.com>
parents:
17170
diff
changeset
|
322 } |
ca5103ab0b21
check_gzip_magic before get_file_format (wrong type detection, bug #39652)
Andreas Weber <andy.weber.aw@gmail.com>
parents:
17170
diff
changeset
|
323 else if (! quiet) |
21102
dfcb9d74b253
Rename local gripe_XXX functions to err_XXX or warn_XXX.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
324 err_file_open ("load", orig_fname); |
5269 | 325 } |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21691
diff
changeset
|
326 #if defined (HAVE_ZLIB) |
17183
ca5103ab0b21
check_gzip_magic before get_file_format (wrong type detection, bug #39652)
Andreas Weber <andy.weber.aw@gmail.com>
parents:
17170
diff
changeset
|
327 else |
ca5103ab0b21
check_gzip_magic before get_file_format (wrong type detection, bug #39652)
Andreas Weber <andy.weber.aw@gmail.com>
parents:
17170
diff
changeset
|
328 { |
21972
d31e0f704d0b
Open files in binary mode when testing file format (bug #48201).
Rik <rik@octave.org>
parents:
21966
diff
changeset
|
329 gzifstream gzfile (fname.c_str (), std::ios::in | std::ios::binary); |
17183
ca5103ab0b21
check_gzip_magic before get_file_format (wrong type detection, bug #39652)
Andreas Weber <andy.weber.aw@gmail.com>
parents:
17170
diff
changeset
|
330 if (gzfile) |
ca5103ab0b21
check_gzip_magic before get_file_format (wrong type detection, bug #39652)
Andreas Weber <andy.weber.aw@gmail.com>
parents:
17170
diff
changeset
|
331 { |
ca5103ab0b21
check_gzip_magic before get_file_format (wrong type detection, bug #39652)
Andreas Weber <andy.weber.aw@gmail.com>
parents:
17170
diff
changeset
|
332 retval = get_file_format (gzfile, orig_fname); |
ca5103ab0b21
check_gzip_magic before get_file_format (wrong type detection, bug #39652)
Andreas Weber <andy.weber.aw@gmail.com>
parents:
17170
diff
changeset
|
333 gzfile.close (); |
ca5103ab0b21
check_gzip_magic before get_file_format (wrong type detection, bug #39652)
Andreas Weber <andy.weber.aw@gmail.com>
parents:
17170
diff
changeset
|
334 } |
ca5103ab0b21
check_gzip_magic before get_file_format (wrong type detection, bug #39652)
Andreas Weber <andy.weber.aw@gmail.com>
parents:
17170
diff
changeset
|
335 else if (! quiet) |
21102
dfcb9d74b253
Rename local gripe_XXX functions to err_XXX or warn_XXX.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
336 err_file_open ("load", orig_fname); |
17183
ca5103ab0b21
check_gzip_magic before get_file_format (wrong type detection, bug #39652)
Andreas Weber <andy.weber.aw@gmail.com>
parents:
17170
diff
changeset
|
337 } |
ca5103ab0b21
check_gzip_magic before get_file_format (wrong type detection, bug #39652)
Andreas Weber <andy.weber.aw@gmail.com>
parents:
17170
diff
changeset
|
338 #endif |
604 | 339 |
340 return retval; | |
341 } | |
342 | |
4329 | 343 octave_value |
7336 | 344 do_load (std::istream& stream, const std::string& orig_fname, |
21739
c4ab2e54f100
use namespace for oct_mach_info class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
345 load_save_format format, octave::mach_info::float_format flt_fmt, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
346 bool list_only, bool swap, bool verbose, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
347 const string_vector& argv, int argv_idx, int argc, int nargout) |
604 | 348 { |
3727 | 349 octave_value retval; |
350 | |
11059
4ffa19147604
replace Octave_map->octave_scalar_map in help.cc and load-save.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
10846
diff
changeset
|
351 octave_scalar_map retstruct; |
604 | 352 |
5765 | 353 std::ostringstream output_buf; |
7779
791231dac333
Add regexp matching to Fwho and Fclear
David Bateman <dbateman@free.fr>
parents:
7767
diff
changeset
|
354 std::list<std::string> symbol_names; |
4051 | 355 |
5754 | 356 octave_idx_type count = 0; |
4051 | 357 |
604 | 358 for (;;) |
359 { | |
3019 | 360 bool global = false; |
2086 | 361 octave_value tc; |
604 | 362 |
4171 | 363 std::string name; |
364 std::string doc; | |
604 | 365 |
8425
2e777f5135a3
support -tabs option for save -ascii
Jaroslav Hajek <highegg@gmail.com>
parents:
8418
diff
changeset
|
366 switch (format.type) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
367 { |
20447
c6224b4e7774
maint: Rename instances of LS_ASCII to LS_TEXT for clarity.
Rik <rik@octave.org>
parents:
20443
diff
changeset
|
368 case LS_TEXT: |
c6224b4e7774
maint: Rename instances of LS_ASCII to LS_TEXT for clarity.
Rik <rik@octave.org>
parents:
20443
diff
changeset
|
369 name = read_text_data (stream, orig_fname, global, tc, count); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
370 break; |
604 | 371 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
372 case LS_BINARY: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
373 name = read_binary_data (stream, swap, flt_fmt, orig_fname, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
374 global, tc, doc); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
375 break; |
604 | 376 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
377 case LS_MAT_ASCII: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
378 name = read_mat_ascii_data (stream, orig_fname, tc); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
379 break; |
2511 | 380 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
381 case LS_MAT_BINARY: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
382 name = read_mat_binary_data (stream, orig_fname, tc); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
383 break; |
604 | 384 |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21691
diff
changeset
|
385 #if defined (HAVE_HDF5) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
386 case LS_HDF5: |
17709
5415a9cd61d4
Implement faster partial loading of HDF5 files.
Rik <rik@octave.org>
parents:
17349
diff
changeset
|
387 name = read_hdf5_data (stream, orig_fname, global, tc, doc, |
5415a9cd61d4
Implement faster partial loading of HDF5 files.
Rik <rik@octave.org>
parents:
17349
diff
changeset
|
388 argv, argv_idx, argc); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
389 break; |
20945
9d9270e2f98f
eliminate comments after preprocessor conditionals
John W. Eaton <jwe@octave.org>
parents:
20940
diff
changeset
|
390 #endif |
3687 | 391 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
392 case LS_MAT5_BINARY: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
393 case LS_MAT7_BINARY: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
394 name = read_mat5_binary_element (stream, orig_fname, swap, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
395 global, tc); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
396 break; |
3688 | 397 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
398 default: |
21100
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
21040
diff
changeset
|
399 err_unrecognized_data_fmt ("load"); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
400 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
401 } |
604 | 402 |
20741
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20727
diff
changeset
|
403 if (stream.eof () || name.empty ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
404 break; |
20443
610c74748518
maint: Clean up code based on static analysis suggestions.
Rik <rik@octave.org>
parents:
20389
diff
changeset
|
405 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
406 { |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
407 if (! tc.is_defined ()) |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
408 error ("load: unable to load variable '%s'", name.c_str ()); |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
409 |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
410 if (format == LS_MAT_ASCII && argv_idx < argc) |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
411 warning ("load: loaded ASCII file '%s' -- ignoring extra args", |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
412 orig_fname.c_str ()); |
3136 | 413 |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
414 if (format == LS_MAT_ASCII |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
415 || argv_idx == argc |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
416 || matches_patterns (argv, argv_idx, argc, name)) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
417 { |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
418 count++; |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
419 if (list_only) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
420 { |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
421 if (verbose) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
422 { |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
423 if (count == 1) |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
424 output_buf |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
425 << "type rows cols name\n" |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
426 << "==== ==== ==== ====\n"; |
621 | 427 |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
428 output_buf |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
429 << std::setiosflags (std::ios::left) |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21739
diff
changeset
|
430 << std::setw (16) << tc.type_name ().c_str () |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
431 << std::setiosflags (std::ios::right) |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
432 << std::setw (7) << tc.rows () |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
433 << std::setw (7) << tc.columns () |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
434 << " " << name << "\n"; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
435 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
436 else |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
437 symbol_names.push_back (name); |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
438 } |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
439 else |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
440 { |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
441 if (nargout == 1) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
442 { |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
443 if (format == LS_MAT_ASCII) |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
444 retval = tc; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
445 else |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
446 retstruct.assign (name, tc); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
447 } |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
448 else |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
449 install_loaded_variable (name, tc, global, doc); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
450 } |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
451 } |
2511 | 452 |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
453 // Only attempt to read one item from a headless text file. |
2511 | 454 |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
455 if (format == LS_MAT_ASCII) |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
456 break; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
457 } |
604 | 458 } |
459 | |
621 | 460 if (list_only && count) |
461 { | |
7779
791231dac333
Add regexp matching to Fwho and Fclear
David Bateman <dbateman@free.fr>
parents:
7767
diff
changeset
|
462 if (verbose) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
463 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
464 std::string msg = output_buf.str (); |
2095 | 465 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
466 if (nargout > 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
467 retval = msg; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
468 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
469 octave_stdout << msg; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
470 } |
621 | 471 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
472 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
473 if (nargout > 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
474 retval = Cell (string_vector (symbol_names)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
475 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
476 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
477 string_vector names (symbol_names); |
7779
791231dac333
Add regexp matching to Fwho and Fclear
David Bateman <dbateman@free.fr>
parents:
7767
diff
changeset
|
478 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
479 names.list_in_columns (octave_stdout); |
7779
791231dac333
Add regexp matching to Fwho and Fclear
David Bateman <dbateman@free.fr>
parents:
7767
diff
changeset
|
480 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
481 octave_stdout << "\n"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
482 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
483 } |
621 | 484 } |
6639 | 485 else if (retstruct.nfields () != 0) |
3727 | 486 retval = retstruct; |
621 | 487 |
863 | 488 return retval; |
489 } | |
490 | |
6159 | 491 std::string |
492 find_file_to_load (const std::string& name, const std::string& orig_name) | |
493 { | |
19030
9ef10e6a5987
make "file found in path" warnings consistent
John W. Eaton <jwe@octave.org>
parents:
18949
diff
changeset
|
494 std::string fname = find_data_file_in_load_path ("load", name, true); |
6159 | 495 |
6838 | 496 size_t dot_pos = fname.rfind ("."); |
21733
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
497 size_t sep_pos = fname.find_last_of (octave::sys::file_ops::dir_sep_chars ()); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
498 |
8021 | 499 if (dot_pos == std::string::npos |
500 || (sep_pos != std::string::npos && dot_pos < sep_pos)) | |
6159 | 501 { |
6838 | 502 // Either no '.' in name or no '.' appears after last directory |
503 // separator. | |
504 | |
21736
0504351a45e6
use namespace for file_stat classes
John W. Eaton <jwe@octave.org>
parents:
21733
diff
changeset
|
505 octave::sys::file_stat fs (fname); |
6159 | 506 |
6584 | 507 if (! (fs.exists () && fs.is_reg ())) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
508 fname = find_file_to_load (fname + ".mat", orig_name); |
6159 | 509 } |
510 else | |
511 { | |
21736
0504351a45e6
use namespace for file_stat classes
John W. Eaton <jwe@octave.org>
parents:
21733
diff
changeset
|
512 octave::sys::file_stat fs (fname); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
513 |
6584 | 514 if (! (fs.exists () && fs.is_reg ())) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
515 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
516 fname = ""; |
6159 | 517 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
518 error ("load: unable to find file %s", orig_name.c_str ()); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
519 } |
6159 | 520 } |
521 | |
522 return fname; | |
523 } | |
524 | |
16555
04fb96f4bea1
allow double-click in file browser to load data files
John W. Eaton <jwe@octave.org>
parents:
16442
diff
changeset
|
525 bool |
04fb96f4bea1
allow double-click in file browser to load data files
John W. Eaton <jwe@octave.org>
parents:
16442
diff
changeset
|
526 is_octave_data_file (const std::string& fname) |
04fb96f4bea1
allow double-click in file browser to load data files
John W. Eaton <jwe@octave.org>
parents:
16442
diff
changeset
|
527 { |
04fb96f4bea1
allow double-click in file browser to load data files
John W. Eaton <jwe@octave.org>
parents:
16442
diff
changeset
|
528 bool use_zlib = false; |
04fb96f4bea1
allow double-click in file browser to load data files
John W. Eaton <jwe@octave.org>
parents:
16442
diff
changeset
|
529 return get_file_format (fname, fname, use_zlib, true) != LS_UNKNOWN; |
04fb96f4bea1
allow double-click in file browser to load data files
John W. Eaton <jwe@octave.org>
parents:
16442
diff
changeset
|
530 } |
6159 | 531 |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8676
diff
changeset
|
532 DEFUN (load, args, nargout, |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
533 doc: /* -*- texinfo -*- |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
534 @deftypefn {} {} load file |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
535 @deftypefnx {} {} load options file |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
536 @deftypefnx {} {} load options file v1 v2 @dots{} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
537 @deftypefnx {} {S =} load ("options", "file", "v1", "v2", @dots{}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
538 @deftypefnx {} {} load file options |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
539 @deftypefnx {} {} load file options v1 v2 @dots{} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
540 @deftypefnx {} {S =} load ("file", "options", "v1", "v2", @dots{}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
541 Load the named variables @var{v1}, @var{v2}, @dots{}, from the file |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
542 @var{file}. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
543 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
544 If no variables are specified then all variables found in the |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
545 file will be loaded. As with @code{save}, the list of variables to extract |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
546 can be full names or use a pattern syntax. The format of the file is |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
547 automatically detected but may be overridden by supplying the appropriate |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
548 option. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
549 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
550 If load is invoked using the functional form |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
551 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
552 @example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
553 load ("-option1", @dots{}, "file", "v1", @dots{}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
554 @end example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
555 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
556 @noindent |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
557 then the @var{options}, @var{file}, and variable name arguments |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
558 (@var{v1}, @dots{}) must be specified as character strings. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
559 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
560 If a variable that is not marked as global is loaded from a file when a |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
561 global symbol with the same name already exists, it is loaded in the |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
562 global symbol table. Also, if a variable is marked as global in a file |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
563 and a local symbol exists, the local symbol is moved to the global |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
564 symbol table and given the value from the file. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
565 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
566 If invoked with a single output argument, Octave returns data instead |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
567 of inserting variables in the symbol table. If the data file contains |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
568 only numbers (TAB- or space-delimited columns), a matrix of values is |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
569 returned. Otherwise, @code{load} returns a structure with members |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
570 corresponding to the names of the variables in the file. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
571 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
572 The @code{load} command can read data stored in Octave's text and |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
573 binary formats, and @sc{matlab}'s binary format. If compiled with zlib |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
574 support, it can also load gzip-compressed files. It will automatically |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
575 detect the type of file and do conversion from different floating point |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
576 formats (currently only IEEE big and little endian, though other formats |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
577 may be added in the future). |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
578 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
579 Valid options for @code{load} are listed in the following table. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
580 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
581 @table @code |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
582 @item -force |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
583 This option is accepted for backward compatibility but is ignored. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
584 Octave now overwrites variables currently in memory with |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
585 those of the same name found in the file. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
586 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
587 @item -ascii |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
588 Force Octave to assume the file contains columns of numbers in text format |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
589 without any header or other information. Data in the file will be loaded |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
590 as a single numeric matrix with the name of the variable derived from the |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
591 name of the file. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
592 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
593 @item -binary |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
594 Force Octave to assume the file is in Octave's binary format. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
595 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
596 @item -hdf5 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
597 Force Octave to assume the file is in @sc{hdf5} format. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
598 (@sc{hdf5} is a free, portable binary format developed by the National |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
599 Center for Supercomputing Applications at the University of Illinois.) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
600 Note that Octave can read @sc{hdf5} files not created by itself, but may |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
601 skip some datasets in formats that it cannot support. This format is |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
602 only available if Octave was built with a link to the @sc{hdf5} libraries. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
603 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
604 @item -import |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
605 This option is accepted for backward compatibility but is ignored. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
606 Octave can now support multi-dimensional HDF data and automatically |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
607 modifies variable names if they are invalid Octave identifiers. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
608 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
609 @item -mat |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
610 @itemx -mat-binary |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
611 @itemx -6 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
612 @itemx -v6 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
613 @itemx -7 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
614 @itemx -v7 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
615 Force Octave to assume the file is in @sc{matlab}'s version 6 or 7 binary |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
616 format. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
617 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
618 @item -mat4-binary |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
619 @itemx -4 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
620 @itemx -v4 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
621 @itemx -V4 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
622 Force Octave to assume the file is in the binary format written by |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
623 @sc{matlab} version 4. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
624 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
625 @item -text |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
626 Force Octave to assume the file is in Octave's text format. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
627 @end table |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
628 @seealso{save, dlmwrite, csvwrite, fwrite} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
629 @end deftypefn */) |
863 | 630 { |
2086 | 631 octave_value_list retval; |
863 | 632 |
1755 | 633 int argc = args.length () + 1; |
634 | |
1968 | 635 string_vector argv = args.make_argv ("load"); |
1755 | 636 |
12895
8edece28cf4d
Allow Matlab-style syntax for load command (Bug #33527).
Rik <octave@nomad.inbox5.com>
parents:
12661
diff
changeset
|
637 int i = 1; |
8edece28cf4d
Allow Matlab-style syntax for load command (Bug #33527).
Rik <octave@nomad.inbox5.com>
parents:
12661
diff
changeset
|
638 std::string orig_fname = ""; |
8edece28cf4d
Allow Matlab-style syntax for load command (Bug #33527).
Rik <octave@nomad.inbox5.com>
parents:
12661
diff
changeset
|
639 |
8edece28cf4d
Allow Matlab-style syntax for load command (Bug #33527).
Rik <octave@nomad.inbox5.com>
parents:
12661
diff
changeset
|
640 // Function called with Matlab-style ["filename", options] syntax |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14366
diff
changeset
|
641 if (argc > 1 && ! argv[1].empty () && argv[1].at (0) != '-') |
12895
8edece28cf4d
Allow Matlab-style syntax for load command (Bug #33527).
Rik <octave@nomad.inbox5.com>
parents:
12661
diff
changeset
|
642 { |
8edece28cf4d
Allow Matlab-style syntax for load command (Bug #33527).
Rik <octave@nomad.inbox5.com>
parents:
12661
diff
changeset
|
643 orig_fname = argv[1]; |
8edece28cf4d
Allow Matlab-style syntax for load command (Bug #33527).
Rik <octave@nomad.inbox5.com>
parents:
12661
diff
changeset
|
644 i++; |
8edece28cf4d
Allow Matlab-style syntax for load command (Bug #33527).
Rik <octave@nomad.inbox5.com>
parents:
12661
diff
changeset
|
645 } |
8edece28cf4d
Allow Matlab-style syntax for load command (Bug #33527).
Rik <octave@nomad.inbox5.com>
parents:
12661
diff
changeset
|
646 |
1358 | 647 // It isn't necessary to have the default load format stored in a |
648 // user preference variable since we can determine the type of file | |
649 // as we are reading. | |
863 | 650 |
651 load_save_format format = LS_UNKNOWN; | |
652 | |
3019 | 653 bool list_only = false; |
654 bool verbose = false; | |
863 | 655 |
13026
9a2a6054460f
maint: Fix 2 compiler warnings
Rik <octave@nomad.inbox5.com>
parents:
12895
diff
changeset
|
656 for (; i < argc; i++) |
863 | 657 { |
1755 | 658 if (argv[i] == "-force" || argv[i] == "-f") |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
659 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
660 // Silently ignore this |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
661 // warning ("load: -force ignored"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
662 } |
1755 | 663 else if (argv[i] == "-list" || argv[i] == "-l") |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
664 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
665 list_only = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
666 } |
1755 | 667 else if (argv[i] == "-verbose" || argv[i] == "-v") |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
668 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
669 verbose = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
670 } |
1755 | 671 else if (argv[i] == "-ascii" || argv[i] == "-a") |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
672 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
673 format = LS_MAT_ASCII; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
674 } |
1755 | 675 else if (argv[i] == "-binary" || argv[i] == "-b") |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
676 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
677 format = LS_BINARY; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
678 } |
5269 | 679 else if (argv[i] == "-mat-binary" || argv[i] == "-mat" || argv[i] == "-m" |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
680 || argv[i] == "-6" || argv[i] == "-v6") |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
681 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
682 format = LS_MAT5_BINARY; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
683 } |
7819
b7e8ea6a5143
trivial fix option in Fload
Jaroslav Hajek <highegg@gmail.com>
parents:
7779
diff
changeset
|
684 else if (argv[i] == "-7" || argv[i] == "-v7") |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
685 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
686 format = LS_MAT7_BINARY; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
687 } |
5256 | 688 else if (argv[i] == "-mat4-binary" || argv[i] == "-V4" |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
689 || argv[i] == "-v4" || argv[i] == "-4") |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
690 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
691 format = LS_MAT_BINARY; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
692 } |
3687 | 693 else if (argv[i] == "-hdf5" || argv[i] == "-h") |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
694 { |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21691
diff
changeset
|
695 #if defined (HAVE_HDF5) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
696 format = LS_HDF5; |
20945
9d9270e2f98f
eliminate comments after preprocessor conditionals
John W. Eaton <jwe@octave.org>
parents:
20940
diff
changeset
|
697 #else |
21109
bd1752782e56
Use err_disabled_feature, warn_disabled_feature throughout code base.
Rik <rik@octave.org>
parents:
21102
diff
changeset
|
698 err_disabled_feature ("load", "HDF5"); |
20945
9d9270e2f98f
eliminate comments after preprocessor conditionals
John W. Eaton <jwe@octave.org>
parents:
20940
diff
changeset
|
699 #endif |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
700 } |
3687 | 701 else if (argv[i] == "-import" || argv[i] == "-i") |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
702 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
703 warning ("load: -import ignored"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
704 } |
5197 | 705 else if (argv[i] == "-text" || argv[i] == "-t") |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
706 { |
20447
c6224b4e7774
maint: Rename instances of LS_ASCII to LS_TEXT for clarity.
Rik <rik@octave.org>
parents:
20443
diff
changeset
|
707 format = LS_TEXT; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
708 } |
863 | 709 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
710 break; |
863 | 711 } |
712 | |
12895
8edece28cf4d
Allow Matlab-style syntax for load command (Bug #33527).
Rik <octave@nomad.inbox5.com>
parents:
12661
diff
changeset
|
713 if (orig_fname == "") |
863 | 714 { |
12895
8edece28cf4d
Allow Matlab-style syntax for load command (Bug #33527).
Rik <octave@nomad.inbox5.com>
parents:
12661
diff
changeset
|
715 if (i == argc) |
20801
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20741
diff
changeset
|
716 print_usage (); |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20741
diff
changeset
|
717 |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20741
diff
changeset
|
718 orig_fname = argv[i]; |
863 | 719 } |
12895
8edece28cf4d
Allow Matlab-style syntax for load command (Bug #33527).
Rik <octave@nomad.inbox5.com>
parents:
12661
diff
changeset
|
720 else |
8edece28cf4d
Allow Matlab-style syntax for load command (Bug #33527).
Rik <octave@nomad.inbox5.com>
parents:
12661
diff
changeset
|
721 i--; |
863 | 722 |
21739
c4ab2e54f100
use namespace for oct_mach_info class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
723 octave::mach_info::float_format flt_fmt = octave::mach_info::flt_fmt_unknown; |
863 | 724 |
3019 | 725 bool swap = false; |
863 | 726 |
12895
8edece28cf4d
Allow Matlab-style syntax for load command (Bug #33527).
Rik <octave@nomad.inbox5.com>
parents:
12661
diff
changeset
|
727 if (orig_fname == "-") |
863 | 728 { |
1755 | 729 i++; |
863 | 730 |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21691
diff
changeset
|
731 #if defined (HAVE_HDF5) |
3687 | 732 if (format == LS_HDF5) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
733 error ("load: cannot read HDF5 format from stdin"); |
3687 | 734 else |
20945
9d9270e2f98f
eliminate comments after preprocessor conditionals
John W. Eaton <jwe@octave.org>
parents:
20940
diff
changeset
|
735 #endif |
863 | 736 if (format != LS_UNKNOWN) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
737 { |
17861
870f3e12e163
maint: Use phrase "FIXME:" for problem areas in code.
Rik <rik@octave.org>
parents:
17787
diff
changeset
|
738 // FIXME: if we have already seen EOF on a previous call, |
870f3e12e163
maint: Use phrase "FIXME:" for problem areas in code.
Rik <rik@octave.org>
parents:
17787
diff
changeset
|
739 // how do we fix up the state of std::cin so that we can get |
870f3e12e163
maint: Use phrase "FIXME:" for problem areas in code.
Rik <rik@octave.org>
parents:
17787
diff
changeset
|
740 // additional input? I'm afraid that we can't fix this |
870f3e12e163
maint: Use phrase "FIXME:" for problem areas in code.
Rik <rik@octave.org>
parents:
17787
diff
changeset
|
741 // using std::cin only. |
3531 | 742 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
743 retval = do_load (std::cin, orig_fname, format, flt_fmt, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
744 list_only, swap, verbose, argv, i, argc, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
745 nargout); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
746 } |
863 | 747 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
748 error ("load: must specify file format if reading from stdin"); |
863 | 749 } |
750 else | |
751 { | |
21733
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
752 std::string fname = octave::sys::file_ops::tilde_expand (orig_fname); |
6159 | 753 |
754 fname = find_file_to_load (fname, orig_fname); | |
863 | 755 |
6159 | 756 bool use_zlib = false; |
5089 | 757 |
863 | 758 if (format == LS_UNKNOWN) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
759 format = get_file_format (fname, orig_fname, use_zlib); |
863 | 760 |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21691
diff
changeset
|
761 #if defined (HAVE_HDF5) |
3687 | 762 if (format == LS_HDF5) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
763 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
764 i++; |
3687 | 765 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
766 hdf5_ifstream hdf5_file (fname.c_str ()); |
3687 | 767 |
21118
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21109
diff
changeset
|
768 if (hdf5_file.file_id < 0) |
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21109
diff
changeset
|
769 err_file_open ("load", orig_fname); |
4844 | 770 |
21118
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21109
diff
changeset
|
771 retval = do_load (hdf5_file, orig_fname, format, |
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21109
diff
changeset
|
772 flt_fmt, list_only, swap, verbose, |
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21109
diff
changeset
|
773 argv, i, argc, nargout); |
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21109
diff
changeset
|
774 |
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21109
diff
changeset
|
775 hdf5_file.close (); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
776 } |
3687 | 777 else |
20945
9d9270e2f98f
eliminate comments after preprocessor conditionals
John W. Eaton <jwe@octave.org>
parents:
20940
diff
changeset
|
778 #endif |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
779 // don't insert any statements here; the "else" above has to |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
780 // go with the "if" below!!!!! |
863 | 781 if (format != LS_UNKNOWN) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
782 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
783 i++; |
863 | 784 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
785 // Always open in binary mode and handle various |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
786 // line-endings explicitly. |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
787 std::ios::openmode mode = std::ios::in | std::ios::binary; |
863 | 788 |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21691
diff
changeset
|
789 #if defined (HAVE_ZLIB) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
790 if (use_zlib) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
791 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
792 gzifstream file (fname.c_str (), mode); |
863 | 793 |
21118
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21109
diff
changeset
|
794 if (! file) |
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21109
diff
changeset
|
795 err_file_open ("load", orig_fname); |
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21109
diff
changeset
|
796 |
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21109
diff
changeset
|
797 if (format == LS_BINARY) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
798 { |
21118
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21109
diff
changeset
|
799 if (read_binary_file_header (file, swap, flt_fmt) < 0) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
800 { |
21118
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21109
diff
changeset
|
801 if (file) file.close (); |
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21109
diff
changeset
|
802 return retval; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
803 } |
21118
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21109
diff
changeset
|
804 } |
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21109
diff
changeset
|
805 else if (format == LS_MAT5_BINARY |
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21109
diff
changeset
|
806 || format == LS_MAT7_BINARY) |
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21109
diff
changeset
|
807 { |
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21109
diff
changeset
|
808 if (read_mat5_binary_file_header (file, swap, false, |
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21109
diff
changeset
|
809 orig_fname) < 0) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
810 { |
21118
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21109
diff
changeset
|
811 if (file) file.close (); |
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21109
diff
changeset
|
812 return retval; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
813 } |
21118
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21109
diff
changeset
|
814 } |
5269 | 815 |
21118
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21109
diff
changeset
|
816 retval = do_load (file, orig_fname, format, |
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21109
diff
changeset
|
817 flt_fmt, list_only, swap, verbose, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
818 argv, i, argc, nargout); |
5269 | 819 |
21118
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21109
diff
changeset
|
820 file.close (); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
821 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
822 else |
5269 | 823 #endif |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
824 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
825 std::ifstream file (fname.c_str (), mode); |
5269 | 826 |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
827 if (! file) |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14268
diff
changeset
|
828 error ("load: unable to open input file '%s'", |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
829 orig_fname.c_str ()); |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
830 |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
831 if (format == LS_BINARY) |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
832 { |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
833 if (read_binary_file_header (file, swap, flt_fmt) < 0) |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
834 { |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
835 if (file) file.close (); |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
836 return retval; |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
837 } |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
838 } |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
839 else if (format == LS_MAT5_BINARY |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
840 || format == LS_MAT7_BINARY) |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
841 { |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
842 if (read_mat5_binary_file_header (file, swap, false, |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
843 orig_fname) < 0) |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
844 { |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
845 if (file) file.close (); |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
846 return retval; |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
847 } |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
848 } |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
849 |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
850 retval = do_load (file, orig_fname, format, |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
851 flt_fmt, list_only, swap, verbose, |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
852 argv, i, argc, nargout); |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
853 |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
854 file.close (); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
855 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
856 } |
19387
616f2b22787b
Issue error if load file format cannot be determined (bug #43575).
Rik <rik@octave.org>
parents:
18853
diff
changeset
|
857 else |
20956
850e3d2533d4
maint: Eliminate more useless statements after error().
Rik <rik@octave.org>
parents:
20945
diff
changeset
|
858 error ("load: unable to determine file format of '%s'", |
850e3d2533d4
maint: Eliminate more useless statements after error().
Rik <rik@octave.org>
parents:
20945
diff
changeset
|
859 orig_fname.c_str ()); |
850e3d2533d4
maint: Eliminate more useless statements after error().
Rik <rik@octave.org>
parents:
20945
diff
changeset
|
860 |
863 | 861 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
862 |
604 | 863 return retval; |
864 } | |
865 | |
3019 | 866 // Return TRUE if PATTERN has any special globbing chars in it. |
867 | |
868 static bool | |
3523 | 869 glob_pattern_p (const std::string& pattern) |
604 | 870 { |
871 int open = 0; | |
872 | |
1755 | 873 int len = pattern.length (); |
874 | |
875 for (int i = 0; i < len; i++) | |
604 | 876 { |
1755 | 877 char c = pattern[i]; |
878 | |
604 | 879 switch (c) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
880 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
881 case '?': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
882 case '*': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
883 return true; |
604 | 884 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
885 case '[': // Only accept an open brace if there is a close |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
886 open++; // brace to match it. Bracket expressions must be |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
887 continue; // complete, according to Posix.2 |
604 | 888 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
889 case ']': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
890 if (open) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
891 return true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
892 continue; |
4402 | 893 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
894 case '\\': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
895 if (i == len - 1) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
896 return false; |
604 | 897 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
898 default: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
899 continue; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
900 } |
604 | 901 } |
902 | |
3019 | 903 return false; |
604 | 904 } |
905 | |
4791 | 906 static void |
907 do_save (std::ostream& os, const octave_value& tc, | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
908 const std::string& name, const std::string& help, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
909 bool global, load_save_format fmt, bool save_as_floats) |
604 | 910 { |
8425
2e777f5135a3
support -tabs option for save -ascii
Jaroslav Hajek <highegg@gmail.com>
parents:
8418
diff
changeset
|
911 switch (fmt.type) |
604 | 912 { |
20447
c6224b4e7774
maint: Rename instances of LS_ASCII to LS_TEXT for clarity.
Rik <rik@octave.org>
parents:
20443
diff
changeset
|
913 case LS_TEXT: |
c6224b4e7774
maint: Rename instances of LS_ASCII to LS_TEXT for clarity.
Rik <rik@octave.org>
parents:
20443
diff
changeset
|
914 save_text_data (os, tc, name, global, 0); |
604 | 915 break; |
916 | |
917 case LS_BINARY: | |
630 | 918 save_binary_data (os, tc, name, help, global, save_as_floats); |
604 | 919 break; |
920 | |
5938 | 921 case LS_MAT_ASCII: |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
922 if (! save_mat_ascii_data (os, tc, fmt.opts & LS_MAT_ASCII_LONG ? 16 : 8, |
8425
2e777f5135a3
support -tabs option for save -ascii
Jaroslav Hajek <highegg@gmail.com>
parents:
8418
diff
changeset
|
923 fmt.opts & LS_MAT_ASCII_TABS)) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
924 warning ("save: unable to save %s in ASCII format", name.c_str ()); |
5938 | 925 break; |
926 | |
667 | 927 case LS_MAT_BINARY: |
928 save_mat_binary_data (os, tc, name); | |
929 break; | |
930 | |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21691
diff
changeset
|
931 #if defined (HAVE_HDF5) |
3687 | 932 case LS_HDF5: |
933 save_hdf5_data (os, tc, name, help, global, save_as_floats); | |
934 break; | |
20945
9d9270e2f98f
eliminate comments after preprocessor conditionals
John W. Eaton <jwe@octave.org>
parents:
20940
diff
changeset
|
935 #endif |
3687 | 936 |
3688 | 937 case LS_MAT5_BINARY: |
5269 | 938 save_mat5_binary_element (os, tc, name, global, false, save_as_floats); |
939 break; | |
940 | |
941 case LS_MAT7_BINARY: | |
942 save_mat5_binary_element (os, tc, name, global, true, save_as_floats); | |
3688 | 943 break; |
944 | |
604 | 945 default: |
21100
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
21040
diff
changeset
|
946 err_unrecognized_data_fmt ("save"); |
604 | 947 break; |
948 } | |
949 } | |
950 | |
4791 | 951 // Save the info from SR on stream OS in the format specified by FMT. |
952 | |
953 void | |
7336 | 954 do_save (std::ostream& os, const symbol_table::symbol_record& sr, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
955 load_save_format fmt, bool save_as_floats) |
4791 | 956 { |
7336 | 957 octave_value val = sr.varval (); |
4791 | 958 |
7336 | 959 if (val.is_defined ()) |
4791 | 960 { |
7336 | 961 std::string name = sr.name (); |
962 std::string help; | |
963 bool global = sr.is_global (); | |
4791 | 964 |
7336 | 965 do_save (os, val, name, help, global, fmt, save_as_floats); |
4791 | 966 } |
967 } | |
968 | |
7635
ba7a3e20ee3d
add -struct modifier to save
Jaroslav Hajek <highegg@gmail.com>
parents:
7336
diff
changeset
|
969 // save fields of a scalar structure STR matching PATTERN on stream OS |
ba7a3e20ee3d
add -struct modifier to save
Jaroslav Hajek <highegg@gmail.com>
parents:
7336
diff
changeset
|
970 // in the format specified by FMT. |
ba7a3e20ee3d
add -struct modifier to save
Jaroslav Hajek <highegg@gmail.com>
parents:
7336
diff
changeset
|
971 |
ba7a3e20ee3d
add -struct modifier to save
Jaroslav Hajek <highegg@gmail.com>
parents:
7336
diff
changeset
|
972 static size_t |
11059
4ffa19147604
replace Octave_map->octave_scalar_map in help.cc and load-save.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
10846
diff
changeset
|
973 save_fields (std::ostream& os, const octave_scalar_map& m, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
974 const std::string& pattern, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
975 load_save_format fmt, bool save_as_floats) |
7635
ba7a3e20ee3d
add -struct modifier to save
Jaroslav Hajek <highegg@gmail.com>
parents:
7336
diff
changeset
|
976 { |
ba7a3e20ee3d
add -struct modifier to save
Jaroslav Hajek <highegg@gmail.com>
parents:
7336
diff
changeset
|
977 glob_match pat (pattern); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
978 |
7635
ba7a3e20ee3d
add -struct modifier to save
Jaroslav Hajek <highegg@gmail.com>
parents:
7336
diff
changeset
|
979 size_t saved = 0; |
ba7a3e20ee3d
add -struct modifier to save
Jaroslav Hajek <highegg@gmail.com>
parents:
7336
diff
changeset
|
980 |
11059
4ffa19147604
replace Octave_map->octave_scalar_map in help.cc and load-save.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
10846
diff
changeset
|
981 for (octave_scalar_map::const_iterator p = m.begin (); p != m.end (); p++) |
7635
ba7a3e20ee3d
add -struct modifier to save
Jaroslav Hajek <highegg@gmail.com>
parents:
7336
diff
changeset
|
982 { |
ba7a3e20ee3d
add -struct modifier to save
Jaroslav Hajek <highegg@gmail.com>
parents:
7336
diff
changeset
|
983 std::string empty_str; |
ba7a3e20ee3d
add -struct modifier to save
Jaroslav Hajek <highegg@gmail.com>
parents:
7336
diff
changeset
|
984 |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14366
diff
changeset
|
985 if (pat.match (m.key (p))) |
7635
ba7a3e20ee3d
add -struct modifier to save
Jaroslav Hajek <highegg@gmail.com>
parents:
7336
diff
changeset
|
986 { |
11059
4ffa19147604
replace Octave_map->octave_scalar_map in help.cc and load-save.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
10846
diff
changeset
|
987 do_save (os, m.contents (p), m.key (p), empty_str, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
988 0, fmt, save_as_floats); |
7635
ba7a3e20ee3d
add -struct modifier to save
Jaroslav Hajek <highegg@gmail.com>
parents:
7336
diff
changeset
|
989 |
ba7a3e20ee3d
add -struct modifier to save
Jaroslav Hajek <highegg@gmail.com>
parents:
7336
diff
changeset
|
990 saved++; |
ba7a3e20ee3d
add -struct modifier to save
Jaroslav Hajek <highegg@gmail.com>
parents:
7336
diff
changeset
|
991 } |
ba7a3e20ee3d
add -struct modifier to save
Jaroslav Hajek <highegg@gmail.com>
parents:
7336
diff
changeset
|
992 } |
ba7a3e20ee3d
add -struct modifier to save
Jaroslav Hajek <highegg@gmail.com>
parents:
7336
diff
changeset
|
993 |
ba7a3e20ee3d
add -struct modifier to save
Jaroslav Hajek <highegg@gmail.com>
parents:
7336
diff
changeset
|
994 return saved; |
ba7a3e20ee3d
add -struct modifier to save
Jaroslav Hajek <highegg@gmail.com>
parents:
7336
diff
changeset
|
995 } |
ba7a3e20ee3d
add -struct modifier to save
Jaroslav Hajek <highegg@gmail.com>
parents:
7336
diff
changeset
|
996 |
604 | 997 // Save variables with names matching PATTERN on stream OS in the |
5794 | 998 // format specified by FMT. |
604 | 999 |
7336 | 1000 static size_t |
5794 | 1001 save_vars (std::ostream& os, const std::string& pattern, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1002 load_save_format fmt, bool save_as_floats) |
604 | 1003 { |
7336 | 1004 std::list<symbol_table::symbol_record> vars = symbol_table::glob (pattern); |
1005 | |
1006 size_t saved = 0; | |
3355 | 1007 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17755
diff
changeset
|
1008 typedef std::list<symbol_table::symbol_record>::const_iterator |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17755
diff
changeset
|
1009 const_vars_iterator; |
3355 | 1010 |
7336 | 1011 for (const_vars_iterator p = vars.begin (); p != vars.end (); p++) |
620 | 1012 { |
7336 | 1013 do_save (os, *p, fmt, save_as_floats); |
620 | 1014 |
7336 | 1015 saved++; |
620 | 1016 } |
604 | 1017 |
1018 return saved; | |
1019 } | |
1020 | |
8034
f61bd8e0d682
fix default_save_options parsing and allow mixing options with other arguments.
Jaroslav Hajek <highegg@gmail.com>
parents:
8021
diff
changeset
|
1021 static string_vector |
f61bd8e0d682
fix default_save_options parsing and allow mixing options with other arguments.
Jaroslav Hajek <highegg@gmail.com>
parents:
8021
diff
changeset
|
1022 parse_save_options (const string_vector &argv, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1023 load_save_format &format, bool &append, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1024 bool &save_as_floats, bool &use_zlib) |
604 | 1025 { |
21691
263d18409fdf
Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents:
21568
diff
changeset
|
1026 #if ! defined (HAVE_ZLIB) |
263d18409fdf
Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents:
21568
diff
changeset
|
1027 octave_unused_parameter (use_zlib); |
263d18409fdf
Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents:
21568
diff
changeset
|
1028 #endif |
263d18409fdf
Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents:
21568
diff
changeset
|
1029 |
8034
f61bd8e0d682
fix default_save_options parsing and allow mixing options with other arguments.
Jaroslav Hajek <highegg@gmail.com>
parents:
8021
diff
changeset
|
1030 string_vector retval; |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20172
diff
changeset
|
1031 int argc = argv.numel (); |
8034
f61bd8e0d682
fix default_save_options parsing and allow mixing options with other arguments.
Jaroslav Hajek <highegg@gmail.com>
parents:
8021
diff
changeset
|
1032 |
18100
6a71e5030df5
Follow coding convention of defining and initializing only 1 variable per line in liboctinterp.
Rik <rik@octave.org>
parents:
17861
diff
changeset
|
1033 bool do_double = false; |
6a71e5030df5
Follow coding convention of defining and initializing only 1 variable per line in liboctinterp.
Rik <rik@octave.org>
parents:
17861
diff
changeset
|
1034 bool do_tabs = false; |
8418
679c22082ac7
handle -double option for save
John W. Eaton <jwe@octave.org>
parents:
8377
diff
changeset
|
1035 |
8034
f61bd8e0d682
fix default_save_options parsing and allow mixing options with other arguments.
Jaroslav Hajek <highegg@gmail.com>
parents:
8021
diff
changeset
|
1036 for (int i = 0; i < argc; i++) |
5284 | 1037 { |
1038 if (argv[i] == "-append") | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1039 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1040 append = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1041 } |
5284 | 1042 else if (argv[i] == "-ascii" || argv[i] == "-a") |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1043 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1044 format = LS_MAT_ASCII; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1045 } |
8418
679c22082ac7
handle -double option for save
John W. Eaton <jwe@octave.org>
parents:
8377
diff
changeset
|
1046 else if (argv[i] == "-double") |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1047 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1048 do_double = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1049 } |
8425
2e777f5135a3
support -tabs option for save -ascii
Jaroslav Hajek <highegg@gmail.com>
parents:
8418
diff
changeset
|
1050 else if (argv[i] == "-tabs") |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1051 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1052 do_tabs = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1053 } |
5284 | 1054 else if (argv[i] == "-text" || argv[i] == "-t") |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1055 { |
20447
c6224b4e7774
maint: Rename instances of LS_ASCII to LS_TEXT for clarity.
Rik <rik@octave.org>
parents:
20443
diff
changeset
|
1056 format = LS_TEXT; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1057 } |
5284 | 1058 else if (argv[i] == "-binary" || argv[i] == "-b") |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1059 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1060 format = LS_BINARY; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1061 } |
5284 | 1062 else if (argv[i] == "-hdf5" || argv[i] == "-h") |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1063 { |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21691
diff
changeset
|
1064 #if defined (HAVE_HDF5) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1065 format = LS_HDF5; |
20945
9d9270e2f98f
eliminate comments after preprocessor conditionals
John W. Eaton <jwe@octave.org>
parents:
20940
diff
changeset
|
1066 #else |
21109
bd1752782e56
Use err_disabled_feature, warn_disabled_feature throughout code base.
Rik <rik@octave.org>
parents:
21102
diff
changeset
|
1067 err_disabled_feature ("save", "HDF5"); |
20945
9d9270e2f98f
eliminate comments after preprocessor conditionals
John W. Eaton <jwe@octave.org>
parents:
20940
diff
changeset
|
1068 #endif |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1069 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
1070 else if (argv[i] == "-mat-binary" || argv[i] == "-mat" |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1071 || argv[i] == "-m" || argv[i] == "-6" || argv[i] == "-v6" |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1072 || argv[i] == "-V6") |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1073 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1074 format = LS_MAT5_BINARY; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1075 } |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21691
diff
changeset
|
1076 #if defined (HAVE_ZLIB) |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
1077 else if (argv[i] == "-mat7-binary" || argv[i] == "-7" |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1078 || argv[i] == "-v7" || argv[i] == "-V7") |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1079 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1080 format = LS_MAT7_BINARY; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1081 } |
5284 | 1082 #endif |
1083 else if (argv[i] == "-mat4-binary" || argv[i] == "-V4" | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1084 || argv[i] == "-v4" || argv[i] == "-4") |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1085 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1086 format = LS_MAT_BINARY; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1087 } |
5284 | 1088 else if (argv[i] == "-float-binary" || argv[i] == "-f") |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1089 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1090 format = LS_BINARY; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1091 save_as_floats = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1092 } |
5284 | 1093 else if (argv[i] == "-float-hdf5") |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1094 { |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21691
diff
changeset
|
1095 #if defined (HAVE_HDF5) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1096 format = LS_HDF5; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1097 save_as_floats = true; |
20945
9d9270e2f98f
eliminate comments after preprocessor conditionals
John W. Eaton <jwe@octave.org>
parents:
20940
diff
changeset
|
1098 #else |
21109
bd1752782e56
Use err_disabled_feature, warn_disabled_feature throughout code base.
Rik <rik@octave.org>
parents:
21102
diff
changeset
|
1099 err_disabled_feature ("save", "HDF5"); |
20945
9d9270e2f98f
eliminate comments after preprocessor conditionals
John W. Eaton <jwe@octave.org>
parents:
20940
diff
changeset
|
1100 #endif |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1101 } |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21691
diff
changeset
|
1102 #if defined (HAVE_ZLIB) |
5284 | 1103 else if (argv[i] == "-zip" || argv[i] == "-z") |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1104 { |
21568
3d60ed163b70
maint: Eliminate bad spacing around '='.
Rik <rik@octave.org>
parents:
21301
diff
changeset
|
1105 use_zlib = true; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1106 } |
5284 | 1107 #endif |
15571
7b9551c65b7b
Don't report '-struct' as an unrecognized option to save().
Rik <rik@octave.org>
parents:
15567
diff
changeset
|
1108 else if (argv[i] == "-struct") |
7b9551c65b7b
Don't report '-struct' as an unrecognized option to save().
Rik <rik@octave.org>
parents:
15567
diff
changeset
|
1109 { |
7b9551c65b7b
Don't report '-struct' as an unrecognized option to save().
Rik <rik@octave.org>
parents:
15567
diff
changeset
|
1110 retval.append (argv[i]); |
7b9551c65b7b
Don't report '-struct' as an unrecognized option to save().
Rik <rik@octave.org>
parents:
15567
diff
changeset
|
1111 } |
18442
5c0b8f2da650
Allow save() to write to the terminal with the filename '-' (bug #41505)
Mike Miller <mtmiller@ieee.org>
parents:
17861
diff
changeset
|
1112 else if (argv[i][0] == '-' && argv[i] != "-") |
15567
e05eafe7105a
Print an error message if save() called with unrecognized option (bug #37502)
Rik <rik@octave.org>
parents:
15467
diff
changeset
|
1113 { |
e05eafe7105a
Print an error message if save() called with unrecognized option (bug #37502)
Rik <rik@octave.org>
parents:
15467
diff
changeset
|
1114 error ("save: Unrecognized option '%s'", argv[i].c_str ()); |
e05eafe7105a
Print an error message if save() called with unrecognized option (bug #37502)
Rik <rik@octave.org>
parents:
15467
diff
changeset
|
1115 } |
5284 | 1116 else |
8034
f61bd8e0d682
fix default_save_options parsing and allow mixing options with other arguments.
Jaroslav Hajek <highegg@gmail.com>
parents:
8021
diff
changeset
|
1117 retval.append (argv[i]); |
5284 | 1118 } |
1119 | |
8418
679c22082ac7
handle -double option for save
John W. Eaton <jwe@octave.org>
parents:
8377
diff
changeset
|
1120 if (do_double) |
679c22082ac7
handle -double option for save
John W. Eaton <jwe@octave.org>
parents:
8377
diff
changeset
|
1121 { |
679c22082ac7
handle -double option for save
John W. Eaton <jwe@octave.org>
parents:
8377
diff
changeset
|
1122 if (format == LS_MAT_ASCII) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1123 format.opts |= LS_MAT_ASCII_LONG; |
8418
679c22082ac7
handle -double option for save
John W. Eaton <jwe@octave.org>
parents:
8377
diff
changeset
|
1124 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1125 warning ("save: \"-double\" option only has an effect with \"-ascii\""); |
8418
679c22082ac7
handle -double option for save
John W. Eaton <jwe@octave.org>
parents:
8377
diff
changeset
|
1126 } |
679c22082ac7
handle -double option for save
John W. Eaton <jwe@octave.org>
parents:
8377
diff
changeset
|
1127 |
8425
2e777f5135a3
support -tabs option for save -ascii
Jaroslav Hajek <highegg@gmail.com>
parents:
8418
diff
changeset
|
1128 if (do_tabs) |
2e777f5135a3
support -tabs option for save -ascii
Jaroslav Hajek <highegg@gmail.com>
parents:
8418
diff
changeset
|
1129 { |
2e777f5135a3
support -tabs option for save -ascii
Jaroslav Hajek <highegg@gmail.com>
parents:
8418
diff
changeset
|
1130 if (format == LS_MAT_ASCII) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1131 format.opts |= LS_MAT_ASCII_TABS; |
8425
2e777f5135a3
support -tabs option for save -ascii
Jaroslav Hajek <highegg@gmail.com>
parents:
8418
diff
changeset
|
1132 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1133 warning ("save: \"-tabs\" option only has an effect with \"-ascii\""); |
8425
2e777f5135a3
support -tabs option for save -ascii
Jaroslav Hajek <highegg@gmail.com>
parents:
8418
diff
changeset
|
1134 } |
2e777f5135a3
support -tabs option for save -ascii
Jaroslav Hajek <highegg@gmail.com>
parents:
8418
diff
changeset
|
1135 |
8034
f61bd8e0d682
fix default_save_options parsing and allow mixing options with other arguments.
Jaroslav Hajek <highegg@gmail.com>
parents:
8021
diff
changeset
|
1136 return retval; |
5284 | 1137 } |
1138 | |
8034
f61bd8e0d682
fix default_save_options parsing and allow mixing options with other arguments.
Jaroslav Hajek <highegg@gmail.com>
parents:
8021
diff
changeset
|
1139 static string_vector |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
1140 parse_save_options (const std::string &arg, load_save_format &format, |
20996 | 1141 bool &append, bool &save_as_floats, bool &use_zlib) |
5284 | 1142 { |
5765 | 1143 std::istringstream is (arg); |
5284 | 1144 std::string str; |
1145 string_vector argv; | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
1146 |
5765 | 1147 while (! is.eof ()) |
5284 | 1148 { |
1149 is >> str; | |
1150 argv.append (str); | |
1151 } | |
1152 | |
20996 | 1153 return parse_save_options (argv, format, append, save_as_floats, use_zlib); |
604 | 1154 } |
1155 | |
4329 | 1156 void |
3523 | 1157 write_header (std::ostream& os, load_save_format format) |
863 | 1158 { |
8425
2e777f5135a3
support -tabs option for save -ascii
Jaroslav Hajek <highegg@gmail.com>
parents:
8418
diff
changeset
|
1159 switch (format.type) |
863 | 1160 { |
3185 | 1161 case LS_BINARY: |
1162 { | |
21739
c4ab2e54f100
use namespace for oct_mach_info class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
1163 os << (octave::mach_info::words_big_endian () |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1164 ? "Octave-1-B" : "Octave-1-L"); |
3185 | 1165 |
21739
c4ab2e54f100
use namespace for oct_mach_info class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
1166 octave::mach_info::float_format flt_fmt = |
c4ab2e54f100
use namespace for oct_mach_info class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
1167 octave::mach_info::native_float_format (); |
3185 | 1168 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1169 char tmp = static_cast<char> (float_format_to_mopt_digit (flt_fmt)); |
3185 | 1170 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1171 os.write (&tmp, 1); |
3185 | 1172 } |
3688 | 1173 break; |
1174 | |
1175 case LS_MAT5_BINARY: | |
5269 | 1176 case LS_MAT7_BINARY: |
3688 | 1177 { |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1178 char const * versionmagic; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1179 int16_t number = *(reinterpret_cast<const int16_t *>("\x00\x01")); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1180 char headertext[128]; |
21730
30c53770f47e
use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
1181 octave::sys::gmtime now; |
3688 | 1182 |
20389
6bc09e953927
Use octave_gmtime to write timestamp to mat-file format
Mike Miller <mtmiller@octave.org>
parents:
20264
diff
changeset
|
1183 // ISO 8601 format date |
6bc09e953927
Use octave_gmtime to write timestamp to mat-file format
Mike Miller <mtmiller@octave.org>
parents:
20264
diff
changeset
|
1184 const char *matlab_format = "MATLAB 5.0 MAT-file, written by Octave " |
6bc09e953927
Use octave_gmtime to write timestamp to mat-file format
Mike Miller <mtmiller@octave.org>
parents:
20264
diff
changeset
|
1185 OCTAVE_VERSION ", %Y-%m-%d %T UTC"; |
6bc09e953927
Use octave_gmtime to write timestamp to mat-file format
Mike Miller <mtmiller@octave.org>
parents:
20264
diff
changeset
|
1186 std::string comment_string = now.strftime (matlab_format); |
6bc09e953927
Use octave_gmtime to write timestamp to mat-file format
Mike Miller <mtmiller@octave.org>
parents:
20264
diff
changeset
|
1187 |
6bc09e953927
Use octave_gmtime to write timestamp to mat-file format
Mike Miller <mtmiller@octave.org>
parents:
20264
diff
changeset
|
1188 size_t len = std::min (comment_string.length (), static_cast<size_t> (124)); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1189 memset (headertext, ' ', 124); |
20389
6bc09e953927
Use octave_gmtime to write timestamp to mat-file format
Mike Miller <mtmiller@octave.org>
parents:
20264
diff
changeset
|
1190 memcpy (headertext, comment_string.data (), len); |
3688 | 1191 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1192 // The first pair of bytes give the version of the MAT file |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1193 // format. The second pair of bytes form a magic number which |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1194 // signals a MAT file. MAT file data are always written in |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1195 // native byte order. The order of the bytes in the second |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1196 // pair indicates whether the file was written by a big- or |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1197 // little-endian machine. However, the version number is |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1198 // written in the *opposite* byte order from everything else! |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1199 if (number == 1) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1200 versionmagic = "\x01\x00\x4d\x49"; // this machine is big endian |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1201 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1202 versionmagic = "\x00\x01\x49\x4d"; // this machine is little endian |
3688 | 1203 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1204 memcpy (headertext+124, versionmagic, 4); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1205 os.write (headertext, 128); |
3688 | 1206 } |
1207 | |
1208 break; | |
3185 | 1209 |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21691
diff
changeset
|
1210 #if defined (HAVE_HDF5) |
3687 | 1211 case LS_HDF5: |
20945
9d9270e2f98f
eliminate comments after preprocessor conditionals
John W. Eaton <jwe@octave.org>
parents:
20940
diff
changeset
|
1212 #endif |
20447
c6224b4e7774
maint: Rename instances of LS_ASCII to LS_TEXT for clarity.
Rik <rik@octave.org>
parents:
20443
diff
changeset
|
1213 case LS_TEXT: |
3185 | 1214 { |
21730
30c53770f47e
use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
1215 octave::sys::localtime now; |
3709 | 1216 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1217 std::string comment_string = now.strftime (Vsave_header_format_string); |
3709 | 1218 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1219 if (! comment_string.empty ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1220 { |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21691
diff
changeset
|
1221 #if defined (HAVE_HDF5) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1222 if (format == LS_HDF5) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1223 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1224 hdf5_ofstream& hs = dynamic_cast<hdf5_ofstream&> (os); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1225 H5Gset_comment (hs.file_id, "/", comment_string.c_str ()); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1226 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1227 else |
20945
9d9270e2f98f
eliminate comments after preprocessor conditionals
John W. Eaton <jwe@octave.org>
parents:
20940
diff
changeset
|
1228 #endif |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1229 os << comment_string << "\n"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1230 } |
3185 | 1231 } |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17755
diff
changeset
|
1232 break; |
3185 | 1233 |
1234 default: | |
1235 break; | |
863 | 1236 } |
1237 } | |
1238 | |
17755
9c03b071fd7b
avoid HDF5 error message at exit (bug #37713)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
1239 void |
9c03b071fd7b
avoid HDF5 error message at exit (bug #37713)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
1240 octave_prepare_hdf5 (void) |
9c03b071fd7b
avoid HDF5 error message at exit (bug #37713)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
1241 { |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21691
diff
changeset
|
1242 #if defined (HAVE_HDF5) |
17755
9c03b071fd7b
avoid HDF5 error message at exit (bug #37713)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
1243 H5dont_atexit (); |
9c03b071fd7b
avoid HDF5 error message at exit (bug #37713)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
1244 #endif |
9c03b071fd7b
avoid HDF5 error message at exit (bug #37713)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
1245 } |
9c03b071fd7b
avoid HDF5 error message at exit (bug #37713)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
1246 |
9c03b071fd7b
avoid HDF5 error message at exit (bug #37713)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
1247 void |
9c03b071fd7b
avoid HDF5 error message at exit (bug #37713)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
1248 octave_finalize_hdf5 (void) |
9c03b071fd7b
avoid HDF5 error message at exit (bug #37713)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
1249 { |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21691
diff
changeset
|
1250 #if defined (HAVE_HDF5) |
17755
9c03b071fd7b
avoid HDF5 error message at exit (bug #37713)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
1251 H5close (); |
9c03b071fd7b
avoid HDF5 error message at exit (bug #37713)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
1252 #endif |
9c03b071fd7b
avoid HDF5 error message at exit (bug #37713)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
1253 } |
9c03b071fd7b
avoid HDF5 error message at exit (bug #37713)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
1254 |
863 | 1255 static void |
3769 | 1256 save_vars (const string_vector& argv, int argv_idx, int argc, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1257 std::ostream& os, load_save_format fmt, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1258 bool save_as_floats, bool write_header_info) |
863 | 1259 { |
3185 | 1260 if (write_header_info) |
1261 write_header (os, fmt); | |
863 | 1262 |
1755 | 1263 if (argv_idx == argc) |
863 | 1264 { |
5794 | 1265 save_vars (os, "*", fmt, save_as_floats); |
863 | 1266 } |
7635
ba7a3e20ee3d
add -struct modifier to save
Jaroslav Hajek <highegg@gmail.com>
parents:
7336
diff
changeset
|
1267 else if (argv[argv_idx] == "-struct") |
ba7a3e20ee3d
add -struct modifier to save
Jaroslav Hajek <highegg@gmail.com>
parents:
7336
diff
changeset
|
1268 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
1269 if (++argv_idx >= argc) |
20831
35241c4b696c
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20801
diff
changeset
|
1270 error ("save: missing struct name"); |
7635
ba7a3e20ee3d
add -struct modifier to save
Jaroslav Hajek <highegg@gmail.com>
parents:
7336
diff
changeset
|
1271 |
ba7a3e20ee3d
add -struct modifier to save
Jaroslav Hajek <highegg@gmail.com>
parents:
7336
diff
changeset
|
1272 std::string struct_name = argv[argv_idx]; |
ba7a3e20ee3d
add -struct modifier to save
Jaroslav Hajek <highegg@gmail.com>
parents:
7336
diff
changeset
|
1273 |
ba7a3e20ee3d
add -struct modifier to save
Jaroslav Hajek <highegg@gmail.com>
parents:
7336
diff
changeset
|
1274 if (! symbol_table::is_variable (struct_name)) |
20831
35241c4b696c
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20801
diff
changeset
|
1275 error ("save: no such variable: '%s'", struct_name.c_str ()); |
7635
ba7a3e20ee3d
add -struct modifier to save
Jaroslav Hajek <highegg@gmail.com>
parents:
7336
diff
changeset
|
1276 |
16442
302157614308
deprecate symbol_table::varref functions
John W. Eaton <jwe@octave.org>
parents:
15571
diff
changeset
|
1277 octave_value struct_var = symbol_table::varval (struct_name); |
7635
ba7a3e20ee3d
add -struct modifier to save
Jaroslav Hajek <highegg@gmail.com>
parents:
7336
diff
changeset
|
1278 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
1279 if (! struct_var.is_map () || struct_var.numel () != 1) |
20831
35241c4b696c
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20801
diff
changeset
|
1280 error ("save: '%s' is not a scalar structure", struct_name.c_str ()); |
35241c4b696c
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20801
diff
changeset
|
1281 |
11059
4ffa19147604
replace Octave_map->octave_scalar_map in help.cc and load-save.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
10846
diff
changeset
|
1282 octave_scalar_map struct_var_map = struct_var.scalar_map_value (); |
7635
ba7a3e20ee3d
add -struct modifier to save
Jaroslav Hajek <highegg@gmail.com>
parents:
7336
diff
changeset
|
1283 |
ba7a3e20ee3d
add -struct modifier to save
Jaroslav Hajek <highegg@gmail.com>
parents:
7336
diff
changeset
|
1284 ++argv_idx; |
ba7a3e20ee3d
add -struct modifier to save
Jaroslav Hajek <highegg@gmail.com>
parents:
7336
diff
changeset
|
1285 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
1286 if (argv_idx < argc) |
7635
ba7a3e20ee3d
add -struct modifier to save
Jaroslav Hajek <highegg@gmail.com>
parents:
7336
diff
changeset
|
1287 { |
ba7a3e20ee3d
add -struct modifier to save
Jaroslav Hajek <highegg@gmail.com>
parents:
7336
diff
changeset
|
1288 for (int i = argv_idx; i < argc; i++) |
ba7a3e20ee3d
add -struct modifier to save
Jaroslav Hajek <highegg@gmail.com>
parents:
7336
diff
changeset
|
1289 { |
ba7a3e20ee3d
add -struct modifier to save
Jaroslav Hajek <highegg@gmail.com>
parents:
7336
diff
changeset
|
1290 if (! save_fields (os, struct_var_map, argv[i], fmt, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1291 save_as_floats)) |
7635
ba7a3e20ee3d
add -struct modifier to save
Jaroslav Hajek <highegg@gmail.com>
parents:
7336
diff
changeset
|
1292 { |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14268
diff
changeset
|
1293 warning ("save: no such field '%s.%s'", |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1294 struct_name.c_str (), argv[i].c_str ()); |
7635
ba7a3e20ee3d
add -struct modifier to save
Jaroslav Hajek <highegg@gmail.com>
parents:
7336
diff
changeset
|
1295 } |
ba7a3e20ee3d
add -struct modifier to save
Jaroslav Hajek <highegg@gmail.com>
parents:
7336
diff
changeset
|
1296 } |
ba7a3e20ee3d
add -struct modifier to save
Jaroslav Hajek <highegg@gmail.com>
parents:
7336
diff
changeset
|
1297 } |
ba7a3e20ee3d
add -struct modifier to save
Jaroslav Hajek <highegg@gmail.com>
parents:
7336
diff
changeset
|
1298 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1299 save_fields (os, struct_var_map, "*", fmt, save_as_floats); |
7635
ba7a3e20ee3d
add -struct modifier to save
Jaroslav Hajek <highegg@gmail.com>
parents:
7336
diff
changeset
|
1300 } |
863 | 1301 else |
1302 { | |
1755 | 1303 for (int i = argv_idx; i < argc; i++) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1304 { |
17349
cb27dbf9e4ba
Don't warn about saving empty variable names for Matlab compatibility (bug #34259)
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
1305 if (argv[i] == "") |
cb27dbf9e4ba
Don't warn about saving empty variable names for Matlab compatibility (bug #34259)
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
1306 continue; // Skip empty vars for Matlab compatibility |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1307 if (! save_vars (os, argv[i], fmt, save_as_floats)) |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14268
diff
changeset
|
1308 warning ("save: no such variable '%s'", argv[i].c_str ()); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1309 } |
863 | 1310 } |
1311 } | |
1312 | |
5284 | 1313 static void |
1314 dump_octave_core (std::ostream& os, const char *fname, load_save_format fmt, | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1315 bool save_as_floats) |
4791 | 1316 { |
1317 write_header (os, fmt); | |
1318 | |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
1319 std::list<symbol_table::symbol_record> vars |
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
1320 = symbol_table::all_variables (symbol_table::top_scope (), 0); |
4791 | 1321 |
1322 double save_mem_size = 0; | |
1323 | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17755
diff
changeset
|
1324 typedef std::list<symbol_table::symbol_record>::const_iterator |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17755
diff
changeset
|
1325 const_vars_iterator; |
7336 | 1326 |
1327 for (const_vars_iterator p = vars.begin (); p != vars.end (); p++) | |
4791 | 1328 { |
7336 | 1329 octave_value val = p->varval (); |
4791 | 1330 |
7336 | 1331 if (val.is_defined ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1332 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1333 std::string name = p->name (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1334 std::string help; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1335 bool global = p->is_global (); |
4791 | 1336 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1337 double val_size = val.byte_size () / 1024; |
4791 | 1338 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17755
diff
changeset
|
1339 // FIXME: maybe we should try to throw out the largest first... |
4791 | 1340 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1341 if (Voctave_core_file_limit < 0 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1342 || save_mem_size + val_size < Voctave_core_file_limit) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1343 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1344 save_mem_size += val_size; |
4791 | 1345 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1346 do_save (os, val, name, help, global, fmt, save_as_floats); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1347 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1348 } |
4791 | 1349 } |
1350 | |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14268
diff
changeset
|
1351 message (0, "save to '%s' complete", fname); |
4791 | 1352 } |
1353 | |
1354 void | |
1355 dump_octave_core (void) | |
1380 | 1356 { |
3189 | 1357 if (Vcrash_dumps_octave_core) |
1380 | 1358 { |
20713
2469d78a1d8b
Consistently use 'filename' rather than 'file name' throughout code base.
Rik <rik@octave.org>
parents:
20678
diff
changeset
|
1359 // FIXME: should choose better filename? |
3189 | 1360 |
4791 | 1361 const char *fname = Voctave_core_file_name.c_str (); |
3189 | 1362 |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14268
diff
changeset
|
1363 message (0, "attempting to save variables to '%s'...", fname); |
3189 | 1364 |
5284 | 1365 load_save_format format = LS_BINARY; |
1366 | |
1367 bool save_as_floats = false; | |
1368 | |
1369 bool append = false; | |
3189 | 1370 |
5284 | 1371 bool use_zlib = false; |
1372 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
1373 parse_save_options (Voctave_core_file_options, format, append, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1374 save_as_floats, use_zlib); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
1375 |
5284 | 1376 std::ios::openmode mode = std::ios::out; |
4791 | 1377 |
6625 | 1378 // Matlab v7 files are always compressed |
1379 if (format == LS_MAT7_BINARY) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1380 use_zlib = false; |
6625 | 1381 |
4791 | 1382 if (format == LS_BINARY |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21691
diff
changeset
|
1383 #if defined (HAVE_HDF5) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1384 || format == LS_HDF5 |
4791 | 1385 #endif |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1386 || format == LS_MAT_BINARY |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1387 || format == LS_MAT5_BINARY |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1388 || format == LS_MAT7_BINARY) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1389 mode |= std::ios::binary; |
3189 | 1390 |
5284 | 1391 mode |= append ? std::ios::ate : std::ios::trunc; |
1392 | |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21691
diff
changeset
|
1393 #if defined (HAVE_HDF5) |
3687 | 1394 if (format == LS_HDF5) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1395 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1396 hdf5_ofstream file (fname, mode); |
3687 | 1397 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1398 if (file.file_id >= 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1399 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1400 dump_octave_core (file, fname, format, save_as_floats); |
3687 | 1401 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1402 file.close (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1403 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1404 else |
20727
a5949b3d2332
Preface warning() messages with name of function when possible.
Rik <rik@octave.org>
parents:
20713
diff
changeset
|
1405 warning ("dump_octave_core: unable to open '%s' for writing...", |
a5949b3d2332
Preface warning() messages with name of function when possible.
Rik <rik@octave.org>
parents:
20713
diff
changeset
|
1406 fname); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1407 } |
3189 | 1408 else |
20945
9d9270e2f98f
eliminate comments after preprocessor conditionals
John W. Eaton <jwe@octave.org>
parents:
20940
diff
changeset
|
1409 #endif |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1410 // don't insert any commands here! The open brace below must |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1411 // go with the else above! |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1412 { |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21691
diff
changeset
|
1413 #if defined (HAVE_ZLIB) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1414 if (use_zlib) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1415 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1416 gzofstream file (fname, mode); |
4791 | 1417 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1418 if (file) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1419 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1420 dump_octave_core (file, fname, format, save_as_floats); |
5284 | 1421 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1422 file.close (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1423 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1424 else |
20727
a5949b3d2332
Preface warning() messages with name of function when possible.
Rik <rik@octave.org>
parents:
20713
diff
changeset
|
1425 warning ("dump_octave_core: unable to open '%s' for writing...", |
a5949b3d2332
Preface warning() messages with name of function when possible.
Rik <rik@octave.org>
parents:
20713
diff
changeset
|
1426 fname); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1427 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1428 else |
5284 | 1429 #endif |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1430 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1431 std::ofstream file (fname, mode); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
1432 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1433 if (file) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1434 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1435 dump_octave_core (file, fname, format, save_as_floats); |
5284 | 1436 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1437 file.close (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1438 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1439 else |
20727
a5949b3d2332
Preface warning() messages with name of function when possible.
Rik <rik@octave.org>
parents:
20713
diff
changeset
|
1440 warning ("dump_octave_core: unable to open '%s' for writing...", |
a5949b3d2332
Preface warning() messages with name of function when possible.
Rik <rik@octave.org>
parents:
20713
diff
changeset
|
1441 fname); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1442 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1443 } |
1380 | 1444 } |
1445 } | |
1446 | |
19817
bafcfc5b99af
if save file name is "-" and nargout is 0, write to stdout
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
1447 DEFUN (save, args, nargout, |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1448 doc: /* -*- texinfo -*- |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1449 @deftypefn {} {} save file |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1450 @deftypefnx {} {} save options file |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1451 @deftypefnx {} {} save options file @var{v1} @var{v2} @dots{} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1452 @deftypefnx {} {} save options file -struct @var{STRUCT} @var{f1} @var{f2} @dots{} |
23047
97a9fd0af57b
doc: Don't use @code in @deftypefn because it expands badly in plain text format.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
1453 @deftypefnx {} {} save - @var{v1} @var{v2} @dots{} |
97a9fd0af57b
doc: Don't use @code in @deftypefn because it expands badly in plain text format.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
1454 @deftypefnx {} {@var{str} =} save ("-", @qcode{"@var{v1}"}, @qcode{"@var{v2}"}, @dots{}) |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1455 Save the named variables @var{v1}, @var{v2}, @dots{}, in the file |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1456 @var{file}. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1457 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1458 The special filename @samp{-} may be used to return the |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1459 content of the variables as a string. If no variable names are listed, |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1460 Octave saves all the variables in the current scope. Otherwise, full |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1461 variable names or pattern syntax can be used to specify the variables to |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1462 save. If the @option{-struct} modifier is used, fields @var{f1} @var{f2} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1463 @dots{} of the scalar structure @var{STRUCT} are saved as if they were |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1464 variables with corresponding names. Valid options for the @code{save} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1465 command are listed in the following table. Options that modify the output |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1466 format override the format specified by @code{save_default_options}. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1467 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1468 If save is invoked using the functional form |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1469 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1470 @example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1471 save ("-option1", @dots{}, "file", "v1", @dots{}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1472 @end example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1473 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1474 @noindent |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1475 then the @var{options}, @var{file}, and variable name arguments |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1476 (@var{v1}, @dots{}) must be specified as character strings. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1477 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1478 If called with a filename of @qcode{"-"}, write the output to stdout |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1479 if nargout is 0, otherwise return the output in a character string. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1480 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1481 @table @code |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1482 @item -append |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1483 Append to the destination instead of overwriting. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1484 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1485 @item -ascii |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1486 Save a single matrix in a text file without header or any other information. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1487 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1488 @item -binary |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1489 Save the data in Octave's binary data format. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1490 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1491 @item -float-binary |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1492 Save the data in Octave's binary data format but only using single |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1493 precision. Only use this format if you know that all the |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1494 values to be saved can be represented in single precision. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1495 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1496 @item -hdf5 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1497 Save the data in @sc{hdf5} format. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1498 (HDF5 is a free, portable binary format developed by the National |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1499 Center for Supercomputing Applications at the University of Illinois.) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1500 This format is only available if Octave was built with a link to the |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1501 @sc{hdf5} libraries. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1502 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1503 @item -float-hdf5 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1504 Save the data in @sc{hdf5} format but only using single precision. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1505 Only use this format if you know that all the |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1506 values to be saved can be represented in single precision. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1507 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1508 @item -V7 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1509 @itemx -v7 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1510 @itemx -7 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1511 @itemx -mat7-binary |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1512 Save the data in @sc{matlab}'s v7 binary data format. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1513 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1514 @item -V6 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1515 @itemx -v6 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1516 @itemx -6 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1517 @itemx -mat |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1518 @itemx -mat-binary |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1519 Save the data in @sc{matlab}'s v6 binary data format. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1520 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1521 @item -V4 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1522 @itemx -v4 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1523 @itemx -4 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1524 @itemx -mat4-binary |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1525 Save the data in the binary format written by @sc{matlab} version 4. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1526 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1527 @item -text |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1528 Save the data in Octave's text data format. (default). |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1529 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1530 @item -zip |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1531 @itemx -z |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1532 Use the gzip algorithm to compress the file. This works equally on files |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1533 that are compressed with gzip outside of octave, and gzip can equally be |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1534 used to convert the files for backward compatibility. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1535 This option is only available if Octave was built with a link to the zlib |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1536 libraries. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1537 @end table |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1538 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1539 The list of variables to save may use wildcard patterns containing |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1540 the following special characters: |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1541 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1542 @table @code |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1543 @item ? |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1544 Match any single character. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1545 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1546 @item * |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1547 Match zero or more characters. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1548 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1549 @item [ @var{list} ] |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1550 Match the list of characters specified by @var{list}. If the first |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1551 character is @code{!} or @code{^}, match all characters except those |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1552 specified by @var{list}. For example, the pattern @code{[a-zA-Z]} will |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1553 match all lower and uppercase alphabetic characters. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1554 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1555 Wildcards may also be used in the field name specifications when using |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1556 the @option{-struct} modifier (but not in the struct name itself). |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1557 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1558 @end table |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1559 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1560 Except when using the @sc{matlab} binary data file format or the |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1561 @samp{-ascii} format, saving global |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1562 variables also saves the global status of the variable. If the variable |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1563 is restored at a later time using @samp{load}, it will be restored as a |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1564 global variable. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1565 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1566 The command |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1567 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1568 @example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1569 save -binary data a b* |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1570 @end example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1571 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1572 @noindent |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1573 saves the variable @samp{a} and all variables beginning with @samp{b} to |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1574 the file @file{data} in Octave's binary format. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1575 @seealso{load, save_default_options, save_header_format_string, dlmread, csvread, fread} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1576 @end deftypefn */) |
604 | 1577 { |
1358 | 1578 // Here is where we would get the default save format if it were |
1579 // stored in a user preference variable. | |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
1580 load_save_format format = LS_TEXT; |
3019 | 1581 bool save_as_floats = false; |
3185 | 1582 bool append = false; |
5269 | 1583 bool use_zlib = false; |
1584 | |
8034
f61bd8e0d682
fix default_save_options parsing and allow mixing options with other arguments.
Jaroslav Hajek <highegg@gmail.com>
parents:
8021
diff
changeset
|
1585 // get default options |
16875
b04ae15530fc
Rename default_save_options() to save_default_options().
Rik <rik@octave.org>
parents:
16555
diff
changeset
|
1586 parse_save_options (Vsave_default_options, format, append, save_as_floats, |
8034
f61bd8e0d682
fix default_save_options parsing and allow mixing options with other arguments.
Jaroslav Hajek <highegg@gmail.com>
parents:
8021
diff
changeset
|
1587 use_zlib); |
5351 | 1588 |
8034
f61bd8e0d682
fix default_save_options parsing and allow mixing options with other arguments.
Jaroslav Hajek <highegg@gmail.com>
parents:
8021
diff
changeset
|
1589 // override from command line |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
1590 string_vector argv = args.make_argv (); |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
1591 |
20996 | 1592 argv = parse_save_options (argv, format, append, save_as_floats, use_zlib); |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
1593 |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20172
diff
changeset
|
1594 int argc = argv.numel (); |
8034
f61bd8e0d682
fix default_save_options parsing and allow mixing options with other arguments.
Jaroslav Hajek <highegg@gmail.com>
parents:
8021
diff
changeset
|
1595 int i = 0; |
5197 | 1596 |
2057 | 1597 if (i == argc) |
20801
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20741
diff
changeset
|
1598 print_usage (); |
604 | 1599 |
20447
c6224b4e7774
maint: Rename instances of LS_ASCII to LS_TEXT for clarity.
Rik <rik@octave.org>
parents:
20443
diff
changeset
|
1600 if (save_as_floats && format == LS_TEXT) |
20831
35241c4b696c
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20801
diff
changeset
|
1601 error ("save: cannot specify both -text and -float-binary"); |
630 | 1602 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
1603 octave_value_list retval; |
630 | 1604 |
1755 | 1605 if (argv[i] == "-") |
604 | 1606 { |
1755 | 1607 i++; |
863 | 1608 |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21691
diff
changeset
|
1609 #if defined (HAVE_HDF5) |
3687 | 1610 if (format == LS_HDF5) |
4687 | 1611 error ("save: cannot write HDF5 format to stdout"); |
3687 | 1612 else |
20945
9d9270e2f98f
eliminate comments after preprocessor conditionals
John W. Eaton <jwe@octave.org>
parents:
20940
diff
changeset
|
1613 #endif |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1614 // don't insert any commands here! the brace below must go |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1615 // with the "else" above! |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1616 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1617 if (append) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1618 warning ("save: ignoring -append option for output to stdout"); |
6759 | 1619 |
19817
bafcfc5b99af
if save file name is "-" and nargout is 0, write to stdout
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
1620 if (nargout == 0) |
bafcfc5b99af
if save file name is "-" and nargout is 0, write to stdout
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
1621 save_vars (argv, i, argc, std::cout, format, save_as_floats, true); |
bafcfc5b99af
if save file name is "-" and nargout is 0, write to stdout
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
1622 else |
bafcfc5b99af
if save file name is "-" and nargout is 0, write to stdout
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
1623 { |
bafcfc5b99af
if save file name is "-" and nargout is 0, write to stdout
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
1624 std::ostringstream output_buf; |
bafcfc5b99af
if save file name is "-" and nargout is 0, write to stdout
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
1625 save_vars (argv, i, argc, output_buf, format, save_as_floats, true); |
bafcfc5b99af
if save file name is "-" and nargout is 0, write to stdout
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
1626 retval = octave_value (output_buf.str()); |
bafcfc5b99af
if save file name is "-" and nargout is 0, write to stdout
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
1627 } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1628 } |
604 | 1629 } |
1755 | 1630 |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14268
diff
changeset
|
1631 // Guard against things like 'save a*', which are probably mistakes... |
1755 | 1632 |
1633 else if (i == argc - 1 && glob_pattern_p (argv[i])) | |
20801
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20741
diff
changeset
|
1634 print_usage (); |
604 | 1635 else |
1636 { | |
21733
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
1637 std::string fname = octave::sys::file_ops::tilde_expand (argv[i]); |
1755 | 1638 |
1639 i++; | |
604 | 1640 |
6625 | 1641 // Matlab v7 files are always compressed |
1642 if (format == LS_MAT7_BINARY) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1643 use_zlib = false; |
6625 | 1644 |
6759 | 1645 std::ios::openmode mode |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1646 = append ? (std::ios::app | std::ios::ate) : std::ios::out; |
6759 | 1647 |
4791 | 1648 if (format == LS_BINARY |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21691
diff
changeset
|
1649 #if defined (HAVE_HDF5) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1650 || format == LS_HDF5 |
4791 | 1651 #endif |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1652 || format == LS_MAT_BINARY |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1653 || format == LS_MAT5_BINARY |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1654 || format == LS_MAT7_BINARY) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1655 mode |= std::ios::binary; |
3538 | 1656 |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21691
diff
changeset
|
1657 #if defined (HAVE_HDF5) |
3687 | 1658 if (format == LS_HDF5) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1659 { |
17861
870f3e12e163
maint: Use phrase "FIXME:" for problem areas in code.
Rik <rik@octave.org>
parents:
17787
diff
changeset
|
1660 // FIXME: It should be possible to append to HDF5 files. |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1661 if (append) |
20831
35241c4b696c
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20801
diff
changeset
|
1662 error ("save: appending to HDF5 files is not implemented"); |
6759 | 1663 |
19864
17d647821d61
maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents:
19817
diff
changeset
|
1664 bool write_header_info |
17d647821d61
maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents:
19817
diff
changeset
|
1665 = ! (append && H5Fis_hdf5 (fname.c_str ()) > 0); |
3687 | 1666 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1667 hdf5_ofstream hdf5_file (fname.c_str (), mode); |
6760 | 1668 |
21118
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21109
diff
changeset
|
1669 if (hdf5_file.file_id == -1) |
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21109
diff
changeset
|
1670 err_file_open ("save", fname); |
3687 | 1671 |
21118
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21109
diff
changeset
|
1672 save_vars (argv, i, argc, hdf5_file, format, |
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21109
diff
changeset
|
1673 save_as_floats, write_header_info); |
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21109
diff
changeset
|
1674 |
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21109
diff
changeset
|
1675 hdf5_file.close (); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1676 } |
863 | 1677 else |
20945
9d9270e2f98f
eliminate comments after preprocessor conditionals
John W. Eaton <jwe@octave.org>
parents:
20940
diff
changeset
|
1678 #endif |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1679 // don't insert any statements here! The brace below must go |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1680 // with the "else" above! |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1681 { |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21691
diff
changeset
|
1682 #if defined (HAVE_ZLIB) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1683 if (use_zlib) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1684 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1685 gzofstream file (fname.c_str (), mode); |
5269 | 1686 |
21118
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21109
diff
changeset
|
1687 if (! file) |
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21109
diff
changeset
|
1688 err_file_open ("save", fname); |
6760 | 1689 |
21118
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21109
diff
changeset
|
1690 bool write_header_info = ! file.tellp (); |
5269 | 1691 |
21118
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21109
diff
changeset
|
1692 save_vars (argv, i, argc, file, format, |
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21109
diff
changeset
|
1693 save_as_floats, write_header_info); |
5269 | 1694 |
21118
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21109
diff
changeset
|
1695 file.close (); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1696 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1697 else |
5269 | 1698 #endif |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1699 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1700 std::ofstream file (fname.c_str (), mode); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
1701 |
21118
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21109
diff
changeset
|
1702 if (! file) |
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21109
diff
changeset
|
1703 err_file_open ("save", fname); |
6760 | 1704 |
21118
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21109
diff
changeset
|
1705 bool write_header_info = ! file.tellp (); |
5269 | 1706 |
21118
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21109
diff
changeset
|
1707 save_vars (argv, i, argc, file, format, |
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21109
diff
changeset
|
1708 save_as_floats, write_header_info); |
5269 | 1709 |
21118
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21109
diff
changeset
|
1710 file.close (); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1711 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1712 } |
604 | 1713 } |
1714 | |
1715 return retval; | |
1716 } | |
1717 | |
5794 | 1718 DEFUN (crash_dumps_octave_core, args, nargout, |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1719 doc: /* -*- texinfo -*- |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1720 @deftypefn {} {@var{val} =} crash_dumps_octave_core () |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1721 @deftypefnx {} {@var{old_val} =} crash_dumps_octave_core (@var{new_val}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1722 @deftypefnx {} {} crash_dumps_octave_core (@var{new_val}, "local") |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1723 Query or set the internal variable that controls whether Octave tries |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1724 to save all current variables to the file @file{octave-workspace} if it |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1725 crashes or receives a hangup, terminate or similar signal. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1726 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1727 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:
21888
diff
changeset
|
1728 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:
21888
diff
changeset
|
1729 The original variable value is restored when exiting the function. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1730 @seealso{octave_core_file_limit, octave_core_file_name, octave_core_file_options} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1731 @end deftypefn */) |
2194 | 1732 { |
5794 | 1733 return SET_INTERNAL_VARIABLE (crash_dumps_octave_core); |
2194 | 1734 } |
1735 | |
16875
b04ae15530fc
Rename default_save_options() to save_default_options().
Rik <rik@octave.org>
parents:
16555
diff
changeset
|
1736 DEFUN (save_default_options, args, nargout, |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1737 doc: /* -*- texinfo -*- |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1738 @deftypefn {} {@var{val} =} save_default_options () |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1739 @deftypefnx {} {@var{old_val} =} save_default_options (@var{new_val}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1740 @deftypefnx {} {} save_default_options (@var{new_val}, "local") |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1741 Query or set the internal variable that specifies the default options |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1742 for the @code{save} command, and defines the default format. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1743 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1744 Typical values include @qcode{"-ascii"}, @qcode{"-text -zip"}. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1745 The default value is @option{-text}. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1746 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1747 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:
21888
diff
changeset
|
1748 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:
21888
diff
changeset
|
1749 The original variable value is restored when exiting the function. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1750 @seealso{save} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1751 @end deftypefn */) |
4788 | 1752 { |
16875
b04ae15530fc
Rename default_save_options() to save_default_options().
Rik <rik@octave.org>
parents:
16555
diff
changeset
|
1753 return SET_NONEMPTY_INTERNAL_STRING_VARIABLE (save_default_options); |
4788 | 1754 } |
1755 | |
5794 | 1756 DEFUN (octave_core_file_limit, args, nargout, |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1757 doc: /* -*- texinfo -*- |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1758 @deftypefn {} {@var{val} =} octave_core_file_limit () |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1759 @deftypefnx {} {@var{old_val} =} octave_core_file_limit (@var{new_val}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1760 @deftypefnx {} {} octave_core_file_limit (@var{new_val}, "local") |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1761 Query or set the internal variable that specifies the maximum amount |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1762 of memory (in kilobytes) of the top-level workspace that Octave will |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1763 attempt to save when writing data to the crash dump file (the name of |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1764 the file is specified by @var{octave_core_file_name}). |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1765 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1766 If @var{octave_core_file_options} flags specify a binary format, |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1767 then @var{octave_core_file_limit} will be approximately the maximum |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1768 size of the file. If a text file format is used, then the file could |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1769 be much larger than the limit. The default value is -1 (unlimited) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1770 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1771 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:
21888
diff
changeset
|
1772 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:
21888
diff
changeset
|
1773 The original variable value is restored when exiting the function. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1774 @seealso{crash_dumps_octave_core, octave_core_file_name, octave_core_file_options} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1775 @end deftypefn */) |
3709 | 1776 { |
5794 | 1777 return SET_INTERNAL_VARIABLE (octave_core_file_limit); |
3709 | 1778 } |
1779 | |
5794 | 1780 DEFUN (octave_core_file_name, args, nargout, |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1781 doc: /* -*- texinfo -*- |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1782 @deftypefn {} {@var{val} =} octave_core_file_name () |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1783 @deftypefnx {} {@var{old_val} =} octave_core_file_name (@var{new_val}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1784 @deftypefnx {} {} octave_core_file_name (@var{new_val}, "local") |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1785 Query or set the internal variable that specifies the name of the file |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1786 used for saving data from the top-level workspace if Octave aborts. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1787 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1788 The default value is @qcode{"octave-workspace"} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1789 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1790 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:
21888
diff
changeset
|
1791 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:
21888
diff
changeset
|
1792 The original variable value is restored when exiting the function. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1793 @seealso{crash_dumps_octave_core, octave_core_file_name, octave_core_file_options} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1794 @end deftypefn */) |
2194 | 1795 { |
5794 | 1796 return SET_NONEMPTY_INTERNAL_STRING_VARIABLE (octave_core_file_name); |
1797 } | |
4791 | 1798 |
5794 | 1799 DEFUN (octave_core_file_options, args, nargout, |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1800 doc: /* -*- texinfo -*- |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1801 @deftypefn {} {@var{val} =} octave_core_file_options () |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1802 @deftypefnx {} {@var{old_val} =} octave_core_file_options (@var{new_val}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1803 @deftypefnx {} {} octave_core_file_options (@var{new_val}, "local") |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1804 Query or set the internal variable that specifies the options used for |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1805 saving the workspace data if Octave aborts. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1806 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1807 The value of @code{octave_core_file_options} should follow the same format |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1808 as the options for the @code{save} function. The default value is Octave's |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1809 binary format. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1810 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1811 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:
21888
diff
changeset
|
1812 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:
21888
diff
changeset
|
1813 The original variable value is restored when exiting the function. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1814 @seealso{crash_dumps_octave_core, octave_core_file_name, octave_core_file_limit} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1815 @end deftypefn */) |
5794 | 1816 { |
1817 return SET_NONEMPTY_INTERNAL_STRING_VARIABLE (octave_core_file_options); | |
1818 } | |
2194 | 1819 |
5794 | 1820 DEFUN (save_header_format_string, args, nargout, |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1821 doc: /* -*- texinfo -*- |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1822 @deftypefn {} {@var{val} =} save_header_format_string () |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1823 @deftypefnx {} {@var{old_val} =} save_header_format_string (@var{new_val}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1824 @deftypefnx {} {} save_header_format_string (@var{new_val}, "local") |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1825 Query or set the internal variable that specifies the format |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1826 string used for the comment line written at the beginning of |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1827 text-format data files saved by Octave. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1828 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1829 The format string is passed to @code{strftime} and should begin with the |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1830 character @samp{#} and contain no newline characters. If the value of |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1831 @code{save_header_format_string} is the empty string, the header comment is |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1832 omitted from text-format data files. The default value is |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1833 @c Set example in small font to prevent overfull line |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1834 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1835 @smallexample |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1836 "# Created by Octave VERSION, %a %b %d %H:%M:%S %Y %Z <USER@@HOST>" |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1837 @end smallexample |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1838 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1839 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:
21888
diff
changeset
|
1840 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:
21888
diff
changeset
|
1841 The original variable value is restored when exiting the function. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1842 @seealso{strftime, save} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1843 @end deftypefn */) |
5794 | 1844 { |
1845 return SET_INTERNAL_VARIABLE (save_header_format_string); | |
2194 | 1846 } |
22407
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
1847 |