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