Esempio n. 1
0
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;
}
Esempio n. 2
0
int main(int argc,char *argv[])
{
  int imode,satno=0,arg,desigflag=0;
  FILE *file;
  orbit_t orb;
  xyz_t r,v;
  char tlefile[LIM],nfd[32];
  char line1[80],line2[80],desig[20];
  double mjd,epoch,ep_day,bstar;
  char *env;
  int ep_year;

  // Get environment variable
  env=getenv("ST_TLEDIR");
  sprintf(tlefile,"%s/classfd.tle",env);

  // Set date
  nfd_now(nfd);
  mjd=nfd2mjd(nfd);

  // Decode options
  while ((arg=getopt(argc,argv,"c:i:t:m:he:d:"))!=-1) {
    switch (arg) {

    case 't':
      strcpy(nfd,optarg);
      mjd=nfd2mjd(nfd);
      break;

    case 'e':
      epoch=(double) atof(optarg);
      ep_year=(int) floor(epoch/1000.0);
      ep_day=epoch-1000*ep_year;
      printf("%d %f\n",ep_year,ep_day);
      if (ep_year<50)
	ep_year+=2000;
      else
	ep_year+=1900;
      
      mjd=doy2mjd(ep_year,ep_day);
      break;

    case 'd':
      strcpy(desig,optarg);
      desigflag=1;
      break;
      
    case 'm':
      mjd=(double) atof(optarg);
      break;
      
    case 'c':
      strcpy(tlefile,optarg);
      break;

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

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

    default:
      usage();
      return 0;
    }
  }


  // Open file
  file=fopen(tlefile,"r");
  while (read_twoline(file,satno,&orb)==0) {
    format_tle(orb,line1,line2);
    //    printf("Input:\n%s\n%s\n",line1,line2);
    if (desigflag==0)
      strcpy(desig,orb.desig);
    bstar=orb.bstar;
    
    // Propagate
    imode=init_sgdp4(&orb);
    imode=satpos_xyz(mjd+2400000.5,&r,&v);
    
    // Convert
    orb=rv2el(orb.satno,mjd,r,v);

    // Copy back
    strcpy(orb.desig,desig);
    orb.bstar=bstar;

    format_tle(orb,line1,line2);
    printf("%s\n%s\n",line1,line2);
  }
  fclose(file);

  return 0;
}