url = "http://ssd.jpl.nasa.gov/horizons.cgi"; $this->curl = curl_init($this->url); $this->cookiefile = "/tmp/horizon_cookie"; $this->verbose = false; /* try to delete cruft from prior session */ unlink ( $this->cookiefile ); curl_setopt($this->curl, CURLOPT_COOKIEJAR, $this->cookiefile ); curl_setopt($this->curl, CURLOPT_HEADER, 1); curl_setopt($this->curl, CURLOPT_RETURNTRANSFER, 1); curl_setopt($this->curl, CURLOPT_POST, 1); } public function cleanup () { curl_close($this->curl); unlink ( $this->cookiefile ); shell_exec ( "rm -f " . $this->cookiefile ); } function ck_error ( $html ) { if ( strpos ( $html, "
**");
$end = strpos($this->html, "\$\$EOE");
return substr($this->html, $start, $end-$start+5) . "\n";
}
function extract_header ( $info ) {
/* extract header for display */
$start = strpos($info, "**");
$end = strpos($info, "\$\$SOE");
return substr($info, $start, $end-$start-1);
}
function extract_table ( $info ) {
/* extract the table */
$start = strpos($info, "\$\$SOE");
$end = strpos($info, "\$\$EOE");
return substr($info, $start, $end-$start+6);
}
function parseTable ( $table ) {
$rv = array();
$lines = split("\n", $table);
$i = 0;
foreach($lines as $line) {
$words = split(",", $line);
if(count($words) > 3) {
$entry = new Entry($words[0], $words[3], $words[4], $words[5], $words[6]);
$rv[$i++] = $entry;
}
}
return rv;
}
function misc ( $ephemeris ) {
if ( count($ephemeris) < 1 ) {
return;
}
/* First line in table */
$first = $ephemeris[0];
/* XXX - really need to check against current time */
if ( $first->alt < 6.0 ) {
$below_horizon = true;
$status = "Ephemeris generated. (starts below horizon)";
} else {
$below_horizon = false;
$status = "Ephemeris generated. Ready to send to the telescope.";
}
}
}
/* ------------------------------------------------------ */
/* ------------------------------------------------------ */
if ( $argc == 2 ) {
$target = $argv[1];
} else {
$target = "Europa";
$target = "Mars";
$target = "MB:499";
$target = "MB:52"; // fails
$target = "Europa";
$target = "MB:502";
$target = "pallas";
}
// Just doesn't work via web interface.
//$target = "g:62.2,84.4,0@301";
//$search = true;
if ( strpos ( $target, ":" ) ) {
$search = false;
echo "Looking for " . $target . "\n";
} else {
$search = true;
echo "Searching for " . $target . "\n";
}
/* set defaults for first time through script,
* the +7 hours takes us from MST to UT
*/
$start_time = date("Y-m-d H:i", strtotime("now +7 hours"));
$stop_time = date("Y-m-d H:i", strtotime("+12 hours +7 hours"));
$start_time = "2009-03-31 19:00";
$stop_time = "2009-03-31 21:00";
echo "Start: " . $start_time . "\n";
echo "Stop: " . $stop_time . "\n";
$net = new horizons ();
$msg = $net->set_target ( $target, $search );
//$net->show_settings ();
echo ( "Target Set!\n" );
if ( $msg ) {
echo $msg;
//exit ();
}
$info = $net->get_info ( $start_time, $stop_time );
if ( ! $info ) {
$net->cleanup ();
echo ( "Sorry\n" );
exit ();
}
echo ( $info );
//echo ( "Got it!\n" );
//$ephemeris = $net->parseTable($table);
?>