-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmaster_bash.sh
More file actions
128 lines (95 loc) · 5.44 KB
/
master_bash.sh
File metadata and controls
128 lines (95 loc) · 5.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
##################################################################
##################################################################
# Master bash file - will run on interval specified by crontab
# Initiates scrape & sgp4 computations for all spacecraft
# Prep
# Run as root: chown -R <user> /usr/share/celestia/extras
# Run as root: chown -R <user> /usr/share/celestia/extras-standard
# Add .bak extension to original SSC files or remove
# User Inputs
# Web addresses for Python curl
# Pertinent lines for parsing
# Folder structures
# Outputs
# Updated LOG file for each spacecraft
# New TLE file for each spacecraft
# XYZV files for each spacecraft
# Goals
# Add future expansion to scrape from multiple web pages
##################################################################
##################################################################
# Change from ~/ (crontab default) to working directory and create LOG & TLE
cd /home/<user>/<...>
mkdir -p ./LOG
mkdir -p ./TLE
cd ./TLE
# Move custom python scripts into python-sgp4 submodule
mv date.py ./python-sgp4/date.py
mv sgp4.py ./python-sgp4/sgp4.py
############
## scrape ##
############
# Initialization variables
pages=(stations tdrss gps-ops) # stations, tdrss, gps-ops, sarsat, tle-new, visual, geo
toi=(ISS HST GPS) # spacecraft of interest - string base
for p in ${pages[@]};
do
# Download TLE txt data from the web, get its date, and setup folder structure for ssc and xyzv files
dl=`curl -i http://www.celestrak.com/NORAD/elements/$p.txt`
date=`echo "$dl" | awk "NR==4" | tail -c +16 | head -c -2`
dir=/usr/share/celestia/extras/$p
mkdir $dir
mkdir $dir/data
# Set pre-loop variables
pos=11 # last line of curl -i is line 10
end=`echo "$dl" | wc -l` # end is last line number
# Main loop
while [ $pos -lt $end ]
do
# Set name of spacecraft
name=`echo "$dl" | awk "NR==$pos" | tr -s " " "_" | head -c -3` # trims carriage return "\r" and last "_"
# Check against toi array - improve
for n in "${toi[@]}"; do if [[ $name == $n* ]]; then
# Create TLE file from selected data
echo "$dl" | awk "NR==$pos+1,NR==$pos+2" > ./_$name
# If TLE file does not exist, create and prep a new log file
if [ ! -e "./$name" ]
then echo -e "# Running log file for $name TLE data from Celestrack TLE repository (sourced from NORAD)\n\n# Line 1 is: <line> <sat_num> <int_desig> <ep_yr_fracday> <1_der_mm> <2_der_mm> <drag> <eph_typ> <el_set> <cs>\n# TLE Line 2 is: <line> <sat_num> <incl> <ra> <ecc> <peri> <m_anom> <m_mot> <rev_num> <cs>\n" > ../LOG/$name.txt
fi
# Compare to last TLE file
if ! diff -q ./_$name ./$name
then
# Remove original TLE file and rename temp to new
rm ./$name
mv ./_$name ./$name
# Write updated data to log (in LOG folder) - combine?
echo "#####################################################################" >> ../LOG/$name.txt
echo "$date" >> ../LOG/$name.txt
echo "$dl" | awk "NR==$pos+1,NR==$pos+2" >> ../LOG/$name.txt
echo >> ../LOG/$name.txt
############
## sgp4 ##
############
# Run calculations based on new TLE data - pass variables to Python
s_date=`python ../python-sgp4/date.py $name`
#s_date=`TZ=UTC date +"%a, %d %b %Y %H:%M:%S GMT"`
#es=`date +"%s" -d "$s_date"` # epoch seconds
ss=600 # step size in seconds
ts=36 # time span in hours
e_date=`TZ=UTC date +"%a, %d %b %Y %H:%M:%S GMT" -d "$s_date $ts hours"` # not passed to Python, used to setup xyzv file
echo -e "# Celestia xyzv file generated by sgp4.py\n\n# Satellites deviate from the ideal orbits described in TLE files by 1-3 km/day\n\n# Data post date: $date\n# Calc start date: $s_date\n# Calc end date: $e_date\n# Time span (hours): $ts\n# Step size (sec): $ss\n\n# Records are <jd> <x> <y> <z> <vel x> <vel y> <vel z>\n# Time is a TDB Julian date\n# Position in km\n# Velocity in km/sec\n\n######################################################\n" > $dir/data/$name.xyzv
### Run sgp4.py script ###
# variables with spaces should be in double quotes
python ../python-sgp4/sgp4.py $name $ts $ss >> $dir/data/$name.xyzv # passes <1 filename> <2 current date> <3 current epoch> <4 time span> <5 step size> from bash to Python
# Create SSC file
echo -e ""\""$name"\"" "\""Sol/Earth"\""\n{\nClass "\""spacecraft"\""\n#Mesh "\""<file>"\""\nRadius 0.01\nAlbedo 0.7\nSampledOrbit "\""$name.xyzv"\""\n\nBodyFrame {\n TwoVector {\n Center "\""Sol/Earth/$name"\""\n Primary {\n Axis "\""z"\""\n RelativePosition { Target "\""Sol/Earth"\"" }\n }\n Secondary {\n Axis "\""x"\""\n RelativeVelocity { Target "\""Sol/Earth"\"" }\n }\n }\n}\n\n}" > $dir/$name.ssc
else
# Remove temp TLE file
rm ./_$name
fi
# Check against toi array - improve
fi; done
# Increment pos variable by 3 (lines per spacecraft)
let pos+=3
done
done