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