$inputfile = shift;

#
# open/read/close the file
#
open (INPUT, "$inputfile");
@IN = <INPUT>;
close INPUT;

#
# open the new file (same as input file) for writing
#
open (OUTPUT, ">$inputfile");

my @data;
my $fromObj;

foreach (@IN){
	chomp;
	
	if (($_ =~ /^\s*(.*)-To-/) && (! $fromObj)){
		$fromObj = $1;
		$fromObj =~ s/\-/\//;
		}
	
	# pattern match to pull out 4 adjacent numbers (time/el/az/range)
	# time (epsecs), elevation(degs), azimuth (degs), range (meters)
	if ($_ =~ /^\s*(\d*\.{0,1}\d*)\s+(\d*\.{0,1}\d*)\s+(\d*\.{0,1}\d*)\s+(\d*\.{0,1}\d*)$/){
		push (@data, "\t" . $1 . "\t-" . $2 . "\t" . $3 . "\t" . $4);
		}
	}

print OUTPUT "stk.v.4.3\n\n";
print OUTPUT "BEGIN Ephemeris\n\n";
print OUTPUT "NumberOfEphemerisPoints " . $#data . "\n";
print OUTPUT "\#ScenarioEpoch\n";
print OUTPUT "InterpolationMethod     Lagrange\n";
print OUTPUT "InterpolationOrder      1\n";
print OUTPUT "DistanceUnit            meters\n";
print OUTPUT "CentralBody             Earth\n";
print OUTPUT "CoordinateSystem        Custom Body " . $fromObj . "\n\n";
print OUTPUT "EphemerisLLRTimePos\n";
print OUTPUT join ("\n", @data);