Mercurial > octave
annotate libinterp/corefcn/load-save.cc @ 25579:07c2c42f457e stable
doc: Miscellaneous documentation fixes all over the manual (bug #54288).
* embedded.cc, defaults.cc, error.cc, hex2num.cc, load-save.cc, integral2.m,
integral3.m, quad2d.m, warning_ids.m, decic.m, lsqnonneg.m, pqpnonneg.m,
bicg.m, betaincinv.m: Removal of duplicate words and redundant ')' and ';'
characters. Added missing '"', ')' characters. Renamed variables to match
other occurrences in docstring. Use '*' instead of 'x' for multiply.
Surround variables with @var{}.
author | Rik <rik@octave.org> |
---|---|
date | Wed, 11 Jul 2018 08:40:07 -0700 |
parents | c80323fe4938 |
children | c71d13bf2b63 cfc32b131755 |
rev | line source |
---|---|
6763 | 1 /* |
604 | 2 |
25054
6652d3823428
maint: Update copyright dates in all source files.
John W. Eaton <jwe@octave.org>
parents:
24986
diff
changeset
|
3 Copyright (C) 1994-2018 John W. Eaton |
604 | 4 |
5 This file is part of Octave. | |
6 | |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
24456
diff
changeset
|
7 Octave is free software: you can redistribute it and/or modify it |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
8 under the terms of the GNU General Public License as published by |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
24456
diff
changeset
|
9 the Free Software Foundation, either version 3 of the License, or |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
10 (at your option) any later version. |
604 | 11 |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
12 Octave is distributed in the hope that it will be useful, but |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
13 WITHOUT ANY WARRANTY; without even the implied warranty of |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
15 GNU General Public License for more details. |
604 | 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 |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
24456
diff
changeset
|
19 <https://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 <cstring> |
32 | |
4249 | 33 #include <fstream> |
3503 | 34 #include <iomanip> |
35 #include <iostream> | |
23455
73ff72d3d603
maint: Eliminate <cfloat.h> header from libinterp files
Rik <rik@octave.org>
parents:
23450
diff
changeset
|
36 #include <list> |
5765 | 37 #include <sstream> |
1728 | 38 #include <string> |
39 | |
1961 | 40 #include "byte-swap.h" |
23455
73ff72d3d603
maint: Eliminate <cfloat.h> header from libinterp files
Rik <rik@octave.org>
parents:
23450
diff
changeset
|
41 #include "dMatrix.h" |
1961 | 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" |
23599
5cb3a2bb5e1e
don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents:
23584
diff
changeset
|
59 #include "interpreter-private.h" |
6159 | 60 #include "load-path.h" |
1352 | 61 #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
|
62 #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
|
63 #include "ovl.h" |
3687 | 64 #include "oct-map.h" |
4332 | 65 #include "ov-cell.h" |
1352 | 66 #include "pager.h" |
1750 | 67 #include "pt-exp.h" |
1352 | 68 #include "symtab.h" |
69 #include "sysdep.h" | |
70 #include "unwind-prot.h" | |
604 | 71 #include "utils.h" |
2371 | 72 #include "variables.h" |
3185 | 73 #include "version.h" |
3688 | 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 () |
23807
336f89b6208b
Use character literals 'c' rather than string literals "c" when possible.
Rik <rik@octave.org>
parents:
23803
diff
changeset
|
118 + '@' |
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 () |
23807
336f89b6208b
Use character literals 'c' rather than string literals "c" when possible.
Rik <rik@octave.org>
parents:
23803
diff
changeset
|
120 + '>'; |
5794 | 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 { |
23693
b9378eff6d13
move symbol_table class inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
148 octave::symbol_table& symtab |
24287
ad0ca13aa6e2
Fix typo: varaible -> variable.
John W. Eaton <jwe@octave.org>
parents:
24270
diff
changeset
|
149 = octave::__get_symbol_table__ ("install_loaded_variable"); |
23611
91c8f006ed8b
remove additional functions from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
23603
diff
changeset
|
150 |
24361
8bcfddad15ec
use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents:
24356
diff
changeset
|
151 octave::symbol_scope scope |
23611
91c8f006ed8b
remove additional functions from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
23603
diff
changeset
|
152 = symtab.require_current_scope ("install_loaded_variable"); |
23599
5cb3a2bb5e1e
don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents:
23584
diff
changeset
|
153 |
604 | 154 if (global) |
155 { | |
25201
c80323fe4938
improve handling of global symbols (bug #53599)
John W. Eaton <jwe@octave.org>
parents:
25106
diff
changeset
|
156 octave::symbol_record sym = scope.find_symbol (name); |
c80323fe4938
improve handling of global symbols (bug #53599)
John W. Eaton <jwe@octave.org>
parents:
25106
diff
changeset
|
157 |
c80323fe4938
improve handling of global symbols (bug #53599)
John W. Eaton <jwe@octave.org>
parents:
25106
diff
changeset
|
158 if (! sym.is_global ()) |
c80323fe4938
improve handling of global symbols (bug #53599)
John W. Eaton <jwe@octave.org>
parents:
25106
diff
changeset
|
159 { |
c80323fe4938
improve handling of global symbols (bug #53599)
John W. Eaton <jwe@octave.org>
parents:
25106
diff
changeset
|
160 octave::symbol_scope global_scope = symtab.global_scope (); |
c80323fe4938
improve handling of global symbols (bug #53599)
John W. Eaton <jwe@octave.org>
parents:
25106
diff
changeset
|
161 octave::symbol_record global_sym = global_scope.find_symbol (name); |
c80323fe4938
improve handling of global symbols (bug #53599)
John W. Eaton <jwe@octave.org>
parents:
25106
diff
changeset
|
162 |
c80323fe4938
improve handling of global symbols (bug #53599)
John W. Eaton <jwe@octave.org>
parents:
25106
diff
changeset
|
163 sym.bind_fwd_rep (global_scope.get_rep (), global_sym); |
c80323fe4938
improve handling of global symbols (bug #53599)
John W. Eaton <jwe@octave.org>
parents:
25106
diff
changeset
|
164 } |
604 | 165 } |
25201
c80323fe4938
improve handling of global symbols (bug #53599)
John W. Eaton <jwe@octave.org>
parents:
25106
diff
changeset
|
166 |
c80323fe4938
improve handling of global symbols (bug #53599)
John W. Eaton <jwe@octave.org>
parents:
25106
diff
changeset
|
167 scope.assign (name, val); |
604 | 168 } |
169 | |
3019 | 170 // Return TRUE if NAME matches one of the given globbing PATTERNS. |
604 | 171 |
3013 | 172 static bool |
3769 | 173 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
|
174 int num_pat, const std::string& name) |
604 | 175 { |
1755 | 176 for (int i = pat_idx; i < num_pat; i++) |
604 | 177 { |
1792 | 178 glob_match pattern (patterns[i]); |
3013 | 179 |
1792 | 180 if (pattern.match (name)) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
181 return true; |
604 | 182 } |
3688 | 183 |
3013 | 184 return false; |
604 | 185 } |
186 | |
4329 | 187 int |
3523 | 188 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
|
189 octave::mach_info::float_format& flt_fmt, bool quiet) |
604 | 190 { |
3552 | 191 const int magic_len = 10; |
192 char magic[magic_len+1]; | |
5760 | 193 is.read (magic, magic_len); |
604 | 194 magic[magic_len] = '\0'; |
3688 | 195 |
604 | 196 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
|
197 swap = octave::mach_info::words_big_endian (); |
604 | 198 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
|
199 swap = ! octave::mach_info::words_big_endian (); |
604 | 200 else |
201 { | |
202 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
|
203 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
|
204 |
604 | 205 return -1; |
206 } | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
207 |
604 | 208 char tmp = 0; |
5760 | 209 is.read (&tmp, 1); |
604 | 210 |
2318 | 211 flt_fmt = mopt_digit_to_float_format (tmp); |
212 | |
21739
c4ab2e54f100
use namespace for oct_mach_info class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
213 if (flt_fmt == octave::mach_info::flt_fmt_unknown) |
604 | 214 { |
215 if (! quiet) | |
216 error ("load: unrecognized binary format!"); | |
3688 | 217 |
604 | 218 return -1; |
219 } | |
220 | |
221 return 0; | |
222 } | |
223 | |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21691
diff
changeset
|
224 #if defined (HAVE_ZLIB) |
5269 | 225 static bool |
226 check_gzip_magic (const std::string& fname) | |
227 { | |
228 bool retval = false; | |
21972
d31e0f704d0b
Open files in binary mode when testing file format (bug #48201).
Rik <rik@octave.org>
parents:
21966
diff
changeset
|
229 |
d31e0f704d0b
Open files in binary mode when testing file format (bug #48201).
Rik <rik@octave.org>
parents:
21966
diff
changeset
|
230 std::ifstream file (fname.c_str (), std::ios::in | std::ios::binary); |
5269 | 231 |
23777
cda0614beaec
Replace static instances of OCTAVE_LOCAL_BUFFER with local variables.
Rik <rik@octave.org>
parents:
23693
diff
changeset
|
232 unsigned char magic[2]; |
cda0614beaec
Replace static instances of OCTAVE_LOCAL_BUFFER with local variables.
Rik <rik@octave.org>
parents:
23693
diff
changeset
|
233 if (file.read (reinterpret_cast<char *> (&magic[0]), 2) |
cda0614beaec
Replace static instances of OCTAVE_LOCAL_BUFFER with local variables.
Rik <rik@octave.org>
parents:
23693
diff
changeset
|
234 && magic[0] == 0x1f && magic[1] == 0x8b) |
5269 | 235 retval = true; |
236 | |
237 file.close (); | |
23777
cda0614beaec
Replace static instances of OCTAVE_LOCAL_BUFFER with local variables.
Rik <rik@octave.org>
parents:
23693
diff
changeset
|
238 |
5269 | 239 return retval; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
240 } |
5269 | 241 #endif |
242 | |
604 | 243 static load_save_format |
6625 | 244 get_file_format (std::istream& file, const std::string& filename) |
604 | 245 { |
246 load_save_format retval = LS_UNKNOWN; | |
247 | |
21739
c4ab2e54f100
use namespace for oct_mach_info class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
248 octave::mach_info::float_format flt_fmt = octave::mach_info::flt_fmt_unknown; |
604 | 249 |
3019 | 250 bool swap = false; |
251 | |
252 if (read_binary_file_header (file, swap, flt_fmt, true) == 0) | |
604 | 253 retval = LS_BINARY; |
254 else | |
255 { | |
6202 | 256 file.clear (); |
3538 | 257 file.seekg (0, std::ios::beg); |
604 | 258 |
5828 | 259 int32_t mopt, nr, nc, imag, len; |
1180 | 260 |
16555
04fb96f4bea1
allow double-click in file browser to load data files
John W. Eaton <jwe@octave.org>
parents:
16442
diff
changeset
|
261 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
|
262 true); |
1180 | 263 |
264 if (! err) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
265 retval = LS_MAT_BINARY; |
604 | 266 else |
10315
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); |
604 | 270 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
271 err = read_mat5_binary_file_header (file, swap, true, filename); |
3688 | 272 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
273 if (! err) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
274 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
275 file.clear (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
276 file.seekg (0, std::ios::beg); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
277 retval = LS_MAT5_BINARY; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
278 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
279 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
280 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
281 file.clear (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
282 file.seekg (0, std::ios::beg); |
3688 | 283 |
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
|
284 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
|
285 std::string type_val = extract_keyword (file, "type"); |
4171 | 286 |
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
|
287 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
|
288 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
|
289 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
|
290 { |
ca5103ab0b21
check_gzip_magic before get_file_format (wrong type detection, bug #39652)
Andreas Weber <andy.weber.aw@gmail.com>
parents:
17170
diff
changeset
|
291 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
|
292 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
|
293 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17755
diff
changeset
|
294 // 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
|
295 // 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
|
296 // 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
|
297 // 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
|
298 // 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
|
299 |
ca5103ab0b21
check_gzip_magic before get_file_format (wrong type detection, bug #39652)
Andreas Weber <andy.weber.aw@gmail.com>
parents:
17170
diff
changeset
|
300 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
|
301 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
|
302 } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
303 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
304 } |
604 | 305 } |
306 | |
5269 | 307 return retval; |
308 } | |
5977 | 309 |
5269 | 310 static load_save_format |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
311 get_file_format (const std::string& fname, const std::string& orig_fname, |
23433
c9fab0bc983e
maint: Use convention 'int& x' for naming references.
Rik <rik@octave.org>
parents:
23432
diff
changeset
|
312 bool& use_zlib, bool quiet = false) |
5269 | 313 { |
314 load_save_format retval = LS_UNKNOWN; | |
315 | |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21691
diff
changeset
|
316 #if defined (HAVE_HDF5) |
5269 | 317 // check this before we open the file |
318 if (H5Fis_hdf5 (fname.c_str ()) > 0) | |
319 return LS_HDF5; | |
20945
9d9270e2f98f
eliminate comments after preprocessor conditionals
John W. Eaton <jwe@octave.org>
parents:
20940
diff
changeset
|
320 #endif |
604 | 321 |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21691
diff
changeset
|
322 #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
|
323 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
|
324 #else |
5269 | 325 use_zlib = false; |
5977 | 326 #endif |
5269 | 327 |
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
|
328 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
|
329 { |
21972
d31e0f704d0b
Open files in binary mode when testing file format (bug #48201).
Rik <rik@octave.org>
parents:
21966
diff
changeset
|
330 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
|
331 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
|
332 { |
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 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
|
334 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
|
335 } |
ca5103ab0b21
check_gzip_magic before get_file_format (wrong type detection, bug #39652)
Andreas Weber <andy.weber.aw@gmail.com>
parents:
17170
diff
changeset
|
336 else if (! quiet) |
21102
dfcb9d74b253
Rename local gripe_XXX functions to err_XXX or warn_XXX.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
337 err_file_open ("load", orig_fname); |
5269 | 338 } |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21691
diff
changeset
|
339 #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
|
340 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
|
341 { |
21972
d31e0f704d0b
Open files in binary mode when testing file format (bug #48201).
Rik <rik@octave.org>
parents:
21966
diff
changeset
|
342 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
|
343 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
|
344 { |
ca5103ab0b21
check_gzip_magic before get_file_format (wrong type detection, bug #39652)
Andreas Weber <andy.weber.aw@gmail.com>
parents:
17170
diff
changeset
|
345 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
|
346 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
|
347 } |
ca5103ab0b21
check_gzip_magic before get_file_format (wrong type detection, bug #39652)
Andreas Weber <andy.weber.aw@gmail.com>
parents:
17170
diff
changeset
|
348 else if (! quiet) |
21102
dfcb9d74b253
Rename local gripe_XXX functions to err_XXX or warn_XXX.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
349 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
|
350 } |
ca5103ab0b21
check_gzip_magic before get_file_format (wrong type detection, bug #39652)
Andreas Weber <andy.weber.aw@gmail.com>
parents:
17170
diff
changeset
|
351 #endif |
604 | 352 |
353 return retval; | |
354 } | |
355 | |
4329 | 356 octave_value |
7336 | 357 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
|
358 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
|
359 bool list_only, bool swap, bool verbose, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
360 const string_vector& argv, int argv_idx, int argc, int nargout) |
604 | 361 { |
3727 | 362 octave_value retval; |
363 | |
11059
4ffa19147604
replace Octave_map->octave_scalar_map in help.cc and load-save.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
10846
diff
changeset
|
364 octave_scalar_map retstruct; |
604 | 365 |
5765 | 366 std::ostringstream output_buf; |
7779
791231dac333
Add regexp matching to Fwho and Fclear
David Bateman <dbateman@free.fr>
parents:
7767
diff
changeset
|
367 std::list<std::string> symbol_names; |
4051 | 368 |
5754 | 369 octave_idx_type count = 0; |
4051 | 370 |
604 | 371 for (;;) |
372 { | |
3019 | 373 bool global = false; |
2086 | 374 octave_value tc; |
604 | 375 |
4171 | 376 std::string name; |
377 std::string doc; | |
604 | 378 |
8425
2e777f5135a3
support -tabs option for save -ascii
Jaroslav Hajek <highegg@gmail.com>
parents:
8418
diff
changeset
|
379 switch (format.type) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
380 { |
20447
c6224b4e7774
maint: Rename instances of LS_ASCII to LS_TEXT for clarity.
Rik <rik@octave.org>
parents:
20443
diff
changeset
|
381 case LS_TEXT: |
c6224b4e7774
maint: Rename instances of LS_ASCII to LS_TEXT for clarity.
Rik <rik@octave.org>
parents:
20443
diff
changeset
|
382 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
|
383 break; |
604 | 384 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
385 case LS_BINARY: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
386 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
|
387 global, tc, doc); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
388 break; |
604 | 389 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
390 case LS_MAT_ASCII: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
391 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
|
392 break; |
2511 | 393 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
394 case LS_MAT_BINARY: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
395 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
|
396 break; |
604 | 397 |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21691
diff
changeset
|
398 #if defined (HAVE_HDF5) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
399 case LS_HDF5: |
17709
5415a9cd61d4
Implement faster partial loading of HDF5 files.
Rik <rik@octave.org>
parents:
17349
diff
changeset
|
400 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
|
401 argv, argv_idx, argc); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
402 break; |
20945
9d9270e2f98f
eliminate comments after preprocessor conditionals
John W. Eaton <jwe@octave.org>
parents:
20940
diff
changeset
|
403 #endif |
3687 | 404 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
405 case LS_MAT5_BINARY: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
406 case LS_MAT7_BINARY: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
407 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
|
408 global, tc); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
409 break; |
3688 | 410 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
411 default: |
21100
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
21040
diff
changeset
|
412 err_unrecognized_data_fmt ("load"); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
413 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
414 } |
604 | 415 |
20741
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20727
diff
changeset
|
416 if (stream.eof () || name.empty ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
417 break; |
20443
610c74748518
maint: Clean up code based on static analysis suggestions.
Rik <rik@octave.org>
parents:
20389
diff
changeset
|
418 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
419 { |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
420 if (! tc.is_defined ()) |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
421 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
|
422 |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
423 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
|
424 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
|
425 orig_fname.c_str ()); |
3136 | 426 |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
427 if (format == LS_MAT_ASCII |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
428 || argv_idx == argc |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
429 || matches_patterns (argv, argv_idx, argc, name)) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
430 { |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
431 count++; |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
432 if (list_only) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
433 { |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
434 if (verbose) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
435 { |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
436 if (count == 1) |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
437 output_buf |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
438 << "type rows cols name\n" |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
439 << "==== ==== ==== ====\n"; |
621 | 440 |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
441 output_buf |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
442 << 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
|
443 << 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
|
444 << std::setiosflags (std::ios::right) |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
445 << std::setw (7) << tc.rows () |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
446 << std::setw (7) << tc.columns () |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
447 << " " << name << "\n"; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
448 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
449 else |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
450 symbol_names.push_back (name); |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
451 } |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
452 else |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
453 { |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
454 if (nargout == 1) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
455 { |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
456 if (format == LS_MAT_ASCII) |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
457 retval = tc; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
458 else |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
459 retstruct.assign (name, tc); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
460 } |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
461 else |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
462 install_loaded_variable (name, tc, global, doc); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
463 } |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
464 } |
2511 | 465 |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
466 // Only attempt to read one item from a headless text file. |
2511 | 467 |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
468 if (format == LS_MAT_ASCII) |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
469 break; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
470 } |
604 | 471 } |
472 | |
621 | 473 if (list_only && count) |
474 { | |
7779
791231dac333
Add regexp matching to Fwho and Fclear
David Bateman <dbateman@free.fr>
parents:
7767
diff
changeset
|
475 if (verbose) |
10315
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 std::string msg = output_buf.str (); |
2095 | 478 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
479 if (nargout > 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
480 retval = msg; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
481 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
482 octave_stdout << msg; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
483 } |
621 | 484 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
485 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
486 if (nargout > 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
487 retval = Cell (string_vector (symbol_names)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
488 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
489 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
490 string_vector names (symbol_names); |
7779
791231dac333
Add regexp matching to Fwho and Fclear
David Bateman <dbateman@free.fr>
parents:
7767
diff
changeset
|
491 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
492 names.list_in_columns (octave_stdout); |
7779
791231dac333
Add regexp matching to Fwho and Fclear
David Bateman <dbateman@free.fr>
parents:
7767
diff
changeset
|
493 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
494 octave_stdout << "\n"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
495 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
496 } |
621 | 497 } |
6639 | 498 else if (retstruct.nfields () != 0) |
3727 | 499 retval = retstruct; |
621 | 500 |
863 | 501 return retval; |
502 } | |
503 | |
23143
898c33f4b9c0
declare some functions that are only used once "static"
John W. Eaton <jwe@octave.org>
parents:
23084
diff
changeset
|
504 static std::string |
6159 | 505 find_file_to_load (const std::string& name, const std::string& orig_name) |
506 { | |
19030
9ef10e6a5987
make "file found in path" warnings consistent
John W. Eaton <jwe@octave.org>
parents:
18949
diff
changeset
|
507 std::string fname = find_data_file_in_load_path ("load", name, true); |
6159 | 508 |
23807
336f89b6208b
Use character literals 'c' rather than string literals "c" when possible.
Rik <rik@octave.org>
parents:
23803
diff
changeset
|
509 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
|
510 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
|
511 |
8021 | 512 if (dot_pos == std::string::npos |
513 || (sep_pos != std::string::npos && dot_pos < sep_pos)) | |
6159 | 514 { |
6838 | 515 // Either no '.' in name or no '.' appears after last directory |
516 // separator. | |
517 | |
21736
0504351a45e6
use namespace for file_stat classes
John W. Eaton <jwe@octave.org>
parents:
21733
diff
changeset
|
518 octave::sys::file_stat fs (fname); |
6159 | 519 |
6584 | 520 if (! (fs.exists () && fs.is_reg ())) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
521 fname = find_file_to_load (fname + ".mat", orig_name); |
6159 | 522 } |
523 else | |
524 { | |
21736
0504351a45e6
use namespace for file_stat classes
John W. Eaton <jwe@octave.org>
parents:
21733
diff
changeset
|
525 octave::sys::file_stat fs (fname); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
526 |
6584 | 527 if (! (fs.exists () && fs.is_reg ())) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
528 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
529 fname = ""; |
6159 | 530 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
531 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
|
532 } |
6159 | 533 } |
534 | |
535 return fname; | |
536 } | |
537 | |
16555
04fb96f4bea1
allow double-click in file browser to load data files
John W. Eaton <jwe@octave.org>
parents:
16442
diff
changeset
|
538 bool |
04fb96f4bea1
allow double-click in file browser to load data files
John W. Eaton <jwe@octave.org>
parents:
16442
diff
changeset
|
539 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
|
540 { |
04fb96f4bea1
allow double-click in file browser to load data files
John W. Eaton <jwe@octave.org>
parents:
16442
diff
changeset
|
541 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
|
542 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
|
543 } |
6159 | 544 |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8676
diff
changeset
|
545 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
|
546 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
|
547 @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
|
548 @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
|
549 @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
|
550 @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
|
551 @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
|
552 @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
|
553 @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
|
554 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
|
555 @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
|
556 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
557 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
|
558 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
|
559 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
|
560 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
|
561 option. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
562 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
563 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
|
564 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
565 @example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
566 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
|
567 @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
|
568 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
569 @noindent |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
570 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
|
571 (@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
|
572 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
573 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
|
574 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
|
575 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
|
576 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
|
577 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
|
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 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
|
580 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
|
581 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
|
582 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
|
583 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
|
584 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
585 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
|
586 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
|
587 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
|
588 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
|
589 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
|
590 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
|
591 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
592 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
|
593 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
594 @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
|
595 @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
|
596 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
|
597 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
|
598 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
|
599 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
600 @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
|
601 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
|
602 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
|
603 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
|
604 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
|
605 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
606 @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
|
607 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
|
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 -hdf5 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
610 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
|
611 (@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
|
612 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
|
613 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
|
614 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
|
615 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
|
616 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
617 @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
|
618 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
|
619 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
|
620 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
|
621 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
622 @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
|
623 @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
|
624 @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
|
625 @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
|
626 @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
|
627 @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
|
628 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
|
629 format. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
630 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
631 @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
|
632 @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
|
633 @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
|
634 @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
|
635 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
|
636 @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
|
637 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
638 @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
|
639 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
|
640 @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
|
641 @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
|
642 @end deftypefn */) |
863 | 643 { |
2086 | 644 octave_value_list retval; |
863 | 645 |
1755 | 646 int argc = args.length () + 1; |
647 | |
1968 | 648 string_vector argv = args.make_argv ("load"); |
1755 | 649 |
12895
8edece28cf4d
Allow Matlab-style syntax for load command (Bug #33527).
Rik <octave@nomad.inbox5.com>
parents:
12661
diff
changeset
|
650 int i = 1; |
8edece28cf4d
Allow Matlab-style syntax for load command (Bug #33527).
Rik <octave@nomad.inbox5.com>
parents:
12661
diff
changeset
|
651 std::string orig_fname = ""; |
8edece28cf4d
Allow Matlab-style syntax for load command (Bug #33527).
Rik <octave@nomad.inbox5.com>
parents:
12661
diff
changeset
|
652 |
8edece28cf4d
Allow Matlab-style syntax for load command (Bug #33527).
Rik <octave@nomad.inbox5.com>
parents:
12661
diff
changeset
|
653 // 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
|
654 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
|
655 { |
8edece28cf4d
Allow Matlab-style syntax for load command (Bug #33527).
Rik <octave@nomad.inbox5.com>
parents:
12661
diff
changeset
|
656 orig_fname = argv[1]; |
8edece28cf4d
Allow Matlab-style syntax for load command (Bug #33527).
Rik <octave@nomad.inbox5.com>
parents:
12661
diff
changeset
|
657 i++; |
8edece28cf4d
Allow Matlab-style syntax for load command (Bug #33527).
Rik <octave@nomad.inbox5.com>
parents:
12661
diff
changeset
|
658 } |
8edece28cf4d
Allow Matlab-style syntax for load command (Bug #33527).
Rik <octave@nomad.inbox5.com>
parents:
12661
diff
changeset
|
659 |
1358 | 660 // It isn't necessary to have the default load format stored in a |
661 // user preference variable since we can determine the type of file | |
662 // as we are reading. | |
863 | 663 |
664 load_save_format format = LS_UNKNOWN; | |
665 | |
3019 | 666 bool list_only = false; |
667 bool verbose = false; | |
863 | 668 |
13026
9a2a6054460f
maint: Fix 2 compiler warnings
Rik <octave@nomad.inbox5.com>
parents:
12895
diff
changeset
|
669 for (; i < argc; i++) |
863 | 670 { |
1755 | 671 if (argv[i] == "-force" || argv[i] == "-f") |
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 // Silently ignore this |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
674 // warning ("load: -force ignored"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
675 } |
1755 | 676 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
|
677 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
678 list_only = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
679 } |
1755 | 680 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
|
681 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
682 verbose = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
683 } |
1755 | 684 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
|
685 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
686 format = LS_MAT_ASCII; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
687 } |
1755 | 688 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
|
689 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
690 format = LS_BINARY; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
691 } |
5269 | 692 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
|
693 || argv[i] == "-6" || argv[i] == "-v6") |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
694 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
695 format = LS_MAT5_BINARY; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
696 } |
7819
b7e8ea6a5143
trivial fix option in Fload
Jaroslav Hajek <highegg@gmail.com>
parents:
7779
diff
changeset
|
697 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
|
698 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
699 format = LS_MAT7_BINARY; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
700 } |
5256 | 701 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
|
702 || argv[i] == "-v4" || argv[i] == "-4") |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
703 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
704 format = LS_MAT_BINARY; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
705 } |
3687 | 706 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
|
707 { |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21691
diff
changeset
|
708 #if defined (HAVE_HDF5) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
709 format = LS_HDF5; |
20945
9d9270e2f98f
eliminate comments after preprocessor conditionals
John W. Eaton <jwe@octave.org>
parents:
20940
diff
changeset
|
710 #else |
21109
bd1752782e56
Use err_disabled_feature, warn_disabled_feature throughout code base.
Rik <rik@octave.org>
parents:
21102
diff
changeset
|
711 err_disabled_feature ("load", "HDF5"); |
20945
9d9270e2f98f
eliminate comments after preprocessor conditionals
John W. Eaton <jwe@octave.org>
parents:
20940
diff
changeset
|
712 #endif |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
713 } |
3687 | 714 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
|
715 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
716 warning ("load: -import ignored"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
717 } |
5197 | 718 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
|
719 { |
20447
c6224b4e7774
maint: Rename instances of LS_ASCII to LS_TEXT for clarity.
Rik <rik@octave.org>
parents:
20443
diff
changeset
|
720 format = LS_TEXT; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
721 } |
863 | 722 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
723 break; |
863 | 724 } |
725 | |
12895
8edece28cf4d
Allow Matlab-style syntax for load command (Bug #33527).
Rik <octave@nomad.inbox5.com>
parents:
12661
diff
changeset
|
726 if (orig_fname == "") |
863 | 727 { |
12895
8edece28cf4d
Allow Matlab-style syntax for load command (Bug #33527).
Rik <octave@nomad.inbox5.com>
parents:
12661
diff
changeset
|
728 if (i == argc) |
20801
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20741
diff
changeset
|
729 print_usage (); |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20741
diff
changeset
|
730 |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20741
diff
changeset
|
731 orig_fname = argv[i]; |
863 | 732 } |
12895
8edece28cf4d
Allow Matlab-style syntax for load command (Bug #33527).
Rik <octave@nomad.inbox5.com>
parents:
12661
diff
changeset
|
733 else |
8edece28cf4d
Allow Matlab-style syntax for load command (Bug #33527).
Rik <octave@nomad.inbox5.com>
parents:
12661
diff
changeset
|
734 i--; |
863 | 735 |
21739
c4ab2e54f100
use namespace for oct_mach_info class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
736 octave::mach_info::float_format flt_fmt = octave::mach_info::flt_fmt_unknown; |
863 | 737 |
3019 | 738 bool swap = false; |
863 | 739 |
12895
8edece28cf4d
Allow Matlab-style syntax for load command (Bug #33527).
Rik <octave@nomad.inbox5.com>
parents:
12661
diff
changeset
|
740 if (orig_fname == "-") |
863 | 741 { |
1755 | 742 i++; |
863 | 743 |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21691
diff
changeset
|
744 #if defined (HAVE_HDF5) |
3687 | 745 if (format == LS_HDF5) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
746 error ("load: cannot read HDF5 format from stdin"); |
3687 | 747 else |
20945
9d9270e2f98f
eliminate comments after preprocessor conditionals
John W. Eaton <jwe@octave.org>
parents:
20940
diff
changeset
|
748 #endif |
863 | 749 if (format != LS_UNKNOWN) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
750 { |
17861
870f3e12e163
maint: Use phrase "FIXME:" for problem areas in code.
Rik <rik@octave.org>
parents:
17787
diff
changeset
|
751 // 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
|
752 // 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
|
753 // 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
|
754 // using std::cin only. |
3531 | 755 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
756 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
|
757 list_only, swap, verbose, argv, i, argc, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
758 nargout); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
759 } |
863 | 760 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
761 error ("load: must specify file format if reading from stdin"); |
863 | 762 } |
763 else | |
764 { | |
21733
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
765 std::string fname = octave::sys::file_ops::tilde_expand (orig_fname); |
6159 | 766 |
767 fname = find_file_to_load (fname, orig_fname); | |
863 | 768 |
6159 | 769 bool use_zlib = false; |
5089 | 770 |
863 | 771 if (format == LS_UNKNOWN) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
772 format = get_file_format (fname, orig_fname, use_zlib); |
863 | 773 |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21691
diff
changeset
|
774 #if defined (HAVE_HDF5) |
3687 | 775 if (format == LS_HDF5) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
776 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
777 i++; |
3687 | 778 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
779 hdf5_ifstream hdf5_file (fname.c_str ()); |
3687 | 780 |
21118
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21109
diff
changeset
|
781 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
|
782 err_file_open ("load", orig_fname); |
4844 | 783 |
21118
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21109
diff
changeset
|
784 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
|
785 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
|
786 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
|
787 |
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21109
diff
changeset
|
788 hdf5_file.close (); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
789 } |
3687 | 790 else |
20945
9d9270e2f98f
eliminate comments after preprocessor conditionals
John W. Eaton <jwe@octave.org>
parents:
20940
diff
changeset
|
791 #endif |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
792 // 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
|
793 // go with the "if" below!!!!! |
863 | 794 if (format != LS_UNKNOWN) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
795 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
796 i++; |
863 | 797 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
798 // Always open in binary mode and handle various |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
799 // line-endings explicitly. |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
800 std::ios::openmode mode = std::ios::in | std::ios::binary; |
863 | 801 |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21691
diff
changeset
|
802 #if defined (HAVE_ZLIB) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
803 if (use_zlib) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
804 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
805 gzifstream file (fname.c_str (), mode); |
863 | 806 |
21118
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21109
diff
changeset
|
807 if (! file) |
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21109
diff
changeset
|
808 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
|
809 |
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21109
diff
changeset
|
810 if (format == LS_BINARY) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
811 { |
21118
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21109
diff
changeset
|
812 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
|
813 { |
21118
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21109
diff
changeset
|
814 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
|
815 return retval; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
816 } |
21118
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21109
diff
changeset
|
817 } |
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21109
diff
changeset
|
818 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
|
819 || 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
|
820 { |
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21109
diff
changeset
|
821 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
|
822 orig_fname) < 0) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
823 { |
21118
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21109
diff
changeset
|
824 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
|
825 return retval; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
826 } |
21118
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21109
diff
changeset
|
827 } |
5269 | 828 |
21118
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21109
diff
changeset
|
829 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
|
830 flt_fmt, list_only, swap, verbose, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
831 argv, i, argc, nargout); |
5269 | 832 |
21118
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21109
diff
changeset
|
833 file.close (); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
834 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
835 else |
5269 | 836 #endif |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
837 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
838 std::ifstream file (fname.c_str (), mode); |
5269 | 839 |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
840 if (! file) |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14268
diff
changeset
|
841 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
|
842 orig_fname.c_str ()); |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
843 |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
844 if (format == LS_BINARY) |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
845 { |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
846 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
|
847 { |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
848 if (file) file.close (); |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
849 return retval; |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
850 } |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
851 } |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
852 else if (format == LS_MAT5_BINARY |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
853 || format == LS_MAT7_BINARY) |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
854 { |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
855 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
|
856 orig_fname) < 0) |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
857 { |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
858 if (file) file.close (); |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
859 return retval; |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
860 } |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
861 } |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
862 |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
863 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
|
864 flt_fmt, list_only, swap, verbose, |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
865 argv, i, argc, nargout); |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
866 |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
867 file.close (); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
868 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
869 } |
19387
616f2b22787b
Issue error if load file format cannot be determined (bug #43575).
Rik <rik@octave.org>
parents:
18853
diff
changeset
|
870 else |
20956
850e3d2533d4
maint: Eliminate more useless statements after error().
Rik <rik@octave.org>
parents:
20945
diff
changeset
|
871 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
|
872 orig_fname.c_str ()); |
850e3d2533d4
maint: Eliminate more useless statements after error().
Rik <rik@octave.org>
parents:
20945
diff
changeset
|
873 |
863 | 874 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
875 |
604 | 876 return retval; |
877 } | |
878 | |
3019 | 879 // Return TRUE if PATTERN has any special globbing chars in it. |
880 | |
881 static bool | |
3523 | 882 glob_pattern_p (const std::string& pattern) |
604 | 883 { |
884 int open = 0; | |
885 | |
1755 | 886 int len = pattern.length (); |
887 | |
888 for (int i = 0; i < len; i++) | |
604 | 889 { |
1755 | 890 char c = pattern[i]; |
891 | |
604 | 892 switch (c) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
893 { |
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 case '*': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
896 return true; |
604 | 897 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
898 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
|
899 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
|
900 continue; // complete, according to Posix.2 |
604 | 901 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
902 case ']': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
903 if (open) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
904 return true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
905 continue; |
4402 | 906 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
907 case '\\': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
908 if (i == len - 1) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
909 return false; |
23800
2fdc65c031b5
Add break or continue statements to prevent implicit fall-through in case statements.
Rik <rik@octave.org>
parents:
23795
diff
changeset
|
910 continue; |
604 | 911 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
912 default: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
913 continue; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
914 } |
604 | 915 } |
916 | |
3019 | 917 return false; |
604 | 918 } |
919 | |
4791 | 920 static void |
921 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
|
922 const std::string& name, const std::string& help, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
923 bool global, load_save_format fmt, bool save_as_floats) |
604 | 924 { |
8425
2e777f5135a3
support -tabs option for save -ascii
Jaroslav Hajek <highegg@gmail.com>
parents:
8418
diff
changeset
|
925 switch (fmt.type) |
604 | 926 { |
20447
c6224b4e7774
maint: Rename instances of LS_ASCII to LS_TEXT for clarity.
Rik <rik@octave.org>
parents:
20443
diff
changeset
|
927 case LS_TEXT: |
c6224b4e7774
maint: Rename instances of LS_ASCII to LS_TEXT for clarity.
Rik <rik@octave.org>
parents:
20443
diff
changeset
|
928 save_text_data (os, tc, name, global, 0); |
604 | 929 break; |
930 | |
931 case LS_BINARY: | |
630 | 932 save_binary_data (os, tc, name, help, global, save_as_floats); |
604 | 933 break; |
934 | |
5938 | 935 case LS_MAT_ASCII: |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
936 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
|
937 fmt.opts & LS_MAT_ASCII_TABS)) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
938 warning ("save: unable to save %s in ASCII format", name.c_str ()); |
5938 | 939 break; |
940 | |
667 | 941 case LS_MAT_BINARY: |
942 save_mat_binary_data (os, tc, name); | |
943 break; | |
944 | |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21691
diff
changeset
|
945 #if defined (HAVE_HDF5) |
3687 | 946 case LS_HDF5: |
947 save_hdf5_data (os, tc, name, help, global, save_as_floats); | |
948 break; | |
20945
9d9270e2f98f
eliminate comments after preprocessor conditionals
John W. Eaton <jwe@octave.org>
parents:
20940
diff
changeset
|
949 #endif |
3687 | 950 |
3688 | 951 case LS_MAT5_BINARY: |
5269 | 952 save_mat5_binary_element (os, tc, name, global, false, save_as_floats); |
953 break; | |
954 | |
955 case LS_MAT7_BINARY: | |
956 save_mat5_binary_element (os, tc, name, global, true, save_as_floats); | |
3688 | 957 break; |
958 | |
604 | 959 default: |
21100
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
21040
diff
changeset
|
960 err_unrecognized_data_fmt ("save"); |
604 | 961 break; |
962 } | |
963 } | |
964 | |
4791 | 965 // Save the info from SR on stream OS in the format specified by FMT. |
966 | |
967 void | |
24270
bc3819b7cca1
don't use symbol_table:: nesting for symbol_record, symbol_scope, or fcn_info
John W. Eaton <jwe@octave.org>
parents:
23985
diff
changeset
|
968 do_save (std::ostream& os, const octave::symbol_record& sr, |
24356
8b14ba8296af
refactor symbol_record object
John W. Eaton <jwe@octave.org>
parents:
24287
diff
changeset
|
969 octave::symbol_record::context_id context, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
970 load_save_format fmt, bool save_as_floats) |
4791 | 971 { |
24356
8b14ba8296af
refactor symbol_record object
John W. Eaton <jwe@octave.org>
parents:
24287
diff
changeset
|
972 octave_value val = sr.varval (context); |
4791 | 973 |
7336 | 974 if (val.is_defined ()) |
4791 | 975 { |
7336 | 976 std::string name = sr.name (); |
977 std::string help; | |
978 bool global = sr.is_global (); | |
4791 | 979 |
7336 | 980 do_save (os, val, name, help, global, fmt, save_as_floats); |
4791 | 981 } |
982 } | |
983 | |
7635
ba7a3e20ee3d
add -struct modifier to save
Jaroslav Hajek <highegg@gmail.com>
parents:
7336
diff
changeset
|
984 // 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
|
985 // in the format specified by FMT. |
ba7a3e20ee3d
add -struct modifier to save
Jaroslav Hajek <highegg@gmail.com>
parents:
7336
diff
changeset
|
986 |
ba7a3e20ee3d
add -struct modifier to save
Jaroslav Hajek <highegg@gmail.com>
parents:
7336
diff
changeset
|
987 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
|
988 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
|
989 const std::string& pattern, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
990 load_save_format fmt, bool save_as_floats) |
7635
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 glob_match pat (pattern); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
993 |
7635
ba7a3e20ee3d
add -struct modifier to save
Jaroslav Hajek <highegg@gmail.com>
parents:
7336
diff
changeset
|
994 size_t saved = 0; |
ba7a3e20ee3d
add -struct modifier to save
Jaroslav Hajek <highegg@gmail.com>
parents:
7336
diff
changeset
|
995 |
22862
e365e87371a3
maint: Use C++ range feature to simplify some for loops in libinterp/corefcn.
Rik <rik@octave.org>
parents:
22755
diff
changeset
|
996 for (octave_scalar_map::const_iterator it = m.begin (); it != m.end (); it++) |
7635
ba7a3e20ee3d
add -struct modifier to save
Jaroslav Hajek <highegg@gmail.com>
parents:
7336
diff
changeset
|
997 { |
ba7a3e20ee3d
add -struct modifier to save
Jaroslav Hajek <highegg@gmail.com>
parents:
7336
diff
changeset
|
998 std::string empty_str; |
ba7a3e20ee3d
add -struct modifier to save
Jaroslav Hajek <highegg@gmail.com>
parents:
7336
diff
changeset
|
999 |
22862
e365e87371a3
maint: Use C++ range feature to simplify some for loops in libinterp/corefcn.
Rik <rik@octave.org>
parents:
22755
diff
changeset
|
1000 if (pat.match (m.key (it))) |
7635
ba7a3e20ee3d
add -struct modifier to save
Jaroslav Hajek <highegg@gmail.com>
parents:
7336
diff
changeset
|
1001 { |
22862
e365e87371a3
maint: Use C++ range feature to simplify some for loops in libinterp/corefcn.
Rik <rik@octave.org>
parents:
22755
diff
changeset
|
1002 do_save (os, m.contents (it), m.key (it), empty_str, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1003 0, fmt, save_as_floats); |
7635
ba7a3e20ee3d
add -struct modifier to save
Jaroslav Hajek <highegg@gmail.com>
parents:
7336
diff
changeset
|
1004 |
ba7a3e20ee3d
add -struct modifier to save
Jaroslav Hajek <highegg@gmail.com>
parents:
7336
diff
changeset
|
1005 saved++; |
ba7a3e20ee3d
add -struct modifier to save
Jaroslav Hajek <highegg@gmail.com>
parents:
7336
diff
changeset
|
1006 } |
ba7a3e20ee3d
add -struct modifier to save
Jaroslav Hajek <highegg@gmail.com>
parents:
7336
diff
changeset
|
1007 } |
ba7a3e20ee3d
add -struct modifier to save
Jaroslav Hajek <highegg@gmail.com>
parents:
7336
diff
changeset
|
1008 |
ba7a3e20ee3d
add -struct modifier to save
Jaroslav Hajek <highegg@gmail.com>
parents:
7336
diff
changeset
|
1009 return saved; |
ba7a3e20ee3d
add -struct modifier to save
Jaroslav Hajek <highegg@gmail.com>
parents:
7336
diff
changeset
|
1010 } |
ba7a3e20ee3d
add -struct modifier to save
Jaroslav Hajek <highegg@gmail.com>
parents:
7336
diff
changeset
|
1011 |
604 | 1012 // Save variables with names matching PATTERN on stream OS in the |
5794 | 1013 // format specified by FMT. |
604 | 1014 |
7336 | 1015 static size_t |
5794 | 1016 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
|
1017 load_save_format fmt, bool save_as_floats) |
604 | 1018 { |
24361
8bcfddad15ec
use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents:
24356
diff
changeset
|
1019 octave::symbol_scope scope = octave::__require_current_scope__ ("save_vars"); |
23599
5cb3a2bb5e1e
don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents:
23584
diff
changeset
|
1020 |
24361
8bcfddad15ec
use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents:
24356
diff
changeset
|
1021 octave::symbol_record::context_id context = scope.current_context (); |
24356
8b14ba8296af
refactor symbol_record object
John W. Eaton <jwe@octave.org>
parents:
24287
diff
changeset
|
1022 |
24361
8bcfddad15ec
use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents:
24356
diff
changeset
|
1023 std::list<octave::symbol_record> vars = scope.glob (pattern); |
7336 | 1024 |
1025 size_t saved = 0; | |
3355 | 1026 |
22862
e365e87371a3
maint: Use C++ range feature to simplify some for loops in libinterp/corefcn.
Rik <rik@octave.org>
parents:
22755
diff
changeset
|
1027 for (const auto& var : vars) |
620 | 1028 { |
24356
8b14ba8296af
refactor symbol_record object
John W. Eaton <jwe@octave.org>
parents:
24287
diff
changeset
|
1029 do_save (os, var, context, fmt, save_as_floats); |
620 | 1030 |
7336 | 1031 saved++; |
620 | 1032 } |
604 | 1033 |
1034 return saved; | |
1035 } | |
1036 | |
8034
f61bd8e0d682
fix default_save_options parsing and allow mixing options with other arguments.
Jaroslav Hajek <highegg@gmail.com>
parents:
8021
diff
changeset
|
1037 static string_vector |
23433
c9fab0bc983e
maint: Use convention 'int& x' for naming references.
Rik <rik@octave.org>
parents:
23432
diff
changeset
|
1038 parse_save_options (const string_vector& argv, |
c9fab0bc983e
maint: Use convention 'int& x' for naming references.
Rik <rik@octave.org>
parents:
23432
diff
changeset
|
1039 load_save_format& format, bool& append, |
c9fab0bc983e
maint: Use convention 'int& x' for naming references.
Rik <rik@octave.org>
parents:
23432
diff
changeset
|
1040 bool& save_as_floats, bool& use_zlib) |
604 | 1041 { |
21691
263d18409fdf
Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents:
21568
diff
changeset
|
1042 #if ! defined (HAVE_ZLIB) |
263d18409fdf
Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents:
21568
diff
changeset
|
1043 octave_unused_parameter (use_zlib); |
263d18409fdf
Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents:
21568
diff
changeset
|
1044 #endif |
263d18409fdf
Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents:
21568
diff
changeset
|
1045 |
8034
f61bd8e0d682
fix default_save_options parsing and allow mixing options with other arguments.
Jaroslav Hajek <highegg@gmail.com>
parents:
8021
diff
changeset
|
1046 string_vector retval; |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20172
diff
changeset
|
1047 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
|
1048 |
18100
6a71e5030df5
Follow coding convention of defining and initializing only 1 variable per line in liboctinterp.
Rik <rik@octave.org>
parents:
17861
diff
changeset
|
1049 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
|
1050 bool do_tabs = false; |
8418
679c22082ac7
handle -double option for save
John W. Eaton <jwe@octave.org>
parents:
8377
diff
changeset
|
1051 |
8034
f61bd8e0d682
fix default_save_options parsing and allow mixing options with other arguments.
Jaroslav Hajek <highegg@gmail.com>
parents:
8021
diff
changeset
|
1052 for (int i = 0; i < argc; i++) |
5284 | 1053 { |
1054 if (argv[i] == "-append") | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1055 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1056 append = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1057 } |
5284 | 1058 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
|
1059 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1060 format = LS_MAT_ASCII; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1061 } |
8418
679c22082ac7
handle -double option for save
John W. Eaton <jwe@octave.org>
parents:
8377
diff
changeset
|
1062 else if (argv[i] == "-double") |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1063 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1064 do_double = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1065 } |
8425
2e777f5135a3
support -tabs option for save -ascii
Jaroslav Hajek <highegg@gmail.com>
parents:
8418
diff
changeset
|
1066 else if (argv[i] == "-tabs") |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1067 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1068 do_tabs = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1069 } |
5284 | 1070 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
|
1071 { |
20447
c6224b4e7774
maint: Rename instances of LS_ASCII to LS_TEXT for clarity.
Rik <rik@octave.org>
parents:
20443
diff
changeset
|
1072 format = LS_TEXT; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1073 } |
5284 | 1074 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
|
1075 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1076 format = LS_BINARY; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1077 } |
5284 | 1078 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
|
1079 { |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21691
diff
changeset
|
1080 #if defined (HAVE_HDF5) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1081 format = LS_HDF5; |
20945
9d9270e2f98f
eliminate comments after preprocessor conditionals
John W. Eaton <jwe@octave.org>
parents:
20940
diff
changeset
|
1082 #else |
21109
bd1752782e56
Use err_disabled_feature, warn_disabled_feature throughout code base.
Rik <rik@octave.org>
parents:
21102
diff
changeset
|
1083 err_disabled_feature ("save", "HDF5"); |
20945
9d9270e2f98f
eliminate comments after preprocessor conditionals
John W. Eaton <jwe@octave.org>
parents:
20940
diff
changeset
|
1084 #endif |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1085 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
1086 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
|
1087 || 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
|
1088 || argv[i] == "-V6") |
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_MAT5_BINARY; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1091 } |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21691
diff
changeset
|
1092 #if defined (HAVE_ZLIB) |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
1093 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
|
1094 || argv[i] == "-v7" || argv[i] == "-V7") |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1095 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1096 format = LS_MAT7_BINARY; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1097 } |
5284 | 1098 #endif |
1099 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
|
1100 || argv[i] == "-v4" || argv[i] == "-4") |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1101 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1102 format = LS_MAT_BINARY; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1103 } |
5284 | 1104 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
|
1105 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1106 format = LS_BINARY; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1107 save_as_floats = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1108 } |
5284 | 1109 else if (argv[i] == "-float-hdf5") |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1110 { |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21691
diff
changeset
|
1111 #if defined (HAVE_HDF5) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1112 format = LS_HDF5; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1113 save_as_floats = true; |
20945
9d9270e2f98f
eliminate comments after preprocessor conditionals
John W. Eaton <jwe@octave.org>
parents:
20940
diff
changeset
|
1114 #else |
21109
bd1752782e56
Use err_disabled_feature, warn_disabled_feature throughout code base.
Rik <rik@octave.org>
parents:
21102
diff
changeset
|
1115 err_disabled_feature ("save", "HDF5"); |
20945
9d9270e2f98f
eliminate comments after preprocessor conditionals
John W. Eaton <jwe@octave.org>
parents:
20940
diff
changeset
|
1116 #endif |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1117 } |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21691
diff
changeset
|
1118 #if defined (HAVE_ZLIB) |
5284 | 1119 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
|
1120 { |
21568
3d60ed163b70
maint: Eliminate bad spacing around '='.
Rik <rik@octave.org>
parents:
21301
diff
changeset
|
1121 use_zlib = true; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1122 } |
5284 | 1123 #endif |
15571
7b9551c65b7b
Don't report '-struct' as an unrecognized option to save().
Rik <rik@octave.org>
parents:
15567
diff
changeset
|
1124 else if (argv[i] == "-struct") |
7b9551c65b7b
Don't report '-struct' as an unrecognized option to save().
Rik <rik@octave.org>
parents:
15567
diff
changeset
|
1125 { |
7b9551c65b7b
Don't report '-struct' as an unrecognized option to save().
Rik <rik@octave.org>
parents:
15567
diff
changeset
|
1126 retval.append (argv[i]); |
7b9551c65b7b
Don't report '-struct' as an unrecognized option to save().
Rik <rik@octave.org>
parents:
15567
diff
changeset
|
1127 } |
18442
5c0b8f2da650
Allow save() to write to the terminal with the filename '-' (bug #41505)
Mike Miller <mtmiller@ieee.org>
parents:
17861
diff
changeset
|
1128 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
|
1129 { |
e05eafe7105a
Print an error message if save() called with unrecognized option (bug #37502)
Rik <rik@octave.org>
parents:
15467
diff
changeset
|
1130 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
|
1131 } |
5284 | 1132 else |
8034
f61bd8e0d682
fix default_save_options parsing and allow mixing options with other arguments.
Jaroslav Hajek <highegg@gmail.com>
parents:
8021
diff
changeset
|
1133 retval.append (argv[i]); |
5284 | 1134 } |
1135 | |
8418
679c22082ac7
handle -double option for save
John W. Eaton <jwe@octave.org>
parents:
8377
diff
changeset
|
1136 if (do_double) |
679c22082ac7
handle -double option for save
John W. Eaton <jwe@octave.org>
parents:
8377
diff
changeset
|
1137 { |
679c22082ac7
handle -double option for save
John W. Eaton <jwe@octave.org>
parents:
8377
diff
changeset
|
1138 if (format == LS_MAT_ASCII) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1139 format.opts |= LS_MAT_ASCII_LONG; |
8418
679c22082ac7
handle -double option for save
John W. Eaton <jwe@octave.org>
parents:
8377
diff
changeset
|
1140 else |
23803
90689bdbe048
Use C++11 raw string literals to avoid escaping double quotes.
Rik <rik@octave.org>
parents:
23800
diff
changeset
|
1141 warning (R"(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
|
1142 } |
679c22082ac7
handle -double option for save
John W. Eaton <jwe@octave.org>
parents:
8377
diff
changeset
|
1143 |
8425
2e777f5135a3
support -tabs option for save -ascii
Jaroslav Hajek <highegg@gmail.com>
parents:
8418
diff
changeset
|
1144 if (do_tabs) |
2e777f5135a3
support -tabs option for save -ascii
Jaroslav Hajek <highegg@gmail.com>
parents:
8418
diff
changeset
|
1145 { |
2e777f5135a3
support -tabs option for save -ascii
Jaroslav Hajek <highegg@gmail.com>
parents:
8418
diff
changeset
|
1146 if (format == LS_MAT_ASCII) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1147 format.opts |= LS_MAT_ASCII_TABS; |
8425
2e777f5135a3
support -tabs option for save -ascii
Jaroslav Hajek <highegg@gmail.com>
parents:
8418
diff
changeset
|
1148 else |
23803
90689bdbe048
Use C++11 raw string literals to avoid escaping double quotes.
Rik <rik@octave.org>
parents:
23800
diff
changeset
|
1149 warning (R"(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
|
1150 } |
2e777f5135a3
support -tabs option for save -ascii
Jaroslav Hajek <highegg@gmail.com>
parents:
8418
diff
changeset
|
1151 |
8034
f61bd8e0d682
fix default_save_options parsing and allow mixing options with other arguments.
Jaroslav Hajek <highegg@gmail.com>
parents:
8021
diff
changeset
|
1152 return retval; |
5284 | 1153 } |
1154 | |
8034
f61bd8e0d682
fix default_save_options parsing and allow mixing options with other arguments.
Jaroslav Hajek <highegg@gmail.com>
parents:
8021
diff
changeset
|
1155 static string_vector |
23433
c9fab0bc983e
maint: Use convention 'int& x' for naming references.
Rik <rik@octave.org>
parents:
23432
diff
changeset
|
1156 parse_save_options (const std::string& arg, load_save_format& format, |
c9fab0bc983e
maint: Use convention 'int& x' for naming references.
Rik <rik@octave.org>
parents:
23432
diff
changeset
|
1157 bool& append, bool& save_as_floats, bool& use_zlib) |
5284 | 1158 { |
5765 | 1159 std::istringstream is (arg); |
5284 | 1160 std::string str; |
1161 string_vector argv; | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
1162 |
5765 | 1163 while (! is.eof ()) |
5284 | 1164 { |
1165 is >> str; | |
1166 argv.append (str); | |
1167 } | |
1168 | |
20996 | 1169 return parse_save_options (argv, format, append, save_as_floats, use_zlib); |
604 | 1170 } |
1171 | |
4329 | 1172 void |
3523 | 1173 write_header (std::ostream& os, load_save_format format) |
863 | 1174 { |
8425
2e777f5135a3
support -tabs option for save -ascii
Jaroslav Hajek <highegg@gmail.com>
parents:
8418
diff
changeset
|
1175 switch (format.type) |
863 | 1176 { |
3185 | 1177 case LS_BINARY: |
1178 { | |
21739
c4ab2e54f100
use namespace for oct_mach_info class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
1179 os << (octave::mach_info::words_big_endian () |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1180 ? "Octave-1-B" : "Octave-1-L"); |
3185 | 1181 |
21739
c4ab2e54f100
use namespace for oct_mach_info class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
1182 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
|
1183 octave::mach_info::native_float_format (); |
3185 | 1184 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1185 char tmp = static_cast<char> (float_format_to_mopt_digit (flt_fmt)); |
3185 | 1186 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1187 os.write (&tmp, 1); |
3185 | 1188 } |
3688 | 1189 break; |
1190 | |
1191 case LS_MAT5_BINARY: | |
5269 | 1192 case LS_MAT7_BINARY: |
3688 | 1193 { |
23432
e35a5c1233d0
maint: Use convention 'int *x' for naming pointers.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
1194 char const *versionmagic; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1195 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
|
1196 char headertext[128]; |
21730
30c53770f47e
use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
1197 octave::sys::gmtime now; |
3688 | 1198 |
20389
6bc09e953927
Use octave_gmtime to write timestamp to mat-file format
Mike Miller <mtmiller@octave.org>
parents:
20264
diff
changeset
|
1199 // ISO 8601 format date |
6bc09e953927
Use octave_gmtime to write timestamp to mat-file format
Mike Miller <mtmiller@octave.org>
parents:
20264
diff
changeset
|
1200 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
|
1201 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
|
1202 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
|
1203 |
6bc09e953927
Use octave_gmtime to write timestamp to mat-file format
Mike Miller <mtmiller@octave.org>
parents:
20264
diff
changeset
|
1204 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
|
1205 memset (headertext, ' ', 124); |
20389
6bc09e953927
Use octave_gmtime to write timestamp to mat-file format
Mike Miller <mtmiller@octave.org>
parents:
20264
diff
changeset
|
1206 memcpy (headertext, comment_string.data (), len); |
3688 | 1207 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1208 // 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
|
1209 // 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
|
1210 // 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
|
1211 // 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
|
1212 // 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
|
1213 // little-endian machine. However, the version number is |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1214 // 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
|
1215 if (number == 1) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1216 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
|
1217 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1218 versionmagic = "\x00\x01\x49\x4d"; // this machine is little endian |
3688 | 1219 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1220 memcpy (headertext+124, versionmagic, 4); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1221 os.write (headertext, 128); |
3688 | 1222 } |
1223 | |
1224 break; | |
3185 | 1225 |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21691
diff
changeset
|
1226 #if defined (HAVE_HDF5) |
3687 | 1227 case LS_HDF5: |
20945
9d9270e2f98f
eliminate comments after preprocessor conditionals
John W. Eaton <jwe@octave.org>
parents:
20940
diff
changeset
|
1228 #endif |
20447
c6224b4e7774
maint: Rename instances of LS_ASCII to LS_TEXT for clarity.
Rik <rik@octave.org>
parents:
20443
diff
changeset
|
1229 case LS_TEXT: |
3185 | 1230 { |
21730
30c53770f47e
use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
1231 octave::sys::localtime now; |
3709 | 1232 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1233 std::string comment_string = now.strftime (Vsave_header_format_string); |
3709 | 1234 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1235 if (! comment_string.empty ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1236 { |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21691
diff
changeset
|
1237 #if defined (HAVE_HDF5) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1238 if (format == LS_HDF5) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1239 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1240 hdf5_ofstream& hs = dynamic_cast<hdf5_ofstream&> (os); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1241 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
|
1242 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1243 else |
20945
9d9270e2f98f
eliminate comments after preprocessor conditionals
John W. Eaton <jwe@octave.org>
parents:
20940
diff
changeset
|
1244 #endif |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1245 os << comment_string << "\n"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1246 } |
3185 | 1247 } |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17755
diff
changeset
|
1248 break; |
3185 | 1249 |
1250 default: | |
1251 break; | |
863 | 1252 } |
1253 } | |
1254 | |
17755
9c03b071fd7b
avoid HDF5 error message at exit (bug #37713)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
1255 void |
9c03b071fd7b
avoid HDF5 error message at exit (bug #37713)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
1256 octave_prepare_hdf5 (void) |
9c03b071fd7b
avoid HDF5 error message at exit (bug #37713)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
1257 { |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21691
diff
changeset
|
1258 #if defined (HAVE_HDF5) |
17755
9c03b071fd7b
avoid HDF5 error message at exit (bug #37713)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
1259 H5dont_atexit (); |
9c03b071fd7b
avoid HDF5 error message at exit (bug #37713)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
1260 #endif |
9c03b071fd7b
avoid HDF5 error message at exit (bug #37713)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
1261 } |
9c03b071fd7b
avoid HDF5 error message at exit (bug #37713)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
1262 |
9c03b071fd7b
avoid HDF5 error message at exit (bug #37713)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
1263 void |
9c03b071fd7b
avoid HDF5 error message at exit (bug #37713)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
1264 octave_finalize_hdf5 (void) |
9c03b071fd7b
avoid HDF5 error message at exit (bug #37713)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
1265 { |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21691
diff
changeset
|
1266 #if defined (HAVE_HDF5) |
17755
9c03b071fd7b
avoid HDF5 error message at exit (bug #37713)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
1267 H5close (); |
9c03b071fd7b
avoid HDF5 error message at exit (bug #37713)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
1268 #endif |
9c03b071fd7b
avoid HDF5 error message at exit (bug #37713)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
1269 } |
9c03b071fd7b
avoid HDF5 error message at exit (bug #37713)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
1270 |
863 | 1271 static void |
3769 | 1272 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
|
1273 std::ostream& os, load_save_format fmt, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1274 bool save_as_floats, bool write_header_info) |
863 | 1275 { |
3185 | 1276 if (write_header_info) |
1277 write_header (os, fmt); | |
863 | 1278 |
1755 | 1279 if (argv_idx == argc) |
863 | 1280 { |
5794 | 1281 save_vars (os, "*", fmt, save_as_floats); |
863 | 1282 } |
7635
ba7a3e20ee3d
add -struct modifier to save
Jaroslav Hajek <highegg@gmail.com>
parents:
7336
diff
changeset
|
1283 else if (argv[argv_idx] == "-struct") |
ba7a3e20ee3d
add -struct modifier to save
Jaroslav Hajek <highegg@gmail.com>
parents:
7336
diff
changeset
|
1284 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
1285 if (++argv_idx >= argc) |
20831
35241c4b696c
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20801
diff
changeset
|
1286 error ("save: missing struct name"); |
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 std::string struct_name = argv[argv_idx]; |
ba7a3e20ee3d
add -struct modifier to save
Jaroslav Hajek <highegg@gmail.com>
parents:
7336
diff
changeset
|
1289 |
24361
8bcfddad15ec
use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents:
24356
diff
changeset
|
1290 octave::symbol_scope scope = octave::__get_current_scope__ ("save_vars"); |
23611
91c8f006ed8b
remove additional functions from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
23603
diff
changeset
|
1291 |
91c8f006ed8b
remove additional functions from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
23603
diff
changeset
|
1292 octave_value struct_var; |
23599
5cb3a2bb5e1e
don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents:
23584
diff
changeset
|
1293 |
23611
91c8f006ed8b
remove additional functions from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
23603
diff
changeset
|
1294 if (scope) |
91c8f006ed8b
remove additional functions from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
23603
diff
changeset
|
1295 { |
24361
8bcfddad15ec
use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents:
24356
diff
changeset
|
1296 if (! scope.is_variable (struct_name)) |
23611
91c8f006ed8b
remove additional functions from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
23603
diff
changeset
|
1297 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
|
1298 |
24361
8bcfddad15ec
use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents:
24356
diff
changeset
|
1299 struct_var = scope.varval (struct_name); |
23611
91c8f006ed8b
remove additional functions from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
23603
diff
changeset
|
1300 } |
7635
ba7a3e20ee3d
add -struct modifier to save
Jaroslav Hajek <highegg@gmail.com>
parents:
7336
diff
changeset
|
1301 |
23584
7ed6b258db91
maint: Deprecate is_map and replace with isstruct.
Rik <rik@octave.org>
parents:
23557
diff
changeset
|
1302 if (! struct_var.isstruct () || struct_var.numel () != 1) |
20831
35241c4b696c
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20801
diff
changeset
|
1303 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
|
1304 |
11059
4ffa19147604
replace Octave_map->octave_scalar_map in help.cc and load-save.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
10846
diff
changeset
|
1305 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
|
1306 |
ba7a3e20ee3d
add -struct modifier to save
Jaroslav Hajek <highegg@gmail.com>
parents:
7336
diff
changeset
|
1307 ++argv_idx; |
ba7a3e20ee3d
add -struct modifier to save
Jaroslav Hajek <highegg@gmail.com>
parents:
7336
diff
changeset
|
1308 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
1309 if (argv_idx < argc) |
7635
ba7a3e20ee3d
add -struct modifier to save
Jaroslav Hajek <highegg@gmail.com>
parents:
7336
diff
changeset
|
1310 { |
ba7a3e20ee3d
add -struct modifier to save
Jaroslav Hajek <highegg@gmail.com>
parents:
7336
diff
changeset
|
1311 for (int i = argv_idx; i < argc; i++) |
ba7a3e20ee3d
add -struct modifier to save
Jaroslav Hajek <highegg@gmail.com>
parents:
7336
diff
changeset
|
1312 { |
ba7a3e20ee3d
add -struct modifier to save
Jaroslav Hajek <highegg@gmail.com>
parents:
7336
diff
changeset
|
1313 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
|
1314 save_as_floats)) |
7635
ba7a3e20ee3d
add -struct modifier to save
Jaroslav Hajek <highegg@gmail.com>
parents:
7336
diff
changeset
|
1315 { |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14268
diff
changeset
|
1316 warning ("save: no such field '%s.%s'", |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1317 struct_name.c_str (), argv[i].c_str ()); |
7635
ba7a3e20ee3d
add -struct modifier to save
Jaroslav Hajek <highegg@gmail.com>
parents:
7336
diff
changeset
|
1318 } |
ba7a3e20ee3d
add -struct modifier to save
Jaroslav Hajek <highegg@gmail.com>
parents:
7336
diff
changeset
|
1319 } |
ba7a3e20ee3d
add -struct modifier to save
Jaroslav Hajek <highegg@gmail.com>
parents:
7336
diff
changeset
|
1320 } |
ba7a3e20ee3d
add -struct modifier to save
Jaroslav Hajek <highegg@gmail.com>
parents:
7336
diff
changeset
|
1321 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1322 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
|
1323 } |
863 | 1324 else |
1325 { | |
1755 | 1326 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
|
1327 { |
17349
cb27dbf9e4ba
Don't warn about saving empty variable names for Matlab compatibility (bug #34259)
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
1328 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
|
1329 continue; // Skip empty vars for Matlab compatibility |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1330 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
|
1331 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
|
1332 } |
863 | 1333 } |
1334 } | |
1335 | |
5284 | 1336 static void |
1337 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
|
1338 bool save_as_floats) |
4791 | 1339 { |
1340 write_header (os, fmt); | |
1341 | |
25103
078b795c5219
maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
1342 octave::symbol_table& symtab = |
078b795c5219
maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
1343 octave::__get_symbol_table__ ("dump_octave_core"); |
23599
5cb3a2bb5e1e
don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents:
23584
diff
changeset
|
1344 |
24361
8bcfddad15ec
use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents:
24356
diff
changeset
|
1345 octave::symbol_scope top_scope = symtab.top_scope (); |
23611
91c8f006ed8b
remove additional functions from symbol_table class
John W. Eaton <jwe@octave.org>
parents:
23603
diff
changeset
|
1346 |
24361
8bcfddad15ec
use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents:
24356
diff
changeset
|
1347 octave::symbol_record::context_id context = top_scope.current_context (); |
24356
8b14ba8296af
refactor symbol_record object
John W. Eaton <jwe@octave.org>
parents:
24287
diff
changeset
|
1348 |
24361
8bcfddad15ec
use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents:
24356
diff
changeset
|
1349 std::list<octave::symbol_record> vars = top_scope.all_variables (); |
4791 | 1350 |
1351 double save_mem_size = 0; | |
1352 | |
22862
e365e87371a3
maint: Use C++ range feature to simplify some for loops in libinterp/corefcn.
Rik <rik@octave.org>
parents:
22755
diff
changeset
|
1353 for (const auto& var : vars) |
4791 | 1354 { |
24356
8b14ba8296af
refactor symbol_record object
John W. Eaton <jwe@octave.org>
parents:
24287
diff
changeset
|
1355 octave_value val = var.varval (context); |
4791 | 1356 |
7336 | 1357 if (val.is_defined ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1358 { |
22862
e365e87371a3
maint: Use C++ range feature to simplify some for loops in libinterp/corefcn.
Rik <rik@octave.org>
parents:
22755
diff
changeset
|
1359 std::string name = var.name (); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1360 std::string help; |
22862
e365e87371a3
maint: Use C++ range feature to simplify some for loops in libinterp/corefcn.
Rik <rik@octave.org>
parents:
22755
diff
changeset
|
1361 bool global = var.is_global (); |
4791 | 1362 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1363 double val_size = val.byte_size () / 1024; |
4791 | 1364 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17755
diff
changeset
|
1365 // FIXME: maybe we should try to throw out the largest first... |
4791 | 1366 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1367 if (Voctave_core_file_limit < 0 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1368 || 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
|
1369 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1370 save_mem_size += val_size; |
4791 | 1371 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1372 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
|
1373 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1374 } |
4791 | 1375 } |
1376 | |
23795
980f39c3ab90
Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents:
23777
diff
changeset
|
1377 message (nullptr, "save to '%s' complete", fname); |
4791 | 1378 } |
1379 | |
1380 void | |
1381 dump_octave_core (void) | |
1380 | 1382 { |
3189 | 1383 if (Vcrash_dumps_octave_core) |
1380 | 1384 { |
20713
2469d78a1d8b
Consistently use 'filename' rather than 'file name' throughout code base.
Rik <rik@octave.org>
parents:
20678
diff
changeset
|
1385 // FIXME: should choose better filename? |
3189 | 1386 |
4791 | 1387 const char *fname = Voctave_core_file_name.c_str (); |
3189 | 1388 |
23795
980f39c3ab90
Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents:
23777
diff
changeset
|
1389 message (nullptr, "attempting to save variables to '%s'...", fname); |
3189 | 1390 |
5284 | 1391 load_save_format format = LS_BINARY; |
1392 | |
1393 bool save_as_floats = false; | |
1394 | |
1395 bool append = false; | |
3189 | 1396 |
5284 | 1397 bool use_zlib = false; |
1398 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
1399 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
|
1400 save_as_floats, use_zlib); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
1401 |
5284 | 1402 std::ios::openmode mode = std::ios::out; |
4791 | 1403 |
6625 | 1404 // Matlab v7 files are always compressed |
1405 if (format == LS_MAT7_BINARY) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1406 use_zlib = false; |
6625 | 1407 |
4791 | 1408 if (format == LS_BINARY |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21691
diff
changeset
|
1409 #if defined (HAVE_HDF5) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1410 || format == LS_HDF5 |
4791 | 1411 #endif |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1412 || format == LS_MAT_BINARY |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1413 || format == LS_MAT5_BINARY |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1414 || format == LS_MAT7_BINARY) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1415 mode |= std::ios::binary; |
3189 | 1416 |
5284 | 1417 mode |= append ? std::ios::ate : std::ios::trunc; |
1418 | |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21691
diff
changeset
|
1419 #if defined (HAVE_HDF5) |
3687 | 1420 if (format == LS_HDF5) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1421 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1422 hdf5_ofstream file (fname, mode); |
3687 | 1423 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1424 if (file.file_id >= 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1425 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1426 dump_octave_core (file, fname, format, save_as_floats); |
3687 | 1427 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1428 file.close (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1429 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1430 else |
20727
a5949b3d2332
Preface warning() messages with name of function when possible.
Rik <rik@octave.org>
parents:
20713
diff
changeset
|
1431 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
|
1432 fname); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1433 } |
3189 | 1434 else |
20945
9d9270e2f98f
eliminate comments after preprocessor conditionals
John W. Eaton <jwe@octave.org>
parents:
20940
diff
changeset
|
1435 #endif |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1436 // 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
|
1437 // go with the else above! |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1438 { |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21691
diff
changeset
|
1439 #if defined (HAVE_ZLIB) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1440 if (use_zlib) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1441 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1442 gzofstream file (fname, mode); |
4791 | 1443 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1444 if (file) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1445 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1446 dump_octave_core (file, fname, format, save_as_floats); |
5284 | 1447 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1448 file.close (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1449 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1450 else |
20727
a5949b3d2332
Preface warning() messages with name of function when possible.
Rik <rik@octave.org>
parents:
20713
diff
changeset
|
1451 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
|
1452 fname); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1453 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1454 else |
5284 | 1455 #endif |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1456 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1457 std::ofstream file (fname, mode); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
1458 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1459 if (file) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1460 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1461 dump_octave_core (file, fname, format, save_as_floats); |
5284 | 1462 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1463 file.close (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1464 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1465 else |
20727
a5949b3d2332
Preface warning() messages with name of function when possible.
Rik <rik@octave.org>
parents:
20713
diff
changeset
|
1466 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
|
1467 fname); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1468 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1469 } |
1380 | 1470 } |
1471 } | |
1472 | |
19817
bafcfc5b99af
if save file name is "-" and nargout is 0, write to stdout
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
1473 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
|
1474 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
|
1475 @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
|
1476 @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
|
1477 @deftypefnx {} {} save options file @var{v1} @var{v2} @dots{} |
23985
aa127fce67e4
doc: Document extra save options for -ascii format (bug #51898).
Rik <rik@octave.org>
parents:
23807
diff
changeset
|
1478 @deftypefnx {} {} save options file -struct @var{STRUCT} |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1479 @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
|
1480 @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
|
1481 @deftypefnx {} {@var{str} =} save ("-", @qcode{"@var{v1}"}, @qcode{"@var{v2}"}, @dots{}) |
23985
aa127fce67e4
doc: Document extra save options for -ascii format (bug #51898).
Rik <rik@octave.org>
parents:
23807
diff
changeset
|
1482 Save the named variables @var{v1}, @var{v2}, @dots{}, in the file @var{file}. |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1483 |
23985
aa127fce67e4
doc: Document extra save options for -ascii format (bug #51898).
Rik <rik@octave.org>
parents:
23807
diff
changeset
|
1484 The special filename @samp{-} may be used to return the content of the |
aa127fce67e4
doc: Document extra save options for -ascii format (bug #51898).
Rik <rik@octave.org>
parents:
23807
diff
changeset
|
1485 variables as a string. If no variable names are listed, Octave saves all the |
aa127fce67e4
doc: Document extra save options for -ascii format (bug #51898).
Rik <rik@octave.org>
parents:
23807
diff
changeset
|
1486 variables in the current scope. Otherwise, full variable names or pattern |
aa127fce67e4
doc: Document extra save options for -ascii format (bug #51898).
Rik <rik@octave.org>
parents:
23807
diff
changeset
|
1487 syntax can be used to specify the variables to save. If the @option{-struct} |
aa127fce67e4
doc: Document extra save options for -ascii format (bug #51898).
Rik <rik@octave.org>
parents:
23807
diff
changeset
|
1488 modifier is used then the fields of the @strong{scalar} struct are saved as if |
aa127fce67e4
doc: Document extra save options for -ascii format (bug #51898).
Rik <rik@octave.org>
parents:
23807
diff
changeset
|
1489 they were variables with the corresponding field names. The @option{-struct} |
aa127fce67e4
doc: Document extra save options for -ascii format (bug #51898).
Rik <rik@octave.org>
parents:
23807
diff
changeset
|
1490 option can be combined with specific field names @var{f1}, @var{f2}, @dots{} to |
aa127fce67e4
doc: Document extra save options for -ascii format (bug #51898).
Rik <rik@octave.org>
parents:
23807
diff
changeset
|
1491 write only certain fields to the file. |
aa127fce67e4
doc: Document extra save options for -ascii format (bug #51898).
Rik <rik@octave.org>
parents:
23807
diff
changeset
|
1492 |
aa127fce67e4
doc: Document extra save options for -ascii format (bug #51898).
Rik <rik@octave.org>
parents:
23807
diff
changeset
|
1493 Valid options for the @code{save} command are listed in the following table. |
aa127fce67e4
doc: Document extra save options for -ascii format (bug #51898).
Rik <rik@octave.org>
parents:
23807
diff
changeset
|
1494 Options that modify the output format override the format specified by |
aa127fce67e4
doc: Document extra save options for -ascii format (bug #51898).
Rik <rik@octave.org>
parents:
23807
diff
changeset
|
1495 @code{save_default_options}. |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1496 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1497 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
|
1498 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1499 @example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1500 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
|
1501 @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
|
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 @noindent |
23985
aa127fce67e4
doc: Document extra save options for -ascii format (bug #51898).
Rik <rik@octave.org>
parents:
23807
diff
changeset
|
1504 then the @var{options}, @var{file}, and variable name arguments (@var{v1}, |
aa127fce67e4
doc: Document extra save options for -ascii format (bug #51898).
Rik <rik@octave.org>
parents:
23807
diff
changeset
|
1505 @dots{}) must be specified as character strings. |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1506 |
23985
aa127fce67e4
doc: Document extra save options for -ascii format (bug #51898).
Rik <rik@octave.org>
parents:
23807
diff
changeset
|
1507 If called with a filename of @qcode{"-"}, write the output to stdout if nargout |
aa127fce67e4
doc: Document extra save options for -ascii format (bug #51898).
Rik <rik@octave.org>
parents:
23807
diff
changeset
|
1508 is 0, otherwise return the output in a character string. |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1509 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1510 @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
|
1511 @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
|
1512 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
|
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 -ascii |
23985
aa127fce67e4
doc: Document extra save options for -ascii format (bug #51898).
Rik <rik@octave.org>
parents:
23807
diff
changeset
|
1515 Save a matrix in a text file without a header or any other information. The |
aa127fce67e4
doc: Document extra save options for -ascii format (bug #51898).
Rik <rik@octave.org>
parents:
23807
diff
changeset
|
1516 matrix must be 2-D and only the real part of any complex value is written to |
aa127fce67e4
doc: Document extra save options for -ascii format (bug #51898).
Rik <rik@octave.org>
parents:
23807
diff
changeset
|
1517 the file. Numbers are stored in single-precision format and separated by |
24986
0b9e7fcaab91
doc: grammarcheck docstrings in C++ files ahead of 4.4 release.
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
1518 spaces. Additional options for the @option{-ascii} format are |
23985
aa127fce67e4
doc: Document extra save options for -ascii format (bug #51898).
Rik <rik@octave.org>
parents:
23807
diff
changeset
|
1519 |
aa127fce67e4
doc: Document extra save options for -ascii format (bug #51898).
Rik <rik@octave.org>
parents:
23807
diff
changeset
|
1520 @table @code |
aa127fce67e4
doc: Document extra save options for -ascii format (bug #51898).
Rik <rik@octave.org>
parents:
23807
diff
changeset
|
1521 @item -double |
aa127fce67e4
doc: Document extra save options for -ascii format (bug #51898).
Rik <rik@octave.org>
parents:
23807
diff
changeset
|
1522 Store numbers in double-precision format. |
aa127fce67e4
doc: Document extra save options for -ascii format (bug #51898).
Rik <rik@octave.org>
parents:
23807
diff
changeset
|
1523 |
aa127fce67e4
doc: Document extra save options for -ascii format (bug #51898).
Rik <rik@octave.org>
parents:
23807
diff
changeset
|
1524 @item -tabs |
aa127fce67e4
doc: Document extra save options for -ascii format (bug #51898).
Rik <rik@octave.org>
parents:
23807
diff
changeset
|
1525 Separate numbers with tabs. |
aa127fce67e4
doc: Document extra save options for -ascii format (bug #51898).
Rik <rik@octave.org>
parents:
23807
diff
changeset
|
1526 @end table |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1527 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1528 @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
|
1529 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
|
1530 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1531 @item -float-binary |
23985
aa127fce67e4
doc: Document extra save options for -ascii format (bug #51898).
Rik <rik@octave.org>
parents:
23807
diff
changeset
|
1532 Save the data in Octave's binary data format but using only single precision. |
aa127fce67e4
doc: Document extra save options for -ascii format (bug #51898).
Rik <rik@octave.org>
parents:
23807
diff
changeset
|
1533 Use this format @strong{only} if you know that all the values to be saved can |
aa127fce67e4
doc: Document extra save options for -ascii format (bug #51898).
Rik <rik@octave.org>
parents:
23807
diff
changeset
|
1534 be represented in single precision. |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1535 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1536 @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
|
1537 Save the data in @sc{hdf5} format. |
23985
aa127fce67e4
doc: Document extra save options for -ascii format (bug #51898).
Rik <rik@octave.org>
parents:
23807
diff
changeset
|
1538 (HDF5 is a free, portable, binary format developed by the National Center for |
aa127fce67e4
doc: Document extra save options for -ascii format (bug #51898).
Rik <rik@octave.org>
parents:
23807
diff
changeset
|
1539 Supercomputing Applications at the University of Illinois.) This format is only |
aa127fce67e4
doc: Document extra save options for -ascii format (bug #51898).
Rik <rik@octave.org>
parents:
23807
diff
changeset
|
1540 available if Octave was built with a link to the @sc{hdf5} libraries. |
21966
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 @item -float-hdf5 |
23985
aa127fce67e4
doc: Document extra save options for -ascii format (bug #51898).
Rik <rik@octave.org>
parents:
23807
diff
changeset
|
1543 Save the data in @sc{hdf5} format but using only single precision. Use this |
aa127fce67e4
doc: Document extra save options for -ascii format (bug #51898).
Rik <rik@octave.org>
parents:
23807
diff
changeset
|
1544 format @strong{only} if you know that all the values to be saved can be |
aa127fce67e4
doc: Document extra save options for -ascii format (bug #51898).
Rik <rik@octave.org>
parents:
23807
diff
changeset
|
1545 represented in single precision. |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1546 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1547 @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
|
1548 @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
|
1549 @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
|
1550 @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
|
1551 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
|
1552 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1553 @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
|
1554 @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
|
1555 @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
|
1556 @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
|
1557 @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
|
1558 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
|
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 @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
|
1561 @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
|
1562 @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
|
1563 @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
|
1564 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
|
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 @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
|
1567 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
|
1568 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1569 @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
|
1570 @itemx -z |
23985
aa127fce67e4
doc: Document extra save options for -ascii format (bug #51898).
Rik <rik@octave.org>
parents:
23807
diff
changeset
|
1571 Use the gzip algorithm to compress the file. This works on files that are |
aa127fce67e4
doc: Document extra save options for -ascii format (bug #51898).
Rik <rik@octave.org>
parents:
23807
diff
changeset
|
1572 compressed with gzip outside of Octave, and gzip can also be used to convert |
aa127fce67e4
doc: Document extra save options for -ascii format (bug #51898).
Rik <rik@octave.org>
parents:
23807
diff
changeset
|
1573 the files for backward compatibility. This option is only available if Octave |
aa127fce67e4
doc: Document extra save options for -ascii format (bug #51898).
Rik <rik@octave.org>
parents:
23807
diff
changeset
|
1574 was built with a link to the zlib libraries. |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1575 @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
|
1576 |
23985
aa127fce67e4
doc: Document extra save options for -ascii format (bug #51898).
Rik <rik@octave.org>
parents:
23807
diff
changeset
|
1577 The list of variables to save may use wildcard patterns containing the |
aa127fce67e4
doc: Document extra save options for -ascii format (bug #51898).
Rik <rik@octave.org>
parents:
23807
diff
changeset
|
1578 following special characters: |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1579 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1580 @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
|
1581 @item ? |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1582 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
|
1583 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1584 @item * |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1585 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
|
1586 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1587 @item [ @var{list} ] |
23985
aa127fce67e4
doc: Document extra save options for -ascii format (bug #51898).
Rik <rik@octave.org>
parents:
23807
diff
changeset
|
1588 Match the list of characters specified by @var{list}. If the first character |
aa127fce67e4
doc: Document extra save options for -ascii format (bug #51898).
Rik <rik@octave.org>
parents:
23807
diff
changeset
|
1589 is @code{!} or @code{^}, match all characters except those specified by |
aa127fce67e4
doc: Document extra save options for -ascii format (bug #51898).
Rik <rik@octave.org>
parents:
23807
diff
changeset
|
1590 @var{list}. For example, the pattern @code{[a-zA-Z]} will match all lower and |
aa127fce67e4
doc: Document extra save options for -ascii format (bug #51898).
Rik <rik@octave.org>
parents:
23807
diff
changeset
|
1591 uppercase alphabetic characters. |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1592 |
23985
aa127fce67e4
doc: Document extra save options for -ascii format (bug #51898).
Rik <rik@octave.org>
parents:
23807
diff
changeset
|
1593 Wildcards may also be used in the field name specifications when using the |
aa127fce67e4
doc: Document extra save options for -ascii format (bug #51898).
Rik <rik@octave.org>
parents:
23807
diff
changeset
|
1594 @option{-struct} modifier (but not in the struct name itself). |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1595 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1596 @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
|
1597 |
23985
aa127fce67e4
doc: Document extra save options for -ascii format (bug #51898).
Rik <rik@octave.org>
parents:
23807
diff
changeset
|
1598 Except when using the @sc{matlab} binary data file format or the @samp{-ascii} |
aa127fce67e4
doc: Document extra save options for -ascii format (bug #51898).
Rik <rik@octave.org>
parents:
23807
diff
changeset
|
1599 format, saving global variables also saves the global status of the variable. |
aa127fce67e4
doc: Document extra save options for -ascii format (bug #51898).
Rik <rik@octave.org>
parents:
23807
diff
changeset
|
1600 If the variable is restored at a later time using @samp{load}, it will be |
aa127fce67e4
doc: Document extra save options for -ascii format (bug #51898).
Rik <rik@octave.org>
parents:
23807
diff
changeset
|
1601 restored as a global variable. |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1602 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1603 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
|
1604 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1605 @example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1606 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
|
1607 @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
|
1608 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1609 @noindent |
23985
aa127fce67e4
doc: Document extra save options for -ascii format (bug #51898).
Rik <rik@octave.org>
parents:
23807
diff
changeset
|
1610 saves the variable @samp{a} and all variables beginning with @samp{b} to the |
aa127fce67e4
doc: Document extra save options for -ascii format (bug #51898).
Rik <rik@octave.org>
parents:
23807
diff
changeset
|
1611 file @file{data} in Octave's binary format. |
23557
00b11cee2100
doc: Improve documentation for Octave's save-related functions.
Rik <rik@octave.org>
parents:
23455
diff
changeset
|
1612 @seealso{load, save_default_options, save_header_format_string, save_precision, dlmread, csvread, fread} |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1613 @end deftypefn */) |
604 | 1614 { |
1358 | 1615 // Here is where we would get the default save format if it were |
1616 // stored in a user preference variable. | |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
1617 load_save_format format = LS_TEXT; |
3019 | 1618 bool save_as_floats = false; |
3185 | 1619 bool append = false; |
5269 | 1620 bool use_zlib = false; |
1621 | |
8034
f61bd8e0d682
fix default_save_options parsing and allow mixing options with other arguments.
Jaroslav Hajek <highegg@gmail.com>
parents:
8021
diff
changeset
|
1622 // get default options |
16875
b04ae15530fc
Rename default_save_options() to save_default_options().
Rik <rik@octave.org>
parents:
16555
diff
changeset
|
1623 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
|
1624 use_zlib); |
5351 | 1625 |
8034
f61bd8e0d682
fix default_save_options parsing and allow mixing options with other arguments.
Jaroslav Hajek <highegg@gmail.com>
parents:
8021
diff
changeset
|
1626 // override from command line |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
1627 string_vector argv = args.make_argv (); |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
1628 |
20996 | 1629 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
|
1630 |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20172
diff
changeset
|
1631 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
|
1632 int i = 0; |
5197 | 1633 |
2057 | 1634 if (i == argc) |
20801
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20741
diff
changeset
|
1635 print_usage (); |
604 | 1636 |
20447
c6224b4e7774
maint: Rename instances of LS_ASCII to LS_TEXT for clarity.
Rik <rik@octave.org>
parents:
20443
diff
changeset
|
1637 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
|
1638 error ("save: cannot specify both -text and -float-binary"); |
630 | 1639 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
1640 octave_value_list retval; |
630 | 1641 |
1755 | 1642 if (argv[i] == "-") |
604 | 1643 { |
1755 | 1644 i++; |
863 | 1645 |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21691
diff
changeset
|
1646 #if defined (HAVE_HDF5) |
3687 | 1647 if (format == LS_HDF5) |
4687 | 1648 error ("save: cannot write HDF5 format to stdout"); |
3687 | 1649 else |
20945
9d9270e2f98f
eliminate comments after preprocessor conditionals
John W. Eaton <jwe@octave.org>
parents:
20940
diff
changeset
|
1650 #endif |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1651 // 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
|
1652 // with the "else" above! |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1653 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1654 if (append) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1655 warning ("save: ignoring -append option for output to stdout"); |
6759 | 1656 |
19817
bafcfc5b99af
if save file name is "-" and nargout is 0, write to stdout
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
1657 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
|
1658 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
|
1659 else |
bafcfc5b99af
if save file name is "-" and nargout is 0, write to stdout
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
1660 { |
bafcfc5b99af
if save file name is "-" and nargout is 0, write to stdout
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
1661 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
|
1662 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
|
1663 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
|
1664 } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1665 } |
604 | 1666 } |
1755 | 1667 |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14268
diff
changeset
|
1668 // Guard against things like 'save a*', which are probably mistakes... |
1755 | 1669 |
1670 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
|
1671 print_usage (); |
604 | 1672 else |
1673 { | |
21733
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
1674 std::string fname = octave::sys::file_ops::tilde_expand (argv[i]); |
1755 | 1675 |
1676 i++; | |
604 | 1677 |
6625 | 1678 // Matlab v7 files are always compressed |
1679 if (format == LS_MAT7_BINARY) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1680 use_zlib = false; |
6625 | 1681 |
6759 | 1682 std::ios::openmode mode |
23450
855122b993da
maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents:
23433
diff
changeset
|
1683 = (append ? (std::ios::app | std::ios::ate) : std::ios::out); |
6759 | 1684 |
4791 | 1685 if (format == LS_BINARY |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21691
diff
changeset
|
1686 #if defined (HAVE_HDF5) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1687 || format == LS_HDF5 |
4791 | 1688 #endif |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1689 || format == LS_MAT_BINARY |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1690 || format == LS_MAT5_BINARY |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1691 || format == LS_MAT7_BINARY) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1692 mode |= std::ios::binary; |
3538 | 1693 |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21691
diff
changeset
|
1694 #if defined (HAVE_HDF5) |
3687 | 1695 if (format == LS_HDF5) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1696 { |
17861
870f3e12e163
maint: Use phrase "FIXME:" for problem areas in code.
Rik <rik@octave.org>
parents:
17787
diff
changeset
|
1697 // 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
|
1698 if (append) |
20831
35241c4b696c
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20801
diff
changeset
|
1699 error ("save: appending to HDF5 files is not implemented"); |
6759 | 1700 |
19864
17d647821d61
maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents:
19817
diff
changeset
|
1701 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
|
1702 = ! (append && H5Fis_hdf5 (fname.c_str ()) > 0); |
3687 | 1703 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1704 hdf5_ofstream hdf5_file (fname.c_str (), mode); |
6760 | 1705 |
21118
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21109
diff
changeset
|
1706 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
|
1707 err_file_open ("save", fname); |
3687 | 1708 |
21118
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21109
diff
changeset
|
1709 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
|
1710 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
|
1711 |
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21109
diff
changeset
|
1712 hdf5_file.close (); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1713 } |
863 | 1714 else |
20945
9d9270e2f98f
eliminate comments after preprocessor conditionals
John W. Eaton <jwe@octave.org>
parents:
20940
diff
changeset
|
1715 #endif |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1716 // 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
|
1717 // with the "else" above! |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1718 { |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21691
diff
changeset
|
1719 #if defined (HAVE_ZLIB) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1720 if (use_zlib) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1721 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1722 gzofstream file (fname.c_str (), mode); |
5269 | 1723 |
21118
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21109
diff
changeset
|
1724 if (! file) |
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21109
diff
changeset
|
1725 err_file_open ("save", fname); |
6760 | 1726 |
21118
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21109
diff
changeset
|
1727 bool write_header_info = ! file.tellp (); |
5269 | 1728 |
21118
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21109
diff
changeset
|
1729 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
|
1730 save_as_floats, write_header_info); |
5269 | 1731 |
21118
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21109
diff
changeset
|
1732 file.close (); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1733 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1734 else |
5269 | 1735 #endif |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1736 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1737 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
|
1738 |
21118
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21109
diff
changeset
|
1739 if (! file) |
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21109
diff
changeset
|
1740 err_file_open ("save", fname); |
6760 | 1741 |
21118
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21109
diff
changeset
|
1742 bool write_header_info = ! file.tellp (); |
5269 | 1743 |
21118
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21109
diff
changeset
|
1744 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
|
1745 save_as_floats, write_header_info); |
5269 | 1746 |
21118
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21109
diff
changeset
|
1747 file.close (); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1748 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1749 } |
604 | 1750 } |
1751 | |
1752 return retval; | |
1753 } | |
1754 | |
5794 | 1755 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
|
1756 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
|
1757 @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
|
1758 @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
|
1759 @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
|
1760 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
|
1761 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
|
1762 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
|
1763 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1764 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
|
1765 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
|
1766 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
|
1767 @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
|
1768 @end deftypefn */) |
2194 | 1769 { |
5794 | 1770 return SET_INTERNAL_VARIABLE (crash_dumps_octave_core); |
2194 | 1771 } |
1772 | |
16875
b04ae15530fc
Rename default_save_options() to save_default_options().
Rik <rik@octave.org>
parents:
16555
diff
changeset
|
1773 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
|
1774 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
|
1775 @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
|
1776 @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
|
1777 @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
|
1778 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
|
1779 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
|
1780 |
23557
00b11cee2100
doc: Improve documentation for Octave's save-related functions.
Rik <rik@octave.org>
parents:
23455
diff
changeset
|
1781 The default value is @qcode{"-text"} (Octave's own text-based file format). |
00b11cee2100
doc: Improve documentation for Octave's save-related functions.
Rik <rik@octave.org>
parents:
23455
diff
changeset
|
1782 See the documentation of the @code{save} command for other choices. |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1783 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1784 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
|
1785 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
|
1786 The original variable value is restored when exiting the function. |
23557
00b11cee2100
doc: Improve documentation for Octave's save-related functions.
Rik <rik@octave.org>
parents:
23455
diff
changeset
|
1787 @seealso{save, save_header_format_string, save_precision} |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1788 @end deftypefn */) |
4788 | 1789 { |
16875
b04ae15530fc
Rename default_save_options() to save_default_options().
Rik <rik@octave.org>
parents:
16555
diff
changeset
|
1790 return SET_NONEMPTY_INTERNAL_STRING_VARIABLE (save_default_options); |
4788 | 1791 } |
1792 | |
5794 | 1793 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
|
1794 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
|
1795 @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
|
1796 @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
|
1797 @deftypefnx {} {} octave_core_file_limit (@var{new_val}, "local") |
25106
d7ad543255c5
doc: Shorten very long first sentences of docstrings (bug #53388).
Rik <rik@octave.org>
parents:
25103
diff
changeset
|
1798 Query or set the internal variable that specifies the maximum amount of memory |
d7ad543255c5
doc: Shorten very long first sentences of docstrings (bug #53388).
Rik <rik@octave.org>
parents:
25103
diff
changeset
|
1799 that Octave will save when writing a crash dump file. |
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 |
25106
d7ad543255c5
doc: Shorten very long first sentences of docstrings (bug #53388).
Rik <rik@octave.org>
parents:
25103
diff
changeset
|
1801 The limit is measured in kilobytes and is applied to the top-level workspace. |
25579
07c2c42f457e
doc: Miscellaneous documentation fixes all over the manual (bug #54288).
Rik <rik@octave.org>
parents:
25201
diff
changeset
|
1802 The name of the crash dump file is specified by |
07c2c42f457e
doc: Miscellaneous documentation fixes all over the manual (bug #54288).
Rik <rik@octave.org>
parents:
25201
diff
changeset
|
1803 @var{octave_core_file_name}. |
25106
d7ad543255c5
doc: Shorten very long first sentences of docstrings (bug #53388).
Rik <rik@octave.org>
parents:
25103
diff
changeset
|
1804 |
d7ad543255c5
doc: Shorten very long first sentences of docstrings (bug #53388).
Rik <rik@octave.org>
parents:
25103
diff
changeset
|
1805 If @var{octave_core_file_options} flags specify a binary format, then |
d7ad543255c5
doc: Shorten very long first sentences of docstrings (bug #53388).
Rik <rik@octave.org>
parents:
25103
diff
changeset
|
1806 @var{octave_core_file_limit} will be approximately the maximum size of the |
d7ad543255c5
doc: Shorten very long first sentences of docstrings (bug #53388).
Rik <rik@octave.org>
parents:
25103
diff
changeset
|
1807 file. If a text file format is used, then the file could be much larger than |
d7ad543255c5
doc: Shorten very long first sentences of docstrings (bug #53388).
Rik <rik@octave.org>
parents:
25103
diff
changeset
|
1808 the limit. The default value is -1 (unlimited). |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1809 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1810 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
|
1811 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
|
1812 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
|
1813 @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
|
1814 @end deftypefn */) |
3709 | 1815 { |
5794 | 1816 return SET_INTERNAL_VARIABLE (octave_core_file_limit); |
3709 | 1817 } |
1818 | |
5794 | 1819 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
|
1820 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
|
1821 @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
|
1822 @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
|
1823 @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
|
1824 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
|
1825 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
|
1826 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1827 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
|
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 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
|
1830 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
|
1831 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
|
1832 @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
|
1833 @end deftypefn */) |
2194 | 1834 { |
5794 | 1835 return SET_NONEMPTY_INTERNAL_STRING_VARIABLE (octave_core_file_name); |
1836 } | |
4791 | 1837 |
5794 | 1838 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
|
1839 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
|
1840 @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
|
1841 @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
|
1842 @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
|
1843 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
|
1844 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
|
1845 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1846 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
|
1847 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
|
1848 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
|
1849 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1850 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
|
1851 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
|
1852 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
|
1853 @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
|
1854 @end deftypefn */) |
5794 | 1855 { |
1856 return SET_NONEMPTY_INTERNAL_STRING_VARIABLE (octave_core_file_options); | |
1857 } | |
2194 | 1858 |
5794 | 1859 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
|
1860 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
|
1861 @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
|
1862 @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
|
1863 @deftypefnx {} {} save_header_format_string (@var{new_val}, "local") |
23557
00b11cee2100
doc: Improve documentation for Octave's save-related functions.
Rik <rik@octave.org>
parents:
23455
diff
changeset
|
1864 Query or set the internal variable that specifies the format string used for |
00b11cee2100
doc: Improve documentation for Octave's save-related functions.
Rik <rik@octave.org>
parents:
23455
diff
changeset
|
1865 the comment line written at the beginning of text-format data files saved by |
00b11cee2100
doc: Improve documentation for Octave's save-related functions.
Rik <rik@octave.org>
parents:
23455
diff
changeset
|
1866 Octave. |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1867 |
23557
00b11cee2100
doc: Improve documentation for Octave's save-related functions.
Rik <rik@octave.org>
parents:
23455
diff
changeset
|
1868 The format string is passed to @code{strftime} and must begin with the |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1869 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
|
1870 @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
|
1871 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
|
1872 @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
|
1873 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1874 @smallexample |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1875 "# 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
|
1876 @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
|
1877 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1878 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
|
1879 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
|
1880 The original variable value is restored when exiting the function. |
23557
00b11cee2100
doc: Improve documentation for Octave's save-related functions.
Rik <rik@octave.org>
parents:
23455
diff
changeset
|
1881 @seealso{strftime, save_default_options} |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
1882 @end deftypefn */) |
5794 | 1883 { |
1884 return SET_INTERNAL_VARIABLE (save_header_format_string); | |
2194 | 1885 } |