casa
$Rev:20696$
|
00001 //# VAXConversion.h: A class with static functions to convert VAX format 00002 //# Copyright (C) 1996,1997,1999,2001 00003 //# Associated Universities, Inc. Washington DC, USA. 00004 //# 00005 //# This library is free software; you can redistribute it and/or modify it 00006 //# under the terms of the GNU Library General Public License as published by 00007 //# the Free Software Foundation; either version 2 of the License, or (at your 00008 //# option) any later version. 00009 //# 00010 //# This library is distributed in the hope that it will be useful, but WITHOUT 00011 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00012 //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public 00013 //# License for more details. 00014 //# 00015 //# You should have received a copy of the GNU Library General Public License 00016 //# along with this library; if not, write to the Free Software Foundation, 00017 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA. 00018 //# 00019 //# Correspondence concerning AIPS++ should be addressed as follows: 00020 //# Internet email: aips2-request@nrao.edu. 00021 //# Postal address: AIPS++ Project Office 00022 //# National Radio Astronomy Observatory 00023 //# 520 Edgemont Road 00024 //# Charlottesville, VA 22903-2475 USA 00025 //# 00026 //# $Id: VAXConversion.h 20551 2009-03-25 00:11:33Z Malte.Marquarding $ 00027 00028 #ifndef CASA_VAXCONVERSION_H 00029 #define CASA_VAXCONVERSION_H 00030 00031 //# Includes 00032 #include <casa/aips.h> 00033 #include <assert.h> 00034 #include <casa/OS/LittleEndianConversion.h> 00035 00036 00037 namespace casa { //# NAMESPACE CASA - BEGIN 00038 00039 // Define the canonical sizes of the built-in data types. 00040 // These are the same for all machine architectures. 00041 00042 #define SIZE_VAX_CHAR 1 00043 #define SIZE_VAX_UCHAR 1 00044 #define SIZE_VAX_SHORT 2 00045 #define SIZE_VAX_USHORT 2 00046 #define SIZE_VAX_INT 4 00047 #define SIZE_VAX_UINT 4 00048 #define SIZE_VAX_INT64 4 00049 #define SIZE_VAX_UINT64 4 00050 #define SIZE_VAX_FLOAT 4 00051 #define SIZE_VAX_DOUBLE 8 00052 00053 00054 // <summary> 00055 // A class with static functions to convert VAX format 00056 // </summary> 00057 00058 // <use visibility=export> 00059 00060 // <reviewed reviewer="Friso Olnon" date="1996/11/06" tests="tVAXConversion" demos=""> 00061 // </reviewed> 00062 00063 // <synopsis> 00064 // This class contains static toLocal functions to convert data from VAX 00065 // format to local format and vice-versa. It only handles VAX D-float format. 00066 // Another class should be implemented to handle VAX G-float format. 00067 // <p> 00068 // The functions work well on big-endian as well as little-endian machines. 00069 // </synopsis> 00070 00071 // <motivation> 00072 // Archived WSRT data can be stored in the old VAX format 00073 // (little-endian and VAX D-float floating point format). 00074 // Conversion functions are needed to read these data. 00075 // </motivation> 00076 00077 // <todo asof="$DATE$"> 00078 // <li> Support data type long double. 00079 // </todo> 00080 00081 00082 class VAXConversion 00083 { 00084 public: 00085 // Convert one value from VAX format to local format. 00086 // The from and to buffer should not overlap. 00087 // <group> 00088 static void toLocal (char& to, const void* from); 00089 static void toLocal (unsigned char& to, const void* from); 00090 static void toLocal (short& to, const void* from); 00091 static void toLocal (unsigned short& to, const void* from); 00092 static void toLocal (int& to, const void* from); 00093 static void toLocal (unsigned int& to, const void* from); 00094 static void toLocal (Int64& to, const void* from); 00095 static void toLocal (uInt64& to, const void* from); 00096 static void toLocal (float& to, const void* from); 00097 static void toLocal (double& to, const void* from); 00098 // </group> 00099 00100 // Convert nr values from VAX format to local format. 00101 // The from and to buffer should not overlap. 00102 // <group> 00103 static void toLocal (char* to, const void* from, 00104 unsigned int nr); 00105 static void toLocal (unsigned char* to, const void* from, 00106 unsigned int nr); 00107 static void toLocal (short* to, const void* from, 00108 unsigned int nr); 00109 static void toLocal (unsigned short* to, const void* from, 00110 unsigned int nr); 00111 static void toLocal (int* to, const void* from, 00112 unsigned int nr); 00113 static void toLocal (unsigned int* to, const void* from, 00114 unsigned int nr); 00115 static void toLocal (Int64* to, const void* from, 00116 unsigned int nr); 00117 static void toLocal (uInt64* to, const void* from, 00118 unsigned int nr); 00119 static void toLocal (float* to, const void* from, 00120 unsigned int nr); 00121 static void toLocal (double* to, const void* from, 00122 unsigned int nr); 00123 // </group> 00124 00125 // Convert one value from local format to VAX format. 00126 // The from and to buffer should not overlap. 00127 // <group> 00128 static void fromLocal (void* to, char from); 00129 static void fromLocal (void* to, unsigned char from); 00130 static void fromLocal (void* to, short from); 00131 static void fromLocal (void* to, unsigned short from); 00132 static void fromLocal (void* to, int from); 00133 static void fromLocal (void* to, unsigned int from); 00134 static void fromLocal (void* to, Int64 from); 00135 static void fromLocal (void* to, uInt64 from); 00136 static void fromLocal (void* to, float from); 00137 static void fromLocal (void* to, double from); 00138 // </group> 00139 00140 // Convert nr values from local format to VAX format. 00141 // The from and to buffer should not overlap. 00142 // <group> 00143 static void fromLocal (void* to, const char* from, 00144 unsigned int nr); 00145 static void fromLocal (void* to, const unsigned char* from, 00146 unsigned int nr); 00147 static void fromLocal (void* to, const short* from, 00148 unsigned int nr); 00149 static void fromLocal (void* to, const unsigned short* from, 00150 unsigned int nr); 00151 static void fromLocal (void* to, const int* from, 00152 unsigned int nr); 00153 static void fromLocal (void* to, const unsigned int* from, 00154 unsigned int nr); 00155 static void fromLocal (void* to, const Int64* from, 00156 unsigned int nr); 00157 static void fromLocal (void* to, const uInt64* from, 00158 unsigned int nr); 00159 static void fromLocal (void* to, const float* from, 00160 unsigned int nr); 00161 static void fromLocal (void* to, const double* from, 00162 unsigned int nr); 00163 // </group> 00164 00165 // Move a float value (by swapping bytes correctly). 00166 static void moveFloat (void* to, const void* from); 00167 00168 private: 00169 // This class should not be constructed 00170 // (so declare the constructor private). 00171 VAXConversion(); 00172 }; 00173 00174 00175 00176 inline void VAXConversion::toLocal (char& to, const void* from) 00177 { 00178 LittleEndianConversion::toLocal (to, from); 00179 } 00180 00181 inline void VAXConversion::toLocal (unsigned char& to, const void* from) 00182 { 00183 LittleEndianConversion::toLocal (to, from); 00184 } 00185 00186 inline void VAXConversion::toLocal (short& to, const void* from) 00187 { 00188 LittleEndianConversion::toLocal (to, from); 00189 } 00190 00191 inline void VAXConversion::toLocal (unsigned short& to, const void* from) 00192 { 00193 LittleEndianConversion::toLocal (to, from); 00194 } 00195 00196 inline void VAXConversion::toLocal (int& to, const void* from) 00197 { 00198 LittleEndianConversion::toLocal (to, from); 00199 } 00200 00201 inline void VAXConversion::toLocal (unsigned int& to, const void* from) 00202 { 00203 LittleEndianConversion::toLocal (to, from); 00204 } 00205 00206 inline void VAXConversion::toLocal (Int64& to, const void* from) 00207 { 00208 LittleEndianConversion::toLocal (to, from); 00209 } 00210 00211 inline void VAXConversion::toLocal (uInt64& to, const void* from) 00212 { 00213 LittleEndianConversion::toLocal (to, from); 00214 } 00215 00216 inline void VAXConversion::toLocal (float& to, const void* from) 00217 { 00218 toLocal (&to, from, 1); 00219 } 00220 00221 inline void VAXConversion::toLocal (double& to, const void* from) 00222 { 00223 toLocal (&to, from, 1); 00224 } 00225 00226 inline void VAXConversion::toLocal (char* to, const void* from, 00227 unsigned int nr) 00228 { 00229 LittleEndianConversion::toLocal (to, from, nr); 00230 } 00231 00232 inline void VAXConversion::toLocal (unsigned char* to, const void* from, 00233 unsigned int nr) 00234 { 00235 LittleEndianConversion::toLocal (to, from, nr); 00236 } 00237 00238 inline void VAXConversion::toLocal (short* to, const void* from, 00239 unsigned int nr) 00240 { 00241 LittleEndianConversion::toLocal (to, from, nr); 00242 } 00243 00244 inline void VAXConversion::toLocal (unsigned short* to, const void* from, 00245 unsigned int nr) 00246 { 00247 LittleEndianConversion::toLocal (to, from, nr); 00248 } 00249 00250 inline void VAXConversion::toLocal (int* to, const void* from, 00251 unsigned int nr) 00252 { 00253 LittleEndianConversion::toLocal (to, from, nr); 00254 } 00255 00256 inline void VAXConversion::toLocal (unsigned int* to, const void* from, 00257 unsigned int nr) 00258 { 00259 LittleEndianConversion::toLocal (to, from, nr); 00260 } 00261 00262 inline void VAXConversion::toLocal (Int64* to, const void* from, 00263 unsigned int nr) 00264 { 00265 LittleEndianConversion::toLocal (to, from, nr); 00266 } 00267 00268 inline void VAXConversion::toLocal (uInt64* to, const void* from, 00269 unsigned int nr) 00270 { 00271 LittleEndianConversion::toLocal (to, from, nr); 00272 } 00273 00274 00275 inline void VAXConversion::fromLocal (void* to, char from) 00276 { 00277 LittleEndianConversion::fromLocal (to, from); 00278 } 00279 00280 inline void VAXConversion::fromLocal (void* to, unsigned char from) 00281 { 00282 LittleEndianConversion::fromLocal (to, from); 00283 } 00284 00285 inline void VAXConversion::fromLocal (void* to, short from) 00286 { 00287 LittleEndianConversion::fromLocal (to, from); 00288 } 00289 00290 inline void VAXConversion::fromLocal (void* to, unsigned short from) 00291 { 00292 LittleEndianConversion::fromLocal (to, from); 00293 } 00294 00295 inline void VAXConversion::fromLocal (void* to, int from) 00296 { 00297 LittleEndianConversion::fromLocal (to, from); 00298 } 00299 00300 inline void VAXConversion::fromLocal (void* to, unsigned int from) 00301 { 00302 LittleEndianConversion::fromLocal (to, from); 00303 } 00304 00305 inline void VAXConversion::fromLocal (void* to, Int64 from) 00306 { 00307 LittleEndianConversion::fromLocal (to, from); 00308 } 00309 00310 inline void VAXConversion::fromLocal (void* to, uInt64 from) 00311 { 00312 LittleEndianConversion::fromLocal (to, from); 00313 } 00314 00315 inline void VAXConversion::fromLocal (void* to, float from) 00316 { 00317 fromLocal (to, &from, 1); 00318 } 00319 00320 inline void VAXConversion::fromLocal (void* to, double from) 00321 { 00322 fromLocal (to, &from, 1); 00323 } 00324 00325 inline void VAXConversion::fromLocal (void* to, const char* from, 00326 unsigned int nr) 00327 { 00328 LittleEndianConversion::fromLocal (to, from, nr); 00329 } 00330 00331 inline void VAXConversion::fromLocal (void* to, const unsigned char* from, 00332 unsigned int nr) 00333 { 00334 LittleEndianConversion::fromLocal (to, from, nr); 00335 } 00336 00337 inline void VAXConversion::fromLocal (void* to, const short* from, 00338 unsigned int nr) 00339 { 00340 LittleEndianConversion::fromLocal (to, from, nr); 00341 } 00342 00343 inline void VAXConversion::fromLocal (void* to, const unsigned short* from, 00344 unsigned int nr) 00345 { 00346 LittleEndianConversion::fromLocal (to, from, nr); 00347 } 00348 00349 inline void VAXConversion::fromLocal (void* to, const int* from, 00350 unsigned int nr) 00351 { 00352 LittleEndianConversion::fromLocal (to, from, nr); 00353 } 00354 00355 inline void VAXConversion::fromLocal (void* to, const unsigned int* from, 00356 unsigned int nr) 00357 { 00358 LittleEndianConversion::fromLocal (to, from, nr); 00359 } 00360 00361 inline void VAXConversion::fromLocal (void* to, const Int64* from, 00362 unsigned int nr) 00363 { 00364 LittleEndianConversion::fromLocal (to, from, nr); 00365 } 00366 00367 inline void VAXConversion::fromLocal (void* to, const uInt64* from, 00368 unsigned int nr) 00369 { 00370 LittleEndianConversion::fromLocal (to, from, nr); 00371 } 00372 00373 00374 00375 inline void VAXConversion::moveFloat (void* to, const void* from) 00376 { 00377 #if defined(AIPS_LITTLE_ENDIAN) 00378 ((char*)to)[0] = ((const char*)from)[2]; 00379 ((char*)to)[1] = ((const char*)from)[3]; 00380 ((char*)to)[2] = ((const char*)from)[0]; 00381 ((char*)to)[3] = ((const char*)from)[1]; 00382 #else 00383 ((char*)to)[0] = ((const char*)from)[1]; 00384 ((char*)to)[1] = ((const char*)from)[0]; 00385 ((char*)to)[2] = ((const char*)from)[3]; 00386 ((char*)to)[3] = ((const char*)from)[2]; 00387 #endif 00388 } 00389 00390 00391 00392 } //# NAMESPACE CASA - END 00393 00394 #endif