我正在开发基于开源库的gps处理软件。该库为我提供了一个RINEX文件阅读器,它可以打开包含gps导航消息或观察数据和许多数据处理功能的现有文件。上面引用的gps数据文件的内容用于填充算法执行数据处理所使用的结构成员。
我的问题是RINEX阅读器功能正确读取包含观察数据的文件(文件类型:yyO,其中yy是观察年份的两个最右边的数字)但它无法打开我给出的任何导航消息文件输入(文件类型:yyN)。
在调试会话之后,我意识到读者的函数为这种类型的文件返回 NULL 文件指针。奇怪的是,这些文件存在于程序的工作目录中,并且没有损坏。
我进一步向下提供了相对的代码块:
我的主要来电代码:
int main(){
int stat; //Identifier of RINEX file status.
//Memory allocation for a "stat_t" variable (initialization of its members will be done when the program flow passes into the "rinex.c" file functions):
sta_t *st = (sta_t *) malloc(sizeof(sta_t));
//Get current working directory (for debugging):
char directory[_MAX_PATH];
_getcwd(directory, sizeof(directory));
printf("Current working directory: %s \n", directory);
//Initialize options structure members:
init_opt_members();
//Initialize processing options structure members:
init_prcopt_members();
//Initialization of observation data structure members (NULL: obs data not available):
init_obs_members();
//Initialization of navigation data structure members (NULL: nav data not available):
init_nav_members();
//Initialization of solution parameters data structure members (NULL: ...):
init_sol_members();
//Read configuration file and update the values of processing options struct:
loadopts("prcopt.txt", opt);
getsysopts(op, NULL, NULL);
//Read RINEX nav file:
stat = readrnx("IOAN.12N", 1, NULL, na, st); //ob = NULL
printf("Reader status = %d \n", stat);
//Read RINEX obs file:
stat = readrnx("IOAN.12O", 1, ob, NULL, st); //na = NULL, st members values will be updated by obs file header data.
printf("Reader status = %d \n", stat);
//Call the single-point positioning function:
stat = pntpos(ob->data, ob->n, na, op, so, NULL, NULL, "Error!");
printf("Single point pos status = %d \n", stat);
system("PAUSE");
return 0;
}
其中readrnx()函数(由库提供)是:
extern int readrnx(const char *file, int rcv, obs_t *obs, nav_t *nav, sta_t *sta)
{
gtime_t t={0};
trace(3,"readrnx : file=%s rcv=%d\n",file,rcv);
return readrnxt(file,rcv,t,t,0.0,obs,nav,sta);
}
readrnxt()在某些时候调用文件解压缩和打开函数readrnxfile()。这是(从标准库的实现中略微修改):
static int readrnxfile(const char *file, gtime_t ts, gtime_t te, double tint,
int flag, int index, char *type, obs_t *obs, nav_t *nav,
sta_t *sta)
{
FILE *fp = NULL;
int cstat,stat;
char tmpfile[1024];
trace(3,"readrnxfile: file=%s flag=%d index=%d\n",file,flag,index);
if (sta) init_sta(sta);
/* uncompress file */
/*if ((cstat=uncompress(file,tmpfile))<0) {
trace(2,"rinex file uncompact error: %s\n",file);
return 0;
}*/
/*if (!(fp=fopen(cstat?tmpfile:file,"r"))) {
trace(2,"rinex file open error: %s\n",cstat?tmpfile:file);
return 0;
}*/
//It can't open nav files!
if (!(fp=fopen(file,"r"))) {
trace(2,"rinex file open error: %s\n",file);
printf("opening file failed: %s\n", strerror(errno)); //For debugging.
return 0;
}
/* read rinex file */
stat=readrnxfp(fp,ts,te,tint,flag,index,type,obs,nav,sta);
fclose(fp);
/* delete temporary file */
//if (cstat) remove(tmpfile);
return stat;
}
通过打印 errno ,我发现上面引用的文件打开错误,仅当上述函数尝试打开导航消息文件时才会出现。
编辑:忘了说我已经检查了文件权限(我使用的是Windows 7),而且我使用的是Microsoft Visual Studio 2008专业版。
答案 0 :(得分:0)
您可以尝试打印完整的文件名,并检查它是否可用。 此外,您可能需要检查是否可以打开该文件。它被其他东西打开了吗?