DATRW++ library: seismic data I/O with multiple formats

◆ cpu()

Ecpu_type datrw::util::cpu ( )

check for my CPU model

Check CPU model. ,.

Returns
return value indicates the CPU model found

Definition at line 73 of file bytesex.cc.

References datrw::util::IOUnion< T >::bytes, cpu_Intel, cpu_Motorola, cpu_unknown, DATRW_assert, magic(), and datrw::util::IOUnion< T >::value.

Referenced by main(), datrw::mseed::needswap(), and datrw::mseed::MiniSEEDRecord::readheader().

74  {
75  Ecpu_type result=cpu_unknown;
76  IOUnion<int> u1,u2;
77  DATRW_assert((sizeof(int) == 4),
78  "The integer memory size on this CPU differs from the"
79  "required value of 4");
80  const int& intsize=sizeof(int);
81  char test_seq[]="ABCD";
82  // prepare sequence and reverse sequence
83  for (int i=0; i<intsize; i++)
84  {
85  u1.bytes[i]=test_seq[i];
86  u2.bytes[i]=test_seq[intsize-i-1];
87  }
88  // request magic number for sequence
89  int magnum=magic(u1.bytes);
90  // test against byte representation of sequence and reverse sequence
91  if (magnum == u1.value)
92  {
93  result=cpu_Motorola;
94  }
95  else if (magnum == u2.value)
96  {
97  result=cpu_Intel;
98  }
99  return(result);
100  } // cpu()
#define DATRW_assert(C, M)
Check an assertion and report by throwing an exception.
Definition: error.h:92
Ecpu_type
Define different CPU type that are recognized.
Definition: bytesex.h:88
unknown CPU
Definition: bytesex.h:94
Motorola CPU.
Definition: bytesex.h:92
int magic(const char *const cmagic)
function to create the magic number
Definition: bytesex.cc:52
Intel CPU.
Definition: bytesex.h:90
Here is the call graph for this function:
Here is the caller graph for this function: