annotate main/fixed/src/ov-fixed-mat.cc @ 2383:d1930f8af7ca octave-forge

Changed the directory structure of fixed to match the package system
author hauberg
date Sun, 20 Aug 2006 14:43:38 +0000
parents
children 1728eb2120ef
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2383
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
1 /*
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
2
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
3 Copyright (C) 2003 Motorola Inc
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
4 Copyright (C) 2003 David Bateman
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
5
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
6 This program is free software; you can redistribute it and/or modify it
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
7 under the terms of the GNU General Public License as published by the
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
8 Free Software Foundation; either version 2, or (at your option) any
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
9 later version.
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
10
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
11 This program is distributed in the hope that it will be useful, but WITHOUT
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
14 for more details.
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
15
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
16 You should have received a copy of the GNU General Public License
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
17 along with this program; see the file COPYING. If not, write to the Free
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
18 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
19
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
20 In addition to the terms of the GPL, you are permitted to link
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
21 this program with any Open Source program, as defined by the
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
22 Open Source Initiative (www.opensource.org)
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
23
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
24 */
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
25
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
26 #if defined (__GNUG__) && defined (USE_PRAGMA_INTERFACE_IMPLEMENTATION)
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
27 #pragma implementation
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
28 #endif
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
29
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
30 #include <climits>
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
31 #include <iostream>
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
32 #include <iomanip>
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
33
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
34 #include <octave/config.h>
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
35 #include <octave/oct-obj.h>
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
36 #include <octave/ov.h>
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
37 #include <octave/lo-ieee.h>
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
38 #include <octave/gripes.h>
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
39 #include <octave/unwind-prot.h>
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
40 #include <octave/cmd-edit.h>
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
41 #include <octave/parse.h>
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
42 #include <octave/utils.h>
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
43 #include <octave/unwind-prot.h>
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
44 #include <octave/variables.h>
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
45 #ifdef CLASS_HAS_LOAD_SAVE
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
46 #include <octave/ls-oct-ascii.h>
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
47 #include <octave/byte-swap.h>
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
48 #endif
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
49
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
50 #ifdef NEED_OCTAVE_QUIT
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
51 #define OCTAVE_QUIT do {} while (0)
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
52 #else
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
53 #include <octave/quit.h>
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
54 #endif
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
55
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
56 #include <memory>
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
57 #ifndef OCTAVE_LOCAL_BUFFER
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
58 #define OCTAVE_LOCAL_BUFFER(T, buf, size) \
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
59 std::auto_ptr<T> buf ## _auto_ptr (new T [size]); \
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
60 T *buf = buf ## _auto_ptr.get ()
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
61 #endif
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
62
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
63 #include "fixed-def.h"
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
64 #include "ov-base-fixed-mat.h"
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
65 #include "ov-base-fixed-mat.cc"
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
66 #include "int/fixed.h"
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
67 #include "fixed-var.h"
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
68 #include "ov-fixed.h"
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
69 #include "ov-fixed-mat.h"
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
70 #include "fixed-conv.h"
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
71
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
72 #if ! defined (UCHAR_MAX)
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
73 #define UCHAR_MAX 255
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
74 #endif
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
75
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
76 template class octave_base_fixed_matrix<FixedMatrix>;
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
77
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
78 DEFINE_OCTAVE_ALLOCATOR (octave_fixed_matrix);
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
79
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
80 #ifdef TYPEID_HAS_CLASS
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
81 DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (octave_fixed_matrix, "fixed matrix",
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
82 "FixedPoint");
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
83 #else
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
84 DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (octave_fixed_matrix, "fixed matrix");
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
85 #endif
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
86
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
87 #ifdef HAVE_ND_ARRAYS
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
88 NDArray
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
89 octave_fixed_matrix::array_value (bool) const
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
90 {
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
91 int nr = rows ();
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
92 int nc = columns ();
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
93 dim_vector dv(nr,nc);
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
94 NDArray retval (dv);
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
95
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
96 for (int i=0; i<nr; i++)
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
97 for (int j=0; j<nc; j++)
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
98 retval(i + j*nr) = matrix(i,j).fixedpoint();
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
99
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
100 return retval;
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
101 }
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
102
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
103 ComplexNDArray
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
104 octave_fixed_matrix::complex_array_value (bool) const
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
105 {
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
106 int nr = rows ();
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
107 int nc = columns ();
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
108 dim_vector dv(nr,nc);
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
109 ComplexNDArray retval (dv);
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
110
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
111 for (int i=0; i<nr; i++)
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
112 for (int j=0; j<nc; j++)
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
113 retval(i + j*nr) = matrix(i,j).fixedpoint();
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
114
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
115 return retval;
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
116 }
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
117 #endif
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
118
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
119 #if defined (HAVE_OCTAVE_CONCAT) || defined (HAVE_OLD_OCTAVE_CONCAT)
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
120 octave_value
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
121 octave_fixed_matrix::resize (const dim_vector& dv, bool) const
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
122 {
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
123 if (dv.length() > 2)
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
124 {
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
125 error ("Can not resize fixed point to NDArray");
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
126 return octave_value ();
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
127 }
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
128 FixedMatrix retval (matrix);
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
129 retval.resize (dv(0), dv(1));
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
130 return new octave_fixed_matrix (retval);
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
131 }
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
132 #endif
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
133
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
134 FixedMatrix
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
135 octave_fixed_matrix::do_index_intern (const octave_value_list& idx,
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
136 int resize_ok)
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
137 {
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
138 FixedMatrix retval;
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
139
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
140 int len = idx.length ();
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
141
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
142 switch (len)
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
143 {
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
144 case 2:
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
145 {
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
146 idx_vector i = idx (0).index_vector ();
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
147 idx_vector j = idx (1).index_vector ();
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
148 retval = FixedMatrix(matrix.index (i, j, resize_ok));
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
149 }
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
150 break;
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
151
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
152 case 1:
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
153 {
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
154 idx_vector i = idx (0).index_vector ();
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
155 retval = FixedMatrix(matrix.index (i, resize_ok));
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
156 }
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
157 break;
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
158
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
159 default:
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
160 {
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
161 std::string n = type_name ();
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
162
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
163 error ("invalid number of indices (%d) for %s value",
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
164 len, n.c_str ());
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
165 }
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
166 break;
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
167 }
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
168
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
169 return retval;
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
170 }
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
171
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
172
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
173 octave_value
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
174 octave_fixed_matrix::do_index_op (const octave_value_list& idx,
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
175 int resize_ok)
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
176 {
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
177 octave_value retval;
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
178
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
179 FixedMatrix new_matrix = do_index_intern (idx, resize_ok);
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
180
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
181 if (!error_state) {
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
182 retval = new octave_fixed_matrix ( new_matrix);
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
183 retval.maybe_mutate();
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
184 }
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
185
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
186 return retval;
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
187 }
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
188
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
189 octave_value
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
190 octave_fixed_matrix::subsasgn (const std::string& type,
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
191 const std::list<octave_value_list>& idx,
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
192 const octave_value& rhs)
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
193 {
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
194 octave_value retval;
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
195
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
196 switch (type[0])
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
197 {
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
198 case '(':
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
199 {
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
200 std::string nm = type_name ();
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
201 if (type.length () == 1)
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
202 retval = numeric_assign (type, idx, rhs);
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
203 else if (type.length () == 2)
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
204 {
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
205 std::list<octave_value_list>::const_iterator p = idx.begin ();
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
206 octave_value_list key_idx = *++p;
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
207
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
208 assert (key_idx.length () == 1);
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
209
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
210 std::string key = key_idx(0).string_value ();
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
211
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
212 if (key == __FIXED_SIGN_STR)
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
213 error("can not directly change the sign in a fixed structure");
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
214 else if (key == __FIXED_VALUE_STR)
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
215 error("can not directly change the value of a fixed structure");
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
216 else if (key == __FIXED_DECSIZE_STR) {
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
217 if (rhs.is_matrix_type()) {
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
218 FixedMatrix old_matrix = do_index_intern(idx.front(), 0);
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
219 octave_value new_matrix = new octave_fixed_matrix(
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
220 old_matrix.chdecsize(rhs.matrix_value()));
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
221 retval = numeric_assign (type, idx, new_matrix);
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
222 } else {
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
223 FixedMatrix old_matrix = do_index_intern(idx.front(), 0);
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
224 octave_value new_matrix = new octave_fixed_matrix(
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
225 old_matrix.chdecsize(rhs.double_value()));
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
226 retval = numeric_assign (type, idx, new_matrix);
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
227 }
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
228 } else if (key == __FIXED_INTSIZE_STR) {
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
229 if (rhs.is_matrix_type()) {
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
230 FixedMatrix old_matrix = do_index_intern(idx.front(), 0);
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
231 octave_value new_matrix = new octave_fixed_matrix(
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
232 old_matrix.chintsize(rhs.matrix_value()));
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
233 retval = numeric_assign (type, idx, new_matrix);
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
234 } else {
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
235 FixedMatrix old_matrix = do_index_intern(idx.front(), 0);
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
236 octave_value new_matrix = new octave_fixed_matrix(
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
237 old_matrix.chintsize(rhs.double_value()));
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
238 retval = numeric_assign (type, idx, new_matrix);
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
239 }
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
240 } else
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
241 error ("fixed point structure has no member `%s'",
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
242 key.c_str ());
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
243 }
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
244 else
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
245 error ("in indexed assignment of %s, illegal assignment",
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
246 nm.c_str ());
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
247 }
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
248 break;
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
249
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
250 case '.':
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
251 {
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
252 octave_value_list key_idx = idx.front ();
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
253
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
254 assert (key_idx.length () == 1);
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
255
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
256 std::string key = key_idx(0).string_value ();
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
257
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
258 if (key == __FIXED_SIGN_STR)
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
259 error("can not directly change the sign in a fixed structure");
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
260 else if (key == __FIXED_VALUE_STR)
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
261 error("can not directly change the value of a fixed structure");
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
262 else if (key == __FIXED_DECSIZE_STR) {
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
263 if (rhs.is_matrix_type())
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
264 retval = new octave_fixed_matrix (matrix.chdecsize(
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
265 rhs.matrix_value()));
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
266 else
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
267 retval = new octave_fixed_matrix (matrix.chdecsize(
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
268 rhs.double_value()));
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
269 } else if (key == __FIXED_INTSIZE_STR) {
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
270 if (rhs.is_matrix_type())
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
271 retval = new octave_fixed_matrix (matrix.chintsize(
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
272 rhs.matrix_value()));
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
273 else
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
274 retval = new octave_fixed_matrix (matrix.chintsize(
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
275 rhs.double_value()));
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
276 } else
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
277 error ("fixed point structure has no member `%s'", key.c_str ());
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
278 }
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
279 break;
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
280
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
281 case '{':
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
282 {
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
283 std::string nm = type_name ();
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
284 error ("%s cannot be indexed with %c", nm.c_str (), type[0]);
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
285 }
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
286 break;
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
287
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
288 default:
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
289 panic_impossible ();
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
290 }
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
291
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
292 return retval;
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
293 }
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
294
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
295 OV_REP_TYPE *
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
296 octave_fixed_matrix::try_narrowing_conversion (void)
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
297 {
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
298 OV_REP_TYPE *retval = 0;
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
299
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
300 int nr = matrix.rows ();
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
301 int nc = matrix.cols ();
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
302
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
303 if (nr == 1 && nc == 1)
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
304 retval = new octave_fixed (matrix (0, 0));
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
305
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
306 return retval;
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
307 }
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
308
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
309 double
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
310 octave_fixed_matrix::double_value (bool) const
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
311 {
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
312 double retval = lo_ieee_nan_value ();
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
313
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
314 if (rows () > 0 && columns () > 0)
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
315 {
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
316 gripe_implicit_conversion ("Octave:array-as-scalar",
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
317 "real matrix", "real scalar");
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
318
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
319 retval = matrix (0, 0) .fixedpoint();
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
320 }
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
321 else
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
322 gripe_invalid_conversion ("fixed matrix", "real scalar");
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
323
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
324 return retval;
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
325 }
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
326
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
327 Matrix
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
328 octave_fixed_matrix::matrix_value ( bool ) const
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
329 {
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
330 int nr = rows();
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
331 int nc = columns();
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
332 Matrix retval(nr, nc);
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
333 for (int i = 0; i < nr; i++)
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
334 for (int j = 0; j < nc; j++)
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
335 retval(i,j) = matrix(i,j).fixedpoint();
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
336
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
337 return retval;
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
338 }
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
339
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
340 Complex
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
341 octave_fixed_matrix::complex_value (bool) const
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
342 {
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
343 double tmp = lo_ieee_nan_value ();
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
344
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
345 Complex retval (tmp, tmp);
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
346
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
347 if (rows () > 0 && columns () > 0)
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
348 {
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
349 gripe_implicit_conversion ("Octave:array-as-scalar",
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
350 "real matrix", "real scalar");
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
351
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
352 retval = matrix (0, 0) .fixedpoint();
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
353 }
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
354 else
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
355 gripe_invalid_conversion ("fixed matrix", "complex scalar");
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
356
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
357 return retval;
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
358 }
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
359
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
360 octave_value
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
361 octave_fixed_matrix::convert_to_str (bool) const
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
362 {
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
363 octave_value retval;
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
364
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
365 int nr = matrix.rows ();
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
366 int nc = matrix.columns ();
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
367
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
368 if (nr == 0 && nc == 0)
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
369 {
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
370 char s = '\0';
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
371 retval = octave_value (&s);
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
372 }
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
373 else
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
374 {
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
375 if (nr == 0 || nc == 0)
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
376 {
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
377 char s = '\0';
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
378 retval = octave_value (&s);
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
379 }
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
380 else
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
381 {
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
382 charMatrix chm (nr, nc);
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
383
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
384 bool warned = false;
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
385
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
386 for (int j = 0; j < nc; j++)
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
387 {
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
388 for (int i = 0; i < nr; i++)
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
389 {
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
390 OCTAVE_QUIT;
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
391
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
392 FixedPoint d = matrix (i, j);
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
393
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
394 int ival = NINT (d.fixedpoint());
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
395
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
396 if (ival < 0 || ival > UCHAR_MAX)
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
397 {
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
398 // XXX FIXME XXX -- is there something
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
399 // better we could do?
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
400
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
401 ival = 0;
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
402
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
403 if (! warned)
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
404 {
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
405 ::warning ("range error for conversion to character value");
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
406 warned = true;
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
407 }
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
408 }
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
409
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
410 chm (i, j) = static_cast<char> (ival);
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
411 }
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
412 }
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
413
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
414 retval = octave_value (chm, 1);
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
415 }
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
416 }
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
417
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
418 return retval;
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
419 }
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
420
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
421 static void
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
422 restore_precision (void *p)
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
423 {
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
424 bind_internal_variable ("output_precision", *(static_cast<int *> (p)));
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
425 }
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
426
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
427 void
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
428 octave_fixed_matrix::print_raw (std::ostream& os,
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
429 bool pr_as_read_syntax) const
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
430 {
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
431 double min_num = matrix.abs().row_min().min().fixedpoint();
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
432 int new_prec = (int)matrix.getdecsize().row_max().max() +
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
433 (min_num >= 1. ? (int)log10(min_num) + 1 : 0);
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
434
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
435 octave_value_list tmp = feval ("output_precision");
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
436 int prec = tmp(0).int_value ();
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
437 unwind_protect::add (restore_precision, &prec);
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
438 bind_internal_variable ("output_precision", new_prec);
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
439
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
440 octave_print_internal (os, matrix_value(), false,
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
441 current_print_indent_level ());
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
442
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
443 unwind_protect::run ();
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
444 }
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
445
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
446 #ifdef CLASS_HAS_LOAD_SAVE
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
447 bool
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
448 octave_fixed_matrix::save_ascii (std::ostream& os, bool& infnan_warned,
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
449 bool strip_nan_and_inf)
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
450 {
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
451 dim_vector d = dims ();
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
452 os << "# ndims: " << d.length () << "\n";
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
453
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
454 for (int i=0; i < d.length (); i++)
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
455 os << " " << d (i);
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
456
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
457 os << "\n" << matrix.getintsize () << matrix.getdecsize()
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
458 << matrix_value();
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
459
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
460 return true;
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
461 }
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
462
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
463 bool
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
464 octave_fixed_matrix::load_ascii (std::istream& is)
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
465 {
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
466 int mdims;
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
467 bool success = true;
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
468
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
469 if (extract_keyword (is, "ndims", mdims))
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
470 {
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
471 dim_vector dv;
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
472 dv.resize (mdims);
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
473
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
474 for (int i = 0; i < mdims; i++)
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
475 is >> dv(i);
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
476
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
477 if (dv.length() != 2)
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
478 {
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
479 error ("load: N-D fixed arrays not supported");
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
480 success = false;
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
481 }
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
482 else
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
483 {
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
484 Matrix intsize (dv(0), dv(1)), decsize (dv(0), dv(1)),
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
485 number (dv(0), dv(1));
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
486
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
487 is >> intsize >> decsize >> number;
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
488
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
489 if (!is)
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
490 {
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
491 error ("load: failed to load matrix constant");
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
492 success = false;
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
493 }
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
494 matrix = FixedMatrix (intsize, decsize, number);
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
495
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
496 }
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
497 }
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
498 else
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
499 {
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
500 error ("load: failed to extract dimension of fixed point variable");
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
501 success = false;
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
502 }
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
503
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
504 return success;;
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
505 }
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
506
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
507 bool
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
508 octave_fixed_matrix::save_binary (std::ostream& os, bool& save_as_floats)
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
509 {
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
510 dim_vector d = dims ();
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
511
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
512 // Only treat 2-D array for now
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
513 if (d.length() != 2)
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
514 return false;
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
515
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
516 // Use negative value for ndims to be consistent with other types
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
517 int32_t tmp = - d.length();
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
518 os.write (X_CAST (char *, &tmp), 4);
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
519 for (int i=0; i < d.length (); i++)
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
520 {
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
521 tmp = d(i);
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
522 os.write (X_CAST (char *, &tmp), 4);
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
523 }
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
524
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
525 char size = (char) sizeof (unsigned int);
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
526 os.write (X_CAST (char *, &size), 1);
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
527
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
528 // intsize and decsize are integers in the range [0:32], so store as char
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
529 LS_DO_WRITE (char, matrix.getintsize ().fortran_vec (), 1, d.numel (), os);
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
530 LS_DO_WRITE (char, matrix.getdecsize ().fortran_vec (), 1, d.numel (), os);
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
531 LS_DO_WRITE (unsigned int, matrix.getnumber ().fortran_vec (),
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
532 sizeof (unsigned int), d.numel (), os);
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
533
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
534 return true;
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
535 }
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
536
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
537 #ifdef HAVE_SWAP_BYTES
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
538 static inline void swap_4_bytes (volatile void *ptr)
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
539 {
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
540 swap_bytes <4> (ptr);
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
541 }
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
542 #endif
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
543
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
544 bool
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
545 octave_fixed_matrix::load_binary (std::istream& is, bool swap,
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
546 oct_mach_info::float_format fmt)
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
547 {
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
548 int32_t mdims;
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
549 if (! is.read (X_CAST (char *, &mdims), 4))
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
550 return false;
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
551 if (swap)
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
552 swap_4_bytes (X_CAST (char *, &mdims));
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
553
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
554 if (mdims != -2)
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
555 return false;
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
556
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
557 mdims = - mdims;
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
558 int32_t di;
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
559 dim_vector dv;
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
560 dv.resize (mdims);
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
561
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
562 for (int i = 0; i < mdims; i++)
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
563 {
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
564 if (! is.read (X_CAST (char *, &di), 4))
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
565 return false;
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
566 if (swap)
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
567 swap_4_bytes (X_CAST (char *, &di));
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
568 dv(i) = di;
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
569 }
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
570
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
571 char size;
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
572 Matrix intsize (dv(0), dv(1)), decsize (dv(0), dv(1)),
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
573 number(dv(0), dv(1));
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
574
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
575 if (! is.read (X_CAST (char *, &size), 1))
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
576 return false;
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
577
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
578 LS_DO_READ_1(intsize.fortran_vec (), dv.numel (), is);
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
579 LS_DO_READ_1(decsize.fortran_vec (), dv.numel (), is);
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
580
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
581 if (size == 4)
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
582 LS_DO_READ(unsigned int, swap, number.fortran_vec (), 4,
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
583 dv.numel (), is);
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
584 else if (size == 8)
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
585 LS_DO_READ(unsigned int, swap, number.fortran_vec (), 8,
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
586 dv.numel (), is);
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
587 else
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
588 return false;
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
589
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
590 if (error_state || ! is)
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
591 return false;
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
592
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
593 // This is ugly, is there a better way?
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
594 matrix.resize (dv(0), dv(1));
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
595 for (int i = 0; i < dv(0); i++)
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
596 for (int j = 0; j < dv(1); j++)
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
597 matrix (i, j) = FixedPoint ((unsigned int)intsize (i, j),
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
598 (unsigned int)decsize (i, j),
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
599 (unsigned int)number (i, j));
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
600
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
601 return true;
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
602 }
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
603
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
604 #if defined (HAVE_HDF5)
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
605 bool
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
606 octave_fixed_matrix::save_hdf5 (hid_t loc_id, const char *name, bool save_as_floats)
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
607 {
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
608 hid_t group_hid = -1;
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
609 group_hid = H5Gcreate (loc_id, name, 0);
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
610 if (group_hid < 0 ) return false;
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
611
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
612 dim_vector d = dims ();
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
613 hsize_t hdims[d.length () > 2 ? d.length () : 3];
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
614 hid_t space_hid = -1, data_hid = -1;
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
615 int rank = ( (d (0) == 1) && (d.length () == 2) ? 1 : d.length ());
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
616 bool retval = true;
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
617
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
618 // Octave uses column-major, while HDF5 uses row-major ordering
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
619 for (int i = 0, j = d.length() - 1; i < d.length (); i++, j--)
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
620 hdims[i] = d (j);
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
621
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
622 space_hid = H5Screate_simple (rank, hdims, (hsize_t*) 0);
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
623 if (space_hid < 0)
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
624 {
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
625 H5Gclose (group_hid);
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
626 return false;
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
627 }
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
628
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
629 data_hid = H5Dcreate (group_hid, "int", H5T_NATIVE_UCHAR, space_hid,
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
630 H5P_DEFAULT);
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
631 if (data_hid < 0)
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
632 {
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
633 H5Sclose (space_hid);
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
634 H5Gclose (group_hid);
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
635 return false;
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
636 }
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
637
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
638 double * m = matrix.getintsize ().fortran_vec ();
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
639 OCTAVE_LOCAL_BUFFER(unsigned char, tmp, d.numel ());
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
640 for (int i = 0; i < d.numel (); i++)
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
641 tmp[i] = (unsigned char) m[i];
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
642 retval = H5Dwrite (data_hid, H5T_NATIVE_UCHAR, H5S_ALL, H5S_ALL, H5P_DEFAULT,
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
643 (void*) tmp) >= 0;
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
644 H5Dclose (data_hid);
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
645 if (!retval)
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
646 {
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
647 H5Sclose (space_hid);
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
648 H5Gclose (group_hid);
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
649 return false;
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
650 }
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
651
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
652 data_hid = H5Dcreate (group_hid, "dec", H5T_NATIVE_UCHAR, space_hid,
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
653 H5P_DEFAULT);
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
654 if (data_hid < 0)
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
655 {
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
656 H5Sclose (space_hid);
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
657 H5Gclose (group_hid);
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
658 return false;
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
659 }
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
660
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
661 m = matrix.getdecsize ().fortran_vec ();
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
662 for (int i = 0; i < d.numel (); i++)
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
663 tmp[i] = (unsigned char) m[i];
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
664 retval = H5Dwrite (data_hid, H5T_NATIVE_UCHAR, H5S_ALL, H5S_ALL, H5P_DEFAULT,
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
665 (void*) tmp) >= 0;
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
666 H5Dclose (data_hid);
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
667 if (!retval)
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
668 {
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
669 H5Sclose (space_hid);
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
670 H5Gclose (group_hid);
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
671 return false;
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
672 }
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
673
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
674 data_hid = H5Dcreate (group_hid, "num", H5T_NATIVE_UINT, space_hid,
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
675 H5P_DEFAULT);
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
676 if (data_hid < 0)
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
677 {
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
678 H5Sclose (space_hid);
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
679 H5Gclose (group_hid);
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
680 return false;
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
681 }
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
682
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
683 m = matrix.getnumber ().fortran_vec ();
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
684 OCTAVE_LOCAL_BUFFER(unsigned int, num, d.numel ());
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
685 for (int i = 0; i < d.numel (); i++)
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
686 num[i] = (unsigned int) m[i];
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
687 retval = H5Dwrite (data_hid, H5T_NATIVE_UINT, H5S_ALL, H5S_ALL, H5P_DEFAULT,
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
688 (void*) num) >= 0;
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
689 H5Dclose (data_hid);
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
690 H5Sclose (space_hid);
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
691 H5Gclose (group_hid);
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
692 return retval;
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
693 }
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
694
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
695 bool
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
696 octave_fixed_matrix::load_hdf5 (hid_t loc_id, const char *name,
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
697 bool have_h5giterate_bug)
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
698 {
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
699 herr_t retval = -1;
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
700 hid_t group_hid, data_hid, space_id;
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
701 hsize_t rank, rank_old;
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
702
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
703 group_hid = H5Gopen (loc_id, name);
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
704 if (group_hid < 0 ) return false;
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
705
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
706 data_hid = H5Dopen (group_hid, "int");
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
707 space_id = H5Dget_space (data_hid);
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
708 rank = H5Sget_simple_extent_ndims (space_id);
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
709 rank_old = rank;
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
710
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
711 if (rank < 1 || rank > 2)
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
712 {
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
713 // No N-D array yet
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
714 H5Sclose (space_id);
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
715 H5Dclose (data_hid);
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
716 H5Gclose (group_hid);
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
717 return false;
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
718 }
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
719
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
720 OCTAVE_LOCAL_BUFFER (hsize_t, hdims, rank);
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
721 OCTAVE_LOCAL_BUFFER (hsize_t, maxdims, rank);
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
722
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
723 H5Sget_simple_extent_dims (space_id, hdims, maxdims);
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
724
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
725 dim_vector dv;
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
726 dim_vector dv_old;
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
727
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
728 // Octave uses column-major, while HDF5 uses row-major ordering
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
729 if (rank == 1)
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
730 {
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
731 dv.resize (2);
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
732 dv(0) = 1;
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
733 dv(1) = hdims[0];
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
734 }
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
735 else
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
736 {
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
737 dv.resize (rank);
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
738 for (int i = 0, j = rank - 1; i < (int)rank; i++, j--)
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
739 dv(j) = hdims[i];
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
740 }
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
741 dv_old = dv;
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
742
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
743 OCTAVE_LOCAL_BUFFER (unsigned int, intsize, dv.numel ());
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
744 if (H5Dread (data_hid, H5T_NATIVE_INT, H5S_ALL, H5S_ALL,
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
745 H5P_DEFAULT, (void *) intsize) < 0)
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
746 {
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
747 H5Sclose (space_id);
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
748 H5Dclose (data_hid);
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
749 H5Gclose (group_hid);
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
750 return false;
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
751 }
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
752 H5Dclose (data_hid);
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
753
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
754 data_hid = H5Dopen (group_hid, "dec");
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
755 space_id = H5Dget_space (data_hid);
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
756 rank = H5Sget_simple_extent_ndims (space_id);
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
757
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
758 if (rank != rank_old)
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
759 {
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
760 H5Sclose (space_id);
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
761 H5Dclose (data_hid);
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
762 H5Gclose (group_hid);
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
763 return false;
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
764 }
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
765
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
766 H5Sget_simple_extent_dims (space_id, hdims, maxdims);
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
767
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
768 // Octave uses column-major, while HDF5 uses row-major ordering
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
769 if (rank == 1)
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
770 {
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
771 dv.resize (2);
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
772 dv(0) = 1;
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
773 dv(1) = hdims[0];
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
774 }
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
775 else
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
776 {
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
777 dv.resize (rank);
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
778 for (int i = 0, j = rank - 1; i < (int)rank; i++, j--)
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
779 dv(j) = hdims[i];
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
780 }
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
781
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
782 if (dv_old != dv)
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
783 {
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
784 H5Sclose (space_id);
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
785 H5Dclose (data_hid);
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
786 H5Gclose (group_hid);
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
787 return false;
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
788 }
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
789
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
790 OCTAVE_LOCAL_BUFFER (unsigned int, decsize, dv.numel ());
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
791 if (H5Dread (data_hid, H5T_NATIVE_INT, H5S_ALL, H5S_ALL,
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
792 H5P_DEFAULT, (void *) decsize) < 0)
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
793 {
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
794 H5Sclose (space_id);
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
795 H5Dclose (data_hid);
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
796 H5Gclose (group_hid);
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
797 return false;
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
798 }
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
799 H5Dclose (data_hid);
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
800
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
801 data_hid = H5Dopen (group_hid, "num");
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
802 space_id = H5Dget_space (data_hid);
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
803 rank = H5Sget_simple_extent_ndims (space_id);
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
804
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
805 if (rank != rank_old)
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
806 {
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
807 H5Sclose (space_id);
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
808 H5Dclose (data_hid);
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
809 H5Gclose (group_hid);
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
810 return false;
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
811 }
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
812
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
813 H5Sget_simple_extent_dims (space_id, hdims, maxdims);
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
814
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
815 // Octave uses column-major, while HDF5 uses row-major ordering
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
816 if (rank == 1)
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
817 {
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
818 dv.resize (2);
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
819 dv(0) = 1;
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
820 dv(1) = hdims[0];
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
821 }
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
822 else
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
823 {
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
824 dv.resize (rank);
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
825 for (int i = 0, j = rank - 1; i < (int)rank; i++, j--)
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
826 dv(j) = hdims[i];
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
827 }
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
828
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
829 if (dv_old != dv)
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
830 {
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
831 H5Sclose (space_id);
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
832 H5Dclose (data_hid);
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
833 H5Gclose (group_hid);
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
834 return false;
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
835 }
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
836
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
837 OCTAVE_LOCAL_BUFFER (unsigned int, number, dv.numel ());
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
838 retval = H5Dread (data_hid, H5T_NATIVE_INT, H5S_ALL, H5S_ALL,
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
839 H5P_DEFAULT, (void *) number);
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
840 H5Dclose (data_hid);
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
841 H5Sclose (space_id);
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
842 H5Gclose (group_hid);
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
843 if (retval < 0)
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
844 return false;
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
845
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
846 // This is ugly, is there a better way?
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
847 matrix.resize (dv(0), dv(1));
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
848 unsigned int * ivec = intsize;
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
849 unsigned int * dvec = decsize;
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
850 unsigned int * nvec = number;
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
851 for (int j = 0; j < dv(1); j++)
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
852 for (int i = 0; i < dv(0); i++)
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
853 matrix (i, j) = FixedPoint (*ivec++, *dvec++, *nvec++);
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
854
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
855 return true;
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
856 }
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
857 #endif
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
858 #endif
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
859
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
860 /*
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
861 ;;; Local Variables: ***
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
862 ;;; mode: C++ ***
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
863 ;;; End: ***
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
864 */