📄 crx2rnx.c
字号:
/***********************************************************************//* program name : CRX2RNX *//* *//* Program to recover the RINEX file from Compact RINEX file *//* Created by Yuki HATANAKA / Geographical Survey Institute, Japan *//* *//* ver. *//* 4.0.0 2007.01.31 test version Y. Hatanaka *//* - CRINEX 1/3 for RINEX 2.x/3.x *//* 4.0.1 2007.05.08 Y. Hatanaka *//* - elimination of supports for VMS and SUN OS 4.1.x *//* - output not to the current directory but the same *//* directory as the input file. *//* - the same code for DOS and UNIX *//* 4.0.2 2007.06.07 Y. Hatanaka *//* - fixing incompatibility of argument and format *//* string of printf. *//* 4.0.3 2007.06.21 Y. Hatanaka *//* - fixing a bug on lack of carrying the number *//* between lower and upper digits *//* *//* Copyright (c) 2007 Geographical Survey Institute *//* All rights reserved. *//* *//***********************************************************************/#define VERSION "ver.4.0.3"/**** Exit codes are defined here. ****/#ifndef EXIT_SUCCESS#define EXIT_SUCCESS 0#endif#ifndef EXIT_FAILURE#define EXIT_FAILURE 1#endif#define EXIT_WARNING 2/* Don't change the lines from here. */#include <limits.h>#include <stdio.h>#include <stdlib.h>#include <string.h>#include <ctype.h>#define CHOP_LF(q,p) p = strchr(q,'\n'); if( *(p-1) == '\r' && p>q )p--;*p = '\0';/* #define CHOP_LF(q,p) p = strchr(q,'\n'); *p = '\0'; */#define CHOP_BLANK(q,p) p = strchr(q,'\0');while(*--p == ' ' && p>q);*++p = '\0'/* define global constants */#define PROGNAME "CRX2RNX"#define MAXSAT 90 /* Maximum number of satellites observed at one epoch */#define MAXTYPE 30 /* Maximum number of data types */#define MAXCLM 1024 /* Maximum columns in one line (>MAXTYPE*19+3) */#define MAX_BUFF_SIZE 131072 /* Muximum size of output buffer (>MAXSAT*(MAXTYPE*19+4)+60 */#define MAX_DIFF_ORDER 5 /* Muximum order of difference to be dealt with *//* define data structure for fields of clock offset and obsercvation records */typedef struct clock_format{ long u[MAX_DIFF_ORDER+1]; /* upper X digits for each diference order */ long l[MAX_DIFF_ORDER+1]; /* lower 8 digits */} clock_format;typedef struct data_format{ long u[MAX_DIFF_ORDER+1]; /* upper X digits for each diference order */ long l[MAX_DIFF_ORDER+1]; /* lower 5 digits */ int order; int arc_order;} data_format;/* define global variables */clock_format clk1,clk0;data_format y1[MAXSAT][MAXTYPE],y0[MAXSAT][MAXTYPE];char flag1[MAXSAT][MAXTYPE*2+1],flag[MAXSAT][MAXTYPE*2+1];int rinex_version,crinex_version,ep_top_from,ep_top_to;int nsat,ntype,ntype_gnss[UCHAR_MAX],ntype_record[MAXSAT],clk_order = 0, clk_arc_order = 0;long nl_count=0;int skip = 0;int exit_status = EXIT_SUCCESS;char out_buff[MAX_BUFF_SIZE],*p_buff;/* declaration of functions */void fileopen(int argc, char *argv[]);void header();int put_event_data(char *dline, char *p_event);void skip_to_next(char *dline);void process_clock(char *dline);void set_sat_table(char *p_new, char *p_old, int nsat1, int *sattbl);void data(char *p_sat_lst, int *sattbl, char dflag[][MAXTYPE*2]);void repair(char *s, char *ds);int getdiff(data_format *y, data_format *y0, int i0, char *dflag);void putfield(data_format *y, char *flag);void read_clock(char *dline ,long *yu, long *yl);void print_clock(long yu, long yl, int shift_clk);int read_chk_line(char *line);void error_exit(int error_no, char *string);/*---------------------------------------------------------------------*/main(int argc, char *argv[]){ static char line[MAXCLM]="", sat_lst_old[MAXSAT*3]; static int nsat1 = 0, n; char dline[MAXCLM],*p; int sattbl[MAXSAT],i,j,*i0; size_t offset; char dflag[MAXSAT][MAXTYPE*2]; char *p_event,*p_nsat,*p_satlst,*p_clock,shift_clk; /* sattbl[i]: order (at the previous epoch) of i-th satellite */ /* (at the current epoch). -1 is set for the new satellites */ fileopen(argc,argv); for(i=0;i<UCHAR_MAX;i++)ntype_gnss[i]=-1; /** -1 unless GNSS type is not defined **/ header(); if (rinex_version==2){ ep_top_from='&'; ep_top_to =' '; p_event =&dline[28]; /** pointer to event flug **/ p_nsat = &line[29]; /** pointer to n_sat **/ p_satlst = &line[32]; /** pointer to address to add satellite list **/ p_clock = &line[68]; /** pointer to clock offset data **/ shift_clk = 1; offset=3; }else{ ep_top_from='>'; ep_top_to= '>'; p_event =&dline[31]; p_nsat = &line[32]; p_satlst = &line[41]; p_clock = &line[41]; shift_clk = 4; offset=6; } while( fgets(dline,MAXCLM,stdin) != NULL ){ /*** exit program successfully ***/ nl_count++; CHOP_LF(dline,p); SKIP: if(crinex_version == 3) { /*** skip escape lines of CRINEX version 3 ***/ while(dline[0] == '&'){ nl_count++; if( fgets(dline,MAXCLM,stdin) == NULL ) return exit_status; CHOP_LF(dline,p); } } if(dline[0] == ep_top_from){ dline[0] = ep_top_to; if(*p_event!='0' && *p_event!='1' ){ if(put_event_data(dline,p_event)!=0) skip_to_next(dline); goto SKIP; } line[0] = '\0'; /**** initialize arc for epoch data ***/ nsat1 = 0; /**** initialize the all satellite arcs ****/ }else if( dline[0] == '\032' ){ return exit_status; /** DOS EOF **/ } /**** read, repair the line ****/ repair(line,dline); p=&line[offset]; /** pointer to the space between year and month **/ if(line[0] != ep_top_to || strlen(line)<(26+offset) || *(p+23) != ' ' || *(p+24) != ' ' || ! isdigit(*(p+25)) ) { skip_to_next(dline); goto SKIP; } CHOP_BLANK(line,p); nsat=atoi(p_nsat); if(nsat > MAXSAT) error_exit(6,p_nsat); set_sat_table(p_satlst,sat_lst_old,nsat1,sattbl); /**** set satellite table ****/ if(read_chk_line(dline) != 0) {skip_to_next(dline);goto SKIP;} read_clock(dline,clk1.u,clk1.l); for(i=0,i0=sattbl ; i<nsat ; i++,i0++){ ntype=ntype_record[i]; if( getdiff(y1[i],y0[*i0],*i0,dflag[i]) != 0 ) {skip_to_next(dline);goto SKIP;} } /*************************************/ /**** print the recovered line(s) ****/ /*************************************/ if(dline[0] != '\0') process_clock(dline); p_buff = out_buff; if(rinex_version == 2){ if(clk_order >= 0){ p_buff += sprintf(p_buff,"%-68.68s",line); print_clock(clk1.u[clk_order],clk1.l[clk_order],shift_clk); }else{ p_buff += sprintf(p_buff,"%.68s\n",line); } for(p = &line[68],n=nsat-12; n>0; n-=12,p+=36) p_buff += sprintf(p_buff,"%32.s%.36s\n"," ",p); }else{ if(clk_order >= 0){ p_buff += sprintf(p_buff,"%.41s",line); print_clock(clk1.u[clk_order],clk1.l[clk_order],shift_clk); }else{ sprintf(p_buff,"%.41s",line); CHOP_BLANK(p_buff,p);*p++='\n';p_buff=p; } } data(p_satlst,sattbl,dflag); *p_buff = '\0'; printf("%s",out_buff); /****************************/ /**** save current epoch ****/ /****************************/ nsat1 = nsat; clk0 = clk1; strncpy(sat_lst_old,p_satlst,nsat*3); for(i=0;i<nsat;i++){ strncpy(flag1[i],flag[i],ntype_record[i]*2); for(j=0;j<ntype_record[i];j++) y0[i][j] = y1[i][j]; } } return exit_status;}/*---------------------------------------------------------------------*/void fileopen(int argc, char *argv[]){ char *p,*infile,outfile[256],*progname; int nfile=0, force=0, help=0; int nfout = 0; /*** =0 default output file name ***/ /*** =1 standaed output ***/ FILE *ifp; progname = argv[0]; argc--;argv++; for(;argc>0;argc--,argv++){ if((*argv)[0] != '-'){ infile = *argv; nfile++; }else if(strcmp(*argv,"-") == 0){ nfout = 1; }else if(strcmp(*argv,"-f") == 0){ force = 1; }else if(strcmp(*argv,"-s") == 0){ skip = 1; }else if(strcmp(*argv,"-h") == 0){ help = 1; }else{ help = 1; } } if(help == 1 || nfile > 1 || nfile < 0) error_exit(2,progname); if(nfile == 0) return; /*** stdin & stdout will be used ***/ /***********************/ /*** open input file ***/ /***********************/ p=strrchr(infile,'.'); if(p == NULL || (*(p+3) != 'D' && *(p+3) != 'd') || *(p+4) != '\0') error_exit(3,p); if((ifp = fopen(infile,"r")) == NULL) error_exit(4,infile); /************************/ /*** open output file ***/ /************************/ if(nfout == 0) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -