Index: /trunk/tools/eam/rawfix.20230221/src/check_chip_locations.pl
===================================================================
--- /trunk/tools/eam/rawfix.20230221/src/check_chip_locations.pl	(revision 42449)
+++ /trunk/tools/eam/rawfix.20230221/src/check_chip_locations.pl	(revision 42450)
@@ -46,4 +46,7 @@
 my $Ncul2 = 0;
 my $Ncul3 = 0;
+my $Nfail = 0;
+
+my ($goodchips_r, $failchips_r) = &get_good_or_fail_chiplists ($topdir, $dateword, $stage);
 
 foreach my $chip_id (@chip_ids) {
@@ -52,11 +55,8 @@
     open ($outfh, ">$topdir/$dateword/$chip_id.uris.$stage.txt");
 
+    print "open $topdir/$dateword/$chip_id.uris.$stage.txt\n";
+
     # get the list of chip neb paths for one chip
     my ($neb_paths_r, $ds_array_r, $md_array_r) = &get_chip_paths ($fulldate, $chip_id);
-
-    # I think this makes a copy of the arrays, which is inefficient
-    # my @neb_paths = @$neb_paths_r;
-    # my @ds_array  = @$ds_array_r;
-    # my @md_array  = @$md_array_r;
 
     # reset the hostcount for this chip
@@ -115,6 +115,7 @@
 print "Ncul2: $Ncul2\n";
 print "Ncul3: $Ncul3\n";
-
-my $Ntotal = $Ngood + $Ngone + $Ndead + $Nsing + $Ndups + $Nsbck + $Nxbck + $Ncul1 + $Ncul2 + $Ncul3;
+print "Nfail: $Nfail\n";
+
+my $Ntotal = $Ngood + $Ngone + $Ndead + $Nsing + $Ndups + $Nsbck + $Nxbck + $Ncul1 + $Ncul2 + $Ncul3 + $Nfail;
 if ($Ntotal != $Nchip) { die "ERROR: inconsistent count of chips\n"; } 
 
@@ -132,4 +133,5 @@
 $sql_update_stats .= ", Ncul2 = $Ncul2";
 $sql_update_stats .= ", Ncul3 = $Ncul3";
+$sql_update_stats .= ", Nfail = $Nfail";
 $sql_update_stats .= " WHERE dateobs = $dateword";
 
@@ -293,8 +295,17 @@
     $Nchip ++;
 
+    my $haveMD5 = 0;
+    my $goodMD5 = 0;
+    if ($goodchips_r->{$extID}) { $haveMD5 = 1; $goodMD5 = 1; }
+    if ($failchips_r->{$extID}) { $haveMD5 = 1; $goodMD5 = 0; }
+
+    if ($extID eq "gpc1/20100503/o5319g0003d/o5319g0003d.ota46.fits") {
+	print STDERR "$outinfo $Nmain $Nback $haveMD5 $goodMD5\n";
+    }
+
     # GOOD : already fixed 
     if (($Nmain == 1) && ($Nback == 1)) {
 	print $outfh "GOOD: $outinfo\n";
-	$Ngood ++;
+	&update_counts (\$Ngood, \$Nfail, $haveMD5, $goodMD5);
 	return;
     }
@@ -304,5 +315,5 @@
     if (($Nmain == 1) && ($Nback == 0)) {
 	print $outfh "SING: $outinfo\n";
-	$Nsing ++;
+	&update_counts (\$Nsing, \$Nfail, $haveMD5, $goodMD5);
 	return;
     }
@@ -312,5 +323,5 @@
     if (($Nmain == 0) && ($Nback == 1)) {
 	print $outfh "SBCK: $outinfo\n";
-	$Nsbck ++;
+	&update_counts (\$Nsbck, \$Nfail, $haveMD5, $goodMD5);
 	return;
     }
@@ -320,5 +331,5 @@
     if (($Nmain > 1) && ($Nback == 0)) {
 	print $outfh "DUPS: $outinfo\n";
-	$Ndups ++;
+	&update_counts (\$Ndups, \$Nfail, $haveMD5, $goodMD5);
 	return;
     }
@@ -328,5 +339,5 @@
     if (($Nmain == 0) &&  ($Nback > 1)) {
 	print $outfh "XBCK: $outinfo\n";
-	$Nxbck ++;
+	&update_counts (\$Nxbck, \$Nfail, $haveMD5, $goodMD5);
 	return;
     }
@@ -335,5 +346,5 @@
     if (($Nmain == 0) && ($Nback == 0) && $Nlost) {
 	print $outfh "DEAD: $outinfo\n";
-	$Ndead ++;
+	&update_counts (\$Ndead, \$Nfail, $haveMD5, $goodMD5);
 	return;
     }
@@ -341,5 +352,5 @@
     if (($Nmain == 0) && ($Nback == 0) && ($Nlost == 0)) {
 	print $outfh "GONE: $outinfo\n";
-	$Ngone ++;
+	&update_counts (\$Ngone, \$Nfail, $haveMD5, $goodMD5);
 	return;
     }
@@ -349,5 +360,5 @@
     if (($Nmain > 1) && ($Nback == 1)) {
 	print $outfh "CUL1: $outinfo\n";
-	$Ncul1 ++;
+	&update_counts (\$Ncul1, \$Nfail, $haveMD5, $goodMD5);
 	return;
     }
@@ -357,5 +368,5 @@
     if (($Nback > 1) && ($Nmain == 1)) {
 	print $outfh "CUL2: $outinfo\n";
-	$Ncul2 ++;
+	&update_counts (\$Ncul2, \$Nfail, $haveMD5, $goodMD5);
 	return;
     }
@@ -365,5 +376,5 @@
     if (($Nback > 1) && ($Nmain > 1)) {
 	print $outfh "CUL3: $outinfo\n";
-	$Ncul3 ++;
+	&update_counts (\$Ncul3, \$Nfail, $haveMD5, $goodMD5);
 	return;
     }
@@ -372,4 +383,54 @@
     print $outfh "OOPS: $outinfo\n";
     return;
+}
+
+sub update_counts {
+
+    my $Nstat_r = $_[0];
+    my $Nfail_r = $_[1];
+    my $haveMD5 = $_[2];
+    my $goodMD5 = $_[3];
+
+    ## if we know the MD5 is bad, add to Nfail, otherwise add to Ndups
+    if ($haveMD5 && !$goodMD5) {
+	$$Nfail_r ++; 
+    } else { 
+	$$Nstat_r ++;
+    }
+}
+
+sub get_good_or_fail_chiplists {
+
+    my $topdir   = $_[0];
+    my $dateword = $_[1];
+    my $stage    = $_[2];
+
+    # load the lists of good and fail chips
+    my $prev = $stage - 1;
+    my $goodfile = "$topdir/$dateword/goodchips.$prev.txt";
+    my %goodchips;
+    if (-e $goodfile) {
+	open (GOODFILE,  $goodfile);
+	my @lines = <GOODFILE>;
+	close (GOODFILE);
+	
+	foreach my $line (@lines) {
+	    chomp $line;
+	    $goodchips{$line} = 1;
+	}
+    }
+    my $failfile = "$topdir/$dateword/failchips.$prev.txt";
+    my %failchips;
+    if (-e $failfile) {
+	open (FAILFILE,  $failfile);
+	my @lines = <FAILFILE>;
+	close (FAILFILE);
+	
+	foreach my $line (@lines) {
+	    chomp $line;
+	    $failchips{$line} = 1;
+	}
+    }
+    return (\%goodchips, \%failchips);
 }
 
Index: /trunk/tools/eam/rawfix.20230221/src/fix_chip_locations.pl
===================================================================
--- /trunk/tools/eam/rawfix.20230221/src/fix_chip_locations.pl	(revision 42449)
+++ /trunk/tools/eam/rawfix.20230221/src/fix_chip_locations.pl	(revision 42450)
@@ -24,4 +24,6 @@
 my @vol_copy = &get_neb_volumes_copy; # array of neb hosts to copy data to at ITC
 my %vol_good = &get_neb_volumes_good; # hash of valid neb hosts
+
+my $Nchip = 0; # counts the number of instances
 
 my $Ngood = 0;
@@ -38,32 +40,5 @@
 my $Nfail = 0;
 
-my $Nchip = 0; # counts the number of instances
-
-# load the lists of good and fail chips
-my $prev = $stage - 1;
-my $goodfile = "$topdir/$dateword/goodchips.$prev.txt";
-my %goodchips;
-if (-e $goodfile) {
-    open (GOODFILE,  $goodfile);
-    my @lines = <GOODFILE>;
-    close (GOODFILE);
-    
-    foreach my $line (@lines) {
-	chomp $line;
-	$goodchips{$line} = 1;
-    }
-}
-my $failfile = "$topdir/$dateword/failchips.$prev.txt";
-my %failchips;
-if (-e $failfile) {
-    open (FAILFILE,  $failfile);
-    my @lines = <FAILFILE>;
-    close (FAILFILE);
-    
-    foreach my $line (@lines) {
-	chomp $line;
-	$failchips{$line} = 1;
-    }
-}
+my ($goodchips_r, $failchips_r) = &get_good_or_fail_chiplists ($topdir, $dateword, $stage);
 
 # read the list of chip_ids:
@@ -153,6 +128,6 @@
 	my $haveMD5 = 0;
 	my $goodMD5 = 0;
-	if ($goodchips{$ext_id}) { $haveMD5 = 1; $goodMD5 = 1; }
-	if ($failchips{$ext_id}) { $haveMD5 = 1; }
+	if ($goodchips_r->{$ext_id}) { $haveMD5 = 1; $goodMD5 = 1; }
+	if ($failchips_r->{$ext_id}) { $haveMD5 = 1; $goodMD5 = 0; }
 
 	$Nchip ++;
@@ -350,4 +325,39 @@
 }
 
+sub get_good_or_fail_chiplists {
+
+    my $topdir   = $_[0];
+    my $dateword = $_[1];
+    my $stage    = $_[2];
+
+    # load the lists of good and fail chips
+    my $prev = $stage - 1;
+    my $goodfile = "$topdir/$dateword/goodchips.$prev.txt";
+    my %goodchips;
+    if (-e $goodfile) {
+	open (GOODFILE,  $goodfile);
+	my @lines = <GOODFILE>;
+	close (GOODFILE);
+	
+	foreach my $line (@lines) {
+	    chomp $line;
+	    $goodchips{$line} = 1;
+	}
+    }
+    my $failfile = "$topdir/$dateword/failchips.$prev.txt";
+    my %failchips;
+    if (-e $failfile) {
+	open (FAILFILE,  $failfile);
+	my @lines = <FAILFILE>;
+	close (FAILFILE);
+	
+	foreach my $line (@lines) {
+	    chomp $line;
+	    $failchips{$line} = 1;
+	}
+    }
+    return (\%goodchips, \%failchips);
+}
+
 # get the list of neb hosts to copy data to at ITC
 sub get_neb_volumes_copy {
Index: /trunk/tools/eam/rawfix.20230221/src/queue.rawfix.sh
===================================================================
--- /trunk/tools/eam/rawfix.20230221/src/queue.rawfix.sh	(revision 42449)
+++ /trunk/tools/eam/rawfix.20230221/src/queue.rawfix.sh	(revision 42450)
@@ -31,4 +31,22 @@
   set mynight = $2
   
+  set year = `echo $mynight | awk '{print substr($0, 1, 4)}'`
+  if (($year < 2005) || ($year > 2030)) then
+    echo "invalid date $mynight"
+    exit 2
+  endif
+
+  set month = `echo $mynight | awk '{print 1*substr($0, 5, 2)}'`
+  if (($month < 1) || ($month > 12)) then
+    echo "invalid date $mynight"
+    exit 2
+  endif
+
+  set day = `echo $mynight | awk '{print 1*substr($0, 7, 2)}'`
+  if (($day < 1) || ($day > 31)) then
+    echo "invalid date $mynight"
+    exit 2
+  endif
+
   mysql -h $DBHOST -u $DBUSER -p$DBPASS $DBNAME -e "insert into nights (dateobs, state) values ('$mynight', 'new')"
   exit 0
Index: /trunk/tools/eam/rawfix.20230221/src/rawfix.advance.pt
===================================================================
--- /trunk/tools/eam/rawfix.20230221/src/rawfix.advance.pt	(revision 42449)
+++ /trunk/tools/eam/rawfix.20230221/src/rawfix.advance.pt	(revision 42450)
@@ -1,4 +1,4 @@
 
-$MAX_ACTIVE_NIGHTS = 2
+$MAX_ACTIVE_NIGHTS = 5
 
 ## regularly run the command advance.rawfits.sh
