
# coding: utf-8

# In[14]:

# Tracking: Program for formatting of tracking data from GMAT report file,
# for converting azimuth data and for calculating doppler shift data.
# Nico Janssen, PA0DLO, March 2017
#
#

from pathlib import Path
import math

# Open the GMAT ReportFile1.txt file and read all lines
a = []
textfile = "ReportFile1.txt"
p = Path(textfile)
with p.open() as f:
    a = f.readlines()
f.close()

# Input frequency for doppler shift calculations
freq = input("Enter frequency (in MHz) for doppler shift calculations: ")
fre = float(freq)

# Open output file for writing results and write header
f = open('TrackingData.txt', 'w')
f.write('Date & Time (UTC)          Azimuth (deg)   Elevation (deg)    Range (km)    Doppler (Hz) @ '+freq+' MHz\n')

# Process all lines
tjo = 0
rao = 0
for i in range(1,len(a)):
    # Read the data from each line
    dt = str(a[i][0:24])
    azg = float(a[i][30:54])
    el = float(a[i][60:84])
    ran = float(a[i][90:114])
    tj = float(a[i][120:144])

    # Calculate azimuth and doppler shift
    az = 180 - azg
    tjn = tj * 86400
    vr = (ran - rao) / (tjn - tjo)
    df = -fre * 3.335640951981521 * vr
    rao = ran
    tjo = tjn

    # Write results in output file
    s = '{0} {1:11.2f} {2:16.2f} {3:19.3f} {4:17.3f}\n'.format(dt, az, el, ran, df)
    f.write(s)
f.close()


# In[ ]:



