Note that there are some explanatory texts on larger screens.

plurals
  1. POCan't open an existing file placed into working directory using c's fopen()
    primarykey
    data
    text
    <p>I'm working on a gps processing software, based upon an open-source library. This library provides me a RINEX file reader, which opens existing files that contains the gps navigation messages or observation data and many data processing functions. Contents of the above referenced gps data files are used to populate structure members which are used by algorithms perfoming data processing.</p> <p>My problem is that the RINEX reader function reads correctly files which contain observation data (file type: yyO, where yy are the two rightest digits of the observation year) but it can't open any navigation message file that i gave as input (file type: yyN). </p> <p>After a debugging session, i realized that the reader's function returns a <strong>NULL</strong> file pointer for this type of files. The odd thing is that those files exist into the program's working directory and aren't corrupted.</p> <p>I provide the relative <strong>code</strong> blocks further down:</p> <p>My main caller code:</p> <pre><code>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-&gt;data, ob-&gt;n, na, op, so, NULL, NULL, "Error!"); printf("Single point pos status = %d \n", stat); system("PAUSE"); return 0; } </code></pre> <p>where the readrnx() function (provided by the library) is:</p> <pre><code>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); } </code></pre> <p>readrnxt() calls at some point the file uncompressing and opening function readrnxfile(). which is (silghtly modified from the standard library's implementation there):</p> <pre><code>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))&lt;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; } </code></pre> <p>By printing the <strong>errno</strong>, i found the above referenced file opening error, which occurs only when the above function tries to open a navigation message file.</p> <p><strong>Edit</strong>: Forgot to say that i've checked the file permissions (i'm using Windows 7) and i use Microsoft Visual Studio 2008 professional.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload