delic
November 2nd, 2002, 02:26 PM
I thought the following would read in blocks of 15 floats from a binary file but after a bunch of correct reads all the output numbers are giberish, numbers like 1E-20 type stuff..
I have to use stdio routines like fread, I have written the same code with fstreams and it works fine. I am missing some stdio quirk or something.. It seems to get hosed when the _cnt variable in the FILE structure becomes < then the size of 15 floats (60).. I believe it has to do with the buffering of the file, which is the system 4096 size.
I have done more debugging.. _cnt gets to a value of 1 then the next fread reads data that is 1516 bytes downstream instead of 60 (note that this is not even a multiple of 60, my block size).. for no reason, I have no seeks or anything in the code..
float CPDATA[15];
do{
fread((char*)CPDATA,sizeof(float)*15, 1, thO->fd);
//outfile read info to a file
outfile<<ftell(thO->fd)<<" ";
for(int i=0;i<15;i++)
outfile<<CPDATA[i]<<" ";
outfile<<endl;
k++;
}while(k<j);
I have to use stdio routines like fread, I have written the same code with fstreams and it works fine. I am missing some stdio quirk or something.. It seems to get hosed when the _cnt variable in the FILE structure becomes < then the size of 15 floats (60).. I believe it has to do with the buffering of the file, which is the system 4096 size.
I have done more debugging.. _cnt gets to a value of 1 then the next fread reads data that is 1516 bytes downstream instead of 60 (note that this is not even a multiple of 60, my block size).. for no reason, I have no seeks or anything in the code..
float CPDATA[15];
do{
fread((char*)CPDATA,sizeof(float)*15, 1, thO->fd);
//outfile read info to a file
outfile<<ftell(thO->fd)<<" ";
for(int i=0;i<15;i++)
outfile<<CPDATA[i]<<" ";
outfile<<endl;
k++;
}while(k<j);