annotate liboctave/data-conv.h @ 12312:b10ea6efdc58 release-3-4-x ss-3-3-91

version is now 3.3.91
author John W. Eaton <jwe@octave.org>
date Mon, 31 Jan 2011 08:36:58 -0500
parents fd0a3ac60b0e
children 72c96de7a403
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1960
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
1 /*
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
2
11523
fd0a3ac60b0e update copyright notices
John W. Eaton <jwe@octave.org>
parents: 10349
diff changeset
3 Copyright (C) 1996-2011 John W. Eaton
1960
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
4
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
5 This file is part of Octave.
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
6
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
7 Octave is free software; you can redistribute it and/or modify it
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
8 under the terms of the GNU General Public License as published by the
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6108
diff changeset
9 Free Software Foundation; either version 3 of the License, or (at your
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6108
diff changeset
10 option) any later version.
1960
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
11
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
12 Octave is distributed in the hope that it will be useful, but WITHOUT
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
15 for more details.
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
16
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6108
diff changeset
18 along with Octave; see the file COPYING. If not, see
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6108
diff changeset
19 <http://www.gnu.org/licenses/>.
1960
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
20
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
21 */
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
22
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
23 #if !defined (octave_data_conv_h)
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
24 #define octave_data_conv_h 1
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
25
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
26 #include <climits>
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
27
2317
8c09c04f7747 [project @ 1996-07-14 22:30:15 by jwe]
jwe
parents: 1993
diff changeset
28 #include "mach-info.h"
1960
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
29
2317
8c09c04f7747 [project @ 1996-07-14 22:30:15 by jwe]
jwe
parents: 1993
diff changeset
30 class
6108
143b556ce725 [project @ 2006-10-27 01:45:54 by jwe]
jwe
parents: 5828
diff changeset
31 OCTAVE_API
2317
8c09c04f7747 [project @ 1996-07-14 22:30:15 by jwe]
jwe
parents: 1993
diff changeset
32 oct_data_conv
8c09c04f7747 [project @ 1996-07-14 22:30:15 by jwe]
jwe
parents: 1993
diff changeset
33 {
8c09c04f7747 [project @ 1996-07-14 22:30:15 by jwe]
jwe
parents: 1993
diff changeset
34 public:
8c09c04f7747 [project @ 1996-07-14 22:30:15 by jwe]
jwe
parents: 1993
diff changeset
35
8c09c04f7747 [project @ 1996-07-14 22:30:15 by jwe]
jwe
parents: 1993
diff changeset
36 enum data_type
8c09c04f7747 [project @ 1996-07-14 22:30:15 by jwe]
jwe
parents: 1993
diff changeset
37 {
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 3739
diff changeset
38 dt_int8 = 0,
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 3739
diff changeset
39 dt_uint8 = 1,
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 3739
diff changeset
40 dt_int16 = 2,
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 3739
diff changeset
41 dt_uint16 = 3,
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 3739
diff changeset
42 dt_int32 = 4,
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 3739
diff changeset
43 dt_uint32 = 5,
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 3739
diff changeset
44 dt_int64 = 6,
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 3739
diff changeset
45 dt_uint64 = 7,
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 3739
diff changeset
46 dt_single = 8,
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 3739
diff changeset
47 dt_double = 9,
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 3739
diff changeset
48 dt_char = 10,
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 3739
diff changeset
49 dt_schar = 11,
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 3739
diff changeset
50 dt_uchar = 12,
4970
25c2664861bc [project @ 2004-09-08 05:02:32 by jwe]
jwe
parents: 4944
diff changeset
51 dt_logical = 13,
25c2664861bc [project @ 2004-09-08 05:02:32 by jwe]
jwe
parents: 4944
diff changeset
52 dt_short = 14,
25c2664861bc [project @ 2004-09-08 05:02:32 by jwe]
jwe
parents: 4944
diff changeset
53 dt_ushort = 15,
25c2664861bc [project @ 2004-09-08 05:02:32 by jwe]
jwe
parents: 4944
diff changeset
54 dt_int = 16,
25c2664861bc [project @ 2004-09-08 05:02:32 by jwe]
jwe
parents: 4944
diff changeset
55 dt_uint = 17,
25c2664861bc [project @ 2004-09-08 05:02:32 by jwe]
jwe
parents: 4944
diff changeset
56 dt_long = 18,
25c2664861bc [project @ 2004-09-08 05:02:32 by jwe]
jwe
parents: 4944
diff changeset
57 dt_ulong = 19,
25c2664861bc [project @ 2004-09-08 05:02:32 by jwe]
jwe
parents: 4944
diff changeset
58 dt_longlong = 20,
25c2664861bc [project @ 2004-09-08 05:02:32 by jwe]
jwe
parents: 4944
diff changeset
59 dt_ulonglong = 21,
25c2664861bc [project @ 2004-09-08 05:02:32 by jwe]
jwe
parents: 4944
diff changeset
60 dt_float = 22,
25c2664861bc [project @ 2004-09-08 05:02:32 by jwe]
jwe
parents: 4944
diff changeset
61 dt_unknown = 23 // Must be last, have largest value!
2317
8c09c04f7747 [project @ 1996-07-14 22:30:15 by jwe]
jwe
parents: 1993
diff changeset
62 };
8c09c04f7747 [project @ 1996-07-14 22:30:15 by jwe]
jwe
parents: 1993
diff changeset
63
3504
5eef8a2294bd [project @ 2000-02-01 10:06:51 by jwe]
jwe
parents: 2847
diff changeset
64 static data_type string_to_data_type (const std::string& s);
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 3739
diff changeset
65
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 3739
diff changeset
66 static void string_to_data_type (const std::string& s, int& block_size,
10312
cbc402e64d83 untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
67 data_type& input_type,
cbc402e64d83 untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
68 data_type& output_type);
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 3739
diff changeset
69
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 3739
diff changeset
70 static void string_to_data_type (const std::string& s, int& block_size,
10312
cbc402e64d83 untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
71 data_type& output_type);
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 3739
diff changeset
72
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 3739
diff changeset
73 static std::string data_type_as_string (data_type dt);
2317
8c09c04f7747 [project @ 1996-07-14 22:30:15 by jwe]
jwe
parents: 1993
diff changeset
74 };
8c09c04f7747 [project @ 1996-07-14 22:30:15 by jwe]
jwe
parents: 1993
diff changeset
75
3739
85027c5aedc2 [project @ 2000-11-21 01:55:32 by jwe]
jwe
parents: 3688
diff changeset
76 // Add new entries to the end of this enum, otherwise Octave will not
85027c5aedc2 [project @ 2000-11-21 01:55:32 by jwe]
jwe
parents: 3688
diff changeset
77 // be able to read binary data files stored in Octave's binary data
85027c5aedc2 [project @ 2000-11-21 01:55:32 by jwe]
jwe
parents: 3688
diff changeset
78 // format that were created with previous versions of Octave.
85027c5aedc2 [project @ 2000-11-21 01:55:32 by jwe]
jwe
parents: 3688
diff changeset
79
1960
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
80 enum save_type
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
81 {
3739
85027c5aedc2 [project @ 2000-11-21 01:55:32 by jwe]
jwe
parents: 3688
diff changeset
82 LS_U_CHAR = 0,
85027c5aedc2 [project @ 2000-11-21 01:55:32 by jwe]
jwe
parents: 3688
diff changeset
83 LS_U_SHORT = 1,
85027c5aedc2 [project @ 2000-11-21 01:55:32 by jwe]
jwe
parents: 3688
diff changeset
84 LS_U_INT = 2,
85027c5aedc2 [project @ 2000-11-21 01:55:32 by jwe]
jwe
parents: 3688
diff changeset
85 LS_CHAR = 3,
85027c5aedc2 [project @ 2000-11-21 01:55:32 by jwe]
jwe
parents: 3688
diff changeset
86 LS_SHORT = 4,
85027c5aedc2 [project @ 2000-11-21 01:55:32 by jwe]
jwe
parents: 3688
diff changeset
87 LS_INT = 5,
85027c5aedc2 [project @ 2000-11-21 01:55:32 by jwe]
jwe
parents: 3688
diff changeset
88 LS_FLOAT = 6,
85027c5aedc2 [project @ 2000-11-21 01:55:32 by jwe]
jwe
parents: 3688
diff changeset
89 LS_DOUBLE = 7,
85027c5aedc2 [project @ 2000-11-21 01:55:32 by jwe]
jwe
parents: 3688
diff changeset
90 LS_U_LONG = 8,
85027c5aedc2 [project @ 2000-11-21 01:55:32 by jwe]
jwe
parents: 3688
diff changeset
91 LS_LONG = 9
1960
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
92 };
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
93
6108
143b556ce725 [project @ 2006-10-27 01:45:54 by jwe]
jwe
parents: 5828
diff changeset
94 extern OCTAVE_API void
10349
d4d13389c957 make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents: 10312
diff changeset
95 do_double_format_conversion (void *data, octave_idx_type len,
10312
cbc402e64d83 untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
96 oct_mach_info::float_format from_fmt,
cbc402e64d83 untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
97 oct_mach_info::float_format to_fmt
cbc402e64d83 untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
98 = oct_mach_info::native_float_format ());
1960
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
99
6108
143b556ce725 [project @ 2006-10-27 01:45:54 by jwe]
jwe
parents: 5828
diff changeset
100 extern OCTAVE_API void
10349
d4d13389c957 make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents: 10312
diff changeset
101 do_float_format_conversion (void *data, octave_idx_type len,
10312
cbc402e64d83 untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
102 oct_mach_info::float_format from_fmt,
cbc402e64d83 untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
103 oct_mach_info::float_format to_fmt
cbc402e64d83 untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
104 = oct_mach_info::native_float_format ());
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 3739
diff changeset
105
6108
143b556ce725 [project @ 2006-10-27 01:45:54 by jwe]
jwe
parents: 5828
diff changeset
106 extern OCTAVE_API void
10349
d4d13389c957 make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents: 10312
diff changeset
107 do_float_format_conversion (void *data, size_t sz, octave_idx_type len,
10312
cbc402e64d83 untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
108 oct_mach_info::float_format from_fmt,
cbc402e64d83 untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
109 oct_mach_info::float_format to_fmt
cbc402e64d83 untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
110 = oct_mach_info::native_float_format ());
1960
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
111
6108
143b556ce725 [project @ 2006-10-27 01:45:54 by jwe]
jwe
parents: 5828
diff changeset
112 extern OCTAVE_API void
10349
d4d13389c957 make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents: 10312
diff changeset
113 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: 10312
diff changeset
114 octave_idx_type len, bool swap, oct_mach_info::float_format fmt);
d4d13389c957 make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents: 10312
diff changeset
115
6108
143b556ce725 [project @ 2006-10-27 01:45:54 by jwe]
jwe
parents: 5828
diff changeset
116 extern OCTAVE_API void
10349
d4d13389c957 make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents: 10312
diff changeset
117 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: 10312
diff changeset
118 octave_idx_type len);
1960
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
119
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
120 extern OCTAVE_API void
10349
d4d13389c957 make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents: 10312
diff changeset
121 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: 10312
diff changeset
122 octave_idx_type len, bool swap, oct_mach_info::float_format fmt);
d4d13389c957 make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents: 10312
diff changeset
123
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
124 extern OCTAVE_API void
10349
d4d13389c957 make load-save to matlab format work when using --enable-64
John W. Eaton <jwe@octave.org>
parents: 10312
diff changeset
125 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: 10312
diff changeset
126 octave_idx_type len);
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
127
1960
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
128 #endif