Пример #1
0
int main(void)
{     int jbeg, jend, j, d, m, y;
      jbeg = jday(1, 1, 1);
      jend = jday(31, 12, 4000);
      for (j = jbeg; j <= jend; j++)
      {  xassert(jdate(j, &d, &m, &y) == 0);
         xassert(jday(d, m, y) == j);
      }
      xprintf("Routines jday and jdate work correctly.\n");
      return 0;
}
Пример #2
0
/*------------------------------------------------------------------------*/
  void fill_one_event (EVENT *ev, char *buff )
/*------------------------------------------------------------------------*/
{

  sscanf(&(buff[0]),"%4d", &(ev->yy) );
  sscanf(&(buff[5]),"%2d", &(ev->mm) );
  sscanf(&(buff[8]),"%2d", &(ev->dd) );
  //sscanf(&(buff[11]),"%2d", &(ev->h) );
  //sscanf(&(buff[13]),"%2d", &(ev->m) );
  //sscanf(&(buff[15]),"%2d", &(ev->s) );

  //  sscanf(&(buff[20]),"%2d", &(ev->ms) );
  //ev->ms = 10.*ev->ms;

  ev->h  = 0;
  ev->m  = 0;
  ev->ms = 0;


  printf("ev->yy %d, ev->mm %d,ev->dd %d, ev->h %d, ev->m %d, ev->s %d, ev->ms %d\n",
	  ev->yy,    ev->mm,   ev->dd,    ev->h,    ev->m,    ev->s,     ev->ms);



  ev->jday = jday( ev->yy, ev->mm, ev->dd );

  ev->t0 = abs_time (ev->yy, ev->jday, ev->h, ev->m, ev->s, ev->ms );
  sprintf(ev->name,"%d_%d_%d_%d_%d_%d",ev->yy, ev->mm, ev->dd, ev->h, ev->m, ev->s );
  printf(" ev->t0 %f\n",ev->t0);
  system(str);
}
Пример #3
0
void twoline2rv
     (
      char      longstr1[130], char longstr2[130],
      char      typerun,  char typeinput, char opsmode,
      gravconsttype       whichconst,
      double& startmfe, double& stopmfe, double& deltamin,
      sgp4struct &satrec
     )
     {
       const double deg2rad  =   pi / 180.0;         //   0.0174532925199433
       const double xpdotp   =  1440.0 / (2.0 * pi); // 229.1831180523293

       double sec, mu, radiusearthkm, tumin, xke, j2, j3, j4, j3oj2;
       double startsec, stopsec, startdayofyr, stopdayofyr, jdstart, jdstop;
       int startyear, stopyear, startmon, stopmon, startday, stopday,
           starthr, stophr, startmin, stopmin;
       int cardnumb, numb, j;
       long revnum = 0, elnum = 0;
       char classification, intldesg[11];
       int year = 0;
       int mon, day, hr, minute, nexp, ibexp;

       getgravconst( whichconst, tumin, mu, radiusearthkm, xke, j2, j3, j4, j3oj2 );

       satrec.error = 0;

       // set the implied decimal points since doing a formated read
       // fixes for bad input data values (missing, ...)
       for (j = 10; j <= 15; j++)
           if (longstr1[j] == ' ')
               longstr1[j] = '_';

       if (longstr1[44] != ' ')
           longstr1[43] = longstr1[44];
       longstr1[44] = '.';
       if (longstr1[7] == ' ')
           longstr1[7] = 'U';
       if (longstr1[9] == ' ')
           longstr1[9] = '.';
       for (j = 45; j <= 49; j++)
           if (longstr1[j] == ' ')
               longstr1[j] = '0';
       if (longstr1[51] == ' ')
           longstr1[51] = '0';
       if (longstr1[53] != ' ')
           longstr1[52] = longstr1[53];
       longstr1[53] = '.';
       longstr2[25] = '.';
       for (j = 26; j <= 32; j++)
           if (longstr2[j] == ' ')
               longstr2[j] = '0';
       if (longstr1[62] == ' ')
           longstr1[62] = '0';
       if (longstr1[68] == ' ')
           longstr1[68] = '0';

       sscanf(longstr1,"%2d %5ld %1c %10s %2d %12lf %11lf %7lf %2d %7lf %2d %2d %6ld ",
                       &cardnumb,&satrec.noradNum,&classification, intldesg, &satrec.epochyr,
                       &satrec.epochdays,&satrec.ndot, &satrec.nddot, &nexp, &satrec.bstar,
                       &ibexp, &numb, &elnum );

       if (typerun == 'v')  // run for specified times from the file
         {
           if (longstr2[52] == ' ')
               sscanf(longstr2,"%2d %5ld %9lf %9lf %8lf %9lf %9lf %10lf %6ld %lf %lf %lf \n",
                       &cardnumb,&satrec.noradNum, &satrec.inclination,
                       &satrec.rightAscNode,&satrec.eccentricity, &satrec.argpo, &satrec.meanAnomaly, &satrec.meanMotion,
                       &revnum, &startmfe, &stopmfe, &deltamin );
             else
               sscanf(longstr2,"%2d %5ld %9lf %9lf %8lf %9lf %9lf %11lf %6ld %lf %lf %lf \n",
                       &cardnumb,&satrec.noradNum, &satrec.inclination,
                       &satrec.rightAscNode,&satrec.eccentricity, &satrec.argpo, &satrec.meanAnomaly, &satrec.meanMotion,
                       &revnum, &startmfe, &stopmfe, &deltamin );
         }
         else  // simply run -1 day to +1 day or user input times
         {
           if (longstr2[52] == ' ')
               sscanf(longstr2,"%2d %5ld %9lf %9lf %8lf %9lf %9lf %10lf %6ld \n",
                       &cardnumb,&satrec.noradNum, &satrec.inclination,
                       &satrec.rightAscNode,&satrec.eccentricity, &satrec.argpo, &satrec.meanAnomaly, &satrec.meanMotion,
                       &revnum );
             else
               sscanf(longstr2,"%2d %5ld %9lf %9lf %8lf %9lf %9lf %11lf %6ld \n",
                       &cardnumb,&satrec.noradNum, &satrec.inclination,
                       &satrec.rightAscNode,&satrec.eccentricity, &satrec.argpo, &satrec.meanAnomaly, &satrec.meanMotion,
                       &revnum );
         }

       // ---- find no, ndot, nddot ----
       satrec.meanMotionRad   = satrec.meanMotion / xpdotp; //* rad/min
       satrec.nddot= satrec.nddot * pow(10.0, nexp);
       satrec.bstar= satrec.bstar * pow(10.0, ibexp);

       // ---- convert to sgp4 units ----
       satrec.a    = pow( satrec.meanMotionRad*tumin , (-2.0/3.0) );
       satrec.ndot = satrec.ndot  / (xpdotp*1440.0);  //* ? * minperday
       satrec.nddot= satrec.nddot / (xpdotp*1440.0*1440);

       // ---- find standard orbital elements ----
       satrec.inclination = satrec.inclination  * deg2rad;
       satrec.rightAscNode = satrec.rightAscNode  * deg2rad;
       satrec.argpo = satrec.argpo  * deg2rad;
       satrec.meanAnomaly    = satrec.meanAnomaly     * deg2rad;

       satrec.alta = satrec.a*(1.0 + satrec.eccentricity) - 1.0;
       satrec.altp = satrec.a*(1.0 - satrec.eccentricity) - 1.0;

       // ----------------------------------------------------------------
       // find sgp4epoch time of element set
       // remember that sgp4 uses units of days from 0 jan 1950 (sgp4epoch)
       // and minutes from the epoch (time)
       // ----------------------------------------------------------------

       // ---------------- temp fix for years from 1957-2056 -------------------
       // --------- correct fix will occur when year is 4-digit in tle ---------
       if (satrec.epochyr < 57)
           year= satrec.epochyr + 2000;
         else
           year= satrec.epochyr + 1900;

       days2mdhms ( year,satrec.epochdays, mon,day,hr,minute,sec );
       jday( year,mon,day,hr,minute,sec, satrec.jdsatepoch );

       // ---- input start stop times manually
       if ((typerun != 'v') && (typerun != 'c'))
         {
         // ------------- enter start/stop ymd hms values --------------------
           if (typeinput == 'e')
             {
               printf("input start prop year mon day hr min sec \n");
               // make sure there is no space at the end of the format specifiers in scanf!
               scanf( "%i %i %i %i %i %lf",&startyear, &startmon, &startday, &starthr, &startmin, &startsec);
               fflush(stdin);
               jday( startyear,startmon,startday,starthr,startmin,startsec, jdstart );

               printf("input stop prop year mon day hr min sec \n");
               scanf( "%i %i %i %i %i %lf",&stopyear, &stopmon, &stopday, &stophr, &stopmin, &stopsec);
               fflush(stdin);
               jday( stopyear,stopmon,stopday,stophr,stopmin,stopsec, jdstop );

               startmfe = (jdstart - satrec.jdsatepoch) * 1440.0;
               stopmfe  = (jdstop - satrec.jdsatepoch) * 1440.0;

               printf("input time step in minutes \n");
               scanf( "%lf",&deltamin );
             }
           // -------- enter start/stop year and days of year values -----------
           if (typeinput == 'd')
             {
               printf("input start year dayofyr \n");
               scanf( "%i %lf",&startyear, &startdayofyr );
               printf("input stop year dayofyr \n");
               scanf( "%i %lf",&stopyear, &stopdayofyr );

               days2mdhms ( startyear,startdayofyr, mon,day,hr,minute,sec );
               jday( startyear,mon,day,hr,minute,sec, jdstart );
               days2mdhms ( stopyear,stopdayofyr, mon,day,hr,minute,sec );
               jday( stopyear,mon,day,hr,minute,sec, jdstop );

               startmfe = (jdstart - satrec.jdsatepoch) * 1440.0;
               stopmfe  = (jdstop - satrec.jdsatepoch) * 1440.0;

               printf("input time step in minutes \n");
               scanf( "%lf",&deltamin );
             }
           // ------------------ enter start/stop mfe values -------------------
           if (typeinput == 'm')
             {
               printf("input start min from epoch \n");
               scanf( "%lf",&startmfe );
               printf("input stop min from epoch \n");
               scanf( "%lf",&stopmfe );
               printf("input time step in minutes \n");
               scanf( "%lf",&deltamin );
             }
         }

       // ------------ perform complete catalog evaluation, -+ 1 day ----------- 
       if (typerun == 'c')
         {
           startmfe = -1440.0;
           stopmfe  =  1440.0;
           deltamin =    10.0;
         }

       // ---------------- initialize the orbit at sgp4epoch -------------------
       sgp4init( whichconst, opsmode, satrec.noradNum, satrec.jdsatepoch-2433281.5,
               satrec.bstar, satrec.eccentricity, satrec.argpo, satrec.inclination,
               satrec.meanAnomaly, satrec.meanMotionRad, satrec.rightAscNode, satrec);
    } // end twoline2rv
Пример #4
0
/////////////////////////////////////////////////////////////////////////////
// Initialize()
// Initialize the string array.
void QTle::Initialize()
{
   const double deg2rad  =   PI / 180.0;         //   0.0174532925199433
   const double xpdotp   =  1440.0 / (2.0 * PI);  // 229.1831180523293
   int year, mon, day, hr, minute;
   double sec;


   assert(!m_strName.isEmpty());
   assert(!m_strLine1.isEmpty());
   assert(!m_strLine2.isEmpty());
   

   m_Field[FLD_NORADNUM] = m_strLine1.mid(TLE1_COL_SATNUM, TLE1_LEN_SATNUM);
   m_Field[FLD_INTLDESC] = m_strLine1.mid(TLE1_COL_INTLDESC_A,
                                             TLE1_LEN_INTLDESC_A +
                                             TLE1_LEN_INTLDESC_B +   
                                             TLE1_LEN_INTLDESC_C);   
   m_Field[FLD_EPOCHYEAR] = 
         m_strLine1.mid(TLE1_COL_EPOCH_A, TLE1_LEN_EPOCH_A);

   m_Field[FLD_EPOCHDAY] = 
         m_strLine1.mid(TLE1_COL_EPOCH_B, TLE1_LEN_EPOCH_B);
   
   if (m_strLine1[TLE1_COL_MEANMOTIONDT] == '-')
   {
      // value is negative
      m_Field[FLD_MMOTIONDT] = "-0";
   }
   else
      m_Field[FLD_MMOTIONDT] = "0";
   
   m_Field[FLD_MMOTIONDT] += m_strLine1.mid(TLE1_COL_MEANMOTIONDT + 1,
                                               TLE1_LEN_MEANMOTIONDT);
   
   // decimal point assumed; exponential notation
   m_Field[FLD_MMOTIONDT2] = ExpToDecimal(
                                 m_strLine1.mid(TLE1_COL_MEANMOTIONDT2,
                                                   TLE1_LEN_MEANMOTIONDT2));
   // decimal point assumed; exponential notation
   m_Field[FLD_BSTAR] = ExpToDecimal(
                                m_strLine1.mid(TLE1_COL_BSTAR,
                                                       TLE1_LEN_BSTAR));
   //TLE1_COL_EPHEMTYPE      
   //TLE1_LEN_EPHEMTYPE   
   m_Field[FLD_SET] = m_strLine1.mid(TLE1_COL_ELNUM, TLE1_LEN_ELNUM);
   
   //TrimLeft(m_Field[FLD_SET].tr);
   
   //TLE2_COL_SATNUM         
   //TLE2_LEN_SATNUM         
   
   m_Field[FLD_I] = m_strLine2.mid(TLE2_COL_INCLINATION,
                                      TLE2_LEN_INCLINATION).trimmed();
   
   m_Field[FLD_RAAN] = m_strLine2.mid(TLE2_COL_RAASCENDNODE,
                                         TLE2_LEN_RAASCENDNODE).trimmed();
   // decimal point is assumed
   m_Field[FLD_E]   = "0.";
   m_Field[FLD_E]   += m_strLine2.mid(TLE2_COL_ECCENTRICITY,
                                       TLE2_LEN_ECCENTRICITY);
   
   m_Field[FLD_ARGPER] = m_strLine2.mid(TLE2_COL_ARGPERIGEE,
                                           TLE2_LEN_ARGPERIGEE).trimmed();
   
   m_Field[FLD_M]   = m_strLine2.mid(TLE2_COL_MEANANOMALY,
                                      TLE2_LEN_MEANANOMALY).trimmed();
   
   m_Field[FLD_MMOTION]   = m_strLine2.mid(TLE2_COL_MEANMOTION,
                                            TLE2_LEN_MEANMOTION).trimmed();

   m_Field[FLD_ORBITNUM] = m_strLine2.mid(TLE2_COL_REVATEPOCH,
                                             TLE2_LEN_REVATEPOCH).trimmed();

   satnum = m_Field[FLD_NORADNUM].toLong();
   epochyr = m_Field[FLD_EPOCHYEAR].toInt();
   epochdays = m_Field[FLD_EPOCHDAY].toDouble();
   ndot = m_Field[FLD_MMOTIONDT].toDouble();        // mean motion dt
   nddot = m_Field[FLD_MMOTIONDT2].toDouble();      // mean motion dt2
   bstar = m_Field[FLD_BSTAR].toDouble();           // bstar
   inclo = m_Field[FLD_I].toDouble();               // inclination
   nodeo = m_Field[FLD_RAAN].toDouble();            // right ascending node
   ecco = m_Field[FLD_E].toDouble();                // eccenticity
   argpo = m_Field[FLD_ARGPER].toDouble();          // argument of perigee
   mo = m_Field[FLD_M].toDouble();                  // mean anomaly
   no = m_Field[FLD_MMOTION].toDouble();            // mean motion

   getgravconst( whichconst, tumin, mu, radiusearthkm, xke, j2, j3, j4, j3oj2, radiusearthkmminor, flattening );

   // ---- find no ----
   no   = no / xpdotp; //* rad/min
   // ---- convert to sgp4 units ----
   a    = pow( no*tumin , (-2.0/3.0) );
   ndot = ndot  / (xpdotp*1440.0);  //* ? * minperday
   nddot= nddot / (xpdotp*1440.0*1440);

   // ---- find standard orbital elements ----
   inclo = inclo  * deg2rad;
   nodeo = nodeo  * deg2rad;
   argpo = argpo  * deg2rad;
   mo    = mo     * deg2rad;

   alta = a*(1.0 + ecco) - 1.0;
   altp = a*(1.0 - ecco) - 1.0;

   // ----------------------------------------------------------------
   // find sgp4epoch time of element set
   // remember that sgp4 uses units of days from 0 jan 1950 (sgp4epoch)
   // and minutes from the epoch (time)
   // ----------------------------------------------------------------

   // ---------------- temp fix for years from 1957-2056 -------------------
   // --------- correct fix will occur when year is 4-digit in tle ---------
   if (epochyr < 57)
       year= epochyr + 2000;
     else
       year= epochyr + 1900;

   days2mdhms ( year, epochdays, mon, day, hr, minute, sec );
   jday( year, mon, day, hr, minute, sec, jdsatepoch );

   const double a1 = pow( xke / no, 2/3);
   const double cosio = cos(inclo);
   const double theta2 = cosio * cosio;
   const double x3thm1 = 3.0 * theta2 - 1.0;
   const double eosq = ecco * ecco;
   const double betao2 = 1.0 - eosq;
   const double betao = sqrt(betao2);
   const double temp = (1.5 * (j2/2)) * x3thm1 / (betao * betao2);
   const double del1 = temp / (a1 * a1);
   const double a0 = a1 * (1.0 - del1 * (1.0 / 3.0 + del1 * (1.0 + del1 * 134.0 / 81.0)));
   const double del0 = temp / (a0 * a0);

   recovered_mean_motion = no/(1.0 + del0);

} // InitStrVars()