annotate libinterp/interp-core/ls-mat5.cc @ 16226:40cf0a292b20

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