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