annotate libinterp/corefcn/ls-mat5.cc @ 27277:db687716fed6

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