annotate src/ls-mat5.cc @ 10454:79a56d0a6a0d ss-3-3-51

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