コード例 #1
0
ファイル: tleinfo.c プロジェクト: ppapadeas/sattools
int main(int argc,char *argv[])
{
  int arg=0,satno=0,header=0,oneline=0,no,name=0,desig=0;
  char tlefile[LIM];
  char line0[LIM],line1[LIM],line2[LIM],nfd[32];
  FILE *file;
  orbit_t orb;
  float aodp,perigee,apogee,period;
  int info=0;
  double mjd;
  char *env;

  env=getenv("ST_TLEDIR");
  sprintf(tlefile,"%s/bulk.tle",env);

  // Decode options
  while ((arg=getopt(argc,argv,"c:i:aH1ftnd"))!=-1) {
    switch (arg) {
      
    case 'c':
      strcpy(tlefile,optarg);
      break;

    case '1':
      oneline=1;
      break;

    case 'f':
      oneline=2;
      break;

    case 'n':
      name=1;
      break;

    case 'd':
      desig=1;
      break;

    case 'i':
      satno=atoi(optarg);
      break;

    case 'a':
      info=1;
      break;

    case 'H':
      header=1;
      break;

    case 'h':
      usage();
      return 0;
      break;

    default:
      usage();
      return 0;
    }
  }

  if (oneline==0) {
    // Open file
    file=fopen(tlefile,"rb");
    if (file==NULL) 
      fatal_error("File open failed for reading \"%s\"",tlefile);

    while (fgetline(file,line1,LIM)>0) {
      // Find TLE line
      if (line1[0]=='1') {
	fgetline(file,line2,LIM);
	sscanf(line1+2,"%d",&no);
	if (satno==0 || satno==no) {
	  if (name==1 && desig==0) 
	    printf("%s\n",line0);
	  else if (name==0 && desig==1)
	    printf("%.8s\n",line1+9);
	  else
	    printf("%s\n%s\n%s\n",line0,line1,line2);
	}
      }
      strcpy(line0,line1);
    }

    /*
    // Loop over file
    while (fgetline(file,line0,LIM)>0) {
      // Read data lines
      if (line0[0]!='1' || line0[0]!='2') {
	fgetline(file,line1,LIM);
	fgetline(file,line2,LIM);
	sscanf(line1+2,"%d",&no);

	if (satno==0 || satno==no) {
	  if (name==1 && desig==0) 
	    printf("%s\n",line0);
	  else if (name==0 && desig==1)
	    printf("%.8s\n",line1+9);
	  else
	    printf("%s\n%s\n%s\n",line0,line1,line2);
	}
      } else if (line0[0]=='1') {
	fgetline(file,line2,LIM);
	sscanf(line1+2,"%d",&no);

	if (satno==0 || satno==no)
	  printf("%s\n%s\n",line0,line2);
      }
    }
    */
    fclose(file);
  } else if (oneline==1) {
    // Open file
    file=fopen(tlefile,"rb");
    if (file==NULL) 
      fatal_error("File open failed for reading \"%s\"",tlefile);
    
    if (info==0 && header==1)
      printf("SATNO YEAR DOY     INCL    ASCN     ARGP     MA       ECC      MM\n");
    if (info==1 && header==1)
      printf("SATNO SEMI     PERIGEE  APOGEE    PERIOD  ECC\n");
    
    // Loop over file
    while (read_twoline(file,satno,&orb)==0) {
      orbit(orb,&aodp,&perigee,&apogee,&period);
      mjd=doy2mjd(orb.ep_year,orb.ep_day);
      mjd2nfd(mjd,nfd);
      if (info==0) printf("%05d %10.4lf %8.4f %8.4f %8.4f %8.4f %8.6f %8.5f\n",orb.satno,mjd,DEG(orb.eqinc),DEG(orb.ascn),DEG(orb.argp),DEG(orb.mnan),orb.ecc,orb.rev);
      if (info==1) printf("%05d %6.0f x %6.0f x %6.2f %8.2f %8.6f %14.8lf\n",orb.satno,perigee,apogee,DEG(orb.eqinc),period,orb.ecc,mjd);
    }
    fclose(file);
  } else if (oneline==2) {
    // Open file
    file=fopen(tlefile,"rb");
    if (file==NULL) 
      fatal_error("File open failed for reading \"%s\"",tlefile);
    
    if (info==0 && header==1)
      printf("SATNO YEAR DOY     INCL    ASCN     ARGP     MA       ECC      MM\n");
    if (info==1 && header==1)
      printf("SATNO SEMI     PERIGEE  APOGEE    PERIOD  ECC\n");
    
    // Loop over file
    while (read_twoline(file,satno,&orb)==0) 
      print_orb(&orb);
    fclose(file);
  }

  return 0;
}
コード例 #2
0
ファイル: test1.c プロジェクト: tsangiotis/upsat_spg4
int main(int argc, char *argv[])
{
orbit_t orb;
xyz_t pos, vel;
double jd, tsince;
long satno=0;
int imode;

char filename[ST_SIZE] = "twoline.txt";
FILE *fp=NULL;

char ctrl_name[ST_SIZE] = "ssd.txt";

long ii,imax=0,iend=0;

/* Data for the prediction type and time period */
double ts = 0.0, delta=0.0;    /* Time since TLE epoch to start predictions */
int bad=1;
int c;
time_t tnow;

	time(&tnow);
	fprintf(stderr, "# Start time = %s", ctime(&tnow));

    GETOPT(c, options)
        {
		case 'c': strncpy(ctrl_name, optarg, ST_SIZE-1); break;
        case 'i': strncpy(filename, optarg, ST_SIZE-1); break;
        case 's': satno = atol(optarg); break;
        case 'v': Verbose = atoi(optarg); break;

        default:
            fprintf(stderr, usage, argv[0]);
            exit(1);
            break;
        }

	if((fp=fopen(ctrl_name, "rb")) != NULL)
		{
		if(fscanf(fp, " %lf %lf %ld %ld %ld", &ts, &delta, &imax, &iend, &satno) == 5)
			{
			bad=0;
			}
		fclose(fp);
		}


	if(bad)
		{
		fprintf(stderr, "Failed to read ssd.txt file for 'tstart,delta,imax,isat'\n");
		return 1;
		}

	fp = fopen(filename, "rb");
    if(fp == NULL)
        {
        fatal_error("File open failed for reading \"%s\"", filename);
        }


    while(read_twoline(fp, satno, &orb) == 0)
        {
		print_orb(&orb);

		Isat = orb.satno;
		imode = init_sgdp4(&orb);

		switch(imode)
			{
			case SGDP4_ERROR     :  printf("# SGDP error\n"); break;
			case SGDP4_NOT_INIT  :  printf("# SGDP not init\n"); break;
			case SGDP4_ZERO_ECC  :  printf("# SGDP zero ecc\n"); break;
			case SGDP4_NEAR_SIMP :  printf("# SGP4 simple\n"); break;
			case SGDP4_NEAR_NORM :  printf("# SGP4 normal\n"); break;
			case SGDP4_DEEP_NORM :  printf("# SDP4 normal\n"); break;
			case SGDP4_DEEP_RESN :  printf("# SDP4 resonant\n"); break;
			case SGDP4_DEEP_SYNC :  printf("# SDP4 synchronous\n"); break;
			default: 				printf("# SGDP mode not recognised!\n");
			}

		if(imode == SGDP4_ERROR) continue;


		printf("# Satellite number\n");
		printf("%05ld\n", (long)orb.satno);

		printf("#     Tsince         X                Y                Z            Xdot             Ydot             Zdot\n");


		/* Run test like the original SGP doccument */
		for(ii=0; ii <= imax; ii++)
			{
			if(ii != iend)
				{
				tsince=ts + ii*delta;
				}
			else
				{
				tsince=ts + delta;
				}

			jd = SGDP4_jd0 + tsince / 1440.0;
			if(satpos_xyz(jd, &pos, &vel) == SGDP4_ERROR) break;

			printf("%12.4f   %16.8f %16.8f %16.8f %16.12f %16.12f %16.12f\n",
				tsince,
				pos.x, pos.y, pos.z,
				vel.x, vel.y, vel.z);
			}
        }

	time(&tnow);
	fprintf(stderr, "# End time = %s", ctime(&tnow));

exit(0);
return 0;
}