📄 to-rinex.c
字号:
eph->aode = ( i2 ) word1;
word1 = ( u2 ) sub3[9][0];
eph->aode3 = ( i2 ) word1;
/* Mean anomaly at reference time ( m0 ). */
MACRO_MAKE_EPH_WORD(word1, sub2, 3, 2, 4, 0 );
MACRO_MAKE_EPH_WORD(word2, sub2, 4, 1, 4, 2 );
eph->m0 = ( ( ( i4 ) word1 << 16 ) | word2 ) * PITWOM31;
/* Mean motion difference from computed value ( delta_n ). */
MACRO_MAKE_EPH_WORD(word1, sub2, 3, 0, 3, 1 );
eph->deltan = ( i2 ) word1 * PITWOM43;
/* Eccentricity ( e ). */
MACRO_MAKE_EPH_WORD(word1, sub2, 5, 2, 6, 0 );
MACRO_MAKE_EPH_WORD(word2, sub2, 6, 1, 6, 2 );
eph->e = ( ( ( u4 ) word1 << 16 ) | word2 ) * TWOM33;
/* Square root of the semi-major axis ( sqrt_a ). */
MACRO_MAKE_EPH_WORD(word1, sub2, 7, 2, 8, 0 );
MACRO_MAKE_EPH_WORD(word2, sub2, 8, 1, 8, 2 );
eph->roota = ( ( ( u4 ) word1 << 16 ) | word2 ) * TWOM19;
/* Longitude of ascending mode of orbit plane at weekly epoch ( omega_0 ). */
MACRO_MAKE_EPH_WORD(word1, sub3, 2, 2, 3, 0 );
MACRO_MAKE_EPH_WORD(word2, sub3, 3, 1, 3, 2 );
eph->omega0 = ( ( ( i4 ) word1 << 16 ) | word2 ) * PITWOM31;
/* Inclination angle at reference time ( i0 ). */
MACRO_MAKE_EPH_WORD(word1, sub3, 4, 2, 5, 0 );
MACRO_MAKE_EPH_WORD(word2, sub3, 5, 1, 5, 2 );
eph->i0 = ( ( ( i4 ) word1 << 16 ) | word2 ) * PITWOM31;
/* Argument of perigee ( w ). */
MACRO_MAKE_EPH_WORD(word1, sub3, 6, 2, 7, 0 );
MACRO_MAKE_EPH_WORD(word2, sub3, 7, 1, 7, 2 );
eph->omega = ( ( ( i4 ) word1 << 16 ) | word2 ) * PITWOM31;
/* Rate of right ascension ( omega_dot ). */
word1 = ( u2 ) sub3[8][0];
MACRO_SET_UPPER(word1) ; /* Set upper bits if negative. */
MACRO_MAKE_EPH_WORD(word2, sub3,8, 1, 8, 2 );
eph->omegadot = ( ( ( i4 ) word1 << 16 ) | word2 ) * PITWOM43;
/* Rate of inclination angle ( i_dot ). */
MACRO_MAKE_EPH_WORD(word1, sub3, 9, 1, 9, 2 ) ;
word1 = word1 >> 2 ;
if ( word1 & 0x2000 ) /* Set upper bits if negative. */
word1 |= 0xC000;
eph->idot = ( i2 ) word1 * PITWOM43;
/* Amplitude of the cosine harmonic correction term to the argument of latitude (cuc). */
MACRO_MAKE_EPH_WORD(word1, sub2, 5, 0, 5, 1 );
eph->cuc = ( i2 ) word1 * TWOM29;
/* Amplitude of the sine harmonic correction term to the argument of latitude (cus). */
MACRO_MAKE_EPH_WORD(word1, sub2, 7, 0, 7, 1 );
eph->cus = ( i2 ) word1 * TWOM29;
/* Amplitude of the cosine harmonic correction term to the orbit radius (crc). */
MACRO_MAKE_EPH_WORD(word1, sub3, 6, 0, 6, 1 );
eph->crc = ( i2 ) word1 * TWOM5;
/* Amplitude of the sine harmonic correction term to the orbit radius (crs). */
MACRO_MAKE_EPH_WORD(word1, sub2, 2, 1, 2, 2 );
eph->crs = ( i2 ) word1 * TWOM5;
/* Amplitude of the cosine harmonic correction term to the angle of inclination (cic). */
MACRO_MAKE_EPH_WORD(word1, sub3, 2, 0, 2, 1 );
eph->cic = ( i2 ) word1 * TWOM29;
/* Amplitude of the sine harmonic correction term to the angle of inclination (cis). */
MACRO_MAKE_EPH_WORD(word1, sub3, 4, 0, 4, 1 );
eph->cis = ( i2 ) word1 * TWOM29;
/* Polynomial coefficient ( af2 ). */
word1 = ( u2 ) sub1[8][0];
MACRO_SET_UPPER(word1) ; /* Set upper bits if negative. */
eph->af2 = ( i2 ) word1 * TWOM55;
/* Polynomial coefficient ( af1 ). */
MACRO_MAKE_EPH_WORD(word1, sub1, 8, 1, 8, 2 );
eph->af1 = ( i2 ) word1 * TWOM43;
/* Polynomial coefficient ( af0 ). */
word1 = ( u2 ) sub1[9][0];
MACRO_SET_UPPER(word1) ; /* Set upper bits if negative. */
MACRO_MAKE_EPH_WORD(word2, sub1,9, 1, 9, 2 ) ;
word2 = word2 & 0xFFFC ; /* clear 2 bits */
eph->af0 = ( ( ( i4 ) word1 << 16 ) | word2 ) * TWOM3125;
eph->wn = WeekNo;
}
void ReadNovatelEpoch(char *s,RinexEpochType *RinexEpoch)
{
char *ptr;
int i,j;
double sec;
int ObsNum;
ptr=strtok(s,",*");
while(ptr!=NULL)
{
ptr=strtok(NULL,",*"); WeekNo=atoi(ptr);
ptr=strtok(NULL,",*"); sec=atof(ptr);
ptr=strtok(NULL,",*"); ObsNum=atoi(ptr); RinexEpoch->satnum=ObsNum;
ptr=strtok(NULL,",*");
for(j=0;j<ObsNum;j++)
{
ptr=strtok(NULL,",*"); RinexEpoch->PRN[j]=atoi(ptr);
ptr=strtok(NULL,",*"); RinexEpoch->ca_range[j]= atof(ptr);
ptr=strtok(NULL,",*");
ptr=strtok(NULL,",*"); RinexEpoch->phase_l1[j]=atof(ptr);
ptr=strtok(NULL,",*");
ptr=strtok(NULL,",*");
ptr=strtok(NULL,",*");
ptr=strtok(NULL,",*");
ptr=strtok(NULL,",*");
}
break;
}
GetYMDHMS(WeekNo,sec,&RinexEpoch->year,&RinexEpoch->month,
&RinexEpoch->day,&RinexEpoch->hour,&RinexEpoch->minute,&RinexEpoch->second);
rinex_obs_header.EndYear=RinexEpoch->year;
rinex_obs_header.EndMonth=RinexEpoch->month;
rinex_obs_header.EndDay=RinexEpoch->day;
rinex_obs_header.EndHour=RinexEpoch->hour;
rinex_obs_header.EndMinute=RinexEpoch->minute;
rinex_obs_header.EndSecond=RinexEpoch->second;
RinexEpoch->year-=1900;
RinexEpoch->flag = 0;
}
/* This procedure converts an ASCII value to its hex equivalent.*/
i2 Hex(i1 ASCIIvalue)
{
if (((i2) ASCIIvalue) < 0x40) return(((i2) ASCIIvalue) - 0x30);
else if (((i2) ASCIIvalue) < 0x60) return(((i2) ASCIIvalue) - 0x37);
else return(((i2) ASCIIvalue) - 0x57);
}
int Motorola2Rinex(char *SourceFile,char *ObsFile,char *NavFile)
{
FILE *f,*f1,*f2;
RinexEpochType *RinexEpoch;
SVText *RinexEpp;
int First, i, sync1, sync2;
unsigned char buf[200],ch;
FILE *tempf;
if ((tempf=fopen("temp.dat","wb"))==NULL) {
printf("can not open file \n"); }
if((f=fopen(SourceFile,"rb"))==NULL) {
printf("cannot open file \n"); }
if ((f1=fopen(ObsFile,"wb"))==NULL) {
printf("can not open file \n"); }
if ((f2=fopen(NavFile,"wb"))==NULL) {
printf("can not open file \n"); }
if((RinexEpoch=(RinexEpochType *)malloc(sizeof(RinexEpochType)*8))==NULL) {
printf("not enough mem \n"); }
if((RinexEpp=(SVText *)malloc(sizeof(SVText)))==NULL) {
printf("not enough mem \n"); }
WriteRinexNavHeaderFile(f2);
rewind(f); sync1=0; sync2=0; First=1; WeekNo=947;
for(i=0;i<8;i++)
do {
ch=fgetc(f); if(feof(f)) break;
if(ch=='@') { sync1=1; buf[0]=ch; }
if(sync1==1) {
ch=fgetc(f);if(feof(f)) break;
if(ch=='@') { buf[1]=ch; sync2=1; }
else sync2=0; }
if(sync2==1) {
ch=fgetc(f);
if((ch=='E')||(ch=='B')) {
buf[2]=ch;
if(ch=='E') {
ch=fgetc(f);
if((ch=='a')||(ch=='g')) { buf[3]=ch;
if(ch=='a') { for(i=0;i<(76-4);i++) { ch=fgetc(f);buf[4+i]=fgetc(f); } }
else {
for(i=0;i<154;i++) { ch=fgetc(f); buf[4+i]=ch; }
if(WeekNo) {
if(First) {
rinex_obs_header.StartYear=rinex_obs_header.EndYear;
rinex_obs_header.StartMonth=rinex_obs_header.EndMonth;
rinex_obs_header.StartDay=rinex_obs_header.EndDay;
rinex_obs_header.StartHour=rinex_obs_header.EndHour;
rinex_obs_header.StartMinute=rinex_obs_header.EndMinute;
rinex_obs_header.StartSecond=rinex_obs_header.EndSecond;
First=0; }
ReadMotoEpoch(buf,RinexEpoch);
WriteRinexObsEpochFile(f1,RinexEpoch); } } } }
else if(ch=='B') { ch=fgetc(f);
if(ch=='f') {
buf[3]=ch;
for(i=0;i<75;i++) {
ch=fgetc(f); buf[4+i]=ch; }
ReadMotoEph(EG_BINARY,buf,RinexEpp);
WriteRinexNavFile( f2 ,RinexEpp); } } } }
sync1=0;sync2=0;
}while(!feof(f));
fclose(tempf); fclose(f); fclose(f1); fclose(f2);
free(RinexEpoch); free(RinexEpp); return 1;
}
void ReadMotoPos(char *buf)
{
#define MSECS_TO_DEGREES ( ( 1.0 / 1000.0 ) / 3600.0 )
#define NUM_CHANNELS 8
double P0=3.1415926535898/180.0;
u1 month, day, hours,minutes, i;
u2 year;
double seconds,lat,lon, height;
u1 tempchar ,nsecs;
u4 tempu4byte ;
i4 temps4byte ;
i2 wnday;
month = buf[4]; day = buf[5];
tempchar = buf[6]; year = ( (u2)tempchar << 8 ) + buf[7];
hours = buf[8]; minutes = buf[9];
tempchar = buf[10] ; /* integer seconds */
tempu4byte = buf[11];
tempu4byte = ( tempu4byte << 8 ) + buf[12];
tempu4byte = ( tempu4byte << 8 ) + buf[13];
tempu4byte = ( tempu4byte << 8 ) + buf[14];
seconds = (double) tempchar + ( ( (double) tempu4byte ) / 1.0E+9 );
WeekNo= GetWeekNo(year,month,day,&wnday);
temps4byte = buf[15];
temps4byte = ( temps4byte << 8 ) + buf[16];
temps4byte = ( temps4byte << 8 ) + buf[17];
temps4byte = ( temps4byte << 8 ) + buf[18];
lat = (double) temps4byte * MSECS_TO_DEGREES ;
temps4byte = buf[19];
temps4byte = ( temps4byte << 8 ) + buf[20];
temps4byte = ( temps4byte << 8 ) + buf[21];
temps4byte = ( temps4byte << 8 ) + buf[22];
lon = (double) temps4byte * MSECS_TO_DEGREES ;
temps4byte = buf[23];
temps4byte = ( temps4byte << 8 ) + buf[24] ;
temps4byte = ( temps4byte << 8 ) + buf[25] ;
temps4byte = ( temps4byte << 8 ) + buf[26] ;
height = (double) temps4byte / 100.0 ;
BLHtoXYZ(lat*P0,lon*P0,height,
&rinex_obs_header.AppX,&rinex_obs_header.AppY,&rinex_obs_header.AppZ);
}
void ReadMotoEpoch(unsigned char *buf,RinexEpochType *RinexEpoch)
{
double C=29972458.0;
double t[8],fsec,t0,temp;
int num, i,j;
u4 tempu4byte, isec;
i4 temps4byte ;
u2 tempu2byte;
i2 temps2byte,iphase,fphase;
static int k=0;
static int flag=0;
if(k>2) { k=0; flag=1; }
i=j=0;
tempu4byte = buf[5-1];
tempu4byte = ( tempu4byte << 8 ) + buf[6-1];
isec = ( tempu4byte << 8 ) + buf[7-1];
temps4byte = buf[8-1];
temps4byte = ( temps4byte << 8) + buf[9-1];
temps4byte = ( temps4byte << 8) + buf[10-1];
temps4byte = ( temps4byte << 8) + buf[11-1];
t0=isec +(double)temps4byte/1.0e9;
for(i=0;i<8;i++)
{
if(buf[13-1+18*i]==8 )
{
RinexEpoch->PRN[j]=buf[12-1+18*i];
tempu4byte = buf[14-1+18*i];
tempu4byte = ( tempu4byte << 8 ) + buf[15-1+18*i];
isec = ( tempu4byte << 8 ) + buf[16-1+18*i];
temps4byte = buf[17-1 + 18*i ];
temps4byte = ( temps4byte << 8) + buf[18-1+18*i];
temps4byte = ( temps4byte << 8) + buf[19-1+18*i];
temps4byte = ( temps4byte << 8) + buf[20-1+18*i];
t[i]=isec +(double) temps4byte/1.0e9;
RinexEpoch->ca_range[i]=(t0-t[i]) * C;
GetYMDHMS(WeekNo,t[i],&RinexEpoch->year,&RinexEpoch->month,
&RinexEpoch->day,&RinexEpoch->hour,&RinexEpoch->minute,&RinexEpoch->second);
rinex_obs_header.EndYear=RinexEpoch->year;
rinex_obs_header.EndMonth=RinexEpoch->month;
rinex_obs_header.EndDay=RinexEpoch->day;
rinex_obs_header.EndHour=RinexEpoch->hour;
rinex_obs_header.EndMinute=RinexEpoch->minute;
rinex_obs_header.EndSecond=RinexEpoch->second;
RinexEpoch->year-=1900;
RinexEpoch->flag=0;
tempu2byte = buf[21-1+18*i];
iphase = ( tempu2byte << 8 ) + buf[22-1+18*i];
temps2byte = buf[23-1+18*i];
fphase = ( temps2byte << 8 ) + buf[24-1+18*i];
temp =iphase + (double)fphase/65535.0;
RinexEpoch->phase_l1[j]=temp;
j++;
}
}
RinexEpoch->satnum =j;
}
void ReadMotoEph(u1 eg_type, char *buf,SVText *eph)
{
#define EPH_NUM_CHARS 144 /* (72 bytes * 2 nibbles/byte) */
#define EPH_NUM_WORDS 8 /* at 3 bytes/word */
i1 tempchar ;
u1 char_ctr, byte_ctr, word_ctr, i, j,base ;
i1 ascii_buffer[500] ;
i1 *char_ptr ;
char_ptr= buf;
if ( eg_type == EG_ASCII ) {
char_ptr+=4;
eph->prn=((*char_ptr)<<4)|(*(char_ptr+1));
char_ptr+=2;
for ( char_ctr = 0 ; char_ctr < EPH_NUM_CHARS ; char_ctr++ )
ascii_buffer[char_ctr] = *(char_ptr++) ;
base=0;
for ( i = 0 ; i < EPH_NUM_WORDS ; i++ ) {
for(j=0;j<3;j++) sub1[i+2][j] =
(i1) (((Hex(ascii_buffer[base++])) << 4) | Hex(ascii_buffer[base++]));}
for ( i = 0 ; i < EPH_NUM_WORDS ; i++ ) {
for(j=0;j<3;j++) sub2[i+2][j] =
(i1) (((Hex(ascii_buffer[base++])) << 4) | Hex(ascii_buffer[base++])); }
for ( i = 0 ; i < EPH_NUM_WORDS ; i++ ) {
for(j=0;j<3;j++) sub3[i+2][j] =
(i1) (((Hex(ascii_buffer[base++])) << 4) | Hex(ascii_buffer[base++])); } }
else {
char_ptr+=4;
eph->prn=*char_ptr++;
for ( i = 0 ; i < EPH_NUM_WORDS ; i++ )
for(j=0;j<3;j++) sub1[i+2][j] = *char_ptr++ ;
for ( i = 0 ; i < EPH_NUM_WORDS ; i++ )
for(j=0;j<3;j++) sub2[i+2][j] = *char_ptr++ ;
for ( i = 0 ; i < EPH_NUM_WORDS ; i++ )
for(j=0;j<3;j++) sub3[i+2][j] = *char_ptr++ ; }
Convert_Ephemeris(eph) ; eph->wn=WeekNo=947;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -