Index: /trunk/ippMonitor/INSTALL
===================================================================
--- /trunk/ippMonitor/INSTALL	(revision 26887)
+++ /trunk/ippMonitor/INSTALL	(revision 26888)
@@ -14,5 +14,6 @@
  psconfigure --dbhost ipp004 --dbuser ipp --dbpass ipp --htdocs ~ipp/htdocs
 
+# note that we have a special version for ippmonitor without $PSCONFIG/$PSCONFDIR values:
 ipp@ipp004 / ippdb01 example:
- psconfigure --dbhost ippdb01 --dbuser ipp --dbpass ipp --htdocs ~/htdocs --site ~/ippconfig/ipprc.config
+ psconfigure --dbhost ippdb01 --dbuser ipp --dbpass ipp --htdocs ~/htdocs --site ~/ippconfig/ippmonitor.config
 
Index: /trunk/ippMonitor/Makefile.in
===================================================================
--- /trunk/ippMonitor/Makefile.in	(revision 26887)
+++ /trunk/ippMonitor/Makefile.in	(revision 26888)
@@ -145,4 +145,5 @@
 $(DESTWWW)/magicProcessedNodes.php \
 $(DESTWWW)/magicProcessedMasks.php \
+$(DESTWWW)/magicProcessedMasks_Images.php \
 $(DESTWWW)/magicFailedTrees.php \
 $(DESTWWW)/magicFailedNodes.php \
Index: /trunk/ippMonitor/def/camProcessedImfile.d
===================================================================
--- /trunk/ippMonitor/def/camProcessedImfile.d	(revision 26887)
+++ /trunk/ippMonitor/def/camProcessedImfile.d	(revision 26888)
@@ -17,4 +17,6 @@
 OP   OP1  $rawExp.ra * 57.295783
 OP   OP2  $rawExp.decl * 57.295783
+
+HEAD PHP insert_image ('PPIMAGE.JPEG1', 'width=1000pix');
 
 #     field                     	size  format  name          show   	 link to                  extras
@@ -43,4 +45,3 @@
 FIELD rawExp.comment,  	                65,   %s,     Comment
 
-TAIL PHP insert_image ('PPIMAGE.JPEG1');
 TAIL PHP insert_log ('LOG.EXP');
Index: /trunk/ippMonitor/def/detNormalizedImfile_failure.d
===================================================================
--- /trunk/ippMonitor/def/detNormalizedImfile_failure.d	(revision 26887)
+++ /trunk/ippMonitor/def/detNormalizedImfile_failure.d	(revision 26888)
@@ -16,4 +16,4 @@
 #FIELD path_base,     20, %s,     path_base
 
-TAIL PHP insert_image ('PPIMAGE.JPEG1');
+TAIL PHP insert_image ('PPIMAGE.JPEG1', 'width=90%');
 TAIL PHP insert_log ('LOG.EXP');
Index: /trunk/ippMonitor/def/detProcessedImfile.d
===================================================================
--- /trunk/ippMonitor/def/detProcessedImfile.d	(revision 26887)
+++ /trunk/ippMonitor/def/detProcessedImfile.d	(revision 26888)
@@ -20,5 +20,5 @@
 TD_CLASS det_off $detProcessedImfile.fault > 0
 
-TAIL PHP insert_image ('PPIMAGE.JPEG1');
+TAIL PHP insert_image ('PPIMAGE.JPEG1', 'width=90%');
 TAIL PHP insert_log ('LOG.EXP');
 
Index: /trunk/ippMonitor/def/detResidImfile.d
===================================================================
--- /trunk/ippMonitor/def/detResidImfile.d	(revision 26887)
+++ /trunk/ippMonitor/def/detResidImfile.d	(revision 26888)
@@ -22,4 +22,4 @@
 FIELD detResidImfile.uri,           5, %s,      uri, none
 
-TAIL PHP insert_image ('PPIMAGE.JPEG1');
+TAIL PHP insert_image ('PPIMAGE.JPEG1', 'width=90%');
 TAIL PHP insert_log ('LOG.EXP');
Index: /trunk/ippMonitor/def/diffProcessedSkyfile_Images.d
===================================================================
--- /trunk/ippMonitor/def/diffProcessedSkyfile_Images.d	(revision 26887)
+++ /trunk/ippMonitor/def/diffProcessedSkyfile_Images.d	(revision 26888)
@@ -38,4 +38,4 @@
 FIELD diffSkyfile.path_base,           5, %s,     path_base,     none
 
-TAIL PHP insert_image ('PPSUB.OUTPUT.JPEG1');
+TAIL PHP insert_image ('PPSUB.OUTPUT.JPEG1', 'width=90%');
 TAIL PHP insert_log ('LOG.EXP');
Index: /trunk/ippMonitor/def/magicProcessedMasks_Images.d
===================================================================
--- /trunk/ippMonitor/def/magicProcessedMasks_Images.d	(revision 26888)
+++ /trunk/ippMonitor/def/magicProcessedMasks_Images.d	(revision 26888)
@@ -0,0 +1,29 @@
+TABLE magicRun, magicMask
+TITLE Magic Processed Masks
+FILE  magicProcessedMasks_Images.php
+MENU  ipp.stack.dat
+
+WHERE magicRun.magic_id  = magicMask.magic_id
+
+IMAGE JPEG2 $magicRun.workdir_base PPSUB.OUTPUT.JPEG2 GPC1 NONE
+
+# XXX need to get camera from lookup
+ARGS  ARG7 magicRun.magic_id=$magicRun.magic_id
+ARGS  ARG7 camera=GPC1
+ARGS  ARG7 basename=$magicRun.workdir/$magicRun.exp_id/$magicRun.exp_id.mgc.$magicRun.magic_id.verify/$magicRun.exp_id
+
+#        field                   size  format  name           show     link to         extras
+FIELD    magicRun.magic_id,	 5,   %d,     Magic ID
+FIELD    magicRun.exp_id,	 5,   %d,     Exp ID
+FIELD    magicRun.diff_id,	 5,   %d,     Diff ID,		value, magicProcessedMasks_Images.php,  ARG7
+# FIELD    *,                      8,   %s,     image,         image=JPEG2, diffProcessedSkyfile_Images.php,  ARG7
+FIELD    magicRun.label, 	 5,   %s,     Label
+FIELD    magicRun.inverse,	 5,   %s,     Inverse
+FIELD    magicRun.state,	 5,   %s,     State
+FIELD    magicMask.streaks,	 5,   %d,     Fault
+FIELD    magicMask.fault,	 5,   %s,     Fault
+FIELD    magicRun.workdir, 	 5,   %s,     Label, none
+
+TAIL PHP insert_image ('MAGIC.ORIGINAL.PNG', 'width=500pix');
+TAIL PHP insert_image ('MAGIC.DUPLICATE.PNG', 'width=500pix');
+# TAIL PHP insert_log ('LOG.EXP');
Index: /trunk/ippMonitor/def/stackProcessedSkyfile_Images.d
===================================================================
--- /trunk/ippMonitor/def/stackProcessedSkyfile_Images.d	(revision 26887)
+++ /trunk/ippMonitor/def/stackProcessedSkyfile_Images.d	(revision 26888)
@@ -43,4 +43,4 @@
 FIELD stackSumSkyfile.path_base,    5, %s,     path_base,     none
 
-TAIL PHP insert_image ('PPSTACK.OUTPUT.JPEG1');
+TAIL PHP insert_image ('PPSTACK.OUTPUT.JPEG1', 'width=90%');
 TAIL PHP insert_log ('LOG.EXP');
Index: /trunk/ippMonitor/raw/getimage.php
===================================================================
--- /trunk/ippMonitor/raw/getimage.php	(revision 26887)
+++ /trunk/ippMonitor/raw/getimage.php	(revision 26888)
@@ -60,9 +60,15 @@
 if ($debug) {
   exec ("which ipp_filename.pl", $output, $status);
-  echo "output:   $output[0]<br>";
+  echo "which ipp_filename.pl output:<br>";
+  for ($i = 0; $i < count($output); $i++) {
+    echo "output $i: $output[$i]<br>";
+  }
   echo "status:   $status<br>";
 
   exec ("whoami", $output, $status);
-  echo "output:   $output[0]<br>";
+  echo "which whoami output:<br>";
+  for ($i = 0; $i < count($output); $i++) {
+    echo "output $i: $output[$i]<br>";
+  }
   echo "status:   $status<br>";
 }
Index: /trunk/ippMonitor/raw/ipp.php
===================================================================
--- /trunk/ippMonitor/raw/ipp.php	(revision 26887)
+++ /trunk/ippMonitor/raw/ipp.php	(revision 26888)
@@ -651,5 +651,5 @@
 // expect image supplied with key=name
 // this function should define matching hidden inputs in the form
-function insert_image ($rule) {
+function insert_image ($rule, $size) {
 
   if ($_SERVER[REQUEST_METHOD] == 'GET') { 
@@ -666,5 +666,5 @@
 
   if ($basename && $camera && $rule) {
-    echo "<img src=\"getimage.php?name=$basename&rule=$rule&camera=$camera&class_id=$class_id\">\n";
+    echo "<img $size src=\"getimage.php?name=$basename&rule=$rule&camera=$camera&class_id=$class_id\">\n";
   }
 }
Index: /trunk/ippMonitor/raw/ipp.stack.dat
===================================================================
--- /trunk/ippMonitor/raw/ipp.stack.dat	(revision 26887)
+++ /trunk/ippMonitor/raw/ipp.stack.dat	(revision 26888)
@@ -47,4 +47,5 @@
 menulink  | menuselect   | link    | Magic Processed Nodes        | magicProcessedNodes.php
 menulink  | menuselect   | link    | Magic Processed Masks        | magicProcessedMasks.php
+menulink  | menuselect   | link    | Magic Masks w/ Images        | magicProcessedMasks_Images.php
 menulink  | menuselect   | link    | Magic Failed Trees           | magicFailedTrees.php
 menulink  | menuselect   | link    | Magic Failed Nodes           | magicFailedNodes.php
Index: /trunk/ippMonitor/scripts/generate
===================================================================
--- /trunk/ippMonitor/scripts/generate	(revision 26887)
+++ /trunk/ippMonitor/scripts/generate	(revision 26888)
@@ -37,83 +37,83 @@
 
     foreach $line (@list) {
-	chop $line;
-	($key, $value) = split (" ", $line, 2);
-	
-	# strip leading and trailing white space from the following
-	if ($key eq "TABLE") { ($value) = $value =~ m|^\s*(.+)\s*$|; }
-	if ($key eq "TYPE")  { ($value) = $value =~ m|^\s*(.+)\s*$|; }
-
-	&set_keypair ($key, $value);
-
-	# list of the table fields
- 	if ($key eq "FIELD") {
-	    ($field, $width, $format, $name, $show, $link, $extras) = split (/,\s+/, $value, 7);
-	    if (! $name) { die "table $ARGV[0] missing required elements\n"; }
-	    if ($field =~ m|\S+\s+as\s+\S+|) {
-		($fieldreal) = $field =~ m|\S+\s+as\s+(\S+)|;
-	    } else {
-		$fieldreal = $field;
-	    }
-	    
-	    if ($VERBOSE) { printf "%-20s %-20s %-20s %-20s %-20s %-20s\n", $field, $name, $format, $show, $link, $extras; }
-
-	    if ($show eq "") {$show = "value";}
-	    push @field,     $field;
-	    push @fieldreal, $fieldreal;
-	    push @width,     $width;
-	    push @format,    $format;
-	    push @name,      $name;
-	    push @show,      $show;
-	    push @link,      $link;
-	    push @extras,    $extras;
-	}
-
-	if ($key eq "FILE") {
-	    $myFile = $value;
-	}
-
-	# list of the table fields
- 	if ($key eq "HEAD") {
-	    push @headcode, $value;
-	}
-
-	# the IMAGE commands sets up a reference name
-	if ($key eq "IMAGE") {
-	    push @imagedefs, $value;
-	}
-
-	# the GROUP entries are used in summary tables as arguments to the GROUP BY sql statement
-	if ($key eq "GROUP") {
-	    push @group, $value;
-	}
-
-	# the ARGS commands define arguments to FIELDS commands
-	if ($key eq "ARGS") {
-	    push @linkargs, $value;
-	}
-
-	# the OP commands define field operations
-	if ($key eq "OP") {
-	    push @opwords, $value;
-	}
-
-	# the TD_CLASS command sets up an alternate TD class
-	if ($key eq "TD_CLASS") {
-	    push @tdClasses, $value;
-	    # print STDERR "found TD_CLASS\n";
-	}
-
-	# list of the table fields
- 	if ($key eq "TAIL") {
-	    push @tailcode, $value;
-	}
-
-	# list of the table restrictions
-	# replace this with a flexible where statement?
- 	if ($key eq "WHERE") {
-	    ($field) = split (/,\s+/, $value, 1);
-	    if ($VERBOSE) { printf "%-20s\n", $field; }
-	    push @where,   $field;
-	}
+        chop $line;
+        ($key, $value) = split (" ", $line, 2);
+
+        # strip leading and trailing white space from the following
+        if ($key eq "TABLE") { ($value) = $value =~ m|^\s*(.+)\s*$|; }
+        if ($key eq "TYPE")  { ($value) = $value =~ m|^\s*(.+)\s*$|; }
+
+        &set_keypair ($key, $value);
+
+        # list of the table fields
+        if ($key eq "FIELD") {
+            ($field, $width, $format, $name, $show, $link, $extras) = split (/,\s+/, $value, 7);
+            if (! $name) { die "table $ARGV[0] missing required elements\n"; }
+            if ($field =~ m|\S+\s+as\s+\S+|) {
+                ($fieldreal) = $field =~ m|\S+\s+as\s+(\S+)|;
+            } else {
+                $fieldreal = $field;
+            }
+
+            if ($VERBOSE) { printf "%-20s %-20s %-20s %-20s %-20s %-20s\n", $field, $name, $format, $show, $link, $extras; }
+
+            if ($show eq "") {$show = "value";}
+            push @field,     $field;
+            push @fieldreal, $fieldreal;
+            push @width,     $width;
+            push @format,    $format;
+            push @name,      $name;
+            push @show,      $show;
+            push @link,      $link;
+            push @extras,    $extras;
+        }
+
+        if ($key eq "FILE") {
+            $myFile = $value;
+        }
+
+        # list of the table fields
+        if ($key eq "HEAD") {
+            push @headcode, $value;
+        }
+
+        # the IMAGE commands sets up a reference name
+        if ($key eq "IMAGE") {
+            push @imagedefs, $value;
+        }
+
+        # the GROUP entries are used in summary tables as arguments to the GROUP BY sql statement
+        if ($key eq "GROUP") {
+            push @group, $value;
+        }
+
+        # the ARGS commands define arguments to FIELDS commands
+        if ($key eq "ARGS") {
+            push @linkargs, $value;
+        }
+
+        # the OP commands define field operations
+        if ($key eq "OP") {
+            push @opwords, $value;
+        }
+
+        # the TD_CLASS command sets up an alternate TD class
+        if ($key eq "TD_CLASS") {
+            push @tdClasses, $value;
+            # print STDERR "found TD_CLASS\n";
+        }
+
+        # list of the table fields
+        if ($key eq "TAIL") {
+            push @tailcode, $value;
+        }
+
+        # list of the table restrictions
+        # replace this with a flexible where statement?
+        if ($key eq "WHERE") {
+            ($field) = split (/,\s+/, $value, 1);
+            if ($VERBOSE) { printf "%-20s\n", $field; }
+            push @where,   $field;
+        }
     }
 
@@ -126,17 +126,17 @@
     &check_key ("TITLE", "");
     &check_key ("FILE", "");
-    
+
     # these are used internally (not just a replacement)
     for ($i = 0; $i < @key; $i++) {
-	if ($key[$i] eq "MENU") { $MENU = $value[$i]; }
-	if ($key[$i] eq "MODE") { 
-	    if ($value[$i] eq "summary") {
-		if (@group == 0) {
-		    print STDERR "a summary table must have at least one group\n";
-		    exit 1;
-		}
-		&define_groups_string (@group);
-	    }
-	}
+        if ($key[$i] eq "MENU") { $MENU = $value[$i]; }
+        if ($key[$i] eq "MODE") {
+            if ($value[$i] eq "summary") {
+                if (@group == 0) {
+                    print STDERR "a summary table must have at least one group\n";
+                    exit 1;
+                }
+                &define_groups_string (@group);
+            }
+        }
     }
 
@@ -149,32 +149,32 @@
 
     foreach $linkarg (@linkargs) {
-	&parse_linkarg ($linkarg);
+        # print STDERR "linkarg: $linkarg\n";
+        &parse_linkarg ($linkarg);
     }
 
     foreach $imagedef (@imagedefs) {
-	&parse_imagedef ($imagedef);
+        &parse_imagedef ($imagedef);
     }
 
     foreach $opword (@opwords) {
-	&parse_opwords ($opword);
-    }
-
-    if (0) {
-	print STDERR "show: $show[0]\n";
-	($a, $b, $c) = &parse_label ($show[0]);
-	print STDERR "a: $a, b: $b, c: $c\n";
-
-	print STDERR "extras: $extras[0]\n";
-	($a, $b, $c) = &parse_label ($extras[0]);
-	print STDERR "a: $a, b: $b, c: $c\n";
-
-	print STDERR "show: $show[1]\n";
-	($a, $b, $c) = &parse_label ($show[1]);
-	print STDERR "a: $a, b: $b, c: $c\n";
-
-	print STDERR "extras: $extras[1]\n";
-	($a, $b, $c) = &parse_label ($extras[1]);
-	print STDERR "a: $a, b: $b, c: $c\n";
-	exit 0;
+        &parse_opwords ($opword);
+    }
+
+    if ($VERBOSE) {
+        print STDERR "show: $show[0]\n";
+        ($a, $b, $c) = &parse_label ($show[0]);
+        print STDERR "a: $a, b: $b, c: $c\n";
+
+        print STDERR "extras: $extras[0]\n";
+        ($a, $b, $c) = &parse_label ($extras[0]);
+        print STDERR "a: $a, b: $b, c: $c\n";
+
+        print STDERR "show: $show[1]\n";
+        ($a, $b, $c) = &parse_label ($show[1]);
+        print STDERR "a: $a, b: $b, c: $c\n";
+
+        print STDERR "extras: $extras[1]\n";
+        ($a, $b, $c) = &parse_label ($extras[1]);
+        print STDERR "a: $a, b: $b, c: $c\n";
     }
 }
@@ -188,48 +188,48 @@
 
     foreach $line (@list) {
-	
-	&check_keypairs;
-
-	print FILE $line;
-
-	# fill in table header
-	if ($line =~ m|// \*\* TABLE HEADER \*\*|) {
-	    &write_table_header;
-	}
-
-	# fill in TD_CLASS test
-	if ($line =~ m|// \*\* TD CLASS \*\*|) {
-	    &write_td_class;
-	}
-
-	# fill in table data
-	if ($line =~ m|// \*\* TABLE DATA \*\*|) {
-	    &write_table_data;
-	}
-
-	# fill in table query
-	if ($line =~ m|// \*\* TABLE QUERY \*\*|) {
-	    &write_table_query;
-	}
-
-	# fill in table restricts
-	if ($line =~ m|// \*\* TABLE RESTRICTIONS \*\*|) {
-	    &write_table_restrict;
-	}
-
-	# fill in table restricts
-	if ($line =~ m|// \*\* BUTTON RESTRICTIONS \*\*|) {
-	    &write_button_restrict;
-	}
-
-	# fill in head HTML or PHP code
-	if ($line =~ m|// \*\* HEAD CODE \*\*|) {
-	    &write_inline_code (@headcode);
-	}
-
-	# fill in tail HTML or PHP code
-	if ($line =~ m|// \*\* TAIL CODE \*\*|) {
-	    &write_inline_code (@tailcode);
-	}
+
+        &check_keypairs;
+
+        print FILE $line;
+
+        # fill in table header
+        if ($line =~ m|// \*\* TABLE HEADER \*\*|) {
+            &write_table_header;
+        }
+
+        # fill in TD_CLASS test
+        if ($line =~ m|// \*\* TD CLASS \*\*|) {
+            &write_td_class;
+        }
+
+        # fill in table data
+        if ($line =~ m|// \*\* TABLE DATA \*\*|) {
+            &write_table_data;
+        }
+
+        # fill in table query
+        if ($line =~ m|// \*\* TABLE QUERY \*\*|) {
+            &write_table_query;
+        }
+
+        # fill in table restricts
+        if ($line =~ m|// \*\* TABLE RESTRICTIONS \*\*|) {
+            &write_table_restrict;
+        }
+
+        # fill in table restricts
+        if ($line =~ m|// \*\* BUTTON RESTRICTIONS \*\*|) {
+            &write_button_restrict;
+        }
+
+        # fill in head HTML or PHP code
+        if ($line =~ m|// \*\* HEAD CODE \*\*|) {
+            &write_inline_code (@headcode);
+        }
+
+        # fill in tail HTML or PHP code
+        if ($line =~ m|// \*\* TAIL CODE \*\*|) {
+            &write_inline_code (@tailcode);
+        }
     }
     close (FILE);
@@ -239,13 +239,13 @@
     my (@code) = @_;
     my ($i, $code, $type);
-    
+
     for ($i = 0; $i < @code; $i++) {
-	($type, $line) = split (" ", $code[$i], 2);
-	if ($type eq "PHP") {
-	    print FILE "$line\n";
-	}
-	if ($type eq "HTML") {
-	    print FILE "?> $line <?\n";
-	}
+        ($type, $line) = split (" ", $code[$i], 2);
+        if ($type eq "PHP") {
+            print FILE "$line\n";
+        }
+        if ($type eq "HTML") {
+            print FILE "?> $line <?\n";
+        }
     }
 }
@@ -255,23 +255,23 @@
 
     # print the table header (field labels)
-    print FILE "echo \"<tr><td></td>\\n\";\n"; 
-    for ($i = 0; $i < @field; $i++) {
-	($label, $value, $string) = &parse_label ($show[$i]);
-	if ($show[$i] eq "none")  { next; }
-	print FILE "write_header_cell (\"list\", \"$name[$i]\");\n";
+    print FILE "echo \"<tr><td></td>\\n\";\n";
+    for ($i = 0; $i < @field; $i++) {
+        ($label, $value, $string) = &parse_label ($show[$i]);
+        if ($show[$i] eq "none")  { next; }
+        print FILE "write_header_cell (\"list\", \"$name[$i]\");\n";
     }
     print FILE "echo \"</tr>\\n\";\n";
 
     # print the column sort cells
-    print FILE "echo \"<tr><td></td>\\n\";\n"; 
-    for ($i = 0; $i < @field; $i++) {
-	($label, $value, $string) = &parse_label ($show[$i]);
-	if ($show[$i] eq "none")  { next; }
-	if ($field[$i] eq "*") { print FILE "echo \"<td></td>\\n\";\n"; next; } # empty cell (no sort for such fields)
-	if ($label eq "op") {
-	    print FILE "write_sort_cell (\"list\", \"$opf{$value}\", \$buttonLink, \$ID, '$myFile');\n";
-	} else {
-	    print FILE "write_sort_cell (\"list\", \"$fieldreal[$i]\", \$buttonLink, \$ID, '$myFile');\n";
-	}
+    print FILE "echo \"<tr><td></td>\\n\";\n";
+    for ($i = 0; $i < @field; $i++) {
+        ($label, $value, $string) = &parse_label ($show[$i]);
+        if ($show[$i] eq "none")  { next; }
+        if ($field[$i] eq "*") { print FILE "echo \"<td></td>\\n\";\n"; next; } # empty cell (no sort for such fields)
+        if ($label eq "op") {
+            print FILE "write_sort_cell (\"list\", \"$opf{$value}\", \$buttonLink, \$ID, '$myFile');\n";
+        } else {
+            print FILE "write_sort_cell (\"list\", \"$fieldreal[$i]\", \$buttonLink, \$ID, '$myFile');\n";
+        }
     }
     print FILE "echo \"</tr>\\n\";\n";
@@ -284,17 +284,17 @@
     foreach $tdClass (@tdClasses) {
 
-	# TD_CLASS class field expression
-	($class, $testline) = split (" ", $tdClass, 2);
-
-	$testlineFixed = "";
-	@testlineBits = split (" ", $testline);
-	foreach my $bit (@testlineBits) {
-	    $newbit = &parse_fieldname ($bit);
-	    $testlineFixed = "$testlineFixed $newbit";
-	}
-
-	print FILE "  if ($testlineFixed) {\n";
-	print FILE "    \$class = \"$class\";\n";
-	print FILE "  }\n";
+        # TD_CLASS class field expression
+        ($class, $testline) = split (" ", $tdClass, 2);
+
+        $testlineFixed = "";
+        @testlineBits = split (" ", $testline);
+        foreach my $bit (@testlineBits) {
+            $newbit = &parse_fieldname ($bit);
+            $testlineFixed = "$testlineFixed $newbit";
+        }
+
+        print FILE "  if ($testlineFixed) {\n";
+        print FILE "    \$class = \"$class\";\n";
+        print FILE "  }\n";
     }
 }
@@ -304,22 +304,22 @@
 
     if ($WHERE) {
-	print FILE "\$WHERE = \"WHERE $WHERE\";\n";
-    }	
-    for ($i = 0; $i < @field; $i++) {
-	$value = $fieldreal[$i];
-	if ($value eq "*") { next; }
-	if ($format[$i] eq "%s") {
-	    print FILE "\$WHERE = check_restrict ('$value', \$WHERE, 'string', 1.0);\n";
-	    next;
-	} 
-	if ($format[$i] eq "%C") {
-	    # convert the RA & DEC limits to radians for comparison
-	    print FILE "\$WHERE = check_restrict ('$value', \$WHERE, 'min', 0.017453);\n";
-	    print FILE "\$WHERE = check_restrict ('$value', \$WHERE, 'max', 0.017453);\n";
-	    next;
-	} 
-	print FILE "\$WHERE = check_restrict ('$value', \$WHERE, 'string', 1.0);\n";
-	print FILE "\$WHERE = check_restrict ('$value', \$WHERE, 'min', 1.0);\n";
-	print FILE "\$WHERE = check_restrict ('$value', \$WHERE, 'max', 1.0);\n";
+        print FILE "\$WHERE = \"WHERE $WHERE\";\n";
+    }
+    for ($i = 0; $i < @field; $i++) {
+        $value = $fieldreal[$i];
+        if ($value eq "*") { next; }
+        if ($format[$i] eq "%s") {
+            print FILE "\$WHERE = check_restrict ('$value', \$WHERE, 'string', 1.0);\n";
+            next;
+        }
+        if ($format[$i] eq "%C") {
+            # convert the RA & DEC limits to radians for comparison
+            print FILE "\$WHERE = check_restrict ('$value', \$WHERE, 'min', 0.017453);\n";
+            print FILE "\$WHERE = check_restrict ('$value', \$WHERE, 'max', 0.017453);\n";
+            next;
+        }
+        print FILE "\$WHERE = check_restrict ('$value', \$WHERE, 'string', 1.0);\n";
+        print FILE "\$WHERE = check_restrict ('$value', \$WHERE, 'min', 1.0);\n";
+        print FILE "\$WHERE = check_restrict ('$value', \$WHERE, 'max', 1.0);\n";
     }
     print FILE "\$WHERE = check_ordering ('$GROUPS', \$WHERE);\n";
@@ -330,13 +330,13 @@
 
     for ($i = 0; $i < @field; $i++) {
-	$value = $fieldreal[$i];
-	if ($value eq "*") { next; }
-	if ($format[$i] eq "%s") {
-	    print FILE "\$buttonLink = button_restrict_string ('$value', \$buttonLink);\n";
-	} else {
-	    print FILE "\$buttonLink = button_restrict_string ('$value', \$buttonLink);\n";
-	    print FILE "\$buttonLink = button_restrict_min ('$value', \$buttonLink);\n";
-	    print FILE "\$buttonLink = button_restrict_max ('$value', \$buttonLink);\n";
-	}
+        $value = $fieldreal[$i];
+        if ($value eq "*") { next; }
+        if ($format[$i] eq "%s") {
+            print FILE "\$buttonLink = button_restrict_string ('$value', \$buttonLink);\n";
+        } else {
+            print FILE "\$buttonLink = button_restrict_string ('$value', \$buttonLink);\n";
+            print FILE "\$buttonLink = button_restrict_min ('$value', \$buttonLink);\n";
+            print FILE "\$buttonLink = button_restrict_max ('$value', \$buttonLink);\n";
+        }
     }
 }
@@ -349,25 +349,25 @@
     print FILE "echo \"<tr><td>&ge;</td>\\n\";\n";
     for ($i = 0; $i < @field; $i++) {
-	if ($show[$i] eq "none")  { next; }
-	if ($field[$i] eq "*")  { 
-	    # * fields create an empty cell 
-	    print FILE "echo \"<td> &nbsp; </td>\\n\";\n";
-	} else {
-	    if ($format[$i] eq "%s") {
-		print FILE "write_query_row ('$fieldreal[$i]', $width[$i], 'string');\n";
-	    } else {
-		print FILE "write_query_row ('$fieldreal[$i]', $width[$i], 'min');\n";
-	    }
-	}
+        if ($show[$i] eq "none")  { next; }
+        if ($field[$i] eq "*")  {
+            # * fields create an empty cell
+            print FILE "echo \"<td> &nbsp; </td>\\n\";\n";
+        } else {
+            if ($format[$i] eq "%s") {
+                print FILE "write_query_row ('$fieldreal[$i]', $width[$i], 'string');\n";
+            } else {
+                print FILE "write_query_row ('$fieldreal[$i]', $width[$i], 'min');\n";
+            }
+        }
     }
     print FILE "echo \"</tr><tr><td>&le;</td>\\n\";\n";
     for ($i = 0; $i < @field; $i++) {
-	if ($show[$i] eq "none")  { next; }
-	if (($field[$i] eq "*") || ($format[$i] eq "%s")) { 
-	    # * fields create an empty cell 
-	    print FILE "echo \"<td> &nbsp; </td>\\n\";\n";
-	} else {
-	    print FILE "write_query_row ('$fieldreal[$i]', $width[$i], 'max');\n";
-	}
+        if ($show[$i] eq "none")  { next; }
+        if (($field[$i] eq "*") || ($format[$i] eq "%s")) {
+            # * fields create an empty cell
+            print FILE "echo \"<td> &nbsp; </td>\\n\";\n";
+        } else {
+            print FILE "write_query_row ('$fieldreal[$i]', $width[$i], 'max');\n";
+        }
     }
     print FILE "echo \"</tr>\\n\";\n";
@@ -379,62 +379,63 @@
 
     for ($i = 0; $i < @field; $i++) {
-	($label, $value, $string) = &parse_label ($show[$i]);
-	$Nrow = $count[$i];
-
-	# create the link variable if this entry should be linked
-	if ($label eq "none")  { next; }
-
-	if ($label eq "value") {
-	    # create the basic link variable
-	    if ($link[$i]) {
-		print FILE "  \$link = \"$link[$i]\" . \"?menu=$MENU&\" . \$ID['link'];\n";
-		# add extra GET data to target
-		if ($extras[$i]) { &parse_extras ($linkarg{$extras[$i]}); } 
-		$myLink = "\$link";
-	    } else {
-		$myLink = "\"\"";
-	    }
-	    # print the actual table cell line with the link...
-	    if (! $value && ($field[$i] ne "*")) { $value = "\$row[$Nrow]"; }
-
-	    # add special format elements
-	    # $realFormat = $format[$i];
-	    # if ($format[$i] eq '%T') {
-	    # 	$realFormat = '%s';
-	    # }
-	    print FILE "  write_table_cell (\$class, '$format[$i]', $myLink, $value);\n";
-	    next;
-	}
-
-	if ($label eq "op") {
-	    # create the basic link variable
-	    if ($link[$i]) {
-		print FILE "  \$link = \"$link[$i]\" . \"?menu=$MENU&\" . \$ID['link'];\n";
-		# add extra GET data to target
-		if ($extras[$i]) { &parse_extras ($linkarg{$extras[$i]}); } 
-		$myLink = "\$link";
-	    } else {
-		$myLink = "\"\"";
-	    }
-	    print FILE "  write_table_cell (\$class, '$format[$i]', $myLink, $ops{$value});\n";
-	    next;
-	}
-
-	if (($label eq "image") && !$link[$i]) {
-	    # print the actual table cell line with the image...
-	    print FILE "  echo \"<td class=\\\"\$class\\\">\n";
-	    print FILE "  echo \"              <img src=\\\"$image{$value}\\\"></td>\\n\";\n";
-	    next;
-	}
-
-	if (($label eq "image") && $link[$i]) {
-	    # create the basic link 
-	    print FILE "  \$link = \"$link[$i]\" . \"?menu=$MENU&\" . \$ID['link'];\n";
-	    # add extra php data to target
-	    if ($extras[$i]) { &parse_extras ($linkarg{$extras[$i]}); } 
-	    # print the actual table cell line with the link...
-	    print FILE "  echo \"<td class=\\\"\$class\\\"><a href=\\\"\$link\\\"> <img src=\\\"$image{$value}\\\"> </a></td>\\n\";\n";
-	    next;
-	}
+        ($label, $value, $string) = &parse_label ($show[$i]);
+        $Nrow = $count[$i];
+
+        # create the link variable if this entry should be linked
+        if ($label eq "none")  { next; }
+
+        if ($label eq "value") {
+            # create the basic link variable
+            # print STDERR "value: $link[$i]\n";
+            if ($link[$i]) {
+                print FILE "  \$link = \"$link[$i]\" . \"?menu=$MENU&\" . \$ID['link'];\n";
+                # add extra GET data to target
+                if ($extras[$i]) { &parse_extras ($linkarg{$extras[$i]}); }
+                $myLink = "\$link";
+            } else {
+                $myLink = "\"\"";
+            }
+            # print the actual table cell line with the link...
+            if (! $value && ($field[$i] ne "*")) { $value = "\$row[$Nrow]"; }
+
+            # add special format elements
+            # $realFormat = $format[$i];
+            # if ($format[$i] eq '%T') {
+            #   $realFormat = '%s';
+            # }
+            print FILE "  write_table_cell (\$class, '$format[$i]', $myLink, $value);\n";
+            next;
+        }
+
+        if ($label eq "op") {
+            # create the basic link variable
+            if ($link[$i]) {
+                print FILE "  \$link = \"$link[$i]\" . \"?menu=$MENU&\" . \$ID['link'];\n";
+                # add extra GET data to target
+                if ($extras[$i]) { &parse_extras ($linkarg{$extras[$i]}); }
+                $myLink = "\$link";
+            } else {
+                $myLink = "\"\"";
+            }
+            print FILE "  write_table_cell (\$class, '$format[$i]', $myLink, $ops{$value});\n";
+            next;
+        }
+
+        if (($label eq "image") && !$link[$i]) {
+            # print the actual table cell line with the image...
+            print FILE "  echo \"<td class=\\\"\$class\\\">\n";
+            print FILE "  echo \"              <img src=\\\"$image{$value}\\\"></td>\\n\";\n";
+            next;
+        }
+
+        if (($label eq "image") && $link[$i]) {
+            # create the basic link
+            print FILE "  \$link = \"$link[$i]\" . \"?menu=$MENU&\" . \$ID['link'];\n";
+            # add extra php data to target
+            if ($extras[$i]) { &parse_extras ($linkarg{$extras[$i]}); }
+            # print the actual table cell line with the link...
+            print FILE "  echo \"<td class=\\\"\$class\\\"><a href=\\\"\$link\\\"> <img src=\\\"$image{$value}\\\"> </a></td>\\n\";\n";
+            next;
+        }
     }
 }
@@ -446,7 +447,7 @@
     $FIELDS = "$array[0]";
     for ($i = 1; $i < @array; $i++) {
-	# skip * fields (not a valid query element
-	if ($array[$i] eq "*") { next; }
-	$FIELDS = "$FIELDS,$array[$i]";
+        # skip * fields (not a valid query element
+        if ($array[$i] eq "*") { next; }
+        $FIELDS = "$FIELDS,$array[$i]";
     }
     set_keypair ("FIELDS", $FIELDS);
@@ -459,7 +460,7 @@
     $GROUPS = "$array[0]";
     for ($i = 1; $i < @array; $i++) {
-	# skip * fields (not a valid query element
-	if ($array[$i] eq "*") { next; }
-	$GROUPS = "$GROUPS,$array[$i]";
+        # skip * fields (not a valid query element
+        if ($array[$i] eq "*") { next; }
+        $GROUPS = "$GROUPS,$array[$i]";
     }
     set_keypair ("GROUPS", $GROUPS);
@@ -473,11 +474,11 @@
     $Nrow = 0;
     for ($i = 0; $i < @field; $i++) {
-	# skip * fields (not a valid query element
-	if ($field[$i] eq "*") { 
-	    $count[$i] = -1;
-	} else {
-	    $count[$i] = $Nrow;
-	    $Nrow ++;
-	}
+        # skip * fields (not a valid query element
+        if ($field[$i] eq "*") {
+            $count[$i] = -1;
+        } else {
+            $count[$i] = $Nrow;
+            $Nrow ++;
+        }
     }
 }
@@ -491,7 +492,7 @@
     $WHERE = "$array[0]";
     for ($i = 1; $i < @array; $i++) {
-	$WHERE = "$WHERE AND $array[$i]";
-    }
-    
+        $WHERE = "$WHERE AND $array[$i]";
+    }
+
     set_keypair ("WHERE", $WHERE);
 }
@@ -504,8 +505,9 @@
 
     # examine the extras and parse the embedded fields (comma-separated)
+
     @extfields = split (/,/, $extras);
     for ($i = 0; $i < @extfields; $i++) {
-	($label, $value, $outline) = &parse_label ($extfields[$i]);
-	print FILE "  \$link = \$link . \"&$outline\";\n";
+        ($label, $value, $outline) = &parse_label ($extfields[$i]);
+        print FILE "  \$link = \$link . \"&$outline\";\n";
     }
 }
@@ -519,13 +521,16 @@
     ($word, $value) = split (" ", $_[0]);
 
+    # print STDERR "0: $_[0], $word, $value\n";
+
     if ($linkarg{$word}) {
-	$linkarg{$word} = "$linkarg{$word},$value";
+        $linkarg{$word} = "$linkarg{$word},$value";
     } else {
-	$linkarg{$word} = $value;
-    }	
+        $linkarg{$word} = $value;
+    }
+    # print STDERR "linkarg($word) : $linkarg{$word}\n";
 }
 
 # parse strings of the form label=value
-# if 'value' is of the form $field, try to match with 
+# if 'value' is of the form $field, try to match with
 # a supplied DB field, and replace with $row[$n] if found
 sub parse_label {
@@ -542,28 +547,31 @@
     if ($VERBOSE) { print STDERR "string: $string\n"; }
     if ($string =~ m|\S+=\S+|) {
-	($label, $value) = $string =~ m|(\S+)=(\S+)|;
-	if ($value =~ m|^\$|) {
-	  MATCH_LABEL:
-	    for ($i = 0; $i < @field; $i++) {
-		if ($field[$i] eq "*") { next; }
-		if ($value =~ m|^\$$fieldreal[$i]|) {
-		    # print "field: $fieldreal[$i]\n";
-		    ($name, $extra) = $value =~ m|^\$($fieldreal[$i])\@(\S+)|;
-		    # print "name: $name\n";
-		    # print "extra: $extra\n";
-		    # print "value: $value\n";
-
-		    $Nrow = $count[$i];
-		    if ($extra) {
-			$value = "\$row[$Nrow]\@$extra";
-		    } else {
-			$value = "\$row[$Nrow]";
-		    }
-		    # print "outval: $value\n";
-		    last MATCH_LABEL;
-		}
-	    }
-	    $outline = "$label=$value";
-	} 
+        ($label, $value) = $string =~ m|(\S+)=(\S+)|;
+        if ($value =~ m|^\$|) {
+          MATCH_LABEL:
+            for ($i = 0; $i < @field; $i++) {
+                if ($field[$i] eq "*") { next; }
+                while ($value =~ m|\$$fieldreal[$i]|) {
+                    # print "field: $fieldreal[$i]\n";
+                    # ($part1, $name, $part2) = $value =~ m|\$($fieldreal[$i])\@(\S+)|;
+                    ($part1, $name, $part2) = $value =~ m|(\S*)\$($fieldreal[$i])(\S*)|;
+                    # print "name: $name\n";
+                    # print "part1: $part1\n";
+                    # print "part2: $part2\n";
+                    # print "value: $value\n";
+
+                    $Nrow = $count[$i];
+                    $value = $part1 . "\$row[$Nrow]" . $part2;
+
+                    # if ($part1 || $part2) {
+                    # } else {
+                    #     $value = "\$row[$Nrow]";
+                    # }
+                    # print "outval: $value\n";
+                    # last MATCH_LABEL;
+                }
+            }
+            $outline = "$label=$value";
+        }
     }
     return ($label, $value, $outline);
@@ -576,9 +584,9 @@
     my ($variable) = $_[0];
     my ($i);
-    
+
     # print STDERR "variable: $variable\n";
 
     unless ($variable =~ m|^\$|) {
-	return $variable;
+        return $variable;
     }
 
@@ -588,16 +596,16 @@
 
     for ($i = 0; $i < @field; $i++) {
-	# print STDERR "$i: $fieldreal[$i] : $fieldname\n";
-
-	if ($field[$i] eq "*") { next; }
-	if ($fieldname ne $fieldreal[$i]) { next; }
-
-
-	$Nrow = $count[$i];
-
-	$value = "\$row[$Nrow]";
-
-	# print STDERR "found : $i : $count[$i] : $Nrow : $value\n";
-	return $value;
+        # print STDERR "$i: $fieldreal[$i] : $fieldname\n";
+
+        if ($field[$i] eq "*") { next; }
+        if ($fieldname ne $fieldreal[$i]) { next; }
+
+
+        $Nrow = $count[$i];
+
+        $value = "\$row[$Nrow]";
+
+        # print STDERR "found : $i : $count[$i] : $Nrow : $value\n";
+        return $value;
     }
     return $variable;
@@ -625,11 +633,11 @@
     @outfields = ();
     foreach $word (@words) {
-	$fword = &parse_fieldname ($word);
-	# print "field: $word -> $fword\n";
-	push @outwords, $fword;
-	if ($word =~ m|^\$|) {
-	    $word = substr ($word, 1);
-	}
-	push @outfields, $word;
+        $fword = &parse_fieldname ($word);
+        # print "field: $word -> $fword\n";
+        push @outwords, $fword;
+        if ($word =~ m|^\$|) {
+            $word = substr ($word, 1);
+        }
+        push @outfields, $word;
     }
     $outline = join (" ", @outwords);
@@ -657,10 +665,10 @@
 
     for ($i = 0; $i < @key; $i++) {
-	if ($key eq $key[$i]) {
-	    if ($value[$i] ne "") { die "key is multiply defined\n"; }
-	    $value[$i] = $value;
-	    if ($VERBOSE) { print STDERR "setting $key = $value\n"; }
-	    return;
-	}
+        if ($key eq $key[$i]) {
+            if ($value[$i] ne "") { die "key is multiply defined\n"; }
+            $value[$i] = $value;
+            if ($VERBOSE) { print STDERR "setting $key = $value\n"; }
+            return;
+        }
     }
 }
@@ -672,10 +680,10 @@
 
     for ($i = 0; $i < @key; $i++) {
-	if ($key eq $key[$i]) {
-	    if ($VERBOSE) { print "found $key: $key[$i]  -- $value[$i] (def: $default)\n"; }
-	    if (($default eq "") && ($value[$i] eq "")) { die "missing value for required key $key[$i]\n"; }
-	    if ($value[$i] eq "") { $value[$i] = $default; }
-	    return;
-	}
+        if ($key eq $key[$i]) {
+            if ($VERBOSE) { print "found $key: $key[$i]  -- $value[$i] (def: $default)\n"; }
+            if (($default eq "") && ($value[$i] eq "")) { die "missing value for required key $key[$i]\n"; }
+            if ($value[$i] eq "") { $value[$i] = $default; }
+            return;
+        }
     }
     die "unknown key $key\n";
@@ -685,18 +693,18 @@
     my ($i);
     for ($i = 0; $i < @key; $i++) {
-	if ($VERBOSE) { print "$key[$i]  -- $value[$i]\n"; }
-	if ($line =~ m|\$$key[$i]|) {
-	    if ($value[$i] eq "") { die "missing value for required key $key[$i]\n"; }
-	    $line =~ s|\$$key[$i]|$value[$i]|g;
-	}
-    }
-}
-
-# we need to find the structure size, including padding 
-# i'm not sure I know the answer to this: it is probably 
-# the total number of bytes rounded up to the largest 
+        if ($VERBOSE) { print "$key[$i]  -- $value[$i]\n"; }
+        if ($line =~ m|\$$key[$i]|) {
+            if ($value[$i] eq "") { die "missing value for required key $key[$i]\n"; }
+            $line =~ s|\$$key[$i]|$value[$i]|g;
+        }
+    }
+}
+
+# we need to find the structure size, including padding
+# i'm not sure I know the answer to this: it is probably
+# the total number of bytes rounded up to the largest
 # data item in the structure (ie, 8 for a double, etc)
 # if we have the size, then we can double check the structure
 # against the expectation at runtime.  for the moment,
-# calculate by hand and add to def.d file 
-
+# calculate by hand and add to def.d file
+
