annotate liboctave/data-conv.h @ 5403:7bdddf96f028

[project @ 2005-07-07 16:46:23 by jwe]
author jwe
date Thu, 07 Jul 2005 16:46:24 +0000
parents 4c8a2e4e0717
children 22e23bee74c8
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
2847
8b262e771614 [project @ 1997-03-27 16:18:26 by jwe]
jwe
parents: 2802
diff changeset
3 Copyright (C) 1996, 1997 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
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
9 Free Software Foundation; either version 2, or (at your option) any
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
10 later version.
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
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
18 along with Octave; see the file COPYING. If not, write to the Free
5307
4c8a2e4e0717 [project @ 2005-04-26 19:24:27 by jwe]
jwe
parents: 4970
diff changeset
19 Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
4c8a2e4e0717 [project @ 2005-04-26 19:24:27 by jwe]
jwe
parents: 4970
diff changeset
20 02110-1301, USA.
1960
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
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
24 #if !defined (octave_data_conv_h)
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
25 #define octave_data_conv_h 1
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
26
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
27 #include <climits>
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
28
2317
8c09c04f7747 [project @ 1996-07-14 22:30:15 by jwe]
jwe
parents: 1993
diff changeset
29 #include "mach-info.h"
1960
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
30
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
31 // Not all of the following are currently used.
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
32
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
33 #if CHAR_BIT != 8
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
34 #error "CHAR_BIT is not 8!"
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
35 #endif
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
36
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
37 #if SIZEOF_SHORT == 2
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
38 #define TWO_BYTE_INT short
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
39 #elif SIZEOF_INT == 2
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
40 #define TWO_BYTE_INT int
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
41 #else
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
42 #error "No 2 byte integer type found!"
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
43 #endif
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
44
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
45 #if SIZEOF_INT == 4
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
46 #define FOUR_BYTE_INT int
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
47 #elif SIZEOF_LONG == 4
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
48 #define FOUR_BYTE_INT long
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
49 #else
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
50 #error "No 4 byte integer type found!"
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
51 #endif
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
52
3688
8aea513ff224 [project @ 2000-06-29 22:50:23 by jwe]
jwe
parents: 3504
diff changeset
53 #if SIZEOF_LONG == 8
8aea513ff224 [project @ 2000-06-29 22:50:23 by jwe]
jwe
parents: 3504
diff changeset
54 #define EIGHT_BYTE_INT long
8aea513ff224 [project @ 2000-06-29 22:50:23 by jwe]
jwe
parents: 3504
diff changeset
55 #else
8aea513ff224 [project @ 2000-06-29 22:50:23 by jwe]
jwe
parents: 3504
diff changeset
56 #if SIZEOF_LONG_LONG == 8
8aea513ff224 [project @ 2000-06-29 22:50:23 by jwe]
jwe
parents: 3504
diff changeset
57 // if `long long' is not implemented, then SIZEOF_LONG_LONG will be 0
8aea513ff224 [project @ 2000-06-29 22:50:23 by jwe]
jwe
parents: 3504
diff changeset
58 #define EIGHT_BYTE_INT long long
8aea513ff224 [project @ 2000-06-29 22:50:23 by jwe]
jwe
parents: 3504
diff changeset
59 // if no 8 byte integer type is found, then EIGHT_BYTE_INT is not defined
8aea513ff224 [project @ 2000-06-29 22:50:23 by jwe]
jwe
parents: 3504
diff changeset
60 #endif
8aea513ff224 [project @ 2000-06-29 22:50:23 by jwe]
jwe
parents: 3504
diff changeset
61 #endif
8aea513ff224 [project @ 2000-06-29 22:50:23 by jwe]
jwe
parents: 3504
diff changeset
62
2317
8c09c04f7747 [project @ 1996-07-14 22:30:15 by jwe]
jwe
parents: 1993
diff changeset
63 class
8c09c04f7747 [project @ 1996-07-14 22:30:15 by jwe]
jwe
parents: 1993
diff changeset
64 oct_data_conv
8c09c04f7747 [project @ 1996-07-14 22:30:15 by jwe]
jwe
parents: 1993
diff changeset
65 {
8c09c04f7747 [project @ 1996-07-14 22:30:15 by jwe]
jwe
parents: 1993
diff changeset
66 public:
8c09c04f7747 [project @ 1996-07-14 22:30:15 by jwe]
jwe
parents: 1993
diff changeset
67
8c09c04f7747 [project @ 1996-07-14 22:30:15 by jwe]
jwe
parents: 1993
diff changeset
68 enum data_type
8c09c04f7747 [project @ 1996-07-14 22:30:15 by jwe]
jwe
parents: 1993
diff changeset
69 {
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 3739
diff changeset
70 dt_int8 = 0,
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 3739
diff changeset
71 dt_uint8 = 1,
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 3739
diff changeset
72 dt_int16 = 2,
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 3739
diff changeset
73 dt_uint16 = 3,
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 3739
diff changeset
74 dt_int32 = 4,
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 3739
diff changeset
75 dt_uint32 = 5,
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 3739
diff changeset
76 dt_int64 = 6,
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 3739
diff changeset
77 dt_uint64 = 7,
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 3739
diff changeset
78 dt_single = 8,
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 3739
diff changeset
79 dt_double = 9,
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 3739
diff changeset
80 dt_char = 10,
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 3739
diff changeset
81 dt_schar = 11,
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 3739
diff changeset
82 dt_uchar = 12,
4970
25c2664861bc [project @ 2004-09-08 05:02:32 by jwe]
jwe
parents: 4944
diff changeset
83 dt_logical = 13,
25c2664861bc [project @ 2004-09-08 05:02:32 by jwe]
jwe
parents: 4944
diff changeset
84 dt_short = 14,
25c2664861bc [project @ 2004-09-08 05:02:32 by jwe]
jwe
parents: 4944
diff changeset
85 dt_ushort = 15,
25c2664861bc [project @ 2004-09-08 05:02:32 by jwe]
jwe
parents: 4944
diff changeset
86 dt_int = 16,
25c2664861bc [project @ 2004-09-08 05:02:32 by jwe]
jwe
parents: 4944
diff changeset
87 dt_uint = 17,
25c2664861bc [project @ 2004-09-08 05:02:32 by jwe]
jwe
parents: 4944
diff changeset
88 dt_long = 18,
25c2664861bc [project @ 2004-09-08 05:02:32 by jwe]
jwe
parents: 4944
diff changeset
89 dt_ulong = 19,
25c2664861bc [project @ 2004-09-08 05:02:32 by jwe]
jwe
parents: 4944
diff changeset
90 dt_longlong = 20,
25c2664861bc [project @ 2004-09-08 05:02:32 by jwe]
jwe
parents: 4944
diff changeset
91 dt_ulonglong = 21,
25c2664861bc [project @ 2004-09-08 05:02:32 by jwe]
jwe
parents: 4944
diff changeset
92 dt_float = 22,
25c2664861bc [project @ 2004-09-08 05:02:32 by jwe]
jwe
parents: 4944
diff changeset
93 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
94 };
8c09c04f7747 [project @ 1996-07-14 22:30:15 by jwe]
jwe
parents: 1993
diff changeset
95
3504
5eef8a2294bd [project @ 2000-02-01 10:06:51 by jwe]
jwe
parents: 2847
diff changeset
96 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
97
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 3739
diff changeset
98 static void string_to_data_type (const std::string& s, int& block_size,
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 3739
diff changeset
99 data_type& input_type,
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 3739
diff changeset
100 data_type& output_type);
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 3739
diff changeset
101
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 3739
diff changeset
102 static void string_to_data_type (const std::string& s, int& block_size,
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 3739
diff changeset
103 data_type& output_type);
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 3739
diff changeset
104
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 3739
diff changeset
105 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
106 };
8c09c04f7747 [project @ 1996-07-14 22:30:15 by jwe]
jwe
parents: 1993
diff changeset
107
3739
85027c5aedc2 [project @ 2000-11-21 01:55:32 by jwe]
jwe
parents: 3688
diff changeset
108 // 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
109 // 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
110 // format that were created with previous versions of Octave.
85027c5aedc2 [project @ 2000-11-21 01:55:32 by jwe]
jwe
parents: 3688
diff changeset
111
1960
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
112 enum save_type
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
113 {
3739
85027c5aedc2 [project @ 2000-11-21 01:55:32 by jwe]
jwe
parents: 3688
diff changeset
114 LS_U_CHAR = 0,
85027c5aedc2 [project @ 2000-11-21 01:55:32 by jwe]
jwe
parents: 3688
diff changeset
115 LS_U_SHORT = 1,
85027c5aedc2 [project @ 2000-11-21 01:55:32 by jwe]
jwe
parents: 3688
diff changeset
116 LS_U_INT = 2,
85027c5aedc2 [project @ 2000-11-21 01:55:32 by jwe]
jwe
parents: 3688
diff changeset
117 LS_CHAR = 3,
85027c5aedc2 [project @ 2000-11-21 01:55:32 by jwe]
jwe
parents: 3688
diff changeset
118 LS_SHORT = 4,
85027c5aedc2 [project @ 2000-11-21 01:55:32 by jwe]
jwe
parents: 3688
diff changeset
119 LS_INT = 5,
85027c5aedc2 [project @ 2000-11-21 01:55:32 by jwe]
jwe
parents: 3688
diff changeset
120 LS_FLOAT = 6,
85027c5aedc2 [project @ 2000-11-21 01:55:32 by jwe]
jwe
parents: 3688
diff changeset
121 LS_DOUBLE = 7,
85027c5aedc2 [project @ 2000-11-21 01:55:32 by jwe]
jwe
parents: 3688
diff changeset
122 LS_U_LONG = 8,
85027c5aedc2 [project @ 2000-11-21 01:55:32 by jwe]
jwe
parents: 3688
diff changeset
123 LS_LONG = 9
1960
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
124 };
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
125
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
126 extern void
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 3739
diff changeset
127 do_double_format_conversion (void *data, int len,
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 3739
diff changeset
128 oct_mach_info::float_format from_fmt,
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 3739
diff changeset
129 oct_mach_info::float_format to_fmt
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 3739
diff changeset
130 = oct_mach_info::native_float_format ());
1960
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
131
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
132 extern void
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 3739
diff changeset
133 do_float_format_conversion (void *data, int len,
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 3739
diff changeset
134 oct_mach_info::float_format from_fmt,
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 3739
diff changeset
135 oct_mach_info::float_format to_fmt
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 3739
diff changeset
136 = oct_mach_info::native_float_format ());
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 3739
diff changeset
137
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 3739
diff changeset
138 extern void
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 3739
diff changeset
139 do_float_format_conversion (void *data, size_t sz, int len,
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 3739
diff changeset
140 oct_mach_info::float_format from_fmt,
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 3739
diff changeset
141 oct_mach_info::float_format to_fmt
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 3739
diff changeset
142 = oct_mach_info::native_float_format ());
1960
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
143
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
144 extern void
3504
5eef8a2294bd [project @ 2000-02-01 10:06:51 by jwe]
jwe
parents: 2847
diff changeset
145 read_doubles (std::istream& is, double *data, save_type type, int len,
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 3739
diff changeset
146 bool swap, oct_mach_info::float_format fmt);
1960
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
147 extern void
3504
5eef8a2294bd [project @ 2000-02-01 10:06:51 by jwe]
jwe
parents: 2847
diff changeset
148 write_doubles (std::ostream& os, const double *data, save_type type, int len);
1960
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
149
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
150 #endif
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
151
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
152 /*
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
153 ;;; Local Variables: ***
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
154 ;;; mode: C++ ***
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
155 ;;; End: ***
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
156 */