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