Mercurial > octave-nkf
annotate libinterp/corefcn/ls-mat5.cc @ 19731:4197fc428c7d
maint: Update copyright notices for 2015.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Wed, 11 Feb 2015 14:19:08 -0500 |
parents | 0e1f5a750d00 |
children | 17d647821d61 |
rev | line source |
---|---|
4634 | 1 /* |
2 | |
19731
4197fc428c7d
maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents:
19630
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" |
4634 | 59 #include "oct-obj.h" |
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); \ |
18725
9a6646cc7c3e
Fix load/save to handle up to 2^32-1 elements.
Rik <rik@octave.org>
parents:
18712
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:
18712
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)) \ |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
379 { \ |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
380 error ("load: reading matrix data for '%s'", retval.c_str ()); \ |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
381 goto data_read_error; \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
382 } \ |
5089 | 383 \ |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
384 octave_idx_type n = re.numel (); \ |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
385 tmp_pos = is.tellg (); \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
386 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
|
387 static_cast<enum mat5_data_type> (type)); \ |
5089 | 388 \ |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
389 if (! is || error_state) \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
390 { \ |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
391 error ("load: reading matrix data for '%s'", retval.c_str ()); \ |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
392 goto data_read_error; \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
393 } \ |
5089 | 394 \ |
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
|
395 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
|
396 (READ_PAD (is_small_data_element, len))); \ |
5089 | 397 \ |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
398 if (imag) \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
399 { \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
400 /* 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
|
401 NDArray im (dims); \ |
5089 | 402 \ |
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
|
403 if (read_mat5_tag (is, swap, type, len, is_small_data_element)) \ |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
404 { \ |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
405 error ("load: reading matrix data for '%s'", \ |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
406 retval.c_str ()); \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
407 goto data_read_error; \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
408 } \ |
5089 | 409 \ |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
410 n = im.numel (); \ |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
411 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
|
412 static_cast<enum mat5_data_type> (type), flt_fmt); \ |
5089 | 413 \ |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
414 if (! is || error_state) \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
415 { \ |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
416 error ("load: reading imaginary matrix data for '%s'", \ |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
417 retval.c_str ()); \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
418 goto data_read_error; \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
419 } \ |
5089 | 420 \ |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
421 ComplexNDArray ctmp (dims); \ |
5089 | 422 \ |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
423 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
|
424 ctmp(i) = Complex (re(i).double_value (), im(i)); \ |
5089 | 425 \ |
426 tc = ctmp; \ | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
427 } \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
428 else \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
429 tc = re; \ |
5089 | 430 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11580
diff
changeset
|
431 |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11580
diff
changeset
|
432 // 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
|
433 // 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
|
434 // IS_SMALL_DATA_ELEMENT if the tag is 4 (8) bytes long. |
4634 | 435 // return nonzero on error |
436 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
|
437 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
|
438 bool& is_small_data_element) |
4634 | 439 { |
440 unsigned int upper; | |
5828 | 441 int32_t temp; |
4634 | 442 |
18712
6113e0c6920b
maint: Clean up extra spaces before/after parentheses.
Rik <rik@octave.org>
parents:
18099
diff
changeset
|
443 if (! is.read (reinterpret_cast<char *> (&temp), 4)) |
4634 | 444 goto data_read_error; |
445 | |
446 if (swap) | |
4944 | 447 swap_bytes<4> (&temp); |
4634 | 448 |
449 upper = (temp >> 16) & 0xffff; | |
450 type = temp & 0xffff; | |
451 | |
452 if (upper) | |
453 { | |
454 // "compressed" format | |
455 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
|
456 is_small_data_element = true; |
4634 | 457 } |
458 else | |
459 { | |
18712
6113e0c6920b
maint: Clean up extra spaces before/after parentheses.
Rik <rik@octave.org>
parents:
18099
diff
changeset
|
460 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
|
461 goto data_read_error; |
4634 | 462 if (swap) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
463 swap_bytes<4> (&temp); |
4634 | 464 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
|
465 is_small_data_element = false; |
4634 | 466 } |
467 | |
468 return 0; | |
469 | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
470 data_read_error: |
4634 | 471 return 1; |
472 } | |
473 | |
4944 | 474 static void |
5828 | 475 read_int (std::istream& is, bool swap, int32_t& val) |
4944 | 476 { |
477 is.read (reinterpret_cast<char *> (&val), 4); | |
478 | |
479 if (swap) | |
480 swap_bytes<4> (&val); | |
481 } | |
482 | |
4634 | 483 // Extract one data element (scalar, matrix, string, etc.) from stream |
484 // IS and place it in TC, returning the name of the variable. | |
485 // | |
486 // The data is expected to be in Matlab's "Version 5" .mat format, | |
487 // though not all the features of that format are supported. | |
488 // | |
489 // FILENAME is used for error messages. | |
490 | |
491 std::string | |
492 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
|
493 bool swap, bool& global, octave_value& tc) |
4634 | 494 { |
495 std::string retval; | |
496 | |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
497 global = false; |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
498 |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
499 // 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
|
500 // are first used to avoid errors from gcc about goto crossing |
4634 | 501 // initialization of variable. |
502 | |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
503 bool imag; |
6625 | 504 bool isclass = false; |
4634 | 505 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
|
506 dim_vector dims; |
4634 | 507 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
|
508 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
|
509 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
|
510 std::string classname; |
4634 | 511 |
512 // 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
|
513 oct_mach_info::float_format flt_fmt = oct_mach_info::flt_fmt_unknown; |
4634 | 514 if ((number == 1) ^ swap) |
515 flt_fmt = oct_mach_info::flt_fmt_ieee_big_endian; | |
516 else | |
517 flt_fmt = oct_mach_info::flt_fmt_ieee_little_endian; | |
518 | |
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
|
519 // 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
|
520 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
|
521 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
|
522 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
|
523 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
|
524 return retval; // EOF |
4634 | 525 |
5269 | 526 if (type == miCOMPRESSED) |
527 { | |
16225
28be9be86240
better diagnostic when reading compressed fields in mat files (bug #38488)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
15531
diff
changeset
|
528 #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
|
529 // 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
|
530 // 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
|
531 // 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
|
532 // wouldn't be needed. |
5269 | 533 |
534 OCTAVE_LOCAL_BUFFER (char, inbuf, element_length); | |
535 is.read (inbuf, element_length); | |
536 | |
537 // We uncompress the first 8 bytes of the header to get the buffer length | |
538 // This will fail with an error Z_MEM_ERROR | |
539 uLongf destLen = 8; | |
540 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
|
541 if (uncompress (reinterpret_cast<Bytef *> (tmp), &destLen, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
542 reinterpret_cast<Bytef *> (inbuf), element_length) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
543 != Z_MEM_ERROR) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
544 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
545 // Why should I have to initialize outbuf as I'll just overwrite!! |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
546 if (swap) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
547 swap_bytes<4> (tmp, 2); |
5322 | 548 |
12397
c60eaf7dac31
Remove parts of previous changset that weren't supposed to be committed
David Bateman <dbateman@free.fr>
parents:
12396
diff
changeset
|
549 destLen = tmp[1] + 8; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11580
diff
changeset
|
550 std::string outbuf (destLen, ' '); |
5269 | 551 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
552 // FIXME: find a way to avoid casting away const here! |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
553 |
19627
446c46af4b42
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
18869
diff
changeset
|
554 int err = uncompress (reinterpret_cast<Bytef *> |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
555 (const_cast<char *> (outbuf.c_str ())), |
12397
c60eaf7dac31
Remove parts of previous changset that weren't supposed to be committed
David Bateman <dbateman@free.fr>
parents:
12396
diff
changeset
|
556 &destLen, reinterpret_cast<Bytef *> (inbuf), |
c60eaf7dac31
Remove parts of previous changset that weren't supposed to be committed
David Bateman <dbateman@free.fr>
parents:
12396
diff
changeset
|
557 element_length); |
12399
824b3e0ab12a
Finish reverting unintended commit left over by 12396-12397.
Ben Abbott <bpabbott@mac.com>
parents:
12397
diff
changeset
|
558 |
12397
c60eaf7dac31
Remove parts of previous changset that weren't supposed to be committed
David Bateman <dbateman@free.fr>
parents:
12396
diff
changeset
|
559 if (err != Z_OK) |
11580
e306683a7e97
read_mat5_binary_element: improve diagnostic if uncompress fails
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
560 { |
12397
c60eaf7dac31
Remove parts of previous changset that weren't supposed to be committed
David Bateman <dbateman@free.fr>
parents:
12396
diff
changeset
|
561 std::string msg; |
c60eaf7dac31
Remove parts of previous changset that weren't supposed to be committed
David Bateman <dbateman@free.fr>
parents:
12396
diff
changeset
|
562 switch (err) |
11580
e306683a7e97
read_mat5_binary_element: improve diagnostic if uncompress fails
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
563 { |
12397
c60eaf7dac31
Remove parts of previous changset that weren't supposed to be committed
David Bateman <dbateman@free.fr>
parents:
12396
diff
changeset
|
564 case Z_STREAM_END: |
c60eaf7dac31
Remove parts of previous changset that weren't supposed to be committed
David Bateman <dbateman@free.fr>
parents:
12396
diff
changeset
|
565 msg = "stream end"; |
c60eaf7dac31
Remove parts of previous changset that weren't supposed to be committed
David Bateman <dbateman@free.fr>
parents:
12396
diff
changeset
|
566 break; |
c60eaf7dac31
Remove parts of previous changset that weren't supposed to be committed
David Bateman <dbateman@free.fr>
parents:
12396
diff
changeset
|
567 |
c60eaf7dac31
Remove parts of previous changset that weren't supposed to be committed
David Bateman <dbateman@free.fr>
parents:
12396
diff
changeset
|
568 case Z_NEED_DICT: |
c60eaf7dac31
Remove parts of previous changset that weren't supposed to be committed
David Bateman <dbateman@free.fr>
parents:
12396
diff
changeset
|
569 msg = "need dict"; |
c60eaf7dac31
Remove parts of previous changset that weren't supposed to be committed
David Bateman <dbateman@free.fr>
parents:
12396
diff
changeset
|
570 break; |
c60eaf7dac31
Remove parts of previous changset that weren't supposed to be committed
David Bateman <dbateman@free.fr>
parents:
12396
diff
changeset
|
571 |
c60eaf7dac31
Remove parts of previous changset that weren't supposed to be committed
David Bateman <dbateman@free.fr>
parents:
12396
diff
changeset
|
572 case Z_ERRNO: |
c60eaf7dac31
Remove parts of previous changset that weren't supposed to be committed
David Bateman <dbateman@free.fr>
parents:
12396
diff
changeset
|
573 msg = "errno case"; |
c60eaf7dac31
Remove parts of previous changset that weren't supposed to be committed
David Bateman <dbateman@free.fr>
parents:
12396
diff
changeset
|
574 break; |
c60eaf7dac31
Remove parts of previous changset that weren't supposed to be committed
David Bateman <dbateman@free.fr>
parents:
12396
diff
changeset
|
575 |
c60eaf7dac31
Remove parts of previous changset that weren't supposed to be committed
David Bateman <dbateman@free.fr>
parents:
12396
diff
changeset
|
576 case Z_STREAM_ERROR: |
c60eaf7dac31
Remove parts of previous changset that weren't supposed to be committed
David Bateman <dbateman@free.fr>
parents:
12396
diff
changeset
|
577 msg = "stream error"; |
c60eaf7dac31
Remove parts of previous changset that weren't supposed to be committed
David Bateman <dbateman@free.fr>
parents:
12396
diff
changeset
|
578 break; |
c60eaf7dac31
Remove parts of previous changset that weren't supposed to be committed
David Bateman <dbateman@free.fr>
parents:
12396
diff
changeset
|
579 |
c60eaf7dac31
Remove parts of previous changset that weren't supposed to be committed
David Bateman <dbateman@free.fr>
parents:
12396
diff
changeset
|
580 case Z_DATA_ERROR: |
c60eaf7dac31
Remove parts of previous changset that weren't supposed to be committed
David Bateman <dbateman@free.fr>
parents:
12396
diff
changeset
|
581 msg = "data error"; |
c60eaf7dac31
Remove parts of previous changset that weren't supposed to be committed
David Bateman <dbateman@free.fr>
parents:
12396
diff
changeset
|
582 break; |
c60eaf7dac31
Remove parts of previous changset that weren't supposed to be committed
David Bateman <dbateman@free.fr>
parents:
12396
diff
changeset
|
583 |
c60eaf7dac31
Remove parts of previous changset that weren't supposed to be committed
David Bateman <dbateman@free.fr>
parents:
12396
diff
changeset
|
584 case Z_MEM_ERROR: |
c60eaf7dac31
Remove parts of previous changset that weren't supposed to be committed
David Bateman <dbateman@free.fr>
parents:
12396
diff
changeset
|
585 msg = "mem error"; |
c60eaf7dac31
Remove parts of previous changset that weren't supposed to be committed
David Bateman <dbateman@free.fr>
parents:
12396
diff
changeset
|
586 break; |
c60eaf7dac31
Remove parts of previous changset that weren't supposed to be committed
David Bateman <dbateman@free.fr>
parents:
12396
diff
changeset
|
587 |
c60eaf7dac31
Remove parts of previous changset that weren't supposed to be committed
David Bateman <dbateman@free.fr>
parents:
12396
diff
changeset
|
588 case Z_BUF_ERROR: |
c60eaf7dac31
Remove parts of previous changset that weren't supposed to be committed
David Bateman <dbateman@free.fr>
parents:
12396
diff
changeset
|
589 msg = "buf error"; |
c60eaf7dac31
Remove parts of previous changset that weren't supposed to be committed
David Bateman <dbateman@free.fr>
parents:
12396
diff
changeset
|
590 break; |
c60eaf7dac31
Remove parts of previous changset that weren't supposed to be committed
David Bateman <dbateman@free.fr>
parents:
12396
diff
changeset
|
591 |
c60eaf7dac31
Remove parts of previous changset that weren't supposed to be committed
David Bateman <dbateman@free.fr>
parents:
12396
diff
changeset
|
592 case Z_VERSION_ERROR: |
c60eaf7dac31
Remove parts of previous changset that weren't supposed to be committed
David Bateman <dbateman@free.fr>
parents:
12396
diff
changeset
|
593 msg = "version error"; |
11580
e306683a7e97
read_mat5_binary_element: improve diagnostic if uncompress fails
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
594 break; |
e306683a7e97
read_mat5_binary_element: improve diagnostic if uncompress fails
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
595 } |
12397
c60eaf7dac31
Remove parts of previous changset that weren't supposed to be committed
David Bateman <dbateman@free.fr>
parents:
12396
diff
changeset
|
596 |
c60eaf7dac31
Remove parts of previous changset that weren't supposed to be committed
David Bateman <dbateman@free.fr>
parents:
12396
diff
changeset
|
597 error ("load: error uncompressing data element (%s from zlib)", |
c60eaf7dac31
Remove parts of previous changset that weren't supposed to be committed
David Bateman <dbateman@free.fr>
parents:
12396
diff
changeset
|
598 msg.c_str ()); |
c60eaf7dac31
Remove parts of previous changset that weren't supposed to be committed
David Bateman <dbateman@free.fr>
parents:
12396
diff
changeset
|
599 } |
c60eaf7dac31
Remove parts of previous changset that weren't supposed to be committed
David Bateman <dbateman@free.fr>
parents:
12396
diff
changeset
|
600 else |
c60eaf7dac31
Remove parts of previous changset that weren't supposed to be committed
David Bateman <dbateman@free.fr>
parents:
12396
diff
changeset
|
601 { |
c60eaf7dac31
Remove parts of previous changset that weren't supposed to be committed
David Bateman <dbateman@free.fr>
parents:
12396
diff
changeset
|
602 std::istringstream gz_is (outbuf); |
c60eaf7dac31
Remove parts of previous changset that weren't supposed to be committed
David Bateman <dbateman@free.fr>
parents:
12396
diff
changeset
|
603 retval = read_mat5_binary_element (gz_is, filename, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
604 swap, global, tc); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
605 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
606 } |
5269 | 607 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
608 error ("load: error probing size of compressed data element"); |
5269 | 609 |
610 return retval; | |
16225
28be9be86240
better diagnostic when reading compressed fields in mat files (bug #38488)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
15531
diff
changeset
|
611 #else // HAVE_ZLIB |
28be9be86240
better diagnostic when reading compressed fields in mat files (bug #38488)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
15531
diff
changeset
|
612 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
|
613 #endif |
5269 | 614 } |
615 | |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
616 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
|
617 |
4634 | 618 if (type != miMATRIX) |
619 { | |
6625 | 620 pos = is.tellg (); |
5930 | 621 error ("load: invalid element type = %d", type); |
4634 | 622 goto early_read_error; |
623 } | |
624 | |
625 if (element_length == 0) | |
626 { | |
627 tc = Matrix (); | |
628 return retval; | |
629 } | |
630 | |
631 pos = is.tellg (); | |
632 | |
633 // 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
|
634 int32_t len; |
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
|
635 if (read_mat5_tag (is, swap, type, len, 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
|
636 type != miUINT32 || len != 8 || is_small_data_element) |
4634 | 637 { |
638 error ("load: invalid array flags subelement"); | |
639 goto early_read_error; | |
640 } | |
641 | |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
642 int32_t flags; |
4634 | 643 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
|
644 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
645 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
|
646 |
4634 | 647 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
|
648 |
5269 | 649 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
|
650 |
5760 | 651 arrayclass = static_cast<arrayclasstype> (flags & 0xff); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11580
diff
changeset
|
652 |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
653 int32_t tmp_nzmax; |
18851
9ac2357f19bc
doc: Replace "non-zero" with "nonzero" to match existing usage.
Rik <rik@octave.org>
parents:
18725
diff
changeset
|
654 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
|
655 nzmax = tmp_nzmax; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11580
diff
changeset
|
656 |
4634 | 657 // dimensions array subelement |
6625 | 658 if (arrayclass != MAT_FILE_WORKSPACE_CLASS) |
659 { | |
660 int32_t dim_len; | |
4638 | 661 |
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
|
662 if (read_mat5_tag (is, swap, type, dim_len, 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
|
663 type != miINT32) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
664 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
665 error ("load: invalid dimensions array subelement"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
666 goto early_read_error; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
667 } |
4634 | 668 |
6625 | 669 int ndims = dim_len / 4; |
18869
94d791a03737
Allow loading mat5 files generated from R and Python (bug #42562).
Rik <rik@octave.org>
parents:
17861
diff
changeset
|
670 if (ndims == 1) |
94d791a03737
Allow loading mat5 files generated from R and Python (bug #42562).
Rik <rik@octave.org>
parents:
17861
diff
changeset
|
671 { |
94d791a03737
Allow loading mat5 files generated from R and Python (bug #42562).
Rik <rik@octave.org>
parents:
17861
diff
changeset
|
672 // 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
|
673 dims.resize (2); |
94d791a03737
Allow loading mat5 files generated from R and Python (bug #42562).
Rik <rik@octave.org>
parents:
17861
diff
changeset
|
674 dims(1) = 1; |
94d791a03737
Allow loading mat5 files generated from R and Python (bug #42562).
Rik <rik@octave.org>
parents:
17861
diff
changeset
|
675 } |
94d791a03737
Allow loading mat5 files generated from R and Python (bug #42562).
Rik <rik@octave.org>
parents:
17861
diff
changeset
|
676 else |
94d791a03737
Allow loading mat5 files generated from R and Python (bug #42562).
Rik <rik@octave.org>
parents:
17861
diff
changeset
|
677 dims.resize (ndims); |
94d791a03737
Allow loading mat5 files generated from R and Python (bug #42562).
Rik <rik@octave.org>
parents:
17861
diff
changeset
|
678 |
6625 | 679 for (int i = 0; i < ndims; i++) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
680 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
681 int32_t n; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
682 read_int (is, swap, n); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
683 dims(i) = n; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
684 } |
4634 | 685 |
6625 | 686 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
|
687 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
|
688 (READ_PAD (is_small_data_element, dim_len) - dim_len)); |
6625 | 689 } |
690 else | |
691 { | |
692 // 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
|
693 dims.resize (2); |
6625 | 694 dims(0) = 1; |
695 dims(1) = 1; | |
696 } | |
4634 | 697 |
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
|
698 if (read_mat5_tag (is, swap, type, len, is_small_data_element) || !INT8(type)) |
4634 | 699 { |
700 error ("load: invalid array name subelement"); | |
701 goto early_read_error; | |
702 } | |
703 | |
704 { | |
705 OCTAVE_LOCAL_BUFFER (char, name, len+1); | |
706 | |
707 // Structure field subelements have zero-length array name subelements. | |
708 | |
709 std::streampos tmp_pos = is.tellg (); | |
710 | |
711 if (len) | |
712 { | |
18712
6113e0c6920b
maint: Clean up extra spaces before/after parentheses.
Rik <rik@octave.org>
parents:
18099
diff
changeset
|
713 if (! is.read (name, len)) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
714 goto data_read_error; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11580
diff
changeset
|
715 |
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
|
716 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
|
717 (READ_PAD (is_small_data_element, len))); |
4634 | 718 } |
719 | |
720 name[len] = '\0'; | |
721 retval = name; | |
722 } | |
723 | |
724 switch (arrayclass) | |
725 { | |
5900 | 726 case MAT_FILE_CELL_CLASS: |
4634 | 727 { |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
728 Cell cell_array (dims); |
4634 | 729 |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
730 octave_idx_type n = cell_array.numel (); |
4634 | 731 |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
732 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
|
733 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
734 octave_value tc2; |
4634 | 735 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
736 std::string nm |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
737 = read_mat5_binary_element (is, filename, swap, global, tc2); |
4634 | 738 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
739 if (! is || error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
740 { |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
741 error ("load: reading cell data for '%s'", nm.c_str ()); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
742 goto data_read_error; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
743 } |
4634 | 744 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
745 cell_array(i) = tc2; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
746 } |
4634 | 747 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
748 tc = cell_array; |
4634 | 749 } |
750 break; | |
751 | |
5900 | 752 case MAT_FILE_SPARSE_CLASS: |
5164 | 753 { |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
754 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
|
755 octave_idx_type nc = dims(1); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
756 SparseMatrix sm; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
757 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
|
758 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
|
759 octave_idx_type *cidx; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
760 double *data; |
5164 | 761 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
762 // Setup return value |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
763 if (imag) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
764 { |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
765 scm = SparseComplexMatrix (nr, nc, nzmax); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
766 ridx = scm.ridx (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
767 cidx = scm.cidx (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
768 data = 0; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
769 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
770 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
771 { |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
772 sm = SparseMatrix (nr, nc, nzmax); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
773 ridx = sm.ridx (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
774 cidx = sm.cidx (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
775 data = sm.data (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
776 } |
5164 | 777 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
778 // row indices |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
779 std::streampos tmp_pos; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11580
diff
changeset
|
780 |
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
|
781 if (read_mat5_tag (is, swap, type, len, is_small_data_element)) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
782 { |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
783 error ("load: reading sparse row data for '%s'", retval.c_str ()); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
784 goto data_read_error; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
785 } |
5164 | 786 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
787 tmp_pos = is.tellg (); |
5164 | 788 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
789 read_mat5_integer_data (is, ridx, nzmax, swap, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
790 static_cast<enum mat5_data_type> (type)); |
5164 | 791 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
792 if (! is || error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
793 { |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
794 error ("load: reading sparse row data for '%s'", retval.c_str ()); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
795 goto data_read_error; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
796 } |
5164 | 797 |
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
|
798 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
|
799 (READ_PAD (is_small_data_element, len))); |
5164 | 800 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
801 // 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
|
802 if (read_mat5_tag (is, swap, type, len, is_small_data_element)) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
803 { |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
804 error ("load: reading sparse column data for '%s'", |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
805 retval.c_str ()); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
806 goto data_read_error; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
807 } |
5164 | 808 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
809 tmp_pos = is.tellg (); |
5164 | 810 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
811 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
|
812 static_cast<enum mat5_data_type> (type)); |
5164 | 813 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
814 if (! is || error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
815 { |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
816 error ("load: reading sparse column data for '%s'", |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
817 retval.c_str ()); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
818 goto data_read_error; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
819 } |
5164 | 820 |
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
|
821 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
|
822 (READ_PAD (is_small_data_element, len))); |
5164 | 823 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
824 // 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
|
825 if (read_mat5_tag (is, swap, type, len, is_small_data_element)) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
826 { |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
827 error ("load: reading sparse matrix data for '%s'", |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
828 retval.c_str ()); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
829 goto data_read_error; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
830 } |
5164 | 831 |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
832 octave_idx_type nnz = cidx[nc]; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
833 NDArray re; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
834 if (imag) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
835 { |
10350
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10349
diff
changeset
|
836 re = NDArray (dim_vector (nnz, 1)); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
837 data = re.fortran_vec (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
838 } |
5592 | 839 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
840 tmp_pos = is.tellg (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
841 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
|
842 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
|
843 flt_fmt); |
5164 | 844 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
845 if (! is || error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
846 { |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
847 error ("load: reading sparse matrix data for '%s'", |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
848 retval.c_str ()); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
849 goto data_read_error; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
850 } |
5164 | 851 |
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
|
852 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
|
853 (READ_PAD (is_small_data_element, len))); |
5164 | 854 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
855 // imaginary data subelement |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
856 if (imag) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
857 { |
10350
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10349
diff
changeset
|
858 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
|
859 |
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
|
860 if (read_mat5_tag (is, swap, type, len, is_small_data_element)) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
861 { |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
862 error ("load: reading sparse matrix data for '%s'", |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
863 retval.c_str ()); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
864 goto data_read_error; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
865 } |
5164 | 866 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
867 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
|
868 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
|
869 flt_fmt); |
5164 | 870 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
871 if (! is || error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
872 { |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
873 error ("load: reading imaginary sparse matrix data for '%s'", |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
874 retval.c_str ()); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
875 goto data_read_error; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
876 } |
5164 | 877 |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
878 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
|
879 scm.xdata (i) = Complex (re (i), im (i)); |
5164 | 880 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
881 tc = scm; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
882 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
883 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
884 tc = sm; |
5164 | 885 } |
886 break; | |
4634 | 887 |
5900 | 888 case MAT_FILE_FUNCTION_CLASS: |
6625 | 889 { |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
890 octave_value tc2; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
891 std::string nm |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
892 = read_mat5_binary_element (is, filename, swap, global, tc2); |
6625 | 893 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
894 if (! is || error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
895 goto data_read_error; |
6625 | 896 |
16871
5e30b1c950b8
Replace uses of Octave_map with octave_map or octave_scalar_map.
Rik <rik@octave.org>
parents:
16670
diff
changeset
|
897 // 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
|
898 // 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
|
899 // 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
|
900 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
|
901 octave_scalar_map m1 |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
902 = 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
|
903 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
|
904 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
|
905 std::string fpath = m1.contents ("file").string_value (); |
6625 | 906 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
907 if (ftype == "simple" || ftype == "scopedfunction") |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
908 { |
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
|
909 if (fpath.length () == 0) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
910 // We have a builtin function |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
911 tc = make_fcn_handle (fname); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
912 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
913 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11580
diff
changeset
|
914 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
|
915 m0.contents ("matlabroot").string_value (); |
6625 | 916 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
917 if ((fpath.length () >= mroot.length ()) && |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
918 fpath.substr (0, mroot.length ()) == mroot && |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
919 OCTAVE_EXEC_PREFIX != mroot) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
920 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
921 // If fpath starts with matlabroot, and matlabroot |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
922 // doesn't equal octave_config_info ("exec_prefix") |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
923 // 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
|
924 // 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
|
925 // 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
|
926 // running version of Octave? |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11580
diff
changeset
|
927 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
928 // 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
|
929 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
|
930 fpath.substr (mroot.length ()); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
931 file_stat fs (str); |
6625 | 932 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
933 if (fs.exists ()) |
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 size_t xpos |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
936 = str.find_last_of (file_ops::dir_sep_chars ()); |
7336 | 937 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
938 std::string dir_name = str.substr (0, xpos); |
6625 | 939 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
940 octave_function *fcn |
16676
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16442
diff
changeset
|
941 = 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
|
942 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
943 if (fcn) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
944 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
945 octave_value tmp (fcn); |
6625 | 946 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
947 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
|
948 fname)); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
949 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
950 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
951 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
952 { |
16871
5e30b1c950b8
Replace uses of Octave_map with octave_map or octave_scalar_map.
Rik <rik@octave.org>
parents:
16670
diff
changeset
|
953 // 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
|
954 string_vector names(3); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
955 names(0) = fname + ".oct"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
956 names(1) = fname + ".mex"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
957 names(2) = fname + ".m"; |
6625 | 958 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
959 dir_path p (load_path::system_path ()); |
6625 | 960 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
961 str = |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
962 octave_env::make_absolute (p.find_first_of (names)); |
6625 | 963 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
964 size_t xpos |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
965 = str.find_last_of (file_ops::dir_sep_chars ()); |
6625 | 966 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
967 std::string dir_name = str.substr (0, xpos); |
6625 | 968 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
969 octave_function *fcn |
16676
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16442
diff
changeset
|
970 = load_fcn_from_file (str, dir_name, "", "", fname); |
6625 | 971 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
972 if (fcn) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
973 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
974 octave_value tmp (fcn); |
6625 | 975 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
976 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
|
977 fname)); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
978 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
979 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
980 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11580
diff
changeset
|
981 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
|
982 fpath.c_str ()); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
983 goto skip_ahead; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
984 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
985 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
986 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
987 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
988 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
989 size_t xpos |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
990 = fpath.find_last_of (file_ops::dir_sep_chars ()); |
6625 | 991 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
992 std::string dir_name = fpath.substr (0, xpos); |
6625 | 993 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
994 octave_function *fcn |
16676
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16442
diff
changeset
|
995 = load_fcn_from_file (fpath, dir_name, "", "", fname); |
6625 | 996 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
997 if (fcn) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
998 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
999 octave_value tmp (fcn); |
6625 | 1000 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1001 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
|
1002 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1003 else |
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 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
|
1006 fpath.c_str ()); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1007 goto skip_ahead; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1008 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1009 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1010 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1011 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1012 else if (ftype == "nested") |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1013 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1014 warning ("load: can't load nested function"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1015 goto skip_ahead; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1016 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1017 else if (ftype == "anonymous") |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1018 { |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1019 octave_scalar_map m2 |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1020 = 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
|
1021 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
|
1022 octave_idx_type off |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1023 = 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
|
1024 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
|
1025 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
|
1026 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
|
1027 m2 = tc2.scalar_map_value (); |
7336 | 1028 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1029 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
|
1030 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1031 // 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
|
1032 // 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
|
1033 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1034 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
|
1035 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
|
1036 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1037 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
|
1038 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1039 octave_call_stack::push (local_scope, 0); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1040 frame.add_fcn (octave_call_stack::pop); |
7336 | 1041 |
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
|
1042 if (m2.nfields () > 0) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1043 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1044 octave_value tmp; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11580
diff
changeset
|
1045 |
16871
5e30b1c950b8
Replace uses of Octave_map with octave_map or octave_scalar_map.
Rik <rik@octave.org>
parents:
16670
diff
changeset
|
1046 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
|
1047 p0 != m2.end (); p0++) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1048 { |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
1049 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
|
1050 octave_value val = m2.contents (p0); |
6625 | 1051 |
16442
302157614308
deprecate symbol_table::varref functions
John W. Eaton <jwe@octave.org>
parents:
16427
diff
changeset
|
1052 symbol_table::assign (key, val, local_scope, 0); |
6625 | 1053 } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1054 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11580
diff
changeset
|
1055 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1056 int parse_status; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11580
diff
changeset
|
1057 octave_value anon_fcn_handle = |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1058 eval_string (fname.substr (4), true, parse_status); |
6625 | 1059 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1060 if (parse_status == 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1061 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11580
diff
changeset
|
1062 octave_fcn_handle *fh = |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1063 anon_fcn_handle.fcn_handle_value (); |
7761
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
1064 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1065 if (fh) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1066 tc = new octave_fcn_handle (fh->fcn_val (), "@<anonymous>"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1067 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1068 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1069 error ("load: failed to load anonymous function handle"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1070 goto skip_ahead; |
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 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1073 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1074 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1075 error ("load: failed to load anonymous function handle"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1076 goto skip_ahead; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1077 } |
6625 | 1078 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1079 frame.run (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1080 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1081 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1082 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1083 error ("load: invalid function handle type"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1084 goto skip_ahead; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1085 } |
6625 | 1086 } |
1087 break; | |
1088 | |
1089 case MAT_FILE_WORKSPACE_CLASS: | |
1090 { | |
16871
5e30b1c950b8
Replace uses of Octave_map with octave_map or octave_scalar_map.
Rik <rik@octave.org>
parents:
16670
diff
changeset
|
1091 octave_map m (dim_vector (1, 1)); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1092 int n_fields = 2; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1093 string_vector field (n_fields); |
6625 | 1094 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1095 for (int i = 0; i < n_fields; i++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1096 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1097 int32_t fn_type; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1098 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
|
1099 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
|
1100 || !INT8(fn_type)) |
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 error ("load: invalid field name subelement"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1103 goto data_read_error; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1104 } |
6625 | 1105 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1106 OCTAVE_LOCAL_BUFFER (char, elname, fn_len + 1); |
6625 | 1107 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1108 std::streampos tmp_pos = is.tellg (); |
6625 | 1109 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1110 if (fn_len) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1111 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1112 if (! is.read (elname, fn_len)) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1113 goto data_read_error; |
6625 | 1114 |
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
|
1115 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
|
1116 (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
|
1117 } |
6625 | 1118 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1119 elname[fn_len] = '\0'; |
6625 | 1120 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1121 field(i) = elname; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1122 } |
6625 | 1123 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1124 std::vector<Cell> elt (n_fields); |
6625 | 1125 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1126 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
|
1127 elt[i] = Cell (dims); |
6625 | 1128 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1129 octave_idx_type n = dims.numel (); |
6625 | 1130 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1131 // fields subelements |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1132 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
|
1133 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1134 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
|
1135 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1136 if (field(i) == "MCOS") |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1137 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1138 octave_value fieldtc; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1139 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
|
1140 fieldtc); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1141 if (! is || error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1142 goto data_read_error; |
6625 | 1143 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1144 elt[i](j) = fieldtc; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1145 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1146 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1147 elt[i](j) = octave_value (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1148 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1149 } |
6625 | 1150 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1151 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
|
1152 m.assign (field (i), elt[i]); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1153 tc = m; |
6625 | 1154 } |
1155 break; | |
1156 | |
1157 case MAT_FILE_OBJECT_CLASS: | |
1158 { | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1159 isclass = true; |
6625 | 1160 |
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
|
1161 if (read_mat5_tag (is, swap, type, len, 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
|
1162 !INT8(type)) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1163 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1164 error ("load: invalid class name"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1165 goto skip_ahead; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1166 } |
6625 | 1167 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1168 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1169 OCTAVE_LOCAL_BUFFER (char, name, len+1); |
6625 | 1170 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1171 std::streampos tmp_pos = is.tellg (); |
6625 | 1172 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1173 if (len) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1174 { |
18712
6113e0c6920b
maint: Clean up extra spaces before/after parentheses.
Rik <rik@octave.org>
parents:
18099
diff
changeset
|
1175 if (! is.read (name, len)) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1176 goto data_read_error; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11580
diff
changeset
|
1177 |
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
|
1178 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
|
1179 (READ_PAD (is_small_data_element, len))); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1180 } |
6625 | 1181 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1182 name[len] = '\0'; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1183 classname = name; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1184 } |
6625 | 1185 } |
1186 // Fall-through | |
5900 | 1187 case MAT_FILE_STRUCT_CLASS: |
4634 | 1188 { |
16871
5e30b1c950b8
Replace uses of Octave_map with octave_map or octave_scalar_map.
Rik <rik@octave.org>
parents:
16670
diff
changeset
|
1189 octave_map m (dims); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1190 int32_t fn_type; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1191 int32_t fn_len; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1192 int32_t field_name_length; |
4634 | 1193 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1194 // field name length subelement -- actually the maximum length |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1195 // 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
|
1196 // 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
|
1197 // 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
|
1198 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
|
1199 || fn_type != miINT32) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1200 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1201 error ("load: invalid field name length subelement"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1202 goto data_read_error; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1203 } |
4634 | 1204 |
18712
6113e0c6920b
maint: Clean up extra spaces before/after parentheses.
Rik <rik@octave.org>
parents:
18099
diff
changeset
|
1205 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
|
1206 goto data_read_error; |
4634 | 1207 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1208 if (swap) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1209 swap_bytes<4> (&field_name_length); |
4634 | 1210 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1211 // 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
|
1212 // 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
|
1213 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
|
1214 || !INT8(fn_type)) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1215 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1216 error ("load: invalid field name subelement"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1217 goto data_read_error; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1218 } |
4634 | 1219 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1220 octave_idx_type n_fields = fn_len/field_name_length; |
4634 | 1221 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1222 if (n_fields > 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1223 { |
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
|
1224 fn_len = READ_PAD (is_small_data_element, fn_len); |
4634 | 1225 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1226 OCTAVE_LOCAL_BUFFER (char, elname, fn_len); |
4634 | 1227 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1228 if (! is.read (elname, fn_len)) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1229 goto data_read_error; |
4634 | 1230 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1231 std::vector<Cell> elt (n_fields); |
6292 | 1232 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1233 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
|
1234 elt[i] = Cell (dims); |
4634 | 1235 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1236 octave_idx_type n = dims.numel (); |
5336 | 1237 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1238 // fields subelements |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1239 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
|
1240 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1241 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
|
1242 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1243 octave_value fieldtc; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1244 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
|
1245 fieldtc); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1246 elt[i](j) = fieldtc; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1247 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1248 } |
4634 | 1249 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1250 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
|
1251 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1252 const char *key = elname + i*field_name_length; |
5336 | 1253 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1254 m.assign (key, elt[i]); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1255 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1256 } |
4634 | 1257 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1258 if (isclass) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1259 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1260 if (classname == "inline") |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1261 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1262 // 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
|
1263 // 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
|
1264 tc = |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
1265 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
|
1266 m.contents ("args")(0).string_value ()); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1267 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1268 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1269 { |
13874
c1b754d93572
copy parent class info when performing operations on class objects
John W. Eaton <jwe@octave.org>
parents:
12699
diff
changeset
|
1270 octave_class* cls |
c1b754d93572
copy parent class info when performing operations on class objects
John W. Eaton <jwe@octave.org>
parents:
12699
diff
changeset
|
1271 = 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
|
1272 std::list<std::string> ()); |
12699
c0d102ad9bba
Fix loading of objects in MAT-files (bug #32641).
David Bateman <dbateman@free.fr>
parents:
12399
diff
changeset
|
1273 |
c0d102ad9bba
Fix loading of objects in MAT-files (bug #32641).
David Bateman <dbateman@free.fr>
parents:
12399
diff
changeset
|
1274 if (cls->reconstruct_exemplar ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1275 { |
12699
c0d102ad9bba
Fix loading of objects in MAT-files (bug #32641).
David Bateman <dbateman@free.fr>
parents:
12399
diff
changeset
|
1276 |
c0d102ad9bba
Fix loading of objects in MAT-files (bug #32641).
David Bateman <dbateman@free.fr>
parents:
12399
diff
changeset
|
1277 if (! cls->reconstruct_parents ()) |
c0d102ad9bba
Fix loading of objects in MAT-files (bug #32641).
David Bateman <dbateman@free.fr>
parents:
12399
diff
changeset
|
1278 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
|
1279 |
c0d102ad9bba
Fix loading of objects in MAT-files (bug #32641).
David Bateman <dbateman@free.fr>
parents:
12399
diff
changeset
|
1280 tc = cls; |
c0d102ad9bba
Fix loading of objects in MAT-files (bug #32641).
David Bateman <dbateman@free.fr>
parents:
12399
diff
changeset
|
1281 if (load_path::find_method (classname, "loadobj") != |
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
|
1282 std::string ()) |
12699
c0d102ad9bba
Fix loading of objects in MAT-files (bug #32641).
David Bateman <dbateman@free.fr>
parents:
12399
diff
changeset
|
1283 { |
c0d102ad9bba
Fix loading of objects in MAT-files (bug #32641).
David Bateman <dbateman@free.fr>
parents:
12399
diff
changeset
|
1284 octave_value_list tmp = feval ("loadobj", tc, 1); |
c0d102ad9bba
Fix loading of objects in MAT-files (bug #32641).
David Bateman <dbateman@free.fr>
parents:
12399
diff
changeset
|
1285 |
c0d102ad9bba
Fix loading of objects in MAT-files (bug #32641).
David Bateman <dbateman@free.fr>
parents:
12399
diff
changeset
|
1286 if (! error_state) |
c0d102ad9bba
Fix loading of objects in MAT-files (bug #32641).
David Bateman <dbateman@free.fr>
parents:
12399
diff
changeset
|
1287 tc = tmp(0); |
c0d102ad9bba
Fix loading of objects in MAT-files (bug #32641).
David Bateman <dbateman@free.fr>
parents:
12399
diff
changeset
|
1288 else |
c0d102ad9bba
Fix loading of objects in MAT-files (bug #32641).
David Bateman <dbateman@free.fr>
parents:
12399
diff
changeset
|
1289 goto data_read_error; |
c0d102ad9bba
Fix loading of objects in MAT-files (bug #32641).
David Bateman <dbateman@free.fr>
parents:
12399
diff
changeset
|
1290 } |
c0d102ad9bba
Fix loading of objects in MAT-files (bug #32641).
David Bateman <dbateman@free.fr>
parents:
12399
diff
changeset
|
1291 } |
c0d102ad9bba
Fix loading of objects in MAT-files (bug #32641).
David Bateman <dbateman@free.fr>
parents:
12399
diff
changeset
|
1292 else |
c0d102ad9bba
Fix loading of objects in MAT-files (bug #32641).
David Bateman <dbateman@free.fr>
parents:
12399
diff
changeset
|
1293 { |
c0d102ad9bba
Fix loading of objects in MAT-files (bug #32641).
David Bateman <dbateman@free.fr>
parents:
12399
diff
changeset
|
1294 tc = m; |
c0d102ad9bba
Fix loading of objects in MAT-files (bug #32641).
David Bateman <dbateman@free.fr>
parents:
12399
diff
changeset
|
1295 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
|
1296 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1297 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1298 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1299 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1300 tc = m; |
4634 | 1301 } |
1302 break; | |
1303 | |
5900 | 1304 case MAT_FILE_INT8_CLASS: |
5089 | 1305 OCTAVE_MAT5_INTEGER_READ (int8NDArray); |
1306 break; | |
1307 | |
5900 | 1308 case MAT_FILE_UINT8_CLASS: |
5269 | 1309 { |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1310 OCTAVE_MAT5_INTEGER_READ (uint8NDArray); |
5269 | 1311 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1312 // 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
|
1313 // 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
|
1314 // variable and convert it. |
5269 | 1315 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1316 if (logicalvar) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1317 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1318 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
|
1319 octave_idx_type nel = in.numel (); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1320 boolNDArray out (dims); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11580
diff
changeset
|
1321 |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1322 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
|
1323 out(i) = in(i).bool_value (); |
5269 | 1324 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1325 tc = out; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1326 } |
5269 | 1327 } |
5089 | 1328 break; |
1329 | |
5900 | 1330 case MAT_FILE_INT16_CLASS: |
5089 | 1331 OCTAVE_MAT5_INTEGER_READ (int16NDArray); |
1332 break; | |
1333 | |
5900 | 1334 case MAT_FILE_UINT16_CLASS: |
5089 | 1335 OCTAVE_MAT5_INTEGER_READ (uint16NDArray); |
1336 break; | |
1337 | |
5900 | 1338 case MAT_FILE_INT32_CLASS: |
5089 | 1339 OCTAVE_MAT5_INTEGER_READ (int32NDArray); |
1340 break; | |
1341 | |
5900 | 1342 case MAT_FILE_UINT32_CLASS: |
5089 | 1343 OCTAVE_MAT5_INTEGER_READ (uint32NDArray); |
1344 break; | |
1345 | |
5900 | 1346 case MAT_FILE_INT64_CLASS: |
5089 | 1347 OCTAVE_MAT5_INTEGER_READ (int64NDArray); |
1348 break; | |
1349 | |
5900 | 1350 case MAT_FILE_UINT64_CLASS: |
5089 | 1351 OCTAVE_MAT5_INTEGER_READ (uint64NDArray); |
1352 break; | |
1353 | |
10909
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1354 |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1355 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
|
1356 { |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1357 FloatNDArray re (dims); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11580
diff
changeset
|
1358 |
10909
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1359 // real data subelement |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1360 |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1361 std::streampos tmp_pos; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11580
diff
changeset
|
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 if (read_mat5_tag (is, swap, type, len, is_small_data_element)) |
10909
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1364 { |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
1365 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
|
1366 goto data_read_error; |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1367 } |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1368 |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1369 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
|
1370 tmp_pos = is.tellg (); |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1371 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
|
1372 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
|
1373 flt_fmt); |
10909
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1374 |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1375 if (! is || error_state) |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1376 { |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
1377 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
|
1378 goto data_read_error; |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1379 } |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1380 |
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
|
1381 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
|
1382 (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
|
1383 |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1384 if (imag) |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1385 { |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1386 // imaginary data subelement |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1387 |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1388 FloatNDArray im (dims); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11580
diff
changeset
|
1389 |
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
|
1390 if (read_mat5_tag (is, swap, type, len, is_small_data_element)) |
10909
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1391 { |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
1392 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
|
1393 goto data_read_error; |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1394 } |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1395 |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1396 n = im.numel (); |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1397 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
|
1398 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
|
1399 flt_fmt); |
10909
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1400 |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1401 if (! is || error_state) |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1402 { |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
1403 error ("load: reading imaginary matrix data for '%s'", |
10909
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1404 retval.c_str ()); |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1405 goto data_read_error; |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1406 } |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1407 |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1408 FloatComplexNDArray ctmp (dims); |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1409 |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1410 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
|
1411 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
|
1412 |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1413 tc = ctmp; |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1414 } |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1415 else |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1416 tc = re; |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1417 } |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1418 break; |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1419 |
5900 | 1420 case MAT_FILE_CHAR_CLASS: |
4634 | 1421 // handle as a numerical array to start with |
1422 | |
5900 | 1423 case MAT_FILE_DOUBLE_CLASS: |
4634 | 1424 default: |
5089 | 1425 { |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1426 NDArray re (dims); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11580
diff
changeset
|
1427 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1428 // real data subelement |
5089 | 1429 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1430 std::streampos tmp_pos; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11580
diff
changeset
|
1431 |
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
|
1432 if (read_mat5_tag (is, swap, type, len, is_small_data_element)) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1433 { |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
1434 error ("load: reading matrix data for '%s'", retval.c_str ()); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1435 goto data_read_error; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1436 } |
4634 | 1437 |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1438 octave_idx_type n = re.numel (); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1439 tmp_pos = is.tellg (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1440 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
|
1441 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
|
1442 flt_fmt); |
4634 | 1443 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1444 if (! is || error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1445 { |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
1446 error ("load: reading matrix data for '%s'", retval.c_str ()); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1447 goto data_read_error; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1448 } |
4634 | 1449 |
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
|
1450 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
|
1451 (READ_PAD (is_small_data_element, len))); |
5089 | 1452 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1453 if (logicalvar) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1454 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1455 // 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
|
1456 // 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
|
1457 // variable and convert it. |
5269 | 1458 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1459 boolNDArray out (dims); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11580
diff
changeset
|
1460 |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1461 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
|
1462 out (i) = static_cast<bool> (re (i)); |
5269 | 1463 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1464 tc = out; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1465 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1466 else if (imag) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1467 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1468 // imaginary data subelement |
5269 | 1469 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1470 NDArray im (dims); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11580
diff
changeset
|
1471 |
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
|
1472 if (read_mat5_tag (is, swap, type, len, is_small_data_element)) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1473 { |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
1474 error ("load: reading matrix data for '%s'", retval.c_str ()); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1475 goto data_read_error; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1476 } |
4634 | 1477 |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1478 n = im.numel (); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1479 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
|
1480 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
|
1481 flt_fmt); |
4634 | 1482 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1483 if (! is || error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1484 { |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
1485 error ("load: reading imaginary matrix data for '%s'", |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1486 retval.c_str ()); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1487 goto data_read_error; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1488 } |
4634 | 1489 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1490 ComplexNDArray ctmp (dims); |
4634 | 1491 |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1492 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
|
1493 ctmp(i) = Complex (re(i), im(i)); |
4634 | 1494 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1495 tc = ctmp; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1496 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1497 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1498 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1499 if (arrayclass == MAT_FILE_CHAR_CLASS) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1500 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1501 if (type == miUTF16 || type == miUTF32) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1502 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1503 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
|
1504 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
|
1505 { |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1506 if (re(i) > 127) |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1507 { |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1508 re(i) = '?'; |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1509 found_big_char = true; |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1510 } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1511 } |
6954 | 1512 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1513 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
|
1514 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
|
1515 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1516 else if (type == miUTF8) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1517 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1518 // Search for multi-byte encoded UTF8 characters and |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1519 // replace with 0x3F for '?'... Give the user a warning |
4634 | 1520 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1521 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
|
1522 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
|
1523 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1524 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
|
1525 if (a > 0x7f) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1526 utf8_multi_byte = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1527 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11580
diff
changeset
|
1528 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1529 if (utf8_multi_byte) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1530 { |
11590
4ced6b90fffb
style fixes for warning and error messages in source files
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
1531 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
|
1532 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
|
1533 { |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1534 unsigned char a |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1535 = static_cast<unsigned char> (re(i)); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1536 if (a > 0x7f) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1537 re(i) = '?'; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1538 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1539 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1540 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1541 tc = re; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1542 tc = tc.convert_to_str (false, true, '\''); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1543 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1544 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1545 tc = re; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1546 } |
5089 | 1547 } |
4634 | 1548 } |
1549 | |
1550 is.seekg (pos + static_cast<std::streamoff> (element_length)); | |
1551 | |
1552 if (is.eof ()) | |
1553 is.clear (); | |
1554 | |
1555 return retval; | |
1556 | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1557 data_read_error: |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1558 early_read_error: |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
1559 error ("load: trouble reading binary file '%s'", filename.c_str ()); |
4634 | 1560 return std::string (); |
1561 | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1562 skip_ahead: |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
1563 warning ("skipping over '%s'", retval.c_str ()); |
4634 | 1564 is.seekg (pos + static_cast<std::streamoff> (element_length)); |
1565 return read_mat5_binary_element (is, filename, swap, global, tc); | |
1566 } | |
1567 | |
1568 int | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11580
diff
changeset
|
1569 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
|
1570 const std::string& filename) |
4634 | 1571 { |
18099
6a71e5030df5
Follow coding convention of defining and initializing only 1 variable per line in liboctinterp.
Rik <rik@octave.org>
parents:
18019
diff
changeset
|
1572 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
|
1573 int16_t magic = 0; |
6625 | 1574 uint64_t subsys_offset; |
1575 | |
1576 is.seekg (116, std::ios::beg); | |
1577 is.read (reinterpret_cast<char *> (&subsys_offset), 8); | |
4634 | 1578 |
1579 is.seekg (124, std::ios::beg); | |
5760 | 1580 is.read (reinterpret_cast<char *> (&version), 2); |
1581 is.read (reinterpret_cast<char *> (&magic), 2); | |
4634 | 1582 |
1583 if (magic == 0x4d49) | |
1584 swap = 0; | |
1585 else if (magic == 0x494d) | |
1586 swap = 1; | |
1587 else | |
1588 { | |
1589 if (! quiet) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1590 error ("load: can't read binary file"); |
4634 | 1591 return -1; |
1592 } | |
1593 | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1594 if (! swap) // version number is inverse swapped! |
4634 | 1595 version = ((version >> 8) & 0xff) + ((version & 0xff) << 8); |
1596 | |
1597 if (version != 1 && !quiet) | |
1598 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
|
1599 "but only prepared for version 1", version); |
4634 | 1600 |
6625 | 1601 if (swap) |
1602 swap_bytes<8> (&subsys_offset, 1); | |
1603 | |
1604 if (subsys_offset != 0x2020202020202020ULL && subsys_offset != 0ULL) | |
1605 { | |
1606 // Read the subsystem data block | |
1607 is.seekg (subsys_offset, std::ios::beg); | |
1608 | |
1609 octave_value tc; | |
1610 bool global; | |
1611 read_mat5_binary_element (is, filename, swap, global, tc); | |
1612 | |
1613 if (!is || error_state) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1614 return -1; |
6625 | 1615 |
1616 if (tc.is_uint8_type ()) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1617 { |
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
|
1618 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
|
1619 octave_idx_type ilen = itmp.numel (); |
6625 | 1620 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1621 // 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
|
1622 std::string outbuf (ilen - 7, ' '); |
6625 | 1623 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1624 // 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
|
1625 char *ctmp = const_cast<char *> (outbuf.c_str ()); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1626 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
|
1627 ctmp[j-8] = itmp(j).char_value (); |
6625 | 1628 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1629 std::istringstream fh_ws (outbuf); |
6625 | 1630 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1631 read_mat5_binary_element (fh_ws, filename, swap, global, subsys_ov); |
6625 | 1632 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1633 if (error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1634 return -1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1635 } |
6625 | 1636 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1637 return -1; |
6625 | 1638 |
1639 // Reposition to just after the header | |
1640 is.seekg (128, std::ios::beg); | |
1641 } | |
1642 | |
4634 | 1643 return 0; |
1644 } | |
1645 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11580
diff
changeset
|
1646 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
|
1647 write_mat5_tag (std::ostream& is, int type, octave_idx_type bytes) |
4634 | 1648 { |
5828 | 1649 int32_t temp; |
4634 | 1650 |
6292 | 1651 if (bytes > 0 && bytes <= 4) |
4634 | 1652 temp = (bytes << 16) + type; |
1653 else | |
1654 { | |
1655 temp = type; | |
5760 | 1656 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
|
1657 goto data_write_error; |
4634 | 1658 temp = bytes; |
1659 } | |
1660 | |
5760 | 1661 if (! is.write (reinterpret_cast<char *> (&temp), 4)) |
4634 | 1662 goto data_write_error; |
1663 | |
1664 return 0; | |
1665 | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1666 data_write_error: |
4634 | 1667 return 1; |
1668 } | |
1669 | |
1670 // Have to use copy here to avoid writing over data accessed via | |
1671 // Matrix::data(). | |
1672 | |
5760 | 1673 #define MAT5_DO_WRITE(TYPE, data, count, stream) \ |
1674 do \ | |
1675 { \ | |
1676 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
|
1677 for (octave_idx_type i = 0; i < count; i++) \ |
5760 | 1678 ptr[i] = static_cast<TYPE> (data[i]); \ |
18725
9a6646cc7c3e
Fix load/save to handle up to 2^32-1 elements.
Rik <rik@octave.org>
parents:
18712
diff
changeset
|
1679 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:
18712
diff
changeset
|
1680 stream.write (reinterpret_cast<char *> (ptr), n_bytes); \ |
5760 | 1681 } \ |
4634 | 1682 while (0) |
1683 | |
10909
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1684 // 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
|
1685 // preceded by the appropriate tag. |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11580
diff
changeset
|
1686 static void |
10909
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1687 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
|
1688 { |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1689 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
|
1690 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
|
1691 |
4634 | 1692 if (save_as_floats) |
1693 { | |
1694 if (m.too_large_for_float ()) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1695 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1696 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
|
1697 warning ("save: saving as doubles instead"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1698 } |
4634 | 1699 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1700 st = LS_FLOAT; |
4634 | 1701 } |
1702 | |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1703 double max_val, min_val; |
4634 | 1704 if (m.all_integers (max_val, min_val)) |
1705 st = get_save_type (max_val, min_val); | |
1706 | |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1707 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
|
1708 int size; |
4634 | 1709 switch (st) |
1710 { | |
1711 default: | |
1712 case LS_DOUBLE: mst = miDOUBLE; size = 8; break; | |
1713 case LS_FLOAT: mst = miSINGLE; size = 4; break; | |
1714 case LS_U_CHAR: mst = miUINT8; size = 1; break; | |
1715 case LS_U_SHORT: mst = miUINT16; size = 2; break; | |
1716 case LS_U_INT: mst = miUINT32; size = 4; break; | |
1717 case LS_CHAR: mst = miINT8; size = 1; break; | |
1718 case LS_SHORT: mst = miINT16; size = 2; break; | |
1719 case LS_INT: mst = miINT32; size = 4; break; | |
1720 } | |
1721 | |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1722 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
|
1723 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
|
1724 |
4634 | 1725 write_mat5_tag (os, mst, len); |
1726 | |
1727 { | |
1728 switch (st) | |
1729 { | |
1730 case LS_U_CHAR: | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1731 MAT5_DO_WRITE (uint8_t, data, nel, os); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1732 break; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11580
diff
changeset
|
1733 |
4634 | 1734 case LS_U_SHORT: |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1735 MAT5_DO_WRITE (uint16_t, data, nel, os); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1736 break; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11580
diff
changeset
|
1737 |
4634 | 1738 case LS_U_INT: |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1739 MAT5_DO_WRITE (uint32_t, data, nel, os); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1740 break; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11580
diff
changeset
|
1741 |
4634 | 1742 case LS_U_LONG: |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1743 MAT5_DO_WRITE (uint64_t, data, nel, os); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1744 break; |
4634 | 1745 |
1746 case LS_CHAR: | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1747 MAT5_DO_WRITE (int8_t, data, nel, os); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1748 break; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11580
diff
changeset
|
1749 |
4634 | 1750 case LS_SHORT: |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1751 MAT5_DO_WRITE (int16_t, data, nel, os); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1752 break; |
4634 | 1753 |
1754 case LS_INT: | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1755 MAT5_DO_WRITE (int32_t, data, nel, os); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1756 break; |
4634 | 1757 |
1758 case LS_LONG: | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1759 MAT5_DO_WRITE (int64_t, data, nel, os); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1760 break; |
4634 | 1761 |
1762 case LS_FLOAT: | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1763 MAT5_DO_WRITE (float, data, nel, os); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1764 break; |
4634 | 1765 |
1766 case LS_DOUBLE: // No conversion necessary. | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1767 os.write (reinterpret_cast<const char *> (data), len); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1768 break; |
4634 | 1769 |
1770 default: | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1771 (*current_liboctave_error_handler) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1772 ("unrecognized data format requested"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1773 break; |
4634 | 1774 } |
1775 } | |
1776 if (PAD (len) > len) | |
1777 { | |
1778 static char buf[9]="\x00\x00\x00\x00\x00\x00\x00\x00"; | |
1779 os.write (buf, PAD (len) - len); | |
1780 } | |
1781 } | |
1782 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11580
diff
changeset
|
1783 static void |
10909
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1784 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
|
1785 { |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1786 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
|
1787 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
|
1788 |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1789 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
|
1790 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
|
1791 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
|
1792 |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1793 mat5_data_type mst; |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1794 int size; |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1795 switch (st) |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1796 { |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1797 default: |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1798 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
|
1799 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
|
1800 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
|
1801 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
|
1802 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
|
1803 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
|
1804 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
|
1805 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
|
1806 } |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1807 |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1808 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
|
1809 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
|
1810 |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1811 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
|
1812 |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1813 { |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1814 switch (st) |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1815 { |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1816 case LS_U_CHAR: |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1817 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
|
1818 break; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11580
diff
changeset
|
1819 |
10909
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1820 case LS_U_SHORT: |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1821 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
|
1822 break; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11580
diff
changeset
|
1823 |
10909
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1824 case LS_U_INT: |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1825 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
|
1826 break; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11580
diff
changeset
|
1827 |
10909
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1828 case LS_U_LONG: |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1829 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
|
1830 break; |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1831 |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1832 case LS_CHAR: |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1833 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
|
1834 break; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11580
diff
changeset
|
1835 |
10909
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1836 case LS_SHORT: |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1837 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
|
1838 break; |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1839 |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1840 case LS_INT: |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1841 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
|
1842 break; |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1843 |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1844 case LS_LONG: |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1845 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
|
1846 break; |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1847 |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1848 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
|
1849 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
|
1850 break; |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1851 |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1852 case LS_DOUBLE: |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1853 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
|
1854 break; |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1855 |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1856 default: |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1857 (*current_liboctave_error_handler) |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1858 ("unrecognized data format requested"); |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1859 break; |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1860 } |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1861 } |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1862 if (PAD (len) > len) |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1863 { |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1864 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
|
1865 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
|
1866 } |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1867 } |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
1868 |
5089 | 1869 template <class T> |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11580
diff
changeset
|
1870 void |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1871 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
|
1872 octave_idx_type nel) |
5089 | 1873 { |
1874 mat5_data_type mst; | |
1875 unsigned len; | |
1876 | |
1877 switch (size) | |
1878 { | |
1879 case 1: | |
1880 mst = miUINT8; | |
1881 break; | |
1882 case 2: | |
1883 mst = miUINT16; | |
1884 break; | |
5164 | 1885 case 4: |
5089 | 1886 mst = miUINT32; |
1887 break; | |
5164 | 1888 case 8: |
5089 | 1889 mst = miUINT64; |
1890 break; | |
1891 case -1: | |
1892 mst = miINT8; | |
1893 size = - size; | |
1894 break; | |
1895 case -2: | |
1896 mst = miINT16; | |
1897 size = - size; | |
1898 break; | |
5164 | 1899 case -4: |
5089 | 1900 mst = miINT32; |
1901 size = - size; | |
1902 break; | |
5164 | 1903 case -8: |
5089 | 1904 default: |
1905 mst = miINT64; | |
1906 size = - size; | |
1907 break; | |
1908 } | |
1909 | |
1910 len = nel*size; | |
1911 write_mat5_tag (os, mst, len); | |
1912 | |
5760 | 1913 os.write (reinterpret_cast<const char *> (m), len); |
5089 | 1914 |
1915 if (PAD (len) > len) | |
1916 { | |
1917 static char buf[9]="\x00\x00\x00\x00\x00\x00\x00\x00"; | |
1918 os.write (buf, PAD (len) - len); | |
1919 } | |
1920 } | |
1921 | |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1922 template void |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1923 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
|
1924 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
|
1925 |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1926 template void |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1927 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
|
1928 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
|
1929 |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1930 template void |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1931 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
|
1932 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
|
1933 |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1934 template void |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1935 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
|
1936 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
|
1937 |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1938 template void |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1939 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
|
1940 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
|
1941 |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1942 template void |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1943 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
|
1944 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
|
1945 |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1946 template void |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1947 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
|
1948 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
|
1949 |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1950 template void |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1951 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
|
1952 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
|
1953 |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1954 template void |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11580
diff
changeset
|
1955 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
|
1956 int size, octave_idx_type nel); |
5089 | 1957 |
4634 | 1958 // Write out cell element values in the cell array to OS, preceded by |
1959 // the appropriate tag. | |
1960 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11580
diff
changeset
|
1961 static bool |
4701 | 1962 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
|
1963 bool mark_as_global, bool save_as_floats) |
4634 | 1964 { |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1965 octave_idx_type nel = cell.numel (); |
4634 | 1966 |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1967 for (octave_idx_type i = 0; i < nel; i++) |
4634 | 1968 { |
1969 octave_value ov = cell(i); | |
1970 | |
1971 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
|
1972 false, save_as_floats)) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1973 return false; |
4634 | 1974 } |
1975 | |
1976 return true; | |
1977 } | |
1978 | |
5269 | 1979 int |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1980 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
|
1981 bool save_as_floats) |
5269 | 1982 { |
1983 if (nel > 0) | |
1984 { | |
1985 int size = 8; | |
1986 | |
1987 if (save_as_floats) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1988 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1989 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
|
1990 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
|
1991 { |
15020
560317fd5977
maint: Cuddle open bracket used for indexing C++ arrays in source code.
Rik <rik@octave.org>
parents:
14861
diff
changeset
|
1992 double tmp = val[i]; |
5269 | 1993 |
16971
259c1f295a1e
Use xfinite to replace some (isinf || isnan) instances in C++ code.
Rik <rik@octave.org>
parents:
16892
diff
changeset
|
1994 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
|
1995 && fabs (tmp) > std::numeric_limits<float>::max ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1996 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1997 too_large_for_float = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1998 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1999 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2000 } |
5269 | 2001 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2002 if (!too_large_for_float) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2003 size = 4; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2004 } |
5269 | 2005 |
2006 // 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
|
2007 // 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
|
2008 // get_save_type is changed. |
5269 | 2009 |
2010 // double max_val = val[0]; | |
2011 // double min_val = val[0]; | |
2012 // bool all_integers = true; | |
2013 // | |
2014 // for (int i = 0; i < nel; i++) | |
2015 // { | |
2016 // double val = val[i]; | |
2017 // | |
2018 // if (val > max_val) | |
2019 // max_val = val; | |
2020 // | |
2021 // if (val < min_val) | |
2022 // min_val = val; | |
2023 // | |
2024 // if (D_NINT (val) != val) | |
2025 // { | |
2026 // all_integers = false; | |
2027 // break; | |
2028 // } | |
2029 // } | |
2030 // | |
2031 // if (all_integers) | |
2032 // { | |
2033 // if (max_val < 256 && min_val > -1) | |
2034 // size = 1; | |
2035 // else if (max_val < 65536 && min_val > -1) | |
2036 // size = 2; | |
2037 // else if (max_val < 4294967295UL && min_val > -1) | |
2038 // size = 4; | |
2039 // else if (max_val < 128 && min_val >= -128) | |
2040 // size = 1; | |
2041 // else if (max_val < 32768 && min_val >= -32768) | |
2042 // size = 2; | |
2043 // else if (max_val <= 2147483647L && min_val >= -2147483647L) | |
2044 // size = 4; | |
2045 // } | |
2046 | |
2047 return 8 + nel * size; | |
2048 } | |
2049 else | |
2050 return 8; | |
2051 } | |
2052 | |
2053 int | |
11419
a4822f3d1032
Fix for saving of single precision arrays to the matlab file format
David Bateman <dbateman@free.fr>
parents:
10909
diff
changeset
|
2054 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
|
2055 { |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
2056 if (nel > 0) |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
2057 { |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
2058 int size = 4; |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
2059 |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
2060 |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
2061 // 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
|
2062 // 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
|
2063 // 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
|
2064 |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
2065 // 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
|
2066 // 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
|
2067 // bool all_integers = true; |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
2068 // |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
2069 // 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
|
2070 // { |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
2071 // float val = val[i]; |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
2072 // |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
2073 // if (val > max_val) |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
2074 // max_val = val; |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
2075 // |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
2076 // if (val < min_val) |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
2077 // min_val = val; |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
2078 // |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
2079 // 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
|
2080 // { |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
2081 // all_integers = false; |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
2082 // break; |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
2083 // } |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
2084 // } |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
2085 // |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
2086 // if (all_integers) |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
2087 // { |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
2088 // 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
|
2089 // size = 1; |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
2090 // 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
|
2091 // size = 2; |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
2092 // 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
|
2093 // size = 4; |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
2094 // 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
|
2095 // size = 1; |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
2096 // 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
|
2097 // size = 2; |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
2098 // 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
|
2099 // size = 4; |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
2100 // } |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
2101 |
11468
e1edf0ba3bcb
Yet another single precision matlab file fix
David Bateman <dbateman@free.fr>
parents:
11419
diff
changeset
|
2102 // 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
|
2103 // Short tags for 4 byte elements. |
e1edf0ba3bcb
Yet another single precision matlab file fix
David Bateman <dbateman@free.fr>
parents:
11419
diff
changeset
|
2104 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
|
2105 } |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
2106 else |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
2107 return 8; |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
2108 } |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
2109 |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
2110 int |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2111 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
|
2112 bool save_as_floats) |
5269 | 2113 { |
2114 int ret; | |
2115 | |
2116 OCTAVE_LOCAL_BUFFER (double, tmp, nel); | |
2117 | |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2118 for (octave_idx_type i = 1; i < nel; i++) |
5269 | 2119 tmp[i] = std::real (val[i]); |
2120 | |
2121 ret = save_mat5_array_length (tmp, nel, save_as_floats); | |
2122 | |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2123 for (octave_idx_type i = 1; i < nel; i++) |
5269 | 2124 tmp[i] = std::imag (val[i]); |
2125 | |
2126 ret += save_mat5_array_length (tmp, nel, save_as_floats); | |
2127 | |
2128 return ret; | |
2129 } | |
2130 | |
2131 int | |
10909
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
2132 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
|
2133 bool save_as_floats) |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
2134 { |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
2135 int ret; |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
2136 |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
2137 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
|
2138 |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
2139 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
|
2140 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
|
2141 |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
2142 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
|
2143 |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
2144 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
|
2145 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
|
2146 |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
2147 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
|
2148 |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
2149 return ret; |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
2150 } |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
2151 |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
2152 int |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11580
diff
changeset
|
2153 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
|
2154 bool save_as_floats, bool mat7_format) |
5269 | 2155 { |
16303
085976d9ef08
Fix saving names >31 characters to -v6 format (bug #34676)
Rik <rik@octave.org>
parents:
16226
diff
changeset
|
2156 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
|
2157 size_t len = name.length (); |
5269 | 2158 std::string cname = tc.class_name (); |
2159 int ret = 32; | |
2160 | |
2161 if (len > 4) | |
2162 ret += PAD (len > max_namelen ? max_namelen : len); | |
2163 | |
2164 ret += PAD (4 * tc.ndims ()); | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11580
diff
changeset
|
2165 |
5269 | 2166 if (tc.is_string ()) |
2167 { | |
5933 | 2168 charNDArray chm = tc.char_array_value (); |
5384 | 2169 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
|
2170 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
|
2171 ret += PAD (2 * chm.numel ()); |
5269 | 2172 } |
6823 | 2173 else if (tc.is_sparse_type ()) |
5269 | 2174 { |
2175 if (tc.is_complex_type ()) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2176 { |
11468
e1edf0ba3bcb
Yet another single precision matlab file fix
David Bateman <dbateman@free.fr>
parents:
11419
diff
changeset
|
2177 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
|
2178 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
|
2179 octave_idx_type nnz = m.nnz (); |
5269 | 2180 |
10623
0e98fb2068fc
Fix error when saving sparse arrays to matlab files (bug #29786)
David Bateman <dbateman@free.fr>
parents:
10350
diff
changeset
|
2181 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
|
2182 if (nnz > 1) |
0e98fb2068fc
Fix error when saving sparse arrays to matlab files (bug #29786)
David Bateman <dbateman@free.fr>
parents:
10350
diff
changeset
|
2183 ret += PAD (nnz * sizeof (int32_t)); |
10624
3eafa521550b
minor typo in previous changeset
David Bateman <dbateman@free.fr>
parents:
10623
diff
changeset
|
2184 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
|
2185 ret += PAD ((nc + 1) * sizeof (int32_t)); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2186 } |
5269 | 2187 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2188 { |
11468
e1edf0ba3bcb
Yet another single precision matlab file fix
David Bateman <dbateman@free.fr>
parents:
11419
diff
changeset
|
2189 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
|
2190 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
|
2191 octave_idx_type nnz = m.nnz (); |
5269 | 2192 |
10623
0e98fb2068fc
Fix error when saving sparse arrays to matlab files (bug #29786)
David Bateman <dbateman@free.fr>
parents:
10350
diff
changeset
|
2193 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
|
2194 if (nnz > 1) |
0e98fb2068fc
Fix error when saving sparse arrays to matlab files (bug #29786)
David Bateman <dbateman@free.fr>
parents:
10350
diff
changeset
|
2195 ret += PAD (nnz * sizeof (int32_t)); |
10624
3eafa521550b
minor typo in previous changeset
David Bateman <dbateman@free.fr>
parents:
10623
diff
changeset
|
2196 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
|
2197 ret += PAD ((nc + 1) * sizeof (int32_t)); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2198 } |
5269 | 2199 } |
2200 | |
2201 #define INT_LEN(nel, size) \ | |
2202 { \ | |
2203 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
|
2204 octave_idx_type sz = nel * size; \ |
5269 | 2205 if (sz > 4) \ |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2206 ret += PAD (sz); \ |
5269 | 2207 } |
2208 | |
2209 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
|
2210 INT_LEN (tc.int8_array_value ().numel (), 1) |
5269 | 2211 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
|
2212 INT_LEN (tc.int16_array_value ().numel (), 2) |
5269 | 2213 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
|
2214 INT_LEN (tc.int32_array_value ().numel (), 4) |
5269 | 2215 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
|
2216 INT_LEN (tc.int64_array_value ().numel (), 8) |
5269 | 2217 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
|
2218 INT_LEN (tc.uint8_array_value ().numel (), 1) |
5269 | 2219 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
|
2220 INT_LEN (tc.uint16_array_value ().numel (), 2) |
5269 | 2221 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
|
2222 INT_LEN (tc.uint32_array_value ().numel (), 4) |
5269 | 2223 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
|
2224 INT_LEN (tc.uint64_array_value ().numel (), 8) |
5269 | 2225 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
|
2226 INT_LEN (tc.bool_array_value ().numel (), 1) |
5269 | 2227 else if (tc.is_real_scalar () || tc.is_real_matrix () || tc.is_range ()) |
2228 { | |
10909
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
2229 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
|
2230 { |
11468
e1edf0ba3bcb
Yet another single precision matlab file fix
David Bateman <dbateman@free.fr>
parents:
11419
diff
changeset
|
2231 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
|
2232 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
|
2233 save_as_floats); |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
2234 } |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
2235 else |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
2236 { |
11468
e1edf0ba3bcb
Yet another single precision matlab file fix
David Bateman <dbateman@free.fr>
parents:
11419
diff
changeset
|
2237 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
|
2238 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
|
2239 save_as_floats); |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
2240 } |
5269 | 2241 } |
2242 else if (tc.is_cell ()) | |
2243 { | |
2244 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
|
2245 octave_idx_type nel = cell.numel (); |
5269 | 2246 |
2247 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
|
2248 ret += 8 + |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2249 save_mat5_element_length (cell (i), "", save_as_floats, mat7_format); |
5269 | 2250 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11580
diff
changeset
|
2251 else if (tc.is_complex_scalar () || tc.is_complex_matrix ()) |
5269 | 2252 { |
10909
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
2253 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
|
2254 { |
11468
e1edf0ba3bcb
Yet another single precision matlab file fix
David Bateman <dbateman@free.fr>
parents:
11419
diff
changeset
|
2255 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
|
2256 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
|
2257 save_as_floats); |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
2258 } |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
2259 else |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11580
diff
changeset
|
2260 { |
11468
e1edf0ba3bcb
Yet another single precision matlab file fix
David Bateman <dbateman@free.fr>
parents:
11419
diff
changeset
|
2261 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
|
2262 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
|
2263 save_as_floats); |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
2264 } |
5269 | 2265 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11580
diff
changeset
|
2266 else if (tc.is_map () || tc.is_inline_function () || tc.is_object ()) |
5269 | 2267 { |
2268 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
|
2269 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
|
2270 octave_idx_type nel = m.numel (); |
5269 | 2271 |
6625 | 2272 if (tc.is_inline_function ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2273 // length of "inline" is 6 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2274 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
|
2275 else if (tc.is_object ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2276 { |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2277 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
|
2278 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2279 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
|
2280 } |
6625 | 2281 |
16871
5e30b1c950b8
Replace uses of Octave_map with octave_map or octave_scalar_map.
Rik <rik@octave.org>
parents:
16670
diff
changeset
|
2282 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
|
2283 fieldcnt++; |
5269 | 2284 |
2285 ret += 16 + fieldcnt * (max_namelen + 1); | |
2286 | |
2287 | |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2288 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
|
2289 { |
5269 | 2290 |
16871
5e30b1c950b8
Replace uses of Octave_map with octave_map or octave_scalar_map.
Rik <rik@octave.org>
parents:
16670
diff
changeset
|
2291 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
|
2292 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2293 const Cell elts = m.contents (i); |
5269 | 2294 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11580
diff
changeset
|
2295 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
|
2296 save_as_floats, mat7_format); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2297 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2298 } |
5269 | 2299 } |
2300 else | |
2301 ret = -1; | |
2302 | |
2303 return ret; | |
2304 } | |
2305 | |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2306 static void |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2307 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
|
2308 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
|
2309 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
|
2310 { |
10623
0e98fb2068fc
Fix error when saving sparse arrays to matlab files (bug #29786)
David Bateman <dbateman@free.fr>
parents:
10350
diff
changeset
|
2311 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
|
2312 |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2313 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
|
2314 |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2315 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
|
2316 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
|
2317 |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2318 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
|
2319 } |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2320 |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2321 static void |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2322 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
|
2323 { |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2324 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
|
2325 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
|
2326 } |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2327 |
4634 | 2328 // save the data from TC along with the corresponding NAME on stream |
2329 // OS in the MatLab version 5 binary format. Return true on success. | |
2330 | |
2331 bool | |
2332 save_mat5_binary_element (std::ostream& os, | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2333 const octave_value& tc, const std::string& name, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2334 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
|
2335 bool save_as_floats, bool compressing) |
4634 | 2336 { |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2337 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
|
2338 int32_t nnz_32 = 0; |
5089 | 2339 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
|
2340 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
|
2341 |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2342 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
|
2343 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
|
2344 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
|
2345 |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2346 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
|
2347 |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2348 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
|
2349 { |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2350 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
|
2351 { |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2352 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
|
2353 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
|
2354 } |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2355 } |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2356 |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2357 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
|
2358 { |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2359 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
|
2360 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
|
2361 |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2362 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
|
2363 { |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2364 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
|
2365 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
|
2366 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
|
2367 } |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2368 else |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2369 { |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2370 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
|
2371 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
|
2372 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
|
2373 } |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2374 |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2375 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
|
2376 { |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2377 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
|
2378 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
|
2379 } |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2380 |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2381 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
|
2382 } |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2383 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
|
2384 { |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2385 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
|
2386 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
|
2387 } |
5269 | 2388 |
2389 #ifdef HAVE_ZLIB | |
2390 if (mat7_format && !compressing) | |
2391 { | |
2392 bool ret = false; | |
2393 | |
5765 | 2394 std::ostringstream buf; |
5269 | 2395 |
2396 // The code seeks backwards in the stream to fix the header. Can't | |
2397 // do this with zlib, so use a stringstream. | |
2398 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
|
2399 save_as_floats, true); |
5269 | 2400 |
2401 if (ret) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2402 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11580
diff
changeset
|
2403 // 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
|
2404 // + 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
|
2405 std::string buf_str = buf.str (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2406 uLongf srcLen = buf_str.length (); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11580
diff
changeset
|
2407 uLongf destLen = srcLen * 101 / 100 + 12; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2408 OCTAVE_LOCAL_BUFFER (char, out_buf, destLen); |
5269 | 2409 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11580
diff
changeset
|
2410 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
|
2411 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
|
2412 srcLen) |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2413 == Z_OK) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2414 { |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2415 write_mat5_tag (os, miCOMPRESSED, |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11580
diff
changeset
|
2416 static_cast<octave_idx_type> (destLen)); |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2417 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2418 os.write (out_buf, destLen); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2419 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2420 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2421 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2422 error ("save: error compressing data element"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2423 ret = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2424 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2425 } |
5269 | 2426 |
2427 return ret; | |
2428 } | |
2429 #endif | |
4634 | 2430 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11580
diff
changeset
|
2431 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
|
2432 (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
|
2433 |
4634 | 2434 // array flags subelement |
2435 write_mat5_tag (os, miUINT32, 8); | |
2436 | |
5269 | 2437 if (tc.is_bool_type ()) |
2438 flags |= 0x0200; | |
2439 | |
4634 | 2440 if (mark_as_global) |
2441 flags |= 0x0400; | |
2442 | |
2443 if (tc.is_complex_scalar () || tc.is_complex_matrix ()) | |
2444 flags |= 0x0800; | |
2445 | |
2446 if (tc.is_string ()) | |
5900 | 2447 flags |= MAT_FILE_CHAR_CLASS; |
5089 | 2448 else if (cname == "int8") |
5900 | 2449 flags |= MAT_FILE_INT8_CLASS; |
5089 | 2450 else if (cname == "int16") |
5900 | 2451 flags |= MAT_FILE_INT16_CLASS; |
5089 | 2452 else if (cname == "int32") |
5900 | 2453 flags |= MAT_FILE_INT32_CLASS; |
5089 | 2454 else if (cname == "int64") |
5900 | 2455 flags |= MAT_FILE_INT64_CLASS; |
5269 | 2456 else if (cname == "uint8" || tc.is_bool_type ()) |
5900 | 2457 flags |= MAT_FILE_UINT8_CLASS; |
5089 | 2458 else if (cname == "uint16") |
5900 | 2459 flags |= MAT_FILE_UINT16_CLASS; |
5089 | 2460 else if (cname == "uint32") |
5900 | 2461 flags |= MAT_FILE_UINT32_CLASS; |
5089 | 2462 else if (cname == "uint64") |
5900 | 2463 flags |= MAT_FILE_UINT64_CLASS; |
6823 | 2464 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
|
2465 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
|
2466 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
|
2467 || 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
|
2468 { |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
2469 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
|
2470 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
|
2471 else |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
2472 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
|
2473 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11580
diff
changeset
|
2474 else if (tc.is_map ()) |
5900 | 2475 flags |= MAT_FILE_STRUCT_CLASS; |
4634 | 2476 else if (tc.is_cell ()) |
5900 | 2477 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
|
2478 else if (tc.is_inline_function () || tc.is_object ()) |
6625 | 2479 flags |= MAT_FILE_OBJECT_CLASS; |
4634 | 2480 else |
2481 { | |
2482 gripe_wrong_type_arg ("save", tc, false); | |
2483 goto error_cleanup; | |
2484 } | |
2485 | |
5760 | 2486 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
|
2487 // 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
|
2488 // 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
|
2489 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
|
2490 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
|
2491 os.write (reinterpret_cast<char *> (&nnz_32), 4); |
4634 | 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_tag (os, miINT32, dim_len); |
4634 | 2494 |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2495 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
|
2496 { |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2497 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
|
2498 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
|
2499 } |
4638 | 2500 |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2501 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
|
2502 { |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2503 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
|
2504 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
|
2505 } |
4634 | 2506 |
2507 // array name subelement | |
2508 { | |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2509 size_t namelen = name.length (); |
4634 | 2510 |
5269 | 2511 if (namelen > max_namelen) |
16303
085976d9ef08
Fix saving names >31 characters to -v6 format (bug #34676)
Rik <rik@octave.org>
parents:
16226
diff
changeset
|
2512 namelen = max_namelen; // Truncate names if necessary |
4634 | 2513 |
2514 int paddedlength = PAD (namelen); | |
2515 | |
2516 write_mat5_tag (os, miINT8, namelen); | |
2517 OCTAVE_LOCAL_BUFFER (char, paddedname, paddedlength); | |
2518 memset (paddedname, 0, paddedlength); | |
2519 strncpy (paddedname, name.c_str (), namelen); | |
2520 os.write (paddedname, paddedlength); | |
2521 } | |
2522 | |
2523 // data element | |
2524 if (tc.is_string ()) | |
2525 { | |
5933 | 2526 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
|
2527 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
|
2528 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
|
2529 octave_idx_type paddedlength = PAD (len); |
4634 | 2530 |
5933 | 2531 OCTAVE_LOCAL_BUFFER (int16_t, buf, nel+3); |
4634 | 2532 write_mat5_tag (os, miUINT16, len); |
2533 | |
5933 | 2534 const char *s = chm.data (); |
4634 | 2535 |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2536 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
|
2537 buf[i] = *s++ & 0x00FF; |
5933 | 2538 |
2539 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
|
2540 |
4634 | 2541 if (paddedlength > len) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2542 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2543 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
|
2544 os.write (padbuf, paddedlength - len); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2545 } |
4634 | 2546 } |
6823 | 2547 else if (tc.is_sparse_type ()) |
5164 | 2548 { |
2549 if (tc.is_complex_type ()) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2550 { |
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
|
2551 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
|
2552 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
|
2553 octave_idx_type nc = m.cols (); |
5164 | 2554 |
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
|
2555 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
|
2556 write_mat5_sparse_index_vector (os, m.cidx (), nc + 1); |
5164 | 2557 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2558 NDArray buf (dim_vector (nnz, 1)); |
5164 | 2559 |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2560 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
|
2561 buf (i) = std::real (m.data (i)); |
5164 | 2562 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2563 write_mat5_array (os, buf, save_as_floats); |
5164 | 2564 |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2565 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
|
2566 buf (i) = std::imag (m.data (i)); |
5164 | 2567 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2568 write_mat5_array (os, buf, save_as_floats); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2569 } |
5164 | 2570 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2571 { |
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
|
2572 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
|
2573 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
|
2574 octave_idx_type nc = m.cols (); |
5164 | 2575 |
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
|
2576 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
|
2577 write_mat5_sparse_index_vector (os, m.cidx (), nc + 1); |
5164 | 2578 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2579 // FIXME |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2580 // 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
|
2581 NDArray buf (dim_vector (nnz, 1)); |
5164 | 2582 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2583 for (int i = 0; i < nnz; i++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2584 buf (i) = m.data (i); |
5164 | 2585 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2586 write_mat5_array (os, buf, save_as_floats); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2587 } |
5164 | 2588 } |
5089 | 2589 else if (cname == "int8") |
2590 { | |
2591 int8NDArray m = tc.int8_array_value (); | |
2592 | |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2593 write_mat5_integer_data (os, m.fortran_vec (), -1, m.numel ()); |
5089 | 2594 } |
2595 else if (cname == "int16") | |
2596 { | |
2597 int16NDArray m = tc.int16_array_value (); | |
2598 | |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2599 write_mat5_integer_data (os, m.fortran_vec (), -2, m.numel ()); |
5089 | 2600 } |
2601 else if (cname == "int32") | |
2602 { | |
2603 int32NDArray m = tc.int32_array_value (); | |
2604 | |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2605 write_mat5_integer_data (os, m.fortran_vec (), -4, m.numel ()); |
5089 | 2606 } |
2607 else if (cname == "int64") | |
2608 { | |
2609 int64NDArray m = tc.int64_array_value (); | |
2610 | |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2611 write_mat5_integer_data (os, m.fortran_vec (), -8, m.numel ()); |
5089 | 2612 } |
2613 else if (cname == "uint8") | |
2614 { | |
2615 uint8NDArray m = tc.uint8_array_value (); | |
2616 | |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2617 write_mat5_integer_data (os, m.fortran_vec (), 1, m.numel ()); |
5089 | 2618 } |
2619 else if (cname == "uint16") | |
2620 { | |
2621 uint16NDArray m = tc.uint16_array_value (); | |
2622 | |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2623 write_mat5_integer_data (os, m.fortran_vec (), 2, m.numel ()); |
5089 | 2624 } |
2625 else if (cname == "uint32") | |
2626 { | |
2627 uint32NDArray m = tc.uint32_array_value (); | |
2628 | |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2629 write_mat5_integer_data (os, m.fortran_vec (), 4, m.numel ()); |
5089 | 2630 } |
2631 else if (cname == "uint64") | |
2632 { | |
2633 uint64NDArray m = tc.uint64_array_value (); | |
2634 | |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2635 write_mat5_integer_data (os, m.fortran_vec (), 8, m.numel ()); |
5089 | 2636 } |
5269 | 2637 else if (tc.is_bool_type ()) |
2638 { | |
2639 uint8NDArray m (tc.bool_array_value ()); | |
2640 | |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2641 write_mat5_integer_data (os, m.fortran_vec (), 1, m.numel ()); |
5269 | 2642 } |
4634 | 2643 else if (tc.is_real_scalar () || tc.is_real_matrix () || tc.is_range ()) |
2644 { | |
10909
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
2645 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
|
2646 { |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
2647 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
|
2648 |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
2649 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
|
2650 } |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
2651 else |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
2652 { |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
2653 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
|
2654 |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
2655 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
|
2656 } |
4634 | 2657 } |
2658 else if (tc.is_cell ()) | |
2659 { | |
2660 Cell cell = tc.cell_value (); | |
2661 | |
2662 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
|
2663 goto error_cleanup; |
4634 | 2664 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11580
diff
changeset
|
2665 else if (tc.is_complex_scalar () || tc.is_complex_matrix ()) |
4634 | 2666 { |
10909
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
2667 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
|
2668 { |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
2669 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
|
2670 |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
2671 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
|
2672 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
|
2673 } |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
2674 else |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
2675 { |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
2676 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
|
2677 |
ac43a9df78d6
Load/save single precision variables to mat-files (bug #30800)
David Bateman <dbateman@free.fr>
parents:
10624
diff
changeset
|
2678 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
|
2679 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
|
2680 } |
4634 | 2681 } |
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
|
2682 else if (tc.is_map () || tc.is_inline_function () || tc.is_object ()) |
4634 | 2683 { |
8212
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8007
diff
changeset
|
2684 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
|
2685 { |
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
|
2686 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
|
2687 size_t namelen = classname.length (); |
6625 | 2688 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2689 if (namelen > max_namelen) |
16303
085976d9ef08
Fix saving names >31 characters to -v6 format (bug #34676)
Rik <rik@octave.org>
parents:
16226
diff
changeset
|
2690 namelen = max_namelen; // Truncate names if necessary |
6625 | 2691 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2692 int paddedlength = PAD (namelen); |
6625 | 2693 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2694 write_mat5_tag (os, miINT8, namelen); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2695 OCTAVE_LOCAL_BUFFER (char, paddedname, paddedlength); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2696 memset (paddedname, 0, paddedlength); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2697 strncpy (paddedname, classname.c_str (), namelen); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2698 os.write (paddedname, paddedlength); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2699 } |
6625 | 2700 |
16871
5e30b1c950b8
Replace uses of Octave_map with octave_map or octave_scalar_map.
Rik <rik@octave.org>
parents:
16670
diff
changeset
|
2701 octave_map m; |
8212
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8007
diff
changeset
|
2702 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2703 if (tc.is_object () |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2704 && load_path::find_method (tc.class_name (), |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2705 "saveobj") != std::string ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2706 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2707 octave_value_list tmp = feval ("saveobj", tc, 1); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2708 if (! error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2709 m = tmp(0).map_value (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2710 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2711 goto error_cleanup; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2712 } |
8212
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8007
diff
changeset
|
2713 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2714 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
|
2715 |
4634 | 2716 // an Octave structure */ |
2717 // recursively write each element of the structure | |
2718 { | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2719 char buf[64]; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2720 int32_t maxfieldnamelength = max_namelen + 1; |
4634 | 2721 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2722 octave_idx_type nf = m.nfields (); |
8907
5a956c026b6c
preserve field order when saving structs
John W. Eaton <jwe@octave.org>
parents:
8377
diff
changeset
|
2723 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2724 write_mat5_tag (os, miINT32, 4); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2725 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
|
2726 write_mat5_tag (os, miINT8, nf*maxfieldnamelength); |
4634 | 2727 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2728 // 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
|
2729 // the fields. |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2730 string_vector keys = m.keys (); |
8907
5a956c026b6c
preserve field order when saving structs
John W. Eaton <jwe@octave.org>
parents:
8377
diff
changeset
|
2731 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2732 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
|
2733 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2734 std::string key = keys(i); |
8907
5a956c026b6c
preserve field order when saving structs
John W. Eaton <jwe@octave.org>
parents:
8377
diff
changeset
|
2735 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2736 // write the name of each element |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2737 memset (buf, 0, max_namelen + 1); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2738 // only 31 or 63 char names permitted |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2739 strncpy (buf, key.c_str (), max_namelen); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2740 os.write (buf, max_namelen + 1); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2741 } |
4634 | 2742 |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2743 octave_idx_type len = m.numel (); |
4634 | 2744 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2745 // Create temporary copy of structure contents to avoid |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2746 // multiple calls of the contents method. |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2747 std::vector<const octave_value *> elts (nf); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2748 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
|
2749 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
|
2750 |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
2751 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
|
2752 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2753 // write the data of each element |
4634 | 2754 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2755 // 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
|
2756 // of the fields. |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2757 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
|
2758 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2759 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
|
2760 mark_as_global, |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11580
diff
changeset
|
2761 false, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2762 save_as_floats); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2763 if (! retval2) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2764 goto error_cleanup; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2765 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2766 } |
4634 | 2767 } |
2768 } | |
2769 else | |
2770 gripe_wrong_type_arg ("save", tc, false); | |
2771 | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2772 skip_to_next: |
4634 | 2773 return true; |
2774 | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2775 error_cleanup: |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
2776 error ("save: error while writing '%s' to MAT file", name.c_str ()); |
4634 | 2777 |
2778 return false; | |
2779 } |