Esempio n. 1
0
// Read tle
orbit_t read_tle(char *filename,int satno)
{
  int i;
  FILE *file;
  orbit_t orb;

  file=fopen(filename,"r");
  if (file==NULL) 
    fatal_error("Failed to open %s\n",filename);

  // Read TLE
  read_twoline(file,satno,&orb);
  fclose(file);

  return orb;
}
Esempio n. 2
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. 3
0
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;
}
Esempio n. 4
0
int main(int argc,char *argv[])
{
  int imode,satno=0,arg,usecatalog=0,satnomin,flag=0;
  FILE *file;
  orbit_t orb;
  xyz_t r,v,n,m,nm,r0,v0,mr,mv;
  char tlefile[LIM],catalog[LIM],nfd[32];
  char line1[80],line2[80],desig[20];
  double mjd,ra,de,dr,drmin,dmr,dmv;
  char *env;

  // 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:c:i:t:m:h"))!=-1) {
    switch (arg) {

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

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

    case 'C':
      strcpy(catalog,optarg);
      usecatalog=1;
      break;

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

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

    default:
      usage();
      return 0;
    }
  }

  // Reloop stderr
  freopen("/tmp/stderr.txt","w",stderr);

  // Open file
  file=fopen(tlefile,"r");
  while (read_twoline(file,satno,&orb)==0) {
    format_tle(orb,line1,line2);

    // Propagate
    imode=init_sgdp4(&orb);
    imode=satpos_xyz(mjd+2400000.5,&r0,&v0);
    
    // Compute normal
    n=cross(r0,v0);
    ra=modulo(atan2(n.y,n.x)*R2D,360.0);
    de=asin(n.z/magnitude(n))*R2D;

    if (usecatalog==0)
      printf("%05d %14.8lf %10.6f %10.6f %10.2f %10.2f %10.2f %10.2f\n",orb.satno,mjd,ra,de,magnitude(n),n.x,n.y,n.z);

  }
  fclose(file);

  // Match against a catalog
  if (usecatalog==1) {
    // Open file
    file=fopen(catalog,"r");
    while (read_twoline(file,0,&orb)==0) {
      format_tle(orb,line1,line2);

      // Propagate
      imode=init_sgdp4(&orb);
      imode=satpos_xyz(mjd+2400000.5,&r,&v);
      
      
      // Compute normal
      m=cross(r,v);

      // Normal difference
      nm.x=n.x-m.x;
      nm.y=n.y-m.y;
      nm.z=n.z-m.z;
      dr=magnitude(nm);

      // Position/velocity difference
      mr.x=r0.x-r.x;
      mr.y=r0.y-r.y;
      mr.z=r0.z-r.z;
      mv.x=v0.x-v.x;
      mv.y=v0.y-v.y;
      mv.z=v0.z-v.z;
      
      if (flag==0 || dr<drmin) {
	drmin=dr;
	dmr=magnitude(mr);
	dmv=magnitude(mv);
	satnomin=orb.satno;
	flag=1;
      } 
    }
    printf("%05d %05d %8.2f km %8.2f km %10.6f km/s\n",satno,satnomin,drmin,dmr,dmv);
  }

  return 0;
}
Esempio n. 5
0
int main(int argc,char *argv[])
{
  int imode,arg,satno=0,useepoch=0,format=0,gmat=0;
  FILE *file;
  char *env;
  char tlefile[LIM],nfd[32];
  double mjd;
  xyz_t r,v;
  orbit_t orb;
  double rr[3],vv[3],e[3][3],et[3][3];

  // 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:hejg"))!=-1) {
    switch (arg) {

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

    case 'e':
      useepoch=1;
      break;

    case 'j':
      format=1;
      break;

    case 'g':
      gmat=1;
      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) {
    // Propagate
    imode=init_sgdp4(&orb);

    // Use epoch instead of user supplied date
    if (useepoch==1)
      mjd=SGDP4_jd0-2400000.5;

    // Compute position and velocity
    imode=satpos_xyz(mjd+2400000.5,&r,&v);

    // Output
    if (format==0 && gmat==0)
      printf("%05d %14.8lf %f %f %f %f %f %f TEME\n",orb.satno,mjd,r.x,r.y,r.z,v.x,v.y,v.z);

    // To vectors
    rr[0]=r.x;
    rr[1]=r.y;
    rr[2]=r.z;
    vv[0]=v.x;
    vv[1]=v.y;
    vv[2]=v.z;

    // Matrices
    icrs_to_teme(mjd,e);
    matrix_transpose(e,et);

    // Transform
    vector_multiply_in_place(et,rr);
    vector_multiply_in_place(et,vv);
    
    // Output J2000
    if (format==1 && gmat==0)
      printf("%05d %14.8lf %f %f %f %f %f %f J2000\n",orb.satno,mjd,rr[0],rr[1],rr[2],vv[0],vv[1],vv[2]);

    // GMAT output
    if (gmat==1) {
      printf("UTCModJulian = %14.8lf\n",mjd-29999.5);
      printf("CoordinateSystem = EarthMJ2000Eq\n");
      printf("X = %lf\n",rr[0]);
      printf("Y = %lf\n",rr[1]);
      printf("Z = %lf\n",rr[2]);
      printf("VX = %lf\n",vv[0]);
      printf("VY = %lf\n",vv[1]);
      printf("VZ = %lf\n",vv[2]);
    }
  }
  fclose(file);

  return 0;
}
Esempio n. 6
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;
}