Index: /trunk/htdocs/conequery-vo.php
===================================================================
--- /trunk/htdocs/conequery-vo.php	(revision 162)
+++ /trunk/htdocs/conequery-vo.php	(revision 162)
@@ -0,0 +1,170 @@
+<?php	session_start(); 
+header("Content-type: text/xml");
+	// conequery-vo.php
+	// Matthew Whiting June 18 2007
+	// 
+	// A test of a VO-compliant conesearch query for the new data.
+	// This should return a VOTable.
+	//
+	// The query parameters are RA, DEC, SR, all in decimal degrees.
+	//
+	// An example to test is conequery-vo.php?RA=0.&DEC=-49.&SR=1.
+	//
+	// Using Albert Teoh's query.php as a template
+?>
+<?php 
+//
+// Need to enclose the following in a <?php structure else having the <?xml will confuse things
+//
+echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
+?> 
+<!DOCTYPE VOTABLE SYSTEM "http://us-vo.org/xml/VOTable.dtd">
+<VOTABLE version="1.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://www.ivoa.net/xml/VOTable/VOTable/v1.1">
+<?php
+include_once("database.php");
+include_once("utils.php");
+include_once("xmlFunctions.php");
+
+$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 there has been an error, report it as a PARAM and exit.
+if($isError){
+  echo "<RESOURCE type=\"Error message\">\n";
+  printf("<PARAM ID=\"ERROR\" datatype=\"char\" value=\"%s\"/>\n",$errorMsg);
+  echo "</RESOURCE>\n";
+  echo "</VOTABLE>\n";
+  exit;
+}
+// Else, continue!
+
+echo "<DESCRIPTION>\n";
+echo "ATNF Pulsar Archive: Conesearch Query\n";
+echo "</DESCRIPTION>\n";
+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);
+
+
+///////////////////////////////////////////////////////////////////////////
+//  CONNECT TO THE MYSQL DATABASE AND STORE THE S70 DATA.
+//  THIS IS A TEMPORARY MEASURE -- IDEALLY THE DATA WILL BE IN PLACE 
+//   BEFOREHAND.
+//
+
+//$link = db_connect_admin();
+$link = db_connect();
+
+//loadS70();
+//loadNewTables();
+
+///////////////////////////////////////////////////////////////////////////
+	
+
+
+//////////////////////////////////////////////
+// Get the field names to fill the table column headers (FIELD declarations).
+
+$query = "SHOW COLUMNS FROM s70";
+$result = mysql_query($query) or die ('Query failed: ' . mysql_error());
+
+$fields = array();
+if (mysql_num_rows($result)) {
+  while($row = mysql_fetch_assoc($result)) {
+    array_push($fields, $row);
+  }
+}
+
+echo "<TABLE>\n";
+print_column_headers_VO($result);
+
+$whereString = "";
+
+////////////////////////////
+// Cone search
+
+$angsep_str = "";
+if ($radius) {
+  
+  $angsep_str = "degrees( acos( cos(radians(rajd-$raj_degs))*cos(radians(decjd))*cos(radians($decj_degs))+sin(radians(decjd))*sin(radians($decj_degs))) )";
+  
+  $whereString .= "($angsep_str - 0.25*(bmaj+bmin)) < $radius";
+  
+}
+
+// Remove any leading or trailing AND and OR
+$whereString = trim($whereString, " AND OR");
+
+//$query = "SELECT *,$angsep_str as angsep FROM s70 WHERE $whereString ORDER by angsep";
+
+$query = "(SELECT *,$angsep_str as angsep FROM s70 WHERE $whereString) UNION (SELECT *,$angsep_str as angsep FROM obs WHERE $whereString) ORDER BY angsep";
+
+$result = mysql_query($query) or die('Conesearch Query failed: ' . mysql_error());
+
+$all_results = array();
+
+while ($line = mysql_fetch_assoc($result)) {
+  array_push($all_results, $line );
+}
+
+$_SESSION['results'] = $all_results;
+
+mysql_free_result($result);
+
+mysql_close($link);
+
+///////////////////////////////////////////////////////////////////////////
+
+print_data_VO($all_results);
+
+echo "</TABLE>\n";
+echo"</RESOURCE>\n";
+echo"</VOTABLE>\n";
+?>
Index: /trunk/htdocs/query.php
===================================================================
--- /trunk/htdocs/query.php	(revision 161)
+++ /trunk/htdocs/query.php	(revision 162)
@@ -6,22 +6,22 @@
 <link rel="stylesheet" type="text/css" href="styles/query.css" />
 
-<meta http-equiv="Content-Type" content="text/html; charset=iso-8759-1" />
-<meta name="DC.Creator" lang="en" content="personalName=Teoh,Albert" />
-<meta name="ATNF.Maintainer" content="contactName=Webmaster,the" />
-<meta name="DC.Titlepri" lang="en" content="The ATNF Pulsar Archive Searcher" />
-<meta name="DC.Title.alt" lang="en" content="" />
-<meta name="DC.Subject" lang="en" content="pulsar" />
-<meta name="DC.Description" lang="en" content="Search the observation data archives at the ATNF" />
-<meta name="DC.Date.created" scheme="ISO8601" content="2002-12-12" />
-<meta name="ATNF.Site" content="Marsfield" />
-<meta name="ATNF.AccessPermission" content="Public" />
-<meta name="ATNF.MetaVersion" content="1.0" />
-
-<script type="text/javascript" src="scripts/nodomws.js"></script>
-<script type="text/javascript" src="scripts/atnf-css-utils.js"></script>
-<script type="text/javascript" src="scripts/atnf-dom-utils.js"></script>
-<script type="text/javascript" src="scripts/results.js"></script>
-<script type="text/javascript">
-function submit_form()
+    <meta http-equiv="Content-Type" content="text/html; charset=iso-8759-1" />
+    <meta name="DC.Creator" lang="en" content="personalName=Whiting,Matthew" />
+    <meta name="ATNF.Maintainer" content="contactName=Webmaster,the" />
+    <meta name="DC.Titlepri" lang="en" content="The ATNF Pulsar Archive Searcher" />
+    <meta name="DC.Title.alt" lang="en" content="" />
+    <meta name="DC.Subject" lang="en" content="pulsar" />
+    <meta name="DC.Description" lang="en" content="Search the observation data archives at the ATNF" />
+    <meta name="DC.Date.created" scheme="ISO8601" content="2002-12-12" />
+    <meta name="ATNF.Site" content="Marsfield" />
+    <meta name="ATNF.AccessPermission" content="Public" />
+    <meta name="ATNF.MetaVersion" content="1.0" />
+
+    <script type="text/javascript" src="scripts/nodomws.js"></script>
+    <script type="text/javascript" src="scripts/atnf-css-utils.js"></script>
+    <script type="text/javascript" src="scripts/atnf-dom-utils.js"></script>
+    <script type="text/javascript" src="scripts/results.js"></script>
+    <script type="text/javascript">
+    function submit_form()
 {
   document.frmResults.submit();
@@ -36,528 +36,523 @@
 
 <?php
-	// query.php
-	// 
-	// Performs the user's query on the database
-	// Albert Teoh 15.11.2005
-	
-	include_once("constants.php");
-	include_once("database.php");
-	include_once("utils.php");
-	include_once("date.php");
-	include_once("security.php");
-		
-	// Processes the form and queries the database on the given parameters
-	//echo "username = " . $_SESSION['username'] . " authcode = " . $_SESSION['auth_code'] . " <br>\n";
-	
-	
-	if ( !( (isset($_SESSION['username']) && isset($_SESSION['auth_code'])) &&
-	         $_SESSION['auth_code'] == OK)) {
-		
-		echo "<center>Your session has expired due to inactivity. Please <a href=\"index.html\">log in</a>.</center>\n";
-		exit();
-	}
-	
-	// Clean out any old variables
-	init();
-	
-	///////////////////////////
-	// Collect the form values
-	
-	// List of request parameters to display
-	$params           = get_param('params', $HTTP_GET_VARS);	
-	
-	// The current state. E.g cart or results
-	// Need to maintain this because other actions could be performed without changing state 
-	$state            = get_param('state', $HTTP_GET_VARS);
-	
-	// The selected action to perform. E.g. add observations to cart, or view profile
-	$actions          = get_param('actions', $HTTP_GET_VARS);
-	
-	// List of checked observations. Note: Not necessarily observations in the cart.
-	// Cart observations are stored in $cart_items variable
-	$selected_obs              = get_param('selected_obs', $HTTP_GET_VARS);
-	
-	// A boolean value to indicate whether if the user wants to view cals as well
-	$cals             = get_param('cals', $HTTP_GET_VARS);
-	
-	// an array mapping observation number (corresponding to the index in all_results) 
-	// to an array of matching cals
-	$obs_cals = array();
-		
-	// Display cals within this many minutes of the observation
-	$cals_within_mins = get_param('cals_within_mins', $HTTP_GET_VARS);
-	
-	// cart_items is an array of numbers that index to the list of 
-	// results in all_results
-	$cart_items          = $_SESSION['cart_items'];
-	
-	
-	// this holds all the query results of observations as an array of
-	// associative arrays. E.g.
-	// array ( 0 => ( pulsar_name => 'J0437-4715',
-	//                DM          => 10,
-	//                period      => 1
-	//              ),
-	//
-	//         1 => (pulsar_name => 'J0437-4715',
-	//                DM          => 27,
-	//                period      => 1.112
-	//              )
-	//       )
-	//
-	if (isset($_SESSION['results'])) {
-		$all_results = $_SESSION['results'];
-	}
-	
-	
-	// Other form parameters. Pretty self explanatory?
-	$pulsar_name      = trim(get_param('pulsar_name', $HTTP_GET_VARS));
-	$data_type        = trim(get_param('data_type', $HTTP_GET_VARS));
-	$raj              = trim(get_param('raj', $HTTP_GET_VARS));
-	$decj             = trim(get_param('decj', $HTTP_GET_VARS));
-	$radius           = trim(get_param('radius', $HTTP_GET_VARS));
-	$from_day         = get_param('from_day', $HTTP_GET_VARS);
-	$from_month       = get_param('from_month', $HTTP_GET_VARS);
-	$from_year        = get_param('from_year', $HTTP_GET_VARS);
-	$to_day           = get_param('to_day', $HTTP_GET_VARS);	
-	$to_month         = get_param('to_month', $HTTP_GET_VARS);
-	$to_year          = get_param('to_year', $HTTP_GET_VARS);
-	
-	$startRange  = $HTTP_GET_VARS['startRange'];
-	$endRange = $HTTP_GET_VARS['endRange'];	
-	
-	$tar_file = "";
-	
-	///////////////////////
-	// Perform actions
-	//
-	// Precondition: The query has already been made, so the list of cals foreach observation
-	// has already been determined ($_SESSION['obs_cals']).
-	
-	if (isset($actions) && $actions != "") {
-		switch ($actions) {
-
-			case DOWNLOAD_ALL_OBS_CALS:
-
-				if (isset($cart_items) && isset($all_results)) {
-					//echo "Download all<br>\n";
-					$tar_file = tarObsCalFiles($cart_items, $all_results, $cals_within_mins);
-					echo " <meta http-equiv=\"REFRESH\" content=\"0; URL=".WEB_DOWNLOADS_DIR."/$tar_file\">\n";
-				}
-
-				break;
+  // query.php
+  // 
+  // Performs the user's query on the database
+  // Albert Teoh 15.11.2005
+	
+include_once("constants.php");
+include_once("database.php");
+include_once("utils.php");
+include_once("date.php");
+include_once("security.php");
+define("PSR_SEARCH_RADIUS",0.5);
+
+// Processes the form and queries the database on the given parameters
+//echo "username = " . $_SESSION['username'] . " authcode = " . $_SESSION['auth_code'] . " <br>\n";
+	
+	
+if ( !( (isset($_SESSION['username']) && isset($_SESSION['auth_code'])) &&
+	$_SESSION['auth_code'] == OK)) {
+		
+  echo "<center>Your session has expired due to inactivity. Please <a href=\"index.html\">log in</a>.</center>\n";
+  exit();
+ }
+	
+// Clean out any old variables
+init();
+	
+///////////////////////////
+// Collect the form values
+	
+// List of request parameters to display
+$params_in           = get_param('params', $HTTP_GET_VARS);	
+	
+// The current state. E.g cart or results
+// Need to maintain this because other actions could be performed without changing state 
+$state            = get_param('state', $HTTP_GET_VARS);
+	
+// The selected action to perform. E.g. add observations to cart, or view profile
+$actions          = get_param('actions', $HTTP_GET_VARS);
+	
+// List of checked observations. Note: Not necessarily observations in the cart.
+// Cart observations are stored in $cart_items variable
+$selected_obs              = get_param('selected_obs', $HTTP_GET_VARS);
+	
+// A boolean value to indicate whether if the user wants to view cals as well
+$cals             = get_param('cals', $HTTP_GET_VARS);
+	
+// an array mapping observation number (corresponding to the index in all_results) 
+// to an array of matching cals
+$obs_cals = array();
+		
+// Display cals within this many minutes of the observation
+$cals_within_mins = get_param('cals_within_mins', $HTTP_GET_VARS);
+	
+// cart_items is an array of numbers that index to the list of 
+// results in all_results
+$cart_items          = $_SESSION['cart_items'];
+	
+	
+// this holds all the query results of observations as an array of
+// associative arrays. E.g.
+// array ( 0 => ( pulsar_name => 'J0437-4715',
+//                DM          => 10,
+//                period      => 1
+//              ),
+//
+//         1 => (pulsar_name => 'J0437-4715',
+//                DM          => 27,
+//                period      => 1.112
+//              )
+//       )
+//
+if (isset($_SESSION['results'])) {
+  $all_results = $_SESSION['results'];
+ }
+	
+	
+// Other form parameters. Pretty self explanatory?
+$pulsar_name      = trim(get_param('pulsar_name', $HTTP_GET_VARS));
+$data_type        = trim(get_param('data_type', $HTTP_GET_VARS));
+$survey           = trim(get_param('survey', $HTTP_GET_VARS));
+$raj              = trim(get_param('raj', $HTTP_GET_VARS));
+$decj             = trim(get_param('decj', $HTTP_GET_VARS));
+$radius           = trim(get_param('radius', $HTTP_GET_VARS));
+$from_day         = get_param('from_day', $HTTP_GET_VARS);
+$from_month       = get_param('from_month', $HTTP_GET_VARS);
+$from_year        = get_param('from_year', $HTTP_GET_VARS);
+$to_day           = get_param('to_day', $HTTP_GET_VARS);	
+$to_month         = get_param('to_month', $HTTP_GET_VARS);
+$to_year          = get_param('to_year', $HTTP_GET_VARS);
+	
+$startRange  = $HTTP_GET_VARS['startRange'];
+$endRange = $HTTP_GET_VARS['endRange'];	
+	
+$tar_file = "";
+
+$params = array();
+if($radius){ // if we have a conesearch query, add "distance" to the list of returned parameters"
+  $params[0] = "distance";
+ }
+for ($i=0; $i < count($params_in); $i++) {
+  array_push($params,$params_in[$i]);
+ }
+
+///////////////////////
+// Perform actions
+//
+// Precondition: The query has already been made, so the list of cals foreach observation
+// has already been determined ($_SESSION['obs_cals']).
+	
+if (isset($actions) && $actions != "") {
+  switch ($actions) {
+
+  case DOWNLOAD_ALL_OBS_CALS:
+
+    if (isset($cart_items) && isset($all_results)) {
+      //echo "Download all<br>\n";
+      $tar_file = tarObsCalFiles($cart_items, $all_results, $cals_within_mins);
+      echo " <meta http-equiv=\"REFRESH\" content=\"0; URL=".WEB_DOWNLOADS_DIR."/$tar_file\">\n";
+    }
+
+    break;
 				
-			case DOWNLOAD_ALL_OBS:
-
-				if (isset($cart_items) && isset($all_results)) {
-					//echo "Download all<br>\n";
-					$tar_file = tarObsFiles($cart_items, $all_results);
-					echo " <meta http-equiv=\"REFRESH\" content=\"0; URL=".WEB_DOWNLOADS_DIR."/$tar_file\">\n";
-				}
-
-				break;
-			
-			case DOWNLOAD_ALL_CALS:
-
-				if (isset($cart_items) && isset($all_results)) {
-					//echo "Download all<br>\n";
-					$tar_file = tarCalFiles($cart_items, $all_results, $cals_within_mins);
-					echo " <meta http-equiv=\"REFRESH\" content=\"0; URL=".WEB_DOWNLOADS_DIR."/$tar_file\">\n";
-				}
-
-				break;
-			
-			case VIEW_PROFILES:
+  case DOWNLOAD_ALL_OBS:
+
+    if (isset($cart_items) && isset($all_results)) {
+      //echo "Download all<br>\n";
+      $tar_file = tarObsFiles($cart_items, $all_results);
+      echo " <meta http-equiv=\"REFRESH\" content=\"0; URL=".WEB_DOWNLOADS_DIR."/$tar_file\">\n";
+    }
+
+    break;
+			
+  case DOWNLOAD_ALL_CALS:
+
+    if (isset($cart_items) && isset($all_results)) {
+      //echo "Download all<br>\n";
+      $tar_file = tarCalFiles($cart_items, $all_results, $cals_within_mins);
+      echo " <meta http-equiv=\"REFRESH\" content=\"0; URL=".WEB_DOWNLOADS_DIR."/$tar_file\">\n";
+    }
+
+    break;
+			
+  case VIEW_PROFILES:
 				
-				if (isset($selected_obs) && isset($all_results)) {
+    if (isset($selected_obs) && isset($all_results)) {
 					
-					// redirect to the view_profile page and pass through the selected_obs and obs_cals arrays
-					$_SESSION['selected_obs'] = $selected_obs;
-					$_SESSION['display_cals'] = false;
+      // redirect to the view_profile page and pass through the selected_obs and obs_cals arrays
+      $_SESSION['selected_obs'] = $selected_obs;
+      $_SESSION['display_cals'] = false;
 					
-					include_once("view_profiles.php");
-					exit;
-				}
-
-				break;
-			
-			case VIEW_PROFILES_CALS:
+      include_once("view_profiles.php");
+      exit;
+    }
+
+    break;
+			
+  case VIEW_PROFILES_CALS:
 				
-				if (isset($selected_obs) && isset($all_results)) {
+    if (isset($selected_obs) && isset($all_results)) {
 					
-					// redirect to the view_profile page and pass through the selected_obs and obs_cals arrays
-					$_SESSION['selected_obs'] = $selected_obs;
-					$_SESSION['display_cals'] = true;
+      // redirect to the view_profile page and pass through the selected_obs and obs_cals arrays
+      $_SESSION['selected_obs'] = $selected_obs;
+      $_SESSION['display_cals'] = true;
 					
-					include_once("view_profiles.php");
-					exit;
-				}
-
-				break;
-			
-			case REMOVE_FROM_CART:
-				if (isset($selected_obs)) {
-					if ($actions == REMOVE_FROM_CART) {
-						$cart_items = array_diff($cart_items, $selected_obs);
-					}
-				}
-				break;
-
-			case ADD_TO_CART:
-				if (isset($selected_obs)) {
-					foreach ($selected_obs as $ob) {
-						if (!in_array($ob, $cart_items)) {
-							array_push($cart_items, $ob);
-						}
-					}
-				}
-				break;
-		}
-	}
-	
-	if (!(isset($startRange) && isset($endRange))) {
-		
-		if ($HTTP_GET_VARS['submit_button'] == 'submit' || !(isset($_SESSION['start_range']) || isset($_SESSION['end_range']))) {
-			$startRange = 1;
-			$endRange = MAX_DISPLAY_ROWS;
-		}
-	
-		else {
-			$startRange = $_SESSION['start_range'];
-			$endRange = $_SESSION['end_range'];
-		}
-		
-	}
-	
-	if (!isset($cart_items)) {
-		$cart_items = array();
-	}
-	
-	
-	
-	$_SESSION['cart_items'] = $cart_items;
-	$_SESSION['start_range'] = $startRange;
-	$_SESSION['end_range'] = $endRange;
-	
-	//print_r($params);
-	//print_r ($selected_obs);
-	//print_r($_SESSION['cart_items']);
-	//echo "Number of elements in result array = " . count($_SESSION['results']);
-	//echo "<br>pulsar_name = $pulsar_name, data_type = $data_type
-	//      raj = $raj, decj = $decj, from: day = $from_day, month = $from_month
-	//	year = $from_year, to: day = $to_day, month = $to_month, year = $to_year<br>\n";
-	
-	//////////////////////////////////////////
-	// Initialise the output heading format
-	
-	$heading = "<th>&nbsp;</th><th>#</th>";
-	$raj_exists = false;
-	$decj_exists = false;
-	$raj_heading = "";
-	$decj_heading = "";
-	
-	if (!isset($params) && !isset($_SESSION['results'])) {
-		echo "No parameters were selected. Please select at least one.<br>\n";
-		exit;
-	}
-	
-	// Check if RA and Dec were queried
-	$flipped_parameters = array_flip($params);
-	
-	if (array_key_exists('raj_hour, raj_minute, raj_second', $flipped_parameters)) {
-		$raj_heading = "<th>RAJ</th>";
-		unset($flipped_parameters['raj_hour, raj_minute, raj_second']);
-		$raj_exists = true;
-	}
-	if (array_key_exists('decj_degree, decj_minute, decj_second', $flipped_parameters)) {
-		$decj_heading = "<th>DecJ</th>";
-		unset($flipped_parameters['decj_degree, decj_minute, decj_second']);
-		$decj_exists = true;
-	}
-	
-	foreach (array_keys($flipped_parameters) as $key) {
-		if (eregi("raj_", $key)) {
-			$raj_heading = "<th>RAJ</th>";
-			$raj_exists = true;
-		}
-		
-		else if (eregi("decj_", $key)) {
-			$decj_heading = "<th>DecJ</th>";
-			$decj_exists = true;
-		}
-		else {
-			$heading .= "<th>$key</th>";
-		}
-	}
-	
-	$heading .= $raj_heading.$decj_heading;
-
-	if (!isset($_SESSION['results']) || $HTTP_GET_VARS['submit_button'] == 'submit') {
-		
-		/////////////////////////////////////////////////////
-		// Form the parameter string in the SQL SELECT clause
-		$parameters = $params[0];
-
-		for ($i=1; $i < count($params); $i++) {
-			$parameters .= ", " . $params[$i];
-		}
-
-		// remove any leading and trailing commas
-		$parameters = trim($parameters, ",");
-
-
-		///////////////////////////////////////
-		// Convert gregorian day to julian day
-		//
-
-		$from_gregorian = strtotime("$from_month/$from_day/$from_year");
-		$to_gregorian = strtotime("$to_month/$to_day/$to_year");
-
-		$from_mjd = cal_to_jd (CAL_GREGORIAN, $from_month,  $from_day, $from_year ) - 2400000.5;//cal_to_jd ( $from_day, $from_month, $from_year ) - 2400000.5;
-		$to_mjd = cal_to_jd ( CAL_GREGORIAN, $to_month, $to_day, $to_year ) - 2400000.5;	//cal_to_jd ( $to_day, $to_month, $to_year ) - 2400000.5;	
-		
-
-		/////////////////////////////////////////
-		// Check that the user hasn't queried for data younger than 18 months
-		//
-		
-		if (!atnf_staff($_SESSION['username'])) {
-			echo "from_mjd = $from_mjd and to_mjd = $to_mjd<br>\n";
-
-			$today_mjd = cal_to_jd ( CAL_GREGORIAN, date("n"), date("j"), date("Y") ) - 2400000.5;
-		
-			if ($today_mjd - $from_mjd < 730) { // 2 * 365 days = 730 days
-		
-				echo "You're asking for data which has not aged past the 18 month proprietary period<br>\n";
-				echo "<META HTTP-EQUIV=\"Refresh\" CONTENT=\"5; URL=index.html?actions=error\">\n";
-				exit;
-			}
-		
-			// Set the end mjd date to the 18 months prior to current date
-			if ( $to_mjd > ($today_mjd - 730)) {
-				$to_mjd = $today_mjd - 730;
-			}
-		}
-		
-		//////////////////////////
-		// Convert the coordinates
-		//
-		$raj_degs = hms2degs($raj);
-		$dec_degs = dms2degs($decj);
-
-		///////////////////////////////
-		// Set up the query string
-		//
-
-		$whereString = "";
-
-		////////////////////////////
-		// Constraint on boundary
-
-		if ($radius) {
-			$boundary_option = "-boundary";
-			$radec_flag = "1";
-
-			putenv("PSRCAT_FILE=".PSRCAT_FILE);
-			$command = PSRCAT." -nohead -nonumber -c \"PSRJ\" -boundary \"$radec_flag $raj $decj $radius\"";
-			//echo "command = $command<br>\n";
-			exec($command, $output_array);
-
-			//echo "<pre>\n";
-			for ($i = 0; $i < count($output_array); $i++) {
-				list($output_psrname) = preg_split("/[\s]+/", $output_array[$i]);
-				//echo "$output_array[$i],$output_psrname \n";
-
-				// Remove the leading J and B
-				$output_psrname = ltrim($output_psrname, "JBbj");
-
-				$whereString .=  " OR pulsar_name LIKE '%$output_psrname'";
-			} 
-			$whereString = trim($whereString, "OR AND");
-			if ($whereString != "") {
-				$whereString = "($whereString)";
-			}
-			else {
-				echo "No pulsars found within ($raj, $decj) with radius $radius<br>\n";
-				exit;
-			}
-		}
-
-		////////////////////////////
-		// Constraint on data type
-
-		if ($data_type) {
-
-			$whereString .= " AND data_type = '$data_type'";
-		}
-
-		///////////////////////////
-		// Constraint on pulsar name
-		if ($pulsar_name) {
-
-			$whereString .= " AND pulsar_name LIKE '%$pulsar_name%'";
-		}
-
-		//////////////////////
-		// Constraint on MJD
-
-		$whereString .= " AND (MJD < $to_mjd AND MJD > $from_mjd)";
-
-		///////////////////////////////
-		// Performing SQL query
-		//
-
-		$link = db_connect();
-
-		// Remove any leading or trailing AND and OR
-		$whereString = trim($whereString, " AND OR");
-
-		$query = "SELECT * FROM ".OBSERVATIONS_TABLE." WHERE $whereString";
-
-		//echo "query = $query<br>\n";
-
-		$result = mysql_query($query) or die('Query failed: ' . mysql_error());
-
-		$all_results = array();
-
-		while ($line = mysql_fetch_assoc($result)) {
-			array_push($all_results, $line );
-		}
-		
-		$_SESSION['results'] = $all_results;
-	
-		mysql_free_result($result);
-
-	
-		mysql_close($link);
-	
-	}
-	
-	// Make a copy of it to pass to another function
-	$params_cpy = $params;
-
-	// Get the number of rows and report
-	$num_rows = count($all_results);
-	
-	// Calculate the total size of observations cart
-	$total_cart_size_bytes = 0;
-	
-	foreach ($cart_items as $row) {
-		$total_cart_size_bytes += $all_results[$row]['file_size_bytes'];		
-	}
-	
-	if ($state == 'cart') {
-		$num_display_rows = count($cart_items);
-	}
-	else {
-		$num_display_rows = $num_rows;
-	}
-	
-	if (!(isset($startRange) && isset($endRange))) {
-		$startRange = 1;
-		
-		
-		if ($endRange < MAX_DISPLAY_ROWS) {
-			$endRange = $num_display_rows;
-		}
-		else {
-			$endRange = MAX_DISPLAY_ROWS;
-		}
-	}
-	?>
+      include_once("view_profiles.php");
+      exit;
+    }
+
+    break;
+			
+  case REMOVE_FROM_CART:
+    if (isset($selected_obs)) {
+      if ($actions == REMOVE_FROM_CART) {
+	$cart_items = array_diff($cart_items, $selected_obs);
+      }
+    }
+    break;
+
+  case ADD_TO_CART:
+    if (isset($selected_obs)) {
+      foreach ($selected_obs as $ob) {
+	if (!in_array($ob, $cart_items)) {
+	  array_push($cart_items, $ob);
+	}
+      }
+    }
+    break;
+  }
+ }
+	
+if (!(isset($startRange) && isset($endRange))) {
+		
+  if ($HTTP_GET_VARS['submit_button'] == 'submit' || !(isset($_SESSION['start_range']) || isset($_SESSION['end_range']))) {
+    $startRange = 1;
+    $endRange = MAX_DISPLAY_ROWS;
+  }
+	
+  else {
+    $startRange = $_SESSION['start_range'];
+    $endRange = $_SESSION['end_range'];
+  }
+		
+ }
+	
+if (!isset($cart_items)) {
+  $cart_items = array();
+ }
+	
+	
+	
+$_SESSION['cart_items'] = $cart_items;
+$_SESSION['start_range'] = $startRange;
+$_SESSION['end_range'] = $endRange;
+	
+//print_r($params);
+//print_r ($selected_obs);
+//print_r($_SESSION['cart_items']);
+//echo "Number of elements in result array = " . count($_SESSION['results']);
+//echo "<br>pulsar_name = $pulsar_name, data_type = $data_type
+//      raj = $raj, decj = $decj, from: day = $from_day, month = $from_month
+//	year = $from_year, to: day = $to_day, month = $to_month, year = $to_year<br>\n";
+	
+//////////////////////////////////////////
+// Initialise the output heading format
+	
+$heading = "<th>&nbsp;</th><th>#</th>";
+// if($radius){ // if we have a conesearch query, add "distance" to the list of returned parameters"
+//   $heading .= "<th>Distance</th>";
+//  }
+
+$flipped_parameters = array_flip($params);
+foreach (array_keys($flipped_parameters) as $key) $heading .= "<th>$key</th>";
+
+
+if (!isset($params) && !isset($_SESSION['results'])) {
+  echo "No parameters were selected. Please select at least one.<br>\n";
+  exit;
+ }
+	
+if (!isset($_SESSION['results']) || $HTTP_GET_VARS['submit_button'] == 'submit') {
+		
+  /////////////////////////////////////////////////////
+  // Form the parameter string in the SQL SELECT clause
+  $parameters = $params_in[0];
+
+  for ($i=1; $i < count($params_in); $i++) {
+    $parameters .= ", " . $params_in[$i];
+  }
+
+  $parameters .= ",data_loc,file_size_bytes";
+
+  // remove any leading and trailing commas
+  $parameters = trim($parameters, ",");
+
+
+  ///////////////////////////////////////
+  // Convert gregorian day to julian day
+  //
+
+  $from_gregorian = strtotime("$from_month/$from_day/$from_year");
+  $to_gregorian = strtotime("$to_month/$to_day/$to_year");
+
+  $from_mjd = cal_to_jd (CAL_GREGORIAN, $from_month,  $from_day, $from_year ) - 2400000.5;//cal_to_jd ( $from_day, $from_month, $from_year ) - 2400000.5;
+  $to_mjd = cal_to_jd ( CAL_GREGORIAN, $to_month, $to_day, $to_year ) - 2400000.5;	//cal_to_jd ( $to_day, $to_month, $to_year ) - 2400000.5;	
+		
+
+  /////////////////////////////////////////
+  // Check that the user hasn't queried for data younger than 18 months
+  //
+		
+  if (!atnf_staff($_SESSION['username'])) {
+    echo "from_mjd = $from_mjd and to_mjd = $to_mjd<br>\n";
+
+    $today_mjd = cal_to_jd ( CAL_GREGORIAN, date("n"), date("j"), date("Y") ) - 2400000.5;
+		
+    if ($today_mjd - $from_mjd < 730) { // 2 * 365 days = 730 days
+		
+      echo "You're asking for data which has not aged past the 18 month proprietary period<br>\n";
+      echo "<META HTTP-EQUIV=\"Refresh\" CONTENT=\"5; URL=index.php?actions=error\">\n";
+      exit;
+    }
+		
+    // Set the end mjd date to the 18 months prior to current date
+    if ( $to_mjd > ($today_mjd - 730)) {
+      $to_mjd = $today_mjd - 730;
+    }
+  }
+		
+
+  ///////////////////////////////
+  // Set up the query string
+  //
+
+  $whereString = "";
+
+  ///////////////////////////
+  // Constraint on pulsar name
+  //
+  //  In this case, query on pulsar name and on pulsar position 
+  //       -- obtain the latter from PSRCAT
+  if ($pulsar_name) {
+
+    // Remove the leading J and B
+    $output_psrname = ltrim($output_psrname, "JBbj");
+
+    //    $command = PSRCAT." -nohead -nonumber -o short -c \"RAJD DECJD\" $pulsar_name";
+    $command = "psrcat-local -nohead -nonumber -o short -c \"RAJD DECJD\" $pulsar_name";
+    echo $command;
+    echo "<br>";
+    exec($command, $output_array);
+    $output_str = system($command);
+    echo exec("whoami")."<br>";
+    echo "Output of psrcat = ".$output_str."<br>";
+    //echo count($output_array)."<br>";
+    echo $output_array[0]."<br>".$output_array[1]."<br>\n";
+
+    $psr_raj = $output_array[0];
+    $psr_decj = $output_array[1];
+		  
+    $angsepString = "degrees( acos( cos(radians(rajd-$psr_raj))*cos(radians(decjd))*cos(radians($psr_decj))+sin(radians(decjd))*sin(radians($psr_decj))) )";
+		  
+    $whereString .= " AND ( (($angsepString - 0.25*(bmaj+bmin)) < ".PSR_SEARCH_RADIUS.") OR pulsar_name LIKE '%$output_psrname' )";
+  } 
+
+  ////////////////////////////
+  // Constraint on boundary
+
+  $selectString = "SELECT ";
+  if ($radius) {
+
+    $angsepString = "(degrees( acos( cos(radians(rajd-$raj))*cos(radians(decjd))*cos(radians($decj))+sin(radians(decjd))*sin(radians($decj))) ) )";
+		  
+    $whereString .= " AND (($angsepString - 0.25*(bmaj+bmin)) < $radius) ";
+		  
+    $selectString .= "$angsepString as distance, ";
+
+  }
+
+  $selectString .= $parameters;
+
+  ////////////////////////////
+  // Constraint on data type
+
+  if ($data_type) {
+
+    $whereString .= " AND data_type = '$data_type'";
+  }
+
+  ////////////////////////////
+  // Constraint on survey
+
+  if ($survey) {
+
+    $whereString .= " AND survey = '$survey'";
+  }
+
+  //////////////////////
+  // Constraint on MJD
+
+  $whereString .= " AND (MJD < $to_mjd AND MJD > $from_mjd)";
+
+  ///////////////////////////////
+  // Performing SQL query
+  //
+
+  $link = db_connect();
+  //$link = db_connect_admin();
+
+
+  // Remove any leading or trailing AND and OR
+  $whereString = trim($whereString, " AND OR");
+
+  // 		$query = "SELECT * FROM ".OBSERVATIONS_TABLE." WHERE $whereString";
+  $query = "( $selectString FROM s70 WHERE $whereString ) UNION ( $selectString FROM obs WHERE $whereString )";
+
+  if($radius) $query .= "  ORDER BY distance";
+
+  $result = mysql_query($query) or die('Query failed: ' . mysql_error());
+
+  $all_results = array();
+
+  while ($line = mysql_fetch_assoc($result)) {
+    array_push($all_results, $line );
+  }
+		
+  $_SESSION['results'] = $all_results;
+	
+  mysql_free_result($result);
+
+  mysql_close($link);
+	
+ }
+	
+// Make a copy of it to pass to another function
+$params_cpy = $params;
+
+// Get the number of rows and report
+$num_rows = count($all_results);
+	
+// Calculate the total size of observations cart
+$total_cart_size_bytes = 0;
+	
+foreach ($cart_items as $row) {
+  $total_cart_size_bytes += $all_results[$row]['file_size_bytes'];		
+}
+	
+if ($state == 'cart') {
+  $num_display_rows = count($cart_items);
+ }
+ else {
+   $num_display_rows = $num_rows;
+ }
+	
+if (!(isset($startRange) && isset($endRange))) {
+  $startRange = 1;
+		
+		
+  if ($endRange < MAX_DISPLAY_ROWS) {
+    $endRange = $num_display_rows;
+  }
+  else {
+    $endRange = MAX_DISPLAY_ROWS;
+  }
+ }
+?>
 <form action="<?php echo $PHP_SELF; ?>" method="GET" id="frmResults">
-<input type="hidden" name="startRange" value="<?php echo $startRange;?>">
-<input type="hidden" name="endRange" value="<?php echo $endRange;?>">
-
-
-<table class="top_menu" border="0" id="tabQueryResults">
-	<?php if ($state == 'cart') { ?>
-		<tr class="top_menu"><td class="top_menu_heading" colspan="4"><h2>Observations Cart</h2></td></tr>
-	<?php } else if ($state == 'results') { ?>
-		<tr class="top_menu"><td class="top_menu_heading" colspan="4"><h2>Query Results</h2></td></tr>
-	<?php } ?>
-
-		<tr class="top_menu"><td class="top_menu"  align="left" width="30%"><a class="top_menu" href="index.html?command=logout">Logout</a> | 
-		<a class="top_menu" href="change_password.html?prev_page=<?php echo $PHP_SELF;?>">Change Password</a> |
-		<a class="top_menu" href="index.html?actions=new_query">New Query</a>
-</td>
-		<td class="top_menu" width="50%" align="center">
-			Actions: <select name="actions">
-		<?php if ($state == 'cart') { ?>
-
-			<?php 
+  <input type="hidden" name="startRange" value="<?php echo $startRange;?>">
+  <input type="hidden" name="endRange" value="<?php echo $endRange;?>">
+
+
+  <table class="top_menu" border="0" id="tabQueryResults">
+  <?php if ($state == 'cart') { ?>
+				<tr class="top_menu"><td class="top_menu_heading" colspan="4"><h2>Observations Cart</h2></td></tr>
+				<?php } else if ($state == 'results') { ?>
+  <tr class="top_menu"><td class="top_menu_heading" colspan="4"><h2>Query Results</h2></td></tr>
+    <?php } ?>
+
+    <tr class="top_menu"><td class="top_menu"  align="left" width="30%"><a class="top_menu" href="index.php?command=logout">Logout</a> | 
+  <a class="top_menu" href="change_password.html?prev_page=<?php echo $PHP_SELF;?>">Change Password</a> |
+  <a class="top_menu" href="index.php?actions=new_query">New Query</a>
+  </td>
+  <td class="top_menu" width="50%" align="center">
+  Actions: <select name="actions">
+  <?php if ($state == 'cart') { ?>
+
+				<?php 
 				if ($total_cart_size_bytes/1000000 < MAX_DOWNLOAD_MB) {
-					echo "<option>".DOWNLOAD_ALL_OBS_CALS."</option>\n";
-					echo "<option>".DOWNLOAD_ALL_OBS."</option>\n";
-					echo "<option>".DOWNLOAD_ALL_CALS."</option>\n";
+				  echo "<option>".DOWNLOAD_ALL_OBS_CALS."</option>\n";
+				  echo "<option>".DOWNLOAD_ALL_OBS."</option>\n";
+				  echo "<option>".DOWNLOAD_ALL_CALS."</option>\n";
 				}
 				else {
-					echo "<option disabled>Download limit ".MAX_DOWNLOAD_MB."MB exceeded</option>\n";
+				  echo "<option disabled>Download limit ".MAX_DOWNLOAD_MB."MB exceeded</option>\n";
 				}
-			?>
-			</option>
-			<option><?php echo REMOVE_FROM_CART; ?></option>
-			</select>
-			<input type="submit" value="Perform action">
-			</td>
-			<td class="top_menu" align="right"><b><?php echo count($cart_items); ?></b>
-			Item/s (<?php printf("%.1f MB", $total_cart_size_bytes/1000000);?>)</td>
-			<td class="top_menu" align="right" width="1%"><a href="<?php echo $PHP_SELF;?>?state=results&startRange=1&endRange=<?php echo MAX_DISPLAY_ROWS; ?>">
-			<img alt="Revert to query results" border="0" title="Revert to query results" src="images/table_30px_white.png"></img></a>
-			</td>
-		<?php } else { ?>
-			<option><?php echo ADD_TO_CART; ?></option>
-			<option>----- Profile Viewing Options -----</option>
-			<option><?php echo VIEW_PROFILES; ?></option>
-			<?php 
-			   echo "cals = $cals<br>\n";
-			   if (isset($cals) && $cals != "") {
-				echo "<option>".VIEW_PROFILES_CALS."</option>\n";
-			   }
-			?>
-			</select>
-			<input type="submit" value="Perform action">
-			</td>
-			<td class="top_menu" align="right" width="20%"><b><?php echo count($cart_items); ?></b>
-			<a href="<?php echo $PHP_SELF;?>?state=cart&startRange=1&endRange=<?php echo count($cart_items); ?>">Item/s</a> (<?php printf("%.1f MB", $total_cart_size_bytes/1000000);?>)</td>
-			<td class="top_menu" align="right" width="1%"><a href="<?php echo $PHP_SELF;?>?state=cart&startRange=1&endRange=<?php echo count($cart_items); ?>">
-			<img alt="View observation cart" border="0" title="View observation cart" src="images/cart_30px_white.png"></img></a>
-			</td>
-		<?php } ?>
-		</tr></table>
-<?php	
-
-	if ($num_display_rows == 0) {
-		echo "<center>Sorry, no results matched your search</center><br>\n";
-		echo "<center><a href=\"index.html\">Search again</a></center><br>\n";
-		exit();
-	}
-	
-	echo "<center>\n";
-	printNavigate($startRange, $num_display_rows);
-	echo "</center>\n";				
-	
-	
-	if ($num_display_rows < $endRange) {
-		echo "Showing <b>$startRange - $num_display_rows</b> of <b>$num_display_rows</b> rows\n";
-	}
-	else {
-		echo "Showing <b>$startRange - $endRange</b> of <b>$num_display_rows</b> rows\n";
-	}
-	
-	
-	// TODO: Is this a better way to do it?
-	//if (mysql_data_seek($result, $startRange);
-
-	// Show first few
-	//print_r($all_results);
-	showTable($startRange-1, $endRange-1, $heading, $all_results, $params_cpy, $cals, $cals_within_mins);
-	
-
-	echo "<center>\n";
-	printNavigate($startRange, $num_display_rows);
-	echo "</center>\n";
-	
-	//echo "count all results = " . count($all_results);
+				?>
+				</option>
+				<option><?php echo REMOVE_FROM_CART; ?></option>
+				</select>
+				<input type="submit" value="Perform action">
+				</td>
+				<td class="top_menu" align="right"><b><?php echo count($cart_items); ?></b>
+				Item/s (<?php printf("%.1f MB", $total_cart_size_bytes/1000000);?>)</td>
+				<td class="top_menu" align="right" width="1%"><a href="<?php echo $PHP_SELF;?>?state=results&startRange=1&endRange=<?php echo MAX_DISPLAY_ROWS; ?>">
+				<img alt="Revert to query results" border="0" title="Revert to query results" src="/images/table_30px_white.png"></img></a>
+				</td>
+				<?php } else { ?>
+  <option><?php echo ADD_TO_CART; ?></option>
+					<option>----- Profile Viewing Options -----</option>
+					<option><?php echo VIEW_PROFILES; ?></option>
+										<?php 
+										echo "cals = $cals<br>\n";
+  if (isset($cals) && $cals != "") {
+    echo "<option>".VIEW_PROFILES_CALS."</option>\n";
+  }
+
+  echo "</select>\n";
+  echo "<input type=\"submit\" value=\"Perform action\">\n";
+  echo "</td>\n";
+  echo "<td class=\"top_menu\" align=\"right\" width=\"20%\"><b>".count($cart_items)."</b>\n";
+  echo "<a href=\"".$PHP_SELF."?state=cart&startRange=1&endRange=".count($cart_items)."\">Item/s</a> (".printf("%.1f MB", $total_cart_size_bytes/1000000).")</td>\n";
+  echo "<td class=\"top_menu\" align=\"right\" width=\"1%\"><a href=\"".$PHP_SELF."?state=cart&startRange=1&endRange=".count($cart_items)."\">\n";
+  echo "<img alt=\"View observation cart\" border=\"0\" title=\"View observation cart\" src=\"/images/cart_30px_white.png\"></img></a>\n";
+  echo "</td>\n";
+ }
+echo "</tr></table>\n";
+
+if ($num_display_rows == 0) {
+  echo "<center>Sorry, no results matched your search</center><br>\n";
+  echo "<center><a href=\"index.php\">Search again</a></center><br>\n";
+  exit();
+ }
+
+echo "<center>\n";
+printNavigate($startRange, $num_display_rows);
+echo "</center>\n";				
+	
+	
+if ($num_display_rows < $endRange) {
+  echo "Showing <b>$startRange - $num_display_rows</b> of <b>$num_display_rows</b> rows\n";
+ }
+ else {
+   echo "Showing <b>$startRange - $endRange</b> of <b>$num_display_rows</b> rows\n";
+ }
+	
+	
+// TODO: Is this a better way to do it?
+//if (mysql_data_seek($result, $startRange);
+
+// Show first few
+//print_r($all_results);
+showTable($startRange-1, $endRange-1, $heading, $all_results, $params_cpy, $cals, $cals_within_mins);
+	
+
+echo "<center>\n";
+printNavigate($startRange, $num_display_rows);
+echo "</center>\n";
+	
+//echo "count all results = " . count($all_results);
+	
 
 
@@ -569,70 +564,70 @@
 <?php
 
-///////////////////////////////////////////////////////////////////////////////////////////////
-//
-// Function definitions
-// --------------------
-//
-///////////////////////////////////////////////////////////////////////////////////////////////
-
-// The page navigator
+  ///////////////////////////////////////////////////////////////////////////////////////////////
+  //
+  // Function definitions
+  // --------------------
+  //
+  ///////////////////////////////////////////////////////////////////////////////////////////////
+
+  // The page navigator
 function printNavigate($startRange, $num_rows) {
 
-	// Collect the form values
-	global $params, $pulsar_name,	$data_type,
-	$raj,	$decj,$radius, $from_day,	$from_month, $from_year,
-	$to_day, $to_month, $to_year, $state, $cals;
-	
-	if (isset($params)) {
-		$params_str = array2urlstring("params", $params);
-	}
-		
-	$num_pages = ceil($num_rows/MAX_DISPLAY_ROWS);
-	
-	$startPage = ($startRange-1)/MAX_DISPLAY_ROWS;
-	
-	$startPageRange = floor($startPage / MAX_DISPLAY_PAGES) * MAX_DISPLAY_PAGES;
-	
-	// Print the previous button
-	if ($startPageRange > 0) {
-		$prevStartRange = ($startPageRange - 1)*MAX_DISPLAY_ROWS + 1;
-		$prevEndRange = $prevStartRange + MAX_DISPLAY_ROWS - 1;
-		echo "<a href=\"$PHP_SELF?startRange=$prevStartRange&endRange=$prevEndRange&$params_str&cals=$cals&pulsar_name=$pulsar_name&data_type=$data_type&raj=$raj&decj=$decj&radius=$radius&from_day=$from_day&from_month=$from_month&from_year=$from_year&to_day=$to_day&to_month=$to_month&to_year=$to_year&state=$state\"><< Prev 10</a> &nbsp;\n";
-	}
-	
-	for ($i=$startPageRange; $i < $num_pages && $i - $startPageRange <= MAX_DISPLAY_PAGES; $i++) {
-		$start = $i*MAX_DISPLAY_ROWS + 1;
-		$end = $start + MAX_DISPLAY_ROWS - 1;
-		
-		if ($end > $num_rows) {
-			$end = $num_rows;
-		}
-		
-		if ($startRange == $start) {
-			echo "<b>".($i+1)."</b> &nbsp;\n";
-		}
-		// When the page index has reached the maximum range, print the next button
-		else if ($i - $startPageRange == MAX_DISPLAY_PAGES ) {
-			echo " <a href=\"$PHP_SELF?startRange=$start&endRange=$end&$params_str&cals=$cals&pulsar_name=$pulsar_name&data_type=$data_type&raj=$raj&decj=$decj&radius=$radius&from_day=$from_day&from_month=$from_month&from_year=$from_year&to_day=$to_day&to_month=$to_month&to_year=$to_year&state=$state\">Next 10 >></a> \n";
-		
-		}
-		else {
-			echo " <a href=\"$PHP_SELF?startRange=$start&endRange=$end&$params_str&cals=$cals&pulsar_name=$pulsar_name&data_type=$data_type&raj=$raj&decj=$decj&radius=$radius&from_day=$from_day&from_month=$from_month&from_year=$from_year&to_day=$to_day&to_month=$to_month&to_year=$to_year&state=$state\">".($i+1)."</a> &nbsp;\n";
-		}
-	}
-	
-}
+  // Collect the form values
+  global $params_in, $pulsar_name,	$data_type,
+    $raj,	$decj,$radius, $from_day,	$from_month, $from_year,
+    $to_day, $to_month, $to_year, $state, $cals;
+	
+  if (isset($params)) {
+    $params_str = array2urlstring("params", $params_in);
+  }
+		
+  $num_pages = ceil($num_rows/MAX_DISPLAY_ROWS);
+	
+  $startPage = ($startRange-1)/MAX_DISPLAY_ROWS;
+	
+  $startPageRange = floor($startPage / MAX_DISPLAY_PAGES) * MAX_DISPLAY_PAGES;
+	
+  // Print the previous button
+  if ($startPageRange > 0) {
+    $prevStartRange = ($startPageRange - 1)*MAX_DISPLAY_ROWS + 1;
+    $prevEndRange = $prevStartRange + MAX_DISPLAY_ROWS - 1;
+    echo "<a href=\"$PHP_SELF?startRange=$prevStartRange&endRange=$prevEndRange&$params_str&cals=$cals&pulsar_name=$pulsar_name&data_type=$data_type&raj=$raj&decj=$decj&radius=$radius&from_day=$from_day&from_month=$from_month&from_year=$from_year&to_day=$to_day&to_month=$to_month&to_year=$to_year&state=$state\"><< Prev 10</a> &nbsp;\n";
+  }
+	
+  for ($i=$startPageRange; $i < $num_pages && $i - $startPageRange <= MAX_DISPLAY_PAGES; $i++) {
+    $start = $i*MAX_DISPLAY_ROWS + 1;
+    $end = $start + MAX_DISPLAY_ROWS - 1;
+		
+    if ($end > $num_rows) {
+      $end = $num_rows;
+    }
+		
+    if ($startRange == $start) {
+      echo "<b>".($i+1)."</b> &nbsp;\n";
+    }
+    // When the page index has reached the maximum range, print the next button
+    else if ($i - $startPageRange == MAX_DISPLAY_PAGES ) {
+      echo " <a href=\"$PHP_SELF?startRange=$start&endRange=$end&$params_str&cals=$cals&pulsar_name=$pulsar_name&data_type=$data_type&raj=$raj&decj=$decj&radius=$radius&from_day=$from_day&from_month=$from_month&from_year=$from_year&to_day=$to_day&to_month=$to_month&to_year=$to_year&state=$state\">Next 10 >></a> \n";
+		
+    }
+    else {
+      echo " <a href=\"$PHP_SELF?startRange=$start&endRange=$end&$params_str&cals=$cals&pulsar_name=$pulsar_name&data_type=$data_type&raj=$raj&decj=$decj&radius=$radius&from_day=$from_day&from_month=$from_month&from_year=$from_year&to_day=$to_day&to_month=$to_month&to_year=$to_year&state=$state\">".($i+1)."</a> &nbsp;\n";
+    }
+  }
+	
+  }
 
 function showTable($startRange, $endRange, $heading, $all_results, $params, $cals, $cals_within_mins) {
-	global $state, $cart_items, $obs_cals;
-	
-	//echo "showTable: state = $state, startRange = $startRange, endRange = $endRange<br>\n";
-	
-	$link = db_connect();
-
-	// Printing results in HTML
-	echo "<table cellpadding=\"5\">\n";
-
-	echo "<thead class=\"file-headings\">
+  global $state, $cart_items, $obs_cals;
+	
+  //echo "showTable: state = $state, startRange = $startRange, endRange = $endRange<br>\n";
+	
+  $link = db_connect();
+
+  // Printing results in HTML
+  echo "<table cellpadding=\"5\">\n";
+
+  echo "<thead class=\"file-headings\">
 					<tr>
 						$heading
@@ -640,239 +635,243 @@
 				</thead>\n";
 	
-	if (!isset($params)) {
-		echo "No params were selected. Please select at least one.<br>\n";
-	}
-	
-	$index = $startRange;
-	
-	// For each row in the observations results, print it out as a table
-	// and append any matching cals if requested
-	// 
-	// obs_cals is a hash table with key = the index of the observation
-	// and value = an array of cal results
-	for ($i=$startRange; ($i < count($all_results) && $index <= $endRange); $i++) {
-
-		$row_html_unchecked = "\t<td class=\"result_row\">
+  if (!isset($params)) {
+    echo "No params were selected. Please select at least one.<br>\n";
+  }
+	
+  $index = $startRange;
+	
+  // For each row in the observations results, print it out as a table
+  // and append any matching cals if requested
+  // 
+  // obs_cals is a hash table with key = the index of the observation
+  // and value = an array of cal results
+  for ($i=$startRange; ($i < count($all_results) && $index <= $endRange); $i++) {
+
+    if(($params[$i]!="data_loc")&&($params[$i]!="file_size_bytes")){
+
+      $row_html_unchecked = "\t<td class=\"result_row\">
 					<input id=\"chkSelect-$i\"  type=\"checkbox\" name=\"selected_obs[]\" value=\"$i\" />
 					<span class=\"glyph\" id=\"spaToggle-$i\"></span>
 					</td>\n";
 	
-		$row_html_checked = "\t<td class=\"result_row\">
+      $row_html_checked = "\t<td class=\"result_row\">
 					<input id=\"chkSelect-$i\" type=\"checkbox\" name=\"selected_obs[]\" value=\"$i\" checked=\"true\" />
 					<span class=\"glyph\" id=\"spaToggle-$i\"></span>
 					</td>\n";
 
-		$line = $all_results[$i];
-		
-		// Print the checkbox column
-		if ($state == 'cart') {
-			if (in_array($i, $cart_items)) {
-				if ($index % 2 == 0) {
-					echo "<tbody class=\"even\">\n";
-				}
-				else {
-					echo "<tbody class=\"odd\">\n";
-				}
-	  			echo "\t<tr>\n";
-				echo $row_html_checked;
-
-				// Makes the values of array the keys (index)
-				// Guaranteed that values are unique so it's OK
-				//$flipped_cart = array_flip($cart_items);
+      $line = $all_results[$i];
+		
+      // Print the checkbox column
+      if ($state == 'cart') {
+	if (in_array($i, $cart_items)) {
+	  if ($index % 2 == 0) {
+	    echo "<tbody class=\"even\">\n";
+	  }
+	  else {
+	    echo "<tbody class=\"odd\">\n";
+	  }
+	  echo "\t<tr>\n";
+	  echo $row_html_checked;
+
+	  // Makes the values of array the keys (index)
+	  // Guaranteed that values are unique so it's OK
+	  //$flipped_cart = array_flip($cart_items);
 				
-				//$cart_index = $flipped_cart[$i];
-			}
-			else {
-				continue;
-			}
-		}
-		else {			
-			if ($index % 2 == 0) {
-				echo "<tbody class=\"even\">\n";
-			}
-			else {
-				echo "<tbody class=\"odd\">\n";
-			}
+	  //$cart_index = $flipped_cart[$i];
+	}
+	else {
+	  continue;
+	}
+      }
+      else {			
+	if ($index % 2 == 0) {
+	  echo "<tbody class=\"even\">\n";
+	}
+	else {
+	  echo "<tbody class=\"odd\">\n";
+	}
 	  	
-			echo "\t<tr>\n";
-
-			if (in_array($i, $cart_items)) {
-				echo $row_html_checked;
-			}
-			
-			else {
-				echo $row_html_unchecked;
-			}
-		}
-		
-		// Query for cals
-		$all_cals = array();
-		
-		if (isset($cals) && $cals != "") {
-			$num_params = count($params);
-			
-			//echo "\t<tr class=\"extra-detail\">\n";
-			
-			$all_cals = query_cals($line['pulsar_name'], $line['MJD'], $line['data_type'], $cals_within_mins);
-			
-			// Set the obs_cals array
-			if (count($obs_cals) == 0) {
-				$obs_cals = array($index => $all_cals);
-			}
-			else {
-				array_push($obs_cals, $all_cals);
-			}
-			
-			//echo "\t</tr>\n";
-		}
-		
-		
-		///////////////////
-		// Display the row
-		echo "\t<td class=\"result_row\" align=\"right\">".($index+1)."</td>\n";	
+	echo "\t<tr>\n";
+
+	if (in_array($i, $cart_items)) {
+	  echo $row_html_checked;
+	}
+			
+	else {
+	  echo $row_html_unchecked;
+	}
+      }
+		
+      // Query for cals
+      $all_cals = array();
+		
+      if (isset($cals) && $cals != "") {
+	$num_params = count($params);
+			
+	//echo "\t<tr class=\"extra-detail\">\n";
+			
+	//	$all_cals = query_cals($line['pulsar_name'], $line['MJD'], $line['data_type'], $cals_within_mins);
+	$all_cals = query_cals($line['src_name'], $line['MJD'], $line['data_type'], $cals_within_mins);
+			
+	// Set the obs_cals array
+	if (count($obs_cals) == 0) {
+	  $obs_cals = array($index => $all_cals);
+	}
+	else {
+	  array_push($obs_cals, $all_cals);
+	}
+			
+	//echo "\t</tr>\n";
+      }
+		
+		
+      ///////////////////
+      // Display the row
+      echo "\t<td class=\"result_row\" align=\"right\">".($index+1)."</td>\n";	
 		
 				
-  		foreach ($params as $param) {
-			if (eregi("raj_", $param) || eregi("decj_", $param)) {
-				continue;
-			}
-
-			print_param($line, $param);
-
-     			echo "</td>\n";
-  		}
-		//print_r($params);
-		
-		print_ra_dec($line, $params);
+      foreach ($params as $param) {
+	if (eregi("raj_", $param) || eregi("decj_", $param)) {
+	  continue;
+	}
+
+	print_param($line, $param);
+
+	echo "</td>\n";
+      }
+      //print_r($params);
+		
+      //     print_ra_dec($line, $params);
 				
-		echo "\t</tr>\n";
-		
-		print_cals_row($all_cals, $params);
-			
-		// End the row
-		
-		echo "\t</tbody>\n";
-
-		//echo "Printing obs_cals<br><pre>\n";
-		//print_r($obs_cals);
-		//echo "</pre>\n";
-
-		$index++;
-	}
-	echo "</table>\n";
-	
-	// By now all cals for each observation have been determined, so set the obs_cals session variable
-	$_SESSION['obs_cals'] = $obs_cals;
-	
-	mysql_close($link);
+      echo "\t</tr>\n";
+		
+      print_cals_row($all_cals, $params);
+			
+      // End the row
+		
+      echo "\t</tbody>\n";
+
+      //echo "Printing obs_cals<br><pre>\n";
+      //print_r($obs_cals);
+      //echo "</pre>\n";
+
+      $index++;
+    }
+  }
+  echo "</table>\n";
+	
+  // By now all cals for each observation have been determined, so set the obs_cals session variable
+  $_SESSION['obs_cals'] = $obs_cals;
+	
+  mysql_close($link);
 }
 
 function print_cals_row($all_cals, $params) {
 
-	for ($i=0; $i < count($all_cals); $i++) {
-		
-		$line = $all_cals[$i];
-		
-		echo "\t\t<tr class=\"result_row\">\n";
-		echo "\t\t<td class=\"result_row\" colspan=\"2\">&nbsp;</td>\n";
-
-  		foreach ($params as $param) {
-			if (eregi("raj_", $param) || eregi("decj_", $param)) {
-				continue;
-			}
-
- 			print_param($line,$param);
-  		}
-		print_ra_dec($line, $params);
+  for ($i=0; $i < count($all_cals); $i++) {
+		
+    $line = $all_cals[$i];
+		
+    echo "\t\t<tr class=\"result_row\">\n";
+    echo "\t\t<td class=\"result_row\" colspan=\"2\">&nbsp;</td>\n";
+
+    foreach ($params as $param) {
+      if (eregi("raj_", $param) || eregi("decj_", $param)) {
+	continue;
+      }
+
+      print_param($line,$param);
+    }
+//     print_ra_dec($line, $params);
 					
-		echo "\t\t</tr>\n";	
-	}
+    echo "\t\t</tr>\n";	
+  }
 }
 
 function print_ra_dec ($result_row, $params) {
 
-	if (in_array('raj_hour,raj_minute,raj_second', $params)) {
-		$raj_str = sprintf("%02d",$result_row['raj_hour']).":".sprintf("%02d",$result_row['raj_minute']).":". sprintf("%02.3f",$result_row['raj_second']);
-		echo "\t\t<td class=\"result_row\">$raj_str</td>\n";
-	}
-
-	if (in_array('decj_degree,decj_minute,decj_second', $params)) {
-		$decj_str = sprintf("%02d",$result_row['decj_degree']).":".sprintf("%02d",$result_row['decj_minute']).":". sprintf("%02.3f",$result_row['decj_second']);
-		echo "\t\t<td class=\"result_row\">$decj_str</td>\n";
-	}		
+  if (in_array('raj_hour,raj_minute,raj_second', $params)) {
+    $raj_str = sprintf("%02d",$result_row['raj_hour']).":".sprintf("%02d",$result_row['raj_minute']).":". sprintf("%02.3f",$result_row['raj_second']);
+    echo "\t\t<td class=\"result_row\">$raj_str</td>\n";
+  }
+
+  if (in_array('decj_degree,decj_minute,decj_second', $params)) {
+    $decj_str = sprintf("%02d",$result_row['decj_degree']).":".sprintf("%02d",$result_row['decj_minute']).":". sprintf("%02.3f",$result_row['decj_second']);
+    echo "\t\t<td class=\"result_row\">$decj_str</td>\n";
+  }		
 
 }
 
 function print_param($result_row, $param) {
-	/////// Perform formatting specific to the data ///////
-
-	if ($result_row[$param] == "" ) {
-		echo "\t\t<td class=\"result_row\">";
-		echo "&nbsp;";
-	}
-	else {
-		switch ($param) {
-		case PERIOD:
-			echo "\t\t<td class=\"result_row\" align=\"right\">";
-			printf("%.16f", $result_row[$param]);
-			break;
-
-		case DM:
-			echo "\t\t<td class=\"result_row\" align=\"right\">";
-			printf("%.5f", $result_row[$param]);
-			break;
-
-		case FREQUENCY:
-			echo "\t\t<td class=\"result_row\" align=\"right\">";
-			printf("%.3f", $result_row[$param]);
-			break;
-		case MJD:
-			echo "\t\t<td class=\"result_row\" align=\"right\">";
-			printf("%.6f", $result_row[$param]);
-			break;
-		case BW:
-			echo "\t\t<td class=\"result_row\" align=\"right\">";
-			printf("%.3f", $result_row[$param]);
-			break;
-		case LENGTH:
-			echo "\t\t<td class=\"result_row\" align=\"right\">";
-			printf("%.3f", $result_row[$param]);
-			break;
-		case NSUB:
-			echo "\t\t<td class=\"result_row\" align=\"right\">";
-			printf("%d", $result_row[$param]);
-			break;
-		case NBIN:
-			echo "\t\t<td class=\"result_row\" align=\"right\">";
-			printf("%d", $result_row[$param]);
-			break;
-		case FILESIZE:
-			echo "\t\t<td class=\"result_row\" align=\"right\">";
-			printf("%d", $result_row[$param]);
-			break;
-		case TSAMP:
-			echo "\t\t<td class=\"result_row\" align=\"right\">";
-			printf("%.6f", $result_row[$param]);
-			break;
-		case NBEAM:
-			echo "\t\t<td class=\"result_row\" align=\"right\">";
-			printf("%d", $result_row[$param]);
-			break;
-		default:
-			echo "\t\t<td class=\"result_row\">";
-			echo $result_row[$param];
-		}
-	}
+  /////// Perform formatting specific to the data ///////
+
+  if ($result_row[$param] == "" ) {
+    echo "\t\t<td class=\"result_row\">";
+    echo "&nbsp;";
+  }
+  else {
+    switch ($param) {
+    case PERIOD:
+      echo "\t\t<td class=\"result_row\" align=\"right\">";
+      printf("%.16f", $result_row[$param]);
+      break;
+
+    case DM:
+      echo "\t\t<td class=\"result_row\" align=\"right\">";
+      printf("%.5f", $result_row[$param]);
+      break;
+
+    case FREQUENCY:
+      echo "\t\t<td class=\"result_row\" align=\"right\">";
+      printf("%.3f", $result_row[$param]);
+      break;
+    case MJD:
+      echo "\t\t<td class=\"result_row\" align=\"right\">";
+      printf("%.6f", $result_row[$param]);
+      break;
+    case BW:
+      echo "\t\t<td class=\"result_row\" align=\"right\">";
+      printf("%.3f", $result_row[$param]);
+      break;
+    case LENGTH:
+      echo "\t\t<td class=\"result_row\" align=\"right\">";
+      printf("%.3f", $result_row[$param]);
+      break;
+    case NSUB:
+      echo "\t\t<td class=\"result_row\" align=\"right\">";
+      printf("%d", $result_row[$param]);
+      break;
+    case NBIN:
+      echo "\t\t<td class=\"result_row\" align=\"right\">";
+      printf("%d", $result_row[$param]);
+      break;
+    case FILESIZE:
+      echo "\t\t<td class=\"result_row\" align=\"right\">";
+      printf("%d", $result_row[$param]);
+      break;
+    case TSAMP:
+      echo "\t\t<td class=\"result_row\" align=\"right\">";
+      printf("%.6f", $result_row[$param]);
+      break;
+    case NBEAM:
+      echo "\t\t<td class=\"result_row\" align=\"right\">";
+      printf("%d", $result_row[$param]);
+      break;
+    default:
+      echo "\t\t<td class=\"result_row\">";
+      echo $result_row[$param];
+    }
+  }
 }
 
 // Initialise the input form variables
 function init() {
-	global $actions, $selected_obs;
-	
-	unset($actions);
-	unset($selected_obs);
-
-	unset($_SESSION['selected_obs']);
-	unset($_SESSION['actions']);
+  global $actions, $selected_obs;
+	
+  unset($actions);
+  unset($selected_obs);
+
+  unset($_SESSION['selected_obs']);
+  unset($_SESSION['actions']);
 }
 
Index: /trunk/htdocs/utils.php
===================================================================
--- /trunk/htdocs/utils.php	(revision 161)
+++ /trunk/htdocs/utils.php	(revision 162)
@@ -46,20 +46,20 @@
 		
 		// Query for all the respective cals
-		$all_cals = query_cals( $all_results[$index]['pulsar_name'],  $all_results[$index]['MJD'],  $all_results[$index]['data_type'], $cals_within_mins);
+		//		$all_cals = query_cals( $all_results[$index]['pulsar_name'],  $all_results[$index]['MJD'],  $all_results[$index]['data_type'], $cals_within_mins);
+		$all_cals = query_cals( $all_results[$index]['src_name'],  $all_results[$index]['MJD'],  $all_results[$index]['data_type'], $cals_within_mins);
 		
 		
 		// Need to create a symlink first because may not have write
 		// access to the directory
-		if (!file_exists(WORKING_DIR."/$pulsar_name.$file")) {
-			echo WORKING_DIR."$pulsar_name.$file doesn't exist<br>\n";
+		if (!file_exists(WORKING_DIR."/$file")) {
+			echo WORKING_DIR."$file doesn't exist<br>\n";
 			if (file_exists("$dir/$file")) {
 				echo "$dir/$file exists<br>\n";
-				#if (symlink ("$dir/$file", WORKING_DIR."/$pulsar_name.$file")) {
-				if (symlink ("$dir/$file", WORKING_DIR."/$pulsar_name.$file")) {
+				if (symlink ("$dir/$file", WORKING_DIR."/$file")) {
 					echo "Successfully created symlink!<br>\n";
 				}
 			}
 		}
-		$all_files .= " $pulsar_name.$file";
+		$all_files .= " $pulsar_name"."$file";
 		foreach ($all_cals as $cal) {
 			$cal_file = $cal['filename'];
@@ -67,15 +67,14 @@
 			$cal_pulsar_name = $cal['pulsar_name'];
 
-			if (!file_exists(WORKING_DIR."/$cal_pulsar_name.$cal_file")) {
-				echo WORKING_DIR."$cal_pulsar_name.$cal_file doesn't exist<br>\n";
+			if (!file_exists(WORKING_DIR."/$cal_file")) {
+				echo WORKING_DIR."$cal_file doesn't exist<br>\n";
 				if (file_exists("$cal_dir/$cal_file")) {
 					echo "$dir/$file exists<br>\n";
-					#if (symlink ("$dir/$file", WORKING_DIR."/$pulsar_name.$file")) {
-					if (symlink ("$cal_dir/$cal_file", WORKING_DIR."/$cal_pulsar_name.$cal_file")) {
+					if (symlink ("$cal_dir/$cal_file", WORKING_DIR."/$cal_file")) {
 						echo "Successfully created symlink!<br>\n";
 					}
 				}
 			}
-			$all_files .= " $cal_pulsar_name.$cal_file";
+			$all_files .= " $cal_file";
 		}
 		
@@ -120,5 +119,6 @@
 		
 		// Query for all the respective cals
-		$all_cals = query_cals( $all_results[$index]['pulsar_name'],  $all_results[$index]['MJD'],  $all_results[$index]['data_type'], $cals_within_mins);
+	  //		$all_cals = query_cals( $all_results[$index]['pulsar_name'],  $all_results[$index]['MJD'],  $all_results[$index]['data_type'], $cals_within_mins);
+		$all_cals = query_cals( $all_results[$index]['src_name'],  $all_results[$index]['MJD'],  $all_results[$index]['data_type'], $cals_within_mins);
 		
 		foreach ($all_cals as $cal) {
@@ -127,10 +127,9 @@
 			$cal_pulsar_name = $cal['pulsar_name'];
 			
-			if (!file_exists(WORKING_DIR."/$cal_pulsar_name.$cal_file")) {
-				echo WORKING_DIR."$cal_pulsar_name.$cal_file doesn't exist<br>\n";
+			if (!file_exists(WORKING_DIR."/$cal_file")) {
+				echo WORKING_DIR."$cal_file doesn't exist<br>\n";
 				if (file_exists("$cal_dir/$cal_file")) {
 					echo "$dir/$file exists<br>\n";
-					#if (symlink ("$dir/$file", WORKING_DIR."/$pulsar_name.$file")) {
-					if (symlink ("$cal_dir/$cal_file", WORKING_DIR."/$cal_pulsar_name.$cal_file")) {
+					if (symlink ("$cal_dir/$cal_file", WORKING_DIR."/$cal_file")) {
 						echo "Successfully created symlink!<br>\n";
 					}
@@ -174,19 +173,18 @@
 		$file = $all_results[$index]['filename'];
 		$dir = $all_results[$index]['data_loc'];
-		$pulsar_name = $all_results[$index]['pulsar_name'];
 		
 		// Need to create a symlink first because may not have write
 		// access to the directory
-		if (!file_exists(WORKING_DIR."/$pulsar_name.$file")) {
-			echo WORKING_DIR."$pulsar_name.$file doesn't exist<br>\n";
+		if (!file_exists(WORKING_DIR."$file")) {
+			echo WORKING_DIR."$file doesn't exist<br>\n";
 			if (file_exists("$dir/$file")) {
 				echo "$dir/$file exists<br>\n";
-				#if (symlink ("$dir/$file", WORKING_DIR."/$pulsar_name.$file")) {
-				if (symlink ("$dir/$file", WORKING_DIR."/$pulsar_name.$file")) {
+				#if (symlink ("$dir/$file", WORKING_DIR."/$file")) {
+				if (symlink ("$dir/$file", WORKING_DIR."/$file")) {
 					echo "Successfully created symlink!<br>\n";
 				}
 			}
 		}
-		$all_files .= " $pulsar_name.$file";
+		$all_files .= " $file";
 		
 	}
@@ -230,5 +228,7 @@
 function query_cals($pulsar_name, $mjd, $data_type, $span_mins) {
 
- 	$all_cals = array();
+//   global $parameters;
+
+	$all_cals = array();
 	
 	//$full_path = $data_loc . "/" . $filename;
@@ -237,5 +237,7 @@
 	$mjd_min = mjd_add($mjd, $span_mins*-1);
 	
-	$query = "SELECT * FROM " . CALS_TABLE . " WHERE MJD > $mjd_min AND MJD < $mjd_max AND pulsar_name LIKE '$pulsar_name%' AND data_type = '$data_type'";
+	//	$query = "SELECT * FROM " . CALS_TABLE . " WHERE MJD > $mjd_min AND MJD < $mjd_max AND pulsar_name LIKE '$pulsar_name%' AND data_type = '$data_type'";
+// 	$query = "SELECT $params_in FROM calib WHERE (MJD > $mjd_min) AND (MJD < $mjd_max) AND src_name LIKE '$pulsar_name%' AND data_type = '$data_type'";
+ 	$query = "SELECT * FROM calib WHERE (MJD > $mjd_min) AND (MJD < $mjd_max) AND src_name LIKE '$pulsar_name%' AND data_type = '$data_type'";
 	
 	//echo "query = $query <br>\n";
Index: /trunk/htdocs/xmlFunctions.php
===================================================================
--- /trunk/htdocs/xmlFunctions.php	(revision 162)
+++ /trunk/htdocs/xmlFunctions.php	(revision 162)
@@ -0,0 +1,96 @@
+<?php
+
+////////////////////////////////////////////////////////////////////////
+//
+// Function definitions necessary to create XML/VOTABLE files.
+//
+///////////////////////////////////////////////////////////////////////
+
+function print_column_headers_VO() {
+
+  /// PRINT VOTABLE HEADERS (<FIELD>) FOR EACH OF THE COLUMNS TO BE INCLUDED
+
+  echo "<FIELD name=\"Filename\" ID=\"col1\" ucd=\"meta.id;meta.main\" datatype=\"char\" arraysize=\"30\">\n";
+  echo " <DESCRIPTION>\n  This is the name of the PSRFITS file at this position.\n </DESCRIPTION>\n</FIELD>\n";
+
+  echo "<FIELD name=\"Distance\" ID=\"col2\" ucd=\"pos.angDistance\" datatype=\"double\" width=\"10\" precision=\"4\" unit=\"deg\">\n";
+  echo " <DESCRIPTION>\n The angular separation from the queried position.\n </DESCRIPTION>\n</FIELD>\n";
+  
+  echo "<FIELD name=\"Target Name\" ID=\"col3\" ucd=\"obs.field;meta.id\" datatype=\"char\" arraysize=\"20\">\n";
+  echo " <DESCRIPTION>\n  This is the name of the PSRFITS file at this position.\n </DESCRIPTION>\n</FIELD>\n";
+  
+  echo "<FIELD name=\"Survey\" ID=\"col4\" ucd=\"obs;meta.dataset;meta.id\" datatype=\"char\" arraysize=\"10\">\n";
+  echo " <DESCRIPTION>\n  The short code for the survey type: PKS70=70cm Parkes Southern Pulsar Survey; PM=Parkes Multibeam Pulsar Survey, PH=Parkes High-Latitude Pulsar Survey; blank means not part of a survey or unknown.\n </DESCRIPTION>\n</FIELD>\n";
+  
+  echo "<FIELD name=\"RA\" ID=\"col5\" ucd=\"pos.eq.ra;meta.main\" ref=\"J2000\" datatype=\"double\" width=\"10\" precision=\"6\" unit=\"deg\">\n";
+  echo " <DESCRIPTION>\n  The Right Ascension of the central position of the pointing.\n </DESCRIPTION>\n</FIELD>\n";
+  
+  echo "<FIELD name=\"DEC\" ID=\"col6\" ucd=\"pos.eq.dec;meta.main\" ref=\"J2000\" datatype=\"double\" width=\"11\" precision=\"6\" unit=\"deg\">\n";
+  echo " <DESCRIPTION>\n  The Declination of the central position of the pointing.\n </DESCRIPTION>\n</FIELD>\n";
+  
+  echo "<FIELD name=\"BMAJ\" ID=\"col7\" ucd=\"pos.angResolution;phys.angSize.smajAxis\" datatype=\"float\" width=\"6\" precision=\"4\" unit=\"deg\">\n";
+  echo " <DESCRIPTION>\n  The full-width-half-maximum (FWHM) of the major-axis of the beam.\n </DESCRIPTION>\n</FIELD>\n";
+  
+  echo "<FIELD name=\"BMIN\" ID=\"col8\" ucd=\"pos.angResolution;phys.angSize.sminAxis\" datatype=\"float\" width=\"6\" precision=\"4\" unit=\"deg\">\n";
+  echo " <DESCRIPTION>\n  The full-width-half-maximum (FWHM) of the minor-axis of the beam.\n </DESCRIPTION>\n</FIELD>\n";
+  
+  echo "<FIELD name=\"BPA\" ID=\"col9\" ucd=\"pos.angResolution;pos.posAng\" datatype=\"float\" width=\"6\" precision=\"4\" unit=\"deg\">\n";
+  echo " <DESCRIPTION>\n  The position angle of the beam.\n </DESCRIPTION>\n</FIELD>\n";
+  
+  echo "<FIELD name=\"UT Date/Time of Observations\" ID=\"col10\" ucd=\"time.start\" datatype=\"char\" arraysize=\"30\">\n";
+  echo " <DESCRIPTION>\n  The UT Date and Time of the start of the observations, in FITS DATE-OBS format.\n </DESCRIPTION>\n</FIELD>\n";
+  
+  echo "<FIELD name=\"MJD\" ID=\"col11\" ucd=\"time.start\" datatype=\"double\" width=\"14\" precision=\"8\">\n";
+  echo " <DESCRIPTION>\n  The Modified Julian Date of the observation.\n </DESCRIPTION>\n</FIELD>\n";
+  
+  echo "<FIELD name=\"ObsFreq\" ID=\"col12\" ucd=\"em.freq.central\" datatype=\"double\" width=\"9\" precision=\"4\" unit=\"MHz\">\n";
+  echo " <DESCRIPTION>\n  The central observing frequency.\n </DESCRIPTION>\n</FIELD>\n";
+  
+  echo "<FIELD name=\"Channel Bandwidth\" ID=\"col13\" ucd=\"spect.binSize;em.freq\" datatype=\"double\" width=\"9\" precision=\"4\" unit=\"MHz\">\n";
+  echo " <DESCRIPTION>\n  The frequency width of each channel.\n </DESCRIPTION>\n</FIELD>\n";
+  
+  echo "<FIELD name=\"Number of Channels\" ID=\"col14\" ucd=\"em.bin;meta.number\" datatype=\"int\" width=\"6\">\n";
+  echo " <DESCRIPTION>\n  The number of frequency channels.\n </DESCRIPTION>\n</FIELD>\n";
+  
+  echo "<FIELD name=\"Scan length\" ID=\"col15\" ucd=\"obs.exposure;time.duration\" datatype=\"float\" width=\"9\" precision=\"4\" unit=\"s\">\n";
+  echo " <DESCRIPTION>\n  The total length of time taken for this observation.\n </DESCRIPTION>\n</FIELD>\n";
+  
+  echo "<FIELD name=\"Sample time\" ID=\"col16\" ucd=\"time.resolution\" datatype=\"float\" width=\"9\" precision=\"4\" unit=\"s\">\n";
+  echo " <DESCRIPTION>\n  The time for each sample in the observation.\n </DESCRIPTION>\n</FIELD>\n";
+   
+}
+
+function print_data_VO($all_results) {
+  
+  echo "<DATA>\n<TABLEDATA>\n";
+  for ($i=0; $i < count($all_results); $i++) {
+    $line = $all_results[$i];
+    print_data_line_VO($line);
+  }
+  echo "</TABLEDATA>\n</DATA>\n";
+
+}
+
+function print_data_line_VO($line) {
+  // PRINT A SINGLE ROW OF DATA TO THE VOTABLE
+  echo "<TR>\n ";
+  printf("<TD>%s</TD>",$line['filename']);
+  printf("<TD>%6.4f</TD>",$line['angsep']);
+  printf("<TD>%s</TD>",$line['src_name']);
+  printf("<TD>%s</TD>",$line['survey']);
+  printf("<TD>%10.6f</TD>",$line['rajd']);
+  printf("<TD>%+11.6f</TD>",$line['decjd']);
+  printf("<TD>%6.4f</TD>",$line['bmaj']);
+  printf("<TD>%6.4f</TD>",$line['bmin']);
+  printf("<TD>%6.4f</TD>",$line['bpa']);
+  printf("<TD>%s</TD>",$line['date_obs']);
+  printf("<TD>%14.8f</TD>",$line['mjd']);
+  printf("<TD>%9.4f</TD>",$line['obsfreq']);
+  printf("<TD>%9.4f</TD>",$line['chanbw']);
+  printf("<TD>%d</TD>",$line['nchan']);
+  printf("<TD>%9.4f</TD>",$line['scanlen']);
+  printf("<TD>%9.4f</TD>",$line['tsamp']);
+  echo "\n</TR>\n";
+}
+
+?>
Index: /trunk/set_php_files.sh
===================================================================
--- /trunk/set_php_files.sh	(revision 161)
+++ /trunk/set_php_files.sh	(revision 162)
@@ -16,2 +16,5 @@
 scp -rp $LOCALDIR/*.php $HOST$PHPDEST/$MYDIR
 scp -rp $LOCALDIR/new/*.php $HOST$PHPDEST/$MYDIR/new
+
+set LOCALDIR=$PVO/htdocs
+scp -rp $LOCALDIR/*php $HOST$PHPDEST
