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
33
34namespace casacore { //# NAMESPACE CASACORE - BEGIN
35
36// Define the IBM sizes of the built-in data types.
37
38#define SIZE_IBM_CHAR 1
39#define SIZE_IBM_UCHAR 1
40#define SIZE_IBM_SHORT 2
41#define SIZE_IBM_USHORT 2
42#define SIZE_IBM_INT 4
43#define SIZE_IBM_UINT 4
44#define SIZE_IBM_INT64 4
45#define SIZE_IBM_UINT64 4
46#define SIZE_IBM_FLOAT 4
47#define SIZE_IBM_DOUBLE 8
48
49
50// <summary>
51// A class with static functions to convert IBM format
52// </summary>
53
54// <use visibility=export>
55
56// <reviewed reviewer="Friso Olnon" date="1996/11/06" tests="tIBMConversion" demos="">
57// </reviewed>
58
59// <synopsis>
60// This class contains static toLocal functions to convert data from IBM-360
61// format to local format and vice-versa. It also handles the conversion
62// of the IBM EBCDIC characters to ASCII characters (for data type char).
63// <p>
64// The functions work well on big-endian as well as little-endian machines.
65// </synopsis>
66
67// <motivation>
68// Archived WSRT data can be stored in the old IBM format
69// (EBCDIC characters and floats with base 16).
70// Conversion functions are needed to read these data.
71// </motivation>
72
73// <todo asof="$DATE$">
74// <li> Support data type long double.
75// </todo>
76
77
79{
80public:
81 // Convert one value from IBM format to local format.
82 // The from and to buffer should not overlap.
83 // <note>
84 // The char version converts from EBCDIC to ASCII, while the
85 // unsigned char version is a simple copy.
86 // </note>
87 // <group>
88 static void toLocal (char& to, const void* from);
89 static void toLocal (unsigned char& to, const void* from);
90 static void toLocal (short& to, const void* from);
91 static void toLocal (unsigned short& to, const void* from);
92 static void toLocal (int& to, const void* from);
93 static void toLocal (unsigned int& to, const void* from);
94 static void toLocal (Int64& to, const void* from);
95 static void toLocal (uInt64& to, const void* from);
96 static void toLocal (float& to, const void* from);
97 static void toLocal (double& to, const void* from);
98 // </group>
99
100 // Convert nr values from IBM format to local format.
101 // The from and to buffer should not overlap.
102 // <note>
103 // The char version converts from EBCDIC to ASCII, while the
104 // unsigned char version is a simple copy.
105 // </note>
106 // <group>
107 static void toLocal (char* to, const void* from,
108 size_t nr);
109 static void toLocal (unsigned char* to, const void* from,
110 size_t nr);
111 static void toLocal (short* to, const void* from,
112 size_t nr);
113 static void toLocal (unsigned short* to, const void* from,
114 size_t nr);
115 static void toLocal (int* to, const void* from,
116 size_t nr);
117 static void toLocal (unsigned int* to, const void* from,
118 size_t nr);
119 static void toLocal (Int64* to, const void* from,
120 size_t nr);
121 static void toLocal (uInt64* to, const void* from,
122 size_t nr);
123 static void toLocal (float* to, const void* from,
124 size_t nr);
125 static void toLocal (double* to, const void* from,
126 size_t nr);
127 // </group>
128
129 // Convert one value from local format to IBM format.
130 // The from and to buffer should not overlap.
131 // <note>
132 // The char version converts from ASCII to EBCDIC, while the
133 // unsigned char version is a simple copy.
134 // </note>
135 // <group>
136 static void fromLocal (void* to, char from);
137 static void fromLocal (void* to, unsigned char from);
138 static void fromLocal (void* to, short from);
139 static void fromLocal (void* to, unsigned short from);
140 static void fromLocal (void* to, int from);
141 static void fromLocal (void* to, unsigned int from);
142 static void fromLocal (void* to, Int64 from);
143 static void fromLocal (void* to, uInt64 from);
144 static void fromLocal (void* to, float from);
145 static void fromLocal (void* to, double from);
146 // </group>
147
148 // Convert nr values from local format to IBM format.
149 // The from and to buffer should not overlap.
150 // <note>
151 // The char version converts from ASCII to EBCDIC, while the
152 // unsigned char version is a simple copy.
153 // </note>
154 // <group>
155 static void fromLocal (void* to, const char* from,
156 size_t nr);
157 static void fromLocal (void* to, const unsigned char* from,
158 size_t nr);
159 static void fromLocal (void* to, const short* from,
160 size_t nr);
161 static void fromLocal (void* to, const unsigned short* from,
162 size_t nr);
163 static void fromLocal (void* to, const int* from,
164 size_t nr);
165 static void fromLocal (void* to, const unsigned int* from,
166 size_t nr);
167 static void fromLocal (void* to, const Int64* from,
168 size_t nr);
169 static void fromLocal (void* to, const uInt64* from,
170 size_t nr);
171 static void fromLocal (void* to, const float* from,
172 size_t nr);
173 static void fromLocal (void* to, const double* from,
174 size_t nr);
175 // </group>
176
177private:
178 // This class should not be constructed
179 // (so declare the constructor private).
181};
182
183
184
185inline void IBMConversion::toLocal (unsigned char& to, const void* from)
186{
188}
189
190inline void IBMConversion::toLocal (short& to, const void* from)
191{
193}
194
195inline void IBMConversion::toLocal (unsigned short& to, const void* from)
196{
198}
199
200inline void IBMConversion::toLocal (int& to, const void* from)
201{
203}
204
205inline void IBMConversion::toLocal (unsigned int& to, const void* from)
206{
208}
209
210inline void IBMConversion::toLocal (Int64& to, const void* from)
211{
212 if (sizeof(Int64) != 4) {
213 if (((signed char*)from)[0] < 0) {
214 to = -1;
215 }else{
216 to = 0;
217 }
218 }
219#if defined(AIPS_LITTLE_ENDIAN)
221#else
222 CanonicalConversion::move4 (((char*)&to)+sizeof(Int64)-4, from);
223#endif
224}
225
226inline void IBMConversion::toLocal (uInt64& to, const void* from)
227{
228 if (sizeof(uInt64) != 4) {
229 to = 0;
230 }
231#if defined(AIPS_LITTLE_ENDIAN)
233#else
234 CanonicalConversion::move4 (((char*)&to)+sizeof(uInt64)-4, from);
235#endif
236}
237
238inline void IBMConversion::toLocal (float& to, const void* from)
239{
240 toLocal (&to, from, 1);
241}
242
243inline void IBMConversion::toLocal (double& to, const void* from)
244{
245 toLocal (&to, from, 1);
246}
247
248inline void IBMConversion::toLocal (unsigned char* to, const void* from,
249 size_t nr)
250{
251 CanonicalConversion::toLocal (to, from, nr);
252}
253
254inline void IBMConversion::toLocal (short* to, const void* from,
255 size_t nr)
256{
257 CanonicalConversion::toLocal (to, from, nr);
258}
259
260inline void IBMConversion::toLocal (unsigned short* to, const void* from,
261 size_t nr)
262{
263 CanonicalConversion::toLocal (to, from, nr);
264}
265
266inline void IBMConversion::toLocal (int* to, const void* from,
267 size_t nr)
268{
269 CanonicalConversion::toLocal (to, from, nr);
270}
271
272inline void IBMConversion::toLocal (unsigned int* to, const void* from,
273 size_t nr)
274{
275 CanonicalConversion::toLocal (to, from, nr);
276}
277
278
279inline void IBMConversion::fromLocal (void* to, unsigned char from)
280{
282}
283
284inline void IBMConversion::fromLocal (void* to, short from)
285{
287}
288
289inline void IBMConversion::fromLocal (void* to, unsigned short from)
290{
292}
293
294inline void IBMConversion::fromLocal (void* to, int from)
295{
297}
298
299inline void IBMConversion::fromLocal (void* to, unsigned int from)
300{
302}
303
304inline void IBMConversion::fromLocal (void* to, Int64 from)
305{
306#if defined(AIPS_LITTLE_ENDIAN)
308#else
309 CanonicalConversion::move4 (to, ((char*)&from)+sizeof(Int64)-4);
310#endif
311}
312
313inline void IBMConversion::fromLocal (void* to, uInt64 from)
314{
315#if defined(AIPS_LITTLE_ENDIAN)
317#else
318 CanonicalConversion::move4 (to,((char*)&from)+sizeof(uInt64)-4);
319#endif
320}
321
322inline void IBMConversion::fromLocal (void* to, float from)
323{
324 fromLocal (to, &from, 1);
325}
326
327inline void IBMConversion::fromLocal (void* to, double from)
328{
329 fromLocal (to, &from, 1);
330}
331
332
333inline void IBMConversion::fromLocal (void* to, const unsigned char* from,
334 size_t nr)
335{
336 CanonicalConversion::fromLocal (to, from, nr);
337}
338
339inline void IBMConversion::fromLocal (void* to, const short* from,
340 size_t nr)
341{
342 CanonicalConversion::fromLocal (to, from, nr);
343}
344
345inline void IBMConversion::fromLocal (void* to, const unsigned short* from,
346 size_t nr)
347{
348 CanonicalConversion::fromLocal (to, from, nr);
349}
350
351inline void IBMConversion::fromLocal (void* to, const int* from,
352 size_t nr)
353{
354 CanonicalConversion::fromLocal (to, from, nr);
355}
356
357inline void IBMConversion::fromLocal (void* to, const unsigned int* from,
358 size_t nr)
359{
360 CanonicalConversion::fromLocal (to, from, nr);
361}
362
363
364
365
366} //# NAMESPACE CASACORE - END
367
368#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)
this file contains all the compiler specific defines
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