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 |
5269
|
351 get_file_format (std::istream& file) |
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 |
3697
|
377 err = read_mat5_binary_file_header (file, swap, true); |
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 { |
|
418 retval = get_file_format (file); |
|
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 { |
|
429 retval = get_file_format (gzfile); |
|
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 |
|
601 if (! fs.exists ()) |
|
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 |
|
619 if (! fs.exists ()) |
|
620 fname = find_file_to_load (fname + ".mat", orig_name); |
|
621 } |
|
622 else |
|
623 { |
|
624 file_stat fs (fname); |
|
625 |
|
626 if (! fs.exists ()) |
|
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 { |
5269
|
928 if (read_mat5_binary_file_header (file, swap, false) < 0) |
|
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 { |
|
962 if (read_mat5_binary_file_header (file, swap, false) < 0) |
|
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 |
|
1403 if (format == LS_BINARY |
|
1404 #ifdef HAVE_HDF5 |
|
1405 || format == LS_HDF5 |
|
1406 #endif |
|
1407 || format == LS_MAT_BINARY |
5269
|
1408 || format == LS_MAT5_BINARY |
|
1409 || format == LS_MAT7_BINARY) |
3552
|
1410 mode |= std::ios::binary; |
3189
|
1411 |
5284
|
1412 mode |= append ? std::ios::ate : std::ios::trunc; |
|
1413 |
3687
|
1414 #ifdef HAVE_HDF5 |
|
1415 if (format == LS_HDF5) |
3189
|
1416 { |
3687
|
1417 hdf5_ofstream file (fname); |
|
1418 |
|
1419 if (file.file_id >= 0) |
|
1420 { |
5284
|
1421 dump_octave_core (file, fname, format, save_as_floats); |
3687
|
1422 |
|
1423 file.close (); |
|
1424 } |
|
1425 else |
|
1426 warning ("unable to open `%s' for writing...", fname); |
3189
|
1427 } |
|
1428 else |
3687
|
1429 #endif /* HAVE_HDF5 */ |
|
1430 // don't insert any commands here! The open brace below must |
|
1431 // go with the else above! |
|
1432 { |
5284
|
1433 #ifdef HAVE_ZLIB |
|
1434 if (use_zlib) |
3687
|
1435 { |
5284
|
1436 gzofstream file (fname, mode); |
4791
|
1437 |
5284
|
1438 if (file) |
|
1439 { |
|
1440 dump_octave_core (file, fname, format, save_as_floats); |
|
1441 |
|
1442 file.close (); |
|
1443 } |
|
1444 else |
|
1445 warning ("unable to open `%s' for writing...", fname); |
3687
|
1446 } |
|
1447 else |
5284
|
1448 #endif |
|
1449 { |
|
1450 std::ofstream file (fname, mode); |
|
1451 |
|
1452 if (file) |
|
1453 { |
|
1454 dump_octave_core (file, fname, format, save_as_floats); |
|
1455 |
|
1456 file.close (); |
|
1457 } |
|
1458 else |
|
1459 warning ("unable to open `%s' for writing...", fname); |
|
1460 } |
3687
|
1461 } |
1380
|
1462 } |
|
1463 } |
|
1464 |
5269
|
1465 #ifdef HAVE_ZLIB |
|
1466 #define HAVE_ZLIB_HELP_STRING "" |
|
1467 #else /* ! HAVE_ZLIB */ |
|
1468 #define HAVE_ZLIB_HELP_STRING "\n\ |
|
1469 This option is not available, as this Octave executable was not linked with\n\ |
|
1470 the zlib library." |
|
1471 #endif /* ! HAVE ZLIB */ |
|
1472 |
4208
|
1473 DEFCMD (save, args, , |
3372
|
1474 "-*- texinfo -*-\n\ |
5665
|
1475 @deffn {Command} save options file @var{v1} @var{v2} @dots{}\n\ |
3372
|
1476 Save the named variables @var{v1}, @var{v2}, @dots{} in the file\n\ |
|
1477 @var{file}. The special filename @samp{-} can be used to write the\n\ |
|
1478 output to your terminal. If no variable names are listed, Octave saves\n\ |
|
1479 all the variables in the current scope. Valid options for the\n\ |
|
1480 @code{save} command are listed in the following table. Options that\n\ |
5794
|
1481 modify the output format override the format specified by\n\ |
|
1482 @code{default_save_options}.\n\ |
3372
|
1483 \n\ |
5665
|
1484 If save is invoked using the functional form\n\ |
|
1485 \n\ |
|
1486 @example\n\ |
|
1487 save (\"-text\", \"file.txt\", \"a\")\n\ |
|
1488 @end example\n\ |
|
1489 \n\ |
|
1490 @noindent\n\ |
|
1491 then the @var{options}, @var{file}, and variable name arguments\n\ |
|
1492 (@var{vname1}, @dots{}) must be specified as character strings.\n\ |
|
1493 \n\ |
3372
|
1494 @table @code\n\ |
|
1495 @item -ascii\n\ |
5938
|
1496 Save a single matrix in a text file.\n\ |
5197
|
1497 \n\ |
3372
|
1498 @item -binary\n\ |
|
1499 Save the data in Octave's binary data format.\n\ |
|
1500 \n\ |
|
1501 @item -float-binary\n\ |
|
1502 Save the data in Octave's binary data format but only using single\n\ |
|
1503 precision. You should use this format only if you know that all the\n\ |
|
1504 values to be saved can be represented in single precision.\n\ |
|
1505 \n\ |
5269
|
1506 @item -V7\n\ |
|
1507 @itemx -v7\n\ |
|
1508 @itemx -7\n\ |
|
1509 @itemx -mat7-binary\n\ |
|
1510 Save the data in @sc{Matlab}'s v7 binary data format.\n" |
|
1511 |
|
1512 HAVE_ZLIB_HELP_STRING |
|
1513 |
|
1514 "\n\ |
|
1515 @item -V6\n\ |
5284
|
1516 @itemx -v6\n\ |
5269
|
1517 @itemx -6\n\ |
|
1518 @itemx -mat\n\ |
4884
|
1519 @itemx -mat-binary\n\ |
5269
|
1520 Save the data in @sc{Matlab}'s v6 binary data format.\n\ |
3372
|
1521 \n\ |
5256
|
1522 @item -V4\n\ |
|
1523 @itemx -v4\n\ |
|
1524 @itemx -4\n\ |
|
1525 @itemx -mat4-binary\n\ |
3688
|
1526 Save the data in the binary format written by @sc{Matlab} version 4.\n\ |
|
1527 \n\ |
3687
|
1528 @item -hdf5\n\ |
|
1529 Save the data in HDF5 format.\n\ |
|
1530 (HDF5 is a free, portable binary format developed by the National\n\ |
|
1531 Center for Supercomputing Applications at the University of Illinois.)\n" |
|
1532 |
|
1533 HAVE_HDF5_HELP_STRING |
|
1534 |
|
1535 "\n\ |
|
1536 @item -float-hdf5\n\ |
|
1537 Save the data in HDF5 format but only using single precision.\n\ |
|
1538 You should use this format only if you know that all the\n\ |
|
1539 values to be saved can be represented in single precision.\n\ |
|
1540 \n\ |
5269
|
1541 @item -zip\n\ |
|
1542 @itemx -z\n\ |
|
1543 Use the gzip algorithm to compress the file. This works equally on files that\n\ |
|
1544 are compressed with gzip outside of octave, and gzip can equally be used to\n\ |
5380
|
1545 convert the files for backward compatibility.\n" |
5322
|
1546 |
|
1547 HAVE_ZLIB_HELP_STRING |
|
1548 |
5269
|
1549 "@end table\n\ |
604
|
1550 \n\ |
3372
|
1551 The list of variables to save may include wildcard patterns containing\n\ |
|
1552 the following special characters:\n\ |
|
1553 @table @code\n\ |
|
1554 @item ?\n\ |
|
1555 Match any single character.\n\ |
|
1556 \n\ |
|
1557 @item *\n\ |
|
1558 Match zero or more characters.\n\ |
|
1559 \n\ |
|
1560 @item [ @var{list} ]\n\ |
|
1561 Match the list of characters specified by @var{list}. If the first\n\ |
|
1562 character is @code{!} or @code{^}, match all characters except those\n\ |
|
1563 specified by @var{list}. For example, the pattern @samp{[a-zA-Z]} will\n\ |
|
1564 match all lower and upper case alphabetic characters. \n\ |
5197
|
1565 \n\ |
5198
|
1566 @item -text\n\ |
5197
|
1567 Save the data in Octave's text data format.\n\ |
3372
|
1568 @end table\n\ |
|
1569 \n\ |
|
1570 Except when using the @sc{Matlab} binary data file format, saving global\n\ |
|
1571 variables also saves the global status of the variable, so that if it is\n\ |
|
1572 restored at a later time using @samp{load}, it will be restored as a\n\ |
|
1573 global variable.\n\ |
|
1574 \n\ |
|
1575 The command\n\ |
|
1576 \n\ |
|
1577 @example\n\ |
|
1578 save -binary data a b*\n\ |
|
1579 @end example\n\ |
|
1580 \n\ |
|
1581 @noindent\n\ |
|
1582 saves the variable @samp{a} and all variables beginning with @samp{b} to\n\ |
|
1583 the file @file{data} in Octave's binary format.\n\ |
|
1584 @end deffn") |
604
|
1585 { |
2086
|
1586 octave_value_list retval; |
604
|
1587 |
1755
|
1588 int argc = args.length () + 1; |
|
1589 |
1968
|
1590 string_vector argv = args.make_argv ("save"); |
1755
|
1591 |
|
1592 if (error_state) |
|
1593 return retval; |
604
|
1594 |
1358
|
1595 // Here is where we would get the default save format if it were |
|
1596 // stored in a user preference variable. |
604
|
1597 |
3019
|
1598 bool save_as_floats = false; |
630
|
1599 |
5284
|
1600 load_save_format format = LS_ASCII; |
604
|
1601 |
3185
|
1602 bool append = false; |
|
1603 |
5269
|
1604 bool use_zlib = false; |
|
1605 |
5351
|
1606 load_save_format user_file_format = LS_UNKNOWN; |
|
1607 bool dummy; |
|
1608 |
|
1609 // Get user file format |
|
1610 parse_save_options (argv, argc, user_file_format, dummy, |
5794
|
1611 dummy, dummy, 1); |
5351
|
1612 |
|
1613 if (user_file_format == LS_UNKNOWN) |
|
1614 parse_save_options (Vdefault_save_options, format, append, save_as_floats, |
5794
|
1615 use_zlib, 0); |
5351
|
1616 |
5284
|
1617 int i = parse_save_options (argv, argc, format, append, save_as_floats, |
5794
|
1618 use_zlib, 1); |
5197
|
1619 |
5284
|
1620 if (error_state) |
|
1621 return retval; |
604
|
1622 |
2057
|
1623 if (i == argc) |
604
|
1624 { |
5823
|
1625 print_usage (); |
604
|
1626 return retval; |
|
1627 } |
|
1628 |
630
|
1629 if (save_as_floats && format == LS_ASCII) |
|
1630 { |
|
1631 error ("save: cannot specify both -ascii and -float-binary"); |
|
1632 return retval; |
|
1633 } |
|
1634 |
1755
|
1635 if (argv[i] == "-") |
604
|
1636 { |
1755
|
1637 i++; |
863
|
1638 |
3687
|
1639 #ifdef HAVE_HDF5 |
|
1640 if (format == LS_HDF5) |
4687
|
1641 error ("save: cannot write HDF5 format to stdout"); |
3687
|
1642 else |
|
1643 #endif /* HAVE_HDF5 */ |
|
1644 // don't insert any commands here! the brace below must go |
|
1645 // with the "else" above! |
|
1646 { |
5775
|
1647 // FIXME -- should things intended for the screen end up |
3687
|
1648 // in a octave_value (string)? |
|
1649 |
5794
|
1650 save_vars (argv, i, argc, octave_stdout, format, |
3687
|
1651 save_as_floats, true); |
|
1652 } |
604
|
1653 } |
1755
|
1654 |
|
1655 // Guard against things like `save a*', which are probably mistakes... |
|
1656 |
|
1657 else if (i == argc - 1 && glob_pattern_p (argv[i])) |
|
1658 { |
5823
|
1659 print_usage (); |
604
|
1660 return retval; |
|
1661 } |
|
1662 else |
|
1663 { |
3523
|
1664 std::string fname = file_ops::tilde_expand (argv[i]); |
1755
|
1665 |
|
1666 i++; |
604
|
1667 |
3775
|
1668 std::ios::openmode mode = std::ios::out; |
4791
|
1669 |
|
1670 if (format == LS_BINARY |
|
1671 #ifdef HAVE_HDF5 |
|
1672 || format == LS_HDF5 |
|
1673 #endif |
|
1674 || format == LS_MAT_BINARY |
5269
|
1675 || format == LS_MAT5_BINARY |
|
1676 || format == LS_MAT7_BINARY) |
3552
|
1677 mode |= std::ios::binary; |
3538
|
1678 |
|
1679 mode |= append ? std::ios::ate : std::ios::trunc; |
3185
|
1680 |
3687
|
1681 #ifdef HAVE_HDF5 |
|
1682 if (format == LS_HDF5) |
863
|
1683 { |
3687
|
1684 hdf5_ofstream hdf5_file (fname.c_str ()); |
|
1685 |
4687
|
1686 if (hdf5_file.file_id >= 0) |
|
1687 { |
5794
|
1688 save_vars (argv, i, argc, hdf5_file, format, |
4687
|
1689 save_as_floats, true); |
3687
|
1690 |
4687
|
1691 hdf5_file.close (); |
3687
|
1692 } |
|
1693 else |
|
1694 { |
5369
|
1695 gripe_file_open ("save", fname); |
3687
|
1696 return retval; |
|
1697 } |
863
|
1698 } |
|
1699 else |
3687
|
1700 #endif /* HAVE_HDF5 */ |
|
1701 // don't insert any statements here! The brace below must go |
|
1702 // with the "else" above! |
604
|
1703 { |
5269
|
1704 #ifdef HAVE_ZLIB |
|
1705 if (use_zlib) |
3687
|
1706 { |
5269
|
1707 gzofstream file (fname.c_str (), mode); |
|
1708 |
|
1709 if (file) |
|
1710 { |
5829
|
1711 bool write_header_info = ! file.tellp (); |
3687
|
1712 |
5794
|
1713 save_vars (argv, i, argc, file, format, |
5269
|
1714 save_as_floats, write_header_info); |
|
1715 |
|
1716 file.close (); |
|
1717 } |
|
1718 else |
|
1719 { |
5369
|
1720 gripe_file_open ("save", fname); |
5269
|
1721 return retval; |
|
1722 } |
3687
|
1723 } |
|
1724 else |
5269
|
1725 #endif |
3687
|
1726 { |
5269
|
1727 std::ofstream file (fname.c_str (), mode); |
|
1728 |
|
1729 if (file) |
|
1730 { |
5829
|
1731 bool write_header_info = ! file.tellp (); |
5269
|
1732 |
5794
|
1733 save_vars (argv, i, argc, file, format, |
5269
|
1734 save_as_floats, write_header_info); |
|
1735 |
|
1736 file.close (); |
|
1737 } |
|
1738 else |
|
1739 { |
5369
|
1740 gripe_file_open ("save", fname); |
5269
|
1741 return retval; |
|
1742 } |
3687
|
1743 } |
604
|
1744 } |
|
1745 } |
|
1746 |
|
1747 return retval; |
|
1748 } |
|
1749 |
5794
|
1750 DEFUN (crash_dumps_octave_core, args, nargout, |
|
1751 "-*- texinfo -*-\n\ |
|
1752 @deftypefn {Built-in Function} {@var{val} =} crash_dumps_octave_core ()\n\ |
|
1753 @deftypefnx {Built-in Function} {@var{old_val} =} crash_dumps_octave_core (@var{new_val})\n\ |
|
1754 Query or set the internal variable that controls whether Octave tries\n\ |
|
1755 to save all current variables the the file \"octave-core\" if it\n\ |
|
1756 crashes or receives a hangup, terminate or similar signal.\n\ |
|
1757 @seealso{octave_core_file_limit, octave_core_file_name, octave_core_file_options}\n\ |
|
1758 @end deftypefn") |
2194
|
1759 { |
5794
|
1760 return SET_INTERNAL_VARIABLE (crash_dumps_octave_core); |
2194
|
1761 } |
|
1762 |
5794
|
1763 DEFUN (default_save_options, args, nargout, |
|
1764 "-*- texinfo -*-\n\ |
|
1765 @deftypefn {Built-in Function} {@var{val} =} default_save_options ()\n\ |
|
1766 @deftypefnx {Built-in Function} {@var{old_val} =} default_save_options (@var{new_val})\n\ |
|
1767 Query or set the internal variable that specifies the default options\n\ |
|
1768 for the @code{save} command, and defines the default format.\n\ |
|
1769 Typical values include @code{\"-ascii\"}, @code{\"-ascii -zip\"}.\n\ |
|
1770 The default value is @code{-ascii}.\n\ |
|
1771 @seealso{save}\n\ |
|
1772 @end deftypefn") |
4788
|
1773 { |
5794
|
1774 return SET_NONEMPTY_INTERNAL_STRING_VARIABLE (default_save_options); |
4788
|
1775 } |
|
1776 |
5794
|
1777 DEFUN (octave_core_file_limit, args, nargout, |
|
1778 "-*- texinfo -*-\n\ |
|
1779 @deftypefn {Built-in Function} {@var{val} =} octave_core_file_limit ()\n\ |
|
1780 @deftypefnx {Built-in Function} {@var{old_val} =} octave_core_file_limit (@var{new_val})\n\ |
|
1781 Query or set the internal variable that specifies the maximum amount\n\ |
|
1782 of memory (in kilobytes) of the top-level workspace that Octave will\n\ |
|
1783 attempt to save when writing data to the crash dump file (the name of\n\ |
|
1784 the file is specified by @var{octave_core_file_name}). If\n\ |
|
1785 @var{octave_core_file_options} flags specifies a binary format,\n\ |
|
1786 then @var{octave_core_file_limit} will be approximately the maximum\n\ |
|
1787 size of the file. If a text file format is used, then the file could\n\ |
|
1788 be much larger than the limit. The default value is -1 (unlimited)\n\ |
|
1789 @seealso{crash_dumps_octave_core, octave_core_file_name, octave_core_file_options}\n\ |
|
1790 @end deftypefn") |
3709
|
1791 { |
5794
|
1792 return SET_INTERNAL_VARIABLE (octave_core_file_limit); |
3709
|
1793 } |
|
1794 |
5794
|
1795 DEFUN (octave_core_file_name, args, nargout, |
|
1796 "-*- texinfo -*-\n\ |
|
1797 @deftypefn {Built-in Function} {@var{val} =} octave_core_file_name ()\n\ |
|
1798 @deftypefnx {Built-in Function} {@var{old_val} =} octave_core_file_name (@var{new_val})\n\ |
|
1799 Query or set the internal variable that specifies the name of the file\n\ |
|
1800 used for saving data from the top-level workspace if Octave aborts.\n\ |
|
1801 The default value is @code{\"octave-core\"}\n\ |
|
1802 @seealso{crash_dumps_octave_core, octave_core_file_name, octave_core_file_options}\n\ |
|
1803 @end deftypefn") |
2194
|
1804 { |
5794
|
1805 return SET_NONEMPTY_INTERNAL_STRING_VARIABLE (octave_core_file_name); |
|
1806 } |
4791
|
1807 |
5794
|
1808 DEFUN (octave_core_file_options, args, nargout, |
|
1809 "-*- texinfo -*-\n\ |
|
1810 @deftypefn {Built-in Function} {@var{val} =} octave_core_file_options ()\n\ |
|
1811 @deftypefnx {Built-in Function} {@var{old_val} =} octave_core_file_options (@var{new_val})\n\ |
|
1812 Query or set the internal variable that specifies the options used for\n\ |
|
1813 saving the workspace data if Octave aborts. The value of\n\ |
|
1814 @code{octave_core_file_options} should follow the same format as the\n\ |
|
1815 options for the @code{save} function. The default value is Octave's binary\n\ |
5284
|
1816 format.\n\ |
5642
|
1817 @seealso{crash_dumps_octave_core, octave_core_file_name, octave_core_file_limit}\n\ |
5794
|
1818 @end deftypefn") |
|
1819 { |
|
1820 return SET_NONEMPTY_INTERNAL_STRING_VARIABLE (octave_core_file_options); |
|
1821 } |
2194
|
1822 |
5794
|
1823 DEFUN (save_header_format_string, args, nargout, |
|
1824 "-*- texinfo -*-\n\ |
|
1825 @deftypefn {Built-in Function} {@var{val} =} save_header_format_string ()\n\ |
|
1826 @deftypefnx {Built-in Function} {@var{old_val} =} save_header_format_string (@var{new_val})\n\ |
|
1827 Query or set the internal variable that specifies the format\n\ |
|
1828 string used for the comment line written at the beginning of\n\ |
|
1829 text-format data files saved by Octave. The format string is\n\ |
|
1830 passed to @code{strftime} and should begin with the character\n\ |
|
1831 @samp{#} and contain no newline characters. If the value of\n\ |
|
1832 @code{save_header_format_string} is the empty string,\n\ |
3709
|
1833 the header comment is omitted from text-format data files. The\n\ |
|
1834 default value is\n\ |
|
1835 \n\ |
|
1836 @example\n\ |
4060
|
1837 \"# Created by Octave VERSION, %a %b %d %H:%M:%S %Y %Z <USER@@HOST>\"\n\ |
3709
|
1838 @end example\n\ |
|
1839 @seealso{strftime}\n\ |
5794
|
1840 @end deftypefn") |
|
1841 { |
|
1842 return SET_INTERNAL_VARIABLE (save_header_format_string); |
2194
|
1843 } |
|
1844 |
604
|
1845 /* |
|
1846 ;;; Local Variables: *** |
|
1847 ;;; mode: C++ *** |
|
1848 ;;; End: *** |
|
1849 */ |