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