Beispiel #1
0
/* scan observation types ----------------------------------------------------*/
static int scan_obstype(int format, const char *file, rnxopt_t *opt,
                        gtime_t *time)
{
    strfile_t *str;
    unsigned char codes[6][33]={{0}};
    unsigned char types[6][33]={{0}};
    char msg[128];
    int i,j,k,l,c=0,type,sys,abort=0,n[6]={0};
    
    trace(3,"scan_obstype: file=%s, opt=%s\n",file,opt);
    
    if (!(str=gen_strfile(format,opt->rcvopt,*time))) return 0;
    
    if (!open_strfile(str,file)) {
        free_strfile(str);
        return 0;
    }
    /* scan codes in input file */
    while ((type=input_strfile(str))>=-1) {
        
        if (type!=1||str->obs->n<=0) continue;
        
        if (!opt->ts.time||timediff(str->obs->data[0].time,opt->ts)>=0.001) {
             
            for (i=0;i<str->obs->n;i++) {
                sys=satsys(str->obs->data[i].sat,NULL);
                for (l=0;navsys[l];l++) if (navsys[l]==sys) break;
                if (!navsys[l]) continue;
                
                for (j=0;j<NFREQ+NEXOBS;j++) {
                    if (!str->obs->data[i].code[j]) continue;
                    
                    for (k=0;k<n[l];k++) {
                        if (codes[l][k]==str->obs->data[i].code[j]) break;
                    }
                    if (k>=n[l]&&n[l]<32) {
                        codes[l][n[l]++]=str->obs->data[i].code[j];
                    }
                    if (k<n[l]) {
                        if (str->obs->data[i].P[j]!=0.0) types[l][k]|=1;
                        if (str->obs->data[i].L[j]!=0.0) types[l][k]|=2;
                        if (str->obs->data[i].D[j]!=0.0) types[l][k]|=4;
                        if (str->obs->data[i].SNR[j]!=0) types[l][k]|=8;
                    }
                }
            }
            if (!time->time) *time=str->obs->data[0].time;
        }
        if (opt->te.time&&timediff(str->obs->data[0].time,opt->te)>10.0) break;
        
        if (++c%11) continue;
        
        sprintf(msg,"scanning: %s %s%s%s%s%s%s",time_str(str->time,0),
                n[0]?"G":"",n[1]?"R":"",n[2]?"E":"",n[3]?"J":"",
                n[4]?"S":"",n[5]?"C":"");
        if ((abort=showmsg(msg))) break;
    }
    showmsg("");
    
    close_strfile(str);
    free_strfile(str);
    
    if (abort) {
        trace(2,"aborted in scan\n");
        return 0;
    }
    for (i=0;i<6;i++) for (j=0;j<n[i];j++) {
        trace(2,"scan_obstype: sys=%d code=%s type=%d\n",i,code2obs(codes[i][j],NULL),types[i][j]);
    }
    for (i=0;i<6;i++) {
        
        /* sort codes */
        sort_codes(codes[i],types[i],n[i]);
        
        /* set observation types in rinex option */
        setopt_obstype(codes[i],types[i],i,opt);
        
        for (j=0;j<n[i];j++) {
            trace(3,"scan_obstype: sys=%d code=%s\n",i,code2obs(codes[i][j],NULL));
        }
    }
    return 1;
}
Beispiel #2
0
/* set approx position -------------------------------------------------------*/
static void setapppos(strfile_t *str, rnxopt_t *opt)
{
    prcopt_t prcopt=prcopt_default;
    sol_t sol={{0}};
    char msg[128];
    
    prcopt.navsys=opt->navsys;
    
    /* point positioning with last obs data */
#ifdef WAAS_STUDY
    if (!pntpos(str->obs->data,str->obs->n,str->nav,&prcopt,&sol,NULL,NULL,
                NULL,msg)) {
#else
	if (!pntpos(str->obs->data,str->obs->n,str->nav,&prcopt,&sol,NULL,NULL,
			msg)) {
#endif
        trace(2,"point position error (%s)\n",msg);
        return;
    }
    matcpy(opt->apppos,sol.rr,3,1);
}
/* show status message -------------------------------------------------------*/
static int showstat(int sess, gtime_t ts, gtime_t te, int *n)
{
    const char type[]="ONGHQLSE";
    char msg[1024]="",*p=msg,s[64];
    int i;
    
    if (sess>0) {
        p+=sprintf(p,"(%d) ",sess);
    }
    if (ts.time!=0) {
        time2str(ts,s,0);
        p+=sprintf(p,"%s",s);
    }
    if (te.time!=0&&timediff(te,ts)>0.9) {
        time2str(te,s,0);
        p+=sprintf(p,"-%s",s+5);
    }
    p+=sprintf(p,": ");
    
    for (i=0;i<NOUTFILE+1;i++) {
        if (n[i]==0) continue;
        p+=sprintf(p,"%c=%d%s",type[i],n[i],i<NOUTFILE?" ":"");
    }
    return showmsg(msg);
}
/* rinex converter for single-session ----------------------------------------*/
static int convrnx_s(int sess, int format, rnxopt_t *opt, const char *file,
                     char **ofile)
{
    FILE *ofp[NOUTFILE]={NULL};
    strfile_t *str;
    gtime_t ts={0},te={0},tend={0},time={0};
    unsigned char slips[MAXSAT][NFREQ+NEXOBS]={{0}};
    int i,j,nf,type,n[NOUTFILE+1]={0},abort=0;
    char path[1024],*paths[NOUTFILE],s[NOUTFILE][1024];
    char *epath[MAXEXFILE]={0},*staid=*opt->staid?opt->staid:"0000";
    
    trace(3,"convrnx_s: sess=%d format=%d file=%s ofile=%s %s %s %s %s %s %s\n",
          sess,format,file,ofile[0],ofile[1],ofile[2],ofile[3],ofile[4],
          ofile[5],ofile[6]);
    
    /* replace keywords in input file */
    if (reppath(file,path,opt->ts,staid,"")<0) {
        showmsg("no time for input file: %s",file);
        return 0;
    }
    /* expand wild-cards in input file */
    for (i=0;i<MAXEXFILE;i++) {
        if (!(epath[i]=(char *)malloc(1024))) {
            for (i=0;i<MAXEXFILE;i++) free(epath[i]);
            return 0;
        }
    }
    nf=expath(path,epath,MAXEXFILE);
    
    if (format==STRFMT_RTCM2||format==STRFMT_RTCM3) time=opt->trtcm;
    
    if (opt->scanobs) {
        
        /* scan observation types */
        if (!scan_obstype(format,epath[0],opt,&time)) return 0;
    }
    else {
        /* set observation types by format */
        set_obstype(format,opt);
    }
    if (!(str=gen_strfile(format,opt->rcvopt,time))) {
        for (i=0;i<MAXEXFILE;i++) free(epath[i]);
        return 0;
    }
    time=opt->ts.time?opt->ts:(time.time?timeadd(time,TSTARTMARGIN):time);
    
    /* replace keywords in output file */
    for (i=0;i<NOUTFILE;i++) {
        paths[i]=s[i];
        if (reppath(ofile[i],paths[i],time,staid,"")<0) {
            showmsg("no time for output path: %s",ofile[i]);
            for (i=0;i<MAXEXFILE;i++) free(epath[i]);
            free_strfile(str);
            return 0;
        }
    }
    /* open output files */
    if (!openfile(ofp,paths,path,opt,str->nav)) {
        for (i=0;i<MAXEXFILE;i++) free(epath[i]);
        free_strfile(str);
        return 0;
    }
    for (i=0;i<nf&&!abort;i++) {
        
        /* open stream file */
        if (!open_strfile(str,epath[i])) continue;
        
        /* input message */
        for (j=0;(type=input_strfile(str))>=-1;j++) {
            
            if (j%11==1&&(abort=showstat(sess,te,te,n))) break;
            
            /* avioid duplicated if overlapped data */
            if (tend.time&&timediff(str->time,tend)<=0.0) continue;
            
            /* convert message */
            switch (type) {
                case  1: convobs(ofp,opt,str,n,slips); break;
                case  2: convnav(ofp,opt,str,n);       break;
                case  3: convsbs(ofp,opt,str,n);       break;
                case 31: convlex(ofp,opt,str,n);       break;
                case -1: n[NOUTFILE]++; break; /* error */
            }
            te=str->time; if (ts.time==0) ts=te;
            
            /* set approx position */
            if (type==1&&!opt->autopos&&norm(opt->apppos,3)<=0.0) {
                setapppos(str,opt);
            }
            if (opt->te.time&&timediff(te,opt->te)>10.0) break;
        }
        /* close stream file */
        close_strfile(str);
        
        tend=te; /* end time of a file */
    }
    /* set receiver and antenna information to option */
    if (format==STRFMT_RTCM2||format==STRFMT_RTCM3) {
        rtcm2opt(&str->rtcm,opt);
    }
    else if (format==STRFMT_RINEX) {
        rnx2opt(&str->rnx,opt);
    }
    /* close output files */
    closefile(ofp,opt,str->nav);
    
    /* remove empty output files */
    for (i=0;i<NOUTFILE;i++) {
        if (ofp[i]&&n[i]<=0) remove(ofile[i]);
    }
    if (ts.time>0) showstat(sess,ts,te,n);
    
    for (i=0;i<MAXEXFILE;i++) free(epath[i]);
    
    free_strfile(str);
    
    if (opt->tstart.time==0) opt->tstart=opt->ts;
    if (opt->tend  .time==0) opt->tend  =opt->te;
    
    return abort?-1:1;
}
Beispiel #3
0
/* rinex converter for single-session ----------------------------------------*/
static int convrnx_s(int sess, int format, rnxopt_t *opt, const char *file,
                     char **ofile)
{
    FILE *ofp[NOUTFILE]={NULL};
    strfile_t *str;
    gtime_t ts={0},te={0},tend={0},time={0};
    unsigned char slips[MAXSAT][NFREQ+NEXOBS]={{0}};
    int i,j,nf,type,n[NOUTFILE+1]={0},abort=0;
    char path[1024],*paths[NOUTFILE],s[NOUTFILE][1024];
    char *epath[MAXEXFILE]={0},*staid=*opt->staid?opt->staid:"0000";
    
    trace(3,"convrnx_s: sess=%d format=%d file=%s ofile=%s %s %s %s %s %s %s\n",
          sess,format,file,ofile[0],ofile[1],ofile[2],ofile[3],ofile[4],
          ofile[5],ofile[6]);
    
    /* replace keywords in input file */
    if (reppath(file,path,opt->ts,staid,"")<0) {
        showmsg("no time for input file: %s",file);
        return 0;
    }
    /* expand wild-cards in input file */
    for (i=0;i<MAXEXFILE;i++) {
        if (!(epath[i]=(char *)malloc(1024))) {
            for (i=0;i<MAXEXFILE;i++) free(epath[i]);
            return 0;
        }
    }
    nf=expath(path,epath,MAXEXFILE);
    
    if (format==STRFMT_RTCM2||format==STRFMT_RTCM3) time=opt->trtcm;
    
    if (opt->scanobs) {
        
        /* scan observation types */
        if (!scan_obstype(format,epath[0],opt,&time)) return 0;
    }
    else {
        /* set observation types by format */
        set_obstype(format,opt);
    }
    if (!(str=gen_strfile(format,opt->rcvopt,time))) {
        for (i=0;i<MAXEXFILE;i++) free(epath[i]);
        return 0;
    }
    time=opt->ts.time?opt->ts:(time.time?timeadd(time,TSTARTMARGIN):time);
    
    /* replace keywords in output file */
    for (i=0;i<NOUTFILE;i++) {
        paths[i]=s[i];
        if (reppath(ofile[i],paths[i],time,staid,"")<0) {
            showmsg("no time for output path: %s",ofile[i]);
            for (i=0;i<MAXEXFILE;i++) free(epath[i]);
            free_strfile(str);
            return 0;
        }
    }
    /* open output files */
    if (!openfile(ofp,paths,path,opt,str->nav)) {
        for (i=0;i<MAXEXFILE;i++) free(epath[i]);
        free_strfile(str);
        return 0;
    }
    for (i=0;i<nf&&!abort;i++) {
        
        /* open stream file */
        if (!open_strfile(str,epath[i])) continue;
        
        /* input message */
        for (j=0;(type=input_strfile(str))>=-1;j++) {
            
            if (j%11==1&&(abort=showstat(sess,te,te,n))) break;
            
            /* avioid duplicated if overlapped data */
            if (tend.time&&timediff(str->time,tend)<=0.0) continue;
            
            /* convert message */
            switch (type) {
                case  1: convobs(ofp,opt,str,n,slips); break;
                case  2: convnav(ofp,opt,str,n);       break;
                case  3: convsbs(ofp,opt,str,n);       break;
                case 31: convlex(ofp,opt,str,n);       break;
                case -1: n[NOUTFILE]++; break; /* error */
            }
            te=str->time; if (ts.time==0) ts=te;
            
            /* set approx position */
            if (type==1&&!opt->autopos&&norm(opt->apppos,3)<=0.0) {
                setapppos(str,opt);
            }
            if (opt->te.time&&timediff(te,opt->te)>10.0) break;
        }
        /* close stream file */
        close_strfile(str);
        
        tend=te; /* end time of a file */
    }
    /* set receiver and antenna information to option */
    if (format==STRFMT_RTCM2||format==STRFMT_RTCM3) {
        rtcm2opt(&str->rtcm,opt);
    }
    else if (format==STRFMT_RINEX) {
        rnx2opt(&str->rnx,opt);
    }
    /* close output files */
    closefile(ofp,opt,str->nav);
    
    /* remove empty output files */
    for (i=0;i<NOUTFILE;i++) {
        if (ofp[i]&&n[i]<=0) remove(ofile[i]);
    }
    if (ts.time>0) showstat(sess,ts,te,n);
    
    for (i=0;i<MAXEXFILE;i++) free(epath[i]);
    
    free_strfile(str);
    
    if (opt->tstart.time==0) opt->tstart=opt->ts;
    if (opt->tend  .time==0) opt->tend  =opt->te;
    
    return abort?-1:1;
}