📄 crx2rnx.c
字号:
strcpy(outfile,infile); p=strrchr(outfile,'.'); if(*(p+3) == 'd') { *(p+3) = 'o';} else { *(p+3) = 'O';} if((freopen(outfile,"r",stdout)) != NULL && force == 0){ fprintf(stderr,"The file %s already exists. Overwrite?(n)",outfile); if(getchar() != 'y') exit(EXIT_SUCCESS); } freopen(outfile,"w",stdout); } fclose(ifp); freopen(infile,"r",stdin);}/*---------------------------------------------------------------------*/void header(){ char line[MAXCLM],*p; if( read_chk_line(line) == 1 ) error_exit(5,"1.0-2.0"); crinex_version=atoi(line); if( strncmp(&line[0],"1.0",3) != 0 && strncmp(&line[0],"3.0",3) != 0 || strncmp(&line[60],"CRINEX VERS / TYPE",19) != 0 ) error_exit(5,"1.0-2.0"); if( read_chk_line(line) == 1 ) error_exit(8,line); if( read_chk_line(line) == 1 ) error_exit(8,line); CHOP_BLANK(line,p); printf("%s\n",line); if(strncmp(&line[60],"RINEX VERSION / TYPE",20) != 0 || (line[5]!='2' && line[5]!='3') ) error_exit(15,"2.x or 3.x"); rinex_version=atoi(line); do { read_chk_line(line); CHOP_BLANK(line,p); printf("%s\n",line); if (strncmp(&line[60],"# / TYPES OF OBSERV",19) == 0 && line[5] != ' '){ ntype=atoi(line); /** for RINEX2 **/ } else if(strncmp(&line[60],"SYS / # / OBS TYPES",19) == 0){ /** for RINEX3 **/ if (line[0] != ' ') ntype_gnss[line[0]]=atoi(&line[3]); if (ntype_gnss[line[0]] > MAXTYPE) error_exit(15,line); } }while(strncmp(&line[60],"END OF HEADER",13) != 0);}/*---------------------------------------------------------------------*/void read_clock(char *dline, long *yu, long *yl){ char *p,*s,*p1; p = dline; if(*p == '\0'){ clk_order = -1; }else{ if(*(p+1) == '&') { /**** for the case of arc initialization ****/ sscanf(p,"%d&",&clk_arc_order); if(clk_arc_order > MAX_DIFF_ORDER) error_exit(7,dline); clk_order = -1; p += 2; } p1=p; if(*p == '-') p1++; s=strchr(p1,'\0'); if((s-p1) < 9 ){ /** s-p1 == strlen(p1) ***/ *yu = 0; *yl = atol(p); }else{ s -= 8; *yl = atol(s); *s = '\0'; *yu = atol(p); if(*yu < 0) *yl = -*yl; } }}/*---------------------------------------------------------------------*/void process_clock(char *dline){ int i,j; /****************************************/ /**** recover the clock offset value ****/ /****************************************/ if(clk_order < clk_arc_order){ clk_order++; for(i=0,j=1 ; i<clk_order ; i++,j++){ clk1.u[j] = clk1.u[i]+clk0.u[i]; clk1.l[j] = clk1.l[i]+clk0.l[i]; clk1.u[j] += clk1.l[j]/100000000; /*** to avoid overflow of y1.l ***/ clk1.l[j] %= 100000000; } }else{ for(i=0,j=1 ; i<clk_order ; i++,j++){ clk1.u[j] = clk1.u[i]+clk0.u[j]; clk1.l[j] = clk1.l[i]+clk0.l[j]; clk1.u[j] += clk1.l[j]/100000000; clk1.l[j] %= 100000000; } }}/*---------------------------------------------------------------------*/int put_event_data(char *dline, char *p_event){/***********************************************************************//* - Put event data for one event. *//* - This function is called when the event flag > 1. *//***********************************************************************/ int i,n; char *p; do { dline[0] = ep_top_to; CHOP_BLANK(dline,p); printf("%s\n",dline); if( strlen(dline) > 29 ){ n=atoi((p_event+1)); for(i=0;i<n;i++){ read_chk_line(dline); CHOP_BLANK(dline,p); printf("%s\n",dline); if (strncmp(&dline[60],"# / TYPES OF OBSERV",19) == 0 && dline[5] != ' ' ){ ntype=atoi(dline); /** for RINEX2 **/ } else if(strncmp(&dline[60],"SYS / # / OBS TYPES",19) == 0){ /** for RINEX3 **/ if (dline[0] != ' ') ntype_gnss[dline[0]]=atoi(&dline[3]); if (ntype_gnss[dline[0]] > MAXTYPE) error_exit(15,dline); } } } do { nl_count++; if(fgets(dline,MAXCLM,stdin) == NULL) exit(exit_status); /*** eof: exit program successfully ***/ } while (crinex_version == 3 && dline[0] == '&'); CHOP_LF(dline,p); if(dline[0] != ep_top_from || strlen(dline)<29 || ! isdigit(*p_event) ) { if( ! skip ) error_exit(9,dline); fprintf(stderr,"WARNING : The epoch should be initialized, but not.\n"); return 1; } }while(*p_event != '0' && *p_event != '1'); return 0;}/*---------------------------------------------------------------------*/void skip_to_next(char *dline){ char *p; exit_status=EXIT_WARNING; fprintf(stderr," line %ld : skip until an initialized epoch is found.",nl_count); if(rinex_version == 2) { p=dline+3; /** pointer to the space between year and month **/ }else{ p=dline+6; } do { nl_count++; if(fgets(dline,MAXCLM,stdin) == NULL) { fprintf(stderr," .....next epoch not found before EOF.\n"); printf("%29d%3d\n%-60sCOMMENT\n",4,1," *** Some epochs are skiped by CRX2RNX ***"); exit(exit_status); } }while(dline[0]!=ep_top_from || strlen(dline)<29 || *p != ' ' || *(p+3) != ' ' || *(p+6) != ' ' || *(p+9) != ' ' || *(p+12) != ' ' || *(p+23) != ' ' || *(p+24) != ' ' || ! isdigit(*(p+25)) ); CHOP_LF(dline,p); fprintf(stderr," .....next epoch found at line %ld.\n",nl_count); printf("%29d%3d\n%-60sCOMMENT\n",4,1," *** Some epochs are skiped by CRX2RNX ***");}/*---------------------------------------------------------------------*/void set_sat_table(char *p_new, char *p_old, int nsat1, int *sattbl){/***********************************************************************//* - Read number of satellites (nsat) *//* - Compare the satellite list at the epoch (*p_new) and that at the *//* previous epoch(*p_old), and make index (*sattbl) for the *//* corresponding order of the satellites. *//* *sattbl is set to -1 for new satellites. *//***********************************************************************/ int i,j; char *ps; /*** set # of data types for each satellite ***/ if(rinex_version == 2 ) { /** for RINEX2 **/ for (i=0 ; i<nsat ; i++){ ntype_record[i]=ntype; } }else{ /** for RINEX3 **/ for (i=0,ps=p_new ; i<nsat ; i++,ps+=3){ ntype_record[i]=ntype_gnss[*ps]; /*** # of data type for the GNSS system ***/ if(ntype_record[i]<0)error_exit(20,p_new); } } for (i=0,p_new ; i<nsat ; i++,p_new+=3){ *sattbl = -1; for(j=0,ps=p_old ; j<nsat1 ; j++,ps+=3){ if(strncmp(p_new,ps,3) == 0){ *sattbl = j; break; } } sattbl++; }}/*---------------------------------------------------------------------*/void data(char *p_sat_lst, int *sattbl, char dflag[][MAXTYPE*2]){/********************************************************************//* Functions *//* (1) compose the original data from 3rd order difference *//* (2) repair the flags *//* sattbl : previous column on which the satellites are set *//* new satellites are set to -1 *//* u : upper X digits of the data *//* l : lower 5 digits of the data *//* ( y = u*100 + l/1000) *//* date of previous epoch are set to y0 *//********************************************************************/ data_format *py1,*py0; int i,j,k,k1,*i0; char *p; for(i=0,i0=sattbl,p=p_sat_lst ; i<nsat ; i++,i0++,p+=3){ /**** set # of data types for the GNSS type ****/ /**** and write satellite ID in case of RINEX3 ****/ /**** ---------------------------------------- ****/ if(rinex_version == 3 ){ ntype=ntype_record[i]; strncpy(p_buff,p,3); p_buff += 3; } /**** repair the data frags ****/ /**** ----------------------****/ if(*i0 < 0){ /* new satellite */ if(rinex_version == 3 ){ *flag[i]='\0'; }else{ sprintf(flag[i],"%-*s",ntype*2,dflag[i]); } }else{ strncpy(flag[i],flag1[*i0],ntype*2); } repair(flag[i],dflag[i]); /**** recover the date, and output ****/ /**** ---------------------------- ****/ for(j=0,py1=y1[i] ; j<ntype ; j++,py1++){ if(py1->arc_order >= 0){ py0 = &(y0[*i0][j]); if(py1->order < py1->arc_order){ (py1->order)++; for(k=0,k1=1; k<py1->order; k++,k1++){ py1->u[k1] = py1->u[k] + py0->u[k]; py1->l[k1] = py1->l[k] + py0->l[k]; py1->u[k1] += py1->l[k1]/100000; /*** to avoid overflow of y1.l ***/ py1->l[k1] %= 100000; } }else{ for(k=0,k1=1; k<py1->order; k++,k1++){ py1->u[k1] = py1->u[k] + py0->u[k1]; py1->l[k1] = py1->l[k] + py0->l[k1]; py1->u[k1] += py1->l[k1]/100000; py1->l[k1] %= 100000; } } putfield(py1,&flag[i][j*2]); }else{ if (crinex_version == 1 ) { /*** CRINEX 1 assumes that flags are always ***/ p_buff += sprintf(p_buff," "); /*** blank if data field is blank ***/ flag[i][j*2] = flag[i][j*2+1] = ' '; }else{ /*** CRINEX 3 evaluate flags independently **/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -