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