25 #include <type_traits>
32 int fwrite_be(
const int* aa,
int size,
int nb, FILE* fich) {
40 bool little_endian = ( *(
reinterpret_cast<char*
>(&itest) ) == 1) ;
44 int size_tot = 4 * nb ;
46 char* bytes_big =
new char[size_tot] ;
47 char* pbig = bytes_big ;
48 const char* plit =
reinterpret_cast<const char*
>(aa) ;
50 for (
int j=0; j< nb; j++) {
52 for (
int i=0; i<4; i++) {
62 int nx =
static_cast<int>(fwrite(bytes_big, 1, size_tot, fich)) / 4 ;
71 return static_cast<int>(fwrite(aa, size, nb, fich)) ;
82 int fwrite_be(
const double* aa,
int size,
int nb, FILE* fich) {
90 bool little_endian = ( *(
reinterpret_cast<char*
>(&itest) ) == 1) ;
94 int size_tot = 8 * nb ;
96 char* bytes_big =
new char[size_tot] ;
97 char* pbig = bytes_big ;
98 const char* plit =
reinterpret_cast<const char*
>(aa) ;
100 for (
int j=0; j< nb; j++) {
102 for (
int i=0; i<8; i++) {
103 pbig[i] = plit[7-i] ;
111 int nx =
static_cast<int>(fwrite(bytes_big, 1, size_tot, fich)) / 8 ;
112 delete [] bytes_big ;
119 return static_cast<int>(fwrite(aa, size, nb, fich)) ;