"SfR Fresh" - the SfR Freeware/Shareware Archive

Member "eas3pkg/eas3pkg/eas3iomod/conv.c" of archive eas3pkg_v1.6.3.tar.gz:


As a special service "SfR Fresh" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. That can be also achieved for any archive member file by clicking within an archive contents listing on the first character of the file(path) respectively on the according byte size field.
    1 /*-------------------------------------------------------------------------------------------------------*/
    2 /* EAS3 License                                                                                          */
    3 /*                                                                                                       */
    4 /* Copyright (c) 2006 Institut fuer Aerodynamik und Gasdynamik, Universitaet Stuttgart                   */
    5 /*                                                                                                       */
    6 /* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and     */
    7 /* associated documentation files (the "Software"), to deal in the Software without restriction,         */
    8 /* including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, */
    9 /* and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, */
   10 /* subject to the following conditions:                                                                  */
   11 /*                                                                                                       */
   12 /* The above copyright notice and this permission notice shall be included in all copies or substantial  */
   13 /* portions of the Software.                                                                             */
   14 /*                                                                                                       */
   15 /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT */
   16 /* LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.   */
   17 /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER          */
   18 /* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION */
   19 /* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.                                       */
   20 /*-------------------------------------------------------------------------------------------------------*/
   21 /* EAS3 eas3iomod
   22 
   23    conv.c
   24 
   25    Byteweise Konvertierungsroutinen zwischen
   26    BIG ENDIAN (BE) auf NEC SX-4/SX5-5,Cray T3E,SGI, Hitachi SR8K und
   27    LITTLE ENDIAN (LE) auf Intel IA-64/IA-32 basierten Systemen
   28 
   29    Kai Augustin (augustin@iag.uni-stuttgart.de)
   30    Juni 2001                                                           */
   31 
   32 
   33 #if defined(_LITTLEENDIAN)
   34 
   35 #include <stdlib.h>
   36 #include "eas3ioc.h"
   37 #include "conv.h"
   38 
   39 
   40 /* 32-bit Konvertierung */
   41 INTRET conv32(size_t numelem, U_CHAR *in_arr, U_CHAR *out_arr)
   42 {
   43   /* 4 Byte types */
   44   register U_INT32 l4 ;
   45   U_INT32  *inarray4, *outarray4 ;
   46   /* 4 Byte helpers for byteorder */
   47   register U_INT32  b0,b1,b2,b3 ;
   48 
   49   LONGLONGRET i,ilen ;
   50 
   51 #ifdef DEBUG_C_IO
   52   printf("Calling conv32...\n") ;
   53 #endif
   54 
   55   inarray4  = (U_INT32*)in_arr ;
   56   outarray4 = (U_INT32*)out_arr ;
   57 
   58   ilen=(LONGLONGRET)numelem ;
   59   for (i=0;i<ilen;i++)
   60     {
   61       l4 = inarray4[i] ;
   62 #ifdef DEBUG_C_IO
   63       printf("  Vor Conversion: %8.8X\n ",l4) ;
   64 #endif
   65       b0 = (l4 & 0x000000ff) << 24 ;
   66       b1 = (l4 & 0x0000ff00) <<  8 ;
   67       b2 = (l4 & 0x00ff0000) >>  8 ;
   68       b3 = (l4 & 0xff000000) >> 24 ;
   69       l4 = 0 ;
   70       l4 = b0|b1|b2|b3 ;
   71 #ifdef DEBUG_C_IO
   72       printf("  Nach Conversion: %8.8x\n",l4) ;
   73 #endif
   74       outarray4[i] = l4 ;
   75     }
   76   return(0) ;
   77 }
   78 
   79 /* 64-bit Konvertierung */
   80 INTRET conv64(size_t numelem, U_CHAR *in_arr, U_CHAR *out_arr)
   81 {
   82 
   83   /* 8 Byte types */
   84   register U_INT64 l8 ;
   85   U_INT64  *inarray8, *outarray8 ;
   86   /* 4 Byte helpers for byteorder */
   87   register U_INT64 b0,b1,b2,b3,b4,b5,b6,b7 ;
   88 
   89   LONGLONGRET i,ilen ;
   90 
   91 #ifdef DEBUG_C_IO
   92   printf("Calling conv64...\n") ;
   93 #endif
   94 
   95   inarray8 = (U_INT64*)in_arr ;
   96   outarray8 = (U_INT64*)out_arr ;
   97 
   98   ilen=(LONGLONGRET)numelem ;
   99   for (i=0;i<ilen;i++)
  100     {
  101       l8=inarray8[i] ;
  102 #ifdef DEBUG_C_IO
  103       printf("  Vor Conversion: %16.16llX\n ",l8) ;
  104 #endif
  105       b0 = (l8 & 0x00000000000000ff) << 56 ;
  106       b1 = (l8 & 0x000000000000ff00) << 40 ;
  107       b2 = (l8 & 0x0000000000ff0000) << 24 ;
  108       b3 = (l8 & 0x00000000ff000000) <<  8 ;
  109       b4 = (l8 & 0x000000ff00000000) >>  8 ;
  110       b5 = (l8 & 0x0000ff0000000000) >> 24 ;
  111       b6 = (l8 & 0x00ff000000000000) >> 40 ;
  112       b7 = (l8 & 0xff00000000000000) >> 56 ;
  113       l8=0 ;
  114       l8 = b0|b1|b2|b3|b4|b5|b6|b7 ;
  115 #ifdef DEBUG_C_IO
  116       printf("  Nach Conversion: %16.16llX\n ",l8) ;
  117 #endif
  118       outarray8[i] = l8 ;
  119     }
  120   return(0) ;
  121 }
  122 
  123 #endif