home *** CD-ROM | disk | FTP | other *** search
/ rtsi.com / 2014.01.www.rtsi.com.tar / www.rtsi.com / OS9 / OSK / EFFO / forum16.lzh / SOFTWARE / C / ORBIT / nasa.c < prev    next >
C/C++ Source or Header  |  1990-03-24  |  2KB  |  82 lines

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