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

📄 ef18_sp3.c

📁 使用C语言编写的计算GPS卫星在任意时刻的三维速度的程序
💻 C
📖 第 1 页 / 共 3 页
字号:
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*//*                                                                         *//*                               EF18_SP3                                  *//*                               ========                                  *//*                                                                         *//*  This program converts GPS orbit data from a 18-byte EF18 BINARY direct *//*  access file format to a 60_byte SP3 ASCII position file format for any *//*  specified interval from 1 microsecond to whatever.  Various program    *//*  functions and part of the program structure has been taken from        *//*  Ben Remondi's ECF2_SP2.C program.                                      *//*                                                                         *//*  REFERENCE:   NOAA Technical Report NOS 133 NGS 46                      *//*               Extending the NGS Standard GPS Orbit Formats              *//*               Benjamin W. Remondi                                       *//*               Rockville, MD                                             *//*               November 1989                                             *//*                                                                         *//*               NGS Second generation ASCII and binary orbit              *//*               formats and associated interpolation studies              *//*               Benjamin W. Remondi                                       *//*               Rockville, MD                                             *//*               August 1991                                               *//*                                                                         *//*               U.S. Department of Commerce                               *//*               National Oceanic and Atmospheric Administration           *//*               National Ocean Service                                    *//*                                                                         *//* PROGRAMMERS:  Benjamin W. Remondi                                       *//*               Rockwall I, Room 315                                      *//*               11400 Rockville Pike                                      *//*               Rockville, MD  20852                                      *//*               443-8171, 443-5959                                        *//*                                                                         *//*  DATE:        June 1, 1990                                              *//*                                                                         *//*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/#include <stdlib.h>#include <stdio.h>#include <ctype.h>#include <string.h>#include <math.h>#include <time.h>#include <dir.h>#include <dos.h>/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/#define TRUE 1#define FALSE 0#define SW_VERSION "1.1.0b"#define WS_RELEASED "05/20/94"#define INFO_DELAY 1000/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/#define LU_ELBOW   201#define RU_ELBOW   187#define LL_ELBOW   200#define RL_ELBOW   188#define VERTICAL   186#define HORIZONTAL 205#define TEX_WDTH 76/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/FILE *fpsp3, *fpef18;/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/static char config_fname[100];static int dflt_menu_clrs = TRUE;char prog_name[MAXFILE];/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/struct run_time { char    idsv[85];                  char    SV_acc[85];                  long    gpswk_strt,     gpswk_end,                          mjd_strt,       mjd_end;                  double  secofwk_strt,   secofwk_end,                          fmjd_strt,      fmjd_end;                  long    yr_strt,        yr_end,                          month_strt,     month_end,                          mday_strt,      mday_end,                          hr_strt,        hr_end,                          min_strt,       min_end;                  double  sec_strt,       sec_end,                          time_span,      delta_t;                  long    num_epochs;                  int     num_prns;                  char    pva;                } run;/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/static struct header_lines       { int    year;         char   month, day, hour, minute;         double second;         long   nepoch;         char   data_used[5], coordsys[5], orb_type[3];         char   agency[4], version;         int    GPS_week_strt;         double second_of_week, epoch_interval;         long   mjd_strt;         double fmjd_strt;         char   number_of_SVs, pva, spareB[4];         char   idsv[85], spareC[5];         char   SV_acc[85], spareD[5];         char   ca[2], cb[2], cc[3], cd[3], ce[4], cf[4], cg[4], ch[4],                ci[5], cj[5], ck[5], cl[5], spareE[8];         char   cm[2], cn[2], co[3], cp[3], cq[4], cr[4], cs[4], ct[4],                cu[5], cv[5], cw[5], cx[5], spareF[8];         double fa, fb;         char   spareG[2];         double fc, fd;         char   spareH[2];         double fe, ff;         char   spareI[2];         double fg, fh;         char   spareJ[2];         int    ia2;         long   ib4, ic4, id4, ie4, if4, ig4, ih4, ii4;         char   spareK[2];         int    ij2;         long   ik4, il4, im4, in4, io4, ip4, iq4, ir4;         char   spareL[2];         char   line29[18], line30[18], line31[18], line32[3],                spareM[15], line33[18], line34[18], line35[18], line36[3],                spareN[15], line37[18], line38[18], line39[18], line40[3],                spareO[15], line41[18], line42[18], line43[18], line44[3],                spareP[15];       } ef18_hdr;/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/static struct xyz_lines       { char xyz_good_or_bad, clock_good_or_bad;         long x, y, z, clock;       } ef18;/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/static char sp3_line[82];int    dummy;/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/void main (int argc, char *argv[]){{   void extract_args (char *fname, int argc, char *argv[]);   void user_entry(void);   void open_sp3_and_ef18_files_and_read(void);   void change_ef18_headr_lines_to_sp3(void);   void change_ef18_epoch_lines_to_sp3(void);   long tim;   extract_args (config_fname, argc, argv);   system(" cls ");   open_sp3_and_ef18_files_and_read();   user_entry();   tim = time(0);   change_ef18_headr_lines_to_sp3();   change_ef18_epoch_lines_to_sp3();   printf("\nTime: %ld seconds\n", time(0) - tim);   fprintf(fpsp3, "%.3s\n", "EOF");}}/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/void user_entry(void){    void ymdhms_to_gps(long, long, long, long, long, double, long *, double *);    void gps_to_mjd(long, double, long *, double *);    short verify_and_add_acc(long, char);    long ii, jj;    short svexists;    printf("Enter ephemeris start: yyyy mm dd hh mm ss.sssssss\n");    scanf("%ld %ld %ld %ld %ld %lf", &run.yr_strt, &run.month_strt,            &run.mday_strt, &run.hr_strt, &run.min_strt, &run.sec_strt );    printf("Enter ephemeris end:   yyyy mm dd hh mm ss.sssssss\n");    scanf("%ld %ld %ld %ld %ld %lf", &run.yr_end, &run.month_end,            &run.mday_end, &run.hr_end, &run.min_end, &run.sec_end );    /* Compute time span*/    ymdhms_to_gps(run.yr_strt, run.month_strt, run.mday_strt, run.hr_strt,               run.min_strt, run.sec_strt, &run.gpswk_strt, &run.secofwk_strt);    gps_to_mjd(run.gpswk_strt, run.secofwk_strt, &run.mjd_strt,                &run.fmjd_strt);    if( fabs(run.fmjd_strt - 1.00) < 1.0e-12 )    { 
		run.mjd_strt++;        run.fmjd_strt = 0.0;    }    ymdhms_to_gps(run.yr_end, run.month_end, run.mday_end, run.hr_end,                   run.min_end, run.sec_end, &run.gpswk_end, &run.secofwk_end);    gps_to_mjd(run.gpswk_end, run.secofwk_end, &run.mjd_end, &run.fmjd_end);    run.time_span = ((run.mjd_end-run.mjd_strt) + (run.fmjd_end-run.fmjd_strt)) * 86400.0;    printf("time_span (seconds): %lf\n", run.time_span);    printf("Enter epoch interval in seconds.\n");    scanf("%lf", &run.delta_t);    if(run.delta_t <= 0.0)    {
		printf("The epoch interval must be positive.\n");        printf("Please run program again.\n");        exit(0);
	}    run.num_epochs = run.time_span/run.delta_t + 1.5;//??????    printf("number of epochs requested: %ld\n", run.num_epochs);    if(run.time_span < 0.0 || run.num_epochs > 14999)    {
		printf("Program requires start_t<=end_t and total epochs < 15000\n");        printf("Please run program again.\n");        exit(0);
	}    printf("Enter the number of PRNs desired.  Enter -1 for all available\n");    scanf("%d", &run.num_prns);    for(ii=0; ii<85; ii++)     {
		run.idsv[ii]   = 0;
		run.SV_acc[ii] = 0;    }    if(run.num_prns == -1)//所有卫星    {        	 run.num_prns = 0;         for(ii=0; ii<85; ii++)         if(ef18_hdr.idsv[ii] != 0)          {              run.idsv[run.num_prns] 		= ef18_hdr.idsv[ii];              run.SV_acc[run.num_prns++]	= ef18_hdr.SV_acc[ii];         }    }    else    {        	 ENTER_PRNS_AGAIN:;         if(run.num_prns < 0 || run.num_prns > 85)         {
			 printf("Unreasonable number of PRNs requested; please repeat.\n");             goto ENTER_PRNS_AGAIN;         }         for(ii=0; ii<run.num_prns; ii++)         {             	if(run.num_prns == 1)                 { printf("Enter the lone PRN number.\n");                   scanf("%d", &run.idsv[ii] );                   svexists = verify_and_add_acc(ii, run.idsv[ii]);                   if(svexists) {ii--; continue;}                   break;                 }              if(ii == 0) printf("Enter the first PRN number.\n");              if(ii != 0 && ii != run.num_prns-1)                 printf("Enter the next PRN number.\n");              if(ii == run.num_prns-1) printf("Enter the last PRN number.\n");              scanf("%d", &run.idsv[ii] );              svexists = verify_and_add_acc(ii, run.idsv[ii]);              if(svexists) {ii--; continue;}         }    }printf("Would you like pos/clock (p) mode or pos/clock-vel/frequency (v) mode?\n");/*scanf("%c", &run.pva);if(run.pva != 'P' && run.pva != 'V')scanf("%c", &run.pva);run.pva = toupper(run.pva);*/run.pva = toupper(getch());printf("You have selected %c mode.\n", run.pva);}  /*  End of function "user_entry"  *//*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/short verify_and_add_acc(long ii, char prn){short jj, good_prn=-99;for(jj=0; jj<ef18_hdr.number_of_SVs; jj++) {   if(prn==ef18_hdr.idsv[jj]) good_prn = jj;}if(good_prn>=0) run.SV_acc[ii] = ef18_hdr.SV_acc[good_prn];else {  printf("This prn is unavailable\n");  return(1);}return(0);   }/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/void open_sp3_and_ef18_files_and_read(void){/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*//*                Function OPEN_SP3_AND_EF18_FILES_AND_READ                *//*                                                                         *//*  opens files "SP3ASCII" and "EF18BIN", prints out warning messages to   *//*  the crt screen, checks for an error in opening the two files, reads    *//*  the header lines (first 44 lines) of file EF18BIN, and prints out the  *//*  date and time tag, as well as other pieces of information from the     *//*  header data to the CRT screen.                                         *//*                                                                         *//*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/void compute_end_time(long *, long *, long *, long *, long *, double *);    long yr_end, mon_end, mday_end, hr_end, min_end;    double sec_end;    register int ii;/*  printf("The input BINARY EF18 filename must be \"EF18BIN\".\n"); */    if( (fpef18 = fopen("EF18BIN", "rb")) == NULL )       printf("Problem opening EF18BIN.\n");    fread(&ef18_hdr, sizeof(ef18_hdr), 1, fpef18);    compute_end_time(&yr_end, &mon_end, &mday_end, &hr_end, &min_end, &sec_end);    printf("\nEphemeris start   : %4d/%02d/%02d  %02d:%02d:%011.8lf\n",            ef18_hdr.year, ef18_hdr.month, ef18_hdr.day,            ef18_hdr.hour, ef18_hdr.minute, ef18_hdr.second);    printf("Ephemeris end     : %4ld/%02ld/%02ld  %02ld:%02ld:%011.8lf\n",            yr_end, mon_end, mday_end, hr_end, min_end, sec_end);    printf("\nDeltat          : %15.7lf\n", ef18_hdr.epoch_interval);    printf("Start Mjd, Fmjd   : %6ld %15.14lf\n", ef18_hdr.mjd_strt, ef18_hdr.fmjd_strt);//  printf("Fmjd_start        : %15.14lf\n", ef18_hdr.fmjd_strt);*/    printf("Start Week Seconds: %6d %17.7lf\n", ef18_hdr.GPS_week_strt, ef18_hdr.second_of_week);//  printf("GPS_seconds_of_wk : %17.7lf\n", ef18_hdr.second_of_week); */    printf("Number_of_epochs  : %6ld\n", ef18_hdr.nepoch);    printf("Number_of_prns    : %6d\n", ef18_hdr.number_of_SVs);    printf("Type              : %.3s\n", ef18_hdr.orb_type);    printf("Agency            : %.4s\n", ef18_hdr.agency);    printf("Position/Velocity : %c\n", ef18_hdr.pva);    printf("PRN ID's:\n");    for(ii=0; ii<37; ii++) printf("%2d", ef18_hdr.idsv[ii]);    putchar('\n');    for(ii=37; ii<74; ii++) printf("%2d", ef18_hdr.idsv[ii]);    putchar('\n');    for(ii=74; ii<85; ii++) printf("%2d", ef18_hdr.idsv[ii]);    putchar('\n');   printf("\nThe output ASCII SP3 filename will be \"SP3ASCII\".\n");   printf("An existing \"SP3ASCII\" file will be destroyed if you continue.\n");   printf("Would you like to continue?\n");   if( tolower(getch()) != 'y' ) exit(0);   if( (fpsp3 = fopen("SP3ASCII", "wt")) == NULL )      printf("Problem opening SP3ASCII.\n");}/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/void change_ef18_headr_lines_to_sp3(void){   register int i, j, k, ii;   char idsv_hold[3], accuracy_hold[3];   /*  PRINT HEADER LINE 1 TO SP3ASCII FILE  */   /*++++++++++++++++++++++++++++++++++++++++*//*   fprintf(fpsp3, "#%c %4d%3d%3d%3d%3d%12.8lf%8ld %.5s %.5s %.3s %.4s\n",            ef18_hdr.version, ef18_hdr.year, ef18_hdr.month,            ef18_hdr.day, ef18_hdr.hour, ef18_hdr.minute, ef18_hdr.second,            ef18_hdr.nepoch, ef18_hdr.data_used, ef18_hdr.coordsys,            ef18_hdr.orb_type, ef18_hdr.agency);*/   fprintf(fpsp3,             "#%c%c%4ld %2ld %2ld %2ld %2ld %11.8lf %7ld ",            ef18_hdr.version, run.pva, run.yr_strt, run.month_strt,            run.mday_strt, run.hr_strt, run.min_strt, run.sec_strt,            run.num_epochs);            for(ii=0; ii<5; ii++) fprintf(fpsp3, "%c", ef18_hdr.data_used[ii] );            fprintf(fpsp3, " ");            for(ii=0; ii<5; ii++) fprintf(fpsp3, "%c", ef18_hdr.coordsys[ii] );            fprintf(fpsp3, " ");            for(ii=0; ii<3; ii++) fprintf(fpsp3, "%c", ef18_hdr.orb_type[ii] );            fprintf(fpsp3, " ");            for(ii=0; ii<4; ii++) fprintf(fpsp3, "%c", ef18_hdr.agency[ii] );            fprintf(fpsp3, "\n");   /*  PRINT HEADER LINE 2 TO SP3ASCII FILE  */   /*++++++++++++++++++++++++++++++++++++++++*/

⌨️ 快捷键说明

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