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