HARM
harm and utilities
 All Data Structures Files Functions Variables Typedefs Macros Pages
initbase.tools.c
Go to the documentation of this file.
1 
6 #include <stdio.h>
7 #include <stdlib.h>
8 
9 
11 void report_systeminfo(FILE * fileout)
12 {
13  int IsLittleEndian(void);
15  //
16  // check endianness of system and MPI compatibility
17 
18  if(IsLittleEndian()){
19  fprintf(fileout,"System is Little Endian\n");
20  }
21  else fprintf(fileout,"System is Big Endian\n");
22 
23  // inform of data sizes
24  fprintf(fileout,"Size of char: %lld\n",(long long int)sizeof(char));
25  fprintf(fileout,"Size of short: %lld\n",(long long int)sizeof(short));
26  fprintf(fileout,"Size of int: %lld\n",(long long int)sizeof(int));
27  fprintf(fileout,"Size of size_t: %lld\n",(long long int)sizeof(size_t));
28  fprintf(fileout,"Size of long int: %lld\n",(long long int)sizeof(long int));
29  fprintf(fileout,"Size of long long int: %lld\n",(long long int)sizeof(long long int));
30  fprintf(fileout,"Size of float: %lld\n",(long long int)sizeof(float));
31  fprintf(fileout,"Size of double: %lld\n",(long long int)sizeof(double));
32  fprintf(fileout,"Size of long double: %lld\n",(long long int)sizeof(long double));
33 
34  if((long long int)sizeof(int)<=4){
35  fprintf(fileout,"WARNING: Since size of integer is only 4 bytes, some routines that input and output integer arguments will be limited to 2GB. For example, ROMIO will fail to work if try to write >2GB file, since buffer sizes must then be <2GB\n");
36  }
37 
38 
40  //
41  // Some checks
42  //
44 
45  if(sizeof(char)!=1){
46  fprintf(fileout,"sizeof(char) was not 1 byte, void pointer use not going to be correct\n");
47  exit(1);
48  }
49 
50 }
51 
52 
53 // OPENMPMARK: constant static, so ok
54 static long _TestEndian=1;
55 
56 int IsLittleEndian(void)
57 {
58  return *(char*)&_TestEndian;
59 }
60 
65 void *SwapEndian(void* Addr, const int Nb)
66 {
67  static char Swapped[16];
68  switch (Nb) {
69  case 2: Swapped[0]=*((char*)Addr+1);
70  Swapped[1]=*((char*)Addr );
71  break;
72  case 3: // As far as I know, 3 is used only with RGB images
73  Swapped[0]=*((char*)Addr+2);
74  Swapped[1]=*((char*)Addr+1);
75  Swapped[2]=*((char*)Addr );
76  break;
77  case 4: Swapped[0]=*((char*)Addr+3);
78  Swapped[1]=*((char*)Addr+2);
79  Swapped[2]=*((char*)Addr+1);
80  Swapped[3]=*((char*)Addr );
81  break;
82  case 8: Swapped[0]=*((char*)Addr+7);
83  Swapped[1]=*((char*)Addr+6);
84  Swapped[2]=*((char*)Addr+5);
85  Swapped[3]=*((char*)Addr+4);
86  Swapped[4]=*((char*)Addr+3);
87  Swapped[5]=*((char*)Addr+2);
88  Swapped[6]=*((char*)Addr+1);
89  Swapped[7]=*((char*)Addr );
90  break;
91  case 16:Swapped[0]=*((char*)Addr+15);
92  Swapped[1]=*((char*)Addr+14);
93  Swapped[2]=*((char*)Addr+13);
94  Swapped[3]=*((char*)Addr+12);
95  Swapped[4]=*((char*)Addr+11);
96  Swapped[5]=*((char*)Addr+10);
97  Swapped[6]=*((char*)Addr+9);
98  Swapped[7]=*((char*)Addr+8);
99  Swapped[8]=*((char*)Addr+7);
100  Swapped[9]=*((char*)Addr+6);
101  Swapped[10]=*((char*)Addr+5);
102  Swapped[11]=*((char*)Addr+4);
103  Swapped[12]=*((char*)Addr+3);
104  Swapped[13]=*((char*)Addr+2);
105  Swapped[14]=*((char*)Addr+1);
106  Swapped[15]=*((char*)Addr );
107  break;
108  }
109  return (void*)Swapped;
110 }
111