#! /bin/csh
#
# getsts      -----      Manfred Bester  27Mar95
#
# This C shell script can be invoked manually or by cron at a specified time.
# It calls up 'spacelink.msfc.nasa.gov' (192.149.89.61) and gets the most 
# recent files with Keplerian two-line element sets for the upcoming or current 
# space shuttle mission, as used with SatTrack. 
#
# The mission number needs to be specified below in the variable 'stsnum'. 
#
# If the shuttle has not been launched yet, 'prelaunch' has to be set to '1', 
# and otherwise to '0'.
#
# The variable 'satuser' is normally the personal user ID.
#
# If SatTrack is not installed in the user's home directory, the variable 
# 'satdir' needs to be changed to the name of the directory that SatTrack is 
# installed under. The variable 'satuser' is the UID of the user who is allowed 
# to write into the system-wide SatTrack directory, i.e. the person in charge 
# of maintaining SatTrack (maybe 'root').
#
#
#
set stsnum=81
set prelaunch=0
set ftphost=spacelink.msfc.nasa.gov
set satdir=/usr/local/lib
set satuser=sattrack
#
#
#
set hostdot=`hostname | grep '\.'`
if ("$hostdot" == "") then
    set userid=$USER@`hostname`.`domainname`
else
    set userid=$USER@`hostname`
endif
#
set satdirusr=$satdir
if (! -d $satdirusr/SatTrack/tle) then
    mkdir -p $satdirusr/SatTrack/tle
endif
#
cd $satdirusr/SatTrack/tle
#
if ($1 == -v) then 
    echo $userid
    echo calling $ftphost ...
endif
#
if ($prelaunch == 1) then 
    set kepfile=STS-$stsnum.Pre-Launch.Keplerian.Elements
    set mission=Upcoming
    else
    set kepfile=STS-$stsnum.Keplerian.Elements
    set mission=Current
endif
#
set tledir=$mission.Shuttle.Mission.STS-$stsnum
#
ftp $1 -n $ftphost << !
user anonymous -$userid
cd Spacelink.Hot.Topics
cd $tledir
get $kepfile
quit
!
#
if ($1 == -v) then 
    echo saving data files ...
endif
#
"mv" sts-$stsnum.dat sts-$stsnum.bak
echo STS-$stsnum > sts-$stsnum.dat
sed -n -e /\^1\ /p -e /\^2\ /p $kepfile >> sts-$stsnum.dat
touch sts-$stsnum.dat.all
cat sts-$stsnum.dat >> sts-$stsnum.dat.all
"rm" $kepfile
#
if ($1 == -v) then 
    echo ""
    echo new TLE set:
    echo ""
    cat sts-$stsnum.dat
    echo ""
endif
#
if ($1 == -v) then
    echo running 'maketlex' ...
endif
#
maketlex
#
if ($1 == -v) then
    echo done.
endif
#
