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