Mercurial > hg > octave-lojdl
annotate src/ls-mat4.cc @ 15466:d174210ce1ec stable
use ' instead of ` in error messages, warnings and most comments
* intro.txi, io.txi, munge-texi.cc, octave.texi, cmd-edit.cc,
data-conv.cc, file-ops.cc, glob-match.h, kpse.cc, oct-env.cc,
oct-locbuf.h, oct-md5.cc, oct-rand.cc, general/interp2.m, doc.m,
get_first_help_sentence.m, help.m, print_usage.m,
__additional_help_message__.m, type.m, unimplemented.m, which.m,
cast.m, dir.m, license.m, mkoctfile.m, recycle.m, tempdir.m,
optimset.m, pkg/pkg.m, closereq.m, colstyle.m, __fltk_print__.m,
__gnuplot_print__.m, __go_draw_figure__.m, __pie__.m, __pltopt__.m,
__print_parse_opts__.m, uigetdir.m, uigetfile.m, uiputfile.m, stft.m,
mean.m, anova.m, cor_test.m, t_test_regression.m, __magick_read__.cc,
dlmread.cc, schur.cc, data.cc, debug.cc, defun-dld.h, defun.cc,
defun.h, dynamic-ld.cc, error.cc, error.h, gl-render.cc, graphics.cc,
gripes.cc, input.cc, lex.ll, load-path.cc, load-save.cc, ls-hdf5.cc,
ls-mat-ascii.cc, ls-mat4.cc, ls-mat5.cc, ls-oct-ascii.cc,
ls-oct-binary.cc, oct-hist.cc, oct-parse.yy, oct-stream.cc,
oct-stream.h, octave.cc, ov-base-diag.cc, ov-base.cc, ov-class.cc,
ov-colon.h, ov-struct.cc, ov-typeinfo.cc, ov.cc, pager.cc,
pr-output.cc, pt-binop.cc, pt-eval.cc, pt-id.cc, pt-idx.cc,
pt-misc.cc, pt-unop.cc, symtab.cc, symtab.h, toplev.cc, txt-eng-ft.cc,
utils.cc, variables.cc, test_eval-catch.m, test_try.m:
Use ' instead of ` in error messages, warnings, and most comments.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Mon, 01 Oct 2012 17:18:49 -0400 |
parents | 72c96de7a403 |
children |
rev | line source |
---|---|
4634 | 1 /* |
2 | |
14138
72c96de7a403
maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
3 Copyright (C) 1996-2012 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 | |
8 under the terms of the GNU General Public License as published by the | |
7016 | 9 Free Software Foundation; either version 3 of the License, or (at your |
10 option) any later version. | |
4634 | 11 |
12 Octave is distributed in the hope that it will be useful, but WITHOUT | |
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
15 for more details. | |
16 | |
17 You should have received a copy of the GNU General Public License | |
7016 | 18 along with Octave; see the file COPYING. If not, see |
19 <http://www.gnu.org/licenses/>. | |
4634 | 20 |
21 */ | |
22 | |
23 #ifdef HAVE_CONFIG_H | |
24 #include <config.h> | |
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" | |
52 #include "gripes.h" | |
53 #include "load-save.h" | |
54 #include "oct-obj.h" | |
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, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
78 oct_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)) |
4634 | 128 goto data_read_error; |
129 | |
5760 | 130 if (! is.read (reinterpret_cast<char *> (&nc), 4)) |
4634 | 131 goto data_read_error; |
132 | |
5760 | 133 if (! is.read (reinterpret_cast<char *> (&imag), 4)) |
4634 | 134 goto data_read_error; |
135 | |
5760 | 136 if (! is.read (reinterpret_cast<char *> (&len), 4)) |
4634 | 137 goto data_read_error; |
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 | |
148 if (oct_mach_info::words_big_endian () && mopt == 0) | |
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"); |
4634 | 169 return -1; |
170 } | |
171 | |
172 return 0; | |
173 | |
174 data_read_error: | |
175 return -1; | |
176 } | |
177 | |
178 // We don't just use a cast here, because we need to be able to detect | |
179 // possible errors. | |
180 | |
181 oct_mach_info::float_format | |
182 mopt_digit_to_float_format (int mach) | |
183 { | |
184 oct_mach_info::float_format flt_fmt = oct_mach_info::flt_fmt_unknown; | |
185 | |
186 switch (mach) | |
187 { | |
188 case 0: | |
189 flt_fmt = oct_mach_info::flt_fmt_ieee_little_endian; | |
190 break; | |
191 | |
192 case 1: | |
193 flt_fmt = oct_mach_info::flt_fmt_ieee_big_endian; | |
194 break; | |
195 | |
196 case 2: | |
197 flt_fmt = oct_mach_info::flt_fmt_vax_d; | |
198 break; | |
199 | |
200 case 3: | |
201 flt_fmt = oct_mach_info::flt_fmt_vax_g; | |
202 break; | |
203 | |
204 case 4: | |
205 flt_fmt = oct_mach_info::flt_fmt_cray; | |
206 break; | |
207 | |
208 default: | |
209 flt_fmt = oct_mach_info::flt_fmt_unknown; | |
210 break; | |
211 } | |
212 | |
213 return flt_fmt; | |
214 } | |
215 | |
216 int | |
217 float_format_to_mopt_digit (oct_mach_info::float_format flt_fmt) | |
218 { | |
219 int retval = -1; | |
220 | |
221 switch (flt_fmt) | |
222 { | |
223 case oct_mach_info::flt_fmt_ieee_little_endian: | |
224 retval = 0; | |
225 break; | |
226 | |
227 case oct_mach_info::flt_fmt_ieee_big_endian: | |
228 retval = 1; | |
229 break; | |
230 | |
231 case oct_mach_info::flt_fmt_vax_d: | |
232 retval = 2; | |
233 break; | |
234 | |
235 case oct_mach_info::flt_fmt_vax_g: | |
236 retval = 3; | |
237 break; | |
238 | |
239 case oct_mach_info::flt_fmt_cray: | |
240 retval = 4; | |
241 break; | |
242 | |
243 default: | |
244 break; | |
245 } | |
246 | |
247 return retval; | |
248 } | |
249 | |
250 // Extract one value (scalar, matrix, string, etc.) from stream IS and | |
251 // place it in TC, returning the name of the variable. | |
252 // | |
253 // The data is expected to be in Matlab version 4 .mat format, though | |
254 // not all the features of that format are supported. | |
255 // | |
256 // FILENAME is used for error messages. | |
257 // | |
258 // This format provides no way to tag the data as global. | |
259 | |
260 std::string | |
261 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
|
262 octave_value& tc) |
4634 | 263 { |
264 std::string retval; | |
265 | |
266 // These are initialized here instead of closer to where they are | |
267 // first used to avoid errors from gcc about goto crossing | |
268 // initialization of variable. | |
269 | |
270 Matrix re; | |
271 oct_mach_info::float_format flt_fmt = oct_mach_info::flt_fmt_unknown; | |
272 bool swap = false; | |
273 int type = 0; | |
274 int prec = 0; | |
275 int order = 0; | |
276 int mach = 0; | |
277 int dlen = 0; | |
278 | |
5828 | 279 int32_t mopt, nr, nc, imag, len; |
4634 | 280 |
281 int err = read_mat_file_header (is, swap, mopt, nr, nc, imag, len); | |
282 if (err) | |
283 { | |
284 if (err < 0) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
285 goto data_read_error; |
4634 | 286 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
287 return retval; |
4634 | 288 } |
289 | |
290 type = mopt % 10; // Full, sparse, etc. | |
291 mopt /= 10; // Eliminate first digit. | |
292 prec = mopt % 10; // double, float, int, etc. | |
293 mopt /= 10; // Eliminate second digit. | |
294 order = mopt % 10; // Row or column major ordering. | |
295 mopt /= 10; // Eliminate third digit. | |
296 mach = mopt % 10; // IEEE, VAX, etc. | |
297 | |
298 flt_fmt = mopt_digit_to_float_format (mach); | |
299 | |
300 if (flt_fmt == oct_mach_info::flt_fmt_unknown) | |
301 { | |
302 error ("load: unrecognized binary format!"); | |
303 return retval; | |
304 } | |
305 | |
306 if (imag && type == 1) | |
307 { | |
308 error ("load: encountered complex matrix with string flag set!"); | |
309 return retval; | |
310 } | |
311 | |
312 // LEN includes the terminating character, and the file is also | |
313 // supposed to include it, but apparently not all files do. Either | |
314 // way, I think this should work. | |
315 | |
316 { | |
317 OCTAVE_LOCAL_BUFFER (char, name, len+1); | |
318 name[len] = '\0'; | |
5760 | 319 if (! is.read (name, len)) |
4634 | 320 goto data_read_error; |
321 retval = name; | |
322 | |
323 dlen = nr * nc; | |
324 if (dlen < 0) | |
325 goto data_read_error; | |
326 | |
327 if (order) | |
328 { | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
329 octave_idx_type tmp = nr; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
330 nr = nc; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
331 nc = tmp; |
4634 | 332 } |
333 | |
7918
78eef61f75d5
Add matlab V4 sparse matrixload/save
David Bateman <dbateman@free.fr>
parents:
7336
diff
changeset
|
334 if (type == 2) |
78eef61f75d5
Add matlab V4 sparse matrixload/save
David Bateman <dbateman@free.fr>
parents:
7336
diff
changeset
|
335 { |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
336 if (nc == 4) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
337 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
338 octave_idx_type nr_new, nc_new; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
339 Array<Complex> data (dim_vector (1, nr - 1)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
340 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
|
341 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
|
342 OCTAVE_LOCAL_BUFFER (double, dtmp, nr); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
343 OCTAVE_LOCAL_BUFFER (double, ctmp, nr); |
4634 | 344 |
10315
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++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
347 r.xelem(i) = dtmp[i] - 1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
348 nr_new = dtmp[nr - 1]; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
349 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
|
350 for (octave_idx_type i = 0; i < nr - 1; i++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
351 c.xelem(i) = dtmp[i] - 1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
352 nc_new = dtmp[nr - 1]; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
353 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
|
354 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
|
355 read_mat_binary_data (is, ctmp, prec, nr - 1, swap, flt_fmt); |
4634 | 356 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
357 for (octave_idx_type i = 0; i < nr - 1; i++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
358 data.xelem(i) = Complex (dtmp[i], ctmp[i]); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
359 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
|
360 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
361 SparseComplexMatrix smc = SparseComplexMatrix (data, r, c, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
362 nr_new, nc_new); |
4634 | 363 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
364 tc = order ? smc.transpose () : smc; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
365 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
366 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
367 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
368 octave_idx_type nr_new, nc_new; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
369 Array<double> data (dim_vector (1, nr - 1)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
370 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
|
371 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
|
372 OCTAVE_LOCAL_BUFFER (double, dtmp, nr); |
4634 | 373 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
374 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
|
375 for (octave_idx_type i = 0; i < nr - 1; i++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
376 r.xelem(i) = dtmp[i] - 1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
377 nr_new = dtmp[nr - 1]; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
378 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
|
379 for (octave_idx_type i = 0; i < nr - 1; i++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
380 c.xelem(i) = dtmp[i] - 1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
381 nc_new = dtmp[nr - 1]; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
382 read_mat_binary_data (is, data.fortran_vec (), prec, nr - 1, swap, flt_fmt); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
383 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
|
384 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
385 SparseMatrix sm = SparseMatrix (data, r, c, nr_new, nc_new); |
4634 | 386 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
387 tc = order ? sm.transpose () : sm; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
388 } |
7918
78eef61f75d5
Add matlab V4 sparse matrixload/save
David Bateman <dbateman@free.fr>
parents:
7336
diff
changeset
|
389 } |
78eef61f75d5
Add matlab V4 sparse matrixload/save
David Bateman <dbateman@free.fr>
parents:
7336
diff
changeset
|
390 else |
78eef61f75d5
Add matlab V4 sparse matrixload/save
David Bateman <dbateman@free.fr>
parents:
7336
diff
changeset
|
391 { |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
392 re.resize (nr, nc); |
7918
78eef61f75d5
Add matlab V4 sparse matrixload/save
David Bateman <dbateman@free.fr>
parents:
7336
diff
changeset
|
393 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
394 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
|
395 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
396 if (! is || error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
397 { |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
398 error ("load: reading matrix data for '%s'", name); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
399 goto data_read_error; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
400 } |
4634 | 401 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
402 if (imag) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
403 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
404 Matrix im (nr, nc); |
7918
78eef61f75d5
Add matlab V4 sparse matrixload/save
David Bateman <dbateman@free.fr>
parents:
7336
diff
changeset
|
405 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
406 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
|
407 flt_fmt); |
7918
78eef61f75d5
Add matlab V4 sparse matrixload/save
David Bateman <dbateman@free.fr>
parents:
7336
diff
changeset
|
408 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
409 if (! is || error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
410 { |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
411 error ("load: reading imaginary matrix data for '%s'", name); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
412 goto data_read_error; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
413 } |
4634 | 414 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
415 ComplexMatrix ctmp (nr, nc); |
7918
78eef61f75d5
Add matlab V4 sparse matrixload/save
David Bateman <dbateman@free.fr>
parents:
7336
diff
changeset
|
416 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
417 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
|
418 for (octave_idx_type i = 0; i < nr; i++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
419 ctmp (i, j) = Complex (re (i, j), im (i, j)); |
4634 | 420 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
421 tc = order ? ctmp.transpose () : ctmp; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
422 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
423 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
424 tc = order ? re.transpose () : re; |
7918
78eef61f75d5
Add matlab V4 sparse matrixload/save
David Bateman <dbateman@free.fr>
parents:
7336
diff
changeset
|
425 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
426 if (type == 1) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
427 tc = tc.convert_to_str (false, true, '\''); |
7918
78eef61f75d5
Add matlab V4 sparse matrixload/save
David Bateman <dbateman@free.fr>
parents:
7336
diff
changeset
|
428 } |
4634 | 429 |
430 return retval; | |
431 } | |
432 | |
433 data_read_error: | |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
434 error ("load: trouble reading binary file '%s'", filename.c_str ()); |
4634 | 435 return retval; |
436 } | |
437 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
438 // Save the data from TC along with the corresponding NAME on stream OS |
4634 | 439 // in the MatLab version 4 binary format. |
440 | |
441 bool | |
442 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
|
443 const std::string& name) |
4634 | 444 { |
5828 | 445 int32_t mopt = 0; |
4634 | 446 |
7918
78eef61f75d5
Add matlab V4 sparse matrixload/save
David Bateman <dbateman@free.fr>
parents:
7336
diff
changeset
|
447 mopt += tc.is_sparse_type () ? 2 : tc.is_string () ? 1 : 0; |
4634 | 448 |
449 oct_mach_info::float_format flt_fmt = | |
450 oct_mach_info::native_float_format ();; | |
451 | |
452 mopt += 1000 * float_format_to_mopt_digit (flt_fmt); | |
453 | |
5760 | 454 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
|
455 |
7918
78eef61f75d5
Add matlab V4 sparse matrixload/save
David Bateman <dbateman@free.fr>
parents:
7336
diff
changeset
|
456 octave_idx_type len; |
5828 | 457 int32_t nr = tc.rows (); |
4634 | 458 |
5828 | 459 int32_t nc = tc.columns (); |
7918
78eef61f75d5
Add matlab V4 sparse matrixload/save
David Bateman <dbateman@free.fr>
parents:
7336
diff
changeset
|
460 |
78eef61f75d5
Add matlab V4 sparse matrixload/save
David Bateman <dbateman@free.fr>
parents:
7336
diff
changeset
|
461 if (tc.is_sparse_type ()) |
78eef61f75d5
Add matlab V4 sparse matrixload/save
David Bateman <dbateman@free.fr>
parents:
7336
diff
changeset
|
462 { |
78eef61f75d5
Add matlab V4 sparse matrixload/save
David Bateman <dbateman@free.fr>
parents:
7336
diff
changeset
|
463 len = tc.nnz (); |
78eef61f75d5
Add matlab V4 sparse matrixload/save
David Bateman <dbateman@free.fr>
parents:
7336
diff
changeset
|
464 uint32_t nnz = len + 1; |
78eef61f75d5
Add matlab V4 sparse matrixload/save
David Bateman <dbateman@free.fr>
parents:
7336
diff
changeset
|
465 os.write (reinterpret_cast<char *> (&nnz), 4); |
78eef61f75d5
Add matlab V4 sparse matrixload/save
David Bateman <dbateman@free.fr>
parents:
7336
diff
changeset
|
466 |
78eef61f75d5
Add matlab V4 sparse matrixload/save
David Bateman <dbateman@free.fr>
parents:
7336
diff
changeset
|
467 uint32_t iscmplx = tc.is_complex_type () ? 4 : 3; |
78eef61f75d5
Add matlab V4 sparse matrixload/save
David Bateman <dbateman@free.fr>
parents:
7336
diff
changeset
|
468 os.write (reinterpret_cast<char *> (&iscmplx), 4); |
4634 | 469 |
7918
78eef61f75d5
Add matlab V4 sparse matrixload/save
David Bateman <dbateman@free.fr>
parents:
7336
diff
changeset
|
470 uint32_t tmp = 0; |
78eef61f75d5
Add matlab V4 sparse matrixload/save
David Bateman <dbateman@free.fr>
parents:
7336
diff
changeset
|
471 os.write (reinterpret_cast<char *> (&tmp), 4); |
78eef61f75d5
Add matlab V4 sparse matrixload/save
David Bateman <dbateman@free.fr>
parents:
7336
diff
changeset
|
472 } |
78eef61f75d5
Add matlab V4 sparse matrixload/save
David Bateman <dbateman@free.fr>
parents:
7336
diff
changeset
|
473 else |
78eef61f75d5
Add matlab V4 sparse matrixload/save
David Bateman <dbateman@free.fr>
parents:
7336
diff
changeset
|
474 { |
78eef61f75d5
Add matlab V4 sparse matrixload/save
David Bateman <dbateman@free.fr>
parents:
7336
diff
changeset
|
475 os.write (reinterpret_cast<char *> (&nr), 4); |
78eef61f75d5
Add matlab V4 sparse matrixload/save
David Bateman <dbateman@free.fr>
parents:
7336
diff
changeset
|
476 os.write (reinterpret_cast<char *> (&nc), 4); |
4634 | 477 |
7918
78eef61f75d5
Add matlab V4 sparse matrixload/save
David Bateman <dbateman@free.fr>
parents:
7336
diff
changeset
|
478 int32_t imag = tc.is_complex_type () ? 1 : 0; |
78eef61f75d5
Add matlab V4 sparse matrixload/save
David Bateman <dbateman@free.fr>
parents:
7336
diff
changeset
|
479 os.write (reinterpret_cast<char *> (&imag), 4); |
78eef61f75d5
Add matlab V4 sparse matrixload/save
David Bateman <dbateman@free.fr>
parents:
7336
diff
changeset
|
480 |
78eef61f75d5
Add matlab V4 sparse matrixload/save
David Bateman <dbateman@free.fr>
parents:
7336
diff
changeset
|
481 len = nr * nc; |
78eef61f75d5
Add matlab V4 sparse matrixload/save
David Bateman <dbateman@free.fr>
parents:
7336
diff
changeset
|
482 } |
78eef61f75d5
Add matlab V4 sparse matrixload/save
David Bateman <dbateman@free.fr>
parents:
7336
diff
changeset
|
483 |
4634 | 484 |
485 // LEN includes the terminating character, and the file is also | |
486 // supposed to include it. | |
487 | |
5828 | 488 int32_t name_len = name.length () + 1; |
4634 | 489 |
5760 | 490 os.write (reinterpret_cast<char *> (&name_len), 4); |
4634 | 491 os << name << '\0'; |
492 | |
493 if (tc.is_string ()) | |
494 { | |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9377
diff
changeset
|
495 unwind_protect frame; |
4634 | 496 |
497 charMatrix chm = tc.char_matrix_value (); | |
498 | |
5275 | 499 octave_idx_type nrow = chm.rows (); |
500 octave_idx_type ncol = chm.cols (); | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
501 |
4634 | 502 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
|
503 |
5275 | 504 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
|
505 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
506 std::string tstr = chm.row_as_string (i); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
507 const char *s = tstr.data (); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
508 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
509 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
|
510 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
|
511 } |
5760 | 512 os.write (reinterpret_cast<char *> (buf), nrow*ncol*sizeof(double)); |
4634 | 513 } |
514 else if (tc.is_range ()) | |
515 { | |
516 Range r = tc.range_value (); | |
517 double base = r.base (); | |
518 double inc = r.inc (); | |
5275 | 519 octave_idx_type nel = r.nelem (); |
520 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
|
521 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
522 double x = base + i * inc; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
523 os.write (reinterpret_cast<char *> (&x), 8); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
524 } |
4634 | 525 } |
526 else if (tc.is_real_scalar ()) | |
527 { | |
528 double tmp = tc.double_value (); | |
5760 | 529 os.write (reinterpret_cast<char *> (&tmp), 8); |
4634 | 530 } |
7918
78eef61f75d5
Add matlab V4 sparse matrixload/save
David Bateman <dbateman@free.fr>
parents:
7336
diff
changeset
|
531 else if (tc.is_sparse_type ()) |
78eef61f75d5
Add matlab V4 sparse matrixload/save
David Bateman <dbateman@free.fr>
parents:
7336
diff
changeset
|
532 { |
78eef61f75d5
Add matlab V4 sparse matrixload/save
David Bateman <dbateman@free.fr>
parents:
7336
diff
changeset
|
533 double ds; |
78eef61f75d5
Add matlab V4 sparse matrixload/save
David Bateman <dbateman@free.fr>
parents:
7336
diff
changeset
|
534 OCTAVE_LOCAL_BUFFER (double, dtmp, len); |
78eef61f75d5
Add matlab V4 sparse matrixload/save
David Bateman <dbateman@free.fr>
parents:
7336
diff
changeset
|
535 if (tc.is_complex_matrix ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
536 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
537 SparseComplexMatrix m = tc.sparse_complex_matrix_value (); |
7918
78eef61f75d5
Add matlab V4 sparse matrixload/save
David Bateman <dbateman@free.fr>
parents:
7336
diff
changeset
|
538 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
539 for (octave_idx_type i = 0; i < len; i++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
540 dtmp [i] = m.ridx(i) + 1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
541 os.write (reinterpret_cast<const char *> (dtmp), 8 * len); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
542 ds = nr; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
543 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
|
544 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
545 octave_idx_type ii = 0; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
546 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
|
547 for (octave_idx_type i = m.cidx(j); i < m.cidx(j+1); i++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
548 dtmp[ii++] = j + 1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
549 os.write (reinterpret_cast<const char *> (dtmp), 8 * len); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
550 ds = nc; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
551 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
|
552 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
553 for (octave_idx_type i = 0; i < len; i++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
554 dtmp [i] = std::real (m.data(i)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
555 os.write (reinterpret_cast<const char *> (dtmp), 8 * len); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
556 ds = 0.; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
557 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
|
558 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
559 for (octave_idx_type i = 0; i < len; i++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
560 dtmp [i] = std::imag (m.data(i)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
561 os.write (reinterpret_cast<const char *> (dtmp), 8 * len); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
562 os.write (reinterpret_cast<const char *> (&ds), 8); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
563 } |
7918
78eef61f75d5
Add matlab V4 sparse matrixload/save
David Bateman <dbateman@free.fr>
parents:
7336
diff
changeset
|
564 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
565 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
566 SparseMatrix m = tc.sparse_matrix_value (); |
7918
78eef61f75d5
Add matlab V4 sparse matrixload/save
David Bateman <dbateman@free.fr>
parents:
7336
diff
changeset
|
567 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
568 for (octave_idx_type i = 0; i < len; i++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
569 dtmp [i] = m.ridx(i) + 1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
570 os.write (reinterpret_cast<const char *> (dtmp), 8 * len); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
571 ds = nr; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
572 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
|
573 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
574 octave_idx_type ii = 0; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
575 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
|
576 for (octave_idx_type i = m.cidx(j); i < m.cidx(j+1); i++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
577 dtmp[ii++] = j + 1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
578 os.write (reinterpret_cast<const char *> (dtmp), 8 * len); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
579 ds = nc; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
580 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
|
581 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
582 os.write (reinterpret_cast<const char *> (m.data ()), 8 * len); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
583 ds = 0.; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
584 os.write (reinterpret_cast<const char *> (&ds), 8); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
585 } |
7918
78eef61f75d5
Add matlab V4 sparse matrixload/save
David Bateman <dbateman@free.fr>
parents:
7336
diff
changeset
|
586 } |
4634 | 587 else if (tc.is_real_matrix ()) |
588 { | |
589 Matrix m = tc.matrix_value (); | |
5760 | 590 os.write (reinterpret_cast<const char *> (m.data ()), 8 * len); |
4634 | 591 } |
592 else if (tc.is_complex_scalar ()) | |
593 { | |
594 Complex tmp = tc.complex_value (); | |
5760 | 595 os.write (reinterpret_cast<char *> (&tmp), 16); |
4634 | 596 } |
597 else if (tc.is_complex_matrix ()) | |
598 { | |
599 ComplexMatrix m_cmplx = tc.complex_matrix_value (); | |
600 Matrix m = ::real (m_cmplx); | |
5760 | 601 os.write (reinterpret_cast<const char *> (m.data ()), 8 * len); |
4634 | 602 m = ::imag (m_cmplx); |
5760 | 603 os.write (reinterpret_cast<const char *> (m.data ()), 8 * len); |
4634 | 604 } |
605 else | |
606 gripe_wrong_type_arg ("save", tc, false); | |
607 | |
608 return os; | |
609 } |