The OrbitTools Libraries
NORAD SGP4/SDP4 Implementations in C++ and C#
by
Michael F. Henry

Track Library C++ Source Code Example #3
 

//
// This program illustrates how to use the OrbitTools Track Library 
// to determine the time periods when satellites in an arbitrary 
// constellation can be acquired from an earth ground site.
//
// To demonstrate, the times when a ground site has a clear view of
// satellites in the GPS constellation are calculated.
//
// Copyright © 2014 Michael F. Henry
// 2014-06-28
//
#include "stdafx.h"
#include <fstream>

// These header files provide access to the main functionality
// of the OrbitTools software libraries.
#include "coreLib.h"
#include "orbitLib.h"
#include "trackLib.h"

using namespace Zeptomoby::OrbitTools::Track::Acquire;

// Forward declaration of helper function (see below)
void PrintInfo(const cSchedule<IEciObject>& sched);

int main(int argc, char* argv[])
{
   // The file "tleGpsOps.txt" contains TLE data for all operational
   // GPS satellites (31 satellites total).
   std::ifstream tleFile("tleGpsOps.txt");

   // Read all TLEs from the input file, and create a vector of satellites.
   // Note: "satellite_ptr" is a typedef for "shared_ptr<cSatellite>"
   vector<satellite_ptr> gpsSats;

   while (!tleFile.eof())
   {
      string line0;
      string line1;
      string line2;

      getline(tleFile, line0);
      getline(tleFile, line1);
      getline(tleFile, line2);

      cTle tle(line0, line1, line2);
      auto sat = make_shared<cSatellite>(tle, cWgs84::Instance());
      
      gpsSats.push_back(sat);
   }

   // The earth ground site: London, England
   cSite site = cSite(51.507222, -0.1275, 10.0, cWgs84::Instance());

   // The time period of interest
   cJulian t1 = cJulian(2014, 1, 24,  0,  0);  // 01/24/2014 00:00 UTC
   cJulian t2 = cJulian(2014, 1, 24, 23, 59);  // 01/24/2014 23:59 UTC

   // Create an object that will provide acquisition information about
   // a constellation of satellites over the time period t1..t2 for
   // the given ground site.
   cAcquire acqInfo(site, gpsSats, t1, t2);

   // Show the time periods in which any satellite in the GPS constellation 
   // can be acquired. The returned object is a schedule, whose time periods
   // contain references to IEciObject objects. In this case, those IEciObject
   // objects are cSatellite objects.
   cSchedule<IEciObject> sched = acqInfo.AcquireAny();

   printf("ANY Sats\n");
   PrintInfo(sched);

   // Program output:
   //
   // ANY Sats
   // 2014-01-24 00:00:00 2014-01-24 00:02:08 : 8
   //    GPS BIIA-23 (PRN 04)
   //    GPS BIIR-6  (PRN 14)
   //    GPS BIIR-13 (PRN 02)
   //    GPS BIIRM-2 (PRN 31)
   //    GPS BIIRM-3 (PRN 12)
   //    GPS BIIRM-5 (PRN 29)
   //    GPS BIIF-1  (PRN 25)
   //    GPS BIIF-3  (PRN 24)
   // 
   // 2014-01-24 00:02:09 2014-01-24 00:02:57 : 7
   //    GPS BIIA-23 (PRN 04)
   //    GPS BIIR-6  (PRN 14)
   //    GPS BIIR-13 (PRN 02)
   //    GPS BIIRM-2 (PRN 31)
   //    GPS BIIRM-3 (PRN 12)
   //    GPS BIIRM-5 (PRN 29)
   //    GPS BIIF-1  (PRN 25)
   // 
   // 2014-01-24 00:02:58 2014-01-24 00:12:32 : 8
   //    GPS BIIA-23 (PRN 04)
   //    GPS BIIR-6  (PRN 14)
   //    GPS BIIR-9  (PRN 21)
   //    GPS BIIR-13 (PRN 02)
   //    GPS BIIRM-2 (PRN 31)
   //    GPS BIIRM-3 (PRN 12)
   //    GPS BIIRM-5 (PRN 29)
   //    GPS BIIF-1  (PRN 25)
   // 
   // ( output truncated... )

   // Show the time periods in which the minimum number of satellites in
   // the GPS constellation can be acquired.
   sched = acqInfo.AcquireMin();

   printf("MIN Sats\n");
   PrintInfo(sched);

   // Program output:
   //
   // MIN Sats
   // 2014-01-24 00:02:09 2014-01-24 00:02:57 : 7
   //    GPS BIIA-23 (PRN 04)
   //    GPS BIIR-6  (PRN 14)
   //    GPS BIIR-13 (PRN 02)
   //    GPS BIIRM-2 (PRN 31)
   //    GPS BIIRM-3 (PRN 12)
   //    GPS BIIRM-5 (PRN 29)
   //    GPS BIIF-1  (PRN 25)
   // 
   // 2014-01-24 23:58:01 2014-01-24 23:58:45 : 7
   //    GPS BIIA-23 (PRN 04)
   //    GPS BIIR-6  (PRN 14)
   //    GPS BIIR-13 (PRN 02)
   //    GPS BIIRM-2 (PRN 31)
   //    GPS BIIRM-3 (PRN 12)
   //    GPS BIIRM-5 (PRN 29)
   //    GPS BIIF-1  (PRN 25)

   // Show the time periods in which the maximum number of satellites in
   // the GPS constellation can be acquired.
   sched = acqInfo.AcquireMax();

   printf("MAX Sats\n");
   PrintInfo(sched);

   // Program output:
   // 
   // MAX Sats
   // 2014-01-24 05:58:10 2014-01-24 06:19:09 : 17
   //    GPS BIIA-10 (PRN 32)
   //    GPS BIIA-21 (PRN 09)
   //    GPS BIIA-24 (PRN 06)
   //    GPS BIIA-25 (PRN 03)
   //    GPS BIIA-28 (PRN 08)
   //    GPS BIIR-3  (PRN 11)
   //    GPS BIIR-5  (PRN 28)
   //    GPS BIIR-6  (PRN 14)
   //    GPS BIIR-7  (PRN 18)
   //    GPS BIIR-8  (PRN 16)
   //    GPS BIIR-9  (PRN 21)
   //    GPS BIIR-10 (PRN 22)
   //    GPS BIIR-11 (PRN 19)
   //    GPS BIIRM-4 (PRN 15)
   //    GPS BIIRM-6 (PRN 07)
   //    GPS BIIF-2  (PRN 01)
   //    GPS BIIF-4  (PRN 27)

	return 0;
}

//
// Helper function to display schedule information
//
void PrintInfo(const cSchedule<IEciObject>& sched)
{
   // Print information about each period in the given schedule
   for (const auto& period : sched.Periods())
   {
      // The start/stop time of the period, followed by the number
      // of content items (cSatellites) associated with the period, i.e.,
      // "2014-01-24 00:00:00 2014-01-24 00:02:08 : 8"
      printf("%s\n", period->ToString().c_str());

      // The "content" of each period. Here the content is an IEciObject 
      // pointer, which points to a cSatellite object. Use the pointer to 
      // print the satellite name.
      for (auto& sat : period->Content())
      {
         printf("   %s\n", sat->Name().c_str());
      }

      printf("\n");
   }
}


Return to Track Library Resources

Copyright  © 2014 Michael F. Henry.