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> |
5765
|
39 #include <sstream> |
1728
|
40 #include <string> |
|
41 |
3687
|
42 #ifdef HAVE_HDF5 |
|
43 #include <hdf5.h> |
|
44 #endif |
|
45 |
1961
|
46 #include "byte-swap.h" |
|
47 #include "data-conv.h" |
2926
|
48 #include "file-ops.h" |
|
49 #include "glob-match.h" |
2890
|
50 #include "lo-mappers.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 |
5775
|
121 // FIXME -- shouldn't this be implemented in terms of other |
630
|
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]; |
5760
|
289 is.read (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; |
5760
|
304 is.read (&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 |
5760
|
327 if (file.read (reinterpret_cast<char *> (magic), 2) && magic[0] == 0x1f && |
5269
|
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 |
5765
|
447 std::ostringstream output_buf; |
4051
|
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 { |
5765
|
563 std::string msg = output_buf.str (); |
2095
|
564 |
621
|
565 if (nargout > 0) |
2095
|
566 retval = msg; |
621
|
567 else |
2095
|
568 octave_stdout << msg; |
621
|
569 } |
3727
|
570 else if (! retstruct.empty ()) |
|
571 retval = retstruct; |
621
|
572 |
863
|
573 return retval; |
|
574 } |
|
575 |
3687
|
576 // HDF5 load/save documentation is included in the Octave manual |
|
577 // regardless, but if HDF5 is not linked in we also include a |
|
578 // sentence noting this, so the user understands that the features |
|
579 // aren't available. Define a macro for this sentence: |
|
580 |
|
581 #ifdef HAVE_HDF5 |
|
582 #define HAVE_HDF5_HELP_STRING "" |
|
583 #else /* ! HAVE_HDF5 */ |
|
584 #define HAVE_HDF5_HELP_STRING "\n\ |
|
585 HDF5 load and save are not available, as this Octave executable was\n\ |
|
586 not linked with the HDF5 library." |
|
587 #endif /* ! HAVE HDF5 */ |
|
588 |
4208
|
589 DEFCMD (load, args, nargout, |
3372
|
590 "-*- texinfo -*-\n\ |
|
591 @deffn {Command} load options file v1 v2 @dots{}\n\ |
|
592 Load the named variables from the file @var{file}. As with @code{save},\n\ |
|
593 you may specify a list of variables and @code{load} will only extract\n\ |
|
594 those variables with names that match. For example, to restore the\n\ |
|
595 variables saved in the file @file{data}, use the command\n\ |
|
596 \n\ |
|
597 @example\n\ |
|
598 load data\n\ |
|
599 @end example\n\ |
863
|
600 \n\ |
5665
|
601 If load is invoked using the functional form\n\ |
|
602 \n\ |
|
603 @example\n\ |
|
604 load (\"-text\", \"file.txt\", \"a\")\n\ |
|
605 @end example\n\ |
|
606 \n\ |
|
607 @noindent\n\ |
|
608 then the @var{options}, @var{file}, and variable name arguments\n\ |
|
609 (@var{v1}, @dots{}) must be specified as character strings.\n\ |
|
610 \n\ |
3372
|
611 If a variable that is not marked as global is loaded from a file when a\n\ |
|
612 global symbol with the same name already exists, it is loaded in the\n\ |
|
613 global symbol table. Also, if a variable is marked as global in a file\n\ |
|
614 and a local symbol exists, the local symbol is moved to the global\n\ |
|
615 symbol table and given the value from the file. Since it seems that\n\ |
|
616 both of these cases are likely to be the result of some sort of error,\n\ |
|
617 they will generate warnings.\n\ |
863
|
618 \n\ |
3727
|
619 If invoked with a single output argument, Octave returns data instead\n\ |
|
620 of inserting variables in the symbol table. If the data file contains\n\ |
|
621 only numbers (TAB- or space-delimited columns), a matrix of values is\n\ |
|
622 returned. Otherwise, @code{load} returns a structure with members\n\ |
|
623 corresponding to the names of the variables in the file.\n\ |
|
624 \n\ |
3372
|
625 The @code{load} command can read data stored in Octave's text and\n\ |
|
626 binary formats, and @sc{Matlab}'s binary format. It will automatically\n\ |
|
627 detect the type of file and do conversion from different floating point\n\ |
|
628 formats (currently only IEEE big and little endian, though other formats\n\ |
|
629 may added in the future).\n\ |
|
630 \n\ |
|
631 Valid options for @code{load} are listed in the following table.\n\ |
863
|
632 \n\ |
3372
|
633 @table @code\n\ |
|
634 @item -force\n\ |
4884
|
635 The @samp{-force} option is accepted but ignored for backward\n\ |
5457
|
636 compatiability. Octave now overwrites variables currently in memory with\n\ |
4884
|
637 the same name as those found in the file.\n\ |
3372
|
638 \n\ |
|
639 @item -ascii\n\ |
|
640 Force Octave to assume the file is in Octave's text format.\n\ |
|
641 \n\ |
5197
|
642 @strong{WARNING: the meaning of this option will change in a future\n\ |
|
643 version of Octave to be compatible with @sc{Matlab}. To keep the\n\ |
|
644 meaning of your code the same across this change, use the @code{-text}\n\ |
|
645 option instead.}\n\ |
|
646 \n\ |
3372
|
647 @item -binary\n\ |
|
648 Force Octave to assume the file is in Octave's binary format.\n\ |
|
649 \n\ |
4884
|
650 @item -mat\n\ |
|
651 @itemx -mat-binary\n\ |
5269
|
652 @itemx -6\n\ |
|
653 @itemx -v6\n\ |
|
654 @itemx -7\n\ |
|
655 @itemx -v7\n\ |
|
656 Force Octave to assume the file is in @sc{Matlab}'s version 6 or 7 binary\n\ |
5256
|
657 format.\n\ |
3687
|
658 \n\ |
5256
|
659 @item -V4\n\ |
|
660 @itemx -v4\n\ |
|
661 @itemx -4\n\ |
|
662 @itemx -mat4-binary\n\ |
3688
|
663 Force Octave to assume the file is in the binary format written by\n\ |
|
664 @sc{Matlab} version 4.\n\ |
|
665 \n\ |
3687
|
666 @item -hdf5\n\ |
|
667 Force Octave to assume the file is in HDF5 format.\n\ |
|
668 (HDF5 is a free, portable binary format developed by the National\n\ |
|
669 Center for Supercomputing Applications at the University of Illinois.)\n\ |
|
670 Note that Octave can read HDF5 files not created by itself, but may\n\ |
4687
|
671 skip some datasets in formats that it cannot support.\n" |
3687
|
672 |
|
673 HAVE_HDF5_HELP_STRING |
|
674 |
|
675 "\n\ |
|
676 @item -import\n\ |
4884
|
677 The @samp{-import} is accepted but ignored for backward compatiability.\n\ |
|
678 Octave can now support multi-dimensional HDF data and automatically\n\ |
|
679 modifies variable names if they are invalid Octave identifiers.\n\ |
3687
|
680 \n\ |
5198
|
681 @item -text\n\ |
5197
|
682 Force Octave to assume the file is in Octave's text format.\n\ |
3372
|
683 @end table\n\ |
|
684 @end deffn") |
863
|
685 { |
2086
|
686 octave_value_list retval; |
863
|
687 |
1755
|
688 int argc = args.length () + 1; |
|
689 |
1968
|
690 string_vector argv = args.make_argv ("load"); |
1755
|
691 |
|
692 if (error_state) |
|
693 return retval; |
863
|
694 |
1358
|
695 // It isn't necessary to have the default load format stored in a |
|
696 // user preference variable since we can determine the type of file |
|
697 // as we are reading. |
863
|
698 |
|
699 load_save_format format = LS_UNKNOWN; |
|
700 |
4691
|
701 bool force = true; |
3019
|
702 bool list_only = false; |
|
703 bool verbose = false; |
863
|
704 |
1755
|
705 int i; |
|
706 for (i = 1; i < argc; i++) |
863
|
707 { |
1755
|
708 if (argv[i] == "-force" || argv[i] == "-f") |
863
|
709 { |
4884
|
710 // Silently ignore this |
|
711 // warning ("load: -force ignored"); |
863
|
712 } |
1755
|
713 else if (argv[i] == "-list" || argv[i] == "-l") |
863
|
714 { |
3019
|
715 list_only = true; |
863
|
716 } |
1755
|
717 else if (argv[i] == "-verbose" || argv[i] == "-v") |
863
|
718 { |
3019
|
719 verbose = true; |
863
|
720 } |
1755
|
721 else if (argv[i] == "-ascii" || argv[i] == "-a") |
863
|
722 { |
5197
|
723 warning ("the meaning of this option will change in a future"); |
5321
|
724 warning ("version of Octave to be compatible with Matlab."); |
5197
|
725 warning ("To keep the meaning of your code the same across"); |
|
726 warning ("this change, use the -text option instead."); |
|
727 |
863
|
728 format = LS_ASCII; |
|
729 } |
1755
|
730 else if (argv[i] == "-binary" || argv[i] == "-b") |
863
|
731 { |
|
732 format = LS_BINARY; |
|
733 } |
5269
|
734 else if (argv[i] == "-mat-binary" || argv[i] == "-mat" || argv[i] == "-m" |
|
735 || argv[i] == "-6" || argv[i] == "-v6") |
863
|
736 { |
3688
|
737 format = LS_MAT5_BINARY; |
|
738 } |
5269
|
739 else if (argv[i] == "7" || argv[i] == "-v7") |
|
740 { |
|
741 format = LS_MAT7_BINARY; |
|
742 } |
5256
|
743 else if (argv[i] == "-mat4-binary" || argv[i] == "-V4" |
|
744 || argv[i] == "-v4" || argv[i] == "-4") |
3688
|
745 { |
863
|
746 format = LS_MAT_BINARY; |
|
747 } |
3687
|
748 else if (argv[i] == "-hdf5" || argv[i] == "-h") |
|
749 { |
|
750 #ifdef HAVE_HDF5 |
|
751 format = LS_HDF5; |
|
752 #else /* ! HAVE_HDF5 */ |
|
753 error ("load: octave executable was not linked with HDF5 library"); |
|
754 return retval; |
|
755 #endif /* ! HAVE_HDF5 */ |
|
756 } |
|
757 else if (argv[i] == "-import" || argv[i] == "-i") |
|
758 { |
4687
|
759 warning ("load: -import ignored"); |
3687
|
760 } |
5197
|
761 else if (argv[i] == "-text" || argv[i] == "-t") |
|
762 { |
|
763 format = LS_ASCII; |
|
764 } |
863
|
765 else |
|
766 break; |
|
767 } |
|
768 |
1755
|
769 if (i == argc) |
863
|
770 { |
2057
|
771 print_usage ("load"); |
863
|
772 return retval; |
|
773 } |
|
774 |
3523
|
775 std::string orig_fname = argv[i]; |
863
|
776 |
4574
|
777 oct_mach_info::float_format flt_fmt = oct_mach_info::flt_fmt_unknown; |
863
|
778 |
3019
|
779 bool swap = false; |
863
|
780 |
1755
|
781 if (argv[i] == "-") |
863
|
782 { |
1755
|
783 i++; |
863
|
784 |
3687
|
785 #ifdef HAVE_HDF5 |
|
786 if (format == LS_HDF5) |
|
787 error ("load: cannot read HDF5 format from stdin"); |
|
788 else |
|
789 #endif /* HAVE_HDF5 */ |
863
|
790 if (format != LS_UNKNOWN) |
|
791 { |
5775
|
792 // FIXME -- if we have already seen EOF on a |
3531
|
793 // previous call, how do we fix up the state of std::cin so |
|
794 // that we can get additional input? I'm afraid that we |
|
795 // can't fix this using std::cin only. |
|
796 |
|
797 retval = do_load (std::cin, orig_fname, force, format, flt_fmt, |
4687
|
798 list_only, swap, verbose, argv, i, argc, |
863
|
799 nargout); |
|
800 } |
|
801 else |
|
802 error ("load: must specify file format if reading from stdin"); |
|
803 } |
|
804 else |
|
805 { |
3523
|
806 std::string fname = file_ops::tilde_expand (argv[i]); |
5269
|
807 bool use_zlib = false; |
863
|
808 |
5089
|
809 // Check if file exists, if it doesn't then also check with a |
|
810 // .mat extension |
|
811 std::ifstream file_exist (fname.c_str ()); |
|
812 if (file_exist) |
|
813 file_exist.close (); |
|
814 else |
|
815 { |
|
816 fname.append (".mat"); |
|
817 std::ifstream file_mat_exist (fname.c_str ()); |
|
818 if (file_mat_exist) |
|
819 file_mat_exist.close (); |
|
820 else |
|
821 { |
5369
|
822 gripe_file_open ("load", orig_fname); |
5089
|
823 return retval; |
|
824 } |
|
825 } |
|
826 |
863
|
827 if (format == LS_UNKNOWN) |
5269
|
828 format = get_file_format (fname, orig_fname, use_zlib); |
863
|
829 |
3687
|
830 #ifdef HAVE_HDF5 |
|
831 if (format == LS_HDF5) |
|
832 { |
|
833 i++; |
|
834 |
5089
|
835 hdf5_ifstream hdf5_file (fname.c_str ()); |
3687
|
836 |
5089
|
837 if (hdf5_file.file_id >= 0) |
|
838 { |
|
839 retval = do_load (hdf5_file, orig_fname, force, format, |
|
840 flt_fmt, list_only, swap, verbose, |
|
841 argv, i, argc, nargout); |
4844
|
842 |
5089
|
843 hdf5_file.close (); |
3687
|
844 } |
4845
|
845 else |
5369
|
846 gripe_file_open ("load", orig_fname); |
3687
|
847 } |
|
848 else |
|
849 #endif /* HAVE_HDF5 */ |
|
850 // don't insert any statements here; the "else" above has to |
|
851 // go with the "if" below!!!!! |
863
|
852 if (format != LS_UNKNOWN) |
|
853 { |
1755
|
854 i++; |
863
|
855 |
3775
|
856 std::ios::openmode mode = std::ios::in; |
4791
|
857 |
|
858 if (format == LS_BINARY |
|
859 #ifdef HAVE_HDF5 |
|
860 || format == LS_HDF5 |
|
861 #endif |
|
862 || format == LS_MAT_BINARY |
5269
|
863 || format == LS_MAT5_BINARY |
|
864 || format == LS_MAT7_BINARY) |
3552
|
865 mode |= std::ios::binary; |
863
|
866 |
5269
|
867 #ifdef HAVE_ZLIB |
|
868 if (use_zlib) |
|
869 { |
|
870 gzifstream file (fname.c_str (), mode); |
863
|
871 |
5269
|
872 if (file) |
863
|
873 { |
5269
|
874 if (format == LS_BINARY) |
|
875 { |
|
876 if (read_binary_file_header (file, swap, flt_fmt) < 0) |
|
877 { |
|
878 if (file) file.close (); |
|
879 return retval; |
|
880 } |
|
881 } |
|
882 else if (format == LS_MAT5_BINARY |
|
883 || format == LS_MAT7_BINARY) |
863
|
884 { |
5269
|
885 if (read_mat5_binary_file_header (file, swap, false) < 0) |
|
886 { |
|
887 if (file) file.close (); |
|
888 return retval; |
|
889 } |
863
|
890 } |
5269
|
891 |
|
892 retval = do_load (file, orig_fname, force, format, |
|
893 flt_fmt, list_only, swap, verbose, |
|
894 argv, i, argc, nargout); |
|
895 |
|
896 file.close (); |
863
|
897 } |
5269
|
898 else |
5369
|
899 gripe_file_open ("load", orig_fname); |
863
|
900 } |
|
901 else |
5269
|
902 #endif |
|
903 { |
|
904 std::ifstream file (fname.c_str (), mode); |
|
905 |
|
906 if (file) |
|
907 { |
|
908 if (format == LS_BINARY) |
|
909 { |
|
910 if (read_binary_file_header (file, swap, flt_fmt) < 0) |
|
911 { |
|
912 if (file) file.close (); |
|
913 return retval; |
|
914 } |
|
915 } |
|
916 else if (format == LS_MAT5_BINARY |
|
917 || format == LS_MAT7_BINARY) |
|
918 { |
|
919 if (read_mat5_binary_file_header (file, swap, false) < 0) |
|
920 { |
|
921 if (file) file.close (); |
|
922 return retval; |
|
923 } |
|
924 } |
|
925 |
|
926 retval = do_load (file, orig_fname, force, format, |
|
927 flt_fmt, list_only, swap, verbose, |
|
928 argv, i, argc, nargout); |
|
929 |
|
930 file.close (); |
|
931 } |
|
932 else |
5369
|
933 error ("load: unable open input file `%s'", |
5269
|
934 orig_fname.c_str ()); |
|
935 } |
863
|
936 } |
|
937 } |
5269
|
938 |
604
|
939 return retval; |
|
940 } |
|
941 |
3019
|
942 // Return TRUE if PATTERN has any special globbing chars in it. |
|
943 |
|
944 static bool |
3523
|
945 glob_pattern_p (const std::string& pattern) |
604
|
946 { |
|
947 int open = 0; |
|
948 |
1755
|
949 int len = pattern.length (); |
|
950 |
|
951 for (int i = 0; i < len; i++) |
604
|
952 { |
1755
|
953 char c = pattern[i]; |
|
954 |
604
|
955 switch (c) |
|
956 { |
|
957 case '?': |
|
958 case '*': |
3019
|
959 return true; |
604
|
960 |
|
961 case '[': // Only accept an open brace if there is a close |
|
962 open++; // brace to match it. Bracket expressions must be |
|
963 continue; // complete, according to Posix.2 |
|
964 |
|
965 case ']': |
|
966 if (open) |
3019
|
967 return true; |
604
|
968 continue; |
4402
|
969 |
604
|
970 case '\\': |
1755
|
971 if (i == len - 1) |
3019
|
972 return false; |
604
|
973 |
|
974 default: |
|
975 continue; |
|
976 } |
|
977 } |
|
978 |
3019
|
979 return false; |
604
|
980 } |
|
981 |
4791
|
982 static void |
|
983 do_save (std::ostream& os, const octave_value& tc, |
|
984 const std::string& name, const std::string& help, |
|
985 int global, load_save_format fmt, bool save_as_floats, |
|
986 bool& infnan_warned) |
604
|
987 { |
|
988 switch (fmt) |
|
989 { |
|
990 case LS_ASCII: |
3738
|
991 save_ascii_data (os, tc, name, infnan_warned, false, global, 0); |
604
|
992 break; |
|
993 |
|
994 case LS_BINARY: |
630
|
995 save_binary_data (os, tc, name, help, global, save_as_floats); |
604
|
996 break; |
|
997 |
667
|
998 case LS_MAT_BINARY: |
|
999 save_mat_binary_data (os, tc, name); |
|
1000 break; |
|
1001 |
3687
|
1002 #ifdef HAVE_HDF5 |
|
1003 case LS_HDF5: |
|
1004 save_hdf5_data (os, tc, name, help, global, save_as_floats); |
|
1005 break; |
|
1006 #endif /* HAVE_HDF5 */ |
|
1007 |
3688
|
1008 case LS_MAT5_BINARY: |
5269
|
1009 save_mat5_binary_element (os, tc, name, global, false, save_as_floats); |
|
1010 break; |
|
1011 |
|
1012 case LS_MAT7_BINARY: |
|
1013 save_mat5_binary_element (os, tc, name, global, true, save_as_floats); |
3688
|
1014 break; |
|
1015 |
604
|
1016 default: |
775
|
1017 gripe_unrecognized_data_fmt ("save"); |
604
|
1018 break; |
|
1019 } |
|
1020 } |
|
1021 |
4791
|
1022 // Save the info from SR on stream OS in the format specified by FMT. |
|
1023 |
|
1024 void |
|
1025 do_save (std::ostream& os, symbol_record *sr, load_save_format fmt, |
|
1026 bool save_as_floats, bool& infnan_warned) |
|
1027 { |
|
1028 if (! sr->is_variable ()) |
|
1029 { |
|
1030 error ("save: can only save variables, not functions"); |
|
1031 return; |
|
1032 } |
|
1033 |
|
1034 octave_value tc = sr->def (); |
|
1035 |
|
1036 if (tc.is_defined ()) |
|
1037 { |
|
1038 std::string name = sr->name (); |
|
1039 std::string help = sr->help (); |
|
1040 |
|
1041 int global = sr->is_linked_to_global (); |
|
1042 |
|
1043 do_save (os, tc, name, help, global, fmt, save_as_floats, |
|
1044 infnan_warned); |
|
1045 } |
|
1046 } |
|
1047 |
604
|
1048 // Save variables with names matching PATTERN on stream OS in the |
3019
|
1049 // format specified by FMT. If SAVE_BUILTINS is TRUE, also save |
604
|
1050 // builtin variables with names that match PATTERN. |
|
1051 |
|
1052 static int |
3523
|
1053 save_vars (std::ostream& os, const std::string& pattern, bool save_builtins, |
4791
|
1054 load_save_format fmt, bool save_as_floats) |
604
|
1055 { |
3355
|
1056 Array<symbol_record *> vars = curr_sym_tab->glob |
|
1057 (pattern, symbol_record::USER_VARIABLE, SYMTAB_ALL_SCOPES); |
|
1058 |
|
1059 int saved = vars.length (); |
|
1060 |
3738
|
1061 bool infnan_warned = false; |
|
1062 |
3355
|
1063 for (int i = 0; i < saved; 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 |
620
|
1071 if (! error_state && save_builtins) |
604
|
1072 { |
4009
|
1073 vars = fbi_sym_tab->glob |
3355
|
1074 (pattern, symbol_record::BUILTIN_VARIABLE, SYMTAB_ALL_SCOPES); |
|
1075 |
|
1076 int count = vars.length (); |
604
|
1077 |
|
1078 saved += count; |
|
1079 |
3355
|
1080 for (int i = 0; i < count; i++) |
620
|
1081 { |
4791
|
1082 do_save (os, vars(i), fmt, save_as_floats, infnan_warned); |
620
|
1083 |
|
1084 if (error_state) |
|
1085 break; |
|
1086 } |
604
|
1087 } |
|
1088 |
|
1089 return saved; |
|
1090 } |
|
1091 |
5284
|
1092 static int |
|
1093 parse_save_options (const string_vector &argv, int argc, |
|
1094 load_save_format &format, bool &append, |
|
1095 bool &save_as_floats, bool &save_builtins, |
|
1096 bool &use_zlib, int start_arg) |
604
|
1097 { |
5284
|
1098 int i; |
|
1099 for (i = start_arg; i < argc; i++) |
|
1100 { |
|
1101 if (argv[i] == "-append") |
|
1102 { |
|
1103 append = true; |
|
1104 } |
|
1105 else if (argv[i] == "-ascii" || argv[i] == "-a") |
|
1106 { |
|
1107 warning ("the meaning of this option will change in a future"); |
5321
|
1108 warning ("version of Octave to be compatible with Matlab."); |
5284
|
1109 warning ("To keep the meaning of your code the same across"); |
|
1110 warning ("this change, use the -text option instead."); |
1755
|
1111 |
5284
|
1112 format = LS_ASCII; |
|
1113 } |
|
1114 else if (argv[i] == "-text" || argv[i] == "-t") |
|
1115 { |
|
1116 format = LS_ASCII; |
|
1117 } |
|
1118 else if (argv[i] == "-binary" || argv[i] == "-b") |
|
1119 { |
|
1120 format = LS_BINARY; |
|
1121 } |
|
1122 else if (argv[i] == "-hdf5" || argv[i] == "-h") |
|
1123 { |
3687
|
1124 #ifdef HAVE_HDF5 |
5284
|
1125 format = LS_HDF5; |
|
1126 #else /* ! HAVE_HDF5 */ |
|
1127 error ("save: octave executable was not linked with HDF5 library"); |
|
1128 #endif /* ! HAVE_HDF5 */ |
|
1129 } |
|
1130 else if (argv[i] == "-mat-binary" || argv[i] == "-mat" |
|
1131 || argv[i] == "-m" || argv[i] == "-6" || argv[i] == "-v6" |
|
1132 || argv[i] == "-V6") |
|
1133 { |
|
1134 format = LS_MAT5_BINARY; |
|
1135 } |
|
1136 #ifdef HAVE_ZLIB |
|
1137 else if (argv[i] == "-mat7-binary" || argv[i] == "-7" |
|
1138 || argv[i] == "-v7" || argv[i] == "-V7") |
|
1139 { |
|
1140 format = LS_MAT7_BINARY; |
|
1141 } |
|
1142 #endif |
|
1143 else if (argv[i] == "-mat4-binary" || argv[i] == "-V4" |
|
1144 || argv[i] == "-v4" || argv[i] == "-4") |
|
1145 { |
|
1146 format = LS_MAT_BINARY; |
|
1147 } |
|
1148 else if (argv[i] == "-float-binary" || argv[i] == "-f") |
|
1149 { |
|
1150 format = LS_BINARY; |
|
1151 save_as_floats = true; |
|
1152 } |
|
1153 else if (argv[i] == "-float-hdf5") |
|
1154 { |
|
1155 #ifdef HAVE_HDF5 |
|
1156 format = LS_HDF5; |
|
1157 save_as_floats = true; |
|
1158 #else /* ! HAVE_HDF5 */ |
|
1159 error ("save: octave executable was not linked with HDF5 library"); |
|
1160 #endif /* ! HAVE_HDF5 */ |
|
1161 } |
|
1162 else if (argv[i] == "-save-builtins") |
|
1163 { |
|
1164 save_builtins = true; |
|
1165 } |
|
1166 #ifdef HAVE_ZLIB |
|
1167 else if (argv[i] == "-zip" || argv[i] == "-z") |
|
1168 { |
|
1169 use_zlib = true; |
|
1170 } |
|
1171 #endif |
|
1172 else |
|
1173 break; |
|
1174 } |
|
1175 |
|
1176 return i; |
|
1177 } |
|
1178 |
|
1179 static int |
|
1180 parse_save_options (const std::string &arg, load_save_format &format, |
|
1181 bool &append, bool &save_as_floats, |
|
1182 bool &save_builtins, bool &use_zlib, int start_arg) |
|
1183 { |
5765
|
1184 std::istringstream is (arg); |
5284
|
1185 std::string str; |
|
1186 int argc = 0; |
|
1187 string_vector argv; |
|
1188 |
5765
|
1189 while (! is.eof ()) |
5284
|
1190 { |
|
1191 is >> str; |
|
1192 argv.append (str); |
|
1193 argc++; |
|
1194 } |
|
1195 |
|
1196 return parse_save_options (argv, argc, format, append, save_as_floats, |
|
1197 save_builtins, use_zlib, start_arg); |
604
|
1198 } |
|
1199 |
4329
|
1200 void |
3523
|
1201 write_header (std::ostream& os, load_save_format format) |
863
|
1202 { |
3185
|
1203 switch (format) |
863
|
1204 { |
3185
|
1205 case LS_BINARY: |
|
1206 { |
|
1207 os << (oct_mach_info::words_big_endian () |
|
1208 ? "Octave-1-B" : "Octave-1-L"); |
|
1209 |
|
1210 oct_mach_info::float_format flt_fmt = |
|
1211 oct_mach_info::native_float_format (); |
|
1212 |
5760
|
1213 char tmp = static_cast<char> (float_format_to_mopt_digit (flt_fmt)); |
3185
|
1214 |
5760
|
1215 os.write (&tmp, 1); |
3185
|
1216 } |
3688
|
1217 break; |
|
1218 |
|
1219 case LS_MAT5_BINARY: |
5269
|
1220 case LS_MAT7_BINARY: |
3688
|
1221 { |
3775
|
1222 char const * versionmagic; |
3688
|
1223 TWO_BYTE_INT number = *(TWO_BYTE_INT *)"\x00\x01"; |
|
1224 struct tm bdt; |
|
1225 time_t now; |
|
1226 char headertext[128]; |
|
1227 |
|
1228 time (&now); |
|
1229 bdt = *gmtime (&now); |
|
1230 memset (headertext, ' ', 124); |
|
1231 // ISO 8601 format date |
|
1232 strftime (headertext, 124, "MATLAB 5.0 MAT-file, written by Octave " |
5760
|
1233 OCTAVE_VERSION ", %Y-%m-%d %T UTC", &bdt); |
3688
|
1234 |
|
1235 // The first pair of bytes give the version of the MAT file |
|
1236 // format. The second pair of bytes form a magic number which |
|
1237 // signals a MAT file. MAT file data are always written in |
|
1238 // native byte order. The order of the bytes in the second |
|
1239 // pair indicates whether the file was written by a big- or |
|
1240 // little-endian machine. However, the version number is |
|
1241 // written in the *opposite* byte order from everything else! |
|
1242 if (number == 1) |
|
1243 versionmagic = "\x01\x00\x4d\x49"; // this machine is big endian |
|
1244 else |
|
1245 versionmagic = "\x00\x01\x49\x4d"; // this machine is little endian |
|
1246 |
|
1247 memcpy (headertext+124, versionmagic, 4); |
|
1248 os.write (headertext, 128); |
|
1249 } |
|
1250 |
|
1251 break; |
3185
|
1252 |
3687
|
1253 #ifdef HAVE_HDF5 |
|
1254 case LS_HDF5: |
|
1255 #endif /* HAVE_HDF5 */ |
3185
|
1256 case LS_ASCII: |
|
1257 { |
3709
|
1258 octave_localtime now; |
|
1259 |
|
1260 std::string comment_string = now.strftime (Vsave_header_format_string); |
|
1261 |
|
1262 if (! comment_string.empty ()) |
|
1263 { |
3687
|
1264 #ifdef HAVE_HDF5 |
3709
|
1265 if (format == LS_HDF5) |
|
1266 { |
5760
|
1267 hdf5_ofstream& hs = dynamic_cast<hdf5_ofstream&> (os); |
3709
|
1268 H5Gset_comment (hs.file_id, "/", comment_string.c_str ()); |
|
1269 } |
|
1270 else |
3687
|
1271 #endif /* HAVE_HDF5 */ |
3709
|
1272 os << comment_string << "\n"; |
3687
|
1273 } |
3185
|
1274 } |
|
1275 break; |
|
1276 |
|
1277 default: |
|
1278 break; |
863
|
1279 } |
|
1280 } |
|
1281 |
|
1282 static void |
3769
|
1283 save_vars (const string_vector& argv, int argv_idx, int argc, |
3523
|
1284 std::ostream& os, bool save_builtins, load_save_format fmt, |
3185
|
1285 bool save_as_floats, bool write_header_info) |
863
|
1286 { |
3185
|
1287 if (write_header_info) |
|
1288 write_header (os, fmt); |
863
|
1289 |
1755
|
1290 if (argv_idx == argc) |
863
|
1291 { |
|
1292 save_vars (os, "*", save_builtins, fmt, save_as_floats); |
|
1293 } |
|
1294 else |
|
1295 { |
1755
|
1296 for (int i = argv_idx; i < argc; i++) |
863
|
1297 { |
1755
|
1298 if (! save_vars (os, argv[i], save_builtins, fmt, save_as_floats)) |
863
|
1299 { |
1755
|
1300 warning ("save: no such variable `%s'", argv[i].c_str ()); |
863
|
1301 } |
|
1302 } |
|
1303 } |
|
1304 } |
|
1305 |
5284
|
1306 static void |
|
1307 dump_octave_core (std::ostream& os, const char *fname, load_save_format fmt, |
|
1308 bool save_as_floats) |
4791
|
1309 { |
|
1310 write_header (os, fmt); |
|
1311 |
|
1312 Array<symbol_record *> vars = curr_sym_tab->glob |
|
1313 ("*", symbol_record::USER_VARIABLE, SYMTAB_ALL_SCOPES); |
|
1314 |
|
1315 int num_to_save = vars.length (); |
|
1316 |
|
1317 bool infnan_warned = false; |
|
1318 |
|
1319 double save_mem_size = 0; |
|
1320 |
|
1321 for (int i = 0; i < num_to_save; i++) |
|
1322 { |
|
1323 symbol_record *sr = vars(i); |
|
1324 |
|
1325 if (sr->is_variable ()) |
|
1326 { |
|
1327 octave_value tc = sr->def (); |
|
1328 |
|
1329 if (tc.is_defined ()) |
|
1330 { |
|
1331 double tc_size = tc.byte_size () / 1024; |
|
1332 |
5775
|
1333 // FIXME -- maybe we should try to throw out the |
4791
|
1334 // largest first... |
|
1335 |
|
1336 if (Voctave_core_file_limit < 0 |
|
1337 || save_mem_size + tc_size < Voctave_core_file_limit) |
|
1338 { |
|
1339 save_mem_size += tc_size; |
|
1340 |
|
1341 std::string name = sr->name (); |
|
1342 std::string help = sr->help (); |
|
1343 |
|
1344 int global = sr->is_linked_to_global (); |
|
1345 |
5284
|
1346 do_save (os, tc, name, help, global, fmt, save_as_floats, |
4791
|
1347 infnan_warned); |
|
1348 |
|
1349 if (error_state) |
|
1350 break; |
|
1351 } |
|
1352 } |
|
1353 } |
|
1354 } |
|
1355 |
|
1356 message (0, "save to `%s' complete", fname); |
|
1357 } |
|
1358 |
|
1359 void |
|
1360 dump_octave_core (void) |
1380
|
1361 { |
3189
|
1362 if (Vcrash_dumps_octave_core) |
1380
|
1363 { |
5775
|
1364 // FIXME -- should choose better file name? |
3189
|
1365 |
4791
|
1366 const char *fname = Voctave_core_file_name.c_str (); |
3189
|
1367 |
|
1368 message (0, "attempting to save variables to `%s'...", fname); |
|
1369 |
5284
|
1370 load_save_format format = LS_BINARY; |
|
1371 |
|
1372 bool save_builtins = false; |
|
1373 |
|
1374 bool save_as_floats = false; |
|
1375 |
|
1376 bool append = false; |
3189
|
1377 |
5284
|
1378 bool use_zlib = false; |
|
1379 |
|
1380 // Note save_builtins is ignored |
|
1381 parse_save_options (Voctave_core_file_options, format, append, |
|
1382 save_as_floats, save_builtins, use_zlib, 0); |
|
1383 |
|
1384 std::ios::openmode mode = std::ios::out; |
4791
|
1385 |
|
1386 if (format == LS_BINARY |
|
1387 #ifdef HAVE_HDF5 |
|
1388 || format == LS_HDF5 |
|
1389 #endif |
|
1390 || format == LS_MAT_BINARY |
5269
|
1391 || format == LS_MAT5_BINARY |
|
1392 || format == LS_MAT7_BINARY) |
3552
|
1393 mode |= std::ios::binary; |
3189
|
1394 |
5284
|
1395 mode |= append ? std::ios::ate : std::ios::trunc; |
|
1396 |
3687
|
1397 #ifdef HAVE_HDF5 |
|
1398 if (format == LS_HDF5) |
3189
|
1399 { |
3687
|
1400 hdf5_ofstream file (fname); |
|
1401 |
|
1402 if (file.file_id >= 0) |
|
1403 { |
5284
|
1404 dump_octave_core (file, fname, format, save_as_floats); |
3687
|
1405 |
|
1406 file.close (); |
|
1407 } |
|
1408 else |
|
1409 warning ("unable to open `%s' for writing...", fname); |
3189
|
1410 } |
|
1411 else |
3687
|
1412 #endif /* HAVE_HDF5 */ |
|
1413 // don't insert any commands here! The open brace below must |
|
1414 // go with the else above! |
|
1415 { |
5284
|
1416 #ifdef HAVE_ZLIB |
|
1417 if (use_zlib) |
3687
|
1418 { |
5284
|
1419 gzofstream file (fname, mode); |
4791
|
1420 |
5284
|
1421 if (file) |
|
1422 { |
|
1423 dump_octave_core (file, fname, format, save_as_floats); |
|
1424 |
|
1425 file.close (); |
|
1426 } |
|
1427 else |
|
1428 warning ("unable to open `%s' for writing...", fname); |
3687
|
1429 } |
|
1430 else |
5284
|
1431 #endif |
|
1432 { |
|
1433 std::ofstream file (fname, mode); |
|
1434 |
|
1435 if (file) |
|
1436 { |
|
1437 dump_octave_core (file, fname, format, save_as_floats); |
|
1438 |
|
1439 file.close (); |
|
1440 } |
|
1441 else |
|
1442 warning ("unable to open `%s' for writing...", fname); |
|
1443 } |
3687
|
1444 } |
1380
|
1445 } |
|
1446 } |
|
1447 |
5269
|
1448 #ifdef HAVE_ZLIB |
|
1449 #define HAVE_ZLIB_HELP_STRING "" |
|
1450 #else /* ! HAVE_ZLIB */ |
|
1451 #define HAVE_ZLIB_HELP_STRING "\n\ |
|
1452 This option is not available, as this Octave executable was not linked with\n\ |
|
1453 the zlib library." |
|
1454 #endif /* ! HAVE ZLIB */ |
|
1455 |
4208
|
1456 DEFCMD (save, args, , |
3372
|
1457 "-*- texinfo -*-\n\ |
5665
|
1458 @deffn {Command} save options file @var{v1} @var{v2} @dots{}\n\ |
3372
|
1459 Save the named variables @var{v1}, @var{v2}, @dots{} in the file\n\ |
|
1460 @var{file}. The special filename @samp{-} can be used to write the\n\ |
|
1461 output to your terminal. If no variable names are listed, Octave saves\n\ |
|
1462 all the variables in the current scope. Valid options for the\n\ |
|
1463 @code{save} command are listed in the following table. Options that\n\ |
|
1464 modify the output format override the format specified by the built-in\n\ |
5284
|
1465 variable @code{default_save_options}.\n\ |
3372
|
1466 \n\ |
5665
|
1467 If save is invoked using the functional form\n\ |
|
1468 \n\ |
|
1469 @example\n\ |
|
1470 save (\"-text\", \"file.txt\", \"a\")\n\ |
|
1471 @end example\n\ |
|
1472 \n\ |
|
1473 @noindent\n\ |
|
1474 then the @var{options}, @var{file}, and variable name arguments\n\ |
|
1475 (@var{vname1}, @dots{}) must be specified as character strings.\n\ |
|
1476 \n\ |
3372
|
1477 @table @code\n\ |
|
1478 @item -ascii\n\ |
|
1479 Save the data in Octave's text data format.\n\ |
|
1480 \n\ |
5197
|
1481 @strong{WARNING: the meaning of this option will change in a future\n\ |
|
1482 version of Octave to be compatible with @sc{Matlab}. To keep the\n\ |
|
1483 meaning of your code the same across this change, use the @code{-text}\n\ |
|
1484 option instead.}\n\ |
|
1485 \n\ |
3372
|
1486 @item -binary\n\ |
|
1487 Save the data in Octave's binary data format.\n\ |
|
1488 \n\ |
|
1489 @item -float-binary\n\ |
|
1490 Save the data in Octave's binary data format but only using single\n\ |
|
1491 precision. You should use this format only if you know that all the\n\ |
|
1492 values to be saved can be represented in single precision.\n\ |
|
1493 \n\ |
5269
|
1494 @item -V7\n\ |
|
1495 @itemx -v7\n\ |
|
1496 @itemx -7\n\ |
|
1497 @itemx -mat7-binary\n\ |
|
1498 Save the data in @sc{Matlab}'s v7 binary data format.\n" |
|
1499 |
|
1500 HAVE_ZLIB_HELP_STRING |
|
1501 |
|
1502 "\n\ |
|
1503 @item -V6\n\ |
5284
|
1504 @itemx -v6\n\ |
5269
|
1505 @itemx -6\n\ |
|
1506 @itemx -mat\n\ |
4884
|
1507 @itemx -mat-binary\n\ |
5269
|
1508 Save the data in @sc{Matlab}'s v6 binary data format.\n\ |
3372
|
1509 \n\ |
5256
|
1510 @item -V4\n\ |
|
1511 @itemx -v4\n\ |
|
1512 @itemx -4\n\ |
|
1513 @itemx -mat4-binary\n\ |
3688
|
1514 Save the data in the binary format written by @sc{Matlab} version 4.\n\ |
|
1515 \n\ |
3687
|
1516 @item -hdf5\n\ |
|
1517 Save the data in HDF5 format.\n\ |
|
1518 (HDF5 is a free, portable binary format developed by the National\n\ |
|
1519 Center for Supercomputing Applications at the University of Illinois.)\n" |
|
1520 |
|
1521 HAVE_HDF5_HELP_STRING |
|
1522 |
|
1523 "\n\ |
|
1524 @item -float-hdf5\n\ |
|
1525 Save the data in HDF5 format but only using single precision.\n\ |
|
1526 You should use this format only if you know that all the\n\ |
|
1527 values to be saved can be represented in single precision.\n\ |
|
1528 \n\ |
3372
|
1529 @item -save-builtins\n\ |
|
1530 Force Octave to save the values of built-in variables too. By default,\n\ |
|
1531 Octave does not save built-in variables.\n\ |
5269
|
1532 \n\ |
|
1533 @item -zip\n\ |
|
1534 @itemx -z\n\ |
|
1535 Use the gzip algorithm to compress the file. This works equally on files that\n\ |
|
1536 are compressed with gzip outside of octave, and gzip can equally be used to\n\ |
5380
|
1537 convert the files for backward compatibility.\n" |
5322
|
1538 |
|
1539 HAVE_ZLIB_HELP_STRING |
|
1540 |
5269
|
1541 "@end table\n\ |
604
|
1542 \n\ |
3372
|
1543 The list of variables to save may include wildcard patterns containing\n\ |
|
1544 the following special characters:\n\ |
|
1545 @table @code\n\ |
|
1546 @item ?\n\ |
|
1547 Match any single character.\n\ |
|
1548 \n\ |
|
1549 @item *\n\ |
|
1550 Match zero or more characters.\n\ |
|
1551 \n\ |
|
1552 @item [ @var{list} ]\n\ |
|
1553 Match the list of characters specified by @var{list}. If the first\n\ |
|
1554 character is @code{!} or @code{^}, match all characters except those\n\ |
|
1555 specified by @var{list}. For example, the pattern @samp{[a-zA-Z]} will\n\ |
|
1556 match all lower and upper case alphabetic characters. \n\ |
5197
|
1557 \n\ |
5198
|
1558 @item -text\n\ |
5197
|
1559 Save the data in Octave's text data format.\n\ |
3372
|
1560 @end table\n\ |
|
1561 \n\ |
|
1562 Except when using the @sc{Matlab} binary data file format, saving global\n\ |
|
1563 variables also saves the global status of the variable, so that if it is\n\ |
|
1564 restored at a later time using @samp{load}, it will be restored as a\n\ |
|
1565 global variable.\n\ |
|
1566 \n\ |
|
1567 The command\n\ |
|
1568 \n\ |
|
1569 @example\n\ |
|
1570 save -binary data a b*\n\ |
|
1571 @end example\n\ |
|
1572 \n\ |
|
1573 @noindent\n\ |
|
1574 saves the variable @samp{a} and all variables beginning with @samp{b} to\n\ |
|
1575 the file @file{data} in Octave's binary format.\n\ |
|
1576 @end deffn") |
604
|
1577 { |
2086
|
1578 octave_value_list retval; |
604
|
1579 |
1755
|
1580 int argc = args.length () + 1; |
|
1581 |
1968
|
1582 string_vector argv = args.make_argv ("save"); |
1755
|
1583 |
|
1584 if (error_state) |
|
1585 return retval; |
604
|
1586 |
1358
|
1587 // Here is where we would get the default save format if it were |
|
1588 // stored in a user preference variable. |
604
|
1589 |
3019
|
1590 bool save_builtins = false; |
|
1591 |
|
1592 bool save_as_floats = false; |
630
|
1593 |
5284
|
1594 load_save_format format = LS_ASCII; |
604
|
1595 |
3185
|
1596 bool append = false; |
|
1597 |
5269
|
1598 bool use_zlib = false; |
|
1599 |
5351
|
1600 load_save_format user_file_format = LS_UNKNOWN; |
|
1601 bool dummy; |
|
1602 |
|
1603 // Get user file format |
|
1604 parse_save_options (argv, argc, user_file_format, dummy, |
|
1605 dummy, dummy, dummy, 1); |
|
1606 |
|
1607 if (user_file_format == LS_UNKNOWN) |
|
1608 parse_save_options (Vdefault_save_options, format, append, save_as_floats, |
|
1609 save_builtins, use_zlib, 0); |
|
1610 |
5284
|
1611 int i = parse_save_options (argv, argc, format, append, save_as_floats, |
5351
|
1612 save_builtins, use_zlib, 1); |
5197
|
1613 |
5284
|
1614 if (error_state) |
|
1615 return retval; |
604
|
1616 |
2057
|
1617 if (i == argc) |
604
|
1618 { |
|
1619 print_usage ("save"); |
|
1620 return retval; |
|
1621 } |
|
1622 |
630
|
1623 if (save_as_floats && format == LS_ASCII) |
|
1624 { |
|
1625 error ("save: cannot specify both -ascii and -float-binary"); |
|
1626 return retval; |
|
1627 } |
|
1628 |
1755
|
1629 if (argv[i] == "-") |
604
|
1630 { |
1755
|
1631 i++; |
863
|
1632 |
3687
|
1633 #ifdef HAVE_HDF5 |
|
1634 if (format == LS_HDF5) |
4687
|
1635 error ("save: cannot write HDF5 format to stdout"); |
3687
|
1636 else |
|
1637 #endif /* HAVE_HDF5 */ |
|
1638 // don't insert any commands here! the brace below must go |
|
1639 // with the "else" above! |
|
1640 { |
5775
|
1641 // FIXME -- should things intended for the screen end up |
3687
|
1642 // in a octave_value (string)? |
|
1643 |
|
1644 save_vars (argv, i, argc, octave_stdout, save_builtins, format, |
|
1645 save_as_floats, true); |
|
1646 } |
604
|
1647 } |
1755
|
1648 |
|
1649 // Guard against things like `save a*', which are probably mistakes... |
|
1650 |
|
1651 else if (i == argc - 1 && glob_pattern_p (argv[i])) |
|
1652 { |
|
1653 print_usage ("save"); |
604
|
1654 return retval; |
|
1655 } |
|
1656 else |
|
1657 { |
3523
|
1658 std::string fname = file_ops::tilde_expand (argv[i]); |
1755
|
1659 |
|
1660 i++; |
604
|
1661 |
3775
|
1662 std::ios::openmode mode = std::ios::out; |
4791
|
1663 |
|
1664 if (format == LS_BINARY |
|
1665 #ifdef HAVE_HDF5 |
|
1666 || format == LS_HDF5 |
|
1667 #endif |
|
1668 || format == LS_MAT_BINARY |
5269
|
1669 || format == LS_MAT5_BINARY |
|
1670 || format == LS_MAT7_BINARY) |
3552
|
1671 mode |= std::ios::binary; |
3538
|
1672 |
|
1673 mode |= append ? std::ios::ate : std::ios::trunc; |
3185
|
1674 |
3687
|
1675 #ifdef HAVE_HDF5 |
|
1676 if (format == LS_HDF5) |
863
|
1677 { |
3687
|
1678 hdf5_ofstream hdf5_file (fname.c_str ()); |
|
1679 |
4687
|
1680 if (hdf5_file.file_id >= 0) |
|
1681 { |
|
1682 save_vars (argv, i, argc, hdf5_file, save_builtins, format, |
|
1683 save_as_floats, true); |
3687
|
1684 |
4687
|
1685 hdf5_file.close (); |
3687
|
1686 } |
|
1687 else |
|
1688 { |
5369
|
1689 gripe_file_open ("save", fname); |
3687
|
1690 return retval; |
|
1691 } |
863
|
1692 } |
|
1693 else |
3687
|
1694 #endif /* HAVE_HDF5 */ |
|
1695 // don't insert any statements here! The brace below must go |
|
1696 // with the "else" above! |
604
|
1697 { |
5269
|
1698 #ifdef HAVE_ZLIB |
|
1699 if (use_zlib) |
3687
|
1700 { |
5269
|
1701 gzofstream file (fname.c_str (), mode); |
|
1702 |
|
1703 if (file) |
|
1704 { |
|
1705 bool write_header_info |
|
1706 = ((file.rdbuf ())->pubseekoff (0, std::ios::cur) |
|
1707 == static_cast<std::streampos> (0)); |
3687
|
1708 |
5269
|
1709 save_vars (argv, i, argc, file, save_builtins, format, |
|
1710 save_as_floats, write_header_info); |
|
1711 |
|
1712 file.close (); |
|
1713 } |
|
1714 else |
|
1715 { |
5369
|
1716 gripe_file_open ("save", fname); |
5269
|
1717 return retval; |
|
1718 } |
3687
|
1719 } |
|
1720 else |
5269
|
1721 #endif |
3687
|
1722 { |
5269
|
1723 std::ofstream file (fname.c_str (), mode); |
|
1724 |
|
1725 if (file) |
|
1726 { |
|
1727 bool write_header_info |
|
1728 = ((file.rdbuf ())->pubseekoff (0, std::ios::cur) |
|
1729 == static_cast<std::streampos> (0)); |
|
1730 |
|
1731 save_vars (argv, i, argc, file, save_builtins, format, |
|
1732 save_as_floats, write_header_info); |
|
1733 |
|
1734 file.close (); |
|
1735 } |
|
1736 else |
|
1737 { |
5369
|
1738 gripe_file_open ("save", fname); |
5269
|
1739 return retval; |
|
1740 } |
3687
|
1741 } |
604
|
1742 } |
|
1743 } |
|
1744 |
|
1745 return retval; |
|
1746 } |
|
1747 |
2194
|
1748 static int |
3189
|
1749 crash_dumps_octave_core (void) |
|
1750 { |
|
1751 Vcrash_dumps_octave_core = check_preference ("crash_dumps_octave_core"); |
4449
|
1752 |
3189
|
1753 return 0; |
|
1754 } |
|
1755 |
|
1756 static int |
5284
|
1757 default_save_options (void) |
2194
|
1758 { |
|
1759 int status = 0; |
|
1760 |
5284
|
1761 std::string s = builtin_string_variable ("default_save_options"); |
2194
|
1762 |
|
1763 if (s.empty ()) |
|
1764 { |
5284
|
1765 gripe_invalid_value_specified ("default_save_options"); |
2194
|
1766 status = -1; |
|
1767 } |
|
1768 else |
5284
|
1769 Vdefault_save_options = s; |
2194
|
1770 |
|
1771 return status; |
|
1772 } |
|
1773 |
4788
|
1774 static int |
4791
|
1775 octave_core_file_limit (void) |
|
1776 { |
|
1777 double val; |
|
1778 |
|
1779 if (builtin_real_scalar_variable ("octave_core_file_limit", val)) |
|
1780 { |
|
1781 Voctave_core_file_limit = val; |
|
1782 return 0; |
|
1783 } |
|
1784 else |
|
1785 gripe_invalid_value_specified ("octave_core_file_limit"); |
|
1786 |
|
1787 return -1; |
|
1788 } |
|
1789 |
|
1790 static int |
|
1791 octave_core_file_name (void) |
4788
|
1792 { |
|
1793 int status = 0; |
|
1794 |
4791
|
1795 std::string s = builtin_string_variable ("octave_core_file_name"); |
4788
|
1796 |
|
1797 if (s.empty ()) |
|
1798 { |
4791
|
1799 gripe_invalid_value_specified ("octave_core_file_name"); |
4788
|
1800 status = -1; |
|
1801 } |
|
1802 else |
4791
|
1803 Voctave_core_file_name = s; |
|
1804 |
|
1805 return status; |
|
1806 } |
|
1807 |
|
1808 static int |
5284
|
1809 octave_core_file_options (void) |
4791
|
1810 { |
|
1811 int status = 0; |
|
1812 |
5284
|
1813 std::string s = builtin_string_variable ("octave_core_file_options"); |
4791
|
1814 |
|
1815 if (s.empty ()) |
|
1816 { |
5284
|
1817 gripe_invalid_value_specified ("octave_core_file_options"); |
4791
|
1818 status = -1; |
|
1819 } |
|
1820 else |
5284
|
1821 Voctave_core_file_options = s; |
4788
|
1822 |
|
1823 return status; |
|
1824 } |
|
1825 |
3769
|
1826 static std::string |
3709
|
1827 default_save_header_format (void) |
|
1828 { |
|
1829 return |
4633
|
1830 std::string ("# Created by Octave " OCTAVE_VERSION |
|
1831 ", %a %b %d %H:%M:%S %Y %Z <") |
3709
|
1832 + octave_env::get_user_name () |
|
1833 + std::string ("@") |
|
1834 + octave_env::get_host_name () |
|
1835 + std::string (">"); |
|
1836 } |
|
1837 |
|
1838 static int |
|
1839 save_header_format_string (void) |
|
1840 { |
|
1841 int status = 0; |
|
1842 |
|
1843 octave_value v = builtin_any_variable ("save_header_format_string"); |
|
1844 |
|
1845 if (v.is_string ()) |
|
1846 Vsave_header_format_string = v.string_value (); |
|
1847 else |
|
1848 { |
|
1849 gripe_invalid_value_specified ("save_header_format_string"); |
|
1850 status = -1; |
|
1851 } |
|
1852 |
|
1853 return status; |
|
1854 } |
|
1855 |
2194
|
1856 void |
|
1857 symbols_of_load_save (void) |
|
1858 { |
4233
|
1859 DEFVAR (crash_dumps_octave_core, true, crash_dumps_octave_core, |
3372
|
1860 "-*- texinfo -*-\n\ |
|
1861 @defvr {Built-in Variable} crash_dumps_octave_core\n\ |
|
1862 If this variable is set to a nonzero value, Octave tries to save all\n\ |
|
1863 current variables the the file \"octave-core\" if it crashes or receives a\n\ |
|
1864 hangup, terminate or similar signal. The default value is 1.\n\ |
5642
|
1865 @seealso{octave_core_file_limit, octave_core_file_name, octave_core_file_options}\n\ |
3372
|
1866 @end defvr"); |
3189
|
1867 |
5284
|
1868 DEFVAR (default_save_options, "-text", default_save_options, |
3372
|
1869 "-*- texinfo -*-\n\ |
5284
|
1870 @defvr {Built-in Variable} default_save_options\n\ |
|
1871 This variable specifies the default options for the @code{save} command,\n\ |
|
1872 and is used to define the default format. Typical values include,\n\ |
|
1873 @code{\"-ascii\"}, @code{\"-ascii -zip\"}. For other possible options\n\ |
|
1874 see the @code{save} command. The initial value of this variable is\n\ |
|
1875 @code{-ascii}.\n\ |
4791
|
1876 @end defvr"); |
|
1877 |
|
1878 DEFVAR (octave_core_file_limit, -1.0, octave_core_file_limit, |
|
1879 "-*- texinfo -*-\n\ |
|
1880 @defvr {Built-in Variable} octave_core_file_limit\n\ |
|
1881 The maximum amount of memory (in kilobytes) of the top-level workspace\n\ |
|
1882 that Octave will attempt to write when saving data to the\n\ |
5284
|
1883 @var{octave_core_file_name}. If @var{octave_core_file_options} flags a\n\ |
4791
|
1884 binary format, then @var{octave_core_file_limit} will be approximately\n\ |
|
1885 the maximum size of the file. If a text file format is used, then the\n\ |
|
1886 file could be much larger than the limit.\n\ |
|
1887 The default value is -1 (unlimited)\n\ |
5642
|
1888 @seealso{crash_dumps_octave_core, octave_core_file_name, octave_core_file_options}\n\ |
4788
|
1889 @end defvr"); |
|
1890 |
4791
|
1891 DEFVAR (octave_core_file_name, "octave-core", octave_core_file_name, |
4788
|
1892 "-*- texinfo -*-\n\ |
4791
|
1893 @defvr {Built-in Variable} octave_core_file_name\n\ |
|
1894 The name of the file used for saving data from the top-level workspace\n\ |
|
1895 when Octave aborts. The default value is @code{\"octave-core\"}\n\ |
5642
|
1896 @seealso{crash_dumps_octave_core, octave_core_file_name, octave_core_file_options}\n\ |
4791
|
1897 @end defvr"); |
|
1898 |
5284
|
1899 DEFVAR (octave_core_file_options, "-binary", octave_core_file_options, |
4791
|
1900 "-*- texinfo -*-\n\ |
5284
|
1901 @defvr {Built-in Variable} octave_core_file_options\n\ |
4788
|
1902 If Octave aborts, it attempts to save the contents of the top-level\n\ |
5284
|
1903 workspace in a file using this variable to define the format. The value of\n\ |
|
1904 @code{octave_core_file_options} should follow the same format as the options\n\ |
|
1905 that may be used with @code{save}. The default value is Octave's binary\n\ |
|
1906 format.\n\ |
5642
|
1907 @seealso{crash_dumps_octave_core, octave_core_file_name, octave_core_file_limit}\n\ |
3372
|
1908 @end defvr"); |
2194
|
1909 |
3709
|
1910 DEFVAR (save_header_format_string, default_save_header_format (), |
|
1911 save_header_format_string, |
|
1912 "-*- texinfo -*-\n\ |
|
1913 @defvr {Built-in Variable} save_header_format_string\n\ |
|
1914 This variable specifies the the format string for the comment line\n\ |
|
1915 that is written at the beginning of text-format data files saved by\n\ |
|
1916 Octave. The format string is passed to @code{strftime} and should\n\ |
|
1917 begin with the character @samp{#} and contain no newline characters.\n\ |
|
1918 If the value of @code{save_header_format_string} is the empty string,\n\ |
|
1919 the header comment is omitted from text-format data files. The\n\ |
|
1920 default value is\n\ |
|
1921 \n\ |
|
1922 @example\n\ |
4060
|
1923 \"# Created by Octave VERSION, %a %b %d %H:%M:%S %Y %Z <USER@@HOST>\"\n\ |
3709
|
1924 @end example\n\ |
|
1925 @seealso{strftime}\n\ |
|
1926 @end defvr"); |
2194
|
1927 } |
|
1928 |
604
|
1929 /* |
|
1930 ;;; Local Variables: *** |
|
1931 ;;; mode: C++ *** |
|
1932 ;;; End: *** |
|
1933 */ |