home *** CD-ROM | disk | FTP | other *** search
/ rtsi.com / 2014.01.www.rtsi.com.tar / www.rtsi.com / OS9 / OSK / TELECOM / OSKBox.lzh / MAILBOX / SAT / nasa.c < prev    next >
C/C++ Source or Header  |  1990-08-22  |  2KB  |  83 lines

  1.  
  2. /* nasa.c   convert file of NASA keplerians to AMSAT format
  3.  7/12/87  Robert W. Berger N3EMO            */
  4.  
  5. /* 11/30/88    v3.5    Incorporate Greg Troxel's fix for reading epoch
  6.             times with imbedded spaces        */
  7.  
  8. #include <stdio.h>
  9.  
  10. main()
  11. {   char SatName[100],line1[100],line2[100];
  12.     FILE *InFile,*OutFile;
  13.     int LineNum,SatNum,ElementSet,EpochRev;
  14.     double EpochDay,DecayRate,Inclination,RAAN,Eccentricity;
  15.     double ArgPerigee,MeanAnomaly,MeanMotion;
  16.     double EpochYear;
  17.  
  18.     if ((InFile = fopen("nasa.dat","r")) == 0)
  19.         {
  20.     printf("\"nasa.dat\" not found\n");
  21.     exit(-1);
  22.     }
  23.  
  24.     if ((OutFile = fopen("kepler.dat","w")) == 0)
  25.         {
  26.     printf("Can't write \"kepler.dat\"\n");
  27.     exit(-1);
  28.     }
  29.  
  30.  
  31.     while (fgets(SatName,100,InFile))
  32.     {
  33.     printf("%s",SatName);
  34.     fgets(line1,100,InFile);
  35.     fgets(line2,100,InFile);
  36.     
  37.         sscanf(line1,"%1d",&LineNum);
  38.       if (LineNum != 1)
  39.         {
  40.         printf("Line 1 not present for satellite %s",SatName);
  41.         exit(-1);
  42.         }
  43.         sscanf(line2,"%1d",&LineNum);
  44.       if (LineNum != 2)
  45.         {
  46.         printf("Line 2 not present for satellite %s",SatName);
  47.         exit(-1);
  48.         }
  49.  
  50.     sscanf(line1,"%*2c%5d%*10c%2lf%12lf%10lf%*21c%5d",
  51.         &SatNum,&EpochYear,&EpochDay,&DecayRate,&ElementSet);
  52.     EpochDay += EpochYear *1000;
  53.  
  54.     ElementSet /= 10;   /* strip off checksum */
  55.  
  56.     sscanf(line2,"%*8c%8lf%8lf%7lf%8lf%8lf%11lf%5d",
  57.        &Inclination,&RAAN,&Eccentricity,&ArgPerigee,&MeanAnomaly,
  58.        &MeanMotion,&EpochRev);
  59.     EpochRev /= 10;   /* strip off checksum */
  60.     Eccentricity *= 1E-7;
  61.  
  62.  
  63.     fprintf(OutFile,"Satellite: %s",SatName);
  64.     fprintf(OutFile,"Catalog number: %d\n",SatNum);
  65.     fprintf(OutFile,"Epoch time: %lf\n",EpochDay);
  66.     fprintf(OutFile,"Element set: %d\n",ElementSet);
  67.     fprintf(OutFile,"Inclination: %lf deg\n",Inclination);
  68.     fprintf(OutFile,"RA of node: %lf deg\n",RAAN);
  69.     fprintf(OutFile,"Eccentricity: %lf\n",Eccentricity);
  70.     fprintf(OutFile,"Arg of perigee: %lf deg\n",ArgPerigee);
  71.     fprintf(OutFile,"Mean anomaly: %lf deg\n",MeanAnomaly);
  72.     fprintf(OutFile,"Mean motion: %lf rev/day\n",MeanMotion);
  73.     fprintf(OutFile,"Decay rate: %le rev/day^2\n",DecayRate);
  74.     fprintf(OutFile,"Epoch rev: %d\n",EpochRev);
  75.     fprintf(OutFile,"\n");
  76.     }
  77.  
  78.     fclose(InFile);
  79.     fclose(OutFile);
  80.  
  81. }
  82.         
  83.