Index: /trunk/htdocs2/conesearch.php
===================================================================
--- /trunk/htdocs2/conesearch.php	(revision 366)
+++ /trunk/htdocs2/conesearch.php	(revision 366)
@@ -0,0 +1,129 @@
+<?php
+
+
+header("Content-type: text/xml");
+
+
+
+require_once 'config.php';
+require_once 'Classes/Queries/ConeQuery.php';
+require_once 'xmlFunctions.php';
+require_once 'Classes/Interfaces/ObsInterface.php';
+
+
+
+echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
+echo "<!DOCTYPE VOTABLE SYSTEM \"http://us-vo.org/xml/VOTable.dtd\">\n";
+echo "<VOTABLE version=\"1.1\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"http://www.ivoa.net/xml/VOTable/VOTable/v1.1\">\n";
+
+echo "  <DESCRIPTION>\n";
+echo "     ATNF Pulsar Data Archive conesearch service.\n";
+echo "     The Archive holds data files from observations of pulsars made with the Parkes radio telescope.\n";
+echo "     This service provides information on what data files exist in the archive within the required cone search area.\n";
+echo "     Note that this service can only see non-proprietry data, which are more than ".PROPRIETRY_PERIOD_YR." years old.\n";
+echo "     To obtain the data, go to ".WEB_ARCHIVE_URL."\n";
+echo "     Usage: Provide three parameters: RA (right ascension), DEC (declination), SR (search radius) \n";
+echo "            All values in decimal degrees\n";
+echo "  </DESCRIPTION>\n";
+
+
+$raj_degs         = trim(get_param('RA', $HTTP_GET_VARS));
+$decj_degs        = trim(get_param('DEC', $HTTP_GET_VARS));
+$radius           = trim(get_param('SR', $HTTP_GET_VARS));
+
+$errorMsg = "";
+$isError = False;  // Assume the best, that all three parameters are present and appropriate.
+
+// If a parameter is missing, we have a problem.
+if($raj_degs==""){
+  $isError=True;
+  $errorMsg .= "RA value not provided.; ";
+}
+if($decj_degs==""){           //	if(!isset($decj_degs)){
+  $isError=True;
+  $errorMsg .= "DEC value not provided.; ";
+	}
+if($radius==""){		//	if(!isset($radius)){
+  $isError=True;
+  $errorMsg .= "SR value not provided.; ";
+}
+
+// If the parameters are not numbers, this is bad.
+if(($raj_degs!="") && !is_numeric($raj_degs)){
+  $isError=True;
+  $errorMsg .= "RA value (" . $raj_degs . ") is not a number.; ";
+}
+if(($decj_degs!="") && !is_numeric($decj_degs)){
+  $isError=True;
+  $errorMsg .= "DEC value (" . $decj_degs . ") is not a number.; ";
+}
+if(($radius!="") && !is_numeric($radius)){
+  $isError=True;
+  $errorMsg .= "SR value (" . $radius . ") is not a number.; ";
+}
+
+// If DEC is out of range, this is bad.
+if( is_numeric($decj_degs) && (abs($decj_degs) > 90.) ){
+  $isError = True;
+  $errorMsg .= "DEC value (" . $decj_degs . ") is out of range; ";
+    //  $errorMsg .= "DEC value is out of range; ";
+}
+
+// If SR is negative, this is bad.
+if( is_numeric($radius) && ($radius < 0.) ){
+  $isError = True;
+  $errorMsg .= "SR value (" . $radius . ") is negative; ";
+}
+
+
+if( $isError )
+{
+  echo "<TABLE>\n";
+  echo "<RESOURCE type=\"Error message\">\n";
+  printf("<PARAM ID=\"ERROR\" datatype=\"char\" value=\"%s\"/>\n",$errorMsg);
+  echo "</RESOURCE>\n";
+  echo "</TABLE>\n";
+  echo "</VOTABLE>\n";
+}
+else
+{
+  try
+  {
+    $db = new MysqlDB();
+    $db->connect( DB_HOST, DB_USER, DB_PASSWD, DB_NAME );
+    
+    $coords = new SkyCoord();
+    $coords->SetRA( $raj_degs );
+    $coords->SetDEC( $decj_degs );
+    
+    $query_parameters = new ConeQueryParameters();
+    $query_parameters->SetCoordinates( $coords );
+    $query_parameters->SetSearchRadius( $radius );
+    
+    // TODO see if we need to limit queries to older than 2 years
+    
+    $query = new ConeQuery();
+    $query->SetParameters( $query_parameters );
+    $query->Execute();
+    $observations = $query->GetObservations();
+    
+    echo "  <TABLE>\n";
+    print_column_headers_VO();
+
+    echo "  <COOSYS ID=\"J2000\" equinox=\"J2000.\" epoch=\"J2000.\" system=\"eq_FK5\"/>\n";
+    echo "  <RESOURCE type=\"conesearch results\">\n";
+    printf("  <PARAM ID=\"RA\" name=\"RA\" datatype=\"float\" unit=\"degrees\" value=\"%10.6f\"></PARAM>\n",$raj_degs);
+    printf("  <PARAM ID=\"DEC\" name=\"DEC\" datatype=\"float\" unit=\"degrees\" value=\"%+11.6f\"></PARAM>\n",$decj_degs);
+    printf("  <PARAM ID=\"SR\" name=\"SR\" datatype=\"float\" unit=\"degrees\" value=\"%10.6f\"></PARAM>\n",$radius);
+
+    print_data_VO($observations, new ObsInterface());
+
+    echo "</RESOURCE>\n";
+    echo "  </TABLE>\n";
+    echo "</VOTABLE>\n";
+  }
+  catch( GZ_Exception $e )
+  {
+  }
+}
+?>
