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