annotate liboctave/data-conv.h @ 5100:5a92c3177fc6 before-gnuplot-split

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