Index: /trunk/htdocs/utils.php
===================================================================
--- /trunk/htdocs/utils.php	(revision 156)
+++ /trunk/htdocs/utils.php	(revision 157)
@@ -230,5 +230,5 @@
 function query_cals($pulsar_name, $mjd, $data_type, $span_mins) {
 
-	$all_cals = array();
+ 	$all_cals = array();
 	
 	//$full_path = $data_loc . "/" . $filename;
Index: /trunk/new-htdocs/loadNewTables.php
===================================================================
--- /trunk/new-htdocs/loadNewTables.php	(revision 156)
+++ /trunk/new-htdocs/loadNewTables.php	(revision 157)
@@ -3,31 +3,17 @@
   //include_once("loadS70.php()");
 
-function loadNewTables() {
-
-  // LOADS THE S70 DATA INTO THE DATABASE, AND CREATES THE NEW OBS
-  // TABLE.
-
-  mysql_query("DROP TEMPORARY TABLE IF EXISTS s70");
-  mysql_query("DROP TEMPORARY TABLE IF EXISTS obs");
-  mysql_query("DROP TEMPORARY TABLE IF EXISTS calib");
-
-  loadS70();
-
-  $createObs = "
-CREATE TEMPORARY TABLE obs (
-	filename VARCHAR(32),
-	data_loc VARCHAR(100),
- 	file_size_bytes INT(32),
+define('TABLEDEF',
+"	filename VARCHAR(32),
+	src_name VARCHAR(16),
 	project_id VARCHAR(10),
-	hdrver VARCHAR(10),
-	survey VARCHAR(10),
-	telescope VARCHAR(16),
- 	site VARCHAR(8),    
-	src_name VARCHAR(16),
+	raj VARCHAR(20),
+	decj VARCHAR(20),
+ 	data_type VARCHAR(128),
+        obsfreq DECIMAL(32,9),
+	bw DECIMAL(16,6),
+	scanlen DECIMAL(32,20),
  	date VARCHAR(16),   
  	ut VARCHAR(16),   
  	MJD DECIMAL(32,26),
-	raj VARCHAR(20),
-	decj VARCHAR(20),
 	rajd DOUBLE,
 	decjd DOUBLE,
@@ -39,34 +25,69 @@
 	dm DECIMAL(16,10),
 	period DECIMAL(32,24),
-	cnfg VARCHAR(128),
- 	inst VARCHAR(32),
-	data_type VARCHAR(128),
- 	rcvr VARCHAR(16),   
- 	obsrvr VARCHAR(32),   
-        obsfreq DECIMAL(32,16),
-	chanbw DECIMAL(16,6),
  	nchan INT(6),        
 	npol INT(6),
  	nbin INT(6),        
  	nsub INT(6),        
- 	scanlen DECIMAL(32,20),
  	tsamp FLOAT,       
 	nbits tinyint(3) unsigned,  
 	nbeam tinyint(3) unsigned,
+	cnfg VARCHAR(128),
+ 	inst VARCHAR(32),
+ 	rcvr VARCHAR(16),   
+	hdrver VARCHAR(10),
+	survey VARCHAR(10),
+	telescope VARCHAR(16),
+ 	site VARCHAR(8),    
+ 	obsrvr VARCHAR(32),   
+	data_loc VARCHAR(100),
+ 	file_size_bytes INT(32),
 	PRIMARY KEY (filename, data_loc)
-)
+");
+
+function loadS70() {
+
+  // LOADS THE S70 DATA FROM THE FILE
+  // /DATA/SITAR_1/whi550/VO/PulsarVO/s70v_summary.csv INTO A TEMPORARY
+  // TABLE IN THE MYSQL DATABASE. THE LINK NEEDS TO HAVE BEEN MADE WITH
+  // ADMIN PRIVILEGES.
+
+  $createTable = "
+CREATE TEMPORARY TABLE s70 (".TABLEDEF.")";
+
+  $result = mysql_query($createTable) or die('Query failed 3: ' . mysql_error());
+
+  $loadTable = "
+LOAD DATA LOCAL INFILE \"/pulsar/archive13/S70V/summary_S70.csv\" 
+INTO TABLE s70 
+FIELDS TERMINATED BY \",\" 
+OPTIONALLY ENCLOSED BY \"\\\"\" 
+IGNORE 1 LINES 
+(filename,src_name,project_id,raj,decj,data_type,obsfreq,bw,scanlen,date,ut,MJD,rajd,decjd,gl,gb,bmaj,bmin,bpa,dm,period,nchan,npol,nbin,nsub,tsamp,nbits,nbeam,cnfg,inst,rcvr,hdrver,survey,telescope,site,obsrvr,data_loc,file_size_bytes)";
+
+  $result = mysql_query($loadTable) or die('Query failed 4: ' . mysql_error());
+
+  $update = "UPDATE s70 SET bw = bw * nchan";
+  $result = mysql_query($update) or die('Query failed 4: ' . mysql_error());
+  
+
+}
+
+function loadNewObs() {
+
+  // LOADS THE S70 DATA INTO THE DATABASE, AND CREATES THE NEW OBS
+  // TABLE.
+
+  mysql_query("DROP TEMPORARY TABLE IF EXISTS s70");
+  mysql_query("DROP TEMPORARY TABLE IF EXISTS obs");
+  mysql_query("DROP TEMPORARY TABLE IF EXISTS calib");
+
+  loadS70();
+
+  $createObs = "
+CREATE TEMPORARY TABLE obs (".TABLEDEF.")
  SELECT
 	o.filename, 
-	o.data_loc, 
-	o.file_size_bytes, 
+	o.pulsar_name as src_name,
 	NULL as project_id,
-	NULL as hdrver,
-	NULL as survey,
-	'PARKES' as telescope,
-	o.site as site,
-	o.pulsar_name as src_name,
-	o.date as date,
-	o.ut as ut,
-	o.MJD as MJD,
 	concat(raj_hour,':',raj_minute,':',raj_second) as raj,
 	case 
@@ -77,4 +98,11 @@
              else concat(abs(o.decj_degree),':',o.decj_minute,':',o.decj_second) 
     	end as decj,
+	o.data_type,
+	o.freq as obsfreq,
+	o.bw as bw,
+	o.length as scanlen, 
+	o.date as date,
+	o.ut as ut,
+	o.MJD as MJD,
         (o.raj_hour+o.raj_minute/60.+o.raj_second/3600.)*15. as rajd,
         case when o.pulsar_name like '%-%'
@@ -91,19 +119,21 @@
 	o.dm, 
 	o.period, 
-	o.cnfg,
-	o.inst,
-	o.data_type,
-	o.rcvr,
-	o.obsrvr,
-	o.freq as obsfreq,
-	o.bw as chanbw,
 	o.nchan,
 	o.npol,
 	o.nbin, 
 	o.nsub, 
-	o.length as scanlen, 
 	o.tsamp,
 	NULL as nbits,
-	o.nbeam	
+	o.nbeam, 
+	o.cnfg,
+	o.inst,
+	o.rcvr,
+	NULL as hdrver,
+	NULL as survey,
+	'PARKES' as telescope,
+	o.site as site,
+	o.obsrvr,
+	o.data_loc, 
+	o.file_size_bytes
  FROM observations as o";
 
@@ -121,61 +151,14 @@
   $result = mysql_query($updateObs) or die('Query failed 2: ' . mysql_error());
 
-  //////////////////////////////////////////
-
-  $query = "
-CREATE TEMPORARY TABLE calib (
-	filename VARCHAR(32),
-	data_loc VARCHAR(100),
- 	file_size_bytes INT(32),
-	project_id VARCHAR(10),
-	hdrver VARCHAR(10),
-	survey VARCHAR(10),
-	telescope VARCHAR(16),
- 	site VARCHAR(8),    
-	src_name VARCHAR(16),
- 	date VARCHAR(16),   
- 	ut VARCHAR(16),   
- 	MJD DECIMAL(32,26),
-	raj VARCHAR(20),
-	decj VARCHAR(20),
-	rajd DOUBLE,
-	decjd DOUBLE,
-	gl DOUBLE,
-	gb DOUBLE,
-	bmaj FLOAT,
-	bmin FLOAT,
-	bpa FLOAT,
-	dm DECIMAL(16,10),
-	period DECIMAL(32,24),
-	cnfg VARCHAR(128),
- 	inst VARCHAR(32),
-	data_type VARCHAR(128),
- 	rcvr VARCHAR(16),   
- 	obsrvr VARCHAR(32),   
-        obsfreq DECIMAL(32,16),
-	chanbw DECIMAL(16,6),
- 	nchan INT(6),        
-	npol INT(6),
- 	nbin INT(6),        
- 	nsub INT(6),        
- 	scanlen DECIMAL(32,20),
- 	tsamp FLOAT,       
-	nbits tinyint(3) unsigned,  
-	nbeam tinyint(3) unsigned,
-	PRIMARY KEY (filename, data_loc)
-)
+}
+
+function loadNewCal() {
+
+  $createCal = "
+CREATE TEMPORARY TABLE calib (".TABLEDEF.")
  SELECT
 	c.filename, 
-	c.data_loc, 
-	c.file_size_bytes, 
+	c.pulsar_name as src_name,
 	NULL as project_id,
-	NULL as hdrver,
-	NULL as survey,
-	'PARKES' as telescope,
-	c.site as site,
-	c.pulsar_name as src_name,
-	NULL as date,
-	NULL as ut,
-	c.MJD as MJD,
 	concat(raj_hour,':',raj_minute,':',raj_second) as raj,
 	case 
@@ -186,4 +169,11 @@
              else concat(abs(c.decj_degree),':',c.decj_minute,':',c.decj_second) 
     	end as decj,
+	c.data_type,
+	c.freq as obsfreq,
+	c.bw as bw,
+	NULL as scanlen, 
+	NULL as date,
+	NULL as ut,
+	c.MJD as MJD,
         (c.raj_hour+c.raj_minute/60.+c.raj_second/3600.)*15. as rajd,
         case when c.pulsar_name like '%-%' 
@@ -200,22 +190,24 @@
 	c.dm, 
 	c.period, 
-	c.cnfg,
-	c.inst,
-	c.data_type,
-	c.rcvr,
-	c.obsrvr,
-	c.freq as obsfreq,
-	c.bw as chanbw,
 	c.nchan,
 	c.npol,
 	c.nbin, 
 	c.nsub, 
-	NULL as scanlen, 
 	NULL as tsamp,
 	NULL as nbits,
-	NULL as nbeam	
+	NULL as nbeam, 
+	c.cnfg,
+	c.inst,
+	c.rcvr,
+	NULL as hdrver,
+	NULL as survey,
+	'PARKES' as telescope,
+	c.site as site,
+	c.obsrvr,
+	c.data_loc, 
+	c.file_size_bytes
  FROM cals as c";
 
-  $result = mysql_query($createObs) or die('Query failed 5: ' . mysql_error());
+  $result = mysql_query($createCal) or die('Query failed 5: ' . mysql_error());
 
   $updateCal = "
@@ -228,7 +220,16 @@
 	gb = (degrees( asin( cos(radians(decjd))*cos(radians(@ngpdec))*cos(radians(rajd-@ngpra)) + sin(radians(decjd))*sin(radians(@ngpdec)))))";
 
-  $result = mysql_query($updateObs) or die('Query failed 6: ' . mysql_error());
-
-  }
+  $result = mysql_query($updateCal) or die('Query failed 6: ' . mysql_error());
+
+}
+
+function loadNewTables(){
+
+  loadS70();
+  loadNewObs();
+  loadNewCal();
+
+}
+
 
 ?>
Index: /trunk/new-htdocs/loadS70.php
===================================================================
--- /trunk/new-htdocs/loadS70.php	(revision 156)
+++ /trunk/new-htdocs/loadS70.php	(revision 157)
@@ -1,5 +1,5 @@
 <?php	
 
-function loadS70() {
+function loadS70_old() {
 
   // LOADS THE S70 DATA FROM THE FILE
Index: /trunk/new-htdocs/new/index.php
===================================================================
--- /trunk/new-htdocs/new/index.php	(revision 156)
+++ /trunk/new-htdocs/new/index.php	(revision 157)
@@ -84,5 +84,4 @@
 include_once("../../../database.php");
 include_once("../../../date.php");
-include_once("../loadS70.php");
 include_once("../loadNewTables.php");
 
@@ -134,5 +133,6 @@
 // Get the field names to fill form checkboxes
 
-$query = "SHOW COLUMNS FROM ".OBSERVATIONS_TABLE;
+//$query = "SHOW COLUMNS FROM ".OBSERVATIONS_TABLE;
+$query = "SHOW COLUMNS FROM obs";
 $result = mysql_query($query) or die ('Query failed: ' . mysql_error());
 
@@ -140,5 +140,6 @@
 if (mysql_num_rows($result)) {
 	while($row = mysql_fetch_assoc($result)) {
-		array_push($fields, $row);
+	  if(($row['Field'] != "data_loc") && ($row['Field'] != "file_size_bytes"))
+	    array_push($fields, $row);
 	}
 }
@@ -148,5 +149,6 @@
 //
 
-$query = "select distinct data_type from " . OBSERVATIONS_TABLE . " order by data_type";
+//$query = "select distinct data_type from " . OBSERVATIONS_TABLE . " order by data_type";
+$query = "(select distinct data_type from obs) union (select distinct data_type from s70)";
 $result = mysql_query($query) or die ('Query failed: ' . mysql_error());
 
@@ -159,4 +161,5 @@
 }
 
+///////////////////////////////////////////////
 // If the user clicked on the logout button
 if (isset($HTTP_GET_VARS['command'])) {
@@ -188,11 +191,11 @@
 //
 
-if (!atnf_staff($username)) {
-	$max_cal_assoc['day'] = date("j");
-	$max_cal_assoc['month'] = date("n");
-	$max_cal_assoc['year'] = date("Y")-2;
-	
-	echo "$username not atnf<br>\n";
-}
+// if (!atnf_staff($username)) {
+// 	$max_cal_assoc['day'] = date("j");
+// 	$max_cal_assoc['month'] = date("n");
+// 	$max_cal_assoc['year'] = date("Y")-2;
+	
+// 	echo "$username not atnf<br>\n";
+// }
 
 // Initial state where no username or password supplied OR bad login state
@@ -259,25 +262,25 @@
 
 				foreach ($fields as $field) {
-					if (ereg("raj_.+", $field['Field'] )) {
-						$raj_field .= "," . $field['Field'];
-						$raj_count++;
-						if ($raj_count == 3) {
-							$raj_field = trim($raj_field, " ,");
-							echo "<input onClick=\"updateSelectAll('ra',
-'$all_params_id')\" type=\"checkbox\" name=\"params[]\" value=\"$raj_field\" id=\"RA\" checked=\"true\">RA<br>\n";
-						}
-					}
-					else if (ereg("decj_.+", $field['Field'] ) ){
-						$decj_field .= "," . $field['Field'];
-						$decj_count++;
-						if ($decj_count == 3) {
-							$decj_field = trim($decj_field, " ,");
-							echo "<input onClick=\"updateSelectAll('dec', '$all_params_id')\" type=\"checkbox\" name=\"params[]\" value=\"$decj_field\" id=\"dec\" checked=\"true\">DecJ<br>\n";
-						}
-					}
-					else {
+// 					if (ereg("raj_.+", $field['Field'] )) {
+// 						$raj_field .= "," . $field['Field'];
+// 						$raj_count++;
+// 						if ($raj_count == 3) {
+// 							$raj_field = trim($raj_field, " ,");
+// 							echo "<input onClick=\"updateSelectAll('ra',
+// '$all_params_id')\" type=\"checkbox\" name=\"params[]\" value=\"$raj_field\" id=\"RA\" checked=\"true\">RA<br>\n";
+// 						}
+// 					}
+// 					else if (ereg("decj_.+", $field['Field'] ) ){
+// 						$decj_field .= "," . $field['Field'];
+// 						$decj_count++;
+// 						if ($decj_count == 3) {
+// 							$decj_field = trim($decj_field, " ,");
+// 							echo "<input onClick=\"updateSelectAll('dec', '$all_params_id')\" type=\"checkbox\" name=\"params[]\" value=\"$decj_field\" id=\"dec\" checked=\"true\">DecJ<br>\n";
+// 						}
+// 					}
+// 					else {
 						echo "<input
 onClick=\"updateSelectAll('".$field['Field']."', '$all_params_id')\" type=\"checkbox\" name=\"params[]\" value=\"".$field['Field']."\" id=\"".$field['Field']."\" checked=\"true\">".$field['Field']."<br>\n";
-					}
+// 					}
 				}
 				?>
Index: /trunk/new-htdocs/new/query.php
===================================================================
--- /trunk/new-htdocs/new/query.php	(revision 156)
+++ /trunk/new-htdocs/new/query.php	(revision 157)
@@ -43,5 +43,5 @@
 include_once("../../../constants.php");
 include_once("../../../database.php");
-include_once("../../../utils.php");
+include_once("../utils.php");
 include_once("../../../date.php");
 include_once("../../../security.php");
@@ -49,4 +49,8 @@
 include_once("../loadNewTables.php");
 
+//		$link = db_connect();
+$link = db_connect_admin();
+
+
 // Processes the form and queries the database on the given parameters
 //echo "username = " . $_SESSION['username'] . " authcode = " . $_SESSION['auth_code'] . " <br>\n";
@@ -67,5 +71,5 @@
 	
 // List of request parameters to display
-$params           = get_param('params', $HTTP_GET_VARS);	
+$params_in           = get_param('params', $HTTP_GET_VARS);	
 	
 // The current state. E.g cart or results
@@ -131,5 +135,13 @@
 	
 $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
@@ -255,28 +267,12 @@
 	
 $heading = "<th>&nbsp;</th><th>#</th>";
-$raj_exists = false;
-$decj_exists = false;
-$raj_heading = "";
-$decj_heading = "";
-
-	// Check if RA and Dec were queried
-	$flipped_parameters = array_flip($params);
-	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($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";
@@ -284,17 +280,12 @@
  }
 	
-// Check if RA and Dec were queried
-$raj_heading = "<th>RAJ</th>";
-$decj_heading = "<th>DecJ</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];
+  $parameters = $params_in[0];
+
+  for ($i=1; $i < count($params_in); $i++) {
+    $parameters .= ", " . $params_in[$i];
   }
 
@@ -367,14 +358,16 @@
   // Constraint on boundary
 
-  $selectString = "SELECT *";
+  $selectString = "SELECT ";
   if ($radius) {
 
-    $angsepString = "degrees( acos( cos(radians(rajd-$raj))*cos(radians(decjd))*cos(radians($decj))+sin(radians(decjd))*sin(radians($decj))) )";
+    $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 angsep";
-
-  }
+    $selectString .= "$angsepString as distance, ";
+
+  }
+
+  $selectString .= $parameters;
 
   ////////////////////////////
@@ -403,6 +396,4 @@
   //
 
-  //		$link = db_connect();
-  $link = db_connect_admin();
 
   // Remove any leading or trailing AND and OR
@@ -412,6 +403,6 @@
   $query = "( $selectString FROM s70 WHERE $whereString ) UNION ( $selectString FROM obs WHERE $whereString )";
 
-  if($radius) $query .= "  ORDER BY angsep";
-  echo "query = $query<br>\n";
+  if($radius) $query .= "  ORDER BY distance";
+  echo $query;
 
   loadNewTables();
@@ -429,6 +420,4 @@
   mysql_free_result($result);
 
-	
-  mysql_close($link);
 	
  }
@@ -504,5 +493,5 @@
 				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>
+				<img alt="Revert to query results" border="0" title="Revert to query results" src="../../../images/table_30px_white.png"></img></a>
 				</td>
 				<?php } else { ?>
@@ -515,23 +504,22 @@
     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.php\">Search again</a></center><br>\n";
-												 exit();
-											       }
-	
+
+  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);
@@ -560,4 +548,6 @@
 	
 //echo "count all results = " . count($all_results);
+  mysql_close($link);
+	
 
 
@@ -580,10 +570,10 @@
 
   // Collect the form values
-  global $params, $pulsar_name,	$data_type,
+  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);
+    $params_str = array2urlstring("params", $params_in);
   }
 		
@@ -744,5 +734,5 @@
     //print_r($params);
 		
-    print_ra_dec($line, $params);
+//     print_ra_dec($line, $params);
 				
     echo "\t</tr>\n";
@@ -784,5 +774,5 @@
       print_param($line,$param);
     }
-    print_ra_dec($line, $params);
+//     print_ra_dec($line, $params);
 					
     echo "\t\t</tr>\n";	
Index: /trunk/new-htdocs/utils.php
===================================================================
--- /trunk/new-htdocs/utils.php	(revision 157)
+++ /trunk/new-htdocs/utils.php	(revision 157)
@@ -0,0 +1,277 @@
+<?php	session_start(); 
+
+// A set of commonly used functions
+// Albert Teoh
+// 27.3.2006
+
+include_once("constants.php");
+include_once("database.php");
+include_once("loadNewTables.php");
+
+// Gets the parameter from the HTTP_GET_VARS or HTTP_POST_VARS assoc 
+// array first. If not set, then gets it off the session
+// variable
+function get_param($param_name, $http_vars) {
+	
+		
+	$param = "";
+	
+	if (isset($http_vars[$param_name])) {
+		$param = $http_vars[$param_name];
+		
+		// Set the session variable
+		$_SESSION[$param_name] = $param;
+		
+	}
+	else {
+		$param = $_SESSION[$param_name];
+	}
+	
+	return $param;
+}
+
+// Create a tar of both observations and cals
+function tarObsCalFiles($cart_obs, $all_results, $cals_within_mins) {
+	$all_files = "";
+	$obs_cals  = array();
+	
+	$tar_filename = date("YmdHis");
+	
+	// Need to open up db connection to query cals in cart
+	$link = db_connect();
+
+	foreach ($cart_obs as $index) {
+		$file = $all_results[$index]['filename'];
+		$dir = $all_results[$index]['data_loc'];
+		$pulsar_name = $all_results[$index]['pulsar_name'];
+		
+		// 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);
+		
+		
+		// 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("$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")) {
+					echo "Successfully created symlink!<br>\n";
+				}
+			}
+		}
+		$all_files .= " $pulsar_name.$file";
+		foreach ($all_cals as $cal) {
+			$cal_file = $cal['filename'];
+			$cal_dir = $cal['data_loc'];
+			$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("$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")) {
+						echo "Successfully created symlink!<br>\n";
+					}
+				}
+			}
+			$all_files .= " $cal_pulsar_name.$cal_file";
+		}
+		
+		
+		
+		//$cal_file = 
+		
+	}
+	//echo "date = $tar_filename<br>\n";
+
+	// -h to dereference the symlinks
+	$command = "tar --dereference -cf $tar_filename.tar $all_files";
+	//echo "command = $command<br>\n";
+
+	// Change into the working directory first then tar
+	chdir(WORKING_DIR);
+
+	exec("$command", $output_array);
+	
+	mysql_close($link);
+	
+	if (file_exists(WORKING_DIR."/$tar_filename.tar")) {
+		echo "Your requested archive set was successfully packaged. If you haven't been redirected to the tar
+		file, you may access it directly by clicking on the following link:<br>
+		<a href=\"".DATA_ARCHIVE_URL."/downloads/$tar_filename.tar\">".DATA_ARCHIVE_URL."/downloads/$tar_filename.tar</a><br>\n";
+		
+		return "$tar_filename.tar";
+	}
+}
+
+// Create a tar of just the cals (no observations)
+function tarCalFiles($cart_obs, $all_results, $cals_within_mins) {
+	$all_files = "";
+	$obs_cals  = array();
+	
+	$tar_filename = date("YmdHis");
+	
+	// Need to open up db connection to query cals in cart
+	$link = db_connect();
+
+	foreach ($cart_obs as $index) {
+		
+		// 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);
+		
+		foreach ($all_cals as $cal) {
+			$cal_file = $cal['filename'];
+			$cal_dir = $cal['data_loc'];
+			$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("$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")) {
+						echo "Successfully created symlink!<br>\n";
+					}
+				}
+			}
+			$all_files .= " $cal_pulsar_name.$cal_file";
+		}
+		
+		
+	}
+	
+	//echo "date = $tar_filename<br>\n";
+
+	// -h to dereference the symlinks
+	$command = "tar --dereference -cf $tar_filename.tar $all_files";
+	//echo "command = $command<br>\n";
+
+	// Change into the working directory first then tar
+	chdir(WORKING_DIR);
+
+	exec("$command", $output_array);
+	
+	mysql_close($link);
+
+	if (file_exists(WORKING_DIR."/$tar_filename.tar")) {
+		echo "Your requested archive set was successfully packaged. If you haven't been redirected to the tar
+		file, you may access it directly by clicking on the following link:<br>
+		<a href=\"".DATA_ARCHIVE_URL."/downloads/$tar_filename.tar\">".DATA_ARCHIVE_URL."/downloads/$tar_filename.tar</a><br>\n";
+		
+		return "$tar_filename.tar";
+	}
+}
+
+// Create a tar of all observation files (only)
+function tarObsFiles($cart_obs, $all_results) {
+	$all_files = "";
+	
+	$tar_filename = date("YmdHis");
+
+	foreach ($cart_obs as $index) {
+		$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("$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")) {
+					echo "Successfully created symlink!<br>\n";
+				}
+			}
+		}
+		$all_files .= " $pulsar_name.$file";
+		
+	}
+	//echo "date = $tar_filename<br>\n";
+
+	// -h to dereference the symlinks
+	$command = "tar --dereference -cf $tar_filename.tar $all_files";
+	//echo "command = $command<br>\n";
+
+	// Change into the working directory first then tar
+	chdir(WORKING_DIR);
+
+	exec("$command", $output_array);
+	
+	if (file_exists(WORKING_DIR."/$tar_filename.tar")) {
+		echo "Your requested archive set was successfully packaged. If you haven't been redirected to the tar
+		file, you may access it directly by clicking on the following link:<br>
+		<a href=\"".DATA_ARCHIVE_URL."/downloads/$tar_filename.tar\">".DATA_ARCHIVE_URL."/downloads/$tar_filename.tar</a><br>\n";
+		
+		return "$tar_filename.tar";
+	}
+}
+
+
+function hms2degs($hms_str) {
+
+	list($hour, $min, $sec) = split(":", $hms_str);
+	
+	return ($hour + $min/60 + $sec/60)*HOURS2DEGS;
+}
+
+function dms2degs($dms_str) {
+	
+	list($deg, $min, $sec) = split(":", $dms_str) ;
+	
+	return $deg + $min/60 + $sec/60;
+}
+
+
+// Query the cals table for respective cals
+function query_cals($pulsar_name, $mjd, $data_type, $span_mins) {
+
+  global $parameters;
+
+//   $link = db_connect_admin();
+//   loadNewTables();
+
+	$all_cals = array();
+	
+	//$full_path = $data_loc . "/" . $filename;
+	
+	$mjd_max = mjd_add($mjd, $span_mins);
+	$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 $parameters 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";
+
+	$result = mysql_query($query) or die('Query failed: ' . mysql_error());
+
+	while ($line = mysql_fetch_assoc($result)) {
+		array_push($all_cals, $line );
+	}
+
+	$_SESSION['cals'] = "cals";
+
+	mysql_free_result($result);
+
+// 	mysql_close($link);
+
+	return $all_cals;
+}
+
+
+function array2urlstring($arrayName, $array ) {
+	$str = "";
+	$brackets = urlencode("[]");
+	
+	foreach ($array as $item) {
+		$str .= "$arrayName$brackets=$item&";
+	}
+	$str = trim($str, "&");
+	return $str;
+}
+
+?>
Index: /trunk/sql/create_new_permanent_tables.sql
===================================================================
--- /trunk/sql/create_new_permanent_tables.sql	(revision 157)
+++ /trunk/sql/create_new_permanent_tables.sql	(revision 157)
@@ -0,0 +1,273 @@
+-- if the table exists, drop it so we can reload it
+DROP TABLE IF EXISTS s70;
+
+-- create the table with the following fields
+CREATE TABLE s70 (
+	filename VARCHAR(32),
+	src_name VARCHAR(16),
+	project_id VARCHAR(10),
+	raj VARCHAR(20),
+	decj VARCHAR(20),
+ 	data_type VARCHAR(128),
+        obsfreq DECIMAL(32,16),
+	bw DECIMAL(16,6),
+	scanlen DECIMAL(32,20),
+ 	date VARCHAR(16),   
+ 	ut VARCHAR(16),   
+ 	MJD DECIMAL(32,26),
+	rajd DOUBLE,
+	decjd DOUBLE,
+	gl DOUBLE,
+	gb DOUBLE,
+	bmaj FLOAT,
+	bmin FLOAT,
+	bpa FLOAT,
+	dm DECIMAL(16,10),
+	period DECIMAL(32,24),
+ 	nchan INT(6),        
+	npol INT(6),
+ 	nbin INT(6),        
+ 	nsub INT(6),        
+ 	tsamp FLOAT,       
+	nbits tinyint(3) unsigned,  
+	nbeam tinyint(3) unsigned,
+	cnfg VARCHAR(128),
+ 	inst VARCHAR(32),
+ 	rcvr VARCHAR(16),   
+	hdrver VARCHAR(10),
+	survey VARCHAR(10),
+	telescope VARCHAR(16),
+ 	site VARCHAR(8),    
+ 	obsrvr VARCHAR(32),   
+	data_loc VARCHAR(100),
+ 	file_size_bytes INT(32),
+	PRIMARY KEY (filename, data_loc)
+);
+
+LOAD DATA LOCAL
+INFILE "/pulsar/archive13/S70V/summary_S70.csv"
+INTO TABLE s70
+FIELDS TERMINATED BY ","
+OPTIONALLY ENCLOSED BY "\""
+IGNORE 1 LINES  -- this ignores the first line in the csv file which contains the column headers.
+(filename,src_name,project_id,raj,decj,data_type,obsfreq,bw,scanlen,date,ut,MJD,rajd,decjd,gl,gb,bmaj,bmin,bpa,dm,period,nchan,npol,nbin,nsub,tsamp,nbits,nbeam,cnfg,inst,rcvr,hdrver,survey,telescope,site,obsrvr,data_loc,file_size_bytes);
+
+UPDATE s70 SET bw = bw * nchan;
+
+
+-- base coords for galactic coord transformation.
+SET @ngpra=192.859508, @ngpdec=27.128336, @ascnode=32.932; 
+
+-- if the table exists, drop it so we can reload it
+DROP TABLE IF EXISTS obs;
+
+-- create the table with the following fields
+CREATE TABLE obs (
+	filename VARCHAR(32),
+	src_name VARCHAR(16),
+	project_id VARCHAR(10),
+	raj VARCHAR(20),
+	decj VARCHAR(20),
+ 	data_type VARCHAR(128),
+        obsfreq DECIMAL(32,16),
+	bw DECIMAL(16,6),
+	scanlen DECIMAL(32,20),
+ 	date VARCHAR(16),   
+ 	ut VARCHAR(16),   
+ 	MJD DECIMAL(32,26),
+	rajd DOUBLE,
+	decjd DOUBLE,
+	gl DOUBLE,
+	gb DOUBLE,
+	bmaj FLOAT,
+	bmin FLOAT,
+	bpa FLOAT,
+	dm DECIMAL(16,10),
+	period DECIMAL(32,24),
+ 	nchan INT(6),        
+	npol INT(6),
+ 	nbin INT(6),        
+ 	nsub INT(6),        
+ 	tsamp FLOAT,       
+	nbits tinyint(3) unsigned,  
+	nbeam tinyint(3) unsigned,
+	cnfg VARCHAR(128),
+ 	inst VARCHAR(32),
+ 	rcvr VARCHAR(16),   
+	hdrver VARCHAR(10),
+	survey VARCHAR(10),
+	telescope VARCHAR(16),
+ 	site VARCHAR(8),    
+ 	obsrvr VARCHAR(32),   
+	data_loc VARCHAR(100),
+ 	file_size_bytes INT(32),
+	PRIMARY KEY (filename, data_loc)
+)
+ SELECT
+	o.filename, 
+	o.pulsar_name as src_name,
+	NULL as project_id,
+	concat(raj_hour,':',raj_minute,':',raj_second) as raj,
+	case 
+	     when (o.pulsar_name like '%-%') 
+		then concat('-',abs(o.decj_degree),':',o.decj_minute,':',o.decj_second)
+	     when (o.decj_degree<0.) 
+		then concat('-',abs(o.decj_degree),':',o.decj_minute,':',o.decj_second)
+             else concat(abs(o.decj_degree),':',o.decj_minute,':',o.decj_second) 
+    	end as decj,
+	o.data_type,
+	o.freq as obsfreq,
+	o.bw as bw,
+	o.length as scanlen, 
+	o.date as date,
+	o.ut as ut,
+	o.MJD as MJD,
+        (o.raj_hour+o.raj_minute/60.+o.raj_second/3600.)*15. as rajd,
+        case when o.pulsar_name like '%-%'
+		then -1.*(abs(o.decj_degree)+o.decj_minute/60.+o.decj_second/3600.)
+             when (o.decj_degree<0.)
+		then -1.*(abs(o.decj_degree)+o.decj_minute/60.+o.decj_second/3600.)
+             else abs(o.decj_degree)+o.decj_minute/60.+o.decj_second/3600. 
+	end as decjd,
+	NULL as gl, 
+	NULL as gb,
+	(1.2*(299792458./(o.freq*1.e6))/64.) * 180./pi() as BMAJ,
+	(1.2*(299792458./(o.freq*1.e6))/64.) * 180./pi() as BMIN,
+	0. as BPA,
+	o.dm, 
+	o.period, 
+	o.nchan,
+	o.npol,
+	o.nbin, 
+	o.nsub, 
+	o.tsamp,
+	NULL as nbits,
+	o.nbeam, 
+	o.cnfg,
+	o.inst,
+	o.rcvr,
+	NULL as hdrver,
+	NULL as survey,
+	'PARKES' as telescope,
+	o.site as site,
+	o.obsrvr,
+	o.data_loc, 
+	o.file_size_bytes
+ FROM observations as o;
+
+
+UPDATE obs
+  SET	gl = case 
+		when degrees( atan2( ( sin(radians(decjd))*cos(radians(@ngpdec)) - cos(radians(decjd))*sin(radians(@ngpdec))*cos(radians(rajd-@ngpra)) ) , ( cos(radians(decjd))*sin(radians(rajd-@ngpra)) ) ) ) + @ascnode > 0 
+	        then degrees( atan2( ( sin(radians(decjd))*cos(radians(@ngpdec)) - cos(radians(decjd))*sin(radians(@ngpdec))*cos(radians(rajd-@ngpra)) ) , ( cos(radians(decjd))*sin(radians(rajd-@ngpra)) ) ) ) + @ascnode
+       		else degrees( atan2( ( sin(radians(decjd))*cos(radians(@ngpdec)) - cos(radians(decjd))*sin(radians(@ngpdec))*cos(radians(rajd-@ngpra)) ) , ( cos(radians(decjd))*sin(radians(rajd-@ngpra)) ) ) ) + @ascnode + 360.
+	   end,
+	gb = (degrees( asin( cos(radians(decjd))*cos(radians(@ngpdec))*cos(radians(rajd-@ngpra)) + sin(radians(decjd))*sin(radians(@ngpdec)))));
+
+--------------------------------------
+-- Now create the new cals table
+--
+-- if the table exists, drop it so we can reload it
+DROP TABLE IF EXISTS calib;
+
+-- create the table with the following fields
+CREATE TABLE calib (
+	filename VARCHAR(32),
+	src_name VARCHAR(16),
+	project_id VARCHAR(10),
+	raj VARCHAR(20),
+	decj VARCHAR(20),
+ 	data_type VARCHAR(128),
+        obsfreq DECIMAL(32,16),
+	bw DECIMAL(16,6),
+	scanlen DECIMAL(32,20),
+ 	date VARCHAR(16),   
+ 	ut VARCHAR(16),   
+ 	MJD DECIMAL(32,26),
+	rajd DOUBLE,
+	decjd DOUBLE,
+	gl DOUBLE,
+	gb DOUBLE,
+	bmaj FLOAT,
+	bmin FLOAT,
+	bpa FLOAT,
+	dm DECIMAL(16,10),
+	period DECIMAL(32,24),
+ 	nchan INT(6),        
+	npol INT(6),
+ 	nbin INT(6),        
+ 	nsub INT(6),        
+ 	tsamp FLOAT,       
+	nbits tinyint(3) unsigned,  
+	nbeam tinyint(3) unsigned,
+	cnfg VARCHAR(128),
+ 	inst VARCHAR(32),
+ 	rcvr VARCHAR(16),   
+	hdrver VARCHAR(10),
+	survey VARCHAR(10),
+	telescope VARCHAR(16),
+ 	site VARCHAR(8),    
+ 	obsrvr VARCHAR(32),   
+	data_loc VARCHAR(100),
+ 	file_size_bytes INT(32),
+	PRIMARY KEY (filename, data_loc)
+)
+ SELECT
+	c.filename, 
+	c.pulsar_name as src_name,
+	NULL as project_id,
+	concat(raj_hour,':',raj_minute,':',raj_second) as raj,
+	case 
+	     when (c.pulsar_name like '%-%') 
+		then concat('-',abs(c.decj_degree),':',c.decj_minute,':',c.decj_second)
+	     when (c.decj_degree<0.) 
+		then concat('-',abs(c.decj_degree),':',c.decj_minute,':',c.decj_second)
+             else concat(abs(c.decj_degree),':',c.decj_minute,':',c.decj_second) 
+    	end as decj,
+	c.data_type,
+	c.freq as obsfreq,
+	c.bw as bw,
+	NULL as scanlen, 
+	NULL as date,
+	NULL as ut,
+	c.MJD as MJD,
+        (c.raj_hour+c.raj_minute/60.+c.raj_second/3600.)*15. as rajd,
+        case when c.pulsar_name like '%-%' 
+		then -1.*(abs(c.decj_degree)+c.decj_minute/60.+c.decj_second/3600.)
+             when (c.decj_degree<0.)
+		then -1.*(abs(c.decj_degree)+c.decj_minute/60.+c.decj_second/3600.)
+             else abs(c.decj_degree)+c.decj_minute/60.+c.decj_second/3600. 
+	end as decjd,
+	NULL as gl, 
+	NULL as gb,
+	(1.2*(299792458./(c.freq*1.e6))/64.) * 180./pi() as BMAJ,
+	(1.2*(299792458./(c.freq*1.e6))/64.) * 180./pi() as BMIN,
+	0. as BPA,
+	c.dm, 
+	c.period, 
+	c.nchan,
+	c.npol,
+	c.nbin, 
+	c.nsub, 
+	NULL as tsamp,
+	NULL as nbits,
+	NULL as nbeam, 
+	c.cnfg,
+	c.inst,
+	c.rcvr,
+	NULL as hdrver,
+	NULL as survey,
+	'PARKES' as telescope,
+	c.site as site,
+	c.obsrvr,
+	c.data_loc, 
+	c.file_size_bytes
+ FROM cals as c;
+
+UPDATE calib
+  SET	gl = case 
+		when degrees( atan2( ( sin(radians(decjd))*cos(radians(@ngpdec)) - cos(radians(decjd))*sin(radians(@ngpdec))*cos(radians(rajd-@ngpra)) ) , ( cos(radians(decjd))*sin(radians(rajd-@ngpra)) ) ) ) + @ascnode > 0 
+	        then degrees( atan2( ( sin(radians(decjd))*cos(radians(@ngpdec)) - cos(radians(decjd))*sin(radians(@ngpdec))*cos(radians(rajd-@ngpra)) ) , ( cos(radians(decjd))*sin(radians(rajd-@ngpra)) ) ) ) + @ascnode
+       		else degrees( atan2( ( sin(radians(decjd))*cos(radians(@ngpdec)) - cos(radians(decjd))*sin(radians(@ngpdec))*cos(radians(rajd-@ngpra)) ) , ( cos(radians(decjd))*sin(radians(rajd-@ngpra)) ) ) ) + @ascnode + 360.
+	   end,
+	gb = (degrees( asin( cos(radians(decjd))*cos(radians(@ngpdec))*cos(radians(rajd-@ngpra)) + sin(radians(decjd))*sin(radians(@ngpdec)))));
Index: /trunk/sql/create_new_tables.sql
===================================================================
--- /trunk/sql/create_new_tables.sql	(revision 156)
+++ /trunk/sql/create_new_tables.sql	(revision 157)
@@ -5,17 +5,15 @@
 CREATE TEMPORARY TABLE s70 (
 	filename VARCHAR(32),
-	data_loc VARCHAR(100),
- 	file_size_bytes INT(32),
+	src_name VARCHAR(16),
 	project_id VARCHAR(10),
-	hdrver VARCHAR(10),
-	survey VARCHAR(10),
-	telescope VARCHAR(16),
- 	site VARCHAR(8),    
-	src_name VARCHAR(16),
+	raj VARCHAR(20),
+	decj VARCHAR(20),
+ 	data_type VARCHAR(128),
+        obsfreq DECIMAL(32,16),
+	bw DECIMAL(16,6),
+	scanlen DECIMAL(32,20),
  	date VARCHAR(16),   
  	ut VARCHAR(16),   
  	MJD DECIMAL(32,26),
-	raj VARCHAR(20),
-	decj VARCHAR(20),
 	rajd DOUBLE,
 	decjd DOUBLE,
@@ -27,19 +25,21 @@
 	dm DECIMAL(16,10),
 	period DECIMAL(32,24),
-	cnfg VARCHAR(128),
- 	inst VARCHAR(32),
-	data_type VARCHAR(128),
- 	rcvr VARCHAR(16),   
- 	obsrvr VARCHAR(32),   
-        obsfreq DECIMAL(32,16),
-	chanbw DECIMAL(16,6),
  	nchan INT(6),        
 	npol INT(6),
  	nbin INT(6),        
  	nsub INT(6),        
- 	scanlen DECIMAL(32,20),
  	tsamp FLOAT,       
 	nbits tinyint(3) unsigned,  
 	nbeam tinyint(3) unsigned,
+	cnfg VARCHAR(128),
+ 	inst VARCHAR(32),
+ 	rcvr VARCHAR(16),   
+	hdrver VARCHAR(10),
+	survey VARCHAR(10),
+	telescope VARCHAR(16),
+ 	site VARCHAR(8),    
+ 	obsrvr VARCHAR(32),   
+	data_loc VARCHAR(100),
+ 	file_size_bytes INT(32),
 	PRIMARY KEY (filename, data_loc)
 );
@@ -51,5 +51,7 @@
 OPTIONALLY ENCLOSED BY "\""
 IGNORE 1 LINES  -- this ignores the first line in the csv file which contains the column headers.
-(filename,data_loc,file_size_bytes,project_id,hdrver,survey,telescope,site,src_name,date,ut,MJD,raj,decj,rajd,decjd,gl,gb,bmaj,bmin,bpa,dm,period,cnfg,inst,data_type,rcvr,obsrvr,obsfreq,chanbw,nchan,npol,nbin,nsub,scanlen,tsamp,nbits,nbeam);
+(filename,src_name,project_id,raj,decj,data_type,obsfreq,bw,scanlen,date,ut,MJD,rajd,decjd,gl,gb,bmaj,bmin,bpa,dm,period,nchan,npol,nbin,nsub,tsamp,nbits,nbeam,cnfg,inst,rcvr,hdrver,survey,telescope,site,obsrvr,data_loc,file_size_bytes);
+
+UPDATE s70 SET bw = bw * nchan;
 
 
@@ -63,17 +65,15 @@
 CREATE TEMPORARY TABLE obs (
 	filename VARCHAR(32),
-	data_loc VARCHAR(100),
- 	file_size_bytes INT(32),
+	src_name VARCHAR(16),
 	project_id VARCHAR(10),
-	hdrver VARCHAR(10),
-	survey VARCHAR(10),
-	telescope VARCHAR(16),
- 	site VARCHAR(8),    
-	src_name VARCHAR(16),
+	raj VARCHAR(20),
+	decj VARCHAR(20),
+ 	data_type VARCHAR(128),
+        obsfreq DECIMAL(32,16),
+	bw DECIMAL(16,6),
+	scanlen DECIMAL(32,20),
  	date VARCHAR(16),   
  	ut VARCHAR(16),   
  	MJD DECIMAL(32,26),
-	raj VARCHAR(20),
-	decj VARCHAR(20),
 	rajd DOUBLE,
 	decjd DOUBLE,
@@ -85,34 +85,27 @@
 	dm DECIMAL(16,10),
 	period DECIMAL(32,24),
-	cnfg VARCHAR(128),
- 	inst VARCHAR(32),
-	data_type VARCHAR(128),
- 	rcvr VARCHAR(16),   
- 	obsrvr VARCHAR(32),   
-        obsfreq DECIMAL(32,16),
-	chanbw DECIMAL(16,6),
  	nchan INT(6),        
 	npol INT(6),
  	nbin INT(6),        
  	nsub INT(6),        
- 	scanlen DECIMAL(32,20),
  	tsamp FLOAT,       
 	nbits tinyint(3) unsigned,  
 	nbeam tinyint(3) unsigned,
+	cnfg VARCHAR(128),
+ 	inst VARCHAR(32),
+ 	rcvr VARCHAR(16),   
+	hdrver VARCHAR(10),
+	survey VARCHAR(10),
+	telescope VARCHAR(16),
+ 	site VARCHAR(8),    
+ 	obsrvr VARCHAR(32),   
+	data_loc VARCHAR(100),
+ 	file_size_bytes INT(32),
 	PRIMARY KEY (filename, data_loc)
 )
  SELECT
 	o.filename, 
-	o.data_loc, 
-	o.file_size_bytes, 
+	o.pulsar_name as src_name,
 	NULL as project_id,
-	NULL as hdrver,
-	NULL as survey,
-	'PARKES' as telescope,
-	o.site as site,
-	o.pulsar_name as src_name,
-	o.date as date,
-	o.ut as ut,
-	o.MJD as MJD,
 	concat(raj_hour,':',raj_minute,':',raj_second) as raj,
 	case 
@@ -123,6 +116,13 @@
              else concat(abs(o.decj_degree),':',o.decj_minute,':',o.decj_second) 
     	end as decj,
+	o.data_type,
+	o.freq as obsfreq,
+	o.bw as bw,
+	o.length as scanlen, 
+	o.date as date,
+	o.ut as ut,
+	o.MJD as MJD,
         (o.raj_hour+o.raj_minute/60.+o.raj_second/3600.)*15. as rajd,
-        case when o.pulsar_name like "%-%" 
+        case when o.pulsar_name like '%-%'
 		then -1.*(abs(o.decj_degree)+o.decj_minute/60.+o.decj_second/3600.)
              when (o.decj_degree<0.)
@@ -137,19 +137,21 @@
 	o.dm, 
 	o.period, 
-	o.cnfg,
-	o.inst,
-	o.data_type,
-	o.rcvr,
-	o.obsrvr,
-	o.freq as obsfreq,
-	o.bw as chanbw,
 	o.nchan,
 	o.npol,
 	o.nbin, 
 	o.nsub, 
-	o.length as scanlen, 
 	o.tsamp,
 	NULL as nbits,
-	o.nbeam	
+	o.nbeam, 
+	o.cnfg,
+	o.inst,
+	o.rcvr,
+	NULL as hdrver,
+	NULL as survey,
+	'PARKES' as telescope,
+	o.site as site,
+	o.obsrvr,
+	o.data_loc, 
+	o.file_size_bytes
  FROM observations as o;
 
@@ -172,17 +174,15 @@
 CREATE TEMPORARY TABLE calib (
 	filename VARCHAR(32),
-	data_loc VARCHAR(100),
- 	file_size_bytes INT(32),
+	src_name VARCHAR(16),
 	project_id VARCHAR(10),
-	hdrver VARCHAR(10),
-	survey VARCHAR(10),
-	telescope VARCHAR(16),
- 	site VARCHAR(8),    
-	src_name VARCHAR(16),
+	raj VARCHAR(20),
+	decj VARCHAR(20),
+ 	data_type VARCHAR(128),
+        obsfreq DECIMAL(32,16),
+	bw DECIMAL(16,6),
+	scanlen DECIMAL(32,20),
  	date VARCHAR(16),   
  	ut VARCHAR(16),   
  	MJD DECIMAL(32,26),
-	raj VARCHAR(20),
-	decj VARCHAR(20),
 	rajd DOUBLE,
 	decjd DOUBLE,
@@ -194,34 +194,27 @@
 	dm DECIMAL(16,10),
 	period DECIMAL(32,24),
-	cnfg VARCHAR(128),
- 	inst VARCHAR(32),
-	data_type VARCHAR(128),
- 	rcvr VARCHAR(16),   
- 	obsrvr VARCHAR(32),   
-        obsfreq DECIMAL(32,16),
-	chanbw DECIMAL(16,6),
  	nchan INT(6),        
 	npol INT(6),
  	nbin INT(6),        
  	nsub INT(6),        
- 	scanlen DECIMAL(32,20),
  	tsamp FLOAT,       
 	nbits tinyint(3) unsigned,  
 	nbeam tinyint(3) unsigned,
+	cnfg VARCHAR(128),
+ 	inst VARCHAR(32),
+ 	rcvr VARCHAR(16),   
+	hdrver VARCHAR(10),
+	survey VARCHAR(10),
+	telescope VARCHAR(16),
+ 	site VARCHAR(8),    
+ 	obsrvr VARCHAR(32),   
+	data_loc VARCHAR(100),
+ 	file_size_bytes INT(32),
 	PRIMARY KEY (filename, data_loc)
 )
  SELECT
 	c.filename, 
-	c.data_loc, 
-	c.file_size_bytes, 
+	c.pulsar_name as src_name,
 	NULL as project_id,
-	NULL as hdrver,
-	NULL as survey,
-	'PARKES' as telescope,
-	c.site as site,
-	c.pulsar_name as src_name,
-	NULL as date,
-	NULL as ut,
-	c.MJD as MJD,
 	concat(raj_hour,':',raj_minute,':',raj_second) as raj,
 	case 
@@ -232,6 +225,13 @@
              else concat(abs(c.decj_degree),':',c.decj_minute,':',c.decj_second) 
     	end as decj,
+	c.data_type,
+	c.freq as obsfreq,
+	c.bw as bw,
+	NULL as scanlen, 
+	NULL as date,
+	NULL as ut,
+	c.MJD as MJD,
         (c.raj_hour+c.raj_minute/60.+c.raj_second/3600.)*15. as rajd,
-        case when c.pulsar_name like "%-%" 
+        case when c.pulsar_name like '%-%' 
 		then -1.*(abs(c.decj_degree)+c.decj_minute/60.+c.decj_second/3600.)
              when (c.decj_degree<0.)
@@ -246,19 +246,21 @@
 	c.dm, 
 	c.period, 
-	c.cnfg,
-	c.inst,
-	c.data_type,
-	c.rcvr,
-	c.obsrvr,
-	c.freq as obsfreq,
-	c.bw as chanbw,
 	c.nchan,
 	c.npol,
 	c.nbin, 
 	c.nsub, 
-	NULL as scanlen, 
 	NULL as tsamp,
 	NULL as nbits,
-	NULL as nbeam	
+	NULL as nbeam, 
+	c.cnfg,
+	c.inst,
+	c.rcvr,
+	NULL as hdrver,
+	NULL as survey,
+	'PARKES' as telescope,
+	c.site as site,
+	c.obsrvr,
+	c.data_loc, 
+	c.file_size_bytes
  FROM cals as c;
 
