I'm writing a program that is creating a lookup table from two tables that are in two separate files. When I read the first table, everything is read correctly. However, when I am reading the second file, fopen
doesn't seem to open the whole file.
I say this because the compiler implements the _iobuf
file structure and _cnt
seems to be initialized a whole lot lower (_cnt = 530
) than when initialized the first time(_cnt ~ 4096
) and as I read from the file it decreases.
Here is a snippet of my code:
int vertical,horizontal,channels,count;
FILE *fp;
fp = fopen(filename,"r");
if(fp==NULL){
cout << "File not found" << endl;
return Mat();
}else{
cout << "Opening and Reading " << filename << endl;
}
//Read header
fread(&count,4,1,fp);
cout << "ReadHistogram(): Count number is " << count;
if(count!= 5){
cout << "Header file reads: " << count << endl;
return Mat();
}
//Read size
fread(&vertical,4,1,fp);
//cout << "ReadHistogram(): Vertical size:" << vertical <<endl;
fread(&horizontal,4,1,fp);
//cout << "ReadHistogram(): Horizontal size:" << horizontal <<endl;
fread(&channels,4,1,fp);
//cout << "ReadHistogram(): Channel size:" << channels<<endl;
//Create Mat array
int size[] = {vertical, horizontal, channels};
Mat histogram(3,size,CV_64F,Scalar::all(0));
//Read in array
count = 0;
for(int i=0;i<vertical;i++){
for(int j=0;j<horizontal;j++){
for(int k=0;k<channels;k++){
double temp5;
fread(&temp5,8,1,fp);
histogram.at<double>(i,j,k) = temp5;
if(count <= 300){
cout << "Array(" << i+1 << "," << j+1 << "," << k+1 << ")" << "=" << histogram.at<double>(i,j,k) << endl;
cout << "Temp5 is " << temp5 << endl;
}
count++;
}
}
}
cout << "Done reading " << filename << endl;
fclose(fp);
return histogram;
PS: I have been trying to look up what exactly is _cnt
in the FILE
structure and I can't find anything of the sort. I would appreciate any pointers anyone can give.