Index: /trunk/htdocs/print_tables.php
===================================================================
--- /trunk/htdocs/print_tables.php	(revision 173)
+++ /trunk/htdocs/print_tables.php	(revision 173)
@@ -0,0 +1,423 @@
+<?php
+
+  ///////////////////////////////////////////////////////////////////////////////////////////////
+  //
+  // Function definitions for printing the results page
+  // --------------------------------------------------
+  //
+  ///////////////////////////////////////////////////////////////////////////////////////////////
+
+  // The page navigator
+function printNavigate($startRange, $num_rows) {
+
+  // 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";
+
+  print_table_header($params);
+
+  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\">
+					<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);
+				
+	  //$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);
+	$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);
+				
+      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);
+					
+    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";
+  }		
+
+}
+
+///////////////////////////////////////////////////////
+
+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 distance:
+      echo "\t\t<td class=\"result_row\" align=\"center\">";
+      printf("%.6f", $result_row[$param]);
+      break;
+    case PERIOD:
+      echo "\t\t<td class=\"result_row\" align=\"center\">";
+      printf("%.16f", $result_row[$param]);
+      break;
+
+    case DM:
+      echo "\t\t<td class=\"result_row\" align=\"center\">";
+      printf("%.5f", $result_row[$param]);
+      break;
+
+    case obsfreq:
+      echo "\t\t<td class=\"result_row\" align=\"center\">";
+      printf("%.3f", $result_row[$param]);
+      break;
+    case BW:
+      echo "\t\t<td class=\"result_row\" align=\"center\">";
+      printf("%.3f", $result_row[$param]);
+      break;
+    case MJD:
+      echo "\t\t<td class=\"result_row\" align=\"center\">";
+      printf("%.6f", $result_row[$param]);
+      break;
+    case rajd:
+    case decjd:
+    case gl:
+    case gb:
+      echo "\t\t<td class=\"result_row\" align=\"center\">";
+      printf("%.6f", $result_row[$param]);
+      break;
+    case bmaj:
+    case bmin:
+      echo "\t\t<td class=\"result_row\" align=\"center\">";
+      printf("%.3f", $result_row[$param]);
+      break;
+    case scanlen:
+      echo "\t\t<td class=\"result_row\" align=\"center\">";
+      printf("%.3f", $result_row[$param]);
+      break;
+    case NSUB:
+      echo "\t\t<td class=\"result_row\" align=\"center\">";
+      printf("%d", $result_row[$param]);
+      break;
+    case NBIN:
+      echo "\t\t<td class=\"result_row\" align=\"center\">";
+      printf("%d", $result_row[$param]);
+      break;
+    case TSAMP:
+      echo "\t\t<td class=\"result_row\" align=\"center\">";
+      printf("%.6f", $result_row[$param]);
+      break;
+    case NBEAM:
+      echo "\t\t<td class=\"result_row\" align=\"center\">";
+      printf("%d", $result_row[$param]);
+      break;
+    default:
+      echo "\t\t<td class=\"result_row\" align=\"center\">";
+      echo $result_row[$param];
+    }
+  }
+}
+
+///////////////////////////////////////////////////////
+
+function print_table_header($params) {
+
+//////////////////////////////////////////
+// Initialise the output heading format
+
+  echo "<thead class=\"file-headings\">
+	  <tr>
+            ";
+
+  echo "<th>&nbsp;</th>"; // Heading for the check-box column
+  echo "<th>#</th>";      // Heading for the row-count column
+
+  $flipped_parameters = array_flip($params);
+  foreach (array_keys($flipped_parameters) as $key) {
+    // loop over each parameter, and do something specific for each one.
+    switch($key){
+    case distance:
+      $header = "Distance"; break;
+    case filename:
+      $header = "Filename"; break;
+    case src_name:
+      $header = "Source Name"; break;
+    case project_id:
+      $header = "Project ID"; break;
+    case raj:
+      $header = "RA (J2000)"; break;
+    case decj:
+      $header = "Dec. (J2000)"; break;
+    case data_type:
+      $header = "Data Type"; break;
+    case obsfreq:
+      $header = "Frequency [MHz]"; break;
+    case bw:
+      $header = "Bandwidth [MHz]"; break;
+    case scanlen:
+      $header = "Scan Length [s]"; break;
+    case date:
+      $header = "UT Date"; break;
+    case ut:
+      $header = "UT Time"; break;
+    case MJD:
+      $header = "MJD"; break;
+    case rajd:
+      $header = "RA (J2000) [deg]"; break;
+    case decjd:
+      $header = "Dec. (J2000) [deg]"; break;
+    case gl:
+      $header = "Gal. Long. [deg]"; break;
+    case gb:
+      $header = "Gal. Lat. [deg]"; break;
+    case BMAJ:
+      $header = "BMAJ [deg]"; break;
+    case BMIN:
+      $header = "BMIN [deg]"; break;
+    case BPA:
+      $header = "BPA [deg]"; break;
+    case dm:
+      $header = "D.M."; break;
+    case period:
+      $header = "Period [s]"; break;
+    case nchan:
+      $header = "# Channels"; break;
+    case npol:
+      $header = "# Pol"; break;
+    case nbin:
+      $header = "# Bins"; break;
+    case nsub:
+      $header = "# Subints"; break;
+    case tsamp:
+      $header = "Sample Time [s]"; break;
+    case nbits:
+      $header = "# Bits / sample"; break;
+    case nbeam:
+      $header = "# Beams"; break;
+    case cnfg:
+      $header = "Config."; break;
+    case inst:
+      $header = "Inst."; break;
+    case rcvr:
+      $header = "Receiver"; break;
+    case hdrver:
+      $header = "Header Version"; break;
+    case survey:
+      $header = "Survey"; break;
+    case telescope:
+      $header = "Telescope"; break;
+    case site:
+      $header = "Site"; break;
+    case obsrvr:
+      $header = "Observers"; break;
+    default:
+      $header = "&nbsp;"; break;  // this should not be needed -- all options are listed above.
+    }
+    echo "<th>$header</th>";
+  }
+  
+  echo "  </tr>
+	</thead>\n";
+
+}
+
+?>
Index: /trunk/htdocs/query.php
===================================================================
--- /trunk/htdocs/query.php	(revision 172)
+++ /trunk/htdocs/query.php	(revision 173)
@@ -3,6 +3,6 @@
 <head>
 <link rel="stylesheet" type="text/css" href="styles/style.css" />
-<link rel="stylesheet" type="text/css" href="styles/results.css" />
-<link rel="stylesheet" type="text/css" href="styles/query.css" />
+    <link rel="stylesheet" type="text/css" href="styles/results.css" />
+    <link rel="stylesheet" type="text/css" href="styles/query.css" />
 
     <meta http-equiv="Content-Type" content="text/html; charset=iso-8759-1" />
@@ -46,4 +46,5 @@
 include_once("date.php");
 include_once("security.php");
+include_once("print_tables.php");
 define("PSR_SEARCH_RADIUS",0.5);
 
@@ -259,15 +260,4 @@
 //	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'])) {
@@ -344,17 +334,10 @@
     //    $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];
+
+    $psr_rajd = $output_array[0];
+    $psr_decjd = $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))) )";
+    $angsepString = "degrees( acos( cos(radians(rajd-$psr_rajd))*cos(radians(decjd))*cos(radians($psr_decjd))+sin(radians(decjd))*sin(radians($psr_decjd))) )";
 		  
     $whereString .= " AND ( (($angsepString - 0.25*(bmaj+bmin)) < ".PSR_SEARCH_RADIUS.") OR pulsar_name LIKE '%$output_psrname' )";
@@ -391,5 +374,4 @@
 
   if ($data_type) {
-
     $whereString .= " AND data_type = '$data_type'";
   }
@@ -399,5 +381,4 @@
 
   if ($survey) {
-
     $whereString .= " AND survey = '$survey'";
   }
@@ -413,11 +394,8 @@
 
   $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 )";
 
@@ -490,45 +468,54 @@
   <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";
-				}
-				else {
-				  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";
-  }
-
-  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";
- }
+  <?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";
+      }
+      else {
+	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";
+    }
+
+    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";
 
@@ -573,317 +560,2 @@
 </html>
 
-<?php
-
-  ///////////////////////////////////////////////////////////////////////////////////////////////
-  //
-  // Function definitions
-  // --------------------
-  //
-  ///////////////////////////////////////////////////////////////////////////////////////////////
-
-  // The page navigator
-function printNavigate($startRange, $num_rows) {
-
-  // 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\">
-					<tr>
-						$heading
-					</tr>
-				</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++) {
-
-    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\">
-					<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);
-				
-	  //$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);
-	$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);
-				
-      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);
-					
-    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";
-  }		
-
-}
-
-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];
-    }
-  }
-}
-
-// Initialise the input form variables
-function init() {
-  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 172)
+++ /trunk/htdocs/utils.php	(revision 173)
@@ -7,4 +7,19 @@
 include_once("constants.php");
 include_once("database.php");
+
+///////////////////////////////////////////////////////
+
+// Initialise the input form variables
+function init() {
+  global $actions, $selected_obs;
+	
+  unset($actions);
+  unset($selected_obs);
+
+  unset($_SESSION['selected_obs']);
+  unset($_SESSION['actions']);
+}
+
+///////////////////////////////////////////////////////
 
 // Gets the parameter from the HTTP_GET_VARS or HTTP_POST_VARS assoc 
Index: /trunk/htdocs/xmlFunctions.php
===================================================================
--- /trunk/htdocs/xmlFunctions.php	(revision 172)
+++ /trunk/htdocs/xmlFunctions.php	(revision 173)
@@ -38,23 +38,26 @@
   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=\"UT Date of Observations\" ID=\"col10\" ucd=\"time.start\" datatype=\"char\" arraysize=\"30\">\n";
+  echo " <DESCRIPTION>\n  The UT Date of the start of the observation.\n </DESCRIPTION>\n</FIELD>\n";
   
-  echo "<FIELD name=\"MJD\" ID=\"col11\" ucd=\"time.start\" datatype=\"double\" width=\"14\" precision=\"8\">\n";
+  echo "<FIELD name=\"UT Time of Observations\" ID=\"col11\" ucd=\"time.start\" datatype=\"char\" arraysize=\"30\">\n";
+  echo " <DESCRIPTION>\n  The UT Time of the start of the observation.\n </DESCRIPTION>\n</FIELD>\n";
+  
+  echo "<FIELD name=\"MJD\" ID=\"col12\" 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 "<FIELD name=\"ObsFreq\" ID=\"col13\" 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 "<FIELD name=\"Channel Bandwidth\" ID=\"col14\" 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 "<FIELD name=\"Number of Channels\" ID=\"col15\" 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 "<FIELD name=\"Scan length\" ID=\"col16\" 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 "<FIELD name=\"Sample time\" ID=\"col17\" 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";
    
@@ -76,5 +79,5 @@
   echo "<TR>\n ";
   printf("<TD>%s</TD>",$line['filename']);
-  printf("<TD>%6.4f</TD>",$line['angsep']);
+  printf("<TD>%8.6f</TD>",$line['angsep']);
   printf("<TD>%s</TD>",$line['src_name']);
   printf("<TD>%s</TD>",$line['survey']);
@@ -84,8 +87,9 @@
   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>%s</TD>",$line['date']);
+  printf("<TD>%s</TD>",$line['ut']);
+  printf("<TD>%14.8f</TD>",$line['MJD']);
   printf("<TD>%9.4f</TD>",$line['obsfreq']);
-  printf("<TD>%9.4f</TD>",$line['chanbw']);
+  printf("<TD>%9.4f</TD>",abs($line['bw']));
   printf("<TD>%d</TD>",$line['nchan']);
   printf("<TD>%9.4f</TD>",$line['scanlen']);
