<?php

# this program takes two arguments: 
# an input list of RA, DEC, n(FILTER)
# an output png filename
# it generates a sky plot showing the locations of the given list of points

$debug = 0;
include 'site.php';

### these need to be set to the correct locations!!
$MISSING = "missing.png";

### we must have been past arguments with GET:
if ($_SERVER[REQUEST_METHOD] != 'GET') { 
  exit ();
}

$PATH = getenv("PATH");
putenv("PATH=$BINDIR:$PATH");

$LD_LIBRARY_PATH = getenv("LD_LIBRARY_PATH");
putenv("LD_LIBRARY_PATH=$LIBDIR:$LD_LIBRARY_PATH");

if ($debug) {
  echo "path: $PATH<br>";

  $newpath = getenv("PATH");
  echo "new path: $newpath<br>";

  $newpath = getenv("LD_LIBRARY_PATH");
  echo "new path: $newpath<br>";

  echo "bindir: $BINDIR<br>";
}

if ($debug) {
  exec ("which skyplot.dvo", $output, $status);
  echo "which output:<br>";
  for ($i = 0; $i < count($output); $i++) {
    echo "output $i: $output[$i]<br>";
  }
  echo "status:   $status<br>";
}

$infile  = $_GET[input];
$outfile = $_GET[output];

exec ("skyplot.dvo $infile $outfile", $output, $status);

if ($debug) {
  for ($i = 0; $i < count($output); $i++) {
    echo "output $i: $output[$i]<br>";
  }
  echo "status:   $status<br>";
  exit ();
}

# use these to check the environment
# passthru ("env");

$file = fopen ($outfile, "r");
if ($file && !$debug) {
  header ('Content-Type: image/png');
  fpassthru ($file);
}
exit ();
?>
