casacore
Loading...
Searching...
No Matches
IBMConversion.h
Go to the documentation of this file.
1// # IBMConversion.h: A class with static functions to convert IBM format
2// # Copyright (C) 1996,1997,1999,2001
3// # Associated Universities, Inc. Washington DC, USA.
4// #
5// # This library is free software; you can redistribute it and/or modify it
6// # under the terms of the GNU Library General Public License as published by
7// # the Free Software Foundation; either version 2 of the License, or (at your
8// # option) any later version.
9// #
10// # This library is distributed in the hope that it will be useful, but WITHOUT
11// # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12// # FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
13// # License for more details.
14// #
15// # You should have received a copy of the GNU Library General Public License
16// # along with this library; if not, write to the Free Software Foundation,
17// # Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
18// #
19// # Correspondence concerning AIPS++ should be addressed as follows:
20// # Internet email: casa-feedback@nrao.edu.
21// # Postal address: AIPS++ Project Office
22// # National Radio Astronomy Observatory
23// # 520 Edgemont Road
24// # Charlottesville, VA 22903-2475 USA
25
26#ifndef CASA_IBMCONVERSION_H
27#define CASA_IBMCONVERSION_H
28
29// # Includes
30#include <casacore/casa/aips.h>
31#include <casacore/casa/OS/CanonicalConversion.h>
32
33namespace casacore { // # NAMESPACE CASACORE - BEGIN
34
35// Define the IBM sizes of the built-in data types.
36
37#define SIZE_IBM_CHAR 1
38#define SIZE_IBM_UCHAR 1
39#define SIZE_IBM_SHORT 2
40#define SIZE_IBM_USHORT 2
41#define SIZE_IBM_INT 4
42#define SIZE_IBM_UINT 4
43#define SIZE_IBM_INT64 4
44#define SIZE_IBM_UINT64 4
45#define SIZE_IBM_FLOAT 4
46#define SIZE_IBM_DOUBLE 8
47
48// <summary>
49// A class with static functions to convert IBM format
50// </summary>
51
52// <use visibility=export>
53
54// <reviewed reviewer="Friso Olnon" date="1996/11/06" tests="tIBMConversion" demos="">
55// </reviewed>
56
57// <synopsis>
58// This class contains static toLocal functions to convert data from IBM-360
59// format to local format and vice-versa. It also handles the conversion
60// of the IBM EBCDIC characters to ASCII characters (for data type char).
61// <p>
62// The functions work well on big-endian as well as little-endian machines.
63// </synopsis>
64
65// <motivation>
66// Archived WSRT data can be stored in the old IBM format
67// (EBCDIC characters and floats with base 16).
68// Conversion functions are needed to read these data.
69// </motivation>
70
71// <todo asof="$DATE$">
72// <li> Support data type long double.
73// </todo>
74
76 public:
77 // Convert one value from IBM format to local format.
78 // The from and to buffer should not overlap.
79 // <note>
80 // The char version converts from EBCDIC to ASCII, while the
81 // unsigned char version is a simple copy.
82 // </note>
83 // <group>
84 static void toLocal(char& to, const void* from);
85 static void toLocal(unsigned char& to, const void* from);
86 static void toLocal(short& to, const void* from);
87 static void toLocal(unsigned short& to, const void* from);
88 static void toLocal(int& to, const void* from);
89 static void toLocal(unsigned int& to, const void* from);
90 static void toLocal(Int64& to, const void* from);
91 static void toLocal(uInt64& to, const void* from);
92 static void toLocal(float& to, const void* from);
93 static void toLocal(double& to, const void* from);
94 // </group>
95
96 // Convert nr values from IBM format to local format.
97 // The from and to buffer should not overlap.
98 // <note>
99 // The char version converts from EBCDIC to ASCII, while the
100 // unsigned char version is a simple copy.
101 // </note>
102 // <group>
103 static void toLocal(char* to, const void* from, size_t nr);
104 static void toLocal(unsigned char* to, const void* from, size_t nr);
105 static void toLocal(short* to, const void* from, size_t nr);
106 static void toLocal(unsigned short* to, const void* from, size_t nr);
107 static void toLocal(int* to, const void* from, size_t nr);
108 static void toLocal(unsigned int* to, const void* from, size_t nr);
109 static void toLocal(Int64* to, const void* from, size_t nr);
110 static void toLocal(uInt64* to, const void* from, size_t nr);
111 static void toLocal(float* to, const void* from, size_t nr);
112 static void toLocal(double* to, const void* from, size_t nr);
113 // </group>
114
115 // Convert one value from local format to IBM format.
116 // The from and to buffer should not overlap.
117 // <note>
118 // The char version converts from ASCII to EBCDIC, while the
119 // unsigned char version is a simple copy.
120 // </note>
121 // <group>
122 static void fromLocal(void* to, char from);
123 static void fromLocal(void* to, unsigned char from);
124 static void fromLocal(void* to, short from);
125 static void fromLocal(void* to, unsigned short from);
126 static void fromLocal(void* to, int from);
127 static void fromLocal(void* to, unsigned int from);
128 static void fromLocal(void* to, Int64 from);
129 static void fromLocal(void* to, uInt64 from);
130 static void fromLocal(void* to, float from);
131 static void fromLocal(void* to, double from);
132 // </group>
133
134 // Convert nr values from local format to IBM format.
135 // The from and to buffer should not overlap.
136 // <note>
137 // The char version converts from ASCII to EBCDIC, while the
138 // unsigned char version is a simple copy.
139 // </note>
140 // <group>
141 static void fromLocal(void* to, const char* from, size_t nr);
142 static void fromLocal(void* to, const unsigned char* from, size_t nr);
143 static void fromLocal(void* to, const short* from, size_t nr);
144 static void fromLocal(void* to, const unsigned short* from, size_t nr);
145 static void fromLocal(void* to, const int* from, size_t nr);
146 static void fromLocal(void* to, const unsigned int* from, size_t nr);
147 static void fromLocal(void* to, const Int64* from, size_t nr);
148 static void fromLocal(void* to, const uInt64* from, size_t nr);
149 static void fromLocal(void* to, const float* from, size_t nr);
150 static void fromLocal(void* to, const double* from, size_t nr);
151 // </group>
152
153 private:
154 // This class should not be constructed
155 // (so declare the constructor private).
157};
158
159inline void IBMConversion::toLocal(unsigned char& to, const void* from) {
161}
162
163inline void IBMConversion::toLocal(short& to, const void* from) {
165}
166
167inline void IBMConversion::toLocal(unsigned short& to, const void* from) {
169}
170
171inline void IBMConversion::toLocal(int& to, const void* from) {
173}
174
175inline void IBMConversion::toLocal(unsigned int& to, const void* from) {
177}
178
179inline void IBMConversion::toLocal(Int64& to, const void* from) {
180 if (sizeof(Int64) != 4) {
181 if (((signed char*)from)[0] < 0) {
182 to = -1;
183 } else {
184 to = 0;
185 }
186 }
187#if defined(AIPS_LITTLE_ENDIAN)
189#else
190 CanonicalConversion::move4(((char*)&to) + sizeof(Int64) - 4, from);
191#endif
192}
193
194inline void IBMConversion::toLocal(uInt64& to, const void* from) {
195 if (sizeof(uInt64) != 4) {
196 to = 0;
197 }
198#if defined(AIPS_LITTLE_ENDIAN)
200#else
201 CanonicalConversion::move4(((char*)&to) + sizeof(uInt64) - 4, from);
202#endif
203}
204
205inline void IBMConversion::toLocal(float& to, const void* from) { toLocal(&to, from, 1); }
206
207inline void IBMConversion::toLocal(double& to, const void* from) { toLocal(&to, from, 1); }
208
209inline void IBMConversion::toLocal(unsigned char* to, const void* from, size_t nr) {
210 CanonicalConversion::toLocal(to, from, nr);
211}
212
213inline void IBMConversion::toLocal(short* to, const void* from, size_t nr) {
214 CanonicalConversion::toLocal(to, from, nr);
215}
216
217inline void IBMConversion::toLocal(unsigned short* to, const void* from, size_t nr) {
218 CanonicalConversion::toLocal(to, from, nr);
219}
220
221inline void IBMConversion::toLocal(int* to, const void* from, size_t nr) {
222 CanonicalConversion::toLocal(to, from, nr);
223}
224
225inline void IBMConversion::toLocal(unsigned int* to, const void* from, size_t nr) {
226 CanonicalConversion::toLocal(to, from, nr);
227}
228
229inline void IBMConversion::fromLocal(void* to, unsigned char from) {
231}
232
233inline void IBMConversion::fromLocal(void* to, short from) {
235}
236
237inline void IBMConversion::fromLocal(void* to, unsigned short from) {
239}
240
241inline void IBMConversion::fromLocal(void* to, int from) {
243}
244
245inline void IBMConversion::fromLocal(void* to, unsigned int from) {
247}
248
249inline void IBMConversion::fromLocal(void* to, Int64 from) {
250#if defined(AIPS_LITTLE_ENDIAN)
252#else
253 CanonicalConversion::move4(to, ((char*)&from) + sizeof(Int64) - 4);
254#endif
255}
256
257inline void IBMConversion::fromLocal(void* to, uInt64 from) {
258#if defined(AIPS_LITTLE_ENDIAN)
260#else
261 CanonicalConversion::move4(to, ((char*)&from) + sizeof(uInt64) - 4);
262#endif
263}
264
265inline void IBMConversion::fromLocal(void* to, float from) { fromLocal(to, &from, 1); }
266
267inline void IBMConversion::fromLocal(void* to, double from) { fromLocal(to, &from, 1); }
268
269inline void IBMConversion::fromLocal(void* to, const unsigned char* from, size_t nr) {
270 CanonicalConversion::fromLocal(to, from, nr);
271}
272
273inline void IBMConversion::fromLocal(void* to, const short* from, size_t nr) {
274 CanonicalConversion::fromLocal(to, from, nr);
275}
276
277inline void IBMConversion::fromLocal(void* to, const unsigned short* from, size_t nr) {
278 CanonicalConversion::fromLocal(to, from, nr);
279}
280
281inline void IBMConversion::fromLocal(void* to, const int* from, size_t nr) {
282 CanonicalConversion::fromLocal(to, from, nr);
283}
284
285inline void IBMConversion::fromLocal(void* to, const unsigned int* from, size_t nr) {
286 CanonicalConversion::fromLocal(to, from, nr);
287}
288
289} // namespace casacore
290
291#endif
static size_t fromLocal(void *to, const char &from)
Convert one value from local format to canonical format.
static void reverse4(void *to, const void *from)
Reverse 4 bytes.
static size_t toLocal(char &to, const void *from)
Convert one value from canonical format to local format.
static void move4(void *to, const void *from)
Move 4 bytes.
IBMConversion()
This class should not be constructed (so declare the constructor private).
static void fromLocal(void *to, char from)
Convert one value from local format to IBM format.
static void fromLocal(void *to, const float *from, size_t nr)
static void toLocal(double *to, const void *from, size_t nr)
static void fromLocal(void *to, const double *from, size_t nr)
static void fromLocal(void *to, const char *from, size_t nr)
Convert nr values from local format to IBM format.
static void fromLocal(void *to, const Int64 *from, size_t nr)
static void toLocal(Int64 *to, const void *from, size_t nr)
static void toLocal(char &to, const void *from)
Convert one value from IBM format to local format.
static void fromLocal(void *to, const uInt64 *from, size_t nr)
static void toLocal(char *to, const void *from, size_t nr)
Convert nr values from IBM format to local format.
static void toLocal(float *to, const void *from, size_t nr)
static void toLocal(uInt64 *to, const void *from, size_t nr)
For temporary backward namespace compatibility, use casa as alias for casacore.
Definition mainpage.dox:28
long long Int64
Define the extra non-standard types used by Casacore (like proposed uSize, Size).
Definition aipsxtype.h:36
unsigned long long uInt64
Definition aipsxtype.h:37