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