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