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

Track Library 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-10-04
//
using System;
using System.IO;
using System.Collections.Generic;
using Zeptomoby.OrbitTools;
using Zeptomoby.OrbitTools.Pro;
using Zeptomoby.OrbitTools.Track;

namespace TrackExample3
{
   class Program
   {
      static void Main(string[] args)
      {
         // The file "tleGpsOps.txt" contains TLE data for all operational
         // GPS satellites (31 satellites total).
         StreamReader tleFile = new StreamReader("tleGpsOps.txt");

         // Read all TLEs from the input file, and create a list of satellites.
         List<Satellite> gpsSats = new List<Satellite>();

         while (!tleFile.EndOfStream)
         {
            string line0 = tleFile.ReadLine();
            string line1 = tleFile.ReadLine();
            string line2 = tleFile.ReadLine();

            Tle       tle = new Tle(line0, line1, line2);
            Satellite sat = new Satellite(tle, new Wgs84());

            gpsSats.Add(sat);
         }

         // The earth ground site: London, England
         Site site = new Site(51.507222, -0.1275, 10.0, new Wgs84());

         // The time period of interest
         DateTime t1 = new DateTime(2014, 1, 24, 0,   0, 0);  // 01/24/2014 00:00:00 UTC
         DateTime t2 = new DateTime(2014, 1, 24, 23, 59, 0);  // 01/24/2014 23:59:00 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.
         Acquire acqInfo = new Acquire(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 Satellite objects.
         Schedule<IEciObject> sched = acqInfo.AcquireAny();

         Console.WriteLine("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();

         Console.WriteLine("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();

         Console.WriteLine("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)    
      }

      //
      // Helper function to display schedule information
      //
      static void PrintInfo(Schedule<IEciObject> sched)
      {
         // Print information about each period in the given schedule
         foreach (var period in sched.Periods())
         {
            // The start/stop time of the period, followed by the number
            // of content items (Satellites) associated with the period, i.e.,
            // "2014-01-24 00:00:00 2014-01-24 00:02:08 : 8"
            Console.WriteLine(period.ToString());

            // The "content" of each period. Here the content is an IEciObject 
            // reference, which points to a Satellite object.
            foreach (var sat in period.Content)
            {
               Console.WriteLine("   {0}", sat.Name);
            }

            Console.WriteLine();
         }
      }
   }
}


Return to Track Library Resources

Copyright  © 2014 Michael F. Henry.