Mercurial > hg > octave-lyh
annotate liboctave/util/data-conv.cc @ 17105:c2b2c7ddf93c
shading.m: Don't apply shading to contour hggroups.
* scripts/plot/shading.m: Search through graphic handle
hierarchy and apply shading to patch and surface objects
which are *NOT* in contour hggroups.
author | Rik <rik@octave.org> |
---|---|
date | Sun, 28 Jul 2013 17:15:37 -0700 |
parents | 821922270b66 |
children | 0b644adf4f31 |
rev | line source |
---|---|
1960 | 1 /* |
2 | |
14138
72c96de7a403
maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
3 Copyright (C) 1996-2012 John W. Eaton |
1960 | 4 |
5 This file is part of Octave. | |
6 | |
7 Octave is free software; you can redistribute it and/or modify it | |
8 under the terms of the GNU General Public License as published by the | |
7016 | 9 Free Software Foundation; either version 3 of the License, or (at your |
10 option) any later version. | |
1960 | 11 |
12 Octave is distributed in the hope that it will be useful, but WITHOUT | |
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
15 for more details. | |
16 | |
17 You should have received a copy of the GNU General Public License | |
7016 | 18 along with Octave; see the file COPYING. If not, see |
19 <http://www.gnu.org/licenses/>. | |
1960 | 20 |
21 */ | |
22 | |
23 #ifdef HAVE_CONFIG_H | |
24 #include <config.h> | |
25 #endif | |
26 | |
2317 | 27 #include <cctype> |
15215
9020dddc925a
use std::numeric_limits for integer max and min values
John W. Eaton <jwe@octave.org>
parents:
15018
diff
changeset
|
28 #include <climits> |
6482 | 29 #include <cstdlib> |
2317 | 30 |
3503 | 31 #include <iostream> |
5760 | 32 #include <vector> |
1960 | 33 |
34 #include "byte-swap.h" | |
35 #include "data-conv.h" | |
36 #include "lo-error.h" | |
7991
139f47cf17ab
Change NA value to support single to double precision conversion
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
37 #include "lo-ieee.h" |
8377
25bc2d31e1bf
improve OCTAVE_LOCAL_BUFFER
Jaroslav Hajek <highegg@gmail.com>
parents:
7991
diff
changeset
|
38 #include "oct-locbuf.h" |
1960 | 39 |
5892 | 40 template void swap_bytes<2> (volatile void *, int); |
41 template void swap_bytes<4> (volatile void *, int); | |
42 template void swap_bytes<8> (volatile void *, int); | |
43 | |
4944 | 44 #if defined HAVE_LONG_LONG_INT |
45 #define FIND_SIZED_INT_TYPE(VAL, BITS, TQ, Q) \ | |
46 do \ | |
47 { \ | |
48 int sz = BITS / CHAR_BIT; \ | |
49 if (sizeof (TQ char) == sz) \ | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
50 VAL = oct_data_conv::dt_ ## Q ## char; \ |
4944 | 51 else if (sizeof (TQ short) == sz) \ |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
52 VAL = oct_data_conv::dt_ ## Q ## short; \ |
4944 | 53 else if (sizeof (TQ int) == sz) \ |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
54 VAL = oct_data_conv::dt_ ## Q ## int; \ |
4944 | 55 else if (sizeof (TQ long) == sz) \ |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
56 VAL = oct_data_conv::dt_ ## Q ## long; \ |
4944 | 57 else if (sizeof (TQ long long) == sz) \ |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
58 VAL = oct_data_conv::dt_ ## Q ## longlong; \ |
4944 | 59 else \ |
60 VAL = oct_data_conv::dt_unknown; \ | |
61 } \ | |
62 while (0) | |
63 #else | |
3359 | 64 #define FIND_SIZED_INT_TYPE(VAL, BITS, TQ, Q) \ |
3358 | 65 do \ |
66 { \ | |
67 int sz = BITS / CHAR_BIT; \ | |
68 if (sizeof (TQ char) == sz) \ | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
69 VAL = oct_data_conv::dt_ ## Q ## char; \ |
3358 | 70 else if (sizeof (TQ short) == sz) \ |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
71 VAL = oct_data_conv::dt_ ## Q ## short; \ |
3358 | 72 else if (sizeof (TQ int) == sz) \ |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
73 VAL = oct_data_conv::dt_ ## Q ## int; \ |
3358 | 74 else if (sizeof (TQ long) == sz) \ |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
75 VAL = oct_data_conv::dt_ ## Q ## long; \ |
3358 | 76 else \ |
77 VAL = oct_data_conv::dt_unknown; \ | |
78 } \ | |
79 while (0) | |
4944 | 80 #endif |
3358 | 81 |
3359 | 82 #define FIND_SIZED_FLOAT_TYPE(VAL, BITS) \ |
3358 | 83 do \ |
84 { \ | |
85 int sz = BITS / CHAR_BIT; \ | |
86 if (sizeof (float) == sz) \ | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
87 VAL = oct_data_conv::dt_float; \ |
3358 | 88 else if (sizeof (double) == sz) \ |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
89 VAL = oct_data_conv::dt_double; \ |
3358 | 90 else \ |
91 VAL = oct_data_conv::dt_unknown; \ | |
92 } \ | |
93 while (0) | |
94 | |
95 // I'm not sure it is worth the trouble, but let's use a lookup table | |
96 // for the types that are supposed to be a specific number of bits | |
97 // wide. Given the macros above, this should work as long as CHAR_BIT | |
98 // is a multiple of 8 and there are types with the right sizes. | |
99 // | |
100 // The sized data type lookup table has the following format: | |
101 // | |
102 // bits | |
103 // +----+----+----+----+ | |
104 // | 8 | 16 | 32 | 64 | | |
105 // +----+----+----+----+ | |
106 // signed integer | | | | | | |
107 // +----+----+----+----+ | |
108 // unsigned integer | | | | | | |
109 // +----+----+----+----+ | |
110 // floating point | | | | | | |
111 // +----+----+----+----+ | |
112 // | |
113 // So, the 0,3 element is supposed to contain the oct_data_conv enum | |
114 // value corresponding to the correct native data type for a signed | |
115 // 32-bit integer. | |
116 | |
117 static void | |
118 init_sized_type_lookup_table (oct_data_conv::data_type table[3][4]) | |
119 { | |
120 int bits = 8; | |
121 | |
122 for (int i = 0; i < 4; i++) | |
123 { | |
3359 | 124 FIND_SIZED_INT_TYPE (table[0][i], bits, , ); |
3358 | 125 |
3359 | 126 FIND_SIZED_INT_TYPE (table[1][i], bits, unsigned, u); |
3358 | 127 |
3359 | 128 FIND_SIZED_FLOAT_TYPE (table[2][i], bits); |
3358 | 129 |
130 bits *= 2; | |
131 } | |
132 } | |
133 | |
4944 | 134 static std::string |
135 strip_spaces (const std::string& str) | |
136 { | |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10314
diff
changeset
|
137 size_t n = str.length (); |
4944 | 138 |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10314
diff
changeset
|
139 size_t k = 0; |
4944 | 140 |
141 std::string s (n, ' '); | |
142 | |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10314
diff
changeset
|
143 for (size_t i = 0; i < n; i++) |
4944 | 144 if (! isspace (str[i])) |
145 s[k++] = tolower (str[i]); | |
146 | |
147 s.resize (k); | |
148 | |
149 return s; | |
150 } | |
151 | |
152 #define GET_SIZED_INT_TYPE(T, U) \ | |
153 do \ | |
154 { \ | |
155 switch (sizeof (T)) \ | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
156 { \ |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
157 case 1: \ |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
158 retval = dt_ ## U ## int8; \ |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
159 break; \ |
4944 | 160 \ |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
161 case 2: \ |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
162 retval = dt_ ## U ## int16; \ |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
163 break; \ |
4944 | 164 \ |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
165 case 4: \ |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
166 retval = dt_ ## U ## int32; \ |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
167 break; \ |
4944 | 168 \ |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
169 case 8: \ |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
170 retval = dt_ ## U ## int64; \ |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
171 break; \ |
4944 | 172 \ |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
173 default: \ |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
174 retval = dt_unknown; \ |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
175 break; \ |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
176 } \ |
4944 | 177 } \ |
178 while (0) | |
179 | |
2317 | 180 oct_data_conv::data_type |
3504 | 181 oct_data_conv::string_to_data_type (const std::string& str) |
2317 | 182 { |
183 data_type retval = dt_unknown; | |
184 | |
3358 | 185 static bool initialized = false; |
186 | |
187 static data_type sized_type_table[3][4]; | |
2317 | 188 |
3358 | 189 if (! initialized) |
190 { | |
191 init_sized_type_lookup_table (sized_type_table); | |
192 | |
193 initialized = true; | |
194 } | |
195 | |
4944 | 196 std::string s = strip_spaces (str); |
2317 | 197 |
4944 | 198 if (s == "int8" || s == "integer*1") |
199 retval = dt_int8; | |
200 else if (s == "uint8") | |
201 retval = dt_uint8; | |
202 else if (s == "int16" || s == "integer*2") | |
203 retval = dt_int16; | |
204 else if (s == "uint16") | |
205 retval = dt_uint16; | |
206 else if (s == "int32" || s == "integer*4") | |
207 retval = dt_int32; | |
208 else if (s == "uint32") | |
209 retval = dt_uint32; | |
210 else if (s == "int64" || s == "integer*8") | |
211 retval = dt_int64; | |
212 else if (s == "uint64") | |
213 retval = dt_uint64; | |
214 else if (s == "single" || s == "float32" || s == "real*4") | |
215 retval = dt_single; | |
216 else if (s == "double" || s == "float64" || s == "real*8") | |
217 retval = dt_double; | |
218 else if (s == "char" || s == "char*1") | |
2317 | 219 retval = dt_char; |
220 else if (s == "schar" || s == "signedchar") | |
221 retval = dt_schar; | |
222 else if (s == "uchar" || s == "unsignedchar") | |
223 retval = dt_uchar; | |
224 else if (s == "short") | |
4944 | 225 GET_SIZED_INT_TYPE (short, ); |
2317 | 226 else if (s == "ushort" || s == "unsignedshort") |
4944 | 227 GET_SIZED_INT_TYPE (unsigned short, u); |
2317 | 228 else if (s == "int") |
4944 | 229 GET_SIZED_INT_TYPE (int, ); |
2317 | 230 else if (s == "uint" || s == "unsignedint") |
4944 | 231 GET_SIZED_INT_TYPE (unsigned int, u); |
2317 | 232 else if (s == "long") |
4944 | 233 GET_SIZED_INT_TYPE (long, ); |
2317 | 234 else if (s == "ulong" || s == "unsignedlong") |
4944 | 235 GET_SIZED_INT_TYPE (unsigned long, u); |
236 else if (s == "longlong") | |
237 GET_SIZED_INT_TYPE (long long, ); | |
238 else if (s == "ulonglong" || s == "unsignedlonglong") | |
239 GET_SIZED_INT_TYPE (unsigned long long, u); | |
3358 | 240 else if (s == "float") |
4944 | 241 { |
242 if (sizeof (float) == sizeof (double)) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
243 retval = dt_double; |
4944 | 244 else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
245 retval = dt_single; |
4944 | 246 } |
4970 | 247 else if (s == "logical") |
248 retval = dt_logical; | |
2317 | 249 else |
250 (*current_liboctave_error_handler) ("invalid data type specified"); | |
251 | |
3358 | 252 if (retval == dt_unknown) |
253 (*current_liboctave_error_handler) | |
254 ("unable to find matching native data type for %s", s.c_str ()); | |
255 | |
2317 | 256 return retval; |
257 } | |
258 | |
4944 | 259 void |
260 oct_data_conv::string_to_data_type | |
261 (const std::string& str, int& block_size, | |
262 oct_data_conv::data_type& input_type, | |
263 oct_data_conv::data_type& output_type) | |
264 { | |
265 block_size = 1; | |
266 input_type = dt_uchar; | |
267 output_type = dt_double; | |
268 | |
269 bool input_is_output = false; | |
270 | |
271 std::string s = strip_spaces (str); | |
272 | |
273 size_t pos = 0; | |
274 | |
275 if (s[0] == '*') | |
276 input_is_output = true; | |
277 else | |
278 { | |
279 size_t len = s.length (); | |
280 | |
281 while (pos < len && isdigit (s[pos])) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
282 pos++; |
4944 | 283 |
284 if (pos > 0) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
285 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
286 if (s[pos] == '*') |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
287 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
288 block_size = atoi (s.c_str ()); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
289 s = s.substr (pos+1); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
290 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
291 else |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
292 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
293 (*current_liboctave_error_handler) |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
294 ("invalid repeat count in '%s'", str.c_str ()); |
4944 | 295 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
296 return; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
297 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
298 } |
4944 | 299 } |
300 | |
301 pos = s.find ('='); | |
302 | |
303 if (pos != std::string::npos) | |
304 { | |
305 if (s[pos+1] == '>') | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
306 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
307 std::string s1; |
5870 | 308 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
309 if (input_is_output) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
310 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
311 input_is_output = false; |
4944 | 312 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
313 s1 = s.substr (1, pos-1); |
5870 | 314 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
315 (*current_liboctave_warning_handler) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
316 ("warning: ignoring leading * in fread precision"); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
317 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
318 else |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
319 s1 = s.substr (0, pos); |
4944 | 320 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
321 input_type = string_to_data_type (s1); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
322 output_type = string_to_data_type (s.substr (pos+2)); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
323 } |
4944 | 324 else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
325 (*current_liboctave_error_handler) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
326 ("fread: invalid precision specified"); |
4944 | 327 } |
328 else | |
329 { | |
5870 | 330 if (input_is_output) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
331 s = s.substr (1); |
5870 | 332 |
4944 | 333 input_type = string_to_data_type (s); |
334 | |
335 if (input_is_output) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
336 output_type = input_type; |
4944 | 337 } |
338 } | |
339 | |
340 void | |
341 oct_data_conv::string_to_data_type | |
342 (const std::string& str, int& block_size, | |
343 oct_data_conv::data_type& output_type) | |
344 { | |
345 block_size = 1; | |
346 output_type = dt_double; | |
347 | |
348 std::string s = strip_spaces (str); | |
349 | |
350 size_t pos = 0; | |
351 | |
352 size_t len = s.length (); | |
353 | |
354 while (pos < len && isdigit (s[pos])) | |
355 pos++; | |
356 | |
357 if (pos > 0) | |
358 { | |
359 if (s[pos] == '*') | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
360 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
361 block_size = atoi (s.c_str ()); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
362 s = s.substr (pos+1); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
363 } |
4944 | 364 else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
365 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
366 (*current_liboctave_error_handler) |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
367 ("invalid repeat count in '%s'", str.c_str ()); |
4944 | 368 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
369 return; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
370 } |
4944 | 371 } |
372 | |
373 output_type = string_to_data_type (s); | |
374 } | |
375 | |
376 std::string | |
377 oct_data_conv::data_type_as_string (oct_data_conv::data_type dt) | |
378 { | |
379 std::string retval; | |
380 | |
381 switch (dt) | |
382 { | |
383 case oct_data_conv::dt_int8: | |
384 retval = "int8"; | |
385 break; | |
386 | |
387 case oct_data_conv::dt_uint8: | |
388 retval = "uint8"; | |
389 break; | |
390 | |
391 case oct_data_conv::dt_int16: | |
392 retval = "int16"; | |
393 break; | |
394 | |
395 case oct_data_conv::dt_uint16: | |
396 retval = "uint16"; | |
397 break; | |
398 | |
399 case oct_data_conv::dt_int32: | |
400 retval = "int32"; | |
401 break; | |
402 | |
403 case oct_data_conv::dt_uint32: | |
404 retval = "uint32"; | |
405 break; | |
406 | |
407 case oct_data_conv::dt_int64: | |
408 retval = "int64"; | |
409 break; | |
410 | |
411 case oct_data_conv::dt_uint64: | |
412 retval = "uint64"; | |
413 break; | |
414 | |
415 case oct_data_conv::dt_single: | |
416 retval = "single"; | |
417 break; | |
418 | |
419 case oct_data_conv::dt_double: | |
420 retval = "double"; | |
421 break; | |
422 | |
423 case oct_data_conv::dt_char: | |
424 retval = "char"; | |
425 break; | |
426 | |
427 case oct_data_conv::dt_schar: | |
428 retval = "signed char"; | |
429 break; | |
430 | |
431 case oct_data_conv::dt_uchar: | |
432 retval = "usigned char"; | |
433 break; | |
434 | |
435 case oct_data_conv::dt_short: | |
436 retval = "short"; | |
437 break; | |
438 | |
439 case oct_data_conv::dt_ushort: | |
440 retval = "unsigned short"; | |
441 break; | |
442 | |
443 case oct_data_conv::dt_int: | |
444 retval = "int"; | |
445 break; | |
446 | |
447 case oct_data_conv::dt_uint: | |
448 retval = "usigned int"; | |
449 break; | |
450 | |
451 case oct_data_conv::dt_long: | |
452 retval = "long"; | |
453 break; | |
454 | |
455 case oct_data_conv::dt_ulong: | |
456 retval = "usigned long"; | |
457 break; | |
458 | |
459 case oct_data_conv::dt_longlong: | |
460 retval = "long long"; | |
461 break; | |
462 | |
463 case oct_data_conv::dt_ulonglong: | |
464 retval = "unsigned long long"; | |
465 break; | |
466 | |
467 case oct_data_conv::dt_float: | |
468 retval = "float"; | |
469 break; | |
470 | |
4970 | 471 case oct_data_conv::dt_logical: |
472 retval = "logical"; | |
473 break; | |
474 | |
4944 | 475 case oct_data_conv::dt_unknown: |
476 default: | |
477 retval = "unknown"; | |
478 break; | |
479 } | |
480 | |
481 return retval; | |
482 } | |
1960 | 483 |
3359 | 484 #define LS_DO_READ(TYPE, swap, data, size, len, stream) \ |
1960 | 485 do \ |
486 { \ | |
3867 | 487 if (len > 0) \ |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
488 { \ |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
489 OCTAVE_LOCAL_BUFFER (TYPE, ptr, len); \ |
16074
821922270b66
Fix saving binary matrices with up to 2^31 elements (Bug #38326).
Rik <rik@octave.org>
parents:
15467
diff
changeset
|
490 std::streamsize n_bytes = size * len; \ |
821922270b66
Fix saving binary matrices with up to 2^31 elements (Bug #38326).
Rik <rik@octave.org>
parents:
15467
diff
changeset
|
491 stream.read (reinterpret_cast<char *> (ptr), n_bytes); \ |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
492 if (swap) \ |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
493 swap_bytes< size > (ptr, len); \ |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10314
diff
changeset
|
494 for (octave_idx_type i = 0; i < len; i++) \ |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
495 data[i] = ptr[i]; \ |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
496 } \ |
1960 | 497 } \ |
498 while (0) | |
499 | |
500 // Have to use copy here to avoid writing over data accessed via | |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14138
diff
changeset
|
501 // Matrix::data (). |
1960 | 502 |
3359 | 503 #define LS_DO_WRITE(TYPE, data, size, len, stream) \ |
1960 | 504 do \ |
505 { \ | |
3867 | 506 if (len > 0) \ |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
507 { \ |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
508 char tmp_type = type; \ |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
509 stream.write (&tmp_type, 1); \ |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
510 OCTAVE_LOCAL_BUFFER (TYPE, ptr, len); \ |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10314
diff
changeset
|
511 for (octave_idx_type i = 0; i < len; i++) \ |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
512 ptr[i] = static_cast <TYPE> (data[i]); \ |
16074
821922270b66
Fix saving binary matrices with up to 2^31 elements (Bug #38326).
Rik <rik@octave.org>
parents:
15467
diff
changeset
|
513 std::streamsize n_bytes = size * len; \ |
821922270b66
Fix saving binary matrices with up to 2^31 elements (Bug #38326).
Rik <rik@octave.org>
parents:
15467
diff
changeset
|
514 stream.write (reinterpret_cast<char *> (ptr), n_bytes); \ |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
515 } \ |
1960 | 516 } \ |
517 while (0) | |
518 | |
519 // Loading variables from files. | |
520 | |
521 static void | |
522 gripe_unrecognized_float_fmt (void) | |
523 { | |
524 (*current_liboctave_error_handler) | |
525 ("unrecognized floating point format requested"); | |
526 } | |
527 | |
528 static void | |
529 gripe_data_conversion (const char *from, const char *to) | |
530 { | |
531 (*current_liboctave_error_handler) | |
532 ("unable to convert from %s to %s format", from, to); | |
533 } | |
534 | |
535 // But first, some data conversion routines. | |
536 | |
537 // Currently, we only handle conversions for the IEEE types. To fix | |
538 // that, make more of the following routines work. | |
539 | |
5775 | 540 // FIXME -- assumes sizeof (Complex) == 8 |
541 // FIXME -- assumes sizeof (double) == 8 | |
542 // FIXME -- assumes sizeof (float) == 4 | |
1960 | 543 |
544 static void | |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10314
diff
changeset
|
545 IEEE_big_double_to_IEEE_little_double (void *d, octave_idx_type len) |
1960 | 546 { |
4944 | 547 swap_bytes<8> (d, len); |
1960 | 548 } |
549 | |
550 static void | |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10314
diff
changeset
|
551 VAX_D_double_to_IEEE_little_double (void * /* d */, octave_idx_type /* len */) |
1960 | 552 { |
553 gripe_data_conversion ("VAX D float", "IEEE little endian format"); | |
554 } | |
555 | |
556 static void | |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10314
diff
changeset
|
557 VAX_G_double_to_IEEE_little_double (void * /* d */, octave_idx_type /* len */) |
1960 | 558 { |
559 gripe_data_conversion ("VAX G float", "IEEE little endian format"); | |
560 } | |
561 | |
562 static void | |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10314
diff
changeset
|
563 Cray_to_IEEE_little_double (void * /* d */, octave_idx_type /* len */) |
1960 | 564 { |
565 gripe_data_conversion ("Cray", "IEEE little endian format"); | |
566 } | |
567 | |
568 static void | |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10314
diff
changeset
|
569 IEEE_big_float_to_IEEE_little_float (void *d, octave_idx_type len) |
1960 | 570 { |
4944 | 571 swap_bytes<4> (d, len); |
1960 | 572 } |
573 | |
574 static void | |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10314
diff
changeset
|
575 VAX_D_float_to_IEEE_little_float (void * /* d */, octave_idx_type /* len */) |
1960 | 576 { |
577 gripe_data_conversion ("VAX D float", "IEEE little endian format"); | |
578 } | |
579 | |
580 static void | |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10314
diff
changeset
|
581 VAX_G_float_to_IEEE_little_float (void * /* d */, octave_idx_type /* len */) |
1960 | 582 { |
583 gripe_data_conversion ("VAX G float", "IEEE little endian format"); | |
584 } | |
585 | |
586 static void | |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10314
diff
changeset
|
587 Cray_to_IEEE_little_float (void * /* d */, octave_idx_type /* len */) |
1960 | 588 { |
589 gripe_data_conversion ("Cray", "IEEE little endian format"); | |
590 } | |
591 | |
592 static void | |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10314
diff
changeset
|
593 IEEE_little_double_to_IEEE_big_double (void *d, octave_idx_type len) |
1960 | 594 { |
4944 | 595 swap_bytes<8> (d, len); |
1960 | 596 } |
597 | |
598 static void | |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10314
diff
changeset
|
599 VAX_D_double_to_IEEE_big_double (void * /* d */, octave_idx_type /* len */) |
1960 | 600 { |
601 gripe_data_conversion ("VAX D float", "IEEE big endian format"); | |
602 } | |
603 | |
604 static void | |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10314
diff
changeset
|
605 VAX_G_double_to_IEEE_big_double (void * /* d */, octave_idx_type /* len */) |
1960 | 606 { |
607 gripe_data_conversion ("VAX G float", "IEEE big endian format"); | |
608 } | |
609 | |
610 static void | |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10314
diff
changeset
|
611 Cray_to_IEEE_big_double (void * /* d */, octave_idx_type /* len */) |
1960 | 612 { |
613 gripe_data_conversion ("Cray", "IEEE big endian format"); | |
614 } | |
615 | |
616 static void | |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10314
diff
changeset
|
617 IEEE_little_float_to_IEEE_big_float (void *d, octave_idx_type len) |
1960 | 618 { |
4944 | 619 swap_bytes<4> (d, len); |
1960 | 620 } |
621 | |
622 static void | |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10314
diff
changeset
|
623 VAX_D_float_to_IEEE_big_float (void * /* d */, octave_idx_type /* len */) |
1960 | 624 { |
625 gripe_data_conversion ("VAX D float", "IEEE big endian format"); | |
626 } | |
627 | |
628 static void | |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10314
diff
changeset
|
629 VAX_G_float_to_IEEE_big_float (void * /* d */, octave_idx_type /* len */) |
1960 | 630 { |
631 gripe_data_conversion ("VAX G float", "IEEE big endian format"); | |
632 } | |
633 | |
634 static void | |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10314
diff
changeset
|
635 Cray_to_IEEE_big_float (void * /* d */, octave_idx_type /* len */) |
1960 | 636 { |
637 gripe_data_conversion ("Cray", "IEEE big endian format"); | |
638 } | |
639 | |
640 static void | |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10314
diff
changeset
|
641 IEEE_little_double_to_VAX_D_double (void * /* d */, octave_idx_type /* len */) |
1960 | 642 { |
643 gripe_data_conversion ("IEEE little endian", "VAX D"); | |
644 } | |
645 | |
646 static void | |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10314
diff
changeset
|
647 IEEE_big_double_to_VAX_D_double (void * /* d */, octave_idx_type /* len */) |
1960 | 648 { |
649 gripe_data_conversion ("IEEE big endian", "VAX D"); | |
650 } | |
651 | |
652 static void | |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10314
diff
changeset
|
653 VAX_G_double_to_VAX_D_double (void * /* d */, octave_idx_type /* len */) |
1960 | 654 { |
655 gripe_data_conversion ("VAX G float", "VAX D"); | |
656 } | |
657 | |
658 static void | |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10314
diff
changeset
|
659 Cray_to_VAX_D_double (void * /* d */, octave_idx_type /* len */) |
1960 | 660 { |
661 gripe_data_conversion ("Cray", "VAX D"); | |
662 } | |
663 | |
664 static void | |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10314
diff
changeset
|
665 IEEE_little_float_to_VAX_D_float (void * /* d */, octave_idx_type /* len */) |
1960 | 666 { |
667 gripe_data_conversion ("IEEE little endian", "VAX D"); | |
668 } | |
669 | |
670 static void | |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10314
diff
changeset
|
671 IEEE_big_float_to_VAX_D_float (void * /* d */, octave_idx_type /* len */) |
1960 | 672 { |
673 gripe_data_conversion ("IEEE big endian", "VAX D"); | |
674 } | |
675 | |
676 static void | |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10314
diff
changeset
|
677 VAX_G_float_to_VAX_D_float (void * /* d */, octave_idx_type /* len */) |
1960 | 678 { |
679 gripe_data_conversion ("VAX G float", "VAX D"); | |
680 } | |
681 | |
682 static void | |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10314
diff
changeset
|
683 Cray_to_VAX_D_float (void * /* d */, octave_idx_type /* len */) |
1960 | 684 { |
685 gripe_data_conversion ("Cray", "VAX D"); | |
686 } | |
687 | |
688 static void | |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10314
diff
changeset
|
689 IEEE_little_double_to_VAX_G_double (void * /* d */, octave_idx_type /* len */) |
1960 | 690 { |
691 gripe_data_conversion ("IEEE little endian", "VAX G"); | |
692 } | |
693 | |
694 static void | |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10314
diff
changeset
|
695 IEEE_big_double_to_VAX_G_double (void * /* d */, octave_idx_type /* len */) |
1960 | 696 { |
697 gripe_data_conversion ("IEEE big endian", "VAX G"); | |
698 } | |
699 | |
700 static void | |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10314
diff
changeset
|
701 VAX_D_double_to_VAX_G_double (void * /* d */, octave_idx_type /* len */) |
1960 | 702 { |
703 gripe_data_conversion ("VAX D float", "VAX G"); | |
704 } | |
705 | |
706 static void | |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10314
diff
changeset
|
707 Cray_to_VAX_G_double (void * /* d */, octave_idx_type /* len */) |
1960 | 708 { |
709 gripe_data_conversion ("VAX G float", "VAX G"); | |
710 } | |
711 | |
712 static void | |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10314
diff
changeset
|
713 IEEE_little_float_to_VAX_G_float (void * /* d */, octave_idx_type /* len */) |
1960 | 714 { |
715 gripe_data_conversion ("IEEE little endian", "VAX G"); | |
716 } | |
717 | |
718 static void | |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10314
diff
changeset
|
719 IEEE_big_float_to_VAX_G_float (void * /* d */, octave_idx_type /* len */) |
1960 | 720 { |
721 gripe_data_conversion ("IEEE big endian", "VAX G"); | |
722 } | |
723 | |
724 static void | |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10314
diff
changeset
|
725 VAX_D_float_to_VAX_G_float (void * /* d */, octave_idx_type /* len */) |
1960 | 726 { |
727 gripe_data_conversion ("VAX D float", "VAX G"); | |
728 } | |
729 | |
730 static void | |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10314
diff
changeset
|
731 Cray_to_VAX_G_float (void * /* d */, octave_idx_type /* len */) |
1960 | 732 { |
733 gripe_data_conversion ("VAX G float", "VAX G"); | |
734 } | |
735 | |
736 void | |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10314
diff
changeset
|
737 do_double_format_conversion (void *data, octave_idx_type len, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
738 oct_mach_info::float_format from_fmt, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
739 oct_mach_info::float_format to_fmt) |
1960 | 740 { |
4944 | 741 switch (to_fmt) |
1960 | 742 { |
4574 | 743 case oct_mach_info::flt_fmt_ieee_little_endian: |
4944 | 744 switch (from_fmt) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
745 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
746 case oct_mach_info::flt_fmt_ieee_little_endian: |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
747 break; |
1960 | 748 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
749 case oct_mach_info::flt_fmt_ieee_big_endian: |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
750 IEEE_big_double_to_IEEE_little_double (data, len); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
751 break; |
1960 | 752 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
753 case oct_mach_info::flt_fmt_vax_d: |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
754 VAX_D_double_to_IEEE_little_double (data, len); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
755 break; |
1960 | 756 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
757 case oct_mach_info::flt_fmt_vax_g: |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
758 VAX_G_double_to_IEEE_little_double (data, len); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
759 break; |
1960 | 760 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
761 case oct_mach_info::flt_fmt_cray: |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
762 Cray_to_IEEE_little_double (data, len); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
763 break; |
1960 | 764 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
765 default: |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
766 gripe_unrecognized_float_fmt (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
767 break; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
768 } |
1960 | 769 break; |
770 | |
4574 | 771 case oct_mach_info::flt_fmt_ieee_big_endian: |
4944 | 772 switch (from_fmt) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
773 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
774 case oct_mach_info::flt_fmt_ieee_little_endian: |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
775 IEEE_little_double_to_IEEE_big_double (data, len); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
776 break; |
1960 | 777 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
778 case oct_mach_info::flt_fmt_ieee_big_endian: |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
779 break; |
1960 | 780 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
781 case oct_mach_info::flt_fmt_vax_d: |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
782 VAX_D_double_to_IEEE_big_double (data, len); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
783 break; |
1960 | 784 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
785 case oct_mach_info::flt_fmt_vax_g: |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
786 VAX_G_double_to_IEEE_big_double (data, len); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
787 break; |
1960 | 788 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
789 case oct_mach_info::flt_fmt_cray: |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
790 Cray_to_IEEE_big_double (data, len); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
791 break; |
1960 | 792 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
793 default: |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
794 gripe_unrecognized_float_fmt (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
795 break; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
796 } |
1960 | 797 break; |
798 | |
4574 | 799 case oct_mach_info::flt_fmt_vax_d: |
4944 | 800 switch (from_fmt) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
801 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
802 case oct_mach_info::flt_fmt_ieee_little_endian: |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
803 IEEE_little_double_to_VAX_D_double (data, len); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
804 break; |
1960 | 805 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
806 case oct_mach_info::flt_fmt_ieee_big_endian: |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
807 IEEE_big_double_to_VAX_D_double (data, len); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
808 break; |
1960 | 809 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
810 case oct_mach_info::flt_fmt_vax_d: |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
811 break; |
1960 | 812 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
813 case oct_mach_info::flt_fmt_vax_g: |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
814 VAX_G_double_to_VAX_D_double (data, len); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
815 break; |
1960 | 816 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
817 case oct_mach_info::flt_fmt_cray: |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
818 Cray_to_VAX_D_double (data, len); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
819 break; |
1960 | 820 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
821 default: |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
822 gripe_unrecognized_float_fmt (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
823 break; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
824 } |
1960 | 825 break; |
826 | |
4574 | 827 case oct_mach_info::flt_fmt_vax_g: |
4944 | 828 switch (from_fmt) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
829 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
830 case oct_mach_info::flt_fmt_ieee_little_endian: |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
831 IEEE_little_double_to_VAX_G_double (data, len); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
832 break; |
1960 | 833 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
834 case oct_mach_info::flt_fmt_ieee_big_endian: |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
835 IEEE_big_double_to_VAX_G_double (data, len); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
836 break; |
1960 | 837 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
838 case oct_mach_info::flt_fmt_vax_d: |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
839 VAX_D_double_to_VAX_G_double (data, len); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
840 break; |
1960 | 841 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
842 case oct_mach_info::flt_fmt_vax_g: |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
843 break; |
1960 | 844 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
845 case oct_mach_info::flt_fmt_cray: |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
846 Cray_to_VAX_G_double (data, len); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
847 break; |
1960 | 848 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
849 default: |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
850 gripe_unrecognized_float_fmt (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
851 break; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
852 } |
1960 | 853 break; |
854 | |
855 default: | |
856 (*current_liboctave_error_handler) | |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
857 ("impossible state reached in file '%s' at line %d", |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
858 __FILE__, __LINE__); |
1960 | 859 break; |
860 } | |
861 } | |
862 | |
863 void | |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10314
diff
changeset
|
864 do_float_format_conversion (void *data, octave_idx_type len, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
865 oct_mach_info::float_format from_fmt, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
866 oct_mach_info::float_format to_fmt) |
1960 | 867 { |
4944 | 868 switch (to_fmt) |
1960 | 869 { |
4574 | 870 case oct_mach_info::flt_fmt_ieee_little_endian: |
4944 | 871 switch (from_fmt) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
872 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
873 case oct_mach_info::flt_fmt_ieee_little_endian: |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
874 break; |
1960 | 875 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
876 case oct_mach_info::flt_fmt_ieee_big_endian: |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
877 IEEE_big_float_to_IEEE_little_float (data, len); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
878 break; |
1960 | 879 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
880 case oct_mach_info::flt_fmt_vax_d: |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
881 VAX_D_float_to_IEEE_little_float (data, len); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
882 break; |
1960 | 883 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
884 case oct_mach_info::flt_fmt_vax_g: |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
885 VAX_G_float_to_IEEE_little_float (data, len); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
886 break; |
1960 | 887 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
888 case oct_mach_info::flt_fmt_cray: |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
889 Cray_to_IEEE_little_float (data, len); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
890 break; |
1960 | 891 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
892 default: |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
893 gripe_unrecognized_float_fmt (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
894 break; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
895 } |
1960 | 896 break; |
897 | |
4574 | 898 case oct_mach_info::flt_fmt_ieee_big_endian: |
4944 | 899 switch (from_fmt) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
900 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
901 case oct_mach_info::flt_fmt_ieee_little_endian: |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
902 IEEE_little_float_to_IEEE_big_float (data, len); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
903 break; |
1960 | 904 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
905 case oct_mach_info::flt_fmt_ieee_big_endian: |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
906 break; |
1960 | 907 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
908 case oct_mach_info::flt_fmt_vax_d: |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
909 VAX_D_float_to_IEEE_big_float (data, len); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
910 break; |
1960 | 911 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
912 case oct_mach_info::flt_fmt_vax_g: |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
913 VAX_G_float_to_IEEE_big_float (data, len); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
914 break; |
1960 | 915 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
916 case oct_mach_info::flt_fmt_cray: |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
917 Cray_to_IEEE_big_float (data, len); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
918 break; |
1960 | 919 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
920 default: |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
921 gripe_unrecognized_float_fmt (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
922 break; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
923 } |
1960 | 924 break; |
925 | |
4574 | 926 case oct_mach_info::flt_fmt_vax_d: |
4944 | 927 switch (from_fmt) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
928 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
929 case oct_mach_info::flt_fmt_ieee_little_endian: |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
930 IEEE_little_float_to_VAX_D_float (data, len); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
931 break; |
1960 | 932 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
933 case oct_mach_info::flt_fmt_ieee_big_endian: |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
934 IEEE_big_float_to_VAX_D_float (data, len); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
935 break; |
1960 | 936 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
937 case oct_mach_info::flt_fmt_vax_d: |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
938 break; |
1960 | 939 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
940 case oct_mach_info::flt_fmt_vax_g: |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
941 VAX_G_float_to_VAX_D_float (data, len); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
942 break; |
1960 | 943 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
944 case oct_mach_info::flt_fmt_cray: |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
945 Cray_to_VAX_D_float (data, len); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
946 break; |
1960 | 947 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
948 default: |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
949 gripe_unrecognized_float_fmt (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
950 break; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
951 } |
1960 | 952 break; |
953 | |
4574 | 954 case oct_mach_info::flt_fmt_vax_g: |
4944 | 955 switch (from_fmt) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
956 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
957 case oct_mach_info::flt_fmt_ieee_little_endian: |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
958 IEEE_little_float_to_VAX_G_float (data, len); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
959 break; |
1960 | 960 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
961 case oct_mach_info::flt_fmt_ieee_big_endian: |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
962 IEEE_big_float_to_VAX_G_float (data, len); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
963 break; |
1960 | 964 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
965 case oct_mach_info::flt_fmt_vax_d: |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
966 VAX_D_float_to_VAX_G_float (data, len); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
967 break; |
1960 | 968 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
969 case oct_mach_info::flt_fmt_vax_g: |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
970 break; |
1960 | 971 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
972 case oct_mach_info::flt_fmt_cray: |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
973 Cray_to_VAX_G_float (data, len); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
974 break; |
1960 | 975 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
976 default: |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
977 gripe_unrecognized_float_fmt (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
978 break; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
979 } |
1960 | 980 break; |
981 | |
982 default: | |
983 (*current_liboctave_error_handler) | |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
984 ("impossible state reached in file '%s' at line %d", |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
985 __FILE__, __LINE__); |
1960 | 986 break; |
987 } | |
988 } | |
989 | |
990 void | |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10314
diff
changeset
|
991 do_float_format_conversion (void *data, size_t sz, octave_idx_type len, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
992 oct_mach_info::float_format from_fmt, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
993 oct_mach_info::float_format to_fmt) |
4944 | 994 { |
995 switch (sz) | |
996 { | |
997 case sizeof (float): | |
998 do_float_format_conversion (data, len, from_fmt, to_fmt); | |
999 break; | |
1000 | |
1001 case sizeof (double): | |
1002 do_double_format_conversion (data, len, from_fmt, to_fmt); | |
1003 break; | |
1004 | |
1005 default: | |
1006 (*current_liboctave_error_handler) | |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
1007 ("impossible state reached in file '%s' at line %d", |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1008 __FILE__, __LINE__); |
4944 | 1009 break; |
1010 } | |
1011 } | |
1012 | |
1013 void | |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10314
diff
changeset
|
1014 read_doubles (std::istream& is, double *data, save_type type, |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10314
diff
changeset
|
1015 octave_idx_type len, bool swap, |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10314
diff
changeset
|
1016 oct_mach_info::float_format fmt) |
1960 | 1017 { |
1018 switch (type) | |
1019 { | |
1020 case LS_U_CHAR: | |
5828 | 1021 LS_DO_READ (uint8_t, swap, data, 1, len, is); |
1960 | 1022 break; |
1023 | |
1024 case LS_U_SHORT: | |
5828 | 1025 LS_DO_READ (uint16_t, swap, data, 2, len, is); |
1960 | 1026 break; |
1027 | |
1028 case LS_U_INT: | |
5828 | 1029 LS_DO_READ (uint32_t, swap, data, 4, len, is); |
1960 | 1030 break; |
1031 | |
1032 case LS_CHAR: | |
5828 | 1033 LS_DO_READ (int8_t, swap, data, 1, len, is); |
1960 | 1034 break; |
1035 | |
1036 case LS_SHORT: | |
5828 | 1037 LS_DO_READ (int16_t, swap, data, 2, len, is); |
1960 | 1038 break; |
1039 | |
1040 case LS_INT: | |
5828 | 1041 LS_DO_READ (int32_t, swap, data, 4, len, is); |
1960 | 1042 break; |
1043 | |
1044 case LS_FLOAT: | |
1045 { | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1046 OCTAVE_LOCAL_BUFFER (float, ptr, len); |
16074
821922270b66
Fix saving binary matrices with up to 2^31 elements (Bug #38326).
Rik <rik@octave.org>
parents:
15467
diff
changeset
|
1047 std::streamsize n_bytes = 4 * len; |
821922270b66
Fix saving binary matrices with up to 2^31 elements (Bug #38326).
Rik <rik@octave.org>
parents:
15467
diff
changeset
|
1048 is.read (reinterpret_cast<char *> (ptr), n_bytes); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1049 do_float_format_conversion (ptr, len, fmt); |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10314
diff
changeset
|
1050 for (octave_idx_type i = 0; i < len; i++) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1051 data[i] = ptr[i]; |
1960 | 1052 } |
1053 break; | |
1054 | |
3359 | 1055 case LS_DOUBLE: // No conversion necessary. |
7991
139f47cf17ab
Change NA value to support single to double precision conversion
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
1056 { |
16074
821922270b66
Fix saving binary matrices with up to 2^31 elements (Bug #38326).
Rik <rik@octave.org>
parents:
15467
diff
changeset
|
1057 std::streamsize n_bytes = 8 * static_cast<std::streamsize> (len); |
821922270b66
Fix saving binary matrices with up to 2^31 elements (Bug #38326).
Rik <rik@octave.org>
parents:
15467
diff
changeset
|
1058 is.read (reinterpret_cast<char *> (data), n_bytes); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1059 do_double_format_conversion (data, len, fmt); |
7991
139f47cf17ab
Change NA value to support single to double precision conversion
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
1060 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1061 for (int i = 0; i < len; i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1062 data[i] = __lo_ieee_replace_old_NA (data[i]); |
7991
139f47cf17ab
Change NA value to support single to double precision conversion
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
1063 } |
1960 | 1064 break; |
1065 | |
1066 default: | |
3504 | 1067 is.clear (std::ios::failbit|is.rdstate ()); |
1960 | 1068 break; |
1069 } | |
1070 } | |
1071 | |
1072 void | |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10314
diff
changeset
|
1073 read_floats (std::istream& is, float *data, save_type type, |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10314
diff
changeset
|
1074 octave_idx_type len, bool swap, |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10314
diff
changeset
|
1075 oct_mach_info::float_format fmt) |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
1076 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
1077 switch (type) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
1078 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
1079 case LS_U_CHAR: |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
1080 LS_DO_READ (uint8_t, swap, data, 1, len, is); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
1081 break; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
1082 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
1083 case LS_U_SHORT: |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
1084 LS_DO_READ (uint16_t, swap, data, 2, len, is); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
1085 break; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
1086 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
1087 case LS_U_INT: |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
1088 LS_DO_READ (uint32_t, swap, data, 4, len, is); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
1089 break; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
1090 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
1091 case LS_CHAR: |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
1092 LS_DO_READ (int8_t, swap, data, 1, len, is); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
1093 break; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
1094 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
1095 case LS_SHORT: |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
1096 LS_DO_READ (int16_t, swap, data, 2, len, is); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
1097 break; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
1098 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
1099 case LS_INT: |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
1100 LS_DO_READ (int32_t, swap, data, 4, len, is); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
1101 break; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
1102 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
1103 case LS_FLOAT: // No conversion necessary. |
16074
821922270b66
Fix saving binary matrices with up to 2^31 elements (Bug #38326).
Rik <rik@octave.org>
parents:
15467
diff
changeset
|
1104 { |
821922270b66
Fix saving binary matrices with up to 2^31 elements (Bug #38326).
Rik <rik@octave.org>
parents:
15467
diff
changeset
|
1105 std::streamsize n_bytes = 4 * len; |
821922270b66
Fix saving binary matrices with up to 2^31 elements (Bug #38326).
Rik <rik@octave.org>
parents:
15467
diff
changeset
|
1106 is.read (reinterpret_cast<char *> (data), n_bytes); |
821922270b66
Fix saving binary matrices with up to 2^31 elements (Bug #38326).
Rik <rik@octave.org>
parents:
15467
diff
changeset
|
1107 do_float_format_conversion (data, len, fmt); |
821922270b66
Fix saving binary matrices with up to 2^31 elements (Bug #38326).
Rik <rik@octave.org>
parents:
15467
diff
changeset
|
1108 } |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
1109 break; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
1110 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
1111 case LS_DOUBLE: |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
1112 { |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1113 OCTAVE_LOCAL_BUFFER (double, ptr, len); |
16074
821922270b66
Fix saving binary matrices with up to 2^31 elements (Bug #38326).
Rik <rik@octave.org>
parents:
15467
diff
changeset
|
1114 std::streamsize n_bytes = 8 * len; |
821922270b66
Fix saving binary matrices with up to 2^31 elements (Bug #38326).
Rik <rik@octave.org>
parents:
15467
diff
changeset
|
1115 is.read (reinterpret_cast<char *> (ptr), n_bytes); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1116 do_double_format_conversion (ptr, len, fmt); |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10314
diff
changeset
|
1117 for (octave_idx_type i = 0; i < len; i++) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1118 data[i] = ptr[i]; |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
1119 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
1120 break; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
1121 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
1122 default: |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
1123 is.clear (std::ios::failbit|is.rdstate ()); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
1124 break; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
1125 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
1126 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
1127 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
1128 void |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10314
diff
changeset
|
1129 write_doubles (std::ostream& os, const double *data, save_type type, |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10314
diff
changeset
|
1130 octave_idx_type len) |
1960 | 1131 { |
1132 switch (type) | |
1133 { | |
1134 case LS_U_CHAR: | |
5828 | 1135 LS_DO_WRITE (uint8_t, data, 1, len, os); |
1960 | 1136 break; |
1137 | |
1138 case LS_U_SHORT: | |
5828 | 1139 LS_DO_WRITE (uint16_t, data, 2, len, os); |
1960 | 1140 break; |
1141 | |
1142 case LS_U_INT: | |
5828 | 1143 LS_DO_WRITE (uint32_t, data, 4, len, os); |
1960 | 1144 break; |
1145 | |
1146 case LS_CHAR: | |
5828 | 1147 LS_DO_WRITE (int8_t, data, 1, len, os); |
1960 | 1148 break; |
1149 | |
1150 case LS_SHORT: | |
5828 | 1151 LS_DO_WRITE (int16_t, data, 2, len, os); |
1960 | 1152 break; |
1153 | |
1154 case LS_INT: | |
5828 | 1155 LS_DO_WRITE (int32_t, data, 4, len, os); |
1960 | 1156 break; |
1157 | |
1158 case LS_FLOAT: | |
1159 LS_DO_WRITE (float, data, 4, len, os); | |
1160 break; | |
1161 | |
3359 | 1162 case LS_DOUBLE: // No conversion necessary. |
1960 | 1163 { |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1164 char tmp_type = static_cast<char> (type); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1165 os.write (&tmp_type, 1); |
16074
821922270b66
Fix saving binary matrices with up to 2^31 elements (Bug #38326).
Rik <rik@octave.org>
parents:
15467
diff
changeset
|
1166 std::streamsize n_bytes = 8 * static_cast<std::streamsize> (len); |
821922270b66
Fix saving binary matrices with up to 2^31 elements (Bug #38326).
Rik <rik@octave.org>
parents:
15467
diff
changeset
|
1167 os.write (reinterpret_cast <const char *> (data), n_bytes); |
1960 | 1168 } |
1169 break; | |
1170 | |
1171 default: | |
1172 (*current_liboctave_error_handler) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1173 ("unrecognized data format requested"); |
1960 | 1174 break; |
1175 } | |
1176 } | |
1177 | |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
1178 void |
10349
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10314
diff
changeset
|
1179 write_floats (std::ostream& os, const float *data, save_type type, |
d4d13389c957
make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents:
10314
diff
changeset
|
1180 octave_idx_type len) |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
1181 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
1182 switch (type) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
1183 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
1184 case LS_U_CHAR: |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
1185 LS_DO_WRITE (uint8_t, data, 1, len, os); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
1186 break; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
1187 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
1188 case LS_U_SHORT: |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
1189 LS_DO_WRITE (uint16_t, data, 2, len, os); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
1190 break; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
1191 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
1192 case LS_U_INT: |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
1193 LS_DO_WRITE (uint32_t, data, 4, len, os); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
1194 break; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
1195 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
1196 case LS_CHAR: |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
1197 LS_DO_WRITE (int8_t, data, 1, len, os); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
1198 break; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
1199 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
1200 case LS_SHORT: |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
1201 LS_DO_WRITE (int16_t, data, 2, len, os); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
1202 break; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
1203 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
1204 case LS_INT: |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
1205 LS_DO_WRITE (int32_t, data, 4, len, os); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
1206 break; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
1207 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
1208 case LS_FLOAT: // No conversion necessary. |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
1209 { |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1210 char tmp_type = static_cast<char> (type); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1211 os.write (&tmp_type, 1); |
16074
821922270b66
Fix saving binary matrices with up to 2^31 elements (Bug #38326).
Rik <rik@octave.org>
parents:
15467
diff
changeset
|
1212 std::streamsize n_bytes = 4 * len; |
821922270b66
Fix saving binary matrices with up to 2^31 elements (Bug #38326).
Rik <rik@octave.org>
parents:
15467
diff
changeset
|
1213 os.write (reinterpret_cast <const char *> (data), n_bytes); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
1214 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
1215 break; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
1216 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
1217 case LS_DOUBLE: |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
1218 LS_DO_WRITE (double, data, 8, len, os); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
1219 break; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
1220 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
1221 default: |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
1222 (*current_liboctave_error_handler) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1223 ("unrecognized data format requested"); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
1224 break; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
1225 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
1226 } |