Index: /trunk/tools/bills/adddeltacolumns
===================================================================
--- /trunk/tools/bills/adddeltacolumns	(revision 39114)
+++ /trunk/tools/bills/adddeltacolumns	(revision 39115)
@@ -46,4 +46,5 @@
 # foreach my $line (<C>) {
 my @deltas;
+my @columns;
 foreach my $line (@lines) {
     next if $line =~ '^#';
@@ -61,4 +62,5 @@
     $cmd .=  "addcol -after $p2 $dcol $equation;";
     push @deltas, $dcol;
+    push @columns, $p2;
 }
 $cmd .= "'";
@@ -80,12 +82,15 @@
 output /dev/null
 macro checkdelta
-    \$col = \$1
+    \$dcol = \$1
+    \$col = \$2
     \$thislimit = \$limit
-    \$length = \$col[]
+    set goodmask = \$col != -999
+    subset good = \$dcol where goodmask == 1
+    \$length = good[]
     for i 0 10
-        subset d = \$col where abs(\$col) > \$thislimit
+        subset d = good where abs(good) > \$thislimit
         \$noutliers = d[]
         if (\$noutliers > 0) 
-            echo \$col has \$noutliers out of \$length with difference > \$thislimit
+            echo \$dcol has \$noutliers out of \$length with difference > \$thislimit
             \$thislimit = \$thislimit * 10
         else
@@ -97,6 +102,9 @@
 
     print $manafile "\nmacro dotests\n";
-    foreach my $col (@deltas) {
-        print $manafile "    checkdelta $col\n";
+    my $n = scalar @deltas;
+    for (my $i=0; $i < $n; $i++) {
+        my $col = $columns[$i];
+        my $dcol = $deltas[$i];
+        print $manafile "    checkdelta $dcol $col\n";
     }
     print $manafile "end\n";
@@ -105,4 +113,9 @@
     print $manafile "read -fits Joined";
     foreach my $col (@deltas) {
+        print $manafile " $col";
+    }
+    print $manafile "\n";
+    print $manafile "read -fits Joined";
+    foreach my $col (@columns) {
         print $manafile " $col";
     }
