⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 to-rinex.c

📁 针对GPS系统的全面的源程序 希望能够对学习GPS技术的朋友有所帮助
💻 C
📖 第 1 页 / 共 4 页
字号:
#include "rinex.h"
#include "sv.h"
#define ASHTECH  1
#define TRIMBLE  2
#define NAVSYMM  3
#define MOTOROLA 4
#define NOVATEL  5
#define EG_ASCII  0
#define EG_BINARY 1
/* globe varition */
RinexObsHeaderType rinex_obs_header;
char err_str[64];           /* string containing error message */
int WeekNo;
int MeasType[9];
/* each 10 words (3 bytes per word) corresponding to words 1-10
   of subframes 1-3 of the satellite nav message.              */
u1 sub1[10][3];
u1 sub2[10][3];
u1 sub3[10][3];
int EphPrn;
u1 hex_ephemeris[24][3] ;
    /* [word][byte] : 24 words (3 bytes per word) corresponding to words 3-10
       of subframes 1-3 of the satellite nav message. */

double tphase[3][8];
double F1[3][8],F2[3][8];
int Count1 = 0, Count2 =0;

/* programm describe */
int Ashtech2Rinex(char *SourceFile,char *ObsFile);
int Ashtech21Rinex(char *SourceFile,char *NavFile);
int ReadAshEpoch(FILE *f,int numobs,RinexEpochType *RinexEpoch);
int ReadAshEph(FILE *f,SVText *eph);
void  Navsymm21Rinex(char  *EPPFile,char *RinexNavFile);
int ReadNavsymmEph( FILE *f1,SVText *snv );
int Navsymm2Rinex(char *SourceFile,char *RinexFile);
int ReadNavstarEpoch(FILE *fname,  RinexEpochType  *RinexEpoch);
int Trimble2Rinex(char *SourceFile,char *RinexObsFile,char *RinexNavFile);
int ReadType11(FILE *fs);
int ReadType17(FILE *fs, RinexEpochType *Epoch);
int ReadType3(int len,FILE *fs,SVText far *eph,FILE *fn);
int ReadType21(int len,FILE *fs, SVText *eph,FILE *fn);
int Novatel2Rinex(char *SourceFile,char *RinexFile,char *RinexNavFile);
void ReadNovatelPos(char *s,  float *X,float *Y,float *Z);
void ReadNovatelEpoch(char *s,RinexEpochType *RinexEpoch);
int ReadNovatelEph(char *s,SVText *snv);
void Convert_Ephemeris(SVText *eph);
i2 Hex(i1 ASCIIvalue);
int Motorola2Rinex(char *SourceFile,char *ObsFile,char *NavFile);
void ReadMotoEpoch(unsigned char *buf,RinexEpochType *RinexEpoch);
void ReadMotoEph(u1 eg_type, char *buf,SVText *eph);

void main()
{
  int Type;
  char *ObsInFile,*EphInFile, str[200];
  char *RinexObsFile,*RinexNavFile;
  FILE *f1,*f2;

  clrscr();
  printf("    ******     Transfer to Rinex File ******\n");
  printf(" Source File Type: 1-Ashtech   2-Trimble 4000  3-Navsymm  \n");
  printf("                   4-Motorola  5-Novatel \n");

  do
  {
    printf("Please Input GPS Type:");
    scanf("%i",&Type);
    if((Type>5)||(Type<1))
      { printf(" Invalid Type Input,Input Again!\n");return;}
    else break;
   }while(1);

  InitRinexObsHeader();
  RinexObsFile="rinex.98o";
  RinexNavFile="rinex.98n";
  WeekNo=0;
/*
  Type=MOTOROLA;
  ObsInFile="c:\\data\\moto.dif";
*/
  switch(Type)
  {
    case ASHTECH:
    case NAVSYMM:
	    printf("Please Input Soure Obs File Name:");
	    scanf("%20s",ObsInFile);
	    printf("Please Input Rinex Nav File Name:");
	    scanf("%20s",EphInFile);

	    if(Type==ASHTECH) {
		 Ashtech21Rinex(EphInFile,RinexNavFile);
		 Ashtech2Rinex(ObsInFile,"temp.obs"); }
	    else if(Type==NAVSYMM) {
		 Navsymm21Rinex(EphInFile,RinexNavFile);
		 Navsymm2Rinex(ObsInFile,"temp.obs");}
	    break;
    case TRIMBLE:
    case MOTOROLA:
    case NOVATEL:
	    printf("Please Input Soure Data File Name:");
	    scanf("%20s",ObsInFile);
	    if(Type==TRIMBLE) {
	       Trimble2Rinex(ObsInFile,"temp.obs",RinexNavFile);}
	    else if(Type==NOVATEL) {
	       Novatel2Rinex(ObsInFile,"temp.obs",RinexNavFile);}
	    else if(Type==MOTOROLA) {
	       Motorola2Rinex(ObsInFile,"temp.obs",RinexNavFile);}
	    break;
    default:break;
   }

   /* format obs file */
   if ((f1 = fopen(RinexObsFile, "wt+"))== NULL) {
      fprintf(stderr, "Cannot open output file.\n"); return;}
   if ((f2 = fopen("temp.obs", "rt"))== NULL) {
      fprintf(stderr, "Cannot open temp file.\n"); return ;}
   MeasType[0]=1;MeasType[1]=2;
   WriteRinexObsHeaderFile(f1, &rinex_obs_header);
   while(!feof(f2)) { fgets(str,2000,f2);fputs(str,f1); }
   fclose(f1); fclose(f2);
}

int Ashtech2Rinex(char *SourceFile,char *ObsFile)
{
  FILE *f1,*f2;
  int i,flag,FirstEpoch,numobs;
  RinexEpochType RinexEpoch;

  struct FileHeaderStruct
  {
    char version[10];
    unsigned char iver;
    char rtype[10];
    char chnver[10];
    char navver[10];
    int  cap;   /* 1=L1 only  2=L1 L2  4=range only */
    long reserved;
    unsigned char numobs;
    char spare[42];
  } Header;

  if ((f1=fopen(ObsFile,"wa+"))==NULL)
    {  sprintf(err_str,"can not open file \n");return 1; }
  if((f2=fopen(SourceFile,"rb"))==NULL)
    {  sprintf(err_str,"cannot open file \n"); return 1; }
   if(fread(&Header,sizeof(struct FileHeaderStruct),1,f2)!=1)
     {  sprintf(err_str,"file read error"); return 1;  }
   numobs=Header.numobs;

   flag=0;  FirstEpoch=1;
   do
   {
     ResetRinexEpoch(&RinexEpoch);
     flag = ReadAshEpoch(f2,numobs,&RinexEpoch);
     if(FirstEpoch==1)
     {
       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;
       FirstEpoch=0;
     }
     WriteRinexObsEpochFile(f1,&RinexEpoch);
   }while(flag==0);
  fclose(f1);  fclose(f2); // free(RinexEpoch);
  return 0;
}

int Ashtech21Rinex(char *SourceFile,char *NavFile)
{
  FILE   *f, *f2;
  SVText *RinexEpp;
  int First;

  if((f=fopen(SourceFile,"rb"))==NULL)
    { sprintf(err_str,"cannot open file \n");  return 1;  }
  if ((f2=fopen(NavFile,"wa"))==NULL)
    { sprintf(err_str,"can not open file \n"); return 1;  }
  if((RinexEpp=(SVText *)malloc(sizeof(SVText)))==NULL)
    { sprintf(err_str,"not enough mem \n");     return 1; }

  WriteRinexNavHeaderFile(f2);
  while(!feof(f))  {
    ResetRinexEpp(RinexEpp);
    ReadAshEph(f,RinexEpp);
    WriteRinexNavFile( f2, RinexEpp);}
  fclose(f);  fclose(f2);  free(RinexEpp);
  return 0;
}

int ReadAshEpoch(FILE *f,int numobs,RinexEpochType *RinexEpoch)
{
   long t;
   int i,j;
   double C = 299792458.0;
   double GPStime;

  struct PosStruct
  {
    char sitename[4];
    double rcv_time,navx,navy,navz,navt,navdot;
    float navxdot,navydot,navzdot;
    int PDOP;
    unsigned char num_sats;
  }PosData;

  struct SatStruct                    /* measurement (data) record  */
  {
    unsigned char svprn;
    unsigned char elev;                  /* unit degree */
    unsigned char azim;                  /*  unit 10 degree */
    unsigned char chnind;
  }SatData;

  struct RawDataStruct
  {
    double raw_range;
    float  smth_r;
    int    smth_n;
    unsigned char polarity;
    unsigned char warning;
    unsigned char goodbad;
    unsigned char ireg;
    unsigned char qa_phase;
    long  doppler;
    double   carphase;
  }RawData[3] ;

   if(fread(&PosData,sizeof(struct PosStruct),1,f)!=1){
       sprintf(err_str,"file read error");  return 1; }
   GPStime=PosData.rcv_time-PosData.navt/C;
   rinex_obs_header.AppX=PosData.navx;
   rinex_obs_header.AppY=PosData.navy;
   rinex_obs_header.AppZ=PosData.navz;

   for(i=0;i<PosData.num_sats;i++)  {
      if(fread(&SatData,sizeof(struct SatStruct),1,f)!=1) {
	 sprintf(err_str,"file read error");  return 1; }
      for(j=0;j<numobs;j++) {
	 if(fread(&RawData[j],sizeof(struct RawDataStruct),1,f)!=1) {
	   sprintf(err_str,"file read error"); return 1; } }
      RinexEpoch->satnum++;
      RinexEpoch->PRN[i]=SatData.svprn;
      RinexEpoch->ca_range[i]=RawData[0].raw_range *C - PosData.navt;
      RinexEpoch->phase_l1[i]=RawData[0].carphase  ;
      RinexEpoch->P1_range[i]=RawData[1].raw_range *C - PosData.navt;
      RinexEpoch->phase_l2[i]=RawData[1].carphase  ;
      RinexEpoch->doppler_l1[i]=RawData[0].doppler/10000.0;}
   GetYMDHMS(WeekNo,GPStime,&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;
   return 0;
}

int ReadAshEph(FILE *f,SVText *eph)
{
   struct EppStruct
   {
     unsigned char prn;
     unsigned int  week;
     long    tow;
     float tgd;
     long aodc,toc;
     float af2,af1,af0;
     long aode;
     float deltan;
     double m0,e, roota;
     long toe;
     float cic,crc,cis,crs,cuc,cus;
     double omega0,omega,i0;
     float omegadot,idot;
     int accuracy,health,fit;
  }EppData;

   if(fread(&EppData,sizeof(struct EppStruct),1,f)!=1) {
       sprintf(err_str,"file read error");  return 1; }
   eph->prn=EppData.prn;      WeekNo=eph->wn=EppData.week;
   eph->tow=EppData.tow;      eph->tgd=EppData.tgd;
   eph->aodc=EppData.aodc;    eph->toc=EppData.toc;
   eph->af2=EppData.af2;      eph->af1=EppData.af1;
   eph->af0=EppData.af0;
   eph->aode=EppData.aode;    eph->deltan=EppData.deltan * PI;
   eph->m0=EppData.m0* PI;    eph->e=EppData.e;
   eph->roota=EppData.roota;  eph->toe=EppData.toe;
   eph->cic=EppData.cic;      eph->crc=EppData.crc;
   eph->cis=EppData.cis;      eph->crs=EppData.crs;
   eph->cuc=EppData.cuc;      eph->cus=EppData.cus;
   eph->omega0=EppData.omega0* PI;  eph->omega=EppData.omega* PI;
   eph->i0=EppData.i0* PI;          eph->omegadot=EppData.omegadot* PI;
   eph->idot=EppData.idot* PI;      eph->accuracy=EppData.accuracy;
   eph->health=EppData.health;  eph->fit=EppData.fit;
   return 0;
}

int Navsymm2Rinex(char *SourceFile,char *RinexFile)
{
  int NumSats;
  int EpochNum,BadEpochNum;
  int flag;
  int IsFirstEpoch;

   struct time_type		  /* time (same as 'tm' type in time.h) */
   {
     short month;                /* 0-11 */
     short day;                  /* 1-31 */
     short year;                 /* year-1900 (eg. 92) */
     short hour;
     short min;
     short sec;
   } ;

   struct navstar_bin_file_type	  /* Header & structure for binary gpb files */
						   /* (202 bytes) */
   {
     short size;                 /* structure size in bytes */
     float version;              /* version number (see above) */
     char receiver;              /* receiver type (see above) */
     char max_channels;          /* maximum number of channels (for safety) */
     struct time_type time;                /* time of file open */
     float interval;             /* data interval in seconds */
     char extra1[64];
				 /* variables used by software */
     char fname[40];             /* file name */
     FILE *f;                    /* file pointer */
     short vbufsize;             /* size of file buffer (internal) */
     void *vbuf;                 /* pointer to vbuf (allocated in open) */
     char extra2[64];
  } Header;

  RinexEpochType  *RinexEpoch;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -