到目前为止,这是我的代码:
#include <stdio.h>
#include <stdint.h>
#define N_DET 432
#define N_PROJ 500
int readSinogram(uint16_t mess[],char filename[], int sample){
//init
FILE *fp;
int i;
//open file
fp=fopen(filename,"r");
//read sinogram
fseek(fp,sizeof(uint16_t)*N_DET*N_PROJ*sample*2,SEEK_SET); //move pointer
fread(mess,sizeof(uint16_t),N_DET*N_PROJ,fp); //read sinogram
return 0;
};
int main()
{
uint16_t mess[N_DET*N_PROJ];
char filename[]="C:\\Path\\MyFile.fxc";
double curr;
int i,DET,PROJ;
readSinogram(mess,filename,0); //read the data
printf("\nDET?"); //ask for input
scanf("%u", &DET);
printf("\nPROJ?");
scanf("%u", &PROJ);
curr=mess[DET+N_DET*PROJ]; //get the data
printf("Data: %f",curr); //print the data
return 0;
}
这会读入 .fxc 文件,该文件只是一个包含 uint16_t 格式数字的二进制文件。"readSinogram" 读取一个包含 N_DET*N_PROJ 个数的数据集。(指针移动了两倍的块大小,因为文件中有两个测量值的交替块。)读完后,可以放入 DET 和 PROJ 并查看此时的数据。
到目前为止,一切正常。数据对于某个数据范围是正确的,但是当要求太大的 DET 和/或 PROJ 时,数据是不正确的。我确实在 Matlab 中读入了相同的文件,并且可以确认其中的数据没有问题。
更准确地说:[DET+N_DET*PROJ] > 248835 以上的每个索引都将返回 52428 而不是正确的值(范围从 0 到 4088)。达到这些值的值可以正常工作。所以我猜该索引上方的“混乱”数组一定有问题。
我究竟做错了什么?提前致谢!