27 char fwrite_be_C[] =
"$Header: /cvsroot/Lorene/C++/Source/Non_class_members/Utilities/fwrite_be.C,v 1.6 2014/10/13 08:53:32 j_novak Exp $" ;
70 int fwrite_be(
const int* aa,
int size,
int nb, FILE* fich) {
78 bool little_endian = ( *(
reinterpret_cast<char*
>(&itest) ) == 1) ;
82 int size_tot = 4 * nb ;
84 char* bytes_big =
new char[size_tot] ;
85 char* pbig = bytes_big ;
86 const char* plit =
reinterpret_cast<const char*
>(aa) ;
88 for (
int j=0; j< nb; j++) {
90 for (
int i=0; i<4; i++) {
100 int nx = int(fwrite(bytes_big, 1, size_tot, fich) / 4) ;
102 delete [] bytes_big ;
109 return int(fwrite(aa, size, nb, fich)) ;
120 int fwrite_be(
const double* aa,
int size,
int nb, FILE* fich) {
128 bool little_endian = ( *(
reinterpret_cast<char*
>(&itest) ) == 1) ;
132 int size_tot = 8 * nb ;
134 char* bytes_big =
new char[size_tot] ;
135 char* pbig = bytes_big ;
136 const char* plit =
reinterpret_cast<const char*
>(aa) ;
138 for (
int j=0; j< nb; j++) {
140 for (
int i=0; i<8; i++) {
141 pbig[i] = plit[7-i] ;
149 int nx = int(fwrite(bytes_big, 1, size_tot, fich) / 8) ;
150 delete [] bytes_big ;
157 return int(fwrite(aa, size, nb, fich)) ;
int fwrite_be(const int *aa, int size, int nb, FILE *fich)
Writes integer(s) into a binary file according to the big endian convention.