Mercurial > octave
annotate libinterp/corefcn/ls-mat5.cc @ 21055:5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
* __ilu__.cc, data.cc, file-io.cc, graphics.cc, graphics.in.h, ls-mat5.cc,
lu.cc, octave-link.cc, regexp.cc, schur.cc, spparms.cc, sub2ind.cc,
syscalls.cc, toplev.cc, variables.cc, xpow.cc, audiodevinfo.cc, ccolamd.cc,
ov-builtin.cc, ov-classdef.cc, ov-intx.h, ov-lazy-idx.cc, ov-mex-fcn.cc,
op-int.h, lex.ll, oct-parse.in.yy, pt-binop.cc, pt-cbinop.cc, pt-const.cc,
pt-decl.h, pt-fcn-handle.cc, pt-unop.cc, CollocWt.cc:
Replace if/error/else paradigm with just if/error.
author | Rik <rik@octave.org> |
---|---|
date | Wed, 13 Jan 2016 11:02:22 -0800 |
parents | 93748bcaec17 |
children | e39e05d90788 |
rev | line source |
---|---|
4634 | 1 /* |
2 | |
19697
4197fc428c7d
maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents:
19596
diff
changeset
|
3 Copyright (C) 1996-2015 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 // Author: James R. Van Zandt <jrv@vanzandt.mv.com> | |
24 | |
25 #ifdef HAVE_CONFIG_H | |
26 #include <config.h> | |
27 #endif | |
28 | |
29 #include <cfloat> | |
30 #include <cstring> | |
31 #include <cctype> | |
32 | |
33 #include <fstream> | |
34 #include <iomanip> | |
35 #include <iostream> | |
5765 | 36 #include <sstream> |
4634 | 37 #include <string> |
4726 | 38 #include <vector> |
4634 | 39 |
40 #include "byte-swap.h" | |
41 #include "data-conv.h" | |
42 #include "file-ops.h" | |
43 #include "glob-match.h" | |
44 #include "lo-mappers.h" | |
45 #include "mach-info.h" | |
46 #include "oct-env.h" | |
47 #include "oct-time.h" | |
48 #include "quit.h" | |
49 #include "str-vec.h" | |
6625 | 50 #include "file-stat.h" |
8377
25bc2d31e1bf
improve OCTAVE_LOCAL_BUFFER
Jaroslav Hajek <highegg@gmail.com>
parents:
8212
diff
changeset
|
51 #include "oct-locbuf.h" |
4634 | 52 |
53 #include "Cell.h" | |
54 #include "defun.h" | |
55 #include "error.h" | |
56 #include "gripes.h" | |
57 #include "load-save.h" | |
6625 | 58 #include "load-path.h" |
20940
48b2ad5ee801
maint: Rename oct-obj.[cc|h] to ovl.[cc|h] for clarity.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
59 #include "ovl.h" |
4634 | 60 #include "oct-map.h" |
61 #include "ov-cell.h" | |
8212
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8007
diff
changeset
|
62 #include "ov-class.h" |
6625 | 63 #include "ov-fcn-inline.h" |
4634 | 64 #include "pager.h" |
65 #include "pt-exp.h" | |
66 #include "sysdep.h" | |
9144
c6463412aebb
eliminate symbol_table::scope_stack; fix scoping issue with evalin
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
67 #include "toplev.h" |
4634 | 68 #include "unwind-prot.h" |
69 #include "utils.h" | |
70 #include "variables.h" | |
71 #include "version.h" | |
72 #include "dMatrix.h" | |
73 | |
74 #include "ls-utils.h" | |
75 #include "ls-mat5.h" | |
76 | |
6625 | 77 #include "parse.h" |
78 #include "defaults.h" | |
79 | |
5269 | 80 #ifdef HAVE_ZLIB |
81 #include <zlib.h> | |
82 #endif | |
83 | |
16670
dddbb5dcbf6e
read Level 5 MAT files not encoded with small data element format (bug #38870)
Risto Vanhanen <risto.vanhanen@iki.fi>
parents:
16442
diff
changeset
|
84 #define READ_PAD(is_small_data_element, l) ((is_small_data_element) ? 4 : (((l)+7)/8)*8) |
6295 | 85 #define PAD(l) (((l) > 0 && (l) <= 4) ? 4 : (((l)+7)/8)*8) |
16427
1df815271885
allow various types of int for names like ML
Ed Meyer <eem2314@gmail.com>
parents:
16303
diff
changeset
|
86 #define INT8(l) ((l) == miINT8 || (l) == miUINT8 || (l) == miUTF8) |
4634 | 87 |
6625 | 88 |
89 // The subsystem data block | |
90 static octave_value subsys_ov; | |
91 | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
92 // FIXME: the following enum values should be the same as the |
5900 | 93 // mxClassID values in mexproto.h, but it seems they have also changed |
94 // over time. What is the correct way to handle this and maintain | |
95 // backward compatibility with old MAT files? For now, use | |
96 // "MAT_FILE_" instead of "mx" as the prefix for these names to avoid | |
97 // conflict with the mxClassID enum in mexproto.h. | |
98 | |
4634 | 99 enum arrayclasstype |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
100 { |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
101 MAT_FILE_CELL_CLASS=1, // cell array |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
102 MAT_FILE_STRUCT_CLASS, // structure |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
103 MAT_FILE_OBJECT_CLASS, // object |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
104 MAT_FILE_CHAR_CLASS, // character array |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
105 MAT_FILE_SPARSE_CLASS, // sparse array |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
106 MAT_FILE_DOUBLE_CLASS, // double precision array |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
107 MAT_FILE_SINGLE_CLASS, // single precision floating point |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
108 MAT_FILE_INT8_CLASS, // 8 bit signed integer |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
109 MAT_FILE_UINT8_CLASS, // 8 bit unsigned integer |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
110 MAT_FILE_INT16_CLASS, // 16 bit signed integer |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
111 MAT_FILE_UINT16_CLASS, // 16 bit unsigned integer |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
112 MAT_FILE_INT32_CLASS, // 32 bit signed integer |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
113 MAT_FILE_UINT32_CLASS, // 32 bit unsigned integer |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
114 MAT_FILE_INT64_CLASS, // 64 bit signed integer |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
115 MAT_FILE_UINT64_CLASS, // 64 bit unsigned integer |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
116 MAT_FILE_FUNCTION_CLASS, // Function handle |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
117 MAT_FILE_WORKSPACE_CLASS // Workspace (undocumented) |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
118 }; |
4634 | 119 |
120 // Read COUNT elements of data from IS in the format specified by TYPE, | |
121 // placing the result in DATA. If SWAP is TRUE, swap the bytes of | |
122 // each element before copying to DATA. FLT_FMT specifies the format | |
123 // of the data if we are reading floating point numbers. | |
124 | |
125 static void | |
126 read_mat5_binary_data (std::istream& is, double *data, | |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
127 octave_idx_type count, bool swap, mat5_data_type type, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
128 oct_mach_info::float_format flt_fmt) |
4634 | 129 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11580
diff
changeset
|
130 |
4634 | 131 switch (type) |
132 { | |
133 case miINT8: | |
134 read_doubles (is, data, LS_CHAR, count, swap, flt_fmt); | |
135 break; | |
136 | |
5351 | 137 case miUTF8: |
4634 | 138 case miUINT8: |
139 read_doubles (is, data, LS_U_CHAR, count, swap, flt_fmt); | |
140 break; | |
141 | |
142 case miINT16: | |
143 read_doubles (is, data, LS_SHORT, count, swap, flt_fmt); | |
144 break; | |
145 | |
6954 | 146 case miUTF16: |
4634 | 147 case miUINT16: |
148 read_doubles (is, data, LS_U_SHORT, count, swap, flt_fmt); | |
149 break; | |
150 | |
151 case miINT32: | |
152 read_doubles (is, data, LS_INT, count, swap, flt_fmt); | |
153 break; | |
154 | |
6954 | 155 case miUTF32: |
4634 | 156 case miUINT32: |
157 read_doubles (is, data, LS_U_INT, count, swap, flt_fmt); | |
158 break; | |
159 | |
160 case miSINGLE: | |
161 read_doubles (is, data, LS_FLOAT, count, swap, flt_fmt); | |
162 break; | |
163 | |
164 case miRESERVE1: | |
165 break; | |
166 | |
167 case miDOUBLE: | |
168 read_doubles (is, data, LS_DOUBLE, count, swap, flt_fmt); | |
169 break; | |
170 | |
171 case miRESERVE2: | |
172 case miRESERVE3: | |
173 break; | |
174 | |
17861
870f3e12e163
maint: Use phrase "FIXME:" for problem areas in code.
Rik <rik@octave.org>
parents:
17787
diff
changeset
|
175 // FIXME: how are the 64-bit cases supposed to work here? |
4634 | 176 case miINT64: |
177 read_doubles (is, data, LS_LONG, count, swap, flt_fmt); | |
178 break; | |
179 | |
180 case miUINT64: | |
181 read_doubles (is, data, LS_U_LONG, count, swap, flt_fmt); | |
182 break; | |
183 | |
184 case miMATRIX: | |
185 default: | |
186 break; | |
187 } | |
188 } | |
189 | |
10909
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
190 static void |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
191 read_mat5_binary_data (std::istream& is, float *data, |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
192 octave_idx_type count, bool swap, mat5_data_type type, |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
193 oct_mach_info::float_format flt_fmt) |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
194 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11580
diff
changeset
|
195 |
10909
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
196 switch (type) |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
197 { |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
198 case miINT8: |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
199 read_floats (is, data, LS_CHAR, count, swap, flt_fmt); |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
200 break; |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
201 |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
202 case miUTF8: |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
203 case miUINT8: |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
204 read_floats (is, data, LS_U_CHAR, count, swap, flt_fmt); |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
205 break; |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
206 |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
207 case miINT16: |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
208 read_floats (is, data, LS_SHORT, count, swap, flt_fmt); |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
209 break; |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
210 |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
211 case miUTF16: |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
212 case miUINT16: |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
213 read_floats (is, data, LS_U_SHORT, count, swap, flt_fmt); |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
214 break; |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
215 |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
216 case miINT32: |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
217 read_floats (is, data, LS_INT, count, swap, flt_fmt); |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
218 break; |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
219 |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
220 case miUTF32: |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
221 case miUINT32: |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
222 read_floats (is, data, LS_U_INT, count, swap, flt_fmt); |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
223 break; |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
224 |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
225 case miSINGLE: |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
226 read_floats (is, data, LS_FLOAT, count, swap, flt_fmt); |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
227 break; |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
228 |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
229 case miRESERVE1: |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
230 break; |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
231 |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
232 case miDOUBLE: |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
233 read_floats (is, data, LS_DOUBLE, count, swap, flt_fmt); |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
234 break; |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
235 |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
236 case miRESERVE2: |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
237 case miRESERVE3: |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
238 break; |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
239 |
17861
870f3e12e163
maint: Use phrase "FIXME:" for problem areas in code.
Rik <rik@octave.org>
parents:
17787
diff
changeset
|
240 // FIXME: how are the 64-bit cases supposed to work here? |
10909
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
241 case miINT64: |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
242 read_floats (is, data, LS_LONG, count, swap, flt_fmt); |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
243 break; |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
244 |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
245 case miUINT64: |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
246 read_floats (is, data, LS_U_LONG, count, swap, flt_fmt); |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
247 break; |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
248 |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
249 case miMATRIX: |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
250 default: |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
251 break; |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
252 } |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
253 } |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
254 |
5089 | 255 template <class T> |
256 void | |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
257 read_mat5_integer_data (std::istream& is, T *m, octave_idx_type count, |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
258 bool swap, mat5_data_type type) |
5089 | 259 { |
260 | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
261 #define READ_INTEGER_DATA(TYPE, swap, data, size, len, stream) \ |
5089 | 262 do \ |
263 { \ | |
264 if (len > 0) \ | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
265 { \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
266 OCTAVE_LOCAL_BUFFER (TYPE, ptr, len); \ |
18691
9a6646cc7c3e
Fix load/save to handle up to 2^32-1 elements.
Rik <rik@octave.org>
parents:
18678
diff
changeset
|
267 std::streamsize n_bytes = size * static_cast<std::streamsize> (len); \ |
9a6646cc7c3e
Fix load/save to handle up to 2^32-1 elements.
Rik <rik@octave.org>
parents:
18678
diff
changeset
|
268 stream.read (reinterpret_cast<char *> (ptr), n_bytes); \ |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
269 if (swap) \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
270 swap_bytes< size > (ptr, len); \ |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
271 for (octave_idx_type i = 0; i < len; i++) \ |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
272 data[i] = ptr[i]; \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
273 } \ |
5089 | 274 } \ |
275 while (0) | |
276 | |
277 switch (type) | |
278 { | |
279 case miINT8: | |
5828 | 280 READ_INTEGER_DATA (int8_t, swap, m, 1, count, is); |
5089 | 281 break; |
282 | |
283 case miUINT8: | |
5828 | 284 READ_INTEGER_DATA (uint8_t, swap, m, 1, count, is); |
5089 | 285 break; |
286 | |
287 case miINT16: | |
5828 | 288 READ_INTEGER_DATA (int16_t, swap, m, 2, count, is); |
5089 | 289 break; |
290 | |
291 case miUINT16: | |
5828 | 292 READ_INTEGER_DATA (uint16_t, swap, m, 2, count, is); |
5089 | 293 break; |
294 | |
295 case miINT32: | |
5828 | 296 READ_INTEGER_DATA (int32_t, swap, m, 4, count, is); |
5089 | 297 break; |
298 | |
299 case miUINT32: | |
5828 | 300 READ_INTEGER_DATA (uint32_t, swap, m, 4, count, is); |
5089 | 301 break; |
302 | |
303 case miSINGLE: | |
304 case miRESERVE1: | |
305 case miDOUBLE: | |
306 case miRESERVE2: | |
307 case miRESERVE3: | |
308 break; | |
309 | |
310 case miINT64: | |
5828 | 311 READ_INTEGER_DATA (int64_t, swap, m, 8, count, is); |
5089 | 312 break; |
313 | |
314 case miUINT64: | |
5828 | 315 READ_INTEGER_DATA (uint64_t, swap, m, 8, count, is); |
5089 | 316 break; |
317 | |
318 case miMATRIX: | |
319 default: | |
320 break; | |
321 } | |
322 | |
323 #undef READ_INTEGER_DATA | |
324 | |
325 } | |
326 | |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
327 template void |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
328 read_mat5_integer_data (std::istream& is, octave_int8 *m, |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
329 octave_idx_type count, bool swap, |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
330 mat5_data_type type); |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
331 |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
332 template void |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
333 read_mat5_integer_data (std::istream& is, octave_int16 *m, |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
334 octave_idx_type count, bool swap, |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
335 mat5_data_type type); |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
336 |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
337 template void |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
338 read_mat5_integer_data (std::istream& is, octave_int32 *m, |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
339 octave_idx_type count, bool swap, |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
340 mat5_data_type type); |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
341 |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
342 template void |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
343 read_mat5_integer_data (std::istream& is, octave_int64 *m, |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
344 octave_idx_type count, bool swap, |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
345 mat5_data_type type); |
5164 | 346 |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
347 template void |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
348 read_mat5_integer_data (std::istream& is, octave_uint8 *m, |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
349 octave_idx_type count, bool swap, |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
350 mat5_data_type type); |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
351 |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
352 template void |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
353 read_mat5_integer_data (std::istream& is, octave_uint16 *m, |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
354 octave_idx_type count, bool swap, |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
355 mat5_data_type type); |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
356 |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
357 template void |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
358 read_mat5_integer_data (std::istream& is, octave_uint32 *m, |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
359 octave_idx_type count, bool swap, |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
360 mat5_data_type type); |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
361 |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
362 template void |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
363 read_mat5_integer_data (std::istream& is, octave_uint64 *m, |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
364 octave_idx_type count, bool swap, |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
365 mat5_data_type type); |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
366 |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
367 template void |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
368 read_mat5_integer_data (std::istream& is, int *m, |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
369 octave_idx_type count, bool swap, |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
370 mat5_data_type type); |
5089 | 371 |
372 #define OCTAVE_MAT5_INTEGER_READ(TYP) \ | |
373 { \ | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
374 TYP re (dims); \ |
5089 | 375 \ |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
376 std::streampos tmp_pos; \ |
5089 | 377 \ |
16670
dddbb5dcbf6e
read Level 5 MAT files not encoded with small data element format (bug #38870)
Risto Vanhanen <risto.vanhanen@iki.fi>
parents:
16442
diff
changeset
|
378 if (read_mat5_tag (is, swap, type, len, is_small_data_element)) \ |
20831
35241c4b696c
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20727
diff
changeset
|
379 error ("load: reading matrix data for '%s'", retval.c_str ()); \ |
5089 | 380 \ |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
381 octave_idx_type n = re.numel (); \ |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
382 tmp_pos = is.tellg (); \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
383 read_mat5_integer_data (is, re.fortran_vec (), n, swap, \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
384 static_cast<enum mat5_data_type> (type)); \ |
5089 | 385 \ |
20679
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20650
diff
changeset
|
386 if (! is) \ |
20831
35241c4b696c
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20727
diff
changeset
|
387 error ("load: reading matrix data for '%s'", retval.c_str ()); \ |
5089 | 388 \ |
16670
dddbb5dcbf6e
read Level 5 MAT files not encoded with small data element format (bug #38870)
Risto Vanhanen <risto.vanhanen@iki.fi>
parents:
16442
diff
changeset
|
389 is.seekg (tmp_pos + static_cast<std::streamoff>\ |
dddbb5dcbf6e
read Level 5 MAT files not encoded with small data element format (bug #38870)
Risto Vanhanen <risto.vanhanen@iki.fi>
parents:
16442
diff
changeset
|
390 (READ_PAD (is_small_data_element, len))); \ |
5089 | 391 \ |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
392 if (imag) \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
393 { \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
394 /* We don't handle imag integer types, convert to an array */ \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
395 NDArray im (dims); \ |
5089 | 396 \ |
16670
dddbb5dcbf6e
read Level 5 MAT files not encoded with small data element format (bug #38870)
Risto Vanhanen <risto.vanhanen@iki.fi>
parents:
16442
diff
changeset
|
397 if (read_mat5_tag (is, swap, type, len, is_small_data_element)) \ |
20831
35241c4b696c
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20727
diff
changeset
|
398 error ("load: reading matrix data for '%s'", \ |
35241c4b696c
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20727
diff
changeset
|
399 retval.c_str ()); \ |
5089 | 400 \ |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
401 n = im.numel (); \ |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
402 read_mat5_binary_data (is, im.fortran_vec (), n, swap, \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
403 static_cast<enum mat5_data_type> (type), flt_fmt); \ |
5089 | 404 \ |
20679
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20650
diff
changeset
|
405 if (! is) \ |
20831
35241c4b696c
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20727
diff
changeset
|
406 error ("load: reading imaginary matrix data for '%s'", \ |
35241c4b696c
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20727
diff
changeset
|
407 retval.c_str ()); \ |
5089 | 408 \ |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
409 ComplexNDArray ctmp (dims); \ |
5089 | 410 \ |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
411 for (octave_idx_type i = 0; i < n; i++) \ |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
412 ctmp(i) = Complex (re(i).double_value (), im(i)); \ |
5089 | 413 \ |
414 tc = ctmp; \ | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
415 } \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
416 else \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
417 tc = re; \ |
5089 | 418 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11580
diff
changeset
|
419 |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11580
diff
changeset
|
420 // Read one element tag from stream IS, |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
421 // place the type code in TYPE, the byte count in BYTES and true (false) to |
16670
dddbb5dcbf6e
read Level 5 MAT files not encoded with small data element format (bug #38870)
Risto Vanhanen <risto.vanhanen@iki.fi>
parents:
16442
diff
changeset
|
422 // IS_SMALL_DATA_ELEMENT if the tag is 4 (8) bytes long. |
4634 | 423 // return nonzero on error |
424 static int | |
16670
dddbb5dcbf6e
read Level 5 MAT files not encoded with small data element format (bug #38870)
Risto Vanhanen <risto.vanhanen@iki.fi>
parents:
16442
diff
changeset
|
425 read_mat5_tag (std::istream& is, bool swap, int32_t& type, int32_t& bytes, |
dddbb5dcbf6e
read Level 5 MAT files not encoded with small data element format (bug #38870)
Risto Vanhanen <risto.vanhanen@iki.fi>
parents:
16442
diff
changeset
|
426 bool& is_small_data_element) |
4634 | 427 { |
428 unsigned int upper; | |
5828 | 429 int32_t temp; |
4634 | 430 |
18678
6113e0c6920b
maint: Clean up extra spaces before/after parentheses.
Rik <rik@octave.org>
parents:
18100
diff
changeset
|
431 if (! is.read (reinterpret_cast<char *> (&temp), 4)) |
4634 | 432 goto data_read_error; |
433 | |
434 if (swap) | |
4944 | 435 swap_bytes<4> (&temp); |
4634 | 436 |
437 upper = (temp >> 16) & 0xffff; | |
438 type = temp & 0xffff; | |
439 | |
440 if (upper) | |
441 { | |
442 // "compressed" format | |
443 bytes = upper; | |
16670
dddbb5dcbf6e
read Level 5 MAT files not encoded with small data element format (bug #38870)
Risto Vanhanen <risto.vanhanen@iki.fi>
parents:
16442
diff
changeset
|
444 is_small_data_element = true; |
4634 | 445 } |
446 else | |
447 { | |
18678
6113e0c6920b
maint: Clean up extra spaces before/after parentheses.
Rik <rik@octave.org>
parents:
18100
diff
changeset
|
448 if (! is.read (reinterpret_cast<char *> (&temp), 4)) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
449 goto data_read_error; |
4634 | 450 if (swap) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
451 swap_bytes<4> (&temp); |
4634 | 452 bytes = temp; |
16670
dddbb5dcbf6e
read Level 5 MAT files not encoded with small data element format (bug #38870)
Risto Vanhanen <risto.vanhanen@iki.fi>
parents:
16442
diff
changeset
|
453 is_small_data_element = false; |
4634 | 454 } |
455 | |
456 return 0; | |
457 | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
458 data_read_error: |
4634 | 459 return 1; |
460 } | |
461 | |
4944 | 462 static void |
5828 | 463 read_int (std::istream& is, bool swap, int32_t& val) |
4944 | 464 { |
465 is.read (reinterpret_cast<char *> (&val), 4); | |
466 | |
467 if (swap) | |
468 swap_bytes<4> (&val); | |
469 } | |
470 | |
4634 | 471 // Extract one data element (scalar, matrix, string, etc.) from stream |
472 // IS and place it in TC, returning the name of the variable. | |
473 // | |
474 // The data is expected to be in Matlab's "Version 5" .mat format, | |
475 // though not all the features of that format are supported. | |
476 // | |
477 // FILENAME is used for error messages. | |
478 | |
479 std::string | |
480 read_mat5_binary_element (std::istream& is, const std::string& filename, | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
481 bool swap, bool& global, octave_value& tc) |
4634 | 482 { |
483 std::string retval; | |
484 | |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
485 global = false; |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
486 |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
487 // NOTE: these are initialized here instead of closer to where they |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
488 // are first used to avoid errors from gcc about goto crossing |
4634 | 489 // initialization of variable. |
490 | |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
491 bool imag; |
6625 | 492 bool isclass = false; |
4634 | 493 bool logicalvar; |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
494 dim_vector dims; |
4634 | 495 enum arrayclasstype arrayclass; |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
496 int16_t number = *(reinterpret_cast<const int16_t *>("\x00\x01")); |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
497 octave_idx_type nzmax; |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
498 std::string classname; |
4634 | 499 |
500 // MAT files always use IEEE floating point | |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
501 oct_mach_info::float_format flt_fmt = oct_mach_info::flt_fmt_unknown; |
4634 | 502 if ((number == 1) ^ swap) |
503 flt_fmt = oct_mach_info::flt_fmt_ieee_big_endian; | |
504 else | |
505 flt_fmt = oct_mach_info::flt_fmt_ieee_little_endian; | |
506 | |
16670
dddbb5dcbf6e
read Level 5 MAT files not encoded with small data element format (bug #38870)
Risto Vanhanen <risto.vanhanen@iki.fi>
parents:
16442
diff
changeset
|
507 // element type, length and small data element flag |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
508 int32_t type = 0; |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
509 int32_t element_length; |
16670
dddbb5dcbf6e
read Level 5 MAT files not encoded with small data element format (bug #38870)
Risto Vanhanen <risto.vanhanen@iki.fi>
parents:
16442
diff
changeset
|
510 bool is_small_data_element; |
dddbb5dcbf6e
read Level 5 MAT files not encoded with small data element format (bug #38870)
Risto Vanhanen <risto.vanhanen@iki.fi>
parents:
16442
diff
changeset
|
511 if (read_mat5_tag (is, swap, type, element_length, is_small_data_element)) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
512 return retval; // EOF |
4634 | 513 |
5269 | 514 if (type == miCOMPRESSED) |
515 { | |
16225
28be9be86240
better diagnostic when reading compressed fields in mat files (bug #38488)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
15531
diff
changeset
|
516 #ifdef HAVE_ZLIB |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
517 // If C++ allowed us direct access to the file descriptor of an |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
518 // ifstream in a uniform way, the code below could be vastly |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
519 // simplified, and additional copies of the data in memory |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
520 // wouldn't be needed. |
5269 | 521 |
522 OCTAVE_LOCAL_BUFFER (char, inbuf, element_length); | |
523 is.read (inbuf, element_length); | |
524 | |
525 // We uncompress the first 8 bytes of the header to get the buffer length | |
526 // This will fail with an error Z_MEM_ERROR | |
527 uLongf destLen = 8; | |
528 OCTAVE_LOCAL_BUFFER (unsigned int, tmp, 2); | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11580
diff
changeset
|
529 if (uncompress (reinterpret_cast<Bytef *> (tmp), &destLen, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
530 reinterpret_cast<Bytef *> (inbuf), element_length) |
20981
c11cea70b638
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20955
diff
changeset
|
531 == Z_MEM_ERROR) |
c11cea70b638
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20955
diff
changeset
|
532 error ("load: error probing size of compressed data element"); |
c11cea70b638
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20955
diff
changeset
|
533 |
c11cea70b638
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20955
diff
changeset
|
534 // Why should I have to initialize outbuf as I'll just overwrite!! |
c11cea70b638
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20955
diff
changeset
|
535 if (swap) |
c11cea70b638
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20955
diff
changeset
|
536 swap_bytes<4> (tmp, 2); |
c11cea70b638
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20955
diff
changeset
|
537 |
c11cea70b638
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20955
diff
changeset
|
538 destLen = tmp[1] + 8; |
c11cea70b638
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20955
diff
changeset
|
539 std::string outbuf (destLen, ' '); |
c11cea70b638
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20955
diff
changeset
|
540 |
c11cea70b638
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20955
diff
changeset
|
541 // FIXME: find a way to avoid casting away const here! |
c11cea70b638
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20955
diff
changeset
|
542 |
c11cea70b638
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20955
diff
changeset
|
543 int err = uncompress (reinterpret_cast<Bytef *> |
c11cea70b638
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20955
diff
changeset
|
544 (const_cast<char *> (outbuf.c_str ())), |
c11cea70b638
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20955
diff
changeset
|
545 &destLen, reinterpret_cast<Bytef *> (inbuf), |
c11cea70b638
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20955
diff
changeset
|
546 element_length); |
c11cea70b638
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20955
diff
changeset
|
547 |
c11cea70b638
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20955
diff
changeset
|
548 if (err != Z_OK) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
549 { |
20981
c11cea70b638
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20955
diff
changeset
|
550 std::string msg; |
c11cea70b638
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20955
diff
changeset
|
551 switch (err) |
11580
e306683a7e97
read_mat5_binary_element: improve diagnostic if uncompress fails
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
552 { |
20981
c11cea70b638
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20955
diff
changeset
|
553 case Z_STREAM_END: |
c11cea70b638
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20955
diff
changeset
|
554 msg = "stream end"; |
c11cea70b638
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20955
diff
changeset
|
555 break; |
c11cea70b638
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20955
diff
changeset
|
556 |
c11cea70b638
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20955
diff
changeset
|
557 case Z_NEED_DICT: |
c11cea70b638
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20955
diff
changeset
|
558 msg = "need dict"; |
c11cea70b638
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20955
diff
changeset
|
559 break; |
c11cea70b638
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20955
diff
changeset
|
560 |
c11cea70b638
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20955
diff
changeset
|
561 case Z_ERRNO: |
c11cea70b638
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20955
diff
changeset
|
562 msg = "errno case"; |
c11cea70b638
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20955
diff
changeset
|
563 break; |
c11cea70b638
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20955
diff
changeset
|
564 |
c11cea70b638
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20955
diff
changeset
|
565 case Z_STREAM_ERROR: |
c11cea70b638
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20955
diff
changeset
|
566 msg = "stream error"; |
c11cea70b638
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20955
diff
changeset
|
567 break; |
c11cea70b638
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20955
diff
changeset
|
568 |
c11cea70b638
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20955
diff
changeset
|
569 case Z_DATA_ERROR: |
c11cea70b638
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20955
diff
changeset
|
570 msg = "data error"; |
c11cea70b638
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20955
diff
changeset
|
571 break; |
c11cea70b638
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20955
diff
changeset
|
572 |
c11cea70b638
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20955
diff
changeset
|
573 case Z_MEM_ERROR: |
c11cea70b638
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20955
diff
changeset
|
574 msg = "mem error"; |
c11cea70b638
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20955
diff
changeset
|
575 break; |
c11cea70b638
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20955
diff
changeset
|
576 |
c11cea70b638
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20955
diff
changeset
|
577 case Z_BUF_ERROR: |
c11cea70b638
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20955
diff
changeset
|
578 msg = "buf error"; |
c11cea70b638
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20955
diff
changeset
|
579 break; |
c11cea70b638
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20955
diff
changeset
|
580 |
c11cea70b638
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20955
diff
changeset
|
581 case Z_VERSION_ERROR: |
c11cea70b638
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20955
diff
changeset
|
582 msg = "version error"; |
c11cea70b638
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20955
diff
changeset
|
583 break; |
12397
c60eaf7dac31
Remove parts of previous changset that weren't supposed to be committed
David Bateman <dbateman@free.fr>
parents:
12396
diff
changeset
|
584 } |
20981
c11cea70b638
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20955
diff
changeset
|
585 |
c11cea70b638
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20955
diff
changeset
|
586 error ("load: error uncompressing data element (%s from zlib)", |
c11cea70b638
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20955
diff
changeset
|
587 msg.c_str ()); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
588 } |
5269 | 589 else |
20981
c11cea70b638
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20955
diff
changeset
|
590 { |
c11cea70b638
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20955
diff
changeset
|
591 std::istringstream gz_is (outbuf); |
c11cea70b638
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20955
diff
changeset
|
592 retval = read_mat5_binary_element (gz_is, filename, |
c11cea70b638
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20955
diff
changeset
|
593 swap, global, tc); |
c11cea70b638
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20955
diff
changeset
|
594 } |
5269 | 595 |
596 return retval; | |
20945
9d9270e2f98f
eliminate comments after preprocessor conditionals
John W. Eaton <jwe@octave.org>
parents:
20940
diff
changeset
|
597 #else |
16225
28be9be86240
better diagnostic when reading compressed fields in mat files (bug #38488)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
15531
diff
changeset
|
598 error ("load: zlib unavailable, cannot read compressed data element"); |
16226
40cf0a292b20
Fix bad #endif in 28be9be86240
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
16225
diff
changeset
|
599 #endif |
5269 | 600 } |
601 | |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
602 std::streampos pos; |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
603 |
4634 | 604 if (type != miMATRIX) |
605 { | |
6625 | 606 pos = is.tellg (); |
5930 | 607 error ("load: invalid element type = %d", type); |
4634 | 608 } |
609 | |
610 if (element_length == 0) | |
611 { | |
612 tc = Matrix (); | |
613 return retval; | |
614 } | |
615 | |
616 pos = is.tellg (); | |
617 | |
618 // array flags subelement | |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
619 int32_t len; |
19864
17d647821d61
maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
620 if (read_mat5_tag (is, swap, type, len, is_small_data_element) |
17d647821d61
maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
621 || type != miUINT32 || len != 8 || is_small_data_element) |
20831
35241c4b696c
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20727
diff
changeset
|
622 error ("load: invalid array flags subelement"); |
4634 | 623 |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
624 int32_t flags; |
4634 | 625 read_int (is, swap, flags); |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
626 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
627 imag = (flags & 0x0800) != 0; // has an imaginary part? |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
628 |
4634 | 629 global = (flags & 0x0400) != 0; // global variable? |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
630 |
5269 | 631 logicalvar = (flags & 0x0200) != 0; // boolean ? |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
632 |
5760 | 633 arrayclass = static_cast<arrayclasstype> (flags & 0xff); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11580
diff
changeset
|
634 |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
635 int32_t tmp_nzmax; |
18812
9ac2357f19bc
doc: Replace "non-zero" with "nonzero" to match existing usage.
Rik <rik@octave.org>
parents:
18691
diff
changeset
|
636 read_int (is, swap, tmp_nzmax); // max number of nonzero in sparse |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
637 nzmax = tmp_nzmax; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11580
diff
changeset
|
638 |
4634 | 639 // dimensions array subelement |
6625 | 640 if (arrayclass != MAT_FILE_WORKSPACE_CLASS) |
641 { | |
642 int32_t dim_len; | |
4638 | 643 |
19864
17d647821d61
maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
644 if (read_mat5_tag (is, swap, type, dim_len, is_small_data_element) |
17d647821d61
maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
645 || type != miINT32) |
20831
35241c4b696c
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20727
diff
changeset
|
646 error ("load: invalid dimensions array subelement"); |
4634 | 647 |
6625 | 648 int ndims = dim_len / 4; |
18835
94d791a03737
Allow loading mat5 files generated from R and Python (bug #42562).
Rik <rik@octave.org>
parents:
17861
diff
changeset
|
649 if (ndims == 1) |
94d791a03737
Allow loading mat5 files generated from R and Python (bug #42562).
Rik <rik@octave.org>
parents:
17861
diff
changeset
|
650 { |
94d791a03737
Allow loading mat5 files generated from R and Python (bug #42562).
Rik <rik@octave.org>
parents:
17861
diff
changeset
|
651 // R and Python can create a 1-D object which is really an Nx1 object |
94d791a03737
Allow loading mat5 files generated from R and Python (bug #42562).
Rik <rik@octave.org>
parents:
17861
diff
changeset
|
652 dims.resize (2); |
94d791a03737
Allow loading mat5 files generated from R and Python (bug #42562).
Rik <rik@octave.org>
parents:
17861
diff
changeset
|
653 dims(1) = 1; |
94d791a03737
Allow loading mat5 files generated from R and Python (bug #42562).
Rik <rik@octave.org>
parents:
17861
diff
changeset
|
654 } |
94d791a03737
Allow loading mat5 files generated from R and Python (bug #42562).
Rik <rik@octave.org>
parents:
17861
diff
changeset
|
655 else |
94d791a03737
Allow loading mat5 files generated from R and Python (bug #42562).
Rik <rik@octave.org>
parents:
17861
diff
changeset
|
656 dims.resize (ndims); |
94d791a03737
Allow loading mat5 files generated from R and Python (bug #42562).
Rik <rik@octave.org>
parents:
17861
diff
changeset
|
657 |
6625 | 658 for (int i = 0; i < ndims; i++) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
659 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
660 int32_t n; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
661 read_int (is, swap, n); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
662 dims(i) = n; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
663 } |
4634 | 664 |
6625 | 665 std::streampos tmp_pos = is.tellg (); |
16670
dddbb5dcbf6e
read Level 5 MAT files not encoded with small data element format (bug #38870)
Risto Vanhanen <risto.vanhanen@iki.fi>
parents:
16442
diff
changeset
|
666 is.seekg (tmp_pos + static_cast<std::streamoff> |
dddbb5dcbf6e
read Level 5 MAT files not encoded with small data element format (bug #38870)
Risto Vanhanen <risto.vanhanen@iki.fi>
parents:
16442
diff
changeset
|
667 (READ_PAD (is_small_data_element, dim_len) - dim_len)); |
6625 | 668 } |
669 else | |
670 { | |
671 // Why did mathworks decide to not have dims for a workspace!!! | |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
672 dims.resize (2); |
6625 | 673 dims(0) = 1; |
674 dims(1) = 1; | |
675 } | |
4634 | 676 |
19864
17d647821d61
maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
677 if (read_mat5_tag (is, swap, type, len, is_small_data_element) |
17d647821d61
maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
678 || ! INT8(type)) |
20831
35241c4b696c
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20727
diff
changeset
|
679 error ("load: invalid array name subelement"); |
4634 | 680 |
681 { | |
682 OCTAVE_LOCAL_BUFFER (char, name, len+1); | |
683 | |
684 // Structure field subelements have zero-length array name subelements. | |
685 | |
686 std::streampos tmp_pos = is.tellg (); | |
687 | |
688 if (len) | |
689 { | |
18678
6113e0c6920b
maint: Clean up extra spaces before/after parentheses.
Rik <rik@octave.org>
parents:
18100
diff
changeset
|
690 if (! is.read (name, len)) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
691 goto data_read_error; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11580
diff
changeset
|
692 |
16670
dddbb5dcbf6e
read Level 5 MAT files not encoded with small data element format (bug #38870)
Risto Vanhanen <risto.vanhanen@iki.fi>
parents:
16442
diff
changeset
|
693 is.seekg (tmp_pos + static_cast<std::streamoff> |
dddbb5dcbf6e
read Level 5 MAT files not encoded with small data element format (bug #38870)
Risto Vanhanen <risto.vanhanen@iki.fi>
parents:
16442
diff
changeset
|
694 (READ_PAD (is_small_data_element, len))); |
4634 | 695 } |
696 | |
697 name[len] = '\0'; | |
698 retval = name; | |
699 } | |
700 | |
701 switch (arrayclass) | |
702 { | |
5900 | 703 case MAT_FILE_CELL_CLASS: |
4634 | 704 { |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
705 Cell cell_array (dims); |
4634 | 706 |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
707 octave_idx_type n = cell_array.numel (); |
4634 | 708 |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
709 for (octave_idx_type i = 0; i < n; i++) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
710 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
711 octave_value tc2; |
4634 | 712 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
713 std::string nm |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
714 = read_mat5_binary_element (is, filename, swap, global, tc2); |
4634 | 715 |
20679
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20650
diff
changeset
|
716 if (! is) |
20831
35241c4b696c
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20727
diff
changeset
|
717 error ("load: reading cell data for '%s'", nm.c_str ()); |
4634 | 718 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
719 cell_array(i) = tc2; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
720 } |
4634 | 721 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
722 tc = cell_array; |
4634 | 723 } |
724 break; | |
725 | |
5900 | 726 case MAT_FILE_SPARSE_CLASS: |
5164 | 727 { |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
728 octave_idx_type nr = dims(0); |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
729 octave_idx_type nc = dims(1); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
730 SparseMatrix sm; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
731 SparseComplexMatrix scm; |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
732 octave_idx_type *ridx; |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
733 octave_idx_type *cidx; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
734 double *data; |
5164 | 735 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
736 // Setup return value |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
737 if (imag) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
738 { |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
739 scm = SparseComplexMatrix (nr, nc, nzmax); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
740 ridx = scm.ridx (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
741 cidx = scm.cidx (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
742 data = 0; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
743 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
744 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
745 { |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
746 sm = SparseMatrix (nr, nc, nzmax); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
747 ridx = sm.ridx (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
748 cidx = sm.cidx (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
749 data = sm.data (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
750 } |
5164 | 751 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
752 // row indices |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
753 std::streampos tmp_pos; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11580
diff
changeset
|
754 |
16670
dddbb5dcbf6e
read Level 5 MAT files not encoded with small data element format (bug #38870)
Risto Vanhanen <risto.vanhanen@iki.fi>
parents:
16442
diff
changeset
|
755 if (read_mat5_tag (is, swap, type, len, is_small_data_element)) |
20831
35241c4b696c
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20727
diff
changeset
|
756 error ("load: reading sparse row data for '%s'", retval.c_str ()); |
5164 | 757 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
758 tmp_pos = is.tellg (); |
5164 | 759 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
760 read_mat5_integer_data (is, ridx, nzmax, swap, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
761 static_cast<enum mat5_data_type> (type)); |
5164 | 762 |
20679
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20650
diff
changeset
|
763 if (! is) |
20831
35241c4b696c
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20727
diff
changeset
|
764 error ("load: reading sparse row data for '%s'", retval.c_str ()); |
5164 | 765 |
16670
dddbb5dcbf6e
read Level 5 MAT files not encoded with small data element format (bug #38870)
Risto Vanhanen <risto.vanhanen@iki.fi>
parents:
16442
diff
changeset
|
766 is.seekg (tmp_pos + static_cast<std::streamoff> |
dddbb5dcbf6e
read Level 5 MAT files not encoded with small data element format (bug #38870)
Risto Vanhanen <risto.vanhanen@iki.fi>
parents:
16442
diff
changeset
|
767 (READ_PAD (is_small_data_element, len))); |
5164 | 768 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
769 // col indices |
16670
dddbb5dcbf6e
read Level 5 MAT files not encoded with small data element format (bug #38870)
Risto Vanhanen <risto.vanhanen@iki.fi>
parents:
16442
diff
changeset
|
770 if (read_mat5_tag (is, swap, type, len, is_small_data_element)) |
20831
35241c4b696c
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20727
diff
changeset
|
771 error ("load: reading sparse column data for '%s'", |
35241c4b696c
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20727
diff
changeset
|
772 retval.c_str ()); |
5164 | 773 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
774 tmp_pos = is.tellg (); |
5164 | 775 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
776 read_mat5_integer_data (is, cidx, nc + 1, swap, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
777 static_cast<enum mat5_data_type> (type)); |
5164 | 778 |
20679
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20650
diff
changeset
|
779 if (! is) |
20831
35241c4b696c
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20727
diff
changeset
|
780 error ("load: reading sparse column data for '%s'", |
35241c4b696c
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20727
diff
changeset
|
781 retval.c_str ()); |
5164 | 782 |
16670
dddbb5dcbf6e
read Level 5 MAT files not encoded with small data element format (bug #38870)
Risto Vanhanen <risto.vanhanen@iki.fi>
parents:
16442
diff
changeset
|
783 is.seekg (tmp_pos + static_cast<std::streamoff> |
dddbb5dcbf6e
read Level 5 MAT files not encoded with small data element format (bug #38870)
Risto Vanhanen <risto.vanhanen@iki.fi>
parents:
16442
diff
changeset
|
784 (READ_PAD (is_small_data_element, len))); |
5164 | 785 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
786 // real data subelement |
16670
dddbb5dcbf6e
read Level 5 MAT files not encoded with small data element format (bug #38870)
Risto Vanhanen <risto.vanhanen@iki.fi>
parents:
16442
diff
changeset
|
787 if (read_mat5_tag (is, swap, type, len, is_small_data_element)) |
20831
35241c4b696c
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20727
diff
changeset
|
788 error ("load: reading sparse matrix data for '%s'", |
35241c4b696c
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20727
diff
changeset
|
789 retval.c_str ()); |
5164 | 790 |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
791 octave_idx_type nnz = cidx[nc]; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
792 NDArray re; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
793 if (imag) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
794 { |
10350
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10349
diff
changeset
|
795 re = NDArray (dim_vector (nnz, 1)); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
796 data = re.fortran_vec (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
797 } |
5592 | 798 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
799 tmp_pos = is.tellg (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
800 read_mat5_binary_data (is, data, nnz, swap, |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
801 static_cast<enum mat5_data_type> (type), |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
802 flt_fmt); |
5164 | 803 |
20679
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20650
diff
changeset
|
804 if (! is) |
20831
35241c4b696c
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20727
diff
changeset
|
805 error ("load: reading sparse matrix data for '%s'", |
35241c4b696c
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20727
diff
changeset
|
806 retval.c_str ()); |
5164 | 807 |
16670
dddbb5dcbf6e
read Level 5 MAT files not encoded with small data element format (bug #38870)
Risto Vanhanen <risto.vanhanen@iki.fi>
parents:
16442
diff
changeset
|
808 is.seekg (tmp_pos + static_cast<std::streamoff> |
dddbb5dcbf6e
read Level 5 MAT files not encoded with small data element format (bug #38870)
Risto Vanhanen <risto.vanhanen@iki.fi>
parents:
16442
diff
changeset
|
809 (READ_PAD (is_small_data_element, len))); |
5164 | 810 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
811 // imaginary data subelement |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
812 if (imag) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
813 { |
10350
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10349
diff
changeset
|
814 NDArray im (dim_vector (static_cast<int> (nnz), 1)); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11580
diff
changeset
|
815 |
16670
dddbb5dcbf6e
read Level 5 MAT files not encoded with small data element format (bug #38870)
Risto Vanhanen <risto.vanhanen@iki.fi>
parents:
16442
diff
changeset
|
816 if (read_mat5_tag (is, swap, type, len, is_small_data_element)) |
20831
35241c4b696c
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20727
diff
changeset
|
817 error ("load: reading sparse matrix data for '%s'", |
35241c4b696c
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20727
diff
changeset
|
818 retval.c_str ()); |
5164 | 819 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
820 read_mat5_binary_data (is, im.fortran_vec (), nnz, swap, |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
821 static_cast<enum mat5_data_type> (type), |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
822 flt_fmt); |
5164 | 823 |
20679
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20650
diff
changeset
|
824 if (! is) |
20831
35241c4b696c
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20727
diff
changeset
|
825 error ("load: reading imaginary sparse matrix data for '%s'", |
35241c4b696c
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20727
diff
changeset
|
826 retval.c_str ()); |
5164 | 827 |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
828 for (octave_idx_type i = 0; i < nnz; i++) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
829 scm.xdata (i) = Complex (re (i), im (i)); |
5164 | 830 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
831 tc = scm; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
832 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
833 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
834 tc = sm; |
5164 | 835 } |
836 break; | |
4634 | 837 |
5900 | 838 case MAT_FILE_FUNCTION_CLASS: |
6625 | 839 { |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
840 octave_value tc2; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
841 std::string nm |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
842 = read_mat5_binary_element (is, filename, swap, global, tc2); |
6625 | 843 |
20679
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20650
diff
changeset
|
844 if (! is) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
845 goto data_read_error; |
6625 | 846 |
16871
5e30b1c950b8
Replace uses of Octave_map with octave_map or octave_scalar_map.
Rik <rik@octave.org>
parents:
16670
diff
changeset
|
847 // Octave can handle both "/" and "\" as a directory seperator |
5e30b1c950b8
Replace uses of Octave_map with octave_map or octave_scalar_map.
Rik <rik@octave.org>
parents:
16670
diff
changeset
|
848 // and so can ignore the separator field of m0. I think the |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
849 // sentinel field is also save to ignore. |
16871
5e30b1c950b8
Replace uses of Octave_map with octave_map or octave_scalar_map.
Rik <rik@octave.org>
parents:
16670
diff
changeset
|
850 octave_scalar_map m0 = tc2.scalar_map_value (); |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
851 octave_scalar_map m1 |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
852 = m0.contents ("function_handle").scalar_map_value (); |
16871
5e30b1c950b8
Replace uses of Octave_map with octave_map or octave_scalar_map.
Rik <rik@octave.org>
parents:
16670
diff
changeset
|
853 std::string ftype = m1.contents ("type").string_value (); |
5e30b1c950b8
Replace uses of Octave_map with octave_map or octave_scalar_map.
Rik <rik@octave.org>
parents:
16670
diff
changeset
|
854 std::string fname = m1.contents ("function").string_value (); |
5e30b1c950b8
Replace uses of Octave_map with octave_map or octave_scalar_map.
Rik <rik@octave.org>
parents:
16670
diff
changeset
|
855 std::string fpath = m1.contents ("file").string_value (); |
6625 | 856 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
857 if (ftype == "simple" || ftype == "scopedfunction") |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
858 { |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
859 if (fpath.length () == 0) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
860 // We have a builtin function |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
861 tc = make_fcn_handle (fname); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
862 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
863 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11580
diff
changeset
|
864 std::string mroot = |
16871
5e30b1c950b8
Replace uses of Octave_map with octave_map or octave_scalar_map.
Rik <rik@octave.org>
parents:
16670
diff
changeset
|
865 m0.contents ("matlabroot").string_value (); |
6625 | 866 |
19864
17d647821d61
maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
867 if ((fpath.length () >= mroot.length ()) |
17d647821d61
maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
868 && fpath.substr (0, mroot.length ()) == mroot |
17d647821d61
maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
869 && OCTAVE_EXEC_PREFIX != mroot) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
870 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
871 // If fpath starts with matlabroot, and matlabroot |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
872 // doesn't equal octave_config_info ("exec_prefix") |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
873 // then the function points to a version of Octave |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
874 // or Matlab other than the running version. In that |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
875 // case we replace with the same function in the |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
876 // running version of Octave? |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11580
diff
changeset
|
877 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
878 // First check if just replacing matlabroot is enough |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11580
diff
changeset
|
879 std::string str = OCTAVE_EXEC_PREFIX + |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
880 fpath.substr (mroot.length ()); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
881 file_stat fs (str); |
6625 | 882 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
883 if (fs.exists ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
884 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
885 size_t xpos |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
886 = str.find_last_of (file_ops::dir_sep_chars ()); |
7336 | 887 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
888 std::string dir_name = str.substr (0, xpos); |
6625 | 889 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
890 octave_function *fcn |
16676
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16442
diff
changeset
|
891 = load_fcn_from_file (str, dir_name, "", "", fname); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11580
diff
changeset
|
892 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
893 if (fcn) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
894 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
895 octave_value tmp (fcn); |
6625 | 896 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
897 tc = octave_value (new octave_fcn_handle (tmp, |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
898 fname)); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
899 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
900 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
901 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
902 { |
16871
5e30b1c950b8
Replace uses of Octave_map with octave_map or octave_scalar_map.
Rik <rik@octave.org>
parents:
16670
diff
changeset
|
903 // Next just search for it anywhere in the system path |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
904 string_vector names(3); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
905 names(0) = fname + ".oct"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
906 names(1) = fname + ".mex"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
907 names(2) = fname + ".m"; |
6625 | 908 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
909 dir_path p (load_path::system_path ()); |
6625 | 910 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
911 str = |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
912 octave_env::make_absolute (p.find_first_of (names)); |
6625 | 913 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
914 size_t xpos |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
915 = str.find_last_of (file_ops::dir_sep_chars ()); |
6625 | 916 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
917 std::string dir_name = str.substr (0, xpos); |
6625 | 918 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
919 octave_function *fcn |
16676
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16442
diff
changeset
|
920 = load_fcn_from_file (str, dir_name, "", "", fname); |
6625 | 921 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
922 if (fcn) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
923 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
924 octave_value tmp (fcn); |
6625 | 925 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
926 tc = octave_value (new octave_fcn_handle (tmp, |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
927 fname)); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
928 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
929 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
930 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11580
diff
changeset
|
931 warning ("load: can't find the file %s", |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
932 fpath.c_str ()); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
933 goto skip_ahead; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
934 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
935 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
936 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
937 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
938 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
939 size_t xpos |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
940 = fpath.find_last_of (file_ops::dir_sep_chars ()); |
6625 | 941 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
942 std::string dir_name = fpath.substr (0, xpos); |
6625 | 943 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
944 octave_function *fcn |
16676
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16442
diff
changeset
|
945 = load_fcn_from_file (fpath, dir_name, "", "", fname); |
6625 | 946 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
947 if (fcn) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
948 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
949 octave_value tmp (fcn); |
6625 | 950 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
951 tc = octave_value (new octave_fcn_handle (tmp, fname)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
952 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
953 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
954 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11580
diff
changeset
|
955 warning ("load: can't find the file %s", |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
956 fpath.c_str ()); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
957 goto skip_ahead; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
958 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
959 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
960 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
961 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
962 else if (ftype == "nested") |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
963 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
964 warning ("load: can't load nested function"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
965 goto skip_ahead; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
966 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
967 else if (ftype == "anonymous") |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
968 { |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
969 octave_scalar_map m2 |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
970 = m1.contents ("workspace").scalar_map_value (); |
16871
5e30b1c950b8
Replace uses of Octave_map with octave_map or octave_scalar_map.
Rik <rik@octave.org>
parents:
16670
diff
changeset
|
971 uint32NDArray MCOS = m2.contents ("MCOS").uint32_array_value (); |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
972 octave_idx_type off |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
973 = static_cast<octave_idx_type>(MCOS(4).double_value ()); |
16871
5e30b1c950b8
Replace uses of Octave_map with octave_map or octave_scalar_map.
Rik <rik@octave.org>
parents:
16670
diff
changeset
|
974 m2 = subsys_ov.scalar_map_value (); |
5e30b1c950b8
Replace uses of Octave_map with octave_map or octave_scalar_map.
Rik <rik@octave.org>
parents:
16670
diff
changeset
|
975 m2 = m2.contents ("MCOS").scalar_map_value (); |
5e30b1c950b8
Replace uses of Octave_map with octave_map or octave_scalar_map.
Rik <rik@octave.org>
parents:
16670
diff
changeset
|
976 tc2 = m2.contents ("MCOS").cell_value ()(1 + off).cell_value ()(1); |
5e30b1c950b8
Replace uses of Octave_map with octave_map or octave_scalar_map.
Rik <rik@octave.org>
parents:
16670
diff
changeset
|
977 m2 = tc2.scalar_map_value (); |
7336 | 978 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
979 unwind_protect_safe frame; |
9144
c6463412aebb
eliminate symbol_table::scope_stack; fix scoping issue with evalin
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
980 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
981 // Set up temporary scope to use for evaluating the text |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
982 // that defines the anonymous function. |
9144
c6463412aebb
eliminate symbol_table::scope_stack; fix scoping issue with evalin
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
983 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
984 symbol_table::scope_id local_scope = symbol_table::alloc_scope (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
985 frame.add_fcn (symbol_table::erase_scope, local_scope); |
9144
c6463412aebb
eliminate symbol_table::scope_stack; fix scoping issue with evalin
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
986 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
987 symbol_table::set_scope (local_scope); |
9144
c6463412aebb
eliminate symbol_table::scope_stack; fix scoping issue with evalin
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
988 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
989 octave_call_stack::push (local_scope, 0); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
990 frame.add_fcn (octave_call_stack::pop); |
7336 | 991 |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
992 if (m2.nfields () > 0) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
993 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
994 octave_value tmp; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11580
diff
changeset
|
995 |
16871
5e30b1c950b8
Replace uses of Octave_map with octave_map or octave_scalar_map.
Rik <rik@octave.org>
parents:
16670
diff
changeset
|
996 for (octave_map::iterator p0 = m2.begin () ; |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
997 p0 != m2.end (); p0++) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
998 { |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
999 std::string key = m2.key (p0); |
16871
5e30b1c950b8
Replace uses of Octave_map with octave_map or octave_scalar_map.
Rik <rik@octave.org>
parents:
16670
diff
changeset
|
1000 octave_value val = m2.contents (p0); |
6625 | 1001 |
16442
302157614308
deprecate symbol_table::varref functions
John W. Eaton <jwe@octave.org>
parents:
16427
diff
changeset
|
1002 symbol_table::assign (key, val, local_scope, 0); |
6625 | 1003 } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1004 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11580
diff
changeset
|
1005 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1006 int parse_status; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11580
diff
changeset
|
1007 octave_value anon_fcn_handle = |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1008 eval_string (fname.substr (4), true, parse_status); |
6625 | 1009 |
20981
c11cea70b638
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20955
diff
changeset
|
1010 if (parse_status != 0) |
20831
35241c4b696c
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20727
diff
changeset
|
1011 error ("load: failed to load anonymous function handle"); |
6625 | 1012 |
20981
c11cea70b638
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20955
diff
changeset
|
1013 octave_fcn_handle *fh = |
c11cea70b638
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20955
diff
changeset
|
1014 anon_fcn_handle.fcn_handle_value (); |
c11cea70b638
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20955
diff
changeset
|
1015 |
c11cea70b638
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20955
diff
changeset
|
1016 if (! fh) |
c11cea70b638
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20955
diff
changeset
|
1017 error ("load: failed to load anonymous function handle"); |
c11cea70b638
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20955
diff
changeset
|
1018 |
c11cea70b638
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20955
diff
changeset
|
1019 tc = new octave_fcn_handle (fh->fcn_val (), "@<anonymous>"); |
c11cea70b638
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20955
diff
changeset
|
1020 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1021 frame.run (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1022 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1023 else |
20831
35241c4b696c
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20727
diff
changeset
|
1024 error ("load: invalid function handle type"); |
6625 | 1025 } |
1026 break; | |
1027 | |
1028 case MAT_FILE_WORKSPACE_CLASS: | |
1029 { | |
16871
5e30b1c950b8
Replace uses of Octave_map with octave_map or octave_scalar_map.
Rik <rik@octave.org>
parents:
16670
diff
changeset
|
1030 octave_map m (dim_vector (1, 1)); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1031 int n_fields = 2; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1032 string_vector field (n_fields); |
6625 | 1033 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1034 for (int i = 0; i < n_fields; i++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1035 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1036 int32_t fn_type; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1037 int32_t fn_len; |
16871
5e30b1c950b8
Replace uses of Octave_map with octave_map or octave_scalar_map.
Rik <rik@octave.org>
parents:
16670
diff
changeset
|
1038 if (read_mat5_tag (is, swap, fn_type, fn_len, is_small_data_element) |
19864
17d647821d61
maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
1039 || ! INT8(fn_type)) |
20831
35241c4b696c
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20727
diff
changeset
|
1040 error ("load: invalid field name subelement"); |
6625 | 1041 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1042 OCTAVE_LOCAL_BUFFER (char, elname, fn_len + 1); |
6625 | 1043 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1044 std::streampos tmp_pos = is.tellg (); |
6625 | 1045 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1046 if (fn_len) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1047 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1048 if (! is.read (elname, fn_len)) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1049 goto data_read_error; |
6625 | 1050 |
16670
dddbb5dcbf6e
read Level 5 MAT files not encoded with small data element format (bug #38870)
Risto Vanhanen <risto.vanhanen@iki.fi>
parents:
16442
diff
changeset
|
1051 is.seekg (tmp_pos + static_cast<std::streamoff> |
dddbb5dcbf6e
read Level 5 MAT files not encoded with small data element format (bug #38870)
Risto Vanhanen <risto.vanhanen@iki.fi>
parents:
16442
diff
changeset
|
1052 (READ_PAD (is_small_data_element, fn_len))); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1053 } |
6625 | 1054 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1055 elname[fn_len] = '\0'; |
6625 | 1056 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1057 field(i) = elname; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1058 } |
6625 | 1059 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1060 std::vector<Cell> elt (n_fields); |
6625 | 1061 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1062 for (octave_idx_type i = 0; i < n_fields; i++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1063 elt[i] = Cell (dims); |
6625 | 1064 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1065 octave_idx_type n = dims.numel (); |
6625 | 1066 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1067 // fields subelements |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1068 for (octave_idx_type j = 0; j < n; j++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1069 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1070 for (octave_idx_type i = 0; i < n_fields; i++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1071 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1072 if (field(i) == "MCOS") |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1073 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1074 octave_value fieldtc; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1075 read_mat5_binary_element (is, filename, swap, global, |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11580
diff
changeset
|
1076 fieldtc); |
20679
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20650
diff
changeset
|
1077 if (! is) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1078 goto data_read_error; |
6625 | 1079 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1080 elt[i](j) = fieldtc; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1081 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1082 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1083 elt[i](j) = octave_value (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1084 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1085 } |
6625 | 1086 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1087 for (octave_idx_type i = 0; i < n_fields; i++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1088 m.assign (field (i), elt[i]); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1089 tc = m; |
6625 | 1090 } |
1091 break; | |
1092 | |
1093 case MAT_FILE_OBJECT_CLASS: | |
1094 { | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1095 isclass = true; |
6625 | 1096 |
19864
17d647821d61
maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
1097 if (read_mat5_tag (is, swap, type, len, is_small_data_element) |
17d647821d61
maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
1098 || ! INT8(type)) |
20831
35241c4b696c
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20727
diff
changeset
|
1099 error ("load: invalid class name"); |
6625 | 1100 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1101 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1102 OCTAVE_LOCAL_BUFFER (char, name, len+1); |
6625 | 1103 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1104 std::streampos tmp_pos = is.tellg (); |
6625 | 1105 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1106 if (len) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1107 { |
18678
6113e0c6920b
maint: Clean up extra spaces before/after parentheses.
Rik <rik@octave.org>
parents:
18100
diff
changeset
|
1108 if (! is.read (name, len)) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1109 goto data_read_error; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11580
diff
changeset
|
1110 |
16670
dddbb5dcbf6e
read Level 5 MAT files not encoded with small data element format (bug #38870)
Risto Vanhanen <risto.vanhanen@iki.fi>
parents:
16442
diff
changeset
|
1111 is.seekg (tmp_pos + static_cast<std::streamoff> |
dddbb5dcbf6e
read Level 5 MAT files not encoded with small data element format (bug #38870)
Risto Vanhanen <risto.vanhanen@iki.fi>
parents:
16442
diff
changeset
|
1112 (READ_PAD (is_small_data_element, len))); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1113 } |
6625 | 1114 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1115 name[len] = '\0'; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1116 classname = name; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1117 } |
6625 | 1118 } |
1119 // Fall-through | |
5900 | 1120 case MAT_FILE_STRUCT_CLASS: |
4634 | 1121 { |
16871
5e30b1c950b8
Replace uses of Octave_map with octave_map or octave_scalar_map.
Rik <rik@octave.org>
parents:
16670
diff
changeset
|
1122 octave_map m (dims); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1123 int32_t fn_type; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1124 int32_t fn_len; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1125 int32_t field_name_length; |
4634 | 1126 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1127 // field name length subelement -- actually the maximum length |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1128 // of a field name. The Matlab docs promise this will always |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1129 // be 32. We read and use the actual value, on the theory |
16871
5e30b1c950b8
Replace uses of Octave_map with octave_map or octave_scalar_map.
Rik <rik@octave.org>
parents:
16670
diff
changeset
|
1130 // that eventually someone will recognize that's a waste of space. |
5e30b1c950b8
Replace uses of Octave_map with octave_map or octave_scalar_map.
Rik <rik@octave.org>
parents:
16670
diff
changeset
|
1131 if (read_mat5_tag (is, swap, fn_type, fn_len, is_small_data_element) |
5e30b1c950b8
Replace uses of Octave_map with octave_map or octave_scalar_map.
Rik <rik@octave.org>
parents:
16670
diff
changeset
|
1132 || fn_type != miINT32) |
20831
35241c4b696c
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20727
diff
changeset
|
1133 error ("load: invalid field name length subelement"); |
4634 | 1134 |
18678
6113e0c6920b
maint: Clean up extra spaces before/after parentheses.
Rik <rik@octave.org>
parents:
18100
diff
changeset
|
1135 if (! is.read (reinterpret_cast<char *> (&field_name_length), fn_len)) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1136 goto data_read_error; |
4634 | 1137 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1138 if (swap) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1139 swap_bytes<4> (&field_name_length); |
4634 | 1140 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1141 // field name subelement. The length of this subelement tells |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1142 // us how many fields there are. |
16871
5e30b1c950b8
Replace uses of Octave_map with octave_map or octave_scalar_map.
Rik <rik@octave.org>
parents:
16670
diff
changeset
|
1143 if (read_mat5_tag (is, swap, fn_type, fn_len, is_small_data_element) |
19864
17d647821d61
maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
1144 || ! INT8(fn_type)) |
20831
35241c4b696c
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20727
diff
changeset
|
1145 error ("load: invalid field name subelement"); |
4634 | 1146 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1147 octave_idx_type n_fields = fn_len/field_name_length; |
4634 | 1148 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1149 if (n_fields > 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1150 { |
16670
dddbb5dcbf6e
read Level 5 MAT files not encoded with small data element format (bug #38870)
Risto Vanhanen <risto.vanhanen@iki.fi>
parents:
16442
diff
changeset
|
1151 fn_len = READ_PAD (is_small_data_element, fn_len); |
4634 | 1152 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1153 OCTAVE_LOCAL_BUFFER (char, elname, fn_len); |
4634 | 1154 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1155 if (! is.read (elname, fn_len)) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1156 goto data_read_error; |
4634 | 1157 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1158 std::vector<Cell> elt (n_fields); |
6292 | 1159 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1160 for (octave_idx_type i = 0; i < n_fields; i++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1161 elt[i] = Cell (dims); |
4634 | 1162 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1163 octave_idx_type n = dims.numel (); |
5336 | 1164 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1165 // fields subelements |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1166 for (octave_idx_type j = 0; j < n; j++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1167 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1168 for (octave_idx_type i = 0; i < n_fields; i++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1169 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1170 octave_value fieldtc; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1171 read_mat5_binary_element (is, filename, swap, global, |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11580
diff
changeset
|
1172 fieldtc); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1173 elt[i](j) = fieldtc; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1174 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1175 } |
4634 | 1176 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1177 for (octave_idx_type i = 0; i < n_fields; i++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1178 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1179 const char *key = elname + i*field_name_length; |
5336 | 1180 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1181 m.assign (key, elt[i]); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1182 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1183 } |
4634 | 1184 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1185 if (isclass) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1186 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1187 if (classname == "inline") |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1188 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1189 // inline is not an object in Octave but rather an |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1190 // overload of a function handle. Special case. |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11580
diff
changeset
|
1191 tc = |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
1192 new octave_fcn_inline (m.contents ("expr")(0).string_value (), |
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
1193 m.contents ("args")(0).string_value ()); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1194 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1195 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1196 { |
13874
c1b754d93572
copy parent class info when performing operations on class objects
John W. Eaton <jwe@octave.org>
parents:
12699
diff
changeset
|
1197 octave_class* cls |
c1b754d93572
copy parent class info when performing operations on class objects
John W. Eaton <jwe@octave.org>
parents:
12699
diff
changeset
|
1198 = new octave_class (m, classname, |
c1b754d93572
copy parent class info when performing operations on class objects
John W. Eaton <jwe@octave.org>
parents:
12699
diff
changeset
|
1199 std::list<std::string> ()); |
12699
c0d102ad9bba
Fix loading of objects in MAT-files (bug #32641).
David Bateman <dbateman@free.fr>
parents:
12399
diff
changeset
|
1200 |
c0d102ad9bba
Fix loading of objects in MAT-files (bug #32641).
David Bateman <dbateman@free.fr>
parents:
12399
diff
changeset
|
1201 if (cls->reconstruct_exemplar ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1202 { |
12699
c0d102ad9bba
Fix loading of objects in MAT-files (bug #32641).
David Bateman <dbateman@free.fr>
parents:
12399
diff
changeset
|
1203 |
c0d102ad9bba
Fix loading of objects in MAT-files (bug #32641).
David Bateman <dbateman@free.fr>
parents:
12399
diff
changeset
|
1204 if (! cls->reconstruct_parents ()) |
c0d102ad9bba
Fix loading of objects in MAT-files (bug #32641).
David Bateman <dbateman@free.fr>
parents:
12399
diff
changeset
|
1205 warning ("load: unable to reconstruct object inheritance"); |
c0d102ad9bba
Fix loading of objects in MAT-files (bug #32641).
David Bateman <dbateman@free.fr>
parents:
12399
diff
changeset
|
1206 |
c0d102ad9bba
Fix loading of objects in MAT-files (bug #32641).
David Bateman <dbateman@free.fr>
parents:
12399
diff
changeset
|
1207 tc = cls; |
19866
726df008104d
maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents:
19864
diff
changeset
|
1208 if (load_path::find_method (classname, "loadobj") |
21017
93748bcaec17
maint: Replace emtpy 'std::string ()' calls with "".
Rik <rik@octave.org>
parents:
20981
diff
changeset
|
1209 != "") |
12699
c0d102ad9bba
Fix loading of objects in MAT-files (bug #32641).
David Bateman <dbateman@free.fr>
parents:
12399
diff
changeset
|
1210 { |
20679
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20650
diff
changeset
|
1211 try |
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20650
diff
changeset
|
1212 { |
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20650
diff
changeset
|
1213 octave_value_list tmp = feval ("loadobj", tc, 1); |
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20650
diff
changeset
|
1214 |
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20650
diff
changeset
|
1215 tc = tmp(0); |
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20650
diff
changeset
|
1216 } |
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20650
diff
changeset
|
1217 catch (const octave_execution_exception&) |
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20650
diff
changeset
|
1218 { |
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20650
diff
changeset
|
1219 goto data_read_error; |
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20650
diff
changeset
|
1220 } |
12699
c0d102ad9bba
Fix loading of objects in MAT-files (bug #32641).
David Bateman <dbateman@free.fr>
parents:
12399
diff
changeset
|
1221 } |
c0d102ad9bba
Fix loading of objects in MAT-files (bug #32641).
David Bateman <dbateman@free.fr>
parents:
12399
diff
changeset
|
1222 } |
c0d102ad9bba
Fix loading of objects in MAT-files (bug #32641).
David Bateman <dbateman@free.fr>
parents:
12399
diff
changeset
|
1223 else |
c0d102ad9bba
Fix loading of objects in MAT-files (bug #32641).
David Bateman <dbateman@free.fr>
parents:
12399
diff
changeset
|
1224 { |
c0d102ad9bba
Fix loading of objects in MAT-files (bug #32641).
David Bateman <dbateman@free.fr>
parents:
12399
diff
changeset
|
1225 tc = m; |
c0d102ad9bba
Fix loading of objects in MAT-files (bug #32641).
David Bateman <dbateman@free.fr>
parents:
12399
diff
changeset
|
1226 warning ("load: element has been converted to a structure"); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1227 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1228 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1229 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1230 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1231 tc = m; |
4634 | 1232 } |
1233 break; | |
1234 | |
5900 | 1235 case MAT_FILE_INT8_CLASS: |
5089 | 1236 OCTAVE_MAT5_INTEGER_READ (int8NDArray); |
1237 break; | |
1238 | |
5900 | 1239 case MAT_FILE_UINT8_CLASS: |
5269 | 1240 { |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1241 OCTAVE_MAT5_INTEGER_READ (uint8NDArray); |
5269 | 1242 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1243 // Logical variables can either be MAT_FILE_UINT8_CLASS or |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1244 // MAT_FILE_DOUBLE_CLASS, so check if we have a logical |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1245 // variable and convert it. |
5269 | 1246 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1247 if (logicalvar) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1248 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1249 uint8NDArray in = tc.uint8_array_value (); |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1250 octave_idx_type nel = in.numel (); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1251 boolNDArray out (dims); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11580
diff
changeset
|
1252 |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1253 for (octave_idx_type i = 0; i < nel; i++) |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
1254 out(i) = in(i).bool_value (); |
5269 | 1255 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1256 tc = out; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1257 } |
5269 | 1258 } |
5089 | 1259 break; |
1260 | |
5900 | 1261 case MAT_FILE_INT16_CLASS: |
5089 | 1262 OCTAVE_MAT5_INTEGER_READ (int16NDArray); |
1263 break; | |
1264 | |
5900 | 1265 case MAT_FILE_UINT16_CLASS: |
5089 | 1266 OCTAVE_MAT5_INTEGER_READ (uint16NDArray); |
1267 break; | |
1268 | |
5900 | 1269 case MAT_FILE_INT32_CLASS: |
5089 | 1270 OCTAVE_MAT5_INTEGER_READ (int32NDArray); |
1271 break; | |
1272 | |
5900 | 1273 case MAT_FILE_UINT32_CLASS: |
5089 | 1274 OCTAVE_MAT5_INTEGER_READ (uint32NDArray); |
1275 break; | |
1276 | |
5900 | 1277 case MAT_FILE_INT64_CLASS: |
5089 | 1278 OCTAVE_MAT5_INTEGER_READ (int64NDArray); |
1279 break; | |
1280 | |
5900 | 1281 case MAT_FILE_UINT64_CLASS: |
5089 | 1282 OCTAVE_MAT5_INTEGER_READ (uint64NDArray); |
1283 break; | |
1284 | |
10909
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1285 |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1286 case MAT_FILE_SINGLE_CLASS: |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1287 { |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1288 FloatNDArray re (dims); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11580
diff
changeset
|
1289 |
10909
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1290 // real data subelement |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1291 |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1292 std::streampos tmp_pos; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11580
diff
changeset
|
1293 |
16670
dddbb5dcbf6e
read Level 5 MAT files not encoded with small data element format (bug #38870)
Risto Vanhanen <risto.vanhanen@iki.fi>
parents:
16442
diff
changeset
|
1294 if (read_mat5_tag (is, swap, type, len, is_small_data_element)) |
20831
35241c4b696c
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20727
diff
changeset
|
1295 error ("load: reading matrix data for '%s'", retval.c_str ()); |
10909
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1296 |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1297 octave_idx_type n = re.numel (); |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1298 tmp_pos = is.tellg (); |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1299 read_mat5_binary_data (is, re.fortran_vec (), n, swap, |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1300 static_cast<enum mat5_data_type> (type), |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1301 flt_fmt); |
10909
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1302 |
20679
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20650
diff
changeset
|
1303 if (! is) |
20831
35241c4b696c
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20727
diff
changeset
|
1304 error ("load: reading matrix data for '%s'", retval.c_str ()); |
10909
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1305 |
16670
dddbb5dcbf6e
read Level 5 MAT files not encoded with small data element format (bug #38870)
Risto Vanhanen <risto.vanhanen@iki.fi>
parents:
16442
diff
changeset
|
1306 is.seekg (tmp_pos + static_cast<std::streamoff> |
dddbb5dcbf6e
read Level 5 MAT files not encoded with small data element format (bug #38870)
Risto Vanhanen <risto.vanhanen@iki.fi>
parents:
16442
diff
changeset
|
1307 (READ_PAD (is_small_data_element, len))); |
10909
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1308 |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1309 if (imag) |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1310 { |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1311 // imaginary data subelement |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1312 |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1313 FloatNDArray im (dims); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11580
diff
changeset
|
1314 |
16670
dddbb5dcbf6e
read Level 5 MAT files not encoded with small data element format (bug #38870)
Risto Vanhanen <risto.vanhanen@iki.fi>
parents:
16442
diff
changeset
|
1315 if (read_mat5_tag (is, swap, type, len, is_small_data_element)) |
20831
35241c4b696c
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20727
diff
changeset
|
1316 error ("load: reading matrix data for '%s'", retval.c_str ()); |
10909
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1317 |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1318 n = im.numel (); |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1319 read_mat5_binary_data (is, im.fortran_vec (), n, swap, |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1320 static_cast<enum mat5_data_type> (type), |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1321 flt_fmt); |
10909
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1322 |
20679
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20650
diff
changeset
|
1323 if (! is) |
20831
35241c4b696c
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20727
diff
changeset
|
1324 error ("load: reading imaginary matrix data for '%s'", |
35241c4b696c
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20727
diff
changeset
|
1325 retval.c_str ()); |
10909
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1326 |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1327 FloatComplexNDArray ctmp (dims); |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1328 |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1329 for (octave_idx_type i = 0; i < n; i++) |
11419
a4822f3d1032
Fix for saving of single precision arrays to the matlab file format
David Bateman <dbateman@free.fr>
parents:
10909
diff
changeset
|
1330 ctmp(i) = FloatComplex (re(i), im(i)); |
10909
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1331 |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1332 tc = ctmp; |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1333 } |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1334 else |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1335 tc = re; |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1336 } |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1337 break; |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1338 |
5900 | 1339 case MAT_FILE_CHAR_CLASS: |
4634 | 1340 // handle as a numerical array to start with |
1341 | |
5900 | 1342 case MAT_FILE_DOUBLE_CLASS: |
4634 | 1343 default: |
5089 | 1344 { |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1345 NDArray re (dims); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11580
diff
changeset
|
1346 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1347 // real data subelement |
5089 | 1348 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1349 std::streampos tmp_pos; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11580
diff
changeset
|
1350 |
16670
dddbb5dcbf6e
read Level 5 MAT files not encoded with small data element format (bug #38870)
Risto Vanhanen <risto.vanhanen@iki.fi>
parents:
16442
diff
changeset
|
1351 if (read_mat5_tag (is, swap, type, len, is_small_data_element)) |
20831
35241c4b696c
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20727
diff
changeset
|
1352 error ("load: reading matrix data for '%s'", retval.c_str ()); |
4634 | 1353 |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1354 octave_idx_type n = re.numel (); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1355 tmp_pos = is.tellg (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1356 read_mat5_binary_data (is, re.fortran_vec (), n, swap, |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1357 static_cast<enum mat5_data_type> (type), |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1358 flt_fmt); |
4634 | 1359 |
20679
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20650
diff
changeset
|
1360 if (! is) |
20831
35241c4b696c
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20727
diff
changeset
|
1361 error ("load: reading matrix data for '%s'", retval.c_str ()); |
4634 | 1362 |
16670
dddbb5dcbf6e
read Level 5 MAT files not encoded with small data element format (bug #38870)
Risto Vanhanen <risto.vanhanen@iki.fi>
parents:
16442
diff
changeset
|
1363 is.seekg (tmp_pos + static_cast<std::streamoff> |
dddbb5dcbf6e
read Level 5 MAT files not encoded with small data element format (bug #38870)
Risto Vanhanen <risto.vanhanen@iki.fi>
parents:
16442
diff
changeset
|
1364 (READ_PAD (is_small_data_element, len))); |
5089 | 1365 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1366 if (logicalvar) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1367 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1368 // Logical variables can either be MAT_FILE_UINT8_CLASS or |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1369 // MAT_FILE_DOUBLE_CLASS, so check if we have a logical |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1370 // variable and convert it. |
5269 | 1371 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1372 boolNDArray out (dims); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11580
diff
changeset
|
1373 |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1374 for (octave_idx_type i = 0; i < n; i++) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1375 out (i) = static_cast<bool> (re (i)); |
5269 | 1376 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1377 tc = out; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1378 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1379 else if (imag) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1380 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1381 // imaginary data subelement |
5269 | 1382 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1383 NDArray im (dims); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11580
diff
changeset
|
1384 |
16670
dddbb5dcbf6e
read Level 5 MAT files not encoded with small data element format (bug #38870)
Risto Vanhanen <risto.vanhanen@iki.fi>
parents:
16442
diff
changeset
|
1385 if (read_mat5_tag (is, swap, type, len, is_small_data_element)) |
20831
35241c4b696c
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20727
diff
changeset
|
1386 error ("load: reading matrix data for '%s'", retval.c_str ()); |
4634 | 1387 |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1388 n = im.numel (); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1389 read_mat5_binary_data (is, im.fortran_vec (), n, swap, |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1390 static_cast<enum mat5_data_type> (type), |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1391 flt_fmt); |
4634 | 1392 |
20679
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20650
diff
changeset
|
1393 if (! is) |
20831
35241c4b696c
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20727
diff
changeset
|
1394 error ("load: reading imaginary matrix data for '%s'", |
35241c4b696c
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20727
diff
changeset
|
1395 retval.c_str ()); |
4634 | 1396 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1397 ComplexNDArray ctmp (dims); |
4634 | 1398 |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1399 for (octave_idx_type i = 0; i < n; i++) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1400 ctmp(i) = Complex (re(i), im(i)); |
4634 | 1401 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1402 tc = ctmp; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1403 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1404 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1405 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1406 if (arrayclass == MAT_FILE_CHAR_CLASS) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1407 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1408 if (type == miUTF16 || type == miUTF32) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1409 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1410 bool found_big_char = false; |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1411 for (octave_idx_type i = 0; i < n; i++) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1412 { |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1413 if (re(i) > 127) |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1414 { |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1415 re(i) = '?'; |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1416 found_big_char = true; |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1417 } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1418 } |
6954 | 1419 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1420 if (found_big_char) |
11590
4ced6b90fffb
style fixes for warning and error messages in source files
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
1421 warning ("load: can not read non-ASCII portions of UTF characters; replacing unreadable characters with '?'"); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1422 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1423 else if (type == miUTF8) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1424 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1425 // Search for multi-byte encoded UTF8 characters and |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1426 // replace with 0x3F for '?'... Give the user a warning |
4634 | 1427 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1428 bool utf8_multi_byte = false; |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1429 for (octave_idx_type i = 0; i < n; i++) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1430 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1431 unsigned char a = static_cast<unsigned char> (re(i)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1432 if (a > 0x7f) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1433 utf8_multi_byte = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1434 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11580
diff
changeset
|
1435 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1436 if (utf8_multi_byte) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1437 { |
11590
4ced6b90fffb
style fixes for warning and error messages in source files
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
1438 warning ("load: can not read multi-byte encoded UTF8 characters; replacing unreadable characters with '?'"); |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1439 for (octave_idx_type i = 0; i < n; i++) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1440 { |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1441 unsigned char a |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1442 = static_cast<unsigned char> (re(i)); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1443 if (a > 0x7f) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1444 re(i) = '?'; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1445 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1446 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1447 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1448 tc = re; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1449 tc = tc.convert_to_str (false, true, '\''); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1450 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1451 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1452 tc = re; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1453 } |
5089 | 1454 } |
4634 | 1455 } |
1456 | |
1457 is.seekg (pos + static_cast<std::streamoff> (element_length)); | |
1458 | |
1459 if (is.eof ()) | |
1460 is.clear (); | |
1461 | |
1462 return retval; | |
1463 | |
20893
384ff5aa9437
2015 Code Sprint: Eliminate useless return statements after error ().
Rik <rik@octave.org>
parents:
20831
diff
changeset
|
1464 // FIXME: With short-circuiting error(), no need for goto in code |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1465 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
|
1466 error ("load: trouble reading binary file '%s'", filename.c_str ()); |
4634 | 1467 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1468 skip_ahead: |
20727
a5949b3d2332
Preface warning() messages with name of function when possible.
Rik <rik@octave.org>
parents:
20679
diff
changeset
|
1469 warning ("load: skipping over '%s'", retval.c_str ()); |
4634 | 1470 is.seekg (pos + static_cast<std::streamoff> (element_length)); |
1471 return read_mat5_binary_element (is, filename, swap, global, tc); | |
1472 } | |
1473 | |
1474 int | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11580
diff
changeset
|
1475 read_mat5_binary_file_header (std::istream& is, bool& swap, bool quiet, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1476 const std::string& filename) |
4634 | 1477 { |
18100
6a71e5030df5
Follow coding convention of defining and initializing only 1 variable per line in liboctinterp.
Rik <rik@octave.org>
parents:
18019
diff
changeset
|
1478 int16_t version = 0; |
6a71e5030df5
Follow coding convention of defining and initializing only 1 variable per line in liboctinterp.
Rik <rik@octave.org>
parents:
18019
diff
changeset
|
1479 int16_t magic = 0; |
6625 | 1480 uint64_t subsys_offset; |
1481 | |
1482 is.seekg (116, std::ios::beg); | |
1483 is.read (reinterpret_cast<char *> (&subsys_offset), 8); | |
4634 | 1484 |
1485 is.seekg (124, std::ios::beg); | |
5760 | 1486 is.read (reinterpret_cast<char *> (&version), 2); |
1487 is.read (reinterpret_cast<char *> (&magic), 2); | |
4634 | 1488 |
1489 if (magic == 0x4d49) | |
1490 swap = 0; | |
1491 else if (magic == 0x494d) | |
1492 swap = 1; | |
1493 else | |
1494 { | |
1495 if (! quiet) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1496 error ("load: can't read binary file"); |
21055
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21017
diff
changeset
|
1497 |
4634 | 1498 return -1; |
1499 } | |
1500 | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1501 if (! swap) // version number is inverse swapped! |
4634 | 1502 version = ((version >> 8) & 0xff) + ((version & 0xff) << 8); |
1503 | |
20955
77f5591878bf
maint: Use '! expr' rather than '!expr' to conform to coding guidelines.
Rik <rik@octave.org>
parents:
20945
diff
changeset
|
1504 if (version != 1 && ! quiet) |
4634 | 1505 warning ("load: found version %d binary MAT file, " |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1506 "but only prepared for version 1", version); |
4634 | 1507 |
6625 | 1508 if (swap) |
1509 swap_bytes<8> (&subsys_offset, 1); | |
1510 | |
1511 if (subsys_offset != 0x2020202020202020ULL && subsys_offset != 0ULL) | |
1512 { | |
1513 // Read the subsystem data block | |
1514 is.seekg (subsys_offset, std::ios::beg); | |
1515 | |
1516 octave_value tc; | |
1517 bool global; | |
1518 read_mat5_binary_element (is, filename, swap, global, tc); | |
1519 | |
20679
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20650
diff
changeset
|
1520 if (! is) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1521 return -1; |
6625 | 1522 |
1523 if (tc.is_uint8_type ()) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1524 { |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
1525 const uint8NDArray itmp = tc.uint8_array_value (); |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1526 octave_idx_type ilen = itmp.numel (); |
6625 | 1527 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1528 // Why should I have to initialize outbuf as just overwrite |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1529 std::string outbuf (ilen - 7, ' '); |
6625 | 1530 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1531 // FIXME: find a way to avoid casting away const here |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1532 char *ctmp = const_cast<char *> (outbuf.c_str ()); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1533 for (octave_idx_type j = 8; j < ilen; j++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1534 ctmp[j-8] = itmp(j).char_value (); |
6625 | 1535 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1536 std::istringstream fh_ws (outbuf); |
6625 | 1537 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1538 read_mat5_binary_element (fh_ws, filename, swap, global, subsys_ov); |
6625 | 1539 |
20679
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20650
diff
changeset
|
1540 if (! is) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1541 return -1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1542 } |
6625 | 1543 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1544 return -1; |
6625 | 1545 |
1546 // Reposition to just after the header | |
1547 is.seekg (128, std::ios::beg); | |
1548 } | |
1549 | |
4634 | 1550 return 0; |
1551 } | |
1552 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11580
diff
changeset
|
1553 static int |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1554 write_mat5_tag (std::ostream& is, int type, octave_idx_type bytes) |
4634 | 1555 { |
5828 | 1556 int32_t temp; |
4634 | 1557 |
6292 | 1558 if (bytes > 0 && bytes <= 4) |
4634 | 1559 temp = (bytes << 16) + type; |
1560 else | |
1561 { | |
1562 temp = type; | |
5760 | 1563 if (! is.write (reinterpret_cast<char *> (&temp), 4)) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1564 goto data_write_error; |
4634 | 1565 temp = bytes; |
1566 } | |
1567 | |
5760 | 1568 if (! is.write (reinterpret_cast<char *> (&temp), 4)) |
4634 | 1569 goto data_write_error; |
1570 | |
1571 return 0; | |
1572 | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1573 data_write_error: |
4634 | 1574 return 1; |
1575 } | |
1576 | |
1577 // Have to use copy here to avoid writing over data accessed via | |
1578 // Matrix::data(). | |
1579 | |
5760 | 1580 #define MAT5_DO_WRITE(TYPE, data, count, stream) \ |
1581 do \ | |
1582 { \ | |
1583 OCTAVE_LOCAL_BUFFER (TYPE, ptr, count); \ | |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1584 for (octave_idx_type i = 0; i < count; i++) \ |
5760 | 1585 ptr[i] = static_cast<TYPE> (data[i]); \ |
18691
9a6646cc7c3e
Fix load/save to handle up to 2^32-1 elements.
Rik <rik@octave.org>
parents:
18678
diff
changeset
|
1586 std::streamsize n_bytes = sizeof (TYPE) * static_cast<std::streamsize> (count); \ |
9a6646cc7c3e
Fix load/save to handle up to 2^32-1 elements.
Rik <rik@octave.org>
parents:
18678
diff
changeset
|
1587 stream.write (reinterpret_cast<char *> (ptr), n_bytes); \ |
5760 | 1588 } \ |
4634 | 1589 while (0) |
1590 | |
10909
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1591 // write out the numeric values in M to OS, |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1592 // preceded by the appropriate tag. |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11580
diff
changeset
|
1593 static void |
10909
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1594 write_mat5_array (std::ostream& os, const NDArray& m, bool save_as_floats) |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1595 { |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1596 save_type st = LS_DOUBLE; |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1597 const double *data = m.data (); |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1598 |
4634 | 1599 if (save_as_floats) |
1600 { | |
1601 if (m.too_large_for_float ()) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1602 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1603 warning ("save: some values too large to save as floats --"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1604 warning ("save: saving as doubles instead"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1605 } |
4634 | 1606 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1607 st = LS_FLOAT; |
4634 | 1608 } |
1609 | |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1610 double max_val, min_val; |
4634 | 1611 if (m.all_integers (max_val, min_val)) |
1612 st = get_save_type (max_val, min_val); | |
1613 | |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1614 mat5_data_type mst; |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1615 int size; |
4634 | 1616 switch (st) |
1617 { | |
1618 default: | |
1619 case LS_DOUBLE: mst = miDOUBLE; size = 8; break; | |
1620 case LS_FLOAT: mst = miSINGLE; size = 4; break; | |
1621 case LS_U_CHAR: mst = miUINT8; size = 1; break; | |
1622 case LS_U_SHORT: mst = miUINT16; size = 2; break; | |
1623 case LS_U_INT: mst = miUINT32; size = 4; break; | |
1624 case LS_CHAR: mst = miINT8; size = 1; break; | |
1625 case LS_SHORT: mst = miINT16; size = 2; break; | |
1626 case LS_INT: mst = miINT32; size = 4; break; | |
1627 } | |
1628 | |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1629 octave_idx_type nel = m.numel (); |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1630 octave_idx_type len = nel*size; |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1631 |
4634 | 1632 write_mat5_tag (os, mst, len); |
1633 | |
1634 { | |
1635 switch (st) | |
1636 { | |
1637 case LS_U_CHAR: | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1638 MAT5_DO_WRITE (uint8_t, data, nel, os); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1639 break; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11580
diff
changeset
|
1640 |
4634 | 1641 case LS_U_SHORT: |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1642 MAT5_DO_WRITE (uint16_t, data, nel, os); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1643 break; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11580
diff
changeset
|
1644 |
4634 | 1645 case LS_U_INT: |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1646 MAT5_DO_WRITE (uint32_t, data, nel, os); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1647 break; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11580
diff
changeset
|
1648 |
4634 | 1649 case LS_U_LONG: |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1650 MAT5_DO_WRITE (uint64_t, data, nel, os); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1651 break; |
4634 | 1652 |
1653 case LS_CHAR: | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1654 MAT5_DO_WRITE (int8_t, data, nel, os); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1655 break; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11580
diff
changeset
|
1656 |
4634 | 1657 case LS_SHORT: |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1658 MAT5_DO_WRITE (int16_t, data, nel, os); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1659 break; |
4634 | 1660 |
1661 case LS_INT: | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1662 MAT5_DO_WRITE (int32_t, data, nel, os); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1663 break; |
4634 | 1664 |
1665 case LS_LONG: | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1666 MAT5_DO_WRITE (int64_t, data, nel, os); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1667 break; |
4634 | 1668 |
1669 case LS_FLOAT: | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1670 MAT5_DO_WRITE (float, data, nel, os); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1671 break; |
4634 | 1672 |
1673 case LS_DOUBLE: // No conversion necessary. | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1674 os.write (reinterpret_cast<const char *> (data), len); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1675 break; |
4634 | 1676 |
1677 default: | |
20650
a6a452346c42
use error and error_with_id directly in libinterp code
John W. Eaton <jwe@octave.org>
parents:
19866
diff
changeset
|
1678 error ("unrecognized data format requested"); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1679 break; |
4634 | 1680 } |
1681 } | |
1682 if (PAD (len) > len) | |
1683 { | |
1684 static char buf[9]="\x00\x00\x00\x00\x00\x00\x00\x00"; | |
1685 os.write (buf, PAD (len) - len); | |
1686 } | |
1687 } | |
1688 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11580
diff
changeset
|
1689 static void |
10909
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1690 write_mat5_array (std::ostream& os, const FloatNDArray& m, bool) |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1691 { |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1692 save_type st = LS_FLOAT; |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1693 const float *data = m.data (); |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1694 |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1695 float max_val, min_val; |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1696 if (m.all_integers (max_val, min_val)) |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1697 st = get_save_type (max_val, min_val); |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1698 |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1699 mat5_data_type mst; |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1700 int size; |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1701 switch (st) |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1702 { |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1703 default: |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1704 case LS_DOUBLE: mst = miDOUBLE; size = 8; break; |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1705 case LS_FLOAT: mst = miSINGLE; size = 4; break; |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1706 case LS_U_CHAR: mst = miUINT8; size = 1; break; |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1707 case LS_U_SHORT: mst = miUINT16; size = 2; break; |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1708 case LS_U_INT: mst = miUINT32; size = 4; break; |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1709 case LS_CHAR: mst = miINT8; size = 1; break; |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1710 case LS_SHORT: mst = miINT16; size = 2; break; |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1711 case LS_INT: mst = miINT32; size = 4; break; |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1712 } |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1713 |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1714 octave_idx_type nel = m.numel (); |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1715 octave_idx_type len = nel*size; |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1716 |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1717 write_mat5_tag (os, mst, len); |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1718 |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1719 { |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1720 switch (st) |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1721 { |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1722 case LS_U_CHAR: |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1723 MAT5_DO_WRITE (uint8_t, data, nel, os); |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1724 break; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11580
diff
changeset
|
1725 |
10909
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1726 case LS_U_SHORT: |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1727 MAT5_DO_WRITE (uint16_t, data, nel, os); |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1728 break; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11580
diff
changeset
|
1729 |
10909
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1730 case LS_U_INT: |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1731 MAT5_DO_WRITE (uint32_t, data, nel, os); |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1732 break; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11580
diff
changeset
|
1733 |
10909
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1734 case LS_U_LONG: |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1735 MAT5_DO_WRITE (uint64_t, data, nel, os); |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1736 break; |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1737 |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1738 case LS_CHAR: |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1739 MAT5_DO_WRITE (int8_t, data, nel, os); |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1740 break; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11580
diff
changeset
|
1741 |
10909
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1742 case LS_SHORT: |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1743 MAT5_DO_WRITE (int16_t, data, nel, os); |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1744 break; |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1745 |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1746 case LS_INT: |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1747 MAT5_DO_WRITE (int32_t, data, nel, os); |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1748 break; |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1749 |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1750 case LS_LONG: |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1751 MAT5_DO_WRITE (int64_t, data, nel, os); |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1752 break; |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1753 |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1754 case LS_FLOAT: // No conversion necessary. |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1755 os.write (reinterpret_cast<const char *> (data), len); |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1756 break; |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1757 |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1758 case LS_DOUBLE: |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1759 MAT5_DO_WRITE (double, data, nel, os); |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1760 break; |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1761 |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1762 default: |
20650
a6a452346c42
use error and error_with_id directly in libinterp code
John W. Eaton <jwe@octave.org>
parents:
19866
diff
changeset
|
1763 error ("unrecognized data format requested"); |
10909
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1764 break; |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1765 } |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1766 } |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1767 if (PAD (len) > len) |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1768 { |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1769 static char buf[9]="\x00\x00\x00\x00\x00\x00\x00\x00"; |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1770 os.write (buf, PAD (len) - len); |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1771 } |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1772 } |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1773 |
5089 | 1774 template <class T> |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11580
diff
changeset
|
1775 void |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1776 write_mat5_integer_data (std::ostream& os, const T *m, int size, |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1777 octave_idx_type nel) |
5089 | 1778 { |
1779 mat5_data_type mst; | |
1780 unsigned len; | |
1781 | |
1782 switch (size) | |
1783 { | |
1784 case 1: | |
1785 mst = miUINT8; | |
1786 break; | |
1787 case 2: | |
1788 mst = miUINT16; | |
1789 break; | |
5164 | 1790 case 4: |
5089 | 1791 mst = miUINT32; |
1792 break; | |
5164 | 1793 case 8: |
5089 | 1794 mst = miUINT64; |
1795 break; | |
1796 case -1: | |
1797 mst = miINT8; | |
1798 size = - size; | |
1799 break; | |
1800 case -2: | |
1801 mst = miINT16; | |
1802 size = - size; | |
1803 break; | |
5164 | 1804 case -4: |
5089 | 1805 mst = miINT32; |
1806 size = - size; | |
1807 break; | |
5164 | 1808 case -8: |
5089 | 1809 default: |
1810 mst = miINT64; | |
1811 size = - size; | |
1812 break; | |
1813 } | |
1814 | |
1815 len = nel*size; | |
1816 write_mat5_tag (os, mst, len); | |
1817 | |
5760 | 1818 os.write (reinterpret_cast<const char *> (m), len); |
5089 | 1819 |
1820 if (PAD (len) > len) | |
1821 { | |
1822 static char buf[9]="\x00\x00\x00\x00\x00\x00\x00\x00"; | |
1823 os.write (buf, PAD (len) - len); | |
1824 } | |
1825 } | |
1826 | |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1827 template void |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1828 write_mat5_integer_data (std::ostream& os, const octave_int8 *m, |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1829 int size, octave_idx_type nel); |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1830 |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1831 template void |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1832 write_mat5_integer_data (std::ostream& os, const octave_int16 *m, |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1833 int size, octave_idx_type nel); |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1834 |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1835 template void |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1836 write_mat5_integer_data (std::ostream& os, const octave_int32 *m, |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1837 int size, octave_idx_type nel); |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1838 |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1839 template void |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1840 write_mat5_integer_data (std::ostream& os, const octave_int64 *m, |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1841 int size, octave_idx_type nel); |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1842 |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1843 template void |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1844 write_mat5_integer_data (std::ostream& os, const octave_uint8 *m, |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1845 int size, octave_idx_type nel); |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1846 |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1847 template void |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1848 write_mat5_integer_data (std::ostream& os, const octave_uint16 *m, |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1849 int size, octave_idx_type nel); |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1850 |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1851 template void |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1852 write_mat5_integer_data (std::ostream& os, const octave_uint32 *m, |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1853 int size, octave_idx_type nel); |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1854 |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1855 template void |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1856 write_mat5_integer_data (std::ostream& os, const octave_uint64 *m, |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1857 int size, octave_idx_type nel); |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1858 |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1859 template void |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11580
diff
changeset
|
1860 write_mat5_integer_data (std::ostream& os, const int *m, |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1861 int size, octave_idx_type nel); |
5089 | 1862 |
4634 | 1863 // Write out cell element values in the cell array to OS, preceded by |
1864 // the appropriate tag. | |
1865 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11580
diff
changeset
|
1866 static bool |
4701 | 1867 write_mat5_cell_array (std::ostream& os, const Cell& cell, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1868 bool mark_as_global, bool save_as_floats) |
4634 | 1869 { |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1870 octave_idx_type nel = cell.numel (); |
4634 | 1871 |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1872 for (octave_idx_type i = 0; i < nel; i++) |
4634 | 1873 { |
1874 octave_value ov = cell(i); | |
1875 | |
1876 if (! save_mat5_binary_element (os, ov, "", mark_as_global, | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1877 false, save_as_floats)) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1878 return false; |
4634 | 1879 } |
1880 | |
1881 return true; | |
1882 } | |
1883 | |
5269 | 1884 int |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1885 save_mat5_array_length (const double* val, octave_idx_type nel, |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1886 bool save_as_floats) |
5269 | 1887 { |
1888 if (nel > 0) | |
1889 { | |
1890 int size = 8; | |
1891 | |
1892 if (save_as_floats) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1893 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1894 bool too_large_for_float = false; |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1895 for (octave_idx_type i = 0; i < nel; i++) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1896 { |
15020
560317fd5977
maint: Cuddle open bracket used for indexing C++ arrays in source code.
Rik <rik@octave.org>
parents:
14861
diff
changeset
|
1897 double tmp = val[i]; |
5269 | 1898 |
16971
259c1f295a1e
Use xfinite to replace some (isinf || isnan) instances in C++ code.
Rik <rik@octave.org>
parents:
16892
diff
changeset
|
1899 if (xfinite (tmp) |
15213
336f42406671
use numeric_limits functions instead of DBL_MIN, DBL_MAX, etc.
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1900 && fabs (tmp) > std::numeric_limits<float>::max ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1901 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1902 too_large_for_float = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1903 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1904 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1905 } |
5269 | 1906 |
20955
77f5591878bf
maint: Use '! expr' rather than '!expr' to conform to coding guidelines.
Rik <rik@octave.org>
parents:
20945
diff
changeset
|
1907 if (! too_large_for_float) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1908 size = 4; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1909 } |
5269 | 1910 |
1911 // The code below is disabled since get_save_type currently doesn't | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1912 // deal with integer types. This will need to be activated if |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1913 // get_save_type is changed. |
5269 | 1914 |
1915 // double max_val = val[0]; | |
1916 // double min_val = val[0]; | |
1917 // bool all_integers = true; | |
1918 // | |
1919 // for (int i = 0; i < nel; i++) | |
1920 // { | |
1921 // double val = val[i]; | |
1922 // | |
1923 // if (val > max_val) | |
1924 // max_val = val; | |
1925 // | |
1926 // if (val < min_val) | |
1927 // min_val = val; | |
1928 // | |
1929 // if (D_NINT (val) != val) | |
1930 // { | |
1931 // all_integers = false; | |
1932 // break; | |
1933 // } | |
1934 // } | |
1935 // | |
1936 // if (all_integers) | |
1937 // { | |
1938 // if (max_val < 256 && min_val > -1) | |
1939 // size = 1; | |
1940 // else if (max_val < 65536 && min_val > -1) | |
1941 // size = 2; | |
1942 // else if (max_val < 4294967295UL && min_val > -1) | |
1943 // size = 4; | |
1944 // else if (max_val < 128 && min_val >= -128) | |
1945 // size = 1; | |
1946 // else if (max_val < 32768 && min_val >= -32768) | |
1947 // size = 2; | |
1948 // else if (max_val <= 2147483647L && min_val >= -2147483647L) | |
1949 // size = 4; | |
1950 // } | |
1951 | |
1952 return 8 + nel * size; | |
1953 } | |
1954 else | |
1955 return 8; | |
1956 } | |
1957 | |
1958 int | |
11419
a4822f3d1032
Fix for saving of single precision arrays to the matlab file format
David Bateman <dbateman@free.fr>
parents:
10909
diff
changeset
|
1959 save_mat5_array_length (const float* /* val */, octave_idx_type nel, bool) |
10909
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1960 { |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1961 if (nel > 0) |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1962 { |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1963 int size = 4; |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1964 |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1965 |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1966 // The code below is disabled since get_save_type currently doesn't |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1967 // deal with integer types. This will need to be activated if |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1968 // get_save_type is changed. |
10909
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1969 |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1970 // float max_val = val[0]; |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1971 // float min_val = val[0]; |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1972 // bool all_integers = true; |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1973 // |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1974 // for (int i = 0; i < nel; i++) |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1975 // { |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1976 // float val = val[i]; |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1977 // |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1978 // if (val > max_val) |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1979 // max_val = val; |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1980 // |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1981 // if (val < min_val) |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1982 // min_val = val; |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1983 // |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1984 // if (D_NINT (val) != val) |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1985 // { |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1986 // all_integers = false; |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1987 // break; |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1988 // } |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1989 // } |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1990 // |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1991 // if (all_integers) |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1992 // { |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1993 // if (max_val < 256 && min_val > -1) |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1994 // size = 1; |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1995 // else if (max_val < 65536 && min_val > -1) |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1996 // size = 2; |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1997 // else if (max_val < 4294967295UL && min_val > -1) |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1998 // size = 4; |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1999 // else if (max_val < 128 && min_val >= -128) |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
2000 // size = 1; |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
2001 // else if (max_val < 32768 && min_val >= -32768) |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
2002 // size = 2; |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
2003 // else if (max_val <= 2147483647L && min_val >= -2147483647L) |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
2004 // size = 4; |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
2005 // } |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
2006 |
11468
e1edf0ba3bcb
Yet another single precision matlab file fix
David Bateman <dbateman@free.fr>
parents:
11419
diff
changeset
|
2007 // Round nel up to nearest even number of elements. Take into account |
e1edf0ba3bcb
Yet another single precision matlab file fix
David Bateman <dbateman@free.fr>
parents:
11419
diff
changeset
|
2008 // Short tags for 4 byte elements. |
e1edf0ba3bcb
Yet another single precision matlab file fix
David Bateman <dbateman@free.fr>
parents:
11419
diff
changeset
|
2009 return PAD ((nel > 0 && nel * size <= 4 ? 4 : 8) + nel * size); |
10909
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
2010 } |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
2011 else |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
2012 return 8; |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
2013 } |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
2014 |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
2015 int |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2016 save_mat5_array_length (const Complex* val, octave_idx_type nel, |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2017 bool save_as_floats) |
5269 | 2018 { |
2019 int ret; | |
2020 | |
2021 OCTAVE_LOCAL_BUFFER (double, tmp, nel); | |
2022 | |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2023 for (octave_idx_type i = 1; i < nel; i++) |
5269 | 2024 tmp[i] = std::real (val[i]); |
2025 | |
2026 ret = save_mat5_array_length (tmp, nel, save_as_floats); | |
2027 | |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2028 for (octave_idx_type i = 1; i < nel; i++) |
5269 | 2029 tmp[i] = std::imag (val[i]); |
2030 | |
2031 ret += save_mat5_array_length (tmp, nel, save_as_floats); | |
2032 | |
2033 return ret; | |
2034 } | |
2035 | |
2036 int | |
10909
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
2037 save_mat5_array_length (const FloatComplex* val, octave_idx_type nel, |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
2038 bool save_as_floats) |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
2039 { |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
2040 int ret; |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
2041 |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
2042 OCTAVE_LOCAL_BUFFER (float, tmp, nel); |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
2043 |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
2044 for (octave_idx_type i = 1; i < nel; i++) |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
2045 tmp[i] = std::real (val[i]); |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
2046 |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
2047 ret = save_mat5_array_length (tmp, nel, save_as_floats); |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
2048 |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
2049 for (octave_idx_type i = 1; i < nel; i++) |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
2050 tmp[i] = std::imag (val[i]); |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
2051 |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
2052 ret += save_mat5_array_length (tmp, nel, save_as_floats); |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
2053 |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
2054 return ret; |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
2055 } |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
2056 |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
2057 int |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11580
diff
changeset
|
2058 save_mat5_element_length (const octave_value& tc, const std::string& name, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2059 bool save_as_floats, bool mat7_format) |
5269 | 2060 { |
16303
085976d9ef08
Fix saving names >31 characters to -v6 format (bug #34676)
Rik <rik@octave.org>
parents:
16226
diff
changeset
|
2061 size_t max_namelen = 63; |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2062 size_t len = name.length (); |
5269 | 2063 std::string cname = tc.class_name (); |
2064 int ret = 32; | |
2065 | |
2066 if (len > 4) | |
2067 ret += PAD (len > max_namelen ? max_namelen : len); | |
2068 | |
2069 ret += PAD (4 * tc.ndims ()); | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11580
diff
changeset
|
2070 |
5269 | 2071 if (tc.is_string ()) |
2072 { | |
5933 | 2073 charNDArray chm = tc.char_array_value (); |
5384 | 2074 ret += 8; |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2075 if (chm.numel () > 2) |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2076 ret += PAD (2 * chm.numel ()); |
5269 | 2077 } |
6823 | 2078 else if (tc.is_sparse_type ()) |
5269 | 2079 { |
2080 if (tc.is_complex_type ()) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2081 { |
11468
e1edf0ba3bcb
Yet another single precision matlab file fix
David Bateman <dbateman@free.fr>
parents:
11419
diff
changeset
|
2082 const SparseComplexMatrix m = tc.sparse_complex_matrix_value (); |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2083 octave_idx_type nc = m.cols (); |
11517
da8e32c99969
Fix for savving of sparse matrices to matlab files when nnz is not equal to nzmax
David Bateman <dbateman@free.fr>
parents:
11468
diff
changeset
|
2084 octave_idx_type nnz = m.nnz (); |
5269 | 2085 |
10623
0e98fb2068fc
Fix error when saving sparse arrays to matlab files (bug #29786)
David Bateman <dbateman@free.fr>
parents:
10350
diff
changeset
|
2086 ret += 16 + save_mat5_array_length (m.data (), nnz, save_as_floats); |
0e98fb2068fc
Fix error when saving sparse arrays to matlab files (bug #29786)
David Bateman <dbateman@free.fr>
parents:
10350
diff
changeset
|
2087 if (nnz > 1) |
0e98fb2068fc
Fix error when saving sparse arrays to matlab files (bug #29786)
David Bateman <dbateman@free.fr>
parents:
10350
diff
changeset
|
2088 ret += PAD (nnz * sizeof (int32_t)); |
10624
3eafa521550b
minor typo in previous changeset
David Bateman <dbateman@free.fr>
parents:
10623
diff
changeset
|
2089 if (nc > 0) |
10623
0e98fb2068fc
Fix error when saving sparse arrays to matlab files (bug #29786)
David Bateman <dbateman@free.fr>
parents:
10350
diff
changeset
|
2090 ret += PAD ((nc + 1) * sizeof (int32_t)); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2091 } |
5269 | 2092 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2093 { |
11468
e1edf0ba3bcb
Yet another single precision matlab file fix
David Bateman <dbateman@free.fr>
parents:
11419
diff
changeset
|
2094 const SparseMatrix m = tc.sparse_matrix_value (); |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2095 octave_idx_type nc = m.cols (); |
11517
da8e32c99969
Fix for savving of sparse matrices to matlab files when nnz is not equal to nzmax
David Bateman <dbateman@free.fr>
parents:
11468
diff
changeset
|
2096 octave_idx_type nnz = m.nnz (); |
5269 | 2097 |
10623
0e98fb2068fc
Fix error when saving sparse arrays to matlab files (bug #29786)
David Bateman <dbateman@free.fr>
parents:
10350
diff
changeset
|
2098 ret += 16 + save_mat5_array_length (m.data (), nnz, save_as_floats); |
0e98fb2068fc
Fix error when saving sparse arrays to matlab files (bug #29786)
David Bateman <dbateman@free.fr>
parents:
10350
diff
changeset
|
2099 if (nnz > 1) |
0e98fb2068fc
Fix error when saving sparse arrays to matlab files (bug #29786)
David Bateman <dbateman@free.fr>
parents:
10350
diff
changeset
|
2100 ret += PAD (nnz * sizeof (int32_t)); |
10624
3eafa521550b
minor typo in previous changeset
David Bateman <dbateman@free.fr>
parents:
10623
diff
changeset
|
2101 if (nc > 0) |
10623
0e98fb2068fc
Fix error when saving sparse arrays to matlab files (bug #29786)
David Bateman <dbateman@free.fr>
parents:
10350
diff
changeset
|
2102 ret += PAD ((nc + 1) * sizeof (int32_t)); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2103 } |
5269 | 2104 } |
2105 | |
2106 #define INT_LEN(nel, size) \ | |
2107 { \ | |
2108 ret += 8; \ | |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2109 octave_idx_type sz = nel * size; \ |
5269 | 2110 if (sz > 4) \ |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2111 ret += PAD (sz); \ |
5269 | 2112 } |
2113 | |
2114 else if (cname == "int8") | |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2115 INT_LEN (tc.int8_array_value ().numel (), 1) |
5269 | 2116 else if (cname == "int16") |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2117 INT_LEN (tc.int16_array_value ().numel (), 2) |
5269 | 2118 else if (cname == "int32") |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2119 INT_LEN (tc.int32_array_value ().numel (), 4) |
5269 | 2120 else if (cname == "int64") |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2121 INT_LEN (tc.int64_array_value ().numel (), 8) |
5269 | 2122 else if (cname == "uint8") |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2123 INT_LEN (tc.uint8_array_value ().numel (), 1) |
5269 | 2124 else if (cname == "uint16") |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2125 INT_LEN (tc.uint16_array_value ().numel (), 2) |
5269 | 2126 else if (cname == "uint32") |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2127 INT_LEN (tc.uint32_array_value ().numel (), 4) |
5269 | 2128 else if (cname == "uint64") |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2129 INT_LEN (tc.uint64_array_value ().numel (), 8) |
5269 | 2130 else if (tc.is_bool_type ()) |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2131 INT_LEN (tc.bool_array_value ().numel (), 1) |
5269 | 2132 else if (tc.is_real_scalar () || tc.is_real_matrix () || tc.is_range ()) |
2133 { | |
10909
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
2134 if (tc.is_single_type ()) |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
2135 { |
11468
e1edf0ba3bcb
Yet another single precision matlab file fix
David Bateman <dbateman@free.fr>
parents:
11419
diff
changeset
|
2136 const FloatNDArray m = tc.float_array_value (); |
10909
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
2137 ret += save_mat5_array_length (m.fortran_vec (), m.numel (), |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
2138 save_as_floats); |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
2139 } |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
2140 else |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
2141 { |
11468
e1edf0ba3bcb
Yet another single precision matlab file fix
David Bateman <dbateman@free.fr>
parents:
11419
diff
changeset
|
2142 const NDArray m = tc.array_value (); |
10909
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
2143 ret += save_mat5_array_length (m.fortran_vec (), m.numel (), |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
2144 save_as_floats); |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
2145 } |
5269 | 2146 } |
2147 else if (tc.is_cell ()) | |
2148 { | |
2149 Cell cell = tc.cell_value (); | |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2150 octave_idx_type nel = cell.numel (); |
5269 | 2151 |
2152 for (int i = 0; i < nel; i++) | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11580
diff
changeset
|
2153 ret += 8 + |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2154 save_mat5_element_length (cell (i), "", save_as_floats, mat7_format); |
5269 | 2155 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11580
diff
changeset
|
2156 else if (tc.is_complex_scalar () || tc.is_complex_matrix ()) |
5269 | 2157 { |
10909
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
2158 if (tc.is_single_type ()) |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
2159 { |
11468
e1edf0ba3bcb
Yet another single precision matlab file fix
David Bateman <dbateman@free.fr>
parents:
11419
diff
changeset
|
2160 const FloatComplexNDArray m = tc.float_complex_array_value (); |
10909
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
2161 ret += save_mat5_array_length (m.fortran_vec (), m.numel (), |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
2162 save_as_floats); |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
2163 } |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
2164 else |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11580
diff
changeset
|
2165 { |
11468
e1edf0ba3bcb
Yet another single precision matlab file fix
David Bateman <dbateman@free.fr>
parents:
11419
diff
changeset
|
2166 const ComplexNDArray m = tc.complex_array_value (); |
10909
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
2167 ret += save_mat5_array_length (m.fortran_vec (), m.numel (), |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
2168 save_as_floats); |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
2169 } |
5269 | 2170 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11580
diff
changeset
|
2171 else if (tc.is_map () || tc.is_inline_function () || tc.is_object ()) |
5269 | 2172 { |
2173 int fieldcnt = 0; | |
16871
5e30b1c950b8
Replace uses of Octave_map with octave_map or octave_scalar_map.
Rik <rik@octave.org>
parents:
16670
diff
changeset
|
2174 const octave_map m = tc.map_value (); |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2175 octave_idx_type nel = m.numel (); |
5269 | 2176 |
6625 | 2177 if (tc.is_inline_function ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2178 // length of "inline" is 6 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2179 ret += 8 + PAD (6 > max_namelen ? max_namelen : 6); |
8212
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8007
diff
changeset
|
2180 else if (tc.is_object ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2181 { |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2182 size_t classlen = tc.class_name (). length (); |
8212
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8007
diff
changeset
|
2183 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2184 ret += 8 + PAD (classlen > max_namelen ? max_namelen : classlen); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2185 } |
6625 | 2186 |
16871
5e30b1c950b8
Replace uses of Octave_map with octave_map or octave_scalar_map.
Rik <rik@octave.org>
parents:
16670
diff
changeset
|
2187 for (octave_map::const_iterator i = m.begin (); i != m.end (); i++) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2188 fieldcnt++; |
5269 | 2189 |
2190 ret += 16 + fieldcnt * (max_namelen + 1); | |
2191 | |
2192 | |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2193 for (octave_idx_type j = 0; j < nel; j++) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2194 { |
5269 | 2195 |
16871
5e30b1c950b8
Replace uses of Octave_map with octave_map or octave_scalar_map.
Rik <rik@octave.org>
parents:
16670
diff
changeset
|
2196 for (octave_map::const_iterator i = m.begin (); i != m.end (); i++) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2197 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2198 const Cell elts = m.contents (i); |
5269 | 2199 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11580
diff
changeset
|
2200 ret += 8 + save_mat5_element_length (elts(j), "", |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2201 save_as_floats, mat7_format); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2202 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2203 } |
5269 | 2204 } |
2205 else | |
2206 ret = -1; | |
2207 | |
2208 return ret; | |
2209 } | |
2210 | |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2211 static void |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2212 write_mat5_sparse_index_vector (std::ostream& os, |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2213 const octave_idx_type *idx, |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2214 octave_idx_type nel) |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2215 { |
10623
0e98fb2068fc
Fix error when saving sparse arrays to matlab files (bug #29786)
David Bateman <dbateman@free.fr>
parents:
10350
diff
changeset
|
2216 int tmp = sizeof (int32_t); |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2217 |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2218 OCTAVE_LOCAL_BUFFER (int32_t, tmp_idx, nel); |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2219 |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2220 for (octave_idx_type i = 0; i < nel; i++) |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2221 tmp_idx[i] = idx[i]; |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2222 |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2223 write_mat5_integer_data (os, tmp_idx, -tmp, nel); |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2224 } |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2225 |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2226 static void |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2227 gripe_dim_too_large (const std::string& name) |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2228 { |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2229 warning ("save: skipping %s: dimension too large for MAT format", |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2230 name.c_str ()); |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2231 } |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2232 |
4634 | 2233 // save the data from TC along with the corresponding NAME on stream |
2234 // OS in the MatLab version 5 binary format. Return true on success. | |
2235 | |
2236 bool | |
2237 save_mat5_binary_element (std::ostream& os, | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2238 const octave_value& tc, const std::string& name, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2239 bool mark_as_global, bool mat7_format, |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11580
diff
changeset
|
2240 bool save_as_floats, bool compressing) |
4634 | 2241 { |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2242 int32_t flags = 0; |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2243 int32_t nnz_32 = 0; |
5089 | 2244 std::string cname = tc.class_name (); |
16303
085976d9ef08
Fix saving names >31 characters to -v6 format (bug #34676)
Rik <rik@octave.org>
parents:
16226
diff
changeset
|
2245 size_t max_namelen = 63; |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2246 |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2247 dim_vector dv = tc.dims (); |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2248 int nd = tc.ndims (); |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2249 int dim_len = 4*nd; |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2250 |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2251 static octave_idx_type max_dim_val = std::numeric_limits<int32_t>::max (); |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2252 |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2253 for (int i = 0; i < nd; i++) |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2254 { |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2255 if (dv(i) > max_dim_val) |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2256 { |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2257 gripe_dim_too_large (name); |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2258 goto skip_to_next; |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2259 } |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2260 } |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2261 |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2262 if (tc.is_sparse_type ()) |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2263 { |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2264 octave_idx_type nnz; |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2265 octave_idx_type nc; |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2266 |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2267 if (tc.is_complex_type ()) |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2268 { |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2269 SparseComplexMatrix scm = tc.sparse_complex_matrix_value (); |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2270 nnz = scm.nzmax (); |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2271 nc = scm.cols (); |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2272 } |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2273 else |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2274 { |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2275 SparseMatrix sm = tc.sparse_matrix_value (); |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2276 nnz = sm.nzmax (); |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2277 nc = sm.cols (); |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2278 } |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2279 |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2280 if (nnz > max_dim_val || nc + 1 > max_dim_val) |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2281 { |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2282 gripe_dim_too_large (name); |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2283 goto skip_to_next; |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2284 } |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2285 |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2286 nnz_32 = nnz; |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2287 } |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2288 else if (dv.numel () > max_dim_val) |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2289 { |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2290 gripe_dim_too_large (name); |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2291 goto skip_to_next; |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2292 } |
5269 | 2293 |
2294 #ifdef HAVE_ZLIB | |
20955
77f5591878bf
maint: Use '! expr' rather than '!expr' to conform to coding guidelines.
Rik <rik@octave.org>
parents:
20945
diff
changeset
|
2295 if (mat7_format && ! compressing) |
5269 | 2296 { |
2297 bool ret = false; | |
2298 | |
5765 | 2299 std::ostringstream buf; |
5269 | 2300 |
2301 // The code seeks backwards in the stream to fix the header. Can't | |
2302 // do this with zlib, so use a stringstream. | |
2303 ret = save_mat5_binary_element (buf, tc, name, mark_as_global, true, | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2304 save_as_floats, true); |
5269 | 2305 |
2306 if (ret) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2307 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11580
diff
changeset
|
2308 // destLen must be at least 0.1% larger than source buffer |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2309 // + 12 bytes. Reality is it must be larger again than that. |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2310 std::string buf_str = buf.str (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2311 uLongf srcLen = buf_str.length (); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11580
diff
changeset
|
2312 uLongf destLen = srcLen * 101 / 100 + 12; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2313 OCTAVE_LOCAL_BUFFER (char, out_buf, destLen); |
5269 | 2314 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11580
diff
changeset
|
2315 if (compress (reinterpret_cast<Bytef *> (out_buf), &destLen, |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2316 reinterpret_cast<const Bytef *> (buf_str.c_str ()), |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2317 srcLen) |
20981
c11cea70b638
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20955
diff
changeset
|
2318 != Z_OK) |
20831
35241c4b696c
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20727
diff
changeset
|
2319 error ("save: error compressing data element"); |
20981
c11cea70b638
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20955
diff
changeset
|
2320 |
c11cea70b638
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20955
diff
changeset
|
2321 write_mat5_tag (os, miCOMPRESSED, |
c11cea70b638
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20955
diff
changeset
|
2322 static_cast<octave_idx_type> (destLen)); |
c11cea70b638
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20955
diff
changeset
|
2323 |
c11cea70b638
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20955
diff
changeset
|
2324 os.write (out_buf, destLen); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2325 } |
5269 | 2326 |
2327 return ret; | |
2328 } | |
2329 #endif | |
4634 | 2330 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11580
diff
changeset
|
2331 write_mat5_tag (os, miMATRIX, save_mat5_element_length |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2332 (tc, name, save_as_floats, mat7_format)); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11580
diff
changeset
|
2333 |
4634 | 2334 // array flags subelement |
2335 write_mat5_tag (os, miUINT32, 8); | |
2336 | |
5269 | 2337 if (tc.is_bool_type ()) |
2338 flags |= 0x0200; | |
2339 | |
4634 | 2340 if (mark_as_global) |
2341 flags |= 0x0400; | |
2342 | |
2343 if (tc.is_complex_scalar () || tc.is_complex_matrix ()) | |
2344 flags |= 0x0800; | |
2345 | |
2346 if (tc.is_string ()) | |
5900 | 2347 flags |= MAT_FILE_CHAR_CLASS; |
5089 | 2348 else if (cname == "int8") |
5900 | 2349 flags |= MAT_FILE_INT8_CLASS; |
5089 | 2350 else if (cname == "int16") |
5900 | 2351 flags |= MAT_FILE_INT16_CLASS; |
5089 | 2352 else if (cname == "int32") |
5900 | 2353 flags |= MAT_FILE_INT32_CLASS; |
5089 | 2354 else if (cname == "int64") |
5900 | 2355 flags |= MAT_FILE_INT64_CLASS; |
5269 | 2356 else if (cname == "uint8" || tc.is_bool_type ()) |
5900 | 2357 flags |= MAT_FILE_UINT8_CLASS; |
5089 | 2358 else if (cname == "uint16") |
5900 | 2359 flags |= MAT_FILE_UINT16_CLASS; |
5089 | 2360 else if (cname == "uint32") |
5900 | 2361 flags |= MAT_FILE_UINT32_CLASS; |
5089 | 2362 else if (cname == "uint64") |
5900 | 2363 flags |= MAT_FILE_UINT64_CLASS; |
6823 | 2364 else if (tc.is_sparse_type ()) |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2365 flags |= MAT_FILE_SPARSE_CLASS; |
10909
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
2366 else if (tc.is_real_scalar () || tc.is_real_matrix () || tc.is_range () |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
2367 || tc.is_complex_scalar () || tc.is_complex_matrix ()) |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
2368 { |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
2369 if (tc.is_single_type ()) |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
2370 flags |= MAT_FILE_SINGLE_CLASS; |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
2371 else |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
2372 flags |= MAT_FILE_DOUBLE_CLASS; |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
2373 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11580
diff
changeset
|
2374 else if (tc.is_map ()) |
5900 | 2375 flags |= MAT_FILE_STRUCT_CLASS; |
4634 | 2376 else if (tc.is_cell ()) |
5900 | 2377 flags |= MAT_FILE_CELL_CLASS; |
8212
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8007
diff
changeset
|
2378 else if (tc.is_inline_function () || tc.is_object ()) |
6625 | 2379 flags |= MAT_FILE_OBJECT_CLASS; |
4634 | 2380 else |
2381 { | |
2382 gripe_wrong_type_arg ("save", tc, false); | |
2383 goto error_cleanup; | |
2384 } | |
2385 | |
5760 | 2386 os.write (reinterpret_cast<char *> (&flags), 4); |
15347
9ed4fc294f3f
when writing sparse matrices to MAT files, use nzmax of at least 1 (bug #36603)
John W. Eaton <jwe@octave.org>
parents:
15213
diff
changeset
|
2387 // Matlab seems to have trouble reading files that have nzmax == 0 at |
9ed4fc294f3f
when writing sparse matrices to MAT files, use nzmax of at least 1 (bug #36603)
John W. Eaton <jwe@octave.org>
parents:
15213
diff
changeset
|
2388 // this point in the file. |
9ed4fc294f3f
when writing sparse matrices to MAT files, use nzmax of at least 1 (bug #36603)
John W. Eaton <jwe@octave.org>
parents:
15213
diff
changeset
|
2389 if (nnz_32 == 0) |
9ed4fc294f3f
when writing sparse matrices to MAT files, use nzmax of at least 1 (bug #36603)
John W. Eaton <jwe@octave.org>
parents:
15213
diff
changeset
|
2390 nnz_32 = 1; |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2391 os.write (reinterpret_cast<char *> (&nnz_32), 4); |
4634 | 2392 |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2393 write_mat5_tag (os, miINT32, dim_len); |
4634 | 2394 |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2395 for (int i = 0; i < nd; i++) |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2396 { |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2397 int32_t n = dv(i); |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2398 os.write (reinterpret_cast<char *> (&n), 4); |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2399 } |
4638 | 2400 |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2401 if (PAD (dim_len) > dim_len) |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2402 { |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2403 static char buf[9]="\x00\x00\x00\x00\x00\x00\x00\x00"; |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2404 os.write (buf, PAD (dim_len) - dim_len); |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2405 } |
4634 | 2406 |
2407 // array name subelement | |
2408 { | |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2409 size_t namelen = name.length (); |
4634 | 2410 |
5269 | 2411 if (namelen > max_namelen) |
16303
085976d9ef08
Fix saving names >31 characters to -v6 format (bug #34676)
Rik <rik@octave.org>
parents:
16226
diff
changeset
|
2412 namelen = max_namelen; // Truncate names if necessary |
4634 | 2413 |
2414 int paddedlength = PAD (namelen); | |
2415 | |
2416 write_mat5_tag (os, miINT8, namelen); | |
2417 OCTAVE_LOCAL_BUFFER (char, paddedname, paddedlength); | |
2418 memset (paddedname, 0, paddedlength); | |
2419 strncpy (paddedname, name.c_str (), namelen); | |
2420 os.write (paddedname, paddedlength); | |
2421 } | |
2422 | |
2423 // data element | |
2424 if (tc.is_string ()) | |
2425 { | |
5933 | 2426 charNDArray chm = tc.char_array_value (); |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2427 octave_idx_type nel = chm.numel (); |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2428 octave_idx_type len = nel*2; |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2429 octave_idx_type paddedlength = PAD (len); |
4634 | 2430 |
5933 | 2431 OCTAVE_LOCAL_BUFFER (int16_t, buf, nel+3); |
4634 | 2432 write_mat5_tag (os, miUINT16, len); |
2433 | |
5933 | 2434 const char *s = chm.data (); |
4634 | 2435 |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2436 for (octave_idx_type i = 0; i < nel; i++) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2437 buf[i] = *s++ & 0x00FF; |
5933 | 2438 |
2439 os.write (reinterpret_cast<char *> (buf), len); | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11580
diff
changeset
|
2440 |
4634 | 2441 if (paddedlength > len) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2442 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2443 static char padbuf[9]="\x00\x00\x00\x00\x00\x00\x00\x00"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2444 os.write (padbuf, paddedlength - len); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2445 } |
4634 | 2446 } |
6823 | 2447 else if (tc.is_sparse_type ()) |
5164 | 2448 { |
2449 if (tc.is_complex_type ()) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2450 { |
11517
da8e32c99969
Fix for savving of sparse matrices to matlab files when nnz is not equal to nzmax
David Bateman <dbateman@free.fr>
parents:
11468
diff
changeset
|
2451 const SparseComplexMatrix m = tc.sparse_complex_matrix_value (); |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2452 octave_idx_type nnz = m.nnz (); |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2453 octave_idx_type nc = m.cols (); |
5164 | 2454 |
11517
da8e32c99969
Fix for savving of sparse matrices to matlab files when nnz is not equal to nzmax
David Bateman <dbateman@free.fr>
parents:
11468
diff
changeset
|
2455 write_mat5_sparse_index_vector (os, m.ridx (), nnz); |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2456 write_mat5_sparse_index_vector (os, m.cidx (), nc + 1); |
5164 | 2457 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2458 NDArray buf (dim_vector (nnz, 1)); |
5164 | 2459 |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2460 for (octave_idx_type i = 0; i < nnz; i++) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2461 buf (i) = std::real (m.data (i)); |
5164 | 2462 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2463 write_mat5_array (os, buf, save_as_floats); |
5164 | 2464 |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2465 for (octave_idx_type i = 0; i < nnz; i++) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2466 buf (i) = std::imag (m.data (i)); |
5164 | 2467 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2468 write_mat5_array (os, buf, save_as_floats); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2469 } |
5164 | 2470 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2471 { |
11517
da8e32c99969
Fix for savving of sparse matrices to matlab files when nnz is not equal to nzmax
David Bateman <dbateman@free.fr>
parents:
11468
diff
changeset
|
2472 const SparseMatrix m = tc.sparse_matrix_value (); |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2473 octave_idx_type nnz = m.nnz (); |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2474 octave_idx_type nc = m.cols (); |
5164 | 2475 |
11517
da8e32c99969
Fix for savving of sparse matrices to matlab files when nnz is not equal to nzmax
David Bateman <dbateman@free.fr>
parents:
11468
diff
changeset
|
2476 write_mat5_sparse_index_vector (os, m.ridx (), nnz); |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2477 write_mat5_sparse_index_vector (os, m.cidx (), nc + 1); |
5164 | 2478 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2479 // FIXME |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2480 // Is there a way to easily do without this buffer |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2481 NDArray buf (dim_vector (nnz, 1)); |
5164 | 2482 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2483 for (int i = 0; i < nnz; i++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2484 buf (i) = m.data (i); |
5164 | 2485 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2486 write_mat5_array (os, buf, save_as_floats); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2487 } |
5164 | 2488 } |
5089 | 2489 else if (cname == "int8") |
2490 { | |
2491 int8NDArray m = tc.int8_array_value (); | |
2492 | |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2493 write_mat5_integer_data (os, m.fortran_vec (), -1, m.numel ()); |
5089 | 2494 } |
2495 else if (cname == "int16") | |
2496 { | |
2497 int16NDArray m = tc.int16_array_value (); | |
2498 | |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2499 write_mat5_integer_data (os, m.fortran_vec (), -2, m.numel ()); |
5089 | 2500 } |
2501 else if (cname == "int32") | |
2502 { | |
2503 int32NDArray m = tc.int32_array_value (); | |
2504 | |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2505 write_mat5_integer_data (os, m.fortran_vec (), -4, m.numel ()); |
5089 | 2506 } |
2507 else if (cname == "int64") | |
2508 { | |
2509 int64NDArray m = tc.int64_array_value (); | |
2510 | |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2511 write_mat5_integer_data (os, m.fortran_vec (), -8, m.numel ()); |
5089 | 2512 } |
2513 else if (cname == "uint8") | |
2514 { | |
2515 uint8NDArray m = tc.uint8_array_value (); | |
2516 | |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2517 write_mat5_integer_data (os, m.fortran_vec (), 1, m.numel ()); |
5089 | 2518 } |
2519 else if (cname == "uint16") | |
2520 { | |
2521 uint16NDArray m = tc.uint16_array_value (); | |
2522 | |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2523 write_mat5_integer_data (os, m.fortran_vec (), 2, m.numel ()); |
5089 | 2524 } |
2525 else if (cname == "uint32") | |
2526 { | |
2527 uint32NDArray m = tc.uint32_array_value (); | |
2528 | |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2529 write_mat5_integer_data (os, m.fortran_vec (), 4, m.numel ()); |
5089 | 2530 } |
2531 else if (cname == "uint64") | |
2532 { | |
2533 uint64NDArray m = tc.uint64_array_value (); | |
2534 | |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2535 write_mat5_integer_data (os, m.fortran_vec (), 8, m.numel ()); |
5089 | 2536 } |
5269 | 2537 else if (tc.is_bool_type ()) |
2538 { | |
2539 uint8NDArray m (tc.bool_array_value ()); | |
2540 | |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2541 write_mat5_integer_data (os, m.fortran_vec (), 1, m.numel ()); |
5269 | 2542 } |
4634 | 2543 else if (tc.is_real_scalar () || tc.is_real_matrix () || tc.is_range ()) |
2544 { | |
10909
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
2545 if (tc.is_single_type ()) |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
2546 { |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
2547 FloatNDArray m = tc.float_array_value (); |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
2548 |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
2549 write_mat5_array (os, m, save_as_floats); |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
2550 } |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
2551 else |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
2552 { |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
2553 NDArray m = tc.array_value (); |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
2554 |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
2555 write_mat5_array (os, m, save_as_floats); |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
2556 } |
4634 | 2557 } |
2558 else if (tc.is_cell ()) | |
2559 { | |
2560 Cell cell = tc.cell_value (); | |
2561 | |
2562 if (! write_mat5_cell_array (os, cell, mark_as_global, save_as_floats)) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2563 goto error_cleanup; |
4634 | 2564 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11580
diff
changeset
|
2565 else if (tc.is_complex_scalar () || tc.is_complex_matrix ()) |
4634 | 2566 { |
10909
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
2567 if (tc.is_single_type ()) |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
2568 { |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
2569 FloatComplexNDArray m_cmplx = tc.float_complex_array_value (); |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
2570 |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
2571 write_mat5_array (os, ::real (m_cmplx), save_as_floats); |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
2572 write_mat5_array (os, ::imag (m_cmplx), save_as_floats); |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
2573 } |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
2574 else |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
2575 { |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
2576 ComplexNDArray m_cmplx = tc.complex_array_value (); |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
2577 |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
2578 write_mat5_array (os, ::real (m_cmplx), save_as_floats); |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
2579 write_mat5_array (os, ::imag (m_cmplx), save_as_floats); |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
2580 } |
4634 | 2581 } |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
2582 else if (tc.is_map () || tc.is_inline_function () || tc.is_object ()) |
4634 | 2583 { |
8212
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8007
diff
changeset
|
2584 if (tc.is_inline_function () || tc.is_object ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2585 { |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
2586 std::string classname = tc.is_object () ? tc.class_name () : "inline"; |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2587 size_t namelen = classname.length (); |
6625 | 2588 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2589 if (namelen > max_namelen) |
16303
085976d9ef08
Fix saving names >31 characters to -v6 format (bug #34676)
Rik <rik@octave.org>
parents:
16226
diff
changeset
|
2590 namelen = max_namelen; // Truncate names if necessary |
6625 | 2591 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2592 int paddedlength = PAD (namelen); |
6625 | 2593 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2594 write_mat5_tag (os, miINT8, namelen); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2595 OCTAVE_LOCAL_BUFFER (char, paddedname, paddedlength); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2596 memset (paddedname, 0, paddedlength); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2597 strncpy (paddedname, classname.c_str (), namelen); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2598 os.write (paddedname, paddedlength); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2599 } |
6625 | 2600 |
16871
5e30b1c950b8
Replace uses of Octave_map with octave_map or octave_scalar_map.
Rik <rik@octave.org>
parents:
16670
diff
changeset
|
2601 octave_map m; |
8212
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8007
diff
changeset
|
2602 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2603 if (tc.is_object () |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2604 && load_path::find_method (tc.class_name (), |
21017
93748bcaec17
maint: Replace emtpy 'std::string ()' calls with "".
Rik <rik@octave.org>
parents:
20981
diff
changeset
|
2605 "saveobj") != "") |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2606 { |
20679
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20650
diff
changeset
|
2607 try |
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20650
diff
changeset
|
2608 { |
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20650
diff
changeset
|
2609 octave_value_list tmp = feval ("saveobj", tc, 1); |
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20650
diff
changeset
|
2610 |
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20650
diff
changeset
|
2611 m = tmp(0).map_value (); |
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20650
diff
changeset
|
2612 } |
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20650
diff
changeset
|
2613 catch (const octave_execution_exception&) |
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20650
diff
changeset
|
2614 { |
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20650
diff
changeset
|
2615 goto error_cleanup; |
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20650
diff
changeset
|
2616 } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2617 } |
8212
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8007
diff
changeset
|
2618 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2619 m = tc.map_value (); |
8212
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8007
diff
changeset
|
2620 |
4634 | 2621 // an Octave structure */ |
2622 // recursively write each element of the structure | |
2623 { | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2624 char buf[64]; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2625 int32_t maxfieldnamelength = max_namelen + 1; |
4634 | 2626 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2627 octave_idx_type nf = m.nfields (); |
8907
5a956c026b6c
preserve field order when saving structs
John W. Eaton <jwe@octave.org>
parents:
8377
diff
changeset
|
2628 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2629 write_mat5_tag (os, miINT32, 4); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2630 os.write (reinterpret_cast<char *> (&maxfieldnamelength), 4); |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2631 write_mat5_tag (os, miINT8, nf*maxfieldnamelength); |
4634 | 2632 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2633 // Iterating over the list of keys will preserve the order of |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2634 // the fields. |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2635 string_vector keys = m.keys (); |
8907
5a956c026b6c
preserve field order when saving structs
John W. Eaton <jwe@octave.org>
parents:
8377
diff
changeset
|
2636 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2637 for (octave_idx_type i = 0; i < nf; i++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2638 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2639 std::string key = keys(i); |
8907
5a956c026b6c
preserve field order when saving structs
John W. Eaton <jwe@octave.org>
parents:
8377
diff
changeset
|
2640 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2641 // write the name of each element |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2642 memset (buf, 0, max_namelen + 1); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2643 // only 31 or 63 char names permitted |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2644 strncpy (buf, key.c_str (), max_namelen); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2645 os.write (buf, max_namelen + 1); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2646 } |
4634 | 2647 |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2648 octave_idx_type len = m.numel (); |
4634 | 2649 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2650 // Create temporary copy of structure contents to avoid |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2651 // multiple calls of the contents method. |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2652 std::vector<const octave_value *> elts (nf); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2653 for (octave_idx_type i = 0; i < nf; i++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2654 elts[i] = m.contents (keys(i)).data (); |
9203
a542fc158175
improve performance of saving large structs in MAT file format
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
2655 |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2656 for (octave_idx_type j = 0; j < len; j++) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2657 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2658 // write the data of each element |
4634 | 2659 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2660 // Iterating over the list of keys will preserve the order |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2661 // of the fields. |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2662 for (octave_idx_type i = 0; i < nf; i++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2663 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2664 bool retval2 = save_mat5_binary_element (os, elts[i][j], "", |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2665 mark_as_global, |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11580
diff
changeset
|
2666 false, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2667 save_as_floats); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2668 if (! retval2) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2669 goto error_cleanup; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2670 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2671 } |
4634 | 2672 } |
2673 } | |
2674 else | |
2675 gripe_wrong_type_arg ("save", tc, false); | |
2676 | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2677 skip_to_next: |
4634 | 2678 return true; |
2679 | |
20893
384ff5aa9437
2015 Code Sprint: Eliminate useless return statements after error ().
Rik <rik@octave.org>
parents:
20831
diff
changeset
|
2680 // FIXME: With short-circuiting error(), no need for goto in code |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2681 error_cleanup: |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
2682 error ("save: error while writing '%s' to MAT file", name.c_str ()); |
4634 | 2683 |
2684 } |