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

📄 rinexout.c

📁 这是一个GPS应用演示软件
💻 C
字号:
rinexout.c   /* RINEX数据格式形成子程序*/

#include "rinex.h"
#include "SV.h"
extern RinexObsHeaderType rinex_obs_header;
extern MeasType[9];
void findtext(char *s, char *r);
void GetYMDHMS(int weekno,double gpstow,
	       int *year,int *month,int *day,
	       int *hour,int *minute,double *second)
{ long  dayofw,h,m,s;
  double fsec;
  long  isecs;
  long  dayofy, yr, ttlday, mn;
  isecs   = gpstow;
  fsec    =  gpstow - isecs;
  dayofw  =  isecs / 86400;
  isecs   =  isecs - 86400 * dayofw;
  h       =  isecs / 3600;
  isecs   =  isecs - 3600 * h;
  m       =  isecs / 60;
  s       =  isecs - 60 * m +fsec;
  *hour=h;
  *minute=m;
  *second=s;
  ttlday  =  dayofw  + 7 * weekno;
  ttlday  -= 360;
  yr      =  1981;
  while (ttlday > 366)
  {  ttlday -= 365;
     if (yr % 4 == 0 && yr % 100 != 0 || yr % 400 == 0)
     ttlday -= 1;
     yr += 1;  }
  if (ttlday == 366)
  {  if (yr % 4 == 0 && yr % 100 != 0 || yr % 400 == 0)
    { *year   = yr;
      dayofy = 366 ; }
    else
    { *year   = yr + 1;
      dayofy = 1; } }
  else if (ttlday < 366)
  { *year   = yr;
    dayofy = ttlday; }
  for (mn=1; mn<=12; mn++)
  { if ((ttlday <= dinmth[mn]) && (ttlday > 0))
    { *day  =  ttlday;
      *month  =  mn;
      ttlday =  0; }
    else if (mn == 2)
    { if((*year) % 4 == 0 && (*year) % 100 != 0 ||  (*year)% 400 == 0)
      {	if (ttlday > 29) ttlday -= 29;
	else
	{ *day = 29;
	  *month = 2;
	  ttlday = 0;} }
      else    ttlday -= 28; }
    else    ttlday -= dinmth[mn];
    if(ttlday == 0)  break; }
  if(weekno == 0)  *year =0;}
void InitRinexObsHeader()
{ int i;
  char *CurDate;
  FILE *f;
  char t1[60],t2[60];
  if((f=fopen("header.obs","ra"))==NULL)
  { printf("cannot open header.obs file \n");
    exit(-1); }
  fgets(t1,200,f);    findtext(t1,t2);
  strcpy(rinex_obs_header.ObserverAgencyName,t2);
  fgets(t1,200,f);    findtext(t1,t2);
  strcpy(rinex_obs_header.MarkerName,t2);
  fgets(t1,200,f);    findtext(t1,t2);
  strcpy(rinex_obs_header.MarkerID,t2);
  fgets(t1,200,f);    findtext(t1,t2);
  strcpy(rinex_obs_header.ObserverName,t2);
  fgets(t1,200,f);    findtext(t1,t2);
  strcpy(rinex_obs_header.FileAgencyName,t2);
  fgets(t1,200,f);    findtext(t1,t2);
  strcpy(rinex_obs_header.ReceiverType,t2);
  fgets(t1,200,f);    findtext(t1,t2);
  strcpy(rinex_obs_header.AntennaID,t2);
  fgets(t1,200,f);    findtext(t1,t2);
  strcpy(rinex_obs_header.AntennaType,t2);
  fgets(t1,200,f);    findtext(t1,t2);
  rinex_obs_header.AntHeight=atof(t2);
  fgets(t1,200,f);    findtext(t1,t2);
  rinex_obs_header.AntEast=atof(t2);
  fgets(t1,200,f);    findtext(t1,t2);
  rinex_obs_header.AntWest=atof(t2);
  fgets(t1,200,f);    findtext(t1,t2);
  strcpy(rinex_obs_header.CommentStr,t2);
  strcpy(rinex_obs_header.FormatVersion,"1");
  strcpy(rinex_obs_header.FileTypeObsStr,"OBSERVATION DATA ");
  strcpy(rinex_obs_header.PositionSystem,"GPS");
  strcpy(rinex_obs_header.FileAbstractName," ");
  strcpy(rinex_obs_header.FileOpenDate,_strdate(CurDate));
  rinex_obs_header.AppX=0.0;  /* approx position xyz */
  rinex_obs_header.AppY=0.0;
  rinex_obs_header.AppZ=0.0;
  rinex_obs_header.WaveFract=1;  /* full wave */
  rinex_obs_header.SDFreq=0;   /* singal frequency */
  rinex_obs_header.MeasureTypeNum=0;
  for(i=0;i<9;i++)
  { MeasType[i]=0;
    rinex_obs_header.ObsType[i][0]=' ';
    rinex_obs_header.ObsType[i][1]=' '; }
  rinex_obs_header.MeasureInterval=0;
  rinex_obs_header.StartYear=0;
  rinex_obs_header.StartMonth=0;
  rinex_obs_header.StartDay=0;
  rinex_obs_header.StartHour=0;
  rinex_obs_header.StartMinute=0;
  rinex_obs_header.StartSecond=0.0;
  rinex_obs_header.EndYear=0;
  rinex_obs_header.EndMonth=0;
  rinex_obs_header.EndDay=0;
  rinex_obs_header.EndHour=0;
  rinex_obs_header.EndMinute=0;
  rinex_obs_header.EndSecond=0.0;
  fclose(f);}
/* find text after :     */
void findtext(char *s, char *r)
{ int i;
  char *p;
  p=s;
  while(*p!=':') p++;
  p++;
  while(*p!='\n') { *r=*p; r++,p++;};
  *r=NULL;}
void ResetRinexEpoch(RinexEpochType *Epoch)
{ int i;
  Epoch->year=0; Epoch->month=0; Epoch->day=0;
  Epoch->hour=0; Epoch->minute=0;
  Epoch->second=0.0;
  Epoch->flag=0; Epoch->satnum=0;
  for(i=0;i<MAXCHAN;i++) Epoch->PRN[i]=0;
  for(i=0;i<MAXCHAN;i++) Epoch->ca_range[i]=0;
  for(i=0;i<MAXCHAN;i++) Epoch->phase_l1[i]=0;
  for(i=0;i<MAXCHAN;i++) Epoch->doppler_l1[i]=0;
  for(i=0;i<MAXCHAN;i++) Epoch->P1_range[i]=0;
  for(i=0;i<MAXCHAN;i++) Epoch->P2_range[i]=0;
  for(i=0;i<MAXCHAN;i++) Epoch->phase_l2[i]=0;
  for(i=0;i<MAXCHAN;i++) Epoch->doppler_l2[i]=0;
  for(i=0;i<MAXCHAN;i++) Epoch->doppler_t1[i]=0;
  for(i=0;i<MAXCHAN;i++) Epoch->doppler_t2[i]=0;}
/**** 写RINEX观测文件字头 ****/
void WriteRinexObsHeaderFile(FILE *RinexRecFile, RinexObsHeaderType *h)
{ int i,index;
  fprintf(RinexRecFile,"%6s%14s%-20s%-20s%-20s\n",h->FormatVersion," ",
          h->FileTypeObsStr,h->PositionSystem, "RINEX VERSION / TYPE");
  fprintf(RinexRecFile,"%-20s%-20s%-20s%-20s\n",	h->FileAbstractName,
                     h->FileAgencyName,h->FileOpenDate, "PGM / RUN BY / DATE");
  fprintf(RinexRecFile,"%-60s%-20s\n",h->CommentStr, "COMMENT");
  fprintf(RinexRecFile,"%-60s%-20s\n",h->MarkerName, "MARKER NAME");
  fprintf(RinexRecFile,"%-60s%-20s\n",h->MarkerID, "MARKER NUMBER");
  fprintf(RinexRecFile, "%-20s%-40s%-20s\n",h->ObserverName,
                         h->ObserverAgencyName, "OBSERVER / AGENCY");
   fprintf(RinexRecFile, "%-20s%-20s%-20s%-20s\n", h->ReceiverID,
          h->ReceiverType,h->SoftVersion, "REC # / TYPE / VERS");
   fprintf(RinexRecFile, "%-20s%-20s%-20s%-20s\n",h->AntennaID,
          h->AntennaType," ","ANT # / TYPE");
   fprintf(RinexRecFile,"% 14.4f% 14.4f% 14.4f%18s%-20s\n",
			 h->AppX,h->AppY,h->AppZ," ","APPROX POSITION XYZ");
   fprintf(RinexRecFile,"% 14.4f% 14.4f% 14.4f%18s%-20s\n",
			h->AntHeight,h->AntEast,h->AntWest," ",
			"ANTENNA: DELTA H/E/N");
   fprintf(RinexRecFile,"%6i%6i%48s%-20s\n",h->WaveFract,h->SDFreq,
                      " ","WAVELENGTH FACT L1/2");
   for(i=0;i<9;i++) if(MeasType[i]!=0) h->MeasureTypeNum+=1;
   fprintf(RinexRecFile,"%6i",h->MeasureTypeNum);
   for(i=0;i<9;i++)
   { if(MeasType[i]!=0)  
    {  index=MeasType[i];
	   rinex_obs_header.ObsType[i][0]=ObsType[index-1][0];
	   rinex_obs_header.ObsType[i][1]=ObsType[index-1][1];  }  }
   for(i=0;i<9;i++)
   fprintf(RinexRecFile,"    %c%c",h->ObsType[i][0],h->ObsType[i][1]);
   fprintf(RinexRecFile,"%-20s\n","# / TYPES OF OBSERV");
   fprintf(RinexRecFile,"%6i%-54s%-20s\n",h->MeasureInterval," ","INTERVAL");
   fprintf(RinexRecFile,"%6i%6i%6i%6i%6i%12.6f%-18s%-20s\n",
			h->StartYear,h->StartMonth,h->StartDay,h->StartHour,
            h->StartMinute,h->StartSecond," ","TIME OF FIRST OBS");
   fprintf(RinexRecFile,"%6i%6i%6i%6i%6i%12.6f%-18s%-20s\n",	h->EndYear,
            h->EndMonth,h->EndDay,h->EndHour,h->EndMinute,h->EndSecond,
			" ","TIME OF LAST OBS");
   fprintf(RinexRecFile,"%60s%-20s\n"," ","END OF HEADER");}
void WriteRinexNavHeaderFile(FILE *RinexRecFile)
{  fprintf(RinexRecFile,"%6s%14s%-20s%-20s%-20s\n",
		       "1"," ","NAVIGATION DATA"," ","RINEX VERSION / TYPE");
  fprintf(RinexRecFile,"%-20s%-20s%-20s%-20s\n",			" "," "," ",
                  "PGM / RUN BY / DATE");
  fprintf(RinexRecFile,"%-60s%-20s\n"," ","END OF HEADER");}
void WriteRinexObsEpochFile(FILE *RinexRecFile,RinexEpochType *Epoch)
{  int i;
   if (Epoch->satnum!=0)
  { fprintf(RinexRecFile,"%3i%3i%3i%3i%3i%11.7f%3i%3i",Epoch->year,
              Epoch->month,Epoch->day,Epoch->hour,Epoch->minute,
              Epoch->second,Epoch->flag,Epoch->satnum);
    for(i=0;i<Epoch->satnum;i++)    fprintf(RinexRecFile," %2i",Epoch->PRN[i]);
fprintf(RinexRecFile,"\n");
for(i=0;i<Epoch->satnum;i++)
     fprintf(RinexRecFile,"%14.3f  %14.3f\n",Epoch->ca_range[i],
             Epoch->phase_l1[i]);}}
void ResetRinexEpp(SVText * Epp)
{  int i, size;
  char *p;
  p=Epp;
  for(i=0;i<sizeof(SVText);i++) *p=0;}
int WriteRinexNavFile( FILE *RinexRecFile ,SVText *snv)
{   int year,month,day,hour,minute;
   double second;
   GetYMDHMS(snv->wn,(double)snv->toc,&year,&month,&day,&hour,&minute,&second);
   fprintf(RinexRecFile,"%2i%3i%3i%3i%3i%3i%5.1f%19.11e%19.11e%19.11e\n",
		       snv->prn,(year-1900),month,day,
		       hour,minute,second,snv->af0,snv->af1,snv->af2);
   fprintf( RinexRecFile,"   %19.11e%19.11e%19.11e%19.11e\n",
     (double)snv->aode,snv->crs,snv->deltan,snv->m0);
   fprintf( RinexRecFile,"   %19.11e%19.11e%19.11e%19.11e\n",
     snv->cuc,snv->e,snv->cus,snv->roota);
   fprintf( RinexRecFile,"   %19.11e%19.11e%19.11e%19.11e\n",
     (double)snv->toe,snv->cic,snv->omega0,snv->cis);
   fprintf( RinexRecFile,"   %19.11e%19.11e%19.11e%19.11e\n",
     snv->i0,snv->crc,snv->omega,snv->omegadot);
   fprintf( RinexRecFile,"   %19.11e%19.11e%19.11e%19.11e\n",
     snv->idot,0.0,(double)snv->wn,0.0);
   fprintf( RinexRecFile,"   %19.11e%19.11e%19.11e%19.11e\n",
     0.0,0.0,snv->tgd,(double)snv->aodc);
     return(0);}
long GetWeekNo(int year,int month,int day,int *DayOfWeek)
{  int   dayofy, yr, ttlday, m, weekno;
  if (year < 1981 || month < 1 || month > 12 || day < 1 || day > 31)
     weekno = 0;
  if (month == 1)     dayofy = day;
  else
  { dayofy = 0;
    for (m=1; m<=(month-1); m++)
    { dayofy += dinmth[m];
      if ( m==2 )
      {	if (year%4 ==0 && year%100 != 0||year%400 == 0) dayofy += 1; } }
    dayofy += day; }
  ttlday = 360;
  for (yr=1981; yr<=(year-1); yr++)  
  { ttlday  += 365;
    if (yr % 4 == 0 && yr % 100 != 0 || yr % 400 ==0)   ttlday  += 1;  }
  ttlday += dayofy;
  weekno  = ttlday/7;
  *DayOfWeek  = ttlday - 7 * weekno;
  return(weekno);}
char readchar(char *p)
{  char r;
  return *p;}
int readint(char *p)
{  int i,j;
  char *ptr;
  ptr=&i;
  for(j=0;j<sizeof(int);j++) *(ptr+j)=p[j];
  return i;}
long readlong(char * p)
{  long l;
   int j;
   char *ptr;
   ptr=&l;
   for(j=0;j<sizeof(long);j++) *(ptr+j)=p[j];
   return l;}
   float readfloat(char * p)
  {  float f;
     int j;
     char *ptr;
     ptr=&f;
     for(j=0;j<sizeof(float);j++) *(ptr+j)=p[j];
     return f;}
double readdouble(char * p)
{  double d;
  int j;
  char *ptr;
  ptr=&d;
  for(j=0;j<sizeof(double);j++) *(ptr+j)=p[j];
  return d;}

⌨️ 快捷键说明

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