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