Index: trunk/htdocs/perl/find_archives.pl
===================================================================
--- trunk/htdocs/perl/find_archives.pl	(revision 203)
+++ trunk/htdocs/perl/find_archives.pl	(revision 204)
@@ -14,5 +14,5 @@
 use strict;
 use File::Find ();
-use DBI qw(:sql_types);
+#use DBI qw(:sql_types);
 use POSIX;
 
@@ -42,6 +42,5 @@
     $params_DATE    
     $params_TIME    
-    $params_MJDINT  
-    $params_MJDFRAC 
+    $params_MJD
     $params_BMAJ    
     $params_BMIN    
@@ -77,5 +76,5 @@
 #$params  = "name raj decj dm period bw cnfg freq inst intmjd fracmjd npol nchan nbin nsub rcvr site length obsrvr";
 #$params  = "name projid ra dec freq bw length stt_date stt_time intmjd fracmjd bmaj bmin bpa dm period nchan npol nbin nsub nbits tsamp nbeam cnfg backend rcvr telescop site obsrvr";
-$params  = "name projid ra dec freq bw length stt_date stt_time intmjd fracmjd mjd bmaj bmin bpa dm period nchan npol nbin nsub nbits tsamp nbeam cnfg backend rcvr telescop site obsrvr";
+$params  = "name projid ra dec freq bw length stt_date stt_time mjd bmaj bmin bpa dm period nchan npol nbin nsub nbits tsamp nbeam beconfig backend rcvr telescop asite observer";
 
 # vap result parameter indices. Used to locate the resulting 
@@ -90,24 +89,23 @@
 $params_DATE    = 7;
 $params_TIME    = 8;
-$params_MJDINT  = 9;
-$params_MJDFRAC = 10;
-$params_BMAJ    = 11;
-$params_BMIN    = 12;
-$params_BPA     = 13;
-$params_DM      = 14;
-$params_PERIOD  = 15;
-$params_NCHAN   = 16;
-$params_NPOL    = 17;
-$params_NBIN    = 18;
-$params_NSUB    = 19;
-$params_NBITS   = 20;
-$params_TSAMP   = 21;
-$params_NBEAM   = 22;
-$params_CNFG    = 23;
-$params_INST    = 24;
-$params_RCVR    = 25;
-$params_TELESCOP= 26;
-$params_SITE    = 27;
-$params_OBSRVR  = 28;
+$params_MJD     = 9;
+$params_BMAJ    = 10;
+$params_BMIN    = 11;
+$params_BPA     = 12;
+$params_DM      = 13;
+$params_PERIOD  = 14;
+$params_NCHAN   = 15;
+$params_NPOL    = 16;
+$params_NBIN    = 17;
+$params_NSUB    = 18;
+$params_NBITS   = 19;
+$params_TSAMP   = 20;
+$params_NBEAM   = 21;
+$params_CNFG    = 22;
+$params_INST    = 23;
+$params_RCVR    = 24;
+$params_TELESCOP= 25;
+$params_SITE    = 26;
+$params_OBSRVR  = 27;
 
 # filename extensions
@@ -157,5 +155,5 @@
 
 if ($ARGV[0] eq "-d") {
-	deleteStaleRecords();
+#	deleteStaleRecords();
 	$default = 0;
 	shift @ARGV;
@@ -182,5 +180,5 @@
 if ($default) {
 
-	deleteStaleRecords();
+#	deleteStaleRecords();
 
 	@archive_dirs = @ARGV;
@@ -326,16 +324,20 @@
 
 				while ($vap_out = <VAP>) {
+					$vap_out =~ s/^\s+//g; #remove any leading space
 					@result_params = split(/\s+/, $vap_out);
 
 					# +1 because first column is filename
-					if (scalar(@result_params) == ($num_vap_params + 1)) {
+					if (@result_params[0] ne "filename" && scalar(@result_params)!=0){
+					    if (scalar(@result_params) == ($num_vap_params + 1)) {
 						print "@result_params\n";
-
+						
 						populate_observations($File::Find::name);
+					    }
+					    else {
+						print "Incorrect number of cols = ".scalar(@result_params).". Expected " . $num_vap_params+1 ."\n";
+						print "@result_params\n";
+					    }
 					}
-					else {
-						print "Incorrect number of cols = ".scalar(@result_params).". Expected " . $num_vap_params+1 ."\n";
-					}
-				}
+				    }
 				print "\n";
 			}
@@ -351,68 +353,68 @@
     return 0;
 
-	my $filename = $_[0];
-	my $search_data_loc;
-	my $search_filename;
-	my $pulsar_name;
-	
-	if ( $filename =~ m/(.*(J[0-9]{4}[+-][0-9]{1,4}.*))[\/]+([a-z][0-9]{6}_[0-9]{6}\.([a-z]{2,}))$/i ) {
-		$search_data_loc = $1;
-		$search_filename = $3;
-		$pulsar_name = $2;
-	}
-	
-	elsif ($filename =~ m/(.*(J[0-9]{4}[+-][0-9]{1,4}.*))[\/]+([0-9]{4}-[0-9]{2}-[0-9]{2}-[0-9]{2}:[0-9]{2}:[0-9]{2})$/i ) {
-		$search_data_loc = $1;
-		$search_filename = $3;
-		$pulsar_name = $2;
-	}
-	else {
-		return 1;
-	}
-	
-	
-	my $sql;
-	
-	if ($pulsar_name =~ m/.*_R$/) {
-		
-		$sql = qq{ SELECT * from cals 
-							  WHERE data_loc LIKE ? AND 
-								      filename    = ?
-						};
-	}
-	else {
-		print "This is an observation\n";
-		$sql = qq{ SELECT * from observations 
-							  WHERE data_loc LIKE ? AND 
-								      filename    = ?
-						};
-	}
-	
-	my $sth = $db_handle->prepare( $sql );
-
-  eval {
-    print "like $search_data_loc and filename = $search_filename \n";
-    
-    $sth->bind_param( 1, $search_data_loc, SQL_VARCHAR );
-    $sth->bind_param( 2, $search_filename, SQL_VARCHAR );
-    $sth->execute();
-
-	};
-
-  if( $@ ) {
-    warn "Database error: $DBI::errstr\n";
-    $db_handle->rollback(); #just die if rollback is failing
-  }
-	
-	# read the records
-	my @data = $sth->fetchrow_array();
-		
-	$sth->finish();
-	
-	if (scalar(@data) > 0) {
-		return 1;
-	}
-	
-	return 0;
+#	my $filename = $_[0];
+#	my $search_data_loc;
+#	my $search_filename;
+#	my $pulsar_name;
+#	
+#	if ( $filename =~ m/(.*(J[0-9]{4}[+-][0-9]{1,4}.*))[\/]+([a-z][0-9]{6}_[0-9]{6}\.([a-z]{2,}))$/i ) {
+#		$search_data_loc = $1;
+#		$search_filename = $3;
+#		$pulsar_name = $2;
+#	}
+#	
+#	elsif ($filename =~ m/(.*(J[0-9]{4}[+-][0-9]{1,4}.*))[\/]+([0-9]{4}-[0-9]{2}-[0-9]{2}-[0-9]{2}:[0-9]{2}:[0-9]{2})$/i ) {
+#		$search_data_loc = $1;
+#		$search_filename = $3;
+#		$pulsar_name = $2;
+#	}
+#	else {
+#		return 1;
+#	}
+#	
+#	
+#	my $sql;
+#	
+#	if ($pulsar_name =~ m/.*_R$/) {
+#		
+#		$sql = qq{ SELECT * from cals 
+#							  WHERE data_loc LIKE ? AND 
+#								      filename    = ?
+#						};
+#	}
+#	else {
+#		print "This is an observation\n";
+#		$sql = qq{ SELECT * from observations 
+#							  WHERE data_loc LIKE ? AND 
+#								      filename    = ?
+#						};
+#	}
+#	
+#	my $sth = $db_handle->prepare( $sql );
+#
+#  eval {
+#    print "like $search_data_loc and filename = $search_filename \n";
+#    
+#    $sth->bind_param( 1, $search_data_loc, SQL_VARCHAR );
+#    $sth->bind_param( 2, $search_filename, SQL_VARCHAR );
+#    $sth->execute();
+#
+#	};
+#
+#  if( $@ ) {
+#    warn "Database error: $DBI::errstr\n";
+#    $db_handle->rollback(); #just die if rollback is failing
+#  }
+#	
+#	# read the records
+#	my @data = $sth->fetchrow_array();
+#		
+#	$sth->finish();
+#	
+#	if (scalar(@data) > 0) {
+#		return 1;
+#	}
+#	
+#	return 0;
 }
 
@@ -487,10 +489,16 @@
 
 	# Get the total MJD
-	if ( $result_params[$params_MJDINT] eq "N/A" && 
-	     $result_params[$params_MJDFRAC] eq "N/A" ) {
-		$MJD = undef;
-	}
-	else {
-		$MJD = $result_params[$params_MJDINT] + $result_params[$params_MJDFRAC];
+#	if ( $result_params[$params_MJDINT] eq "N/A" && 
+#	     $result_params[$params_MJDFRAC] eq "N/A" ) {
+#		$MJD = undef;
+#	}
+#	else {
+#		$MJD = $result_params[$params_MJDINT] + $result_params[$params_MJDFRAC];
+#	}
+	if($result_params[$params_MJD] eq "INVALID"){
+	    $MJD = undef;
+	}
+	else{
+	    $MJD = $result_params[$params_MJD];
 	}
 	
@@ -599,114 +607,114 @@
 	print "file_size = $file_size bytes\n";
 
-	my $sql;
-	
-	if ($data_loc =~ /\_R/) {
-	    print "Inserting cal file $display_filename\n";
-		
-	    $sql = qq{ INSERT INTO cals 
-			   (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
-			    ) 
-			   
-			   VALUES 
-			   ( ?, ?, ?
-			     ?, ?, ?, ?, ?,
-			     ?, ?, ?, ?, 
-			     ?, ?, ?, ?, ?, ?, ?, 
-			     ?, ?, ?, ?, ?, ?, 
-			     ?, ?, ?, 
-			     ?, ?, ?, ?, ?, 
-			     ?, ?, ?, 
-			     ?, ?, 
-			     ) 
-		       };
-	}
-	else {
-	    
-	    print "Inserting obs file $display_filename\n";
-	    
-	    $sql = qq{ INSERT INTO observations 
-			   (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
-			    ) 
-			   
-			   VALUES 
-			   ( ?, ?, ?
-			     ?, ?, ?, ?, ?,
-			     ?, ?, ?, ?, 
-			     ?, ?, ?, ?, ?, ?, ?, 
-			     ?, ?, ?, ?, ?, ?, 
-			     ?, ?, ?, 
-			     ?, ?, ?, ?, ?, 
-			     ?, ?, ?, 
-			     ?, ?, 
-			     ) 
-		       };
-	}
-#	my $sth = $db_handle->prepare( $sql );
-#DEBUGGING	
-	my $sth;
-
-	#for( @records ) {
-  eval {
-
-    $sth->bind_param( 1,  $display_filename,                SQL_VARCHAR );
-    $sth->bind_param( 2,  $result_params[$params_NAME],     SQL_VARCHAR );
-    $sth->bind_param( 3,  $result_params[$params_RAJ],      SQL_VARCHAR );
-    $sth->bind_param( 4,  $result_params[$params_DECJ],     SQL_VARCHAR );
-    $sth->bind_param( 5,  $data_type,                       SQL_VARCHAR );
-    $sth->bind_param( 6,  $result_params[$params_FREQ],     SQL_NUMERIC );
-    $sth->bind_param( 7,  $result_params[$params_BW],       SQL_NUMERIC );
-    $sth->bind_param( 8,  $result_params[$params_LENGTH],   SQL_NUMERIC );
-    $sth->bind_param( 9,  $result_params[$params_DATE],     SQL_NUMERIC );
-    $sth->bind_param( 10, $result_params[$params_TIME],     SQL_NUMERIC );
-    $sth->bind_param( 11, $MJD,                             SQL_NUMERIC );
-    $sth->bind_param( 12, $rajd,                            SQL_NUMERIC );
-    $sth->bind_param( 13, $decjd,                           SQL_NUMERIC );
-    $sth->bind_param( 14, $gl,                              SQL_NUMERIC );
-    $sth->bind_param( 15, $gb,                              SQL_NUMERIC );
-    $sth->bind_param( 16, $bmaj,                            SQL_NUMERIC );
-    $sth->bind_param( 17, $bmin,                            SQL_NUMERIC );
-    $sth->bind_param( 18, $bpa,                             SQL_NUMERIC );
-    $sth->bind_param( 19, $result_params[$params_DM],       SQL_NUMERIC );
-    $sth->bind_param( 20, $result_params[$params_PERIOD],   SQL_NUMERIC );    
-    $sth->bind_param( 21, $result_params[$params_NCHAN],    SQL_INTEGER );
-    $sth->bind_param( 22, $result_params[$params_NPOL],     SQL_INTEGER );
-    $sth->bind_param( 23, $result_params[$params_NBIN],     SQL_INTEGER );    
-    $sth->bind_param( 24, $result_params[$params_NSUB],     SQL_INTEGER );
-    $sth->bind_param( 25, $result_params[$params_NBITS],    SQL_INTEGER );
-    $sth->bind_param( 26, $result_params[$params_TSAMP],    SQL_INTEGER );
-    $sth->bind_param( 27, $nbeam,                           SQL_INTEGER );
-    $sth->bind_param( 28, $result_params[$params_CNFG],     SQL_VARCHAR );
-    $sth->bind_param( 29, $result_params[$params_INST],     SQL_VARCHAR );
-    $sth->bind_param( 30, $result_params[$params_RCVR],     SQL_VARCHAR );
-    $sth->bind_param( 31, $hdrver,                          SQL_VARCHAR );
-    $sth->bind_param( 32, $survey,                          SQL_VARCHAR );
-    $sth->bind_param( 33, $result_params[$params_TELESCOP], SQL_VARCHAR );
-    $sth->bind_param( 34, $result_params[$params_SITE],     SQL_INTEGER );
-    $sth->bind_param( 35, $result_params[$params_OBSRVR],   SQL_VARCHAR );
-    $sth->bind_param( 13, $display_data_loc,                SQL_VARCHAR );
-    $sth->bind_param( 34, $file_size,                       SQL_INTEGER );
-
-#    $sth->execute();
-#DEBUGGING
-    DBI::dump_results($sth);
-
-    # $db_handle->commit(); # Autocommit is already ON so no need for a manual commit
-  };
+#	my $sql;
+#	
+#	if ($data_loc =~ /\_R/) {
+#	    print "Inserting cal file $display_filename\n";
+#		
+#	    $sql = qq{ INSERT INTO cals 
+#			   (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
+#			    ) 
+#			   
+#			   VALUES 
+#			   ( ?, ?, ?
+#			     ?, ?, ?, ?, ?,
+#			     ?, ?, ?, ?, 
+#			     ?, ?, ?, ?, ?, ?, ?, 
+#			     ?, ?, ?, ?, ?, ?, 
+#			     ?, ?, ?, 
+#			     ?, ?, ?, ?, ?, 
+#			     ?, ?, ?, 
+#			     ?, ?, 
+#			     ) 
+#		       };
+#	}
+#	else {
+#	    
+#	    print "Inserting obs file $display_filename\n";
+#	    
+#	    $sql = qq{ INSERT INTO observations 
+#			   (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
+#			    ) 
+#			   
+#			   VALUES 
+#			   ( ?, ?, ?
+#			     ?, ?, ?, ?, ?,
+#			     ?, ?, ?, ?, 
+#			     ?, ?, ?, ?, ?, ?, ?, 
+#			     ?, ?, ?, ?, ?, ?, 
+#			     ?, ?, ?, 
+#			     ?, ?, ?, ?, ?, 
+#			     ?, ?, ?, 
+#			     ?, ?, 
+#			     ) 
+#		       };
+#	}
+##	my $sth = $db_handle->prepare( $sql );
+##DEBUGGING	
+#	my $sth;
+#
+#	#for( @records ) {
+#  eval {
+#
+#    $sth->bind_param( 1,  $display_filename,                SQL_VARCHAR );
+#    $sth->bind_param( 2,  $result_params[$params_NAME],     SQL_VARCHAR );
+#    $sth->bind_param( 3,  $result_params[$params_RAJ],      SQL_VARCHAR );
+#    $sth->bind_param( 4,  $result_params[$params_DECJ],     SQL_VARCHAR );
+#    $sth->bind_param( 5,  $data_type,                       SQL_VARCHAR );
+#    $sth->bind_param( 6,  $result_params[$params_FREQ],     SQL_NUMERIC );
+#    $sth->bind_param( 7,  $result_params[$params_BW],       SQL_NUMERIC );
+#    $sth->bind_param( 8,  $result_params[$params_LENGTH],   SQL_NUMERIC );
+#    $sth->bind_param( 9,  $result_params[$params_DATE],     SQL_NUMERIC );
+#    $sth->bind_param( 10, $result_params[$params_TIME],     SQL_NUMERIC );
+#    $sth->bind_param( 11, $MJD,                             SQL_NUMERIC );
+#    $sth->bind_param( 12, $rajd,                            SQL_NUMERIC );
+#    $sth->bind_param( 13, $decjd,                           SQL_NUMERIC );
+#    $sth->bind_param( 14, $gl,                              SQL_NUMERIC );
+#    $sth->bind_param( 15, $gb,                              SQL_NUMERIC );
+#    $sth->bind_param( 16, $bmaj,                            SQL_NUMERIC );
+#    $sth->bind_param( 17, $bmin,                            SQL_NUMERIC );
+#    $sth->bind_param( 18, $bpa,                             SQL_NUMERIC );
+#    $sth->bind_param( 19, $result_params[$params_DM],       SQL_NUMERIC );
+#    $sth->bind_param( 20, $result_params[$params_PERIOD],   SQL_NUMERIC );    
+#    $sth->bind_param( 21, $result_params[$params_NCHAN],    SQL_INTEGER );
+#    $sth->bind_param( 22, $result_params[$params_NPOL],     SQL_INTEGER );
+#    $sth->bind_param( 23, $result_params[$params_NBIN],     SQL_INTEGER );    
+#    $sth->bind_param( 24, $result_params[$params_NSUB],     SQL_INTEGER );
+#    $sth->bind_param( 25, $result_params[$params_NBITS],    SQL_INTEGER );
+#    $sth->bind_param( 26, $result_params[$params_TSAMP],    SQL_INTEGER );
+#    $sth->bind_param( 27, $nbeam,                           SQL_INTEGER );
+#    $sth->bind_param( 28, $result_params[$params_CNFG],     SQL_VARCHAR );
+#    $sth->bind_param( 29, $result_params[$params_INST],     SQL_VARCHAR );
+#    $sth->bind_param( 30, $result_params[$params_RCVR],     SQL_VARCHAR );
+#    $sth->bind_param( 31, $hdrver,                          SQL_VARCHAR );
+#    $sth->bind_param( 32, $survey,                          SQL_VARCHAR );
+#    $sth->bind_param( 33, $result_params[$params_TELESCOP], SQL_VARCHAR );
+#    $sth->bind_param( 34, $result_params[$params_SITE],     SQL_INTEGER );
+#    $sth->bind_param( 35, $result_params[$params_OBSRVR],   SQL_VARCHAR );
+#    $sth->bind_param( 13, $display_data_loc,                SQL_VARCHAR );
+#    $sth->bind_param( 34, $file_size,                       SQL_INTEGER );
+#
+##    $sth->execute();
+##DEBUGGING
+#    DBI::dump_results($sth);
+#
+#    # $db_handle->commit(); # Autocommit is already ON so no need for a manual commit
+#  };
 
   if( $@ ) {
@@ -721,136 +729,136 @@
 #DEBUGGING
 #	$sth->finish();
-}
+    }
 
 # Removes 
-sub deleteStaleRecords {
-
-	my $sql, my $sth, my @data, my $file;
-	
-	$sql = qq{ SELECT data_loc, filename from cals };
-	$sth = $db_handle->prepare( $sql );
-
-  eval {
-
-    $sth->execute();
-
-	};
-	
-  if( $@ ) {
-    warn "Database error: $DBI::errstr\n";
-    $db_handle->rollback(); #just die if rollback is failing
-  }
-
-	my @cals2delete;
-	
-	while (@data = $sth->fetchrow_array()) {
-		
-		if (scalar(@data) == 2) {
-			$file = $data[0]."/".$data[1];
-			
-			if (!-e $file) {
-				 print "$file does NOT exist\n\n";
-				
-				# Push the row into the cals to delete
-				# So array will look like:
-				# {/full/path/to/dir, filename.cf, /full/path/to/dir, filename2.cf, etc..}
-				push (@cals2delete, @data);
-			}
-		}
-		        
-  }
-
-	$sql = qq{ SELECT data_loc, filename from observations };
-	
-	$sth = $db_handle->prepare( $sql );
-  eval {
-
-    $sth->execute();
-
-	};
-	
-  if( $@ ) {
-    warn "Database error: $DBI::errstr\n";
-    $db_handle->rollback(); #just die if rollback is failing
-  }
-	
-	my @obs2delete;
-	
-	while (@data = $sth->fetchrow_array()) {
-  	
-		if (scalar(@data) == 2) {
-			$file = $data[0]."/".$data[1];
-			
-			if (!-e $file) {
-				print "$file does NOT exist\n\n";
-				
-				# Push the row into the cals to delete
-				# So array will look like:
-				# {/full/path/to/dir, filename.cf, /full/path/to/dir, filename2.cf, etc..}
-				push (@obs2delete, @data);
-			}
-		}	          
-  }
-
-	print "There are " . scalar(@cals2delete)/2 . " stale cals (" . 
-	      scalar(@cals2delete) . "/2) and " . 
-	      scalar(@obs2delete)/2 . " stale obs to delete\n";
-
-	# Delete the rows
-	my $data_loc, my $filename;
-	
-	while (@cals2delete) {
-		$data_loc = shift @cals2delete;
-		$filename = shift @cals2delete;
-		
-		$sql = qq{ DELETE FROM cals WHERE data_loc = ? AND filename = ?};
-
-		$sth = $db_handle->prepare( $sql );
-  	eval {
-
-    	$sth->bind_param( 1, $data_loc, SQL_VARCHAR );
-    	$sth->bind_param( 2, $filename, SQL_VARCHAR );
-    	$sth->execute();
-
-		};
-		
-		if( $@ ) {
-    	warn "Database error: $DBI::errstr\n";
-    	$db_handle->rollback(); #just die if rollback is failing
-  	}
-		else {
-			print "Successfully deleted $data_loc/$filename\n";
-		}
-
-	}
-	
-	while (@obs2delete) {
-		$data_loc = shift @obs2delete;
-		$filename = shift @obs2delete;
-		
-		$sql = qq{ DELETE FROM observations WHERE data_loc = ? AND filename = ?};
-
-		$sth = $db_handle->prepare( $sql );
-		
-  	eval {
-
-    	$sth->bind_param( 1, $data_loc, SQL_VARCHAR );
-    	$sth->bind_param( 2, $filename, SQL_VARCHAR );
-    	$sth->execute();
-
-		};
-		
-		if( $@ ) {
-    	warn "Database error: $DBI::errstr\n";
-    	$db_handle->rollback(); #just die if rollback is failing
-  	}
-		else {
-			print "Successfully deleted $data_loc/$filename\n";
-		}
-	}
-
-	$sth->finish();
-	
-}
+##sub deleteStaleRecords {
+##
+##	my $sql, my $sth, my @data, my $file;
+##	
+##	$sql = qq{ SELECT data_loc, filename from cals };
+##	$sth = $db_handle->prepare( $sql );
+##
+##  eval {
+##
+##    $sth->execute();
+##
+##	};
+##	
+##  if( $@ ) {
+##    warn "Database error: $DBI::errstr\n";
+##    $db_handle->rollback(); #just die if rollback is failing
+##  }
+##
+##	my @cals2delete;
+##	
+##	while (@data = $sth->fetchrow_array()) {
+##		
+##		if (scalar(@data) == 2) {
+##			$file = $data[0]."/".$data[1];
+##			
+##			if (!-e $file) {
+##				 print "$file does NOT exist\n\n";
+##				
+##				# Push the row into the cals to delete
+##				# So array will look like:
+##				# {/full/path/to/dir, filename.cf, /full/path/to/dir, filename2.cf, etc..}
+##				push (@cals2delete, @data);
+##			}
+##		}
+##		        
+##  }
+##
+##	$sql = qq{ SELECT data_loc, filename from observations };
+##	
+##	$sth = $db_handle->prepare( $sql );
+##  eval {
+##
+##    $sth->execute();
+##
+##	};
+##	
+##  if( $@ ) {
+##    warn "Database error: $DBI::errstr\n";
+##    $db_handle->rollback(); #just die if rollback is failing
+##  }
+##	
+##	my @obs2delete;
+##	
+##	while (@data = $sth->fetchrow_array()) {
+##  	
+##		if (scalar(@data) == 2) {
+##			$file = $data[0]."/".$data[1];
+##			
+##			if (!-e $file) {
+##				print "$file does NOT exist\n\n";
+##				
+##				# Push the row into the cals to delete
+##				# So array will look like:
+##				# {/full/path/to/dir, filename.cf, /full/path/to/dir, filename2.cf, etc..}
+##				push (@obs2delete, @data);
+##			}
+##		}	          
+##  }
+##
+##	print "There are " . scalar(@cals2delete)/2 . " stale cals (" . 
+##	      scalar(@cals2delete) . "/2) and " . 
+##	      scalar(@obs2delete)/2 . " stale obs to delete\n";
+##
+##	# Delete the rows
+##	my $data_loc, my $filename;
+##	
+##	while (@cals2delete) {
+##		$data_loc = shift @cals2delete;
+##		$filename = shift @cals2delete;
+##		
+##		$sql = qq{ DELETE FROM cals WHERE data_loc = ? AND filename = ?};
+##
+##		$sth = $db_handle->prepare( $sql );
+##  	eval {
+##
+##    	$sth->bind_param( 1, $data_loc, SQL_VARCHAR );
+##    	$sth->bind_param( 2, $filename, SQL_VARCHAR );
+##    	$sth->execute();
+##
+##		};
+##		
+##		if( $@ ) {
+##    	warn "Database error: $DBI::errstr\n";
+##    	$db_handle->rollback(); #just die if rollback is failing
+##  	}
+##		else {
+##			print "Successfully deleted $data_loc/$filename\n";
+##		}
+##
+##	}
+##	
+##	while (@obs2delete) {
+##		$data_loc = shift @obs2delete;
+##		$filename = shift @obs2delete;
+##		
+##		$sql = qq{ DELETE FROM observations WHERE data_loc = ? AND filename = ?};
+##
+##		$sth = $db_handle->prepare( $sql );
+##		
+##  	eval {
+##
+##    	$sth->bind_param( 1, $data_loc, SQL_VARCHAR );
+##    	$sth->bind_param( 2, $filename, SQL_VARCHAR );
+##    	$sth->execute();
+##
+##		};
+##		
+##		if( $@ ) {
+##    	warn "Database error: $DBI::errstr\n";
+##    	$db_handle->rollback(); #just die if rollback is failing
+##  	}
+##		else {
+##			print "Successfully deleted $data_loc/$filename\n";
+##		}
+##	}
+##
+##	$sth->finish();
+##	
+##}
 
 sub connectdb {
