Index: trunk/htdocs/perl/find_archives.pl
===================================================================
--- trunk/htdocs/perl/find_archives.pl	(revision 205)
+++ trunk/htdocs/perl/find_archives.pl	(revision 206)
@@ -32,5 +32,5 @@
     $output $vap $archive_extensions $ext	
     $default
-    @result_params $FILE_SIZE_INDEX $FB $DFB $WBC $CPSR2
+    @result_params $FILE_SIZE_INDEX $FB $DFB $WBC $CPSR2 $NULLFIELD
     $params_NAME    
     $params_PROJID  
@@ -58,4 +58,5 @@
     $params_INST    
     $params_RCVR    
+    $params_HDRVER
     $params_TELESCOP
     $params_SITE    
@@ -73,8 +74,11 @@
 $CPSR2 = "CPSR2";
 
+# How to write NULL fields to the database
+$NULLFIELD = "NULL";
+
 # Pulsar parameters (listed in "vap -H")
 #$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 mjd bmaj bmin bpa dm period nchan npol nbin nsub nbits tsamp nbeam beconfig backend rcvr telescop asite observer";
+$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 hdrver telescop asite observer";
 
 # vap result parameter indices. Used to locate the resulting 
@@ -105,10 +109,12 @@
 $params_INST    = 23;
 $params_RCVR    = 24;
-$params_TELESCOP= 25;
-$params_SITE    = 26;
-$params_OBSRVR  = 27;
+$params_HDRVER  = 25;
+$params_TELESCOP= 26;
+$params_SITE    = 27;
+$params_OBSRVR  = 28;
 
 # filename extensions
-$archive_extensions = "ar rf cf cfb fb";
+#$archive_extensions = "ar rf cf cfb fb";
+$archive_extensions = "rf cf cfb fb";
 
 # The machine to do all the processing on
@@ -451,37 +457,68 @@
 	}
 
+
 	# Try to find the data type
-	if ($filename =~ /\.ar$/) {
-		$data_type = $FB;
-	}
-	elsif ($filename =~ /\.rf/ || $filename =~ /\.cf/ || $filename =~ /fb/) {
-		if ($filename =~ /^a/) { # DFB file
-			$data_type = $DFB;
-		}
-		
-		elsif ($filename =~ /^w/) { # Wide Band Correlator file
-			$data_type = $WBC;
-		}
-		elsif ($filename =~ /^m/ || $filename =~ /^n/ || $filename =~ /^r/) {
-			$data_type = $CPSR2;
+#	my $file_is_good = true;
+
+	if ($filename =~ /^a.*\.rf/ || $filename =~ /^a.*\.cf/ || 
+	    $filename =~ /^r.*\.rf/ || $filename =~ /^r.*\.cf/) {
+	    $data_type = $DFB;
+	}
+	elsif ($filename =~ /^w.*\.rf/ || $filename =~ /^w.*\.cf/) {
+	    $data_type = $WBC;
+	}
+	elsif ($filename =~ /^m.*\.cfb/ || $filename =~ /^m.*\.fb/ ||
+	       $filename =~ /^n.*\.cfb/ || $filename =~ /^n.*\.fb/ ||
+	       $filename =~ /^o.*\.cfb/ || $filename =~ /^o.*\.fb/ ) {
+	    $data_type = $CPSR2;
+
+	    # Use the directory of observation instead of filename instance
+	    my @dirs = split(/\//, $data_loc);
+	    print "The new filename will be " . $dirs[$#dirs] . " from $data_loc\n";
+	    $display_filename = $dirs[$#dirs];
+#			# For some reason, the name of the pulsar cals for CPSR2 files are all "CAL"
+#			if ($data_loc =~ /\_R/) {
+#				my @jname_parts = split(/J/i, $dirs[$#dirs-1]);
+#				$result_params[$params_NAME] = $jname_parts[1];
+#			}
 			
-			# Use the directory of observation instead of filename instance
-			my @dirs = split(/\//, $data_loc);
-			
-			print "The new filename will be " . $dirs[$#dirs] . " from $data_loc\n";
-			
-			$display_filename = $dirs[$#dirs];
-			
-			# For some reason, the name of the pulsar cals for CPSR2 files are all "CAL"
-			if ($data_loc =~ /\_R/) {
-				my @jname_parts = split(/J/i, $dirs[$#dirs-1]);
-				$result_params[$params_NAME] = $jname_parts[1];
-			}
-
-		}
-		else {
-			$data_type = undef;
-		}
-	}
+	}
+	else {
+	    $data_type = $NULLFIELD;
+	}
+
+#	# Try to find the data type
+#	if ($filename =~ /\.ar$/) {
+#		$data_type = $FB;
+#	}
+#	elsif ($filename =~ /\.rf/ || $filename =~ /\.cf/ || $filename =~ /fb/) {
+#		if ($filename =~ /^a/) { # DFB file
+#			$data_type = $DFB;
+#		}
+#		
+#		elsif ($filename =~ /^w/) { # Wide Band Correlator file
+#			$data_type = $WBC;
+#		}
+#		elsif ($filename =~ /^m/ || $filename =~ /^n/ || $filename =~ /^r/) {
+#			$data_type = $CPSR2;
+#			
+#			# Use the directory of observation instead of filename instance
+#			my @dirs = split(/\//, $data_loc);
+#			
+#			print "The new filename will be " . $dirs[$#dirs] . " from $data_loc\n";
+#			
+#			$display_filename = $dirs[$#dirs];
+#			
+#			# For some reason, the name of the pulsar cals for CPSR2 files are all "CAL"
+#			if ($data_loc =~ /\_R/) {
+#				my @jname_parts = split(/J/i, $dirs[$#dirs-1]);
+#				$result_params[$params_NAME] = $jname_parts[1];
+#			}
+#
+#		}
+#		else {
+#			$data_type = undef;
+#		}
+#	}
 	print "display_filename = $display_filename\n";
 	
@@ -497,5 +534,5 @@
 #	}
 	if($result_params[$params_MJD] eq "INVALID"){
-	    $MJD = undef;
+	    $MJD = $NULLFIELD;
 	}
 	else{
@@ -562,13 +599,20 @@
 	}
 
+	if($result_params[$params_NBITS] == 0){
+	    $result_params[$params_NBITS] = $NULLFIELD;
+	}
+	if($result_params[$params_TSAMP] == 0){
+	    $result_params[$params_TSAMP] = $NULLFIELD;
+	}
+
+
 	# Dud things that aren't required for this set of data.
-	$hdrver = NULL;
-	$survey = NULL;
+	$survey = $NULLFIELD;
 	$nbeam = 1;
 	
 	my $i;	
 	for ($i = 0; $i <= $#result_params; $i++) {
-		if ($result_params[$i] eq "N/A") {
-			$result_params[$i] = undef;
+		if ($result_params[$i] eq "N/A" || $result_params[$i] eq "UNDEF" || $result_params[$i] eq "INVALID") {
+			$result_params[$i] = $NULLFIELD;
 		}
 	}
@@ -602,9 +646,10 @@
 	print "tsamp = " . $result_params[$params_TSAMP] . "\n";
 	print "nbits = " . $result_params[$params_NBITS] . "\n";
-	print "nbeam = " . $result_params[$params_NBEAM] . "\n";
+#	print "nbeam = " . $result_params[$params_NBEAM] . "\n";
+	print "nbeam = " . $nbeam . "\n";
 	print "cnfg = " . $result_params[$params_CNFG] . "\n";
 	print "inst = " . $result_params[$params_INST] . "\n";
 	print "rcvr = " . $result_params[$params_RCVR] . "\n";
-	print "hdrver = " . $hdrver . "\n";
+	print "hdrver = " . $result_params[$params_HDRVER] . "\n";
 	print "survey = " . $survey . "\n";
 	print "telescope = " . $result_params[$params_TELESCOP] . "\n";
@@ -616,5 +661,5 @@
 #	my $sql;
 #	
-#	if ($data_loc =~ /\_R/) {
+#	if ($data_loc =~ /\_R/ || $) {
 #	    print "Inserting cal file $display_filename\n";
 #		
