annotate libinterp/interpfcn/load-save.cc @ 16555:04fb96f4bea1

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