B
bwv539
I have to read a bynary file with some signed int (32 bit) data and re-
write the same data into another file in floating point format, 32
bit.
The loop where I do this is this:
int inINT[1024];
float inFLOAT[1024];
int idx;
while(...some control...) {
fread (&inINT[0], sizeof(int), 1024, fin);
if(feof(fin)) {
break;
}
for( idx = 0; idx < 1024; idx++) {
inFLOAT[idx] = (float) inINT[idx];
}
fwrite (inFLOAT, sizeof(float), 1024, fout);
}
I read data in blocks of 1024. I am wondering if there is any way of
getting rid of the for loop, for this application I need speed (I have
many TB to convert).
For example, I tried declaring a pointer to union:
union FI_IN {
int intval;
float fval;
};
union FI_IN* fi_in;
But, the following
fread (&inINT[0], sizeof(int), 1024, fin);
fi_in = (union FI_IN*)inINT;
does not work: if I access union members, ints are correct but float
are garbage.
Any hint?
Thank you.
write the same data into another file in floating point format, 32
bit.
The loop where I do this is this:
int inINT[1024];
float inFLOAT[1024];
int idx;
while(...some control...) {
fread (&inINT[0], sizeof(int), 1024, fin);
if(feof(fin)) {
break;
}
for( idx = 0; idx < 1024; idx++) {
inFLOAT[idx] = (float) inINT[idx];
}
fwrite (inFLOAT, sizeof(float), 1024, fout);
}
I read data in blocks of 1024. I am wondering if there is any way of
getting rid of the for loop, for this application I need speed (I have
many TB to convert).
For example, I tried declaring a pointer to union:
union FI_IN {
int intval;
float fval;
};
union FI_IN* fi_in;
But, the following
fread (&inINT[0], sizeof(int), 1024, fin);
fi_in = (union FI_IN*)inINT;
does not work: if I access union members, ints are correct but float
are garbage.
Any hint?
Thank you.