Mercurial > octave
annotate libinterp/corefcn/ls-mat4.cc @ 23450:855122b993da
maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
* Canvas.cc, color-picker.cc, dialog.cc, marker.cc, main-window.cc, Cell.cc,
__magick_read__.cc, __pchip_deriv__.cc, __qp__.cc, bsxfun.cc, call-stack.cc,
cellfun.cc, data.cc, defaults.cc, det.cc, eig.cc, error.cc, file-io.cc,
filter.cc, find.cc, gammainc.cc, gcd.cc, gl-render.cc, graphics.cc,
graphics.in.h, help.cc, hex2num.cc, inv.cc, load-save.cc, lookup.cc,
ls-mat4.cc, ls-mat5.cc, ls-oct-binary.cc, ls-oct-text.cc, lu.cc, max.cc,
mex.cc, oct-hist.cc, oct-map.cc, oct-procbuf.cc, oct-stream.cc, pr-output.cc,
rand.cc, regexp.cc, schur.cc, str2double.cc, strfns.cc, symtab.cc, sysdep.cc,
tril.cc, variables.cc, xdiv.cc, audiodevinfo.cc, audioread.cc, colamd.cc,
gzip.cc, ov-base-diag.cc, ov-base-mat.h, ov-base-scalar.h, ov-class.cc,
ov-classdef.cc, ov-fcn-handle.cc, ov-range.cc, ov-range.h, ov-struct.cc,
ov-usr-fcn.cc, ov.cc, octave.cc, op-class.cc, pt-eval.cc, pt-funcall.cc,
pt-idx.cc, pt-jit.cc, pt-stmt.cc, version.cc, Array-util.cc, Array.cc,
CDiagMatrix.cc, CMatrix.cc, CNDArray.cc, CSparse.cc, Range.cc, Sparse.cc,
chNDArray.cc, dDiagMatrix.cc, dMatrix.cc, dNDArray.cc, dSparse.cc,
dim-vector.cc, fCDiagMatrix.cc, fCMatrix.cc, fCNDArray.cc, fDiagMatrix.cc,
fMatrix.cc, fNDArray.cc, idx-vector.cc, idx-vector.h, Faddeeva.cc, DASPK.cc,
DASRT.cc, DASSL.cc, EIG.cc, fEIG.cc, gsvd.cc, lo-specfun.cc, oct-rand.cc,
qr.cc, qrp.cc, randgamma.cc, schur.cc, svd.cc, Sparse-diag-op-defs.h,
mx-inlines.cc, oct-env.cc, cmd-edit.cc, kpse.cc, oct-inttypes.h, oct-sort.cc:
Wrap tertiary operator in parentheses "(COND ? x : y)".
author | Rik <rik@octave.org> |
---|---|
date | Thu, 27 Apr 2017 17:33:10 -0700 |
parents | 092078913d54 |
children | 73ff72d3d603 |
rev | line source |
---|---|
4634 | 1 /* |
2 | |
23219
3ac9f9ecfae5
maint: Update copyright dates.
John W. Eaton <jwe@octave.org>
parents:
23083
diff
changeset
|
3 Copyright (C) 1996-2017 John W. Eaton |
4634 | 4 |
5 This file is part of Octave. | |
6 | |
7 Octave is free software; you can redistribute it and/or modify it | |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
8 under the terms of the GNU General Public License as published by |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
9 the Free Software Foundation; either version 3 of the License, or |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
10 (at your option) any later version. |
4634 | 11 |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
12 Octave is distributed in the hope that it will be useful, but |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
13 WITHOUT ANY WARRANTY; without even the implied warranty of |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
15 GNU General Public License for more details. |
4634 | 16 |
17 You should have received a copy of the GNU General Public License | |
7016 | 18 along with Octave; see the file COPYING. If not, see |
19 <http://www.gnu.org/licenses/>. | |
4634 | 20 |
21 */ | |
22 | |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
23 #if defined (HAVE_CONFIG_H) |
21301
40de9f8f23a6
Use '#include "config.h"' rather than <config.h>.
Rik <rik@octave.org>
parents:
21200
diff
changeset
|
24 # include "config.h" |
4634 | 25 #endif |
26 | |
27 #include <cfloat> | |
28 #include <cstring> | |
29 #include <cctype> | |
30 | |
31 #include <fstream> | |
32 #include <iomanip> | |
33 #include <iostream> | |
34 #include <string> | |
4726 | 35 #include <vector> |
4634 | 36 |
37 #include "byte-swap.h" | |
38 #include "data-conv.h" | |
39 #include "file-ops.h" | |
40 #include "glob-match.h" | |
41 #include "lo-mappers.h" | |
42 #include "mach-info.h" | |
43 #include "oct-env.h" | |
44 #include "oct-time.h" | |
45 #include "quit.h" | |
46 #include "str-vec.h" | |
8377
25bc2d31e1bf
improve OCTAVE_LOCAL_BUFFER
Jaroslav Hajek <highegg@gmail.com>
parents:
7918
diff
changeset
|
47 #include "oct-locbuf.h" |
4634 | 48 |
49 #include "Cell.h" | |
50 #include "defun.h" | |
51 #include "error.h" | |
21100
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
52 #include "errwarn.h" |
4634 | 53 #include "load-save.h" |
20940
48b2ad5ee801
maint: Rename oct-obj.[cc|h] to ovl.[cc|h] for clarity.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
54 #include "ovl.h" |
4634 | 55 #include "oct-map.h" |
56 #include "ov-cell.h" | |
57 #include "pager.h" | |
58 #include "pt-exp.h" | |
59 #include "sysdep.h" | |
60 #include "unwind-prot.h" | |
61 #include "utils.h" | |
62 #include "variables.h" | |
63 #include "version.h" | |
64 #include "dMatrix.h" | |
7918
78eef61f75d5
Add matlab V4 sparse matrixload/save
David Bateman <dbateman@free.fr>
parents:
7336
diff
changeset
|
65 #include "dSparse.h" |
4634 | 66 |
67 #include "ls-mat4.h" | |
68 | |
69 // Read LEN elements of data from IS in the format specified by | |
70 // PRECISION, placing the result in DATA. If SWAP is TRUE, swap | |
71 // the bytes of each element before copying to DATA. FLT_FMT | |
72 // specifies the format of the data if we are reading floating point | |
73 // numbers. | |
74 | |
75 static void | |
76 read_mat_binary_data (std::istream& is, double *data, int precision, | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
77 int len, bool swap, |
21739
c4ab2e54f100
use namespace for oct_mach_info class
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
78 octave::mach_info::float_format flt_fmt) |
4634 | 79 { |
80 switch (precision) | |
81 { | |
82 case 0: | |
83 read_doubles (is, data, LS_DOUBLE, len, swap, flt_fmt); | |
84 break; | |
85 | |
86 case 1: | |
87 read_doubles (is, data, LS_FLOAT, len, swap, flt_fmt); | |
88 break; | |
89 | |
90 case 2: | |
91 read_doubles (is, data, LS_INT, len, swap, flt_fmt); | |
92 break; | |
93 | |
94 case 3: | |
95 read_doubles (is, data, LS_SHORT, len, swap, flt_fmt); | |
96 break; | |
97 | |
98 case 4: | |
99 read_doubles (is, data, LS_U_SHORT, len, swap, flt_fmt); | |
100 break; | |
101 | |
102 case 5: | |
103 read_doubles (is, data, LS_U_CHAR, len, swap, flt_fmt); | |
104 break; | |
105 | |
106 default: | |
107 break; | |
108 } | |
109 } | |
110 | |
111 int | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
112 read_mat_file_header (std::istream& is, bool& swap, int32_t& mopt, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
113 int32_t& nr, int32_t& nc, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
114 int32_t& imag, int32_t& len, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
115 int quiet) |
4634 | 116 { |
117 swap = false; | |
118 | |
119 // We expect to fail here, at the beginning of a record, so not | |
120 // being able to read another mopt value should not result in an | |
121 // error. | |
122 | |
5760 | 123 is.read (reinterpret_cast<char *> (&mopt), 4); |
4634 | 124 if (! is) |
125 return 1; | |
126 | |
5760 | 127 if (! is.read (reinterpret_cast<char *> (&nr), 4)) |
21170
1edaf1ee65eb
maint: Replace some uses of goto in libinterp.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
128 return -1; |
4634 | 129 |
5760 | 130 if (! is.read (reinterpret_cast<char *> (&nc), 4)) |
21170
1edaf1ee65eb
maint: Replace some uses of goto in libinterp.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
131 return -1; |
4634 | 132 |
5760 | 133 if (! is.read (reinterpret_cast<char *> (&imag), 4)) |
21170
1edaf1ee65eb
maint: Replace some uses of goto in libinterp.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
134 return -1; |
4634 | 135 |
5760 | 136 if (! is.read (reinterpret_cast<char *> (&len), 4)) |
21170
1edaf1ee65eb
maint: Replace some uses of goto in libinterp.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
137 return -1; |
4634 | 138 |
139 // If mopt is nonzero and the byte order is swapped, mopt will be | |
140 // bigger than we expect, so we swap bytes. | |
141 // | |
142 // If mopt is zero, it means the file was written on a little endian | |
143 // machine, and we only need to swap if we are running on a big endian | |
144 // machine. | |
145 // | |
146 // Gag me. | |
147 | |
21739
c4ab2e54f100
use namespace for oct_mach_info class
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
148 if (octave::mach_info::words_big_endian () && mopt == 0) |
4634 | 149 swap = true; |
150 | |
151 // mopt is signed, therefore byte swap may result in negative value. | |
152 | |
153 if (mopt > 9999 || mopt < 0) | |
154 swap = true; | |
155 | |
156 if (swap) | |
157 { | |
4944 | 158 swap_bytes<4> (&mopt); |
159 swap_bytes<4> (&nr); | |
160 swap_bytes<4> (&nc); | |
161 swap_bytes<4> (&imag); | |
162 swap_bytes<4> (&len); | |
4634 | 163 } |
164 | |
165 if (mopt > 9999 || mopt < 0 || imag > 1 || imag < 0) | |
166 { | |
167 if (! quiet) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
168 error ("load: can't read binary file"); |
20831
35241c4b696c
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20555
diff
changeset
|
169 |
4634 | 170 return -1; |
171 } | |
172 | |
173 return 0; | |
174 } | |
175 | |
176 // We don't just use a cast here, because we need to be able to detect | |
177 // possible errors. | |
178 | |
21739
c4ab2e54f100
use namespace for oct_mach_info class
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
179 octave::mach_info::float_format |
4634 | 180 mopt_digit_to_float_format (int mach) |
181 { | |
21739
c4ab2e54f100
use namespace for oct_mach_info class
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
182 octave::mach_info::float_format flt_fmt = octave::mach_info::flt_fmt_unknown; |
4634 | 183 |
184 switch (mach) | |
185 { | |
186 case 0: | |
21739
c4ab2e54f100
use namespace for oct_mach_info class
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
187 flt_fmt = octave::mach_info::flt_fmt_ieee_little_endian; |
4634 | 188 break; |
189 | |
190 case 1: | |
21739
c4ab2e54f100
use namespace for oct_mach_info class
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
191 flt_fmt = octave::mach_info::flt_fmt_ieee_big_endian; |
4634 | 192 break; |
193 | |
194 case 2: | |
195 case 3: | |
196 case 4: | |
197 default: | |
21739
c4ab2e54f100
use namespace for oct_mach_info class
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
198 flt_fmt = octave::mach_info::flt_fmt_unknown; |
4634 | 199 break; |
200 } | |
201 | |
202 return flt_fmt; | |
203 } | |
204 | |
205 int | |
21739
c4ab2e54f100
use namespace for oct_mach_info class
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
206 float_format_to_mopt_digit (octave::mach_info::float_format flt_fmt) |
4634 | 207 { |
208 int retval = -1; | |
209 | |
210 switch (flt_fmt) | |
211 { | |
21739
c4ab2e54f100
use namespace for oct_mach_info class
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
212 case octave::mach_info::flt_fmt_ieee_little_endian: |
4634 | 213 retval = 0; |
214 break; | |
215 | |
21739
c4ab2e54f100
use namespace for oct_mach_info class
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
216 case octave::mach_info::flt_fmt_ieee_big_endian: |
4634 | 217 retval = 1; |
218 break; | |
219 | |
220 default: | |
221 break; | |
222 } | |
223 | |
224 return retval; | |
225 } | |
226 | |
227 // Extract one value (scalar, matrix, string, etc.) from stream IS and | |
228 // place it in TC, returning the name of the variable. | |
229 // | |
230 // The data is expected to be in Matlab version 4 .mat format, though | |
231 // not all the features of that format are supported. | |
232 // | |
233 // FILENAME is used for error messages. | |
234 // | |
235 // This format provides no way to tag the data as global. | |
236 | |
237 std::string | |
238 read_mat_binary_data (std::istream& is, const std::string& filename, | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
239 octave_value& tc) |
4634 | 240 { |
241 std::string retval; | |
242 | |
243 bool swap = false; | |
5828 | 244 int32_t mopt, nr, nc, imag, len; |
4634 | 245 |
246 int err = read_mat_file_header (is, swap, mopt, nr, nc, imag, len); | |
247 if (err) | |
248 { | |
249 if (err < 0) | |
21170
1edaf1ee65eb
maint: Replace some uses of goto in libinterp.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
250 error ("load: trouble reading binary file '%s'", filename.c_str ()); |
1edaf1ee65eb
maint: Replace some uses of goto in libinterp.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
251 |
1edaf1ee65eb
maint: Replace some uses of goto in libinterp.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
252 return retval; |
4634 | 253 } |
254 | |
21170
1edaf1ee65eb
maint: Replace some uses of goto in libinterp.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
255 int type = 0; |
1edaf1ee65eb
maint: Replace some uses of goto in libinterp.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
256 int prec = 0; |
1edaf1ee65eb
maint: Replace some uses of goto in libinterp.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
257 int order = 0; |
1edaf1ee65eb
maint: Replace some uses of goto in libinterp.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
258 int mach = 0; |
1edaf1ee65eb
maint: Replace some uses of goto in libinterp.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
259 |
4634 | 260 type = mopt % 10; // Full, sparse, etc. |
261 mopt /= 10; // Eliminate first digit. | |
262 prec = mopt % 10; // double, float, int, etc. | |
263 mopt /= 10; // Eliminate second digit. | |
264 order = mopt % 10; // Row or column major ordering. | |
265 mopt /= 10; // Eliminate third digit. | |
266 mach = mopt % 10; // IEEE, VAX, etc. | |
267 | |
21739
c4ab2e54f100
use namespace for oct_mach_info class
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
268 octave::mach_info::float_format flt_fmt; |
4634 | 269 flt_fmt = mopt_digit_to_float_format (mach); |
270 | |
21739
c4ab2e54f100
use namespace for oct_mach_info class
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
271 if (flt_fmt == octave::mach_info::flt_fmt_unknown) |
20831
35241c4b696c
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20555
diff
changeset
|
272 error ("load: unrecognized binary format!"); |
4634 | 273 |
274 if (imag && type == 1) | |
20831
35241c4b696c
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20555
diff
changeset
|
275 error ("load: encountered complex matrix with string flag set!"); |
4634 | 276 |
21170
1edaf1ee65eb
maint: Replace some uses of goto in libinterp.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
277 int dlen = 0; |
1edaf1ee65eb
maint: Replace some uses of goto in libinterp.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
278 |
4634 | 279 // LEN includes the terminating character, and the file is also |
280 // supposed to include it, but apparently not all files do. Either | |
281 // way, I think this should work. | |
282 | |
283 { | |
284 OCTAVE_LOCAL_BUFFER (char, name, len+1); | |
285 name[len] = '\0'; | |
5760 | 286 if (! is.read (name, len)) |
21170
1edaf1ee65eb
maint: Replace some uses of goto in libinterp.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
287 error ("load: trouble reading binary file '%s'", filename.c_str ()); |
4634 | 288 retval = name; |
289 | |
290 dlen = nr * nc; | |
291 if (dlen < 0) | |
21170
1edaf1ee65eb
maint: Replace some uses of goto in libinterp.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
292 error ("load: trouble reading binary file '%s'", filename.c_str ()); |
4634 | 293 |
294 if (order) | |
295 { | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
296 octave_idx_type tmp = nr; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
297 nr = nc; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
298 nc = tmp; |
4634 | 299 } |
300 | |
7918
78eef61f75d5
Add matlab V4 sparse matrixload/save
David Bateman <dbateman@free.fr>
parents:
7336
diff
changeset
|
301 if (type == 2) |
78eef61f75d5
Add matlab V4 sparse matrixload/save
David Bateman <dbateman@free.fr>
parents:
7336
diff
changeset
|
302 { |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
303 if (nc == 4) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
304 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
305 octave_idx_type nr_new, nc_new; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
306 Array<Complex> data (dim_vector (1, nr - 1)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
307 Array<octave_idx_type> c (dim_vector (1, nr - 1)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
308 Array<octave_idx_type> r (dim_vector (1, nr - 1)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
309 OCTAVE_LOCAL_BUFFER (double, dtmp, nr); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
310 OCTAVE_LOCAL_BUFFER (double, ctmp, nr); |
4634 | 311 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
312 read_mat_binary_data (is, dtmp, prec, nr, swap, flt_fmt); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
313 for (octave_idx_type i = 0; i < nr - 1; i++) |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
314 r.xelem (i) = dtmp[i] - 1; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
315 nr_new = dtmp[nr - 1]; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
316 read_mat_binary_data (is, dtmp, prec, nr, swap, flt_fmt); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
317 for (octave_idx_type i = 0; i < nr - 1; i++) |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
318 c.xelem (i) = dtmp[i] - 1; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
319 nc_new = dtmp[nr - 1]; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
320 read_mat_binary_data (is, dtmp, prec, nr - 1, swap, flt_fmt); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
321 read_mat_binary_data (is, ctmp, prec, 1, swap, flt_fmt); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
322 read_mat_binary_data (is, ctmp, prec, nr - 1, swap, flt_fmt); |
4634 | 323 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
324 for (octave_idx_type i = 0; i < nr - 1; i++) |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
325 data.xelem (i) = Complex (dtmp[i], ctmp[i]); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
326 read_mat_binary_data (is, ctmp, prec, 1, swap, flt_fmt); |
7918
78eef61f75d5
Add matlab V4 sparse matrixload/save
David Bateman <dbateman@free.fr>
parents:
7336
diff
changeset
|
327 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
328 SparseComplexMatrix smc = SparseComplexMatrix (data, r, c, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
329 nr_new, nc_new); |
4634 | 330 |
23450
855122b993da
maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
331 tc = (order ? smc.transpose () : smc); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
332 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
333 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
334 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
335 octave_idx_type nr_new, nc_new; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
336 Array<double> data (dim_vector (1, nr - 1)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
337 Array<octave_idx_type> c (dim_vector (1, nr - 1)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
338 Array<octave_idx_type> r (dim_vector (1, nr - 1)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
339 OCTAVE_LOCAL_BUFFER (double, dtmp, nr); |
4634 | 340 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
341 read_mat_binary_data (is, dtmp, prec, nr, swap, flt_fmt); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
342 for (octave_idx_type i = 0; i < nr - 1; i++) |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
343 r.xelem (i) = dtmp[i] - 1; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
344 nr_new = dtmp[nr - 1]; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
345 read_mat_binary_data (is, dtmp, prec, nr, swap, flt_fmt); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
346 for (octave_idx_type i = 0; i < nr - 1; i++) |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
347 c.xelem (i) = dtmp[i] - 1; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
348 nc_new = dtmp[nr - 1]; |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
349 read_mat_binary_data (is, data.fortran_vec (), prec, nr - 1, |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
350 swap, flt_fmt); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
351 read_mat_binary_data (is, dtmp, prec, 1, swap, flt_fmt); |
7918
78eef61f75d5
Add matlab V4 sparse matrixload/save
David Bateman <dbateman@free.fr>
parents:
7336
diff
changeset
|
352 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
353 SparseMatrix sm = SparseMatrix (data, r, c, nr_new, nc_new); |
4634 | 354 |
23450
855122b993da
maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
355 tc = (order ? sm.transpose () : sm); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
356 } |
7918
78eef61f75d5
Add matlab V4 sparse matrixload/save
David Bateman <dbateman@free.fr>
parents:
7336
diff
changeset
|
357 } |
78eef61f75d5
Add matlab V4 sparse matrixload/save
David Bateman <dbateman@free.fr>
parents:
7336
diff
changeset
|
358 else |
78eef61f75d5
Add matlab V4 sparse matrixload/save
David Bateman <dbateman@free.fr>
parents:
7336
diff
changeset
|
359 { |
21170
1edaf1ee65eb
maint: Replace some uses of goto in libinterp.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
360 Matrix re (nr, nc); |
7918
78eef61f75d5
Add matlab V4 sparse matrixload/save
David Bateman <dbateman@free.fr>
parents:
7336
diff
changeset
|
361 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
362 read_mat_binary_data (is, re.fortran_vec (), prec, dlen, swap, flt_fmt); |
7918
78eef61f75d5
Add matlab V4 sparse matrixload/save
David Bateman <dbateman@free.fr>
parents:
7336
diff
changeset
|
363 |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20228
diff
changeset
|
364 if (! is) |
20831
35241c4b696c
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20555
diff
changeset
|
365 error ("load: reading matrix data for '%s'", name); |
4634 | 366 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
367 if (imag) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
368 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
369 Matrix im (nr, nc); |
7918
78eef61f75d5
Add matlab V4 sparse matrixload/save
David Bateman <dbateman@free.fr>
parents:
7336
diff
changeset
|
370 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
371 read_mat_binary_data (is, im.fortran_vec (), prec, dlen, swap, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
372 flt_fmt); |
7918
78eef61f75d5
Add matlab V4 sparse matrixload/save
David Bateman <dbateman@free.fr>
parents:
7336
diff
changeset
|
373 |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20228
diff
changeset
|
374 if (! is) |
20831
35241c4b696c
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20555
diff
changeset
|
375 error ("load: reading imaginary matrix data for '%s'", name); |
4634 | 376 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
377 ComplexMatrix ctmp (nr, nc); |
7918
78eef61f75d5
Add matlab V4 sparse matrixload/save
David Bateman <dbateman@free.fr>
parents:
7336
diff
changeset
|
378 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
379 for (octave_idx_type j = 0; j < nc; j++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
380 for (octave_idx_type i = 0; i < nr; i++) |
21170
1edaf1ee65eb
maint: Replace some uses of goto in libinterp.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
381 ctmp (i,j) = Complex (re(i,j), im(i,j)); |
4634 | 382 |
23450
855122b993da
maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
383 tc = (order ? ctmp.transpose () : ctmp); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
384 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
385 else |
23450
855122b993da
maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
386 tc = (order ? re.transpose () : re); |
7918
78eef61f75d5
Add matlab V4 sparse matrixload/save
David Bateman <dbateman@free.fr>
parents:
7336
diff
changeset
|
387 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
388 if (type == 1) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
389 tc = tc.convert_to_str (false, true, '\''); |
7918
78eef61f75d5
Add matlab V4 sparse matrixload/save
David Bateman <dbateman@free.fr>
parents:
7336
diff
changeset
|
390 } |
4634 | 391 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
392 return retval; |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
393 } |
4634 | 394 } |
395 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
396 // Save the data from TC along with the corresponding NAME on stream OS |
4634 | 397 // in the MatLab version 4 binary format. |
398 | |
399 bool | |
400 save_mat_binary_data (std::ostream& os, const octave_value& tc, | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
401 const std::string& name) |
4634 | 402 { |
5828 | 403 int32_t mopt = 0; |
4634 | 404 |
7918
78eef61f75d5
Add matlab V4 sparse matrixload/save
David Bateman <dbateman@free.fr>
parents:
7336
diff
changeset
|
405 mopt += tc.is_sparse_type () ? 2 : tc.is_string () ? 1 : 0; |
4634 | 406 |
21739
c4ab2e54f100
use namespace for oct_mach_info class
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
407 octave::mach_info::float_format flt_fmt = |
c4ab2e54f100
use namespace for oct_mach_info class
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
408 octave::mach_info::native_float_format ();; |
4634 | 409 |
410 mopt += 1000 * float_format_to_mopt_digit (flt_fmt); | |
411 | |
5760 | 412 os.write (reinterpret_cast<char *> (&mopt), 4); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
413 |
7918
78eef61f75d5
Add matlab V4 sparse matrixload/save
David Bateman <dbateman@free.fr>
parents:
7336
diff
changeset
|
414 octave_idx_type len; |
5828 | 415 int32_t nr = tc.rows (); |
4634 | 416 |
5828 | 417 int32_t nc = tc.columns (); |
7918
78eef61f75d5
Add matlab V4 sparse matrixload/save
David Bateman <dbateman@free.fr>
parents:
7336
diff
changeset
|
418 |
78eef61f75d5
Add matlab V4 sparse matrixload/save
David Bateman <dbateman@free.fr>
parents:
7336
diff
changeset
|
419 if (tc.is_sparse_type ()) |
78eef61f75d5
Add matlab V4 sparse matrixload/save
David Bateman <dbateman@free.fr>
parents:
7336
diff
changeset
|
420 { |
78eef61f75d5
Add matlab V4 sparse matrixload/save
David Bateman <dbateman@free.fr>
parents:
7336
diff
changeset
|
421 len = tc.nnz (); |
78eef61f75d5
Add matlab V4 sparse matrixload/save
David Bateman <dbateman@free.fr>
parents:
7336
diff
changeset
|
422 uint32_t nnz = len + 1; |
78eef61f75d5
Add matlab V4 sparse matrixload/save
David Bateman <dbateman@free.fr>
parents:
7336
diff
changeset
|
423 os.write (reinterpret_cast<char *> (&nnz), 4); |
78eef61f75d5
Add matlab V4 sparse matrixload/save
David Bateman <dbateman@free.fr>
parents:
7336
diff
changeset
|
424 |
23450
855122b993da
maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
425 uint32_t iscmplx = (tc.is_complex_type () ? 4 : 3); |
7918
78eef61f75d5
Add matlab V4 sparse matrixload/save
David Bateman <dbateman@free.fr>
parents:
7336
diff
changeset
|
426 os.write (reinterpret_cast<char *> (&iscmplx), 4); |
4634 | 427 |
7918
78eef61f75d5
Add matlab V4 sparse matrixload/save
David Bateman <dbateman@free.fr>
parents:
7336
diff
changeset
|
428 uint32_t tmp = 0; |
78eef61f75d5
Add matlab V4 sparse matrixload/save
David Bateman <dbateman@free.fr>
parents:
7336
diff
changeset
|
429 os.write (reinterpret_cast<char *> (&tmp), 4); |
78eef61f75d5
Add matlab V4 sparse matrixload/save
David Bateman <dbateman@free.fr>
parents:
7336
diff
changeset
|
430 } |
78eef61f75d5
Add matlab V4 sparse matrixload/save
David Bateman <dbateman@free.fr>
parents:
7336
diff
changeset
|
431 else |
78eef61f75d5
Add matlab V4 sparse matrixload/save
David Bateman <dbateman@free.fr>
parents:
7336
diff
changeset
|
432 { |
78eef61f75d5
Add matlab V4 sparse matrixload/save
David Bateman <dbateman@free.fr>
parents:
7336
diff
changeset
|
433 os.write (reinterpret_cast<char *> (&nr), 4); |
78eef61f75d5
Add matlab V4 sparse matrixload/save
David Bateman <dbateman@free.fr>
parents:
7336
diff
changeset
|
434 os.write (reinterpret_cast<char *> (&nc), 4); |
4634 | 435 |
23450
855122b993da
maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
436 int32_t imag = (tc.is_complex_type () ? 1 : 0); |
7918
78eef61f75d5
Add matlab V4 sparse matrixload/save
David Bateman <dbateman@free.fr>
parents:
7336
diff
changeset
|
437 os.write (reinterpret_cast<char *> (&imag), 4); |
78eef61f75d5
Add matlab V4 sparse matrixload/save
David Bateman <dbateman@free.fr>
parents:
7336
diff
changeset
|
438 |
78eef61f75d5
Add matlab V4 sparse matrixload/save
David Bateman <dbateman@free.fr>
parents:
7336
diff
changeset
|
439 len = nr * nc; |
78eef61f75d5
Add matlab V4 sparse matrixload/save
David Bateman <dbateman@free.fr>
parents:
7336
diff
changeset
|
440 } |
78eef61f75d5
Add matlab V4 sparse matrixload/save
David Bateman <dbateman@free.fr>
parents:
7336
diff
changeset
|
441 |
4634 | 442 // LEN includes the terminating character, and the file is also |
443 // supposed to include it. | |
444 | |
5828 | 445 int32_t name_len = name.length () + 1; |
4634 | 446 |
5760 | 447 os.write (reinterpret_cast<char *> (&name_len), 4); |
4634 | 448 os << name << '\0'; |
449 | |
450 if (tc.is_string ()) | |
451 { | |
21743
f4d7d0eb5b0c
use namespace for unwind_protect class
John W. Eaton <jwe@octave.org>
parents:
21739
diff
changeset
|
452 octave::unwind_protect frame; |
4634 | 453 |
454 charMatrix chm = tc.char_matrix_value (); | |
455 | |
5275 | 456 octave_idx_type nrow = chm.rows (); |
457 octave_idx_type ncol = chm.cols (); | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
458 |
4634 | 459 OCTAVE_LOCAL_BUFFER (double, buf, ncol*nrow); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
460 |
5275 | 461 for (octave_idx_type i = 0; i < nrow; i++) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
462 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
463 std::string tstr = chm.row_as_string (i); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
464 const char *s = tstr.data (); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
465 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
466 for (octave_idx_type j = 0; j < ncol; j++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
467 buf[j*nrow+i] = static_cast<double> (*s++ & 0x00FF); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
468 } |
18691
9a6646cc7c3e
Fix load/save to handle up to 2^32-1 elements.
Rik <rik@octave.org>
parents:
18384
diff
changeset
|
469 std::streamsize n_bytes = static_cast<std::streamsize> (nrow) * |
9a6646cc7c3e
Fix load/save to handle up to 2^32-1 elements.
Rik <rik@octave.org>
parents:
18384
diff
changeset
|
470 static_cast<std::streamsize> (ncol) * |
9a6646cc7c3e
Fix load/save to handle up to 2^32-1 elements.
Rik <rik@octave.org>
parents:
18384
diff
changeset
|
471 sizeof (double); |
9a6646cc7c3e
Fix load/save to handle up to 2^32-1 elements.
Rik <rik@octave.org>
parents:
18384
diff
changeset
|
472 os.write (reinterpret_cast<char *> (buf), n_bytes); |
4634 | 473 } |
474 else if (tc.is_range ()) | |
475 { | |
476 Range r = tc.range_value (); | |
477 double base = r.base (); | |
478 double inc = r.inc (); | |
20228
00cf2847355d
Deprecate Array::nelem() and Range::nelem() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
19697
diff
changeset
|
479 octave_idx_type nel = r.numel (); |
5275 | 480 for (octave_idx_type i = 0; i < nel; i++) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
481 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
482 double x = base + i * inc; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
483 os.write (reinterpret_cast<char *> (&x), 8); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
484 } |
4634 | 485 } |
486 else if (tc.is_real_scalar ()) | |
487 { | |
488 double tmp = tc.double_value (); | |
5760 | 489 os.write (reinterpret_cast<char *> (&tmp), 8); |
4634 | 490 } |
7918
78eef61f75d5
Add matlab V4 sparse matrixload/save
David Bateman <dbateman@free.fr>
parents:
7336
diff
changeset
|
491 else if (tc.is_sparse_type ()) |
78eef61f75d5
Add matlab V4 sparse matrixload/save
David Bateman <dbateman@free.fr>
parents:
7336
diff
changeset
|
492 { |
78eef61f75d5
Add matlab V4 sparse matrixload/save
David Bateman <dbateman@free.fr>
parents:
7336
diff
changeset
|
493 double ds; |
78eef61f75d5
Add matlab V4 sparse matrixload/save
David Bateman <dbateman@free.fr>
parents:
7336
diff
changeset
|
494 OCTAVE_LOCAL_BUFFER (double, dtmp, len); |
78eef61f75d5
Add matlab V4 sparse matrixload/save
David Bateman <dbateman@free.fr>
parents:
7336
diff
changeset
|
495 if (tc.is_complex_matrix ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
496 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
497 SparseComplexMatrix m = tc.sparse_complex_matrix_value (); |
7918
78eef61f75d5
Add matlab V4 sparse matrixload/save
David Bateman <dbateman@free.fr>
parents:
7336
diff
changeset
|
498 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
499 for (octave_idx_type i = 0; i < len; i++) |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
500 dtmp[i] = m.ridx (i) + 1; |
18691
9a6646cc7c3e
Fix load/save to handle up to 2^32-1 elements.
Rik <rik@octave.org>
parents:
18384
diff
changeset
|
501 std::streamsize n_bytes = 8 * static_cast<std::streamsize> (len); |
9a6646cc7c3e
Fix load/save to handle up to 2^32-1 elements.
Rik <rik@octave.org>
parents:
18384
diff
changeset
|
502 os.write (reinterpret_cast<const char *> (dtmp), n_bytes); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
503 ds = nr; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
504 os.write (reinterpret_cast<const char *> (&ds), 8); |
7918
78eef61f75d5
Add matlab V4 sparse matrixload/save
David Bateman <dbateman@free.fr>
parents:
7336
diff
changeset
|
505 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
506 octave_idx_type ii = 0; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
507 for (octave_idx_type j = 0; j < nc; j++) |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
508 for (octave_idx_type i = m.cidx (j); i < m.cidx (j+1); i++) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
509 dtmp[ii++] = j + 1; |
18691
9a6646cc7c3e
Fix load/save to handle up to 2^32-1 elements.
Rik <rik@octave.org>
parents:
18384
diff
changeset
|
510 os.write (reinterpret_cast<const char *> (dtmp), n_bytes); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
511 ds = nc; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
512 os.write (reinterpret_cast<const char *> (&ds), 8); |
7918
78eef61f75d5
Add matlab V4 sparse matrixload/save
David Bateman <dbateman@free.fr>
parents:
7336
diff
changeset
|
513 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
514 for (octave_idx_type i = 0; i < len; i++) |
22274
edcad35c364f
don't rely on std:: overloads of arg, conj, imag, and real for real args
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
515 dtmp[i] = octave::math::real (m.data (i)); |
18691
9a6646cc7c3e
Fix load/save to handle up to 2^32-1 elements.
Rik <rik@octave.org>
parents:
18384
diff
changeset
|
516 os.write (reinterpret_cast<const char *> (dtmp), n_bytes); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
517 ds = 0.; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
518 os.write (reinterpret_cast<const char *> (&ds), 8); |
7918
78eef61f75d5
Add matlab V4 sparse matrixload/save
David Bateman <dbateman@free.fr>
parents:
7336
diff
changeset
|
519 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
520 for (octave_idx_type i = 0; i < len; i++) |
22274
edcad35c364f
don't rely on std:: overloads of arg, conj, imag, and real for real args
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
521 dtmp[i] = octave::math::imag (m.data (i)); |
18691
9a6646cc7c3e
Fix load/save to handle up to 2^32-1 elements.
Rik <rik@octave.org>
parents:
18384
diff
changeset
|
522 os.write (reinterpret_cast<const char *> (dtmp), n_bytes); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
523 os.write (reinterpret_cast<const char *> (&ds), 8); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
524 } |
7918
78eef61f75d5
Add matlab V4 sparse matrixload/save
David Bateman <dbateman@free.fr>
parents:
7336
diff
changeset
|
525 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
526 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
527 SparseMatrix m = tc.sparse_matrix_value (); |
7918
78eef61f75d5
Add matlab V4 sparse matrixload/save
David Bateman <dbateman@free.fr>
parents:
7336
diff
changeset
|
528 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
529 for (octave_idx_type i = 0; i < len; i++) |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
530 dtmp[i] = m.ridx (i) + 1; |
18691
9a6646cc7c3e
Fix load/save to handle up to 2^32-1 elements.
Rik <rik@octave.org>
parents:
18384
diff
changeset
|
531 std::streamsize n_bytes = 8 * static_cast<std::streamsize> (len); |
9a6646cc7c3e
Fix load/save to handle up to 2^32-1 elements.
Rik <rik@octave.org>
parents:
18384
diff
changeset
|
532 os.write (reinterpret_cast<const char *> (dtmp), n_bytes); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
533 ds = nr; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
534 os.write (reinterpret_cast<const char *> (&ds), 8); |
7918
78eef61f75d5
Add matlab V4 sparse matrixload/save
David Bateman <dbateman@free.fr>
parents:
7336
diff
changeset
|
535 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
536 octave_idx_type ii = 0; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
537 for (octave_idx_type j = 0; j < nc; j++) |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
538 for (octave_idx_type i = m.cidx (j); i < m.cidx (j+1); i++) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
539 dtmp[ii++] = j + 1; |
18691
9a6646cc7c3e
Fix load/save to handle up to 2^32-1 elements.
Rik <rik@octave.org>
parents:
18384
diff
changeset
|
540 os.write (reinterpret_cast<const char *> (dtmp), n_bytes); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
541 ds = nc; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
542 os.write (reinterpret_cast<const char *> (&ds), 8); |
7918
78eef61f75d5
Add matlab V4 sparse matrixload/save
David Bateman <dbateman@free.fr>
parents:
7336
diff
changeset
|
543 |
18691
9a6646cc7c3e
Fix load/save to handle up to 2^32-1 elements.
Rik <rik@octave.org>
parents:
18384
diff
changeset
|
544 os.write (reinterpret_cast<const char *> (m.data ()), n_bytes); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
545 ds = 0.; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
546 os.write (reinterpret_cast<const char *> (&ds), 8); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
547 } |
7918
78eef61f75d5
Add matlab V4 sparse matrixload/save
David Bateman <dbateman@free.fr>
parents:
7336
diff
changeset
|
548 } |
4634 | 549 else if (tc.is_real_matrix ()) |
550 { | |
551 Matrix m = tc.matrix_value (); | |
18691
9a6646cc7c3e
Fix load/save to handle up to 2^32-1 elements.
Rik <rik@octave.org>
parents:
18384
diff
changeset
|
552 std::streamsize n_bytes = 8 * static_cast<std::streamsize> (len); |
9a6646cc7c3e
Fix load/save to handle up to 2^32-1 elements.
Rik <rik@octave.org>
parents:
18384
diff
changeset
|
553 os.write (reinterpret_cast<const char *> (m.data ()), n_bytes); |
4634 | 554 } |
555 else if (tc.is_complex_scalar ()) | |
556 { | |
557 Complex tmp = tc.complex_value (); | |
5760 | 558 os.write (reinterpret_cast<char *> (&tmp), 16); |
4634 | 559 } |
560 else if (tc.is_complex_matrix ()) | |
561 { | |
562 ComplexMatrix m_cmplx = tc.complex_matrix_value (); | |
563 Matrix m = ::real (m_cmplx); | |
18691
9a6646cc7c3e
Fix load/save to handle up to 2^32-1 elements.
Rik <rik@octave.org>
parents:
18384
diff
changeset
|
564 std::streamsize n_bytes = 8 * static_cast<std::streamsize> (len); |
9a6646cc7c3e
Fix load/save to handle up to 2^32-1 elements.
Rik <rik@octave.org>
parents:
18384
diff
changeset
|
565 os.write (reinterpret_cast<const char *> (m.data ()), n_bytes); |
4634 | 566 m = ::imag (m_cmplx); |
18691
9a6646cc7c3e
Fix load/save to handle up to 2^32-1 elements.
Rik <rik@octave.org>
parents:
18384
diff
changeset
|
567 os.write (reinterpret_cast<const char *> (m.data ()), n_bytes); |
4634 | 568 } |
569 else | |
21100
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
570 // FIXME: Should this just error out rather than warn? |
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
571 warn_wrong_type_arg ("save", tc); |
4634 | 572 |
18384
bd9d34f28b0f
Use std::ostream::fail instead of unsafe implicit bool conversion (bug #41335)
Mike Miller <mtmiller@ieee.org>
parents:
17787
diff
changeset
|
573 return ! os.fail (); |
4634 | 574 } |