Index: /trunk/Ohana/src/perl/src/mkdetrend
===================================================================
--- /trunk/Ohana/src/perl/src/mkdetrend	(revision 45)
+++ /trunk/Ohana/src/perl/src/mkdetrend	(revision 46)
@@ -1,3 +1,4 @@
 #!/usr/bin/perl
+$MKDETREND = "mkdetrend2";
 
 # strip off args related to the elixir config system, set env PTOLEMY
@@ -6,7 +7,7 @@
 # interpret command-line arguments
 if (@ARGV < 1) {
-  print STDOUT "USAGE: mkdetrend (mode) [arguments]\n";
-  print STDOUT "mode = help gives a complete list\n";
-  &escape;
+    print STDOUT "USAGE: $MKDETREND (mode) [arguments]\n";
+    print STDOUT "mode = help gives a complete list\n";
+    &escape;
 }
 if ($ARGV[0] eq "help") { &usage; }
@@ -57,12 +58,20 @@
 if ($ARGV[0] eq "test")         { &mk_test;       }
 
-&escape ("invalid mkdetrend command $ARGV[0]");
+&escape ("invalid $MKDETREND command $ARGV[0]");
 
 ######## top level functions ######################
+
+sub mk_test {
+
+    print "Content-type: text/plain\n\n";
+
+    print "mkdetrend2\n";
+    exit 0;
+}
 
 ############# define run ##############
 sub mk_create {
     if ($ARGV[1] eq "run") { &mk_createrun; }
-    if (@ARGV != 5) { &escape ("USAGE: mkdetrend create (camera) (run) (startdate) (stopdate)"); }
+    if (@ARGV != 5) { &escape ("USAGE: $MKDETREND create (camera) (run) (startdate) (stopdate)"); }
     
     $camera = $ARGV[1];
@@ -115,6 +124,6 @@
 ############# define run ##############
 sub mk_createrun {
-    if (@ARGV != 3) { &escape ("USAGE: mkdetrend create run (run)"); }
-    if ($ARGV[1] ne "run") { &escape ("USAGE: mkdetrend create run (run)"); }
+    if (@ARGV != 3) { &escape ("USAGE: $MKDETREND create run (run)"); }
+    if ($ARGV[1] ne "run") { &escape ("USAGE: $MKDETREND create run (run)"); }
     
     $run    = $ARGV[2];
@@ -157,5 +166,5 @@
 ############# change current run ##############
 sub mk_config {
-    if (@ARGV != 3) { &escape ("USAGE: mkdetrend config (camera) (run)"); }
+    if (@ARGV != 3) { &escape ("USAGE: $MKDETREND config (camera) (run)"); }
     
     $camera = $ARGV[1];
@@ -177,15 +186,15 @@
     my ($start, $stop, $mode);
 
-    if ((@ARGV != 2) && (@ARGV != 3)) { &escape ("USAGE: mkdetrend auto [command]"); }
+    if ((@ARGV != 2) && (@ARGV != 3)) { &escape ("USAGE: $MKDETREND auto [command]"); }
     $command = $ARGV[1];
 
     ($start, $stop, $mode) = load_dates ();
     if ($command eq "set") {
-	if (@ARGV != 3) { &escape ("USAGE: mkdetrend auto set (mode)"); }
+	if (@ARGV != 3) { &escape ("USAGE: $MKDETREND auto set (mode)"); }
 	&save_dates ($start, $stop, $ARGV[2]);
 	&goodbye;
     }
     
-    if (@ARGV != 2) { &escape ("USAGE: mkdetrend auto [command]"); }
+    if (@ARGV != 2) { &escape ("USAGE: $MKDETREND auto [command]"); }
     if ($command eq "show") {
 	print STDERR "MODE : $mode\n";
@@ -195,7 +204,7 @@
     if ($command eq "run") {
 	if ($mode eq "init") {
-	    system ("mkdetrend reset hard");
-	    system ("mkdetrend init");
-	    system ("mkdetrend run");
+	    system ("$MKDETREND reset hard");
+	    system ("$MKDETREND init");
+	    system ("$MKDETREND run");
 	    &save_dates ($start, $stop, "init");
 	    &goodbye;
@@ -203,5 +212,5 @@
 	
 	if ($mode eq "update") {
-	    system ("mkdetrend update");
+	    system ("$MKDETREND update");
 	    &save_dates ($start, $stop, "update");
 	    &goodbye;
@@ -212,45 +221,45 @@
 	}
     }
-    &escape ("mkdetrend auto $command : command not found\n");
+    &escape ("$MKDETREND auto $command : command not found\n");
 }
 
 ############# main run ##############
 sub mk_run {
-    if (@ARGV != 1) { &escape ("USAGE: mkdetrend run"); }
-  
-  system ("mkdetrend flips");
-  system ("mkdetrend norm");
-  system ("mkdetrend merge");
-  
-  &goodbye;
+    if (@ARGV != 1) { &escape ("USAGE: $MKDETREND run"); }
+    
+    system ("$MKDETREND flips");
+    system ("$MKDETREND norm");
+    system ("$MKDETREND merge");
+    
+    &goodbye;
 }
 
 ############# main init ##############
 sub mk_init {
-    if (@ARGV != 1) { &escape ("USAGE: mkdetrend init"); }
-  
-  system ("mkdetrend list.init");
-  system ("mkdetrend split");
-  
-  &goodbye;
+    if (@ARGV != 1) { &escape ("USAGE: $MKDETREND init"); }
+    
+    system ("$MKDETREND list.init");
+    system ("$MKDETREND split");
+    
+    &goodbye;
 }
 
 ############# main update ##############
 sub mk_update {
-    if (@ARGV != 1) { &escape ("USAGE: mkdetrend update"); }
-  
-  system ("mkdetrend reset update");
-  system ("mkdetrend init");
-  system ("mkdetrend update.list");
-  system ("mkdetrend update.stats");
-  system ("mkdetrend run");
-  
-  &goodbye;
+    if (@ARGV != 1) { &escape ("USAGE: $MKDETREND update"); }
+    
+    system ("$MKDETREND reset update");
+    system ("$MKDETREND init");
+    system ("$MKDETREND update.list");
+    system ("$MKDETREND update.stats");
+    system ("$MKDETREND run");
+    
+    &goodbye;
 }
 
 ############# show current state ##############
 sub mk_state {
-    if (@ARGV != 1) { &escape ("USAGE: mkdetrend state"); }
-  
+    if (@ARGV != 1) { &escape ("USAGE: $MKDETREND state"); }
+    
     $file = mkfiles ("dates");
     if (! -e $file) { 
@@ -268,5 +277,5 @@
     
     @list = &load_config;
-    if (@list == 0) { &escape ("mkdetrend not configured"); }
+    if (@list == 0) { &escape ("$MKDETREND not configured"); }
 
     for ($i = 0; $i < @list; $i++) {
@@ -278,8 +287,8 @@
 ############# show current state ##############
 sub mk_list_runs {
-    if (@ARGV != 1) { &escape ("USAGE: mkdetrend list.runs"); }
-  
-  system ("ls $root");
-  &goodbye;
+    if (@ARGV != 1) { &escape ("USAGE: $MKDETREND list.runs"); }
+    
+    system ("ls $root");
+    &goodbye;
 }
 
@@ -287,37 +296,37 @@
 sub mk_dup {
     if (@ARGV != 2) { &escape ("USAGE: detrend dup (config)"); }
-  
-  $key = $ARGV[1];
-  @list = load_config ();
-  
-  # look for entry that matches requested config
-  @match = ();
-  for ($i = 0; $i < @list; $i++) {
-    $config = gtconfig ($list[$i], "config");
-    if ($key eq $config) { @match = (@match, $i); }	
-  }
-  if (@match == 0) { &escape ("config $key not found\n"); }
-  
-  # create new config version based on version 0
-  $Nnew = @match;
-  $old = $list[$match[0]];
-  $new = stconfig ($old, "version", $Nnew);
-  @list = (@list, $new);
-  save_config (@list);
-  
-  # now we need to duplicate all of the reference files from the first config 
-  for ($i = 0; $i < $Nccd; $i++) {
-    $fold = mknames ("master", $old, $ccds[$i]);
-    $fnew = mknames ("master", $new, $ccds[$i]);
-    system ("cp $fold $fnew");
-  }
-  foreach $name ("stats", "medbin", "tenbin", "imbin") {
-    $fold = mknames ($name, $old);
-    $fnew = mknames ($name, $new);
-    system ("cp $fold $fnew");
-  }
-  
-  &goodbye;
-  
+    
+    $key = $ARGV[1];
+    @list = load_config ();
+    
+    # look for entry that matches requested config
+    @match = ();
+    for ($i = 0; $i < @list; $i++) {
+	$config = gtconfig ($list[$i], "config");
+	if ($key eq $config) { @match = (@match, $i); }	
+    }
+    if (@match == 0) { &escape ("config $key not found\n"); }
+    
+    # create new config version based on version 0
+    $Nnew = @match;
+    $old = $list[$match[0]];
+    $new = stconfig ($old, "version", $Nnew);
+    @list = (@list, $new);
+    save_config (@list);
+    
+    # now we need to duplicate all of the reference files from the first config 
+    foreach $ccd (@ccds) {
+	$fold = mknames ("master", $old, $ccd);
+	$fnew = mknames ("master", $new, $ccd);
+	system ("cp $fold $fnew");
+    }
+    foreach $name ("stats", "medbin", "tenbin", "imbin") {
+	$fold = mknames ($name, $old);
+	$fnew = mknames ($name, $new);
+	system ("cp $fold $fnew");
+    }
+    
+    &goodbye;
+    
 }
 
@@ -365,5 +374,5 @@
 	    }
 
-	    # delete files names in these files:
+	    # delete files names in these files (not needed with flips2)
 	    $name = &mknames ("msplit", $confline, $ccd); 
 	    open (FILE, "$name");
@@ -398,243 +407,243 @@
 ############## delete config ###############
 sub mk_del {
-    if (@ARGV != 2) { &escape ("USAGE: mkdetrend del (config.ver)"); }
-  
-  $key = $ARGV[1];
-  @list = load_config ();
-  
-  # look for entry that matches requested config
-  $match = -1;
-  for ($i = 0; $i < @list; $i++) {
-    $version = gtconfig ($list[$i], "version");
-    if ($key eq $version) {
-      $match = $i;
-      last;
-    }	
-  }
-  if ($match == -1) {
-    print STDERR "config.ver $key not found\n";
-    &escape;
-  }
-  
-  # create new list without match:
-  @newlist = ();
-  for ($i = 0; $i < @list; $i++) {
-    if ($i == $match) { next; }
-    @newlist = (@newlist, $list[$i]);
-  }
-  
-  save_config (@newlist);
-  &goodbye;
-  
+    if (@ARGV != 2) { &escape ("USAGE: $MKDETREND del (config.ver)"); }
+    
+    $key = $ARGV[1];
+    @list = load_config ();
+    
+    # look for entry that matches requested config
+    $match = -1;
+    for ($i = 0; $i < @list; $i++) {
+	$version = gtconfig ($list[$i], "version");
+	if ($key eq $version) {
+	    $match = $i;
+	    last;
+	}	
+    }
+    if ($match == -1) {
+	print STDERR "config.ver $key not found\n";
+	&escape;
+    }
+    
+    # create new list without match:
+    @newlist = ();
+    for ($i = 0; $i < @list; $i++) {
+	if ($i == $match) { next; }
+	@newlist = (@newlist, $list[$i]);
+    }
+    
+    save_config (@newlist);
+    &goodbye;
+    
 }
 
 ############## reset config ###############
 sub mk_reset {
-  if (@ARGV != 2) {
-    print STDERR "USAGE: mkdetrend reset (level)\n";
-    print STDERR "       level = hard || update\n";
-    &escape; 
-  }
-
-  $level = $ARGV[1];
-  @list = load_config ();
-  
-  # find specific config:
+    if (@ARGV != 2) {
+	print STDERR "USAGE: $MKDETREND reset (level)\n";
+	print STDERR "       level = hard || update\n";
+	&escape; 
+    }
+
+    $level = $ARGV[1];
+    @list = load_config ();
+    
+    # find specific config:
 RESET:
-  foreach $confline (@list) {
-    $status = gtconfig ($confline, "status");
-
-    if ($level eq "hard" ) {
-	$confline = stconfig ($confline, "status", "init");
-    }
-    if ($level eq "update") {
-	if (($status eq "done.merge") || ($status eq "modified") || ($status eq "update")) {
-	    $confline = stconfig ($confline, "status", "update");
-	    next RESET;
-	} 
-	if (($status eq "freeze") || ($status eq "accepted")) {
-	    $confline = stconfig ($confline, "status", "freeze");
-	    next RESET;
-	} 
-	$confline = stconfig ($confline, "status", "init");
-    }
-  }
-  save_config (@list);
-  &goodbye;
+    foreach $confline (@list) {
+	$status = gtconfig ($confline, "status");
+
+	if ($level eq "hard" ) {
+	    $confline = stconfig ($confline, "status", "init");
+	}
+	if ($level eq "update") {
+	    if (($status eq "done.merge") || ($status eq "modified") || ($status eq "update")) {
+		$confline = stconfig ($confline, "status", "update");
+		next RESET;
+	    } 
+	    if (($status eq "freeze") || ($status eq "accepted")) {
+		$confline = stconfig ($confline, "status", "freeze");
+		next RESET;
+	    } 
+	    $confline = stconfig ($confline, "status", "init");
+	}
+    }
+    save_config (@list);
+    &goodbye;
 }
 
 ############## define config ###############
 sub mk_def {
-    if (@ARGV != 4) { &escape ("USAGE: mkdetrend def (config.ver) (start) (stop)"); }
-  
-  $key   = $ARGV[1];
-  $start = $ARGV[2];
-  $stop  = $ARGV[3];
-  
-  @list = load_config ();
-  
-  # find specific config:
-  $match = -1;
-  for ($i = 0; $i < @list; $i++) {
-    $version = gtconfig ($list[$i], "version");
-    if ($key eq $version) {
-      $match = $i;
-    }	
-  }
-  if (@match == -1) {
-    print STDERR "config.ver $key not found\n";
-    &escape;
-  }
-  
-  $new = $list[$match];
-  $new = stconfig ($new, "start", $start);
-  $new = stconfig ($new, "stop", $stop);
-  $list[$match] = $new;
-  
-  save_config (@list);
-  &goodbye;
-  
+    if (@ARGV != 4) { &escape ("USAGE: $MKDETREND def (config.ver) (start) (stop)"); }
+    
+    $key   = $ARGV[1];
+    $start = $ARGV[2];
+    $stop  = $ARGV[3];
+    
+    @list = load_config ();
+    
+    # find specific config:
+    $match = -1;
+    for ($i = 0; $i < @list; $i++) {
+	$version = gtconfig ($list[$i], "version");
+	if ($key eq $version) {
+	    $match = $i;
+	}	
+    }
+    if (@match == -1) {
+	print STDERR "config.ver $key not found\n";
+	&escape;
+    }
+    
+    $new = $list[$match];
+    $new = stconfig ($new, "start", $start);
+    $new = stconfig ($new, "stop", $stop);
+    $list[$match] = $new;
+    
+    save_config (@list);
+    &goodbye;
+    
 }
 
 ############## list init ###############
 sub mk_list_init {
-  if (@ARGV != 1) { &escape ("USAGE: mkdetrend list.init"); }
-  
-  @list = load_config ();
-  
-  # create namelist
-  $Nrun = 0;
-  $file = mkfiles ("list");
-  open (FILE, ">$file");
-  foreach $confline (@list) {
-      $status = gtconfig ($confline, "status");
-      if ($status ne "init") { next; }
-      $Nrun ++;
-      $line = gtconfig ($confline, "mosaic");
-      print FILE "$line\n";
-      $confline = stconfig ($confline, "status", "running.init");
-  }
-  close (FILE);
-  save_config (@list);
-
-  if ($Nrun == 0) { &goodbye; }
-  
-  system ("elixir -D DETREND_DIR $det -D mode mkdetrend -D global.pending imselect.split $file");
-  system ("mkdetrend meval init");
-  
-  &goodbye;
+    if (@ARGV != 1) { &escape ("USAGE: $MKDETREND list.init"); }
+    
+    @list = load_config ();
+    
+    # create namelist
+    $Nrun = 0;
+    $file = mkfiles ("list");
+    open (FILE, ">$file");
+    foreach $confline (@list) {
+	$status = gtconfig ($confline, "status");
+	if ($status ne "init") { next; }
+	$Nrun ++;
+	$line = gtconfig ($confline, "mosaic");
+	print FILE "$line\n";
+	$confline = stconfig ($confline, "status", "running.init");
+    }
+    close (FILE);
+    save_config (@list);
+
+    if ($Nrun == 0) { &goodbye; }
+    
+    vsystem ("elixir -D DETREND_DIR $det -D mode $MKDETREND -D global.pending imselect.split $file");
+    system ("$MKDETREND meval init");
+    
+    &goodbye;
 }
 
 ############## split ###############
 sub mk_split {
-    if (@ARGV != 1) { &escape ("USAGE: mkdetrend split"); }
-  
-  @list = load_config ();
-  
-  # create namelist
-  $Nrun = 0;
-  $file = mkfiles ("list");
-  open (FILE, ">$file");
-  foreach $confline (@list) {
-      $status = gtconfig ($confline, "status");
-      if (($status ne "done.init") && ($status ne "split")) { next; }
-      $Nrun ++;
-      for ($j = 0; $j < $Nccd; $j++) {
-	$line = gtconfig ($confline, "chiprun", $j);
-	print FILE "$line\n";
-      }
-      $confline = stconfig ($confline, "status", "running.split");
-  }
-  close (FILE);
-  save_config (@list);
-
-  if ($Nrun == 0) { &goodbye; }
-  
-  system ("elixir -D DETREND_DIR $det -D mode mkdetrend -D global.pending split.mef $file");
-  system ("mkdetrend eval split");
-  
-  &goodbye;
+    if (@ARGV != 1) { &escape ("USAGE: $MKDETREND split"); }
+    
+    @list = load_config ();
+    
+    # create namelist
+    $Nrun = 0;
+    $file = mkfiles ("list");
+    open (FILE, ">$file");
+    foreach $confline (@list) {
+	$status = gtconfig ($confline, "status");
+	if (($status ne "done.init") && ($status ne "split")) { next; }
+	$Nrun ++;
+	foreach $ccd (@ccds) {
+	    $line = gtconfig ($confline, "chiprun", $ccd);
+	    print FILE "$line\n";
+	}
+	$confline = stconfig ($confline, "status", "running.split");
+    }
+    close (FILE);
+    save_config (@list);
+
+    if ($Nrun == 0) { &goodbye; }
+    
+    system ("elixir -D DETREND_DIR $det -D mode $MKDETREND -D global.pending merge.lists $file");
+    system ("$MKDETREND eval split");
+    
+    &goodbye;
 }
 
 ############## update lists ###############
 sub mk_update_list {
-    if (@ARGV != 1) { &escape ("USAGE: mkdetrend update.list"); }
-  
-  @list = load_config ();
-  
-  # create namelist
-  $Nrun = 0;
-  $file = mkfiles ("list");
-  open (FILE, ">$file");
-  foreach $confline (@list) {
-      $status = gtconfig ($confline, "status");
-      if ($status ne "update") { next; }
-      $Nrun ++;
-      $line = gtconfig ($confline, "mosaic");
-      print FILE "$line\n";
-      $confline = stconfig ($confline, "status", "running.update.list");
-  }
-  close (FILE);
-  save_config (@list);
-  
-  if ($Nrun == 0) { &goodbye; }
-  
-  system ("elixir -D DETREND_DIR $det -D mode mkdetrend -D global.pending update.split $file");
-  system ("mkdetrend meval update.list");
-  
-  &goodbye;
+    if (@ARGV != 1) { &escape ("USAGE: $MKDETREND update.list"); }
+    
+    @list = load_config ();
+    
+    # create namelist
+    $Nrun = 0;
+    $file = mkfiles ("list");
+    open (FILE, ">$file");
+    foreach $confline (@list) {
+	$status = gtconfig ($confline, "status");
+	if ($status ne "update") { next; }
+	$Nrun ++;
+	$line = gtconfig ($confline, "mosaic");
+	print FILE "$line\n";
+	$confline = stconfig ($confline, "status", "running.update.list");
+    }
+    close (FILE);
+    save_config (@list);
+    
+    if ($Nrun == 0) { &goodbye; }
+    
+    system ("elixir -D DETREND_DIR $det -D mode $MKDETREND -D global.pending update.split $file");
+    system ("$MKDETREND meval update.list");
+    
+    &goodbye;
 }
 
 ############## update stats ###############
 sub mk_update_stats {
-    if (@ARGV != 1) { &escape ("USAGE: mkdetrend update.stats"); }
-  
-  @list = load_config ();
-  
-  # create namelist
-  $Nrun = 0;
-  $file = mkfiles ("list");
-  open (FILE, ">$file");
-  foreach $confline (@list) {
-      $status = gtconfig ($confline, "status");
-      if (($status ne "done.update.list") && ($status ne "update.stats")) { next; }
-      $Nrun ++;
-      for ($j = 0; $j < $Nccd; $j++) {
-	  $line = gtconfig ($confline, "chiprun", $j);
-	  print FILE "$line\n";
-      }
-      $confline = stconfig ($confline, "status", "running.update.stats");
-
-  }
-  close (FILE);
-  save_config (@list);
-  
-  if ($Nrun == 0) { &goodbye; }
-  
-  system ("elixir -D DETREND_DIR $det -D mode mkdetrend -D global.pending update.msplit $file");
-  system ("mkdetrend eval update.stats");
-  
-  &goodbye;
+    if (@ARGV != 1) { &escape ("USAGE: $MKDETREND update.stats"); }
+    
+    @list = load_config ();
+    
+    # create namelist
+    $Nrun = 0;
+    $file = mkfiles ("list");
+    open (FILE, ">$file");
+    foreach $confline (@list) {
+	$status = gtconfig ($confline, "status");
+	if (($status ne "done.update.list") && ($status ne "update.stats")) { next; }
+	$Nrun ++;
+	foreach $ccd (@ccds) {
+	    $line = gtconfig ($confline, "chiprun", $ccd);
+	    print FILE "$line\n";
+	}
+	$confline = stconfig ($confline, "status", "running.update.stats");
+
+    }
+    close (FILE);
+    save_config (@list);
+    
+    if ($Nrun == 0) { &goodbye; }
+    
+    system ("elixir -D DETREND_DIR $det -D mode $MKDETREND -D global.pending update.msplit $file");
+    system ("$MKDETREND eval update.stats");
+    
+    &goodbye;
 }
 
 ############## set state ###############
 sub mk_set {
-    if (@ARGV != 3) { &escape ("USAGE: mkdetrend set (config number) (state)"); }
-  
-  @list = load_config ();
-  
-  $key = $ARGV[1];
-  $state = $ARGV[2];
-  
-  $new = stconfig ($list[$key], "status", "$state");
-  $list[$key] = $new;
-  save_config (@list);
-  
-  &goodbye;
+    if (@ARGV != 3) { &escape ("USAGE: $MKDETREND set (config number) (state)"); }
+    
+    @list = load_config ();
+    
+    $key = $ARGV[1];
+    $state = $ARGV[2];
+    
+    $new = stconfig ($list[$key], "status", "$state");
+    $list[$key] = $new;
+    save_config (@list);
+    
+    &goodbye;
 }
 
 ############## flips run ###############
 sub mk_flips {
-    if (@ARGV != 1) { &escape ("USAGE: mkdetrend flips"); }
+    if (@ARGV != 1) { &escape ("USAGE: $MKDETREND flips"); }
     
     @list = load_config ();
@@ -648,6 +657,6 @@
 	if (($status ne "done.split") && ($status ne "modified") && ($status ne "flips")) { next; }
 	$Nrun ++;
-	for ($j = 0; $j < $Nccd; $j++) {
-	    $line = gtconfig ($confline, "chiprun", $j);
+	foreach $ccd (@ccds) {
+	    $line = gtconfig ($confline, "chiprun", $ccd);
 	    print FILE "$line\n";
 	}
@@ -659,6 +668,6 @@
     if ($Nrun == 0) { &goodbye; }
 
-    system ("elixir -D DETREND_DIR $det -D mode mkdetrend -D global.pending create.subset $file"); 
-    system ("mkdetrend eval flips");
+    system ("elixir -D DETREND_DIR $det -D mode $MKDETREND -D global.pending create.subset $file"); 
+    system ("$MKDETREND eval flips");
 
     &goodbye;
@@ -667,5 +676,5 @@
 ############## norm run ###############
 sub mk_norm {
-    if (@ARGV != 1) { &escape ("USAGE: mkdetrend norm"); }
+    if (@ARGV != 1) { &escape ("USAGE: $MKDETREND norm"); }
 
     @list = load_config ();
@@ -679,6 +688,6 @@
 	if (($status ne "done.flips") && ($status ne "norm")) { next; }
 	$Nrun ++;
-	for ($j = 0; $j < $Nccd; $j++) {
-	    $line = gtconfig ($confline, "chiprun", $j);
+	foreach $ccd (@ccds) {
+	    $line = gtconfig ($confline, "chiprun", $ccd);
 	    print FILE "$line\n";
 	}
@@ -690,6 +699,6 @@
     if ($Nrun == 0) { &goodbye; }
 
-    vsystem ("elixir -D DETREND_DIR $det -D mode mkdetrend -D global.pending normal $file");
-    vsystem ("mkdetrend eval norm");
+    vsystem ("elixir -D DETREND_DIR $det -D mode $MKDETREND -D global.pending normal $file");
+    vsystem ("$MKDETREND eval norm");
 
     &goodbye;
@@ -698,5 +707,5 @@
 ############## merge run ###############
 sub mk_merge {
-    if (@ARGV != 1) { &escape ("USAGE: mkdetrend merge"); }
+    if (@ARGV != 1) { &escape ("USAGE: $MKDETREND merge"); }
     
     @list = load_config ();
@@ -719,6 +728,6 @@
     if ($Nrun == 0) { &goodbye; }
     
-    vsystem ("elixir -D DETREND_DIR $det -D mode mkdetrend -D global.pending stats $file");
-    vsystem ("mkdetrend meval merge");
+    vsystem ("elixir -D DETREND_DIR $det -D mode $MKDETREND -D global.pending stats $file");
+    vsystem ("$MKDETREND meval merge");
     
     &goodbye;
@@ -727,8 +736,12 @@
 ############## reg run ###############
 sub mk_reg {
-    if (@ARGV != 1) { &escape ("USAGE: mkdetrend reg"); }
-    
-    @list = load_config ();
-    
+    if (@ARGV != 1) { &escape ("USAGE: $MKDETREND reg"); }
+    
+    @list = load_config ();
+    
+    # create directory for fhtool to work in
+    $links = mkfiles ("links");
+    if (! -e $links) { mkdir ($links); }
+
     # create namelist for those with appropriate status
     foreach $confline (@list) {
@@ -740,27 +753,58 @@
 	$success = 1;
 	$ID = gtconfig ($confline, "ID");
-	for ($j = 0; $j < $Nccd; $j++) {
-	    $file = mknames ("norm", $confline, $ccds[$j]);
-	    $line = "detregister $file -label elixir -ID $ID";
-	    $status = system ($line);
-	    if ($status) { 
-		print STDERR "error registering $file\n";
-		$success = 0;
+
+	$DBmode = `gconfig DETREND-DB-MODE`; chop $DBmode;
+	$DBmode = "\U$DBmode\E";
+
+	if ($DBmode eq "SPLIT") {
+	    for ($j = 0; $j < $Nccd; $j++) {
+		$file = mknames ("norm", $confline, $ccds[$j]);
+		$line = "detregister $file -label elixir -ID $ID";
+		$status = system ($line);
+		if ($status) { 
+		    print STDERR "error registering $file\n";
+		    $success = 0;
+		}
 	    }
-	}
-	if ($success) {
+	    goto registered;
+	}
+
+	if ($DBmode eq "MEF") {
+	    # make links 
+	    foreach $ccd (@ccds) {
+		$file = mknames ("norm", $confline, $ccd);
+		$link = mknames ("link", $confline, $ccd);
+		symlink $file, $link;
+	    }
+
+	    # mef, register
+	    $mef = mknames ("mef", $confline);
+	    vsystem ("fhtool -P $links $mef");
+	    if ($status) { $success = 0; }
+	    vsystem ("detregister $mef -label elixir -ID $ID");
+	    if ($status) { $success = 0; }
+
+	    # remove links
+	    foreach $ccd (@ccds) {
+		$link = mknames ("link", $confline, $ccd);
+		unlink $link;
+	    }
+	    goto registered;
+	}
+	print STDERR "DB mode not defined?\n";
+	$success = 0;
+
+      registered:
+	if ($success) { 
 	    $confline = stconfig ($confline, "status", "done.reg");
 	} else {
+	    print STDERR "error registering $file\n"; 
 	    $confline = stconfig ($confline, "status", "fail.reg");
 	}
 	save_config (@list);
-    }
-
-    # detregister is sequential anyway, run serial
-    # system ("elixir -D DETREND_DIR $det -D mode mkdetrend -D global.pending detregister $file");
-    # system ("mkdetrend eval reg");
+
+    }
 
     # use recipe file to decide if we apply 'scat' or not!
-
     $file = mkfiles ("list");
     # create list of images to apply scattered-light correction:
@@ -775,6 +819,6 @@
 
 	    open (FILE, ">$file");
-	    for ($j = 0; $j < $Nccd; $j++) {
-		$line = mknames ("norm", $confline, $ccds[$j]);
+	    foreach $ccd (@ccds) {
+		$line = mknames ("norm", $confline, $ccd);
 		print FILE "$line\n";
 	    }
@@ -805,5 +849,5 @@
 ############## html modify ###############
 sub mk_fixmasters {
-    if (@ARGV != 1) { &escape ("USAGE: mkdetrend fix.masters"); }
+    if (@ARGV != 1) { &escape ("USAGE: $MKDETREND fix.masters"); }
     
     @list = load_config ();
@@ -853,5 +897,5 @@
 ############## html modify ###############
 sub mk_checksplits {
-    if (@ARGV != 2) { &escape ("USAGE: mkdetrend check.splits (config)"); }
+    if (@ARGV != 2) { &escape ("USAGE: $MKDETREND check.splits (config)"); }
     
     $Nconfig = $ARGV[1];
@@ -860,8 +904,8 @@
 
     # re-create all masters to match master for chip 00
-    for ($i = 0; $i < $Nccd; $i++) {
+    foreach $ccd (@ccds) {
 	
 	# load existing master file
-	$master = mknames ("master", $name, $ccds[$i]); 
+	$master = mknames ("master", $name, $ccd); 
 	open (FILE, $master);
 	@master = <FILE>;
@@ -882,100 +926,37 @@
 ############## html duplicate ###############
 sub mk_htmldup {
-    if (@ARGV != 2) { &escape ("USAGE: mkdetrend htmldup (config)"); }
-  
-  $config = $ARGV[1];
-  # we are just calling the "mkdetrend dup" function and then calling "mkdetrend html1"
-  
-  system ("mkdetrend dup $config");
-  print STDOUT "<meta http-equiv=refresh content=\"0; url=$CGI/elixir1?&elconf=$elconf\">\n";
-  
-  &goodbye;
-  
+    if (@ARGV != 2) { &escape ("USAGE: $MKDETREND htmldup (config)"); }
+    
+    $config = $ARGV[1];
+    # we are just calling the "mkdetrend dup" function and then calling "$MKDETREND html1"
+    
+    system ("$MKDETREND dup $config");
+    print STDOUT "<meta http-equiv=refresh content=\"0; url=$CGI/elixir1?&elconf=$elconf\">\n";
+    
+    &goodbye;
+    
 }
 
 ############## html delete ###############
 sub mk_htmldel {
-    if (@ARGV != 2) { &escape ("USAGE: mkdetrend htmldel (config.ver)"); }
-  
-  $config = $ARGV[1];
-  # we are just calling the "mkdetrend del" function and then calling "mkdetrend html1"
-  
-  system ("mkdetrend del $config");
-  print STDOUT "<meta http-equiv=refresh content=\"0; url=$CGI/elixir1?&elconf=$elconf\">\n";
-  
-  &goodbye;;
-  
+    if (@ARGV != 2) { &escape ("USAGE: $MKDETREND htmldel (config.ver)"); }
+    
+    $config = $ARGV[1];
+    # we are just calling the "mkdetrend del" function and then calling "mkdetrend html1"
+    
+    system ("$MKDETREND del $config");
+    print STDOUT "<meta http-equiv=refresh content=\"0; url=$CGI/elixir1?&elconf=$elconf\">\n";
+    
+    &goodbye;;
+    
 }
 
 ############## html define ###############
 sub mk_htmldef {
-    if (@ARGV != 2) { &escape ("USAGE: mkdetrend htmldef (config.ver)"); }
-  
-  $key = $ARGV[1];
-  
-  # find (config.ver) in list:
-  
-  @list = load_config ();
-  
-  $match = -1;
-  for ($i = 0; $i < @list; $i++) {
-    $version = gtconfig ($list[$i], "version");
-    if ($key eq $version) {
-      $match = $i;
-      last;
-    }
-  }
-    if ($match == -1) { &escape ("error: can't find config entry"); }
-  
-  # show the complete list for reference
-  print STDOUT "<HEADER> <TITLE>Elixir Mkdetrend Report</TITLE> </HEADER>\n";
-  print STDOUT "<BODY BGCOLOR=#fff0e0 TEXT=#000000 LINK=#0000ff VLINK=#6600ff ALINK=#a0a0a0>\n";
-  print STDOUT "<table border>\n";
-  for ($i = 0; $i < @list; $i++) {
-    $config  = gtconfig ($list[$i], "config");
-    $version = gtconfig ($list[$i], "version");
-    $status  = gtconfig ($list[$i], "status");
-    $from    = gtconfig ($list[$i], "from");
-    $to      = gtconfig ($list[$i], "to");
-    print STDOUT "<tr><td> $version </td>\n";
-    print STDOUT "<td> $from </td><td> $to </td>\n";
-    print STDOUT "<td> <a href=$CGI/elixir2?$version&elconf=$elconf> $status </a></td>\n";
-    print STDOUT "<td> <a href=$CGI/split?$config&elconf=$elconf>      split </a></td>\n";
-    print STDOUT "<td> <a href=$CGI/delete?$version&elconf=$elconf>   delete </a></td>\n";
-    print STDOUT "<td> <a href=$CGI/redef?$version&elconf=$elconf>  redefine </a></td>\n";
-    print STDOUT "</tr>\n";
-  }
-  print STDOUT "</table></body><br><br>\n";
-  
-  $version = gtconfig ($list[$match], "version");
-  $status  = gtconfig ($list[$match], "status");
-  $from    = gtconfig ($list[$match], "from");
-  $to      = gtconfig ($list[$match], "to");
-  print STDOUT "redefining <b> $key: </b> <br>\n";    
-  print STDOUT "<table border>\n";
-  print STDOUT "<tr><td> $version </td>\n";
-  print STDOUT "<td> $from </td><td> $to </td><td> $status </a></td>\n";
-  print STDOUT "</tr></table>\n";
-  
-  
-  # create a simple form for redefine:
-  print STDOUT "<form method=post action=$CGI/redefine&elconf=$elconf>\n";
-  print STDOUT "start: <input type=text value=$from name=start size=40 maxlength=40> <br>\n";
-  print STDOUT "stop: <input type=text value=$to name=stop size=40 maxlength=40> <br>\n";
-  print STDOUT "<input type=hidden name=config value=\"$key\">\n";
-  print STDOUT "<input type=\"submit\" value=\"submit\"><input type=\"reset\" value=\"reset\">\n";
-  print STDOUT "</form>\n";
-  print STDOUT "</body>\n";
-  
-  &goodbye;;
-  
-}
-
-############## html modify ###############
-sub mk_htmlmod {
-    if (@ARGV != 1) { &escape ("USAGE: mkdetrend htmlmod"); }
-    
-    $key = $ENV{'WWW_config'};
-    $Nimage = $ENV{'WWW_Nimage'};
+    if (@ARGV != 2) { &escape ("USAGE: $MKDETREND htmldef (config.ver)"); }
+    
+    $key = $ARGV[1];
+    
+    # find (config.ver) in list:
     
     @list = load_config ();
@@ -991,10 +972,73 @@
     if ($match == -1) { &escape ("error: can't find config entry"); }
     
+    # show the complete list for reference
+    print STDOUT "<HEADER> <TITLE>Elixir Mkdetrend Report</TITLE> </HEADER>\n";
+    print STDOUT "<BODY BGCOLOR=#fff0e0 TEXT=#000000 LINK=#0000ff VLINK=#6600ff ALINK=#a0a0a0>\n";
+    print STDOUT "<table border>\n";
+    for ($i = 0; $i < @list; $i++) {
+	$config  = gtconfig ($list[$i], "config");
+	$version = gtconfig ($list[$i], "version");
+	$status  = gtconfig ($list[$i], "status");
+	$from    = gtconfig ($list[$i], "from");
+	$to      = gtconfig ($list[$i], "to");
+	print STDOUT "<tr><td> $version </td>\n";
+	print STDOUT "<td> $from </td><td> $to </td>\n";
+	print STDOUT "<td> <a href=$CGI/elixir2?$version&elconf=$elconf> $status </a></td>\n";
+	print STDOUT "<td> <a href=$CGI/split?$config&elconf=$elconf>      split </a></td>\n";
+	print STDOUT "<td> <a href=$CGI/delete?$version&elconf=$elconf>   delete </a></td>\n";
+	print STDOUT "<td> <a href=$CGI/redef?$version&elconf=$elconf>  redefine </a></td>\n";
+	print STDOUT "</tr>\n";
+    }
+    print STDOUT "</table></body><br><br>\n";
+    
+    $version = gtconfig ($list[$match], "version");
+    $status  = gtconfig ($list[$match], "status");
+    $from    = gtconfig ($list[$match], "from");
+    $to      = gtconfig ($list[$match], "to");
+    print STDOUT "redefining <b> $key: </b> <br>\n";    
+    print STDOUT "<table border>\n";
+    print STDOUT "<tr><td> $version </td>\n";
+    print STDOUT "<td> $from </td><td> $to </td><td> $status </a></td>\n";
+    print STDOUT "</tr></table>\n";
+    
+    
+    # create a simple form for redefine:
+    print STDOUT "<form method=post action=$CGI/redefine&elconf=$elconf>\n";
+    print STDOUT "start: <input type=text value=$from name=start size=40 maxlength=40> <br>\n";
+    print STDOUT "stop: <input type=text value=$to name=stop size=40 maxlength=40> <br>\n";
+    print STDOUT "<input type=hidden name=config value=\"$key\">\n";
+    print STDOUT "<input type=\"submit\" value=\"submit\"><input type=\"reset\" value=\"reset\">\n";
+    print STDOUT "</form>\n";
+    print STDOUT "</body>\n";
+    
+    &goodbye;;
+    
+}
+
+############## html modify ###############
+sub mk_htmlmod {
+    if (@ARGV != 1) { &escape ("USAGE: $MKDETREND htmlmod"); }
+    
+    $key = $ENV{'WWW_config'};
+    $Nimage = $ENV{'WWW_Nimage'};
+    
+    @list = load_config ();
+    
+    $match = -1;
+    for ($i = 0; $i < @list; $i++) {
+	$version = gtconfig ($list[$i], "version");
+	if ($key eq $version) {
+	    $match = $i;
+	    last;
+	}
+    }
+    if ($match == -1) { &escape ("error: can't find config entry"); }
+    
     # re-create $master to match selections
     # depends on the format of data in the 'master' file
-    for ($i = 0; $i < $Nccd; $i++) {
+    foreach $ccd (@ccds) {
 
 	# load existing master file
-	$master = mknames ("master", $list[$match], $ccds[$i]); 
+	$master = mknames ("master", $list[$match], $ccd); 
 	open (FILE, $master);
 	@master = <FILE>;
@@ -1002,5 +1046,5 @@
 
 	if ($Nimage != @master) {
-	    print STDOUT "error: mis-match in image lists ccd $i\n";
+	    print STDOUT "error: mis-match in image lists ccd $ccd\n";
 	    &escape;
 	}
@@ -1028,212 +1072,212 @@
 ############## html accept ###############
 sub mk_htmlkeep {
-    if (@ARGV != 2) { &escape ("USAGE: mkdetrend htmlkeep (config.ver)"); }
-  
-  $key = $ARGV[1];
-  @list = load_config ();
-  
-  $match = -1;
-  for ($i = 0; $i < @list; $i++) {
-    $version = gtconfig ($list[$i], "version");
-    if ($key eq $version) {
-      $match = $i;
-      last;
-    }
-  }
-  if ($match == -1) {
-    print STDERR "error: can't find config entry\n";
-    &escape;
-  } 
-  
-  # adjust the config file: convert status to 'accepted'
-  $list[$match] = stconfig ($list[$match], "status", "accepted");
-  save_config (@list);
-  
-  print STDOUT "<meta http-equiv=refresh content=\"0; url=$CGI/elixir1?&elconf=$elconf\">";
-  &goodbye;
+    if (@ARGV != 2) { &escape ("USAGE: $MKDETREND htmlkeep (config.ver)"); }
+    
+    $key = $ARGV[1];
+    @list = load_config ();
+    
+    $match = -1;
+    for ($i = 0; $i < @list; $i++) {
+	$version = gtconfig ($list[$i], "version");
+	if ($key eq $version) {
+	    $match = $i;
+	    last;
+	}
+    }
+    if ($match == -1) {
+	print STDERR "error: can't find config entry\n";
+	&escape;
+    } 
+    
+    # adjust the config file: convert status to 'accepted'
+    $list[$match] = stconfig ($list[$match], "status", "accepted");
+    save_config (@list);
+    
+    print STDOUT "<meta http-equiv=refresh content=\"0; url=$CGI/elixir1?&elconf=$elconf\">";
+    &goodbye;
 }
 
 ############## html config ###############
 sub mk_htmlconfig {
-    if (@ARGV != 1) { &escape ("USAGE: mkdetrend htmlconfig"); }
-  
-  ## html headers
-  print STDOUT "<HEADER> <TITLE>Elixir Mkdetrend Report</TITLE> </HEADER>\n";
-  print STDOUT "<BODY BGCOLOR=#fff0f0 TEXT=#000000 LINK=#0000ff VLINK=#6600ff ALINK=#a0a0a0>\n";
-  
-  # create a simple form for redefine:
-  print STDOUT "<form method=post action=$CGI/newconfig>\n";
-  if ($elconf) {
-      print STDOUT "enter new config: <input type=text value=$elconf name=config size=40 maxlength=40> <br>\n";
-  } else {
-      print STDOUT "enter new config: <input type=text name=config size=40 maxlength=40> <br>\n";
-  }
-  print STDOUT "<input type=\"submit\" value=\"submit\"><input type=\"reset\" value=\"reset\">\n";
-  print STDOUT "</form>\n";
-  print STDOUT "</body>\n";
-  
-  &goodbye;
+    if (@ARGV != 1) { &escape ("USAGE: $MKDETREND htmlconfig"); }
+    
+    ## html headers
+    print STDOUT "<HEADER> <TITLE>Elixir Mkdetrend Report</TITLE> </HEADER>\n";
+    print STDOUT "<BODY BGCOLOR=#fff0f0 TEXT=#000000 LINK=#0000ff VLINK=#6600ff ALINK=#a0a0a0>\n";
+    
+    # create a simple form for redefine:
+    print STDOUT "<form method=post action=$CGI/newconfig>\n";
+    if ($elconf) {
+	print STDOUT "enter new config: <input type=text value=$elconf name=config size=40 maxlength=40> <br>\n";
+    } else {
+	print STDOUT "enter new config: <input type=text name=config size=40 maxlength=40> <br>\n";
+    }
+    print STDOUT "<input type=\"submit\" value=\"submit\"><input type=\"reset\" value=\"reset\">\n";
+    print STDOUT "</form>\n";
+    print STDOUT "</body>\n";
+    
+    &goodbye;
 }
 
 ############## html level 1 ###############
 sub mk_html1 {
-    if (@ARGV != 1) { &escape ("USAGE: mkdetrend html1"); }
-  
-  @list = load_config ();
-  
-  ## html headers
-  print STDOUT "<HEADER> <TITLE>Elixir Mkdetrend Report</TITLE> </HEADER>\n";
-  print STDOUT "<BODY BGCOLOR=#fff0f0 TEXT=#000000 LINK=#0000ff VLINK=#6600ff ALINK=#a0a0a0>\n";
-
-  print STDOUT "<table border>\n";
-  for ($i = 0; $i < @list; $i++) {
-    $config  = gtconfig ($list[$i], "config");
-    $version = gtconfig ($list[$i], "version");
-    $from    = gtconfig ($list[$i], "from");
-    $to      = gtconfig ($list[$i], "to");
-    $status  = gtconfig ($list[$i], "status");
-    print STDOUT "<tr><td> $version </td>\n";
-    print STDOUT "<td> $from </td><td> $to </td>\n";
-    print STDOUT "<td> <a href=$CGI/elixir2?$version&elconf=$elconf> $status </a></td>\n";
-    print STDOUT "<td> <a href=$CGI/split?$config&elconf=$elconf> split </a></td>\n";
-    print STDOUT "<td> <a href=$CGI/delete?$version&elconf=$elconf> delete </a></td>\n";
-    print STDOUT "<td> <a href=$CGI/redef?$version&elconf=$elconf> redefine </a></td>\n";
-    print STDOUT "</tr>\n";
-  }
-  
-  print STDOUT "</table><br><br>\n";
-  if ($elconf eq "") {
-      print STDOUT "Current Config: <b>default</b><br>\n";
-  } else {
-      print STDOUT "Current Config: <b>$elconf</b><br>\n";
-  }
-  print STDOUT "<a href=$CGI/config?&elconf=$elconf>Change Config</a></td>\n";
-  print STDOUT "</body>\n";
-  &goodbye;;
+    if (@ARGV != 1) { &escape ("USAGE: $MKDETREND html1"); }
+    
+    @list = load_config ();
+    
+    ## html headers
+    print STDOUT "<HEADER> <TITLE>Elixir Mkdetrend Report</TITLE> </HEADER>\n";
+    print STDOUT "<BODY BGCOLOR=#fff0f0 TEXT=#000000 LINK=#0000ff VLINK=#6600ff ALINK=#a0a0a0>\n";
+
+    print STDOUT "<table border>\n";
+    for ($i = 0; $i < @list; $i++) {
+	$config  = gtconfig ($list[$i], "config");
+	$version = gtconfig ($list[$i], "version");
+	$from    = gtconfig ($list[$i], "from");
+	$to      = gtconfig ($list[$i], "to");
+	$status  = gtconfig ($list[$i], "status");
+	print STDOUT "<tr><td> $version </td>\n";
+	print STDOUT "<td> $from </td><td> $to </td>\n";
+	print STDOUT "<td> <a href=$CGI/elixir2?$version&elconf=$elconf> $status </a></td>\n";
+	print STDOUT "<td> <a href=$CGI/split?$config&elconf=$elconf> split </a></td>\n";
+	print STDOUT "<td> <a href=$CGI/delete?$version&elconf=$elconf> delete </a></td>\n";
+	print STDOUT "<td> <a href=$CGI/redef?$version&elconf=$elconf> redefine </a></td>\n";
+	print STDOUT "</tr>\n";
+    }
+    
+    print STDOUT "</table><br><br>\n";
+    if ($elconf eq "") {
+	print STDOUT "Current Config: <b>default</b><br>\n";
+    } else {
+	print STDOUT "Current Config: <b>$elconf</b><br>\n";
+    }
+    print STDOUT "<a href=$CGI/config?&elconf=$elconf>Change Config</a></td>\n";
+    print STDOUT "</body>\n";
+    &goodbye;;
 }
 
 ############## html level 2 ###############
 sub mk_html2 {
-    if (@ARGV != 2) { &escape ("USAGE: mkdetrend html2 (config.ver)"); }
-  
-  @list = load_config ();
-  
-  # entry on line will be either config.ver (== key) or config.ver.col for sorting
-  # grab just the key portion
-  $status = "none";
-  ($key) = $ARGV[1] =~ /(\w+.\w+.\w+.\w+)/; # (config.ver)
-  $arg = $ARGV[1];
-  
-  # find appropriate config.ver entry:
-  for ($i = 0; $i < @list; $i++) {
-    $version = gtconfig ($list[$i], "version");
-    if ($key eq $version) {
-      $confline = $list[$i];
-      $status = gtconfig ($confline, "status");
-      last;
-    }
-  }
-  
-  $from = gtconfig ($confline, "from");
-  $to   = gtconfig ($confline, "to");
-  print STDOUT "<HEADER> <TITLE>Elixir Mkdetrend Report</TITLE> </HEADER>\n";
-  print STDOUT "<BODY BGCOLOR=#fff0f0 TEXT=#000000 LINK=#0000ff VLINK=#6600ff ALINK=#a0a0a0>\n";
-  print STDOUT "<center><table border>\n";
-  print STDOUT "<tr><th>config   </th><th> from  </th><th> to </th></tr>\n";
-  print STDOUT "<tr><td>$version </td><td> $from </td><td> $to</td></tr>\n";
-  print STDOUT "</table></center><hr>\n";
-  
-  $master = mknames ("master", $confline, $ccds[0]);
-  
-  if ($status eq "modified")   { flips_report ($arg, $confline, "modified"); }
-  if ($status eq "accepted")   { flips_report ($arg, $confline, "accepted"); }
-  if ($status eq "done.merge") { flips_report ($arg, $confline, "merged"); }
-  # if ($status eq "done.update") { flips_report ($arg, $confline, "updated"); }
-  if ($status eq "done.reg")   { flips_report_done ($key, $confline, "registered"); }
-  if ($status eq "clean")      { flips_report ($key, $confline, "registered"); }
-  
-  if ($status eq "none")              { $message = "not found"; }
-  if ($status eq "init")              { $message = "initialized, not yet run."; }
-  if ($status eq "not.available")     { $message = "has no images available for detrend creation."; }
-  
-  foreach $step (init, flips, norm, merge) {
-    if ($status eq "running.$step") { $message = "running step $step"; }
-    if ($status eq "fail.$step")    { $message = "failed step $step"; }
-    if ($status eq "done.$step") { $message = "has finished $step"; }
-  }      
-
-  print STDOUT "config <b> $key </b> $message <br>\n";
-  
-  print STDOUT "<table border>\n";
-  open (FILE, "$master");
-  while ($line = <FILE>) {
-    chop ($line);
-    @entry = split ("/", $line);
-    $N = @entry - 1;
-    print STDOUT "<tr><td>$entry[$N]</td></tr>\n";
-  }
-  print STDOUT "</table>\n";
-  
-  print STDOUT "</body>\n";
-  &goodbye;
-}
-
-############## html level 3 ###############
-sub mk_html3 {
-    if (@ARGV != 2) { &escape ("USAGE: mkdetrend html3 (entry.config.ver)"); }
-  
-  @list = load_config ();
-  
-  # extract the entry and key values from $ARGV[1]
-  ($entry, $key) = $ARGV[1] =~ /(\d+)\Q.\E(.*)/;
-  
-  $status = "none";
-  # find appropriate config.ver entry:
-  for ($i = 0; $i < @list; $i++) {
-    $version = gtconfig ($list[$i], "version");
-    if ($key eq $version) {
-      $confline = $list[$i];
-      $status = gtconfig ($confline, "status");
-      last;
-    }
-  }
-  
-  print STDOUT "<HEADER> <TITLE>Elixir Mkdetrend Report</TITLE> </HEADER>\n";
-  print STDOUT "<BODY BGCOLOR=#fff0f0 TEXT=#000000 LINK=#0000ff VLINK=#6600ff ALINK=#a0a0a0>\n";
-  
-  if ($status eq "none")              { print STDOUT "config <b> $key </b> not found\n </body>\n"; &goodbye; }
-  if ($status eq "init")              { print STDOUT "config <b> $key </b> initialized, not yet run\n </body>\n"; &goodbye; }
-  if ($status eq "not.available")     { print STDOUT "config <b> $key </b> has no images available for detrend creation\n </body>\n"; &goodbye; }
-  
-  # if ($status eq "done.update") { flips_entry ($key, $entry, $confline); }
-  if ($status eq "done.merge") { flips_entry ($key, $entry, $confline); }
-  if ($status eq "accepted")   { flips_entry ($key, $entry, $confline); }
-  if ($status eq "modified")   { flips_entry ($key, $entry, $confline); }
-  if ($status eq "done.reg")   { flips_entry ($key, $entry, $confline); }
-  
-  foreach $step (init, flips, norm, merge) {
-    # print "step: $step, $status: $status\n";
-    if ($status eq "running.$step") { print STDOUT "config <b> $key </b> running step $step \n </body>\n"; &goodbye; }
-    if ($status eq "fail.$step")    { print STDOUT "config <b> $key </b> failed step $step\n </body>\n"; &goodbye; }
-    
-    if ($status eq "done.$step") {
-      print STDOUT "config <b> $key </b> has finished $step\n";
-      
-      # load image names from CCD 0 list:
-      $master = mknames ("master", $confline, $ccds[0]);
-      print STDOUT "<table border>\n";
-      open (FILE, "$master");
-      while ($line = <FILE>) {
+    if (@ARGV != 2) { &escape ("USAGE: $MKDETREND html2 (config.ver)"); }
+    
+    @list = load_config ();
+    
+    # entry on line will be either config.ver (== key) or config.ver.col for sorting
+    # grab just the key portion
+    $status = "none";
+    ($key) = $ARGV[1] =~ /(\w+.\w+.\w+.\w+)/; # (config.ver)
+    $arg = $ARGV[1];
+    
+    # find appropriate config.ver entry:
+    for ($i = 0; $i < @list; $i++) {
+	$version = gtconfig ($list[$i], "version");
+	if ($key eq $version) {
+	    $confline = $list[$i];
+	    $status = gtconfig ($confline, "status");
+	    last;
+	}
+    }
+    
+    $from = gtconfig ($confline, "from");
+    $to   = gtconfig ($confline, "to");
+    print STDOUT "<HEADER> <TITLE>Elixir Mkdetrend Report</TITLE> </HEADER>\n";
+    print STDOUT "<BODY BGCOLOR=#fff0f0 TEXT=#000000 LINK=#0000ff VLINK=#6600ff ALINK=#a0a0a0>\n";
+    print STDOUT "<center><table border>\n";
+    print STDOUT "<tr><th>config   </th><th> from  </th><th> to </th></tr>\n";
+    print STDOUT "<tr><td>$version </td><td> $from </td><td> $to</td></tr>\n";
+    print STDOUT "</table></center><hr>\n";
+    
+    $master = mknames ("master", $confline, $ccds[0]);
+    
+    if ($status eq "modified")   { flips_report ($arg, $confline,      "modified"); }
+    if ($status eq "accepted")   { flips_report ($arg, $confline,      "accepted"); }
+    if ($status eq "done.merge") { flips_report ($arg, $confline,      "merged"); }
+    if ($status eq "done.reg")   { flips_report_done ($key, $confline, "registered"); }
+    if ($status eq "done")       { flips_report_done ($key, $confline, "registered"); }
+    if ($status eq "clean")      { flips_report ($key, $confline,      "registered"); }
+    
+    if ($status eq "none")              { $message = "not found"; }
+    if ($status eq "init")              { $message = "initialized, not yet run."; }
+    if ($status eq "not.available")     { $message = "has no images available for detrend creation."; }
+    
+    foreach $step (init, flips, norm, merge) {
+	if ($status eq "running.$step") { $message = "running step $step"; }
+	if ($status eq "fail.$step")    { $message = "failed step $step"; }
+	if ($status eq "done.$step") { $message = "has finished $step"; }
+    }      
+
+    print STDOUT "config <b> $key </b> $message <br>\n";
+    
+    print STDOUT "<table border>\n";
+    open (FILE, "$master");
+    while ($line = <FILE>) {
 	chop ($line);
 	@entry = split ("/", $line);
 	$N = @entry - 1;
 	print STDOUT "<tr><td>$entry[$N]</td></tr>\n";
-      }
-      print STDOUT "</table>\n";
-    }
-  }
-  
-  # print STDOUT "</body>\n";
-  &goodbye;
+    }
+    print STDOUT "</table>\n";
+    
+    print STDOUT "</body>\n";
+    &goodbye;
+}
+
+############## html level 3 ###############
+sub mk_html3 {
+    if (@ARGV != 2) { &escape ("USAGE: $MKDETREND html3 (entry.config.ver)"); }
+    
+    @list = load_config ();
+    
+    # extract the entry and key values from $ARGV[1]
+    ($entry, $key) = $ARGV[1] =~ /(\d+)\Q.\E(.*)/;
+    
+    $status = "none";
+    # find appropriate config.ver entry:
+    for ($i = 0; $i < @list; $i++) {
+	$version = gtconfig ($list[$i], "version");
+	if ($key eq $version) {
+	    $confline = $list[$i];
+	    $status = gtconfig ($confline, "status");
+	    last;
+	}
+    }
+    
+    print STDOUT "<HEADER> <TITLE>Elixir Mkdetrend Report</TITLE> </HEADER>\n";
+    print STDOUT "<BODY BGCOLOR=#fff0f0 TEXT=#000000 LINK=#0000ff VLINK=#6600ff ALINK=#a0a0a0>\n";
+    
+    if ($status eq "none")              { print STDOUT "config <b> $key </b> not found\n </body>\n"; &goodbye; }
+    if ($status eq "init")              { print STDOUT "config <b> $key </b> initialized, not yet run\n </body>\n"; &goodbye; }
+    if ($status eq "not.available")     { print STDOUT "config <b> $key </b> has no images available for detrend creation\n </body>\n"; &goodbye; }
+    
+    # if ($status eq "done.update") { flips_entry ($key, $entry, $confline); }
+    if ($status eq "done.merge") { flips_entry ($key, $entry, $confline); }
+    if ($status eq "accepted")   { flips_entry ($key, $entry, $confline); }
+    if ($status eq "modified")   { flips_entry ($key, $entry, $confline); }
+    if ($status eq "done.reg")   { flips_entry ($key, $entry, $confline); }
+    
+    foreach $step (init, flips, norm, merge) {
+	# print "step: $step, $status: $status\n";
+	if ($status eq "running.$step") { print STDOUT "config <b> $key </b> running step $step \n </body>\n"; &goodbye; }
+	if ($status eq "fail.$step")    { print STDOUT "config <b> $key </b> failed step $step\n </body>\n"; &goodbye; }
+	
+	if ($status eq "done.$step") {
+	    print STDOUT "config <b> $key </b> has finished $step\n";
+	    
+	    # load image names from CCD 0 list:
+	    $master = mknames ("master", $confline, $ccds[0]);
+	    print STDOUT "<table border>\n";
+	    open (FILE, "$master");
+	    while ($line = <FILE>) {
+		chop ($line);
+		@entry = split ("/", $line);
+		$N = @entry - 1;
+		print STDOUT "<tr><td>$entry[$N]</td></tr>\n";
+	    }
+	    print STDOUT "</table>\n";
+	}
+    }
+    
+    # print STDOUT "</body>\n";
+    &goodbye;
 }
 
@@ -1242,137 +1286,137 @@
 ############## evaluate chip run ###############
 sub mk_eval {
-    if (@ARGV != 2) { &escape ("USAGE: mkdetrend eval (step)"); }
-  
-  $step = $ARGV[1];
-  @list = load_config ();
-  
-  # load success fifo info:
-  $file = `gconfig -D mode mkdetrend global.success`; chop $file;
-  open (FILE, "$file");
-  @success = <FILE>;
-  close (FILE);
-  
-  # load failure fifo info:
-  $file = `gconfig -D mode mkdetrend global.failure`; chop $file;
-  open (FILE, "$file");
-  @failure = <FILE>;
-  close (FILE);
-  
-  # entry must be in state 'running.$step'
-  # possible states:
-  #   1 all 12 chips in success          == done.$step
-  #   2 any chips in failure             == fail.$step
-  #   3 any chips missing                == fail.$step
-  #   4 any chips in failure, merge.list == not.available (only for $step eq init)
-  # valid steps: init flips norm
-  
- CONFIG:
-  foreach $confline (@list) {
-      $status = gtconfig ($confline, "status");
-      if ($status ne "running.$step") { next; }
-      $state = 1;
-
-    CCD:
-      for ($j = 0; $j < $Nccd; $j++) {
-	$entry = gtconfig ($confline, "chiprun", $j);
-
-	# search for entry in success fifo:
-	foreach $value (@success) {
-	  if ($value =~ /^$entry/) { next CCD; }
-	}
-	
-	# search for entry in failure fifo: note the special ending state for 'init'
-	foreach $value (@failure) {
-	  if ($value =~ /^$entry/) {
-	    $state = 2;
-	    if ($step eq "split") {
-	      ($status) = $value =~ /$entry\s+\S+\s+(\S+)/;
-	      if ($status eq "merge.lists") {
-		$state = 4;
-	      }
+    if (@ARGV != 2) { &escape ("USAGE: $MKDETREND eval (step)"); }
+    
+    $step = $ARGV[1];
+    @list = load_config ();
+    
+    # load success fifo info:
+    $file = `gconfig -D mode $MKDETREND global.success`; chop $file;
+    open (FILE, "$file");
+    @success = <FILE>;
+    close (FILE);
+    
+    # load failure fifo info:
+    $file = `gconfig -D mode $MKDETREND global.failure`; chop $file;
+    open (FILE, "$file");
+    @failure = <FILE>;
+    close (FILE);
+    
+    # entry must be in state 'running.$step'
+    # possible states:
+    #   1 all 12 chips in success          == done.$step
+    #   2 any chips in failure             == fail.$step
+    #   3 any chips missing                == fail.$step
+    #   4 any chips in failure, merge.list == not.available (only for $step eq init)
+    # valid steps: init flips norm
+    
+  CONFIG:
+    foreach $confline (@list) {
+	$status = gtconfig ($confline, "status");
+	if ($status ne "running.$step") { next; }
+	$state = 1;
+
+      CCD:
+	foreach $ccd (@ccds) {
+	    $entry = gtconfig ($confline, "chiprun", $ccd);
+
+	    # search for entry in success fifo:
+	    foreach $value (@success) {
+		if ($value =~ /^$entry/) { next CCD; }
 	    }
+	    
+	    # search for entry in failure fifo: note the special ending state for 'init'
+	    foreach $value (@failure) {
+		if ($value =~ /^$entry/) {
+		    $state = 2;
+		    if ($step eq "split") {
+			($status) = $value =~ /$entry\s+\S+\s+(\S+)/;
+			if ($status eq "merge.lists") {
+			    $state = 4;
+			}
+		    }
+		    last CCD;
+		}
+	    }
+	    
+	    # if we make it here, it wasn't in either fifo.success or fifo.failure...
+	    $state = 3;
 	    last CCD;
-	  }
-	}
-	
-	# if we make it here, it wasn't in either fifo.success or fifo.failure...
-	$state = 3;
-	last CCD;
-      }
-      
-      if ($state == 1) { $confline = stconfig ($confline, "status", "done.$step"); } 
-      if ($state == 2) { $confline = stconfig ($confline, "status", "fail.$step"); }
-      if ($state == 3) { $confline = stconfig ($confline, "status", "fail.$step"); } 
-      if ($state == 4) { $confline = stconfig ($confline, "status", "not.available"); }
-  }
-  save_config (@list);
-
-  system ("mkdetrend state");
-  &goodbye;
+	}
+	
+	if ($state == 1) { $confline = stconfig ($confline, "status", "done.$step"); } 
+	if ($state == 2) { $confline = stconfig ($confline, "status", "fail.$step"); }
+	if ($state == 3) { $confline = stconfig ($confline, "status", "fail.$step"); } 
+	if ($state == 4) { $confline = stconfig ($confline, "status", "not.available"); }
+    }
+    save_config (@list);
+
+    system ("$MKDETREND state");
+    &goodbye;
 }
 
 ############## evaluate mosaic run ###############
 sub mk_meval {
-    if (@ARGV != 2) { &escape ("USAGE: mkdetrend meval (step)"); }
-  
-  $step = $ARGV[1];
-  @list = load_config ();
-  
-  # load success fifo info:
-  $file = `gconfig -D mode mkdetrend global.success`; chop $file;
-  open (FILE, "$file");
-  @success = <FILE>;
-  close (FILE);
-  
-  # load failure fifo info:
-  $file = `gconfig -D mode mkdetrend global.failure`; chop $file;
-  open (FILE, "$file");
-  @failure = <FILE>;
-  close (FILE);
-  
-  # entry must be in state 'running.$step'
-  # possible states:
-  #   1 entry in success          == done.$step
-  #   2 entry in failure          == fail.$step
-  #   3 entry missing             == fail.$step
-  # valid steps: merge
-  
-  foreach $confline (@list) {
-      $status = gtconfig ($confline, "status");
-      if ($status ne "running.$step") { next; }
-      $state = 3;
-      $entry = gtconfig ($confline, "mosaic");
-
-    MCHECK: 
-      {
-	  foreach $value (@success) {
-	      if ($value =~ /^$entry/) { 
-		  $state = 1;
-		  last MCHECK;
-	      }
-	  }
-	  
-	  foreach $value (@failure) {
-	      if ($value =~ /^$entry/) { 
-		  $state = 2;
-		  next MCHECK;
+    if (@ARGV != 2) { &escape ("USAGE: $MKDETREND meval (step)"); }
+    
+    $step = $ARGV[1];
+    @list = load_config ();
+    
+    # load success fifo info:
+    $file = `gconfig -D mode $MKDETREND global.success`; chop $file;
+    open (FILE, "$file");
+    @success = <FILE>;
+    close (FILE);
+    
+    # load failure fifo info:
+    $file = `gconfig -D mode $MKDETREND global.failure`; chop $file;
+    open (FILE, "$file");
+    @failure = <FILE>;
+    close (FILE);
+    
+    # entry must be in state 'running.$step'
+    # possible states:
+    #   1 entry in success          == done.$step
+    #   2 entry in failure          == fail.$step
+    #   3 entry missing             == fail.$step
+    # valid steps: merge
+    
+    foreach $confline (@list) {
+	$status = gtconfig ($confline, "status");
+	if ($status ne "running.$step") { next; }
+	$state = 3;
+	$entry = gtconfig ($confline, "mosaic");
+
+      MCHECK: 
+	{
+	    foreach $value (@success) {
+		if ($value =~ /^$entry/) { 
+		    $state = 1;
+		    last MCHECK;
+		}
 	    }
-	  }
-      }
-      
-      if ($state == 1) { $confline = stconfig ($confline, "status", "done.$step"); } 
-      if ($state == 2) { $confline = stconfig ($confline, "status", "fail.$step"); }
-      if ($state == 3) { $confline = stconfig ($confline, "status", "fail.$step"); }
-  }
-  
-  save_config (@list);
-  system ("mkdetrend state");
-  
-  &goodbye;
+	    
+	    foreach $value (@failure) {
+		if ($value =~ /^$entry/) { 
+		    $state = 2;
+		    next MCHECK;
+		}
+	    }
+	}
+	
+	if ($state == 1) { $confline = stconfig ($confline, "status", "done.$step"); } 
+	if ($state == 2) { $confline = stconfig ($confline, "status", "fail.$step"); }
+	if ($state == 3) { $confline = stconfig ($confline, "status", "fail.$step"); }
+    }
+    
+    save_config (@list);
+    system ("$MKDETREND state");
+    
+    &goodbye;
 }
 
 ############## html for dads ###############
 sub mk_dads {
-    if (@ARGV != 2) { &escape ("USAGE: mkdetrend dads (config.ver)"); }
+    if (@ARGV != 2) { &escape ("USAGE: $MKDETREND dads (config.ver)"); }
     
     # options: mkdetrend dads (config.ver)
@@ -1452,5 +1496,5 @@
 ############## html for dads ###############
 sub mk_dads_html {
-    if (@ARGV != 2) { &escape ("USAGE: mkdetrend dads (config.ver)"); }
+    if (@ARGV != 2) { &escape ("USAGE: $MKDETREND dads (config.ver)"); }
     
     @list = load_config ();
@@ -1511,5 +1555,5 @@
     print STDOUT "Total Counts: $Ncnt<br> r.m.s. median sigma: $Sigma% <br><br>\n";
     print STDOUT "</td><td align=right><img src=$imbin></td></tr></table>\n";
-        
+    
     print STDOUT "<center><b>Statistics on each available input image.</b></center>
   Time is in UT, light background means dawn, grey means dusk.\n";
@@ -1567,186 +1611,350 @@
 ############## dads level 1 ###############
 sub mk_dads_top {
-    if (@ARGV != 1) { &escape ("USAGE: mkdetrend dads.top"); }
-  
-  @list = load_config ();
-  
-  ## html headers
-  print STDOUT "<HEADER> <TITLE>Elixir Mkdetrend Report</TITLE> </HEADER>\n";
-  print STDOUT "<BODY BGCOLOR=#fff0f0 TEXT=#000000 LINK=#0000ff VLINK=#6600ff ALINK=#a0a0a0>\n";
-
-  print STDOUT "<table border>\n";
-  for ($i = 0; $i < @list; $i++) {
-    $config  = gtconfig ($list[$i], "config");
-    $version = gtconfig ($list[$i], "version");
-    $from    = gtconfig ($list[$i], "from");
-    $to      = gtconfig ($list[$i], "to");
-    $status  = gtconfig ($list[$i], "status");
-    print STDOUT "<tr><td> $version </td>\n";
-    print STDOUT "<td> $from </td><td> $to </td>\n";
-    print STDOUT "<td> <a href=$version.html> $status </a></td>\n";
-    print STDOUT "</tr>\n";
-  }
-  
-  print STDOUT "</table></body>\n";
-  &goodbye;;
-  
+    if (@ARGV != 1) { &escape ("USAGE: $MKDETREND dads.top"); }
+    
+    @list = load_config ();
+    
+    ## html headers
+    print STDOUT "<HEADER> <TITLE>Elixir Mkdetrend Report</TITLE> </HEADER>\n";
+    print STDOUT "<BODY BGCOLOR=#fff0f0 TEXT=#000000 LINK=#0000ff VLINK=#6600ff ALINK=#a0a0a0>\n";
+
+    print STDOUT "<table border>\n";
+    for ($i = 0; $i < @list; $i++) {
+	$config  = gtconfig ($list[$i], "config");
+	$version = gtconfig ($list[$i], "version");
+	$from    = gtconfig ($list[$i], "from");
+	$to      = gtconfig ($list[$i], "to");
+	$status  = gtconfig ($list[$i], "status");
+	print STDOUT "<tr><td> $version </td>\n";
+	print STDOUT "<td> $from </td><td> $to </td>\n";
+	print STDOUT "<td> <a href=$version.html> $status </a></td>\n";
+	print STDOUT "</tr>\n";
+    }
+    
+    print STDOUT "</table></body>\n";
+    &goodbye;;
+    
 }
 
 sub by_col { 
-  @word = split (" ", $statdata[$a]); $va = $word[$col]; 
-  @word = split (" ", $statdata[$b]); $vb = $word[$col]; 
-  $va <=> $vb;
+    @word = split (" ", $statdata[$a]); $va = $word[$col]; 
+    @word = split (" ", $statdata[$b]); $vb = $word[$col]; 
+    $va <=> $vb;
 }
 
 sub flips_report {
-  
-  $col = 0;
-  ($config) = $_[0] =~ /(\w+.\w+.\w+)/;
-  ($key)    = $_[0] =~ /(\w+.\w+.\w+.\w+)/; # (config.ver)
-
-  # look for optional sort key (config.ver[.key])
-  if ($_[0] =~ /$key.(\d+)/) {
-      ($col) = $_[0] =~ /$key.(\d+)/; 
-  } else {
-      $col = 0;
-  }
-
-  $line = $_[1];
-  $message = $_[2];
-  
-  open (FILE, mknames ("stats",  $line));            @statdata = <FILE>; close (FILE);
-  open (FILE, mknames ("medbin", $line));            @medndata = <FILE>; close (FILE);
-  open (FILE, mknames ("master", $line, $ccds[0]));  @mastdata = <FILE>; close (FILE);
-
-  $Nkeep = 0;
-  $Ncnt = 0;
-  $Sigma = 0;
-  $Nimage = @statdata;
-  for ($i = 0; $i < $Nimage; $i++) {
-    @tmpw = split (" ", $mastdata[$i]);
-    @tmps = split (" ", $statdata[$i]);
-    if ($tmpw[1]) { $Nkeep++; $Ncnt += $tmps[3]; $Sigma += $tmps[8]*$tmps[8]; }
-  }
-  if ($Nkeep > 0) {
-      $Sigma = sprintf "%5.3f", 100*sqrt ($Sigma/$Nkeep);
-  } else {
-      $Sigma = 100.0;
-  }
-
-  $imbin = mknames ("imbin",  $line);
-  print STDOUT "<table><tr><td width=300px valign=top>\n";
-  print STDOUT "<b>this config has been $message. </b><br>\n";
-  print STDOUT "there are $Nimage images, $Nkeep used. <br>\n";
-  print STDOUT "Total Counts: $Ncnt<br> r.m.s. median sigma: $Sigma% <br><br>\n";
-  print STDOUT "you have the following choices: <br>\n";
-  print STDOUT "<a href=$CGI/elixir1?&elconf=$elconf> <b> return to top level </b><br></a>\n";
-  print STDOUT "<a href=$CGI/split?$config&elconf=$elconf> <b> split config </b><br></a>\n";
-  print STDOUT "<a href=$CGI/accept?$key&elconf=$elconf> <b> accept config </b><br></a>\n";
-  print STDOUT "</td><td width=640px align=right><img width=100% src=$imbin></td></tr></table>\n";
-  
-  print STDOUT "<form method=post action=$CGI/modify?&elconf=$elconf>\n";
-
-  print STDOUT "<center><b>Statistics on each available input image.</b></center>
+    
+    $col = 0;
+    ($type)   = $_[0] =~ /\w+.(\w+).\w+/;
+    ($config) = $_[0] =~ /(\w+.\w+.\w+)/;
+    ($key)    = $_[0] =~ /(\w+.\w+.\w+.\w+)/; # (config.ver)
+
+    # look for optional sort key (config.ver[.key])
+    if ($_[0] =~ /$key.(\d+)/) {
+	($col) = $_[0] =~ /$key.(\d+)/; 
+    } else {
+	$col = 0;
+    }
+
+    $line = $_[1];
+    $message = $_[2];
+    
+    open (FILE, mknames ("stats",  $line));            @statdata = <FILE>; close (FILE);
+    open (FILE, mknames ("medbin", $line));            @medndata = <FILE>; close (FILE);
+    open (FILE, mknames ("master", $line, $ccds[0]));  @mastdata = <FILE>; close (FILE);
+
+    $Nkeep = 0;
+    $Ncnt = 0;
+    $Sigma = 0;
+    $Nimage = @statdata;
+    for ($i = 0; $i < $Nimage; $i++) {
+	@tmpw = split (" ", $mastdata[$i]);
+	@tmps = split (" ", $statdata[$i]);
+	if ($tmpw[1]) { $Nkeep++; $Ncnt += $tmps[3]; $Sigma += $tmps[8]*$tmps[8]; }
+    }
+    if ($Nkeep > 0) {
+	if ($type eq "flat") { 
+	    $Sigma = sprintf "%5.3f", 100*sqrt ($Sigma/$Nkeep);
+	    $statline = "Total Counts: $Ncnt<br> r.m.s. median sigma: $Sigma% <br><br>\n";
+	} else {
+	    $Sigma = sprintf "%5.3f", sqrt ($Sigma/$Nkeep);
+	    $Ncnt  = sprintf "%5.3f", ($Ncnt / $Nkeep);
+	    $statline = "Mean Counts: $Ncnt<br> r.m.s. median sigma: $Sigma <br><br>\n";
+	}
+    } else {
+	$statline = "";
+    }
+
+    $imbin = mknames ("imbin",  $line);
+    print STDOUT "<table><tr><td width=300px valign=top>\n";
+    print STDOUT "<b>this config has been $message. </b><br>\n";
+    print STDOUT "there are $Nimage images, $Nkeep used. <br>\n";
+    print STDOUT "$statline\n";
+    print STDOUT "you have the following choices: <br>\n";
+    print STDOUT "<a href=$CGI/elixir1?&elconf=$elconf> <b> return to top level </b><br></a>\n";
+    print STDOUT "<a href=$CGI/split?$config&elconf=$elconf> <b> split config </b><br></a>\n";
+    print STDOUT "<a href=$CGI/accept?$key&elconf=$elconf> <b> accept config </b><br></a>\n";
+    print STDOUT "</td><td width=640px align=right><img width=100% src=$imbin></td></tr></table>\n";
+    
+    print STDOUT "<form method=post action=$CGI/modify?&elconf=$elconf>\n";
+
+    print STDOUT "<center><b>Statistics on each available input image.</b></center>
   Time is in UT, light background means dawn, grey means dusk. Click
   on the column heading to sort by that entry\n";
 
-  print STDOUT "<table bgcolor=#fff0e0 border=1 cellspacing=0 cellpadding=3>\n";
-  print STDOUT "<tr bgcolor=#00aaaa>\n";
-  print STDOUT "<th > <a href=$CGI/elixir2?$key.0&elconf=$elconf> image </a></th>\n";
-  print STDOUT "<th > Date </th>\n";
-  print STDOUT "<th > Time </th>\n";
-  print STDOUT "<th > <a href=$CGI/elixir2?$key.3&elconf=$elconf> Mean </a></th>\n";
-  print STDOUT "<th > <a href=$CGI/elixir2?$key.5&elconf=$elconf> Sigma (raw) </a></th>\n";
-  print STDOUT "<th > <a href=$CGI/elixir2?$key.6&elconf=$elconf> Sigma (clipped) </a></th>\n";
-  print STDOUT "<th > <a href=$CGI/elixir2?$key.8&elconf=$elconf> Sigma (med) </a></th>\n";
-  print STDOUT "<th > image </th>\n";
-  print STDOUT "<th > used? </th>\n";
-  print STDOUT "<th > keep? </th></tr>\n\n";
-  
-  @order = ();
-  for ($i = 0; $i < $Nimage; $i++) { @order = (@order, $i); }
-  
-  @entry = sort by_col @order;
-  
-  for ($i = 0; $i < $Nimage; $i++) {
-    $N = $entry[$i];
-    
-    @word = split (" ", $statdata[$N]);
-    $used = $word[12];
-    $dawn = $word[11];
-    
-    @tmpw = split (" ", $mastdata[$N]);
-    $keep = $tmpw[1];
-    
-    @tmpw = split ("/", $medndata[$N]);
-    $medname = $tmpw[-1];
-    
-    # $sig1 = sprintf "%5.3f", $word[4];
-    # $sig2 = sprintf "%5.3f", $word[5];
-    # $sig3 = sprintf "%5.3f", $word[6];
-    # $sig4 = sprintf "%5.3f", $word[7];
-    # $mean = sprintf "%8.1f", $word[3];
-    
-    print STDOUT "<tr><td> <a href=$CGI/elixir3?$N.$key&elconf=$elconf> $word[0] </a></td><td> $word[1] </td>\n";
-    if ($dawn) { print STDOUT "<td bgcolor=#cccccc> $word[2] </td>\n"; }
-    else       { print STDOUT "<td> $word[2] </td>\n"; }
-    print STDOUT "<td> $word[3] </td>\n";
-    print STDOUT "<td> $word[5] </td><td> $word[6] </td><td> $word[8] </td>\n";
-    print STDOUT "<td> <a border=0 href=$CGI/elixir3?$N.$key&elconf=$elconf>\n";
-    print STDOUT "<img src=$www/$medname></a></td>\n";
-    if ($used) { print STDOUT "<td>yes</td>\n"; }
-    else       { print STDOUT "<td>no</td>\n"; }
-    if ($keep) { print STDOUT "<td bgcolor=#00c000><input type=checkbox checked name=image.$N value=$N size=1></td></tr>\n\n"; }
-    else       { print STDOUT "<td bgcolor=#d00000><input type=checkbox         name=image.$N value=$N size=1></td></tr>\n\n"; }	
-    
-  }
-  
-  print STDOUT "</table>\n";
-  print STDOUT "<input type=hidden    name=Nimage value=\"$Nimage\">\n";
-  print STDOUT "<input type=hidden    name=config value=\"$key\">\n";
-  print STDOUT "<input type=submit    value=\"apply changes\">\n";
-  print STDOUT "<input type=reset     value=Reset>\n";
-  # print STDOUT "<select name=status   size=1> \n";
-  print STDOUT "</form></body>\n";
-  &goodbye;
-  
+    print STDOUT "<table bgcolor=#fff0e0 border=1 cellspacing=0 cellpadding=3>\n";
+    print STDOUT "<tr bgcolor=#00aaaa>\n";
+    print STDOUT "<th > <a href=$CGI/elixir2?$key.0&elconf=$elconf> image </a></th>\n";
+    print STDOUT "<th > Date </th>\n";
+    print STDOUT "<th > Time </th>\n";
+    print STDOUT "<th > <a href=$CGI/elixir2?$key.3&elconf=$elconf> Mean </a></th>\n";
+    print STDOUT "<th > <a href=$CGI/elixir2?$key.5&elconf=$elconf> Sigma (raw) </a></th>\n";
+    print STDOUT "<th > <a href=$CGI/elixir2?$key.6&elconf=$elconf> Sigma (clipped) </a></th>\n";
+    print STDOUT "<th > <a href=$CGI/elixir2?$key.8&elconf=$elconf> Sigma (med) </a></th>\n";
+    print STDOUT "<th > image </th>\n";
+    print STDOUT "<th > used? </th>\n";
+    print STDOUT "<th > keep? </th></tr>\n\n";
+    
+    @order = ();
+    for ($i = 0; $i < $Nimage; $i++) { @order = (@order, $i); }
+    
+    @entry = sort by_col @order;
+    
+    for ($i = 0; $i < $Nimage; $i++) {
+	$N = $entry[$i];
+	
+	@word = split (" ", $statdata[$N]);
+	$used = $word[12];
+	$dawn = $word[11];
+	
+	@tmpw = split (" ", $mastdata[$N]);
+	$keep = $tmpw[1];
+	
+	@tmpw = split ("/", $medndata[$N]);
+	$medname = $tmpw[-1];
+	
+	print STDOUT "<tr><td> <a href=$CGI/elixir3?$N.$key&elconf=$elconf> $word[0] </a></td><td> $word[1] </td>\n";
+	if ($dawn) { print STDOUT "<td bgcolor=#cccccc> $word[2] </td>\n"; }
+	else       { print STDOUT "<td> $word[2] </td>\n"; }
+	print STDOUT "<td> $word[3] </td>\n"; # mean
+	print STDOUT "<td> $word[5] </td>\n"; # Sigma (raw)
+	print STDOUT "<td> $word[6] </td>\n"; # Sigma (clip)
+	print STDOUT "<td> $word[8] </td>\n"; # Sigma (med)
+	print STDOUT "<td> <a border=0 href=$CGI/elixir3?$N.$key&elconf=$elconf>\n";
+	print STDOUT "<img src=$www/$medname></a></td>\n";
+	if ($used) { print STDOUT "<td>yes</td>\n"; }
+	else       { print STDOUT "<td>no</td>\n"; }
+	if ($keep) { print STDOUT "<td bgcolor=#00c000><input type=checkbox checked name=image.$N value=$N size=1></td></tr>\n\n"; }
+	else       { print STDOUT "<td bgcolor=#d00000><input type=checkbox         name=image.$N value=$N size=1></td></tr>\n\n"; }	
+	
+    }
+    
+    print STDOUT "</table>\n";
+    print STDOUT "<input type=hidden    name=Nimage value=\"$Nimage\">\n";
+    print STDOUT "<input type=hidden    name=config value=\"$key\">\n";
+    print STDOUT "<input type=submit    value=\"apply changes\">\n";
+    print STDOUT "<input type=reset     value=Reset>\n";
+    # print STDOUT "<select name=status   size=1> \n";
+    print STDOUT "</form></body>\n";
+    &goodbye;
+    
+}
+
+sub flips_report_done {
+    
+    $col = 0;
+    ($type)   = $_[0] =~ /\w+.(\w+).\w+/;
+    ($config) = $_[0] =~ /(\w+.\w+.\w+)/;
+    ($key)    = $_[0] =~ /(\w+.\w+.\w+.\w+)/; # (config.ver)
+
+    # look for optional sort key (config.ver[.key])
+    if ($_[0] =~ /$key.(\d+)/) {
+	($col) = $_[0] =~ /$key.(\d+)/; 
+    } else {
+	$col = 0;
+    }
+
+    $line = $_[1];
+    $message = $_[2];
+    
+    open (FILE, mknames ("stats",  $line));            @statdata = <FILE>; close (FILE);
+    open (FILE, mknames ("medbin", $line));            @medndata = <FILE>; close (FILE);
+    open (FILE, mknames ("master", $line, $ccds[0]));  @mastdata = <FILE>; close (FILE);
+
+    $Nkeep = 0;
+    $Ncnt = 0;
+    $Sigma = 0;
+    $Nimage = @statdata;
+    for ($i = 0; $i < $Nimage; $i++) {
+	@tmpw = split (" ", $mastdata[$i]);
+	@tmps = split (" ", $statdata[$i]);
+	if ($tmpw[1]) { $Nkeep++; $Ncnt += $tmps[3]; $Sigma += $tmps[8]*$tmps[8]; }
+    }
+    if ($Nkeep > 0) {
+	if ($type eq "flat") { 
+	    $Sigma = sprintf "%5.3f", 100*sqrt ($Sigma/$Nkeep);
+	    $statline = "Total Counts: $Ncnt<br> r.m.s. median sigma: $Sigma% <br><br>\n";
+	} else {
+	    $Sigma = sprintf "%5.3f", sqrt ($Sigma/$Nkeep);
+	    $Ncnt  = sprintf "%5.3f", ($Ncnt / $Nkeep);
+	    $statline = "Mean Counts: $Ncnt<br> r.m.s. median sigma: $Sigma <br><br>\n";
+	}
+    } else {
+	$statline = "";
+    }
+
+    $imbin = mknames ("imbin",  $line);
+    print STDOUT "<table><tr><td width=300px valign=top>\n";
+    print STDOUT "<b>this config has been $message. </b><br>\n";
+    print STDOUT "there are $Nimage images, $Nkeep used. <br>\n";
+    print STDOUT "$statline\n";
+    print STDOUT "you have the following choices: <br>\n";
+    print STDOUT "<a href=$CGI/elixir1?&elconf=$elconf> <b> return to top level </b><br></a>\n";
+    print STDOUT "<a href=$CGI/split?$config&elconf=$elconf> <b> split config </b><br></a>\n";
+    print STDOUT "<a href=$CGI/accept?$key&elconf=$elconf> <b> accept config </b><br></a>\n";
+    print STDOUT "</td><td width=640px align=right><img width=100% src=$imbin></td></tr></table>\n";
+    
+    print STDOUT "<center><b>Statistics on each available input image.</b></center>
+  Time is in UT, light background means dawn, grey means dusk. Click
+  on the column heading to sort by that entry\n";
+
+    print STDOUT "<table bgcolor=#fff0e0 border=1 cellspacing=0 cellpadding=3>\n";
+    print STDOUT "<tr bgcolor=#00aaaa>\n";
+    print STDOUT "<th > <a href=$CGI/elixir2?$key.0&elconf=$elconf> image </a></th>\n";
+    print STDOUT "<th > Date </th>\n";
+    print STDOUT "<th > Time </th>\n";
+    print STDOUT "<th > <a href=$CGI/elixir2?$key.3&elconf=$elconf> Mean </a></th>\n";
+    print STDOUT "<th > <a href=$CGI/elixir2?$key.5&elconf=$elconf> Sigma (raw) </a></th>\n";
+    print STDOUT "<th > <a href=$CGI/elixir2?$key.6&elconf=$elconf> Sigma (clipped) </a></th>\n";
+    print STDOUT "<th > <a href=$CGI/elixir2?$key.8&elconf=$elconf> Sigma (med) </a></th>\n";
+    print STDOUT "<th > image </th>\n";
+    print STDOUT "<th > used? </th></tr>\n\n";
+    
+    @order = ();
+    for ($i = 0; $i < $Nimage; $i++) { @order = (@order, $i); }
+    
+    @entry = sort by_col @order;
+    
+    for ($i = 0; $i < $Nimage; $i++) {
+	$N = $entry[$i];
+	
+	@word = split (" ", $statdata[$N]);
+	$used = $word[12];
+	$dawn = $word[11];
+	
+	@tmpw = split (" ", $mastdata[$N]);
+	$keep = $tmpw[1];
+	
+	@tmpw = split ("/", $medndata[$N]);
+	$medname = $tmpw[-1];
+	
+	print STDOUT "<tr><td> <a href=$CGI/elixir3?$N.$key&elconf=$elconf> $word[0] </a></td><td> $word[1] </td>\n";
+	if ($dawn) { print STDOUT "<td bgcolor=#cccccc> $word[2] </td>\n"; }
+	else       { print STDOUT "<td> $word[2] </td>\n"; }
+	print STDOUT "<td> $word[3] </td>\n"; # mean
+	print STDOUT "<td> $word[5] </td>\n"; # Sigma (raw)
+	print STDOUT "<td> $word[6] </td>\n"; # Sigma (clip)
+	print STDOUT "<td> $word[8] </td>\n"; # Sigma (med)
+	print STDOUT "<td> <a border=0 href=$CGI/elixir3?$N.$key&elconf=$elconf>\n";
+	print STDOUT "<img src=$www/$medname></a></td>\n";
+	if ($used) { print STDOUT "<td>yes</td>\n"; }
+	else       { print STDOUT "<td>no</td>\n"; }
+	print STDOUT "</tr>\n";
+    }
+    
+    print STDOUT "</table></body>\n";
+    &goodbye;
+    
 }
 
 #### process report for html2 ##########
-sub flips_report_done {
-  
-  ($config) = $_[0] =~ /(\w+.\w+.\w+)/;
-  ($key)    = $_[0] =~ /(\w+.\w+.\w+.\w+)/; # (config.ver)
-  $line = $_[1];
-  
-  open (STAT, mknames ("stats", $line));
-  open (MED,  mknames ("medbin", $line));
-  open (MASTER, mknames ("master", $line, $ccds[0]));
-  
-  print STDOUT "<table border>\n";
-  print STDOUT "<tr><th> image </th><th> Date </th><th> Time </th><th> Mean </th>\n";
-  print STDOUT "<th> Sigma (raw) </th><th> Sigma (clipped) </th><th> Sigma (med) </th><th> image </th><th> used? </th></tr>\n\n";
-  
-  for ($i = 0; $line = <STAT>; $i++) {
+sub flips_report_done_old {
+    
+    ($config) = $_[0] =~ /(\w+.\w+.\w+)/;
+    ($key)    = $_[0] =~ /(\w+.\w+.\w+.\w+)/; # (config.ver)
+    $line = $_[1];
+    
+    open (STAT, mknames ("stats", $line));
+    open (MED,  mknames ("medbin", $line));
+    open (MASTER, mknames ("master", $line, $ccds[0]));
+    
+    print STDOUT "<table border>\n";
+    print STDOUT "<tr><th> image </th><th> Date </th><th> Time </th><th> Mean </th>\n";
+    print STDOUT "<th> Sigma (raw) </th><th> Sigma (clipped) </th><th> Sigma (med) </th><th> image </th><th> used? </th></tr>\n\n";
+    
+    for ($i = 0; $line = <STAT>; $i++) {
+	
+	chop ($line);
+	# print STDOUT "$line<br>\n";
+	@word = split (" ",$line);
+	$used = $word[12];
+	$dawn = $word[11];
+	
+	$line = <MASTER>;
+	chop ($line);
+	# print STDOUT "$line<br>\n";
+	@tmpw = split (" ",$line);
+	$keep = $tmpw[1];
+	
+	# mkdetrend works with files in the user's paths, but the web page needs 
+	# to work with files visible to the web server
+	$line = <MED>;
+	chop ($line);
+	@tmpw = split ("/", $line);
+	$N = @tmpw - 1;
+	$medname = $tmpw[$N];
+	
+	$sig1 = sprintf "%5.3f", $word[4];
+	$sig2 = sprintf "%5.3f", $word[5];
+	$sig3 = sprintf "%5.3f", $word[6];
+	$sig4 = sprintf "%5.3f", $word[7];
+	$mean = sprintf "%8.1f", $word[3];
+	
+	print STDOUT "<tr><td> <a href=$CGI/elixir3?$i.$key&elconf=$elconf> $word[0] </a></td><td> $word[1] </td>\n";
+	if ($dawn) { print STDOUT "<td bgcolor=#cccccc> $word[2] </td>\n"; }
+	else       { print STDOUT "<td> $word[2] </td>\n"; } 
+	print STDOUT "<td> $word[3] </td>\n";
+	print STDOUT "<td> $word[5] </td><td> $word[6] </td><td> $word[8] </td><td><img src=$www/$medname></td>\n";
+	if ($used) { print STDOUT "<td bgcolor=#00c000>yes</td>\n"; }
+	else       { print STDOUT "<td bgcolor=#d00000>no</td>\n"; }
+    }
+    $Nimage = $i;
+    
+    print STDOUT "</table>\n";
+    print STDOUT "</body>\n";
+    
+    &goodbye;
+    
+}
+
+#### process report for html3 ##########
+sub flips_entry {
+    
+    my($version)= $_[0];		# version of desired entry
+    my($entry)  = $_[1];		# desired entry in list
+    my($line)   = $_[2];		# list of image stats
+    
+    open (STAT, mknames ("stats", $line));
+    open (TEN,  mknames ("tenbin", $line));
+    
+    for ($i = 0; ($i < $entry + 1) && ($line = <STAT>) && ($tenline = <TEN>); $i++) {}
+    if ($i != $entry + 1) { &escape ("</table> selected entry out of range"); }
+    
+    $first = ($entry == 0);
+    $tmp = <STAT>;
+    $last = ($tmp == "");
+    $next = $entry + 1;
+    $prev = $entry - 1;
     
     chop ($line);
-    # print STDOUT "$line<br>\n";
     @word = split (" ",$line);
-    $used = $word[12];
-    $dawn = $word[11];
-    
-    $line = <MASTER>;
-    chop ($line);
-    # print STDOUT "$line<br>\n";
-    @tmpw = split (" ",$line);
-    $keep = $tmpw[1];
+    $keep = $word[12];
     
     # mkdetrend works with files in the user's paths, but the web page needs 
     # to work with files visible to the web server
-    $line = <MED>;
-    chop ($line);
-    @tmpw = split ("/", $line);
+    chop ($tenline);
+    @tmpw = split ("/", $tenline);
     $N = @tmpw - 1;
-    $medname = $tmpw[$N];
+    $name = $tmpw[$N];
     
     $sig1 = sprintf "%5.3f", $word[4];
@@ -1756,84 +1964,31 @@
     $mean = sprintf "%8.1f", $word[3];
     
-    print STDOUT "<tr><td> <a href=$CGI/elixir3?$i.$key&elconf=$elconf> $word[0] </a></td><td> $word[1] </td>\n";
-    if ($dawn) { print STDOUT "<td bgcolor=#cccccc> $word[2] </td>\n"; }
-    else       { print STDOUT "<td> $word[2] </td>\n"; } 
-    print STDOUT "<td> $word[3] </td>\n";
-    print STDOUT "<td> $word[5] </td><td> $word[6] </td><td> $word[8] </td><td><img src=$www/$medname></td>\n";
-    if ($used) { print STDOUT "<td bgcolor=#00c000>yes</td>\n"; }
-    else       { print STDOUT "<td bgcolor=#d00000>no</td>\n"; }
-  }
-  $Nimage = $i;
-  
-  print STDOUT "</table>\n";
-  print STDOUT "</body>\n";
-  
-  &goodbye;
-  
-}
-
-#### process report for html3 ##########
-sub flips_entry {
-  
-  my($version)= $_[0];		# version of desired entry
-  my($entry)  = $_[1];		# desired entry in list
-  my($line)   = $_[2];		# list of image stats
-  
-  open (STAT, mknames ("stats", $line));
-  open (TEN,  mknames ("tenbin", $line));
-  
-  for ($i = 0; ($i < $entry + 1) && ($line = <STAT>) && ($tenline = <TEN>); $i++) {}
-  if ($i != $entry + 1) { &escape ("</table> selected entry out of range"); }
-  
-  $first = ($entry == 0);
-  $tmp = <STAT>;
-  $last = ($tmp == "");
-  $next = $entry + 1;
-  $prev = $entry - 1;
-  
-  chop ($line);
-  @word = split (" ",$line);
-  $keep = $word[12];
-  
-  # mkdetrend works with files in the user's paths, but the web page needs 
-  # to work with files visible to the web server
-  chop ($tenline);
-  @tmpw = split ("/", $tenline);
-  $N = @tmpw - 1;
-  $name = $tmpw[$N];
-  
-  $sig1 = sprintf "%5.3f", $word[4];
-  $sig2 = sprintf "%5.3f", $word[5];
-  $sig3 = sprintf "%5.3f", $word[6];
-  $sig4 = sprintf "%5.3f", $word[7];
-  $mean = sprintf "%8.1f", $word[3];
-  
-  print STDOUT "<img width=100% src=$www/$name>\n";
-  
-  print STDOUT "<table><tr><td>\n";
-  print STDOUT "<table border>\n";
-  print STDOUT "<tr><th> image </th><th> Date </th><th> Time </th><th> Mean </th>\n";
-  print STDOUT "<th> Sigma (raw) </th><th> Sigma (clipped) </th><th> Sigma (med) </th><th> used? </th></tr>\n\n";
-  
-  print STDOUT "<tr><td> $word[0] </a></td><td> $word[1] </td><td> $word[2] </td><td> $word[3] </td>\n";
-  print STDOUT "<td> $word[5] </td><td> $word[6] </td><td> $word[8] </td>\n";
-  if ($keep) {
-    print STDOUT "<td>yes</td>\n";
-  } else {
-    print STDOUT "<td bgcolor=#ff0000>no</td>\n";
-  }	
-  print STDOUT "</tr>\n\n";
-  print STDOUT "</table>\n";
-  
-  print STDOUT "</td></tr>\n";
-
-  print STDOUT "<tr><td> return to <a href=$CGI/elixir1&elconf=$elconf> config list </a></tr></td>\n"; 
-  print STDOUT "<tr><td> return to <a href=$CGI/elixir2?$version&elconf=$elconf> $version </a></tr></td>\n"; 
-  if (!$first) { print STDOUT "<tr><td> goto <a href=$CGI/elixir3?$prev.$version&elconf=$elconf> prev </a> image </td></tr>\n"; }
-  if (!$last)  { print STDOUT "<tr><td> goto <a href=$CGI/elixir3?$next.$version&elconf=$elconf> next </a> image </td></tr>\n"; }
-  print STDOUT "</table>\n";
-  
-  print STDOUT "</body>\n";
-  &goodbye;
+    print STDOUT "<img width=100% src=$www/$name>\n";
+    
+    print STDOUT "<table><tr><td>\n";
+    print STDOUT "<table border>\n";
+    print STDOUT "<tr><th> image </th><th> Date </th><th> Time </th><th> Mean </th>\n";
+    print STDOUT "<th> Sigma (raw) </th><th> Sigma (clipped) </th><th> Sigma (med) </th><th> used? </th></tr>\n\n";
+    
+    print STDOUT "<tr><td> $word[0] </a></td><td> $word[1] </td><td> $word[2] </td><td> $word[3] </td>\n";
+    print STDOUT "<td> $word[5] </td><td> $word[6] </td><td> $word[8] </td>\n";
+    if ($keep) {
+	print STDOUT "<td>yes</td>\n";
+    } else {
+	print STDOUT "<td bgcolor=#ff0000>no</td>\n";
+    }	
+    print STDOUT "</tr>\n\n";
+    print STDOUT "</table>\n";
+    
+    print STDOUT "</td></tr>\n";
+
+    print STDOUT "<tr><td> return to <a href=$CGI/elixir1&elconf=$elconf> config list </a></tr></td>\n"; 
+    print STDOUT "<tr><td> return to <a href=$CGI/elixir2?$version&elconf=$elconf> $version </a></tr></td>\n"; 
+    if (!$first) { print STDOUT "<tr><td> goto <a href=$CGI/elixir3?$prev.$version&elconf=$elconf> prev </a> image </td></tr>\n"; }
+    if (!$last)  { print STDOUT "<tr><td> goto <a href=$CGI/elixir3?$next.$version&elconf=$elconf> next </a> image </td></tr>\n"; }
+    print STDOUT "</table>\n";
+    
+    print STDOUT "</body>\n";
+    &goodbye;
 }
 
@@ -1945,5 +2100,5 @@
     close (FILE);
 }    
-  
+
 # $root/detrend.config    - current run
 # $det/config.dat         - config info for specific run, 1 line per setup
@@ -1994,4 +2149,8 @@
 	    last;
 	}
+	if ($type eq "links") {
+	    $value = "$det/flips/links";
+	    last;
+	}
 	if ($type eq "split") {
 	    $value = "$det/split";
@@ -2075,4 +2234,16 @@
 	    last;
 	}
+	if ($type eq "link") {
+	    $dir = mkfiles ("links");
+	    $ccd = $_[2];
+	    if ($ccd eq "") { &escape ("missing CCD for mknames fits"); }
+	    $value = "$dir/$words[0].$words[1].$words[2].$ccd.$words[3].fits";
+	    last;
+	}
+	if ($type eq "mef") {
+	    $dir = mkfiles ("flips");
+	    $value = "$dir/$words[0].$words[1].$words[2].$words[3].fits";
+	    last;
+	}
 	if ($type eq "proc.medbin") {
 	    $dir = mkfiles ("flips");
@@ -2106,60 +2277,60 @@
 #**************************
 sub gtconfig {
-  my ($value, $type, @words);
-  # in: (config line) (type)
-  @words = split (" ", $_[0]);
-  $type = $_[1];
-
-  { 
-      if ($type eq "elixir") {
-	  $value = "$words[0] $words[1] $words[2] $words[3]";
-	  last;
-      }
-      if ($type eq "mosaic") {
-	$ccd = "xx";
-	  $value = "$words[0] $words[1] $words[2] $ccd $words[3] $words[4] $words[5]";
-	  last;
-      }
-      if ($type eq "chiprun") {
-	  $ccd  = sprintf "%02d", $_[2];
-	  $value = "$words[0] $words[1] $words[2] $ccd $words[3] $words[4] $words[5]";
-	  last;
-      }
-      if ($type eq "config") {
-	  $value = "$words[0].$words[1].$words[2]";
-	  last;
-      }
-      if ($type eq "version") {
-	  $value = "$words[0].$words[1].$words[2].$words[3]";
-	  last;
-      }
-      if ($type eq "ID") {
-	  $value = "$words[0]";
-	  last;
-      }
-      if ($type eq "type") {
-	  $value = "$words[1]";
-	  last;
-      }
-      if ($type eq "filter") {
-	  $value = "$words[2]";
-	  last;
-      }
-      if ($type eq "from") {
-	  $value = "$words[4]";
-	  last;
-      }
-      if ($type eq "to") {
-	  $value = "$words[5]";
-	  last;
-      }
-      if ($type eq "status") {
-	  $value = "$words[6]";
-	  last;
-      }
-      &escape ("unknown type for gtconfig: $type");
-  }
-  
-  return $value;
+    my ($value, $type, @words);
+    # in: (config line) (type)
+    @words = split (" ", $_[0]);
+    $type = $_[1];
+
+    { 
+	if ($type eq "elixir") {
+	    $value = "$words[0] $words[1] $words[2] $words[3]";
+	    last;
+	}
+	if ($type eq "mosaic") {
+	    $ccd = "xx";
+	    $value = "$words[0] $words[1] $words[2] $ccd $words[3] $words[4] $words[5]";
+	    last;
+	}
+	if ($type eq "chiprun") {
+	    $ccd  = $_[2];
+	    $value = "$words[0] $words[1] $words[2] $ccd $words[3] $words[4] $words[5]";
+	    last;
+	}
+	if ($type eq "config") {
+	    $value = "$words[0].$words[1].$words[2]";
+	    last;
+	}
+	if ($type eq "version") {
+	    $value = "$words[0].$words[1].$words[2].$words[3]";
+	    last;
+	}
+	if ($type eq "ID") {
+	    $value = "$words[0]";
+	    last;
+	}
+	if ($type eq "type") {
+	    $value = "$words[1]";
+	    last;
+	}
+	if ($type eq "filter") {
+	    $value = "$words[2]";
+	    last;
+	}
+	if ($type eq "from") {
+	    $value = "$words[4]";
+	    last;
+	}
+	if ($type eq "to") {
+	    $value = "$words[5]";
+	    last;
+	}
+	if ($type eq "status") {
+	    $value = "$words[6]";
+	    last;
+	}
+	&escape ("unknown type for gtconfig: $type");
+    }
+    
+    return $value;
 }
 
@@ -2214,6 +2385,6 @@
     if ($run eq "") {
 	$run = `gconfig RUNID.MKDETREND`; chop $run;
-	if ($?) {  &escape ("run is not defined: use 'mkdetrend config' or 'mkrun sys'\n"); }
-	if ($run eq "") {  &escape ("run is not defined: use 'mkdetrend config' or 'mkrun sys'\n"); }
+	if ($?) {  &escape ("run is not defined: use '$MKDETREND config' or 'mkrun sys'\n"); }
+	if ($run eq "") {  &escape ("run is not defined: use '$MKDETREND config' or 'mkrun sys'\n"); }
 	push @opt, "-D RUNID.MKDETREND $run -D RUNID $run";
     }
@@ -2244,6 +2415,5 @@
     if ($?) { &escape ("error with elixir camera configuration"); }
 
-    $answer = `cameraconfig -ccds`;
-    @ccds = split (" ", $answer); 
+    @ccds = split (" ", `cameraconfig -ccdn`);
     if ($?) { &escape ("error with elixir camera configuration"); }
 
@@ -2271,9 +2441,9 @@
     return (@argv);
 }
-  
+
 sub vsystem {
-  print STDERR "@_\n";
-  $status = system ("@_");
-  $status;
+    print STDERR "@_\n";
+    $status = system ("@_");
+    $status;
 }
 
@@ -2290,49 +2460,49 @@
 
 sub usage {
-  if (@ARGV == 1) {
-    print STDERR "\n --- user modes ---\n";
-    print STDERR "create (run) (startdate) (stopdate)\n";
-    print STDERR "config (run)\n";
-    print STDERR "init\n";
-    print STDERR "run\n";
-    print STDERR "list.runs\n";
-    print STDERR "set (config.ver) (state)\n";
-    print STDERR "reg\n";
-    print STDERR "state \n";
-    print STDERR "help \n";
-    print STDERR "\n --- internal modes --- \n";
-    print STDERR "flips\n";
-    print STDERR "norm\n";
-    print STDERR "update\n";
-    print STDERR "merge\n";
-    print STDERR "dup (config)\n";
-    print STDERR "del (config)\n";
-    print STDERR "def (config.ver) (start) (stop)\n";
-    print STDERR "eval (step)\n";
-    print STDERR "mevel (step)\n";
-    print STDERR "htmldup\n";
-    print STDERR "htmldel\n";
-    print STDERR "htmldef\n";
-    print STDERR "htmlmod\n";
-    print STDERR "htmlkeep\n";
-    print STDERR "html1\n";
-    print STDERR "html2 (config.ver)\n";
-    print STDERR "html3 (entry.config.ver)\n";
+    if (@ARGV == 1) {
+	print STDERR "\n --- user modes ---\n";
+	print STDERR "create (run) (startdate) (stopdate)\n";
+	print STDERR "config (run)\n";
+	print STDERR "init\n";
+	print STDERR "run\n";
+	print STDERR "list.runs\n";
+	print STDERR "set (config.ver) (state)\n";
+	print STDERR "reg\n";
+	print STDERR "state \n";
+	print STDERR "help \n";
+	print STDERR "\n --- internal modes --- \n";
+	print STDERR "flips\n";
+	print STDERR "norm\n";
+	print STDERR "update\n";
+	print STDERR "merge\n";
+	print STDERR "dup (config)\n";
+	print STDERR "del (config)\n";
+	print STDERR "def (config.ver) (start) (stop)\n";
+	print STDERR "eval (step)\n";
+	print STDERR "mevel (step)\n";
+	print STDERR "htmldup\n";
+	print STDERR "htmldel\n";
+	print STDERR "htmldef\n";
+	print STDERR "htmlmod\n";
+	print STDERR "htmlkeep\n";
+	print STDERR "html1\n";
+	print STDERR "html2 (config.ver)\n";
+	print STDERR "html3 (entry.config.ver)\n";
+	&escape;
+    }
+    
+    if (@ARGV > 2) { print STDERR "USAGE: $MKDETREND (help) [mode]\n"; &escape; }
+    
+    if ($ARGV[1] eq "config") {
+	print STDERR "set up initial configuration\n";
+	&escape;
+    }
+    
+    if ($ARGV[1] eq "save") {
+	print STDERR "save results from current configuration\n";
+	&escape;
+    }
+    
+    print STDERR "help for $ARGV[1] no defined\n";
     &escape;
-  }
-  
-  if (@ARGV > 2) { print STDERR "USAGE: mkdetrend (help) [mode]\n"; &escape; }
-  
-  if ($ARGV[1] eq "config") {
-    print STDERR "set up initial configuration\n";
-    &escape;
-  }
-  
-  if ($ARGV[1] eq "save") {
-    print STDERR "save results from current configuration\n";
-    &escape;
-  }
-  
-  print STDERR "help for $ARGV[1] no defined\n";
-  &escape;
-}
+}
Index: /trunk/Ohana/src/perl/src/mkfringe
===================================================================
--- /trunk/Ohana/src/perl/src/mkfringe	(revision 45)
+++ /trunk/Ohana/src/perl/src/mkfringe	(revision 46)
@@ -1,3 +1,4 @@
 #!/usr/bin/perl
+$MKFRINGE = mkfringe2;
 
 # strip off args related to the elixir config system, set env PTOLEMY
@@ -6,5 +7,5 @@
 # interpret command-line arguments
 if (@ARGV < 1) {
-    print STDOUT "USAGE: mkfringe (mode) [arguments]\n";
+    print STDOUT "USAGE: $MKFRINGE (mode) [arguments]\n";
     print STDOUT "mode = help gives a complete list\n";
     &escape;
@@ -62,5 +63,5 @@
     
     if ($ARGV[1] eq "run") { &mk_createrun; }
-    if (@ARGV != 5) { &escape ("USAGE: mkfringe create (camera) (run) (startdate) (stopdate)"); }
+    if (@ARGV != 5) { &escape ("USAGE: $MKFRINGE create (camera) (run) (startdate) (stopdate)"); }
     
     # setting $run & $start here overrides default values loaded by set_globals()
@@ -109,5 +110,5 @@
 sub mk_createrun {
     
-    if (@ARGV != 3) { &escape ("USAGE: mkfringe create run (run)"); }
+    if (@ARGV != 3) { &escape ("USAGE: $MKFRINGE create run (run)"); }
     if ($ARGV[1] ne "run") { &escape ("USAGE: mkdetrend create run (run)"); }
     
@@ -148,5 +149,5 @@
 sub mk_config {
     
-    if (@ARGV != 3) { &escape ("USAGE: mkfringe config (camera) (run)"); }    
+    if (@ARGV != 3) { &escape ("USAGE: $MKFRINGE config (camera) (run)"); }    
 
     $camera = $ARGV[1];
@@ -167,9 +168,9 @@
 sub mk_init {
     
-    if (@ARGV != 1) { &escape ("USAGE: mkfringe run"); }
-
-    system "mkfringe list.init\n";
-    system "mkfringe detrend\n";
-    system "mkfringe merge\n";
+    if (@ARGV != 1) { &escape ("USAGE: $MKFRINGE run"); }
+
+    system "$MKFRINGE list.init\n";
+    system "$MKFRINGE detrend\n";
+    system "$MKFRINGE merge\n";
     &goodbye;
 }
@@ -178,9 +179,9 @@
 sub mk_run {
     
-    if (@ARGV != 1) { &escape ("USAGE: mkfringe run"); }
-    
-    system "mkfringe mkrough";
-    system "mkfringe defringe";
-    system "mkfringe merge";
+    if (@ARGV != 1) { &escape ("USAGE: $MKFRINGE run"); }
+    
+    system "$MKFRINGE mkrough";
+    system "$MKFRINGE defringe";
+    system "$MKFRINGE merge";
     
     &goodbye;
@@ -190,8 +191,8 @@
 sub mk_reg {
     
-    if (@ARGV != 1) { &escape ("USAGE: mkfringe reg"); }
-    
-    system "mkfringe mksmooth";
-    system "mkfringe regimage";
+    if (@ARGV != 1) { &escape ("USAGE: $MKFRINGE reg"); }
+    
+    system "$MKFRINGE mksmooth";
+    system "$MKFRINGE regimage";
     
     &goodbye;
@@ -201,5 +202,5 @@
 sub mk_state {
     
-    if (@ARGV != 1) { &escape ("USAGE: mkfringe state"); }
+    if (@ARGV != 1) { &escape ("USAGE: $MKFRINGE state"); }
     
     ($start, $stop, $mode) = &load_dates;
@@ -212,5 +213,5 @@
     
     @list = &load_config;
-    if (@list == 0) { &escape ("mkfringe not configured"); }
+    if (@list == 0) { &escape ("$MKFRINGE not configured"); }
 
     for ($i = 0; $i < @list; $i++) {
@@ -223,5 +224,5 @@
 sub mk_list_runs {
     
-    if (@ARGV != 1) { &escape ("USAGE: mkfringe list.runs"); }
+    if (@ARGV != 1) { &escape ("USAGE: $MKFRINGE list.runs"); }
     
     system ("ls $root");
@@ -233,5 +234,5 @@
     
     # create mkfringe config file from existing date entries
-    if (@ARGV != 1) { &escape ("USAGE: mkfringe mkconfig"); }
+    if (@ARGV != 1) { &escape ("USAGE: $MKFRINGE mkconfig"); }
     
     # if new run, need to create the new detdir
@@ -244,5 +245,5 @@
 
     ($start, $stop, $mode) = &load_dates;
-    if (($start eq "") || ($stop eq "")) { &escape ("dates are not defined: use 'mkfringe config'"); }
+    if (($start eq "") || ($stop eq "")) { &escape ("dates are not defined: use '$MKFRINGE config'"); }
 
     # create run-specific config file
@@ -259,5 +260,5 @@
 sub mk_dup {
     
-    if (@ARGV != 2) { &escape ("USAGE: mkfringe dup (config)"); }
+    if (@ARGV != 2) { &escape ("USAGE: $MKFRINGE dup (config)"); }
     
     $key = $ARGV[1];
@@ -286,5 +287,5 @@
 sub mk_cleanup {
     
-    if ((@ARGV != 1) && (@ARGV != 2)) { &escape ("USAGE: mkfringe cleanup [mode]"); }
+    if ((@ARGV != 1) && (@ARGV != 2)) { &escape ("USAGE: $MKFRINGE cleanup [mode]"); }
 
     $DEBUG = 0;
@@ -343,5 +344,5 @@
 sub mk_del {
     
-    if (@ARGV != 2) { &escape ("USAGE: mkfringe del (config.ver)"); }
+    if (@ARGV != 2) { &escape ("USAGE: $MKFRINGE del (config.ver)"); }
     
     $key = $ARGV[1];
@@ -376,5 +377,5 @@
 sub mk_def {
     
-    if (@ARGV != 4) { &escape ("USAGE: mkfringe def (config.ver) (start) (stop)"); }
+    if (@ARGV != 4) { &escape ("USAGE: $MKFRINGE def (config.ver) (start) (stop)"); }
     
     $key   = $ARGV[1];
@@ -408,5 +409,5 @@
 sub mk_set {
     
-    if (@ARGV != 3) { &escape ("USAGE: mkfringe set (config number) (state)"); }
+    if (@ARGV != 3) { &escape ("USAGE: $MKFRINGE set (config number) (state)"); }
     
     @list = load_config ();
@@ -429,5 +430,5 @@
 sub mk_list_init {
     
-    if (@ARGV != 1) { &escape ("USAGE: mkfringe list.init"); }
+    if (@ARGV != 1) { &escape ("USAGE: $MKFRINGE list.init"); }
     
     # create necessary directories
@@ -457,5 +458,5 @@
     
     vsystem ("elixir -D DETREND_DIR $det -D mode fringe1 $file");
-    vsystem ("mkfringe eval $file init");
+    vsystem ("$MKFRINGE eval $file init");
 
     open (FILE, "$file.eval");
@@ -484,5 +485,5 @@
 sub mk_list_reinit {
     
-    if (@ARGV != 1) { &escape ("USAGE: mkfringe list.init"); }
+    if (@ARGV != 1) { &escape ("USAGE: $MKFRINGE list.init"); }
     
     # create necessary directories
@@ -509,5 +510,5 @@
     
     vsystem ("elixir -D DETREND_DIR $det -D mode fringe1 -D global.pending master.lists $file");
-    vsystem ("mkfringe eval $file init");
+    vsystem ("$MKFRINGE eval $file init");
 
     open (FILE, "$file.eval");
@@ -536,5 +537,5 @@
 sub mk_detrend {
     
-    if (@ARGV != 1) { &escape ("USAGE: mkfringe detrend"); }
+    if (@ARGV != 1) { &escape ("USAGE: $MKFRINGE detrend"); }
 
     @list = load_config ();
@@ -563,5 +564,5 @@
     
     vsystem ("elixir -D DETREND_DIR $det -D mode fringe2 $file"); 
-    vsystem ("mkfringe eval $file detrend");
+    vsystem ("$MKFRINGE eval $file detrend");
 
     open (FILE, "$file.eval");
@@ -602,5 +603,5 @@
 sub mk_map {
     
-    if (@ARGV != 1) { &escape ("USAGE: mkfringe map"); }
+    if (@ARGV != 1) { &escape ("USAGE: $MKFRINGE map"); }
 
     @list = load_config ();
@@ -635,5 +636,5 @@
 sub mk_map_reg {
     
-    if (@ARGV != 1) { &escape ("USAGE: mkfringe map.reg"); }
+    if (@ARGV != 1) { &escape ("USAGE: $MKFRINGE map.reg"); }
     
     @list = load_config ();
@@ -666,5 +667,5 @@
 sub mk_mkrough {
     
-    if (@ARGV != 1) { &escape ("USAGE: mkfringe mkrough"); }
+    if (@ARGV != 1) { &escape ("USAGE: $MKFRINGE mkrough"); }
     
     @list = load_config ();
@@ -689,19 +690,25 @@
 	$CONFIG  = mknames ("config", $confline);
 
+	# extract the selected subset of detrend images from master & statlist to sublist
 	vsystem ("fr.mklists -subset  $CONFIG.master $CONFIG.med.statlist $CONFIG.med.sublist");
 	if ($?) { &escape ("failure running fr.mklists -subset"); }
 
+	# extract the selected subset of defringed images from master & statlist to sublist
 	vsystem ("fr.mklists -subset  $CONFIG.master $CONFIG.def.statlist $CONFIG.def.sublist");
 	if ($?) { &escape ("failure running fr.mklists -subset"); }
 
+	# calculate fit parameters based on subset
 	vsystem ("fr.frstats -fitpars $CONFIG.med.sublist $CONFIG.fitpar");
 	if ($?) { &escape ("failure running fr.frstats -fitpars"); }
 
+	# calculate optimal per-image fringe statistics based on fit parameters
 	vsystem ("fr.frstats -frstats $CONFIG.med.statlist $CONFIG.fitpar $CONFIG.med.imstats");
 	if ($?) { &escape ("failure running fr.frstats -frstats"); }
 
+	# calculate per-image residual fringe stats 
 	vsystem ("fr.frstats -dfstats $CONFIG.def.statlist $CONFIG.fitpar $CONFIG.def.imstats");
 	if ($?) { &escape ("failure running fr.frstats -dfstats"); }
 
+	# assemble master fringe statistic file needed by web tools
 	vsystem ("fr.mklists -imstats $CONFIG.master $CONFIG.med.imstats $CONFIG.def.imstats $CONFIG.datlist $CONFIG.imstats");
 	if ($?) { &escape ("failure running fr.mklists -imstats"); }
@@ -714,5 +721,5 @@
     
     vsystem ("elixir -D DETREND_DIR $det -D mode fringe4 $file");
-    vsystem ("mkfringe eval $file mkrough");
+    vsystem ("$MKFRINGE eval $file mkrough");
 
     open (FILE, "$file.eval");
@@ -744,5 +751,5 @@
 sub mk_defringe {
     
-    if (@ARGV != 1) { &escape ("USAGE: mkfringe defringe"); }
+    if (@ARGV != 1) { &escape ("USAGE: $MKFRINGE defringe"); }
 
     @list = load_config ();
@@ -770,5 +777,5 @@
     
     vsystem ("elixir -D DETREND_DIR $det -D mode fringe3 $file"); 
-    vsystem ("mkfringe eval $file defringe");
+    vsystem ("$MKFRINGE eval $file defringe");
 
     open (FILE, "$file.eval");
@@ -805,5 +812,5 @@
 sub mk_merge {
     
-    if (@ARGV != 1) { &escape ("USAGE: mkfringe merge"); }
+    if (@ARGV != 1) { &escape ("USAGE: $MKFRINGE merge"); }
 
     @list = load_config ();
@@ -830,5 +837,5 @@
 
 	vsystem ("fr.frstats -plotstats $CONFIG.med.statlist $CONFIG.fitpar $CONFIG.stats.png");
-	if ($?) { &escape ("failure running fr.frstats -fitpars"); }
+	if ($?) { &escape ("failure running fr.frstats -plotstats"); }
 
 	vsystem ("fr.frstats -frstats $CONFIG.med.statlist $CONFIG.fitpar $CONFIG.med.imstats");
@@ -887,5 +894,5 @@
 sub mk_smooth {
     
-    if (@ARGV != 1) { &escape ("USAGE: mkfringe mksmooth"); }
+    if (@ARGV != 1) { &escape ("USAGE: $MKFRINGE mksmooth"); }
     
     @list = load_config ();
@@ -914,5 +921,5 @@
     
     vsystem ("elixir -D DETREND_DIR $det -D mode fringe4 -D global.pending mksmooth $file");
-    vsystem ("mkfringe eval $file smooth");
+    vsystem ("$MKFRINGE eval $file smooth");
 
     open (FILE, "$file.eval");
@@ -944,5 +951,5 @@
 sub mk_regimage {
     
-    if (@ARGV != 1) { &escape ("USAGE: mkfringe regimage"); }
+    if (@ARGV != 1) { &escape ("USAGE: $MKFRINGE regimage"); }
     
     @list = load_config ();
@@ -957,16 +964,51 @@
 	$success = 1;
 	$ID = gtconfig ($confline, "ID");
-	for ($j = 0; $j < $Nccd; $j++) {
-	    $file = mknames ("smfile", $confline, $ccds[$j]);
-	    $line = "detregister $file -label fringe-2.1 -ID $ID";
-	    $status = system ($line);
-	    if ($status) { 
-		print STDERR "error registering $file\n";
-		$success = 0;
+
+	$DBmode = `gconfig DETREND-DB-MODE`; chop $DBmode;
+	$DBmode = "\U$DBmode\E";
+
+	if ($DBmode eq "SPLIT") {
+	    for ($j = 0; $j < $Nccd; $j++) {
+		$file = mknames ("smfile", $confline, $ccds[$j]);
+		$line = "detregister $file -label fringe-2.1 -ID $ID";
+		$status = system ($line);
+		if ($status) { 
+		    print STDERR "error registering $file\n";
+		    $success = 0;
+		}
 	    }
-	}
+	    goto registered;
+	}
+
+	if ($DBmode eq "MEF") {
+	    # make links 
+	    foreach $ccd (@ccds) {
+		$file = mknames ("smfile", $confline, $ccd);
+		$link = mknames ("link", $confline, $ccd);
+		symlink $file, $link;
+	    }
+
+	    # mef, register
+	    $mef = mknames ("mef", $confline);
+	    vsystem ("fhtool -P $links $mef");
+	    if ($status) { $success = 0; }
+	    vsystem ("detregister $mef -label fringe-2.1 -ID $ID");
+	    if ($status) { $success = 0; }
+
+	    # remove links
+	    foreach $ccd (@ccds) {
+		$link = mknames ("link", $confline, $ccd);
+		unlink $link;
+	    }
+	    goto registered;
+	}
+	print STDERR "DB mode not defined?\n";
+	$success = 0;
+
+      registered:
 	if ($success) {
 	    $confline = stconfig ($confline, "status", "done");
 	} else {
+	    print STDERR "error registering $file\n"; 
 	    $confline = stconfig ($confline, "status", "fail.reg");
 	}
@@ -979,5 +1021,5 @@
 sub mk_eval {
     
-    if (@ARGV != 3) { &escape ("USAGE: mkfringe meval (file) (step)"); }
+    if (@ARGV != 3) { &escape ("USAGE: $MKFRINGE meval (file) (step)"); }
     
     $infile = $ARGV[1];
@@ -1049,8 +1091,8 @@
 sub mk_htmldup {
     
-    if (@ARGV != 2) { &escape ("USAGE: mkfringe htmldup (config)"); }
+    if (@ARGV != 2) { &escape ("USAGE: $MKFRINGE htmldup (config)"); }
     
     $config = $ARGV[1];
-    system ("mkfringe dup $config");
+    system ("$MKFRINGE dup $config");
     print STDOUT "<meta http-equiv=refresh content=\"0; url=$CGI/fr.elixir1?&elconf=$elconf\">\n";
     
@@ -1061,8 +1103,8 @@
 sub mk_htmldel {
     
-    if (@ARGV != 2) { &escape ("USAGE: mkfringe htmldel (config.ver)"); }
+    if (@ARGV != 2) { &escape ("USAGE: $MKFRINGE htmldel (config.ver)"); }
     
     $config = $ARGV[1];
-    system ("mkfringe del $config");
+    system ("$MKFRINGE del $config");
     print STDOUT "<meta http-equiv=refresh content=\"0; url=$CGI/fr.elixir1?&elconf=$elconf\">\n";
     
@@ -1073,5 +1115,5 @@
 sub mk_htmldef {
     
-    if (@ARGV != 2) { &escape ("USAGE: mkfringe htmldef (config.ver)"); }
+    if (@ARGV != 2) { &escape ("USAGE: $MKFRINGE htmldef (config.ver)"); }
     
     $key = $ARGV[1];
@@ -1137,5 +1179,5 @@
 sub mk_htmlmod {
     
-    if (@ARGV != 1) { &escape ("USAGE: mkfringe htmlmod"); }
+    if (@ARGV != 1) { &escape ("USAGE: $MKFRINGE htmlmod"); }
     
     # images which are marked for exclusion are included in the 
@@ -1217,5 +1259,5 @@
 sub mk_htmlmodes {
     
-    if (@ARGV != 1) { &escape ("USAGE: mkfringe htmlmodes"); }
+    if (@ARGV != 1) { &escape ("USAGE: $MKFRINGE htmlmodes"); }
     
     # modes which are marked for exclusion are included in the 
@@ -1271,5 +1313,5 @@
 sub mk_htmlmaps {
     
-    if (@ARGV != 1) { &escape ("USAGE: mkfringe htmlmaps"); }
+    if (@ARGV != 1) { &escape ("USAGE: $MKFRINGE htmlmaps"); }
     
     # maps which are marked for inclusion are given in the 
@@ -1321,5 +1363,5 @@
 sub mk_htmlkeep {
     
-    if (@ARGV != 2) { &escape ("USAGE: mkfringe htmlkeep (config.ver)"); }
+    if (@ARGV != 2) { &escape ("USAGE: $MKFRINGE htmlkeep (config.ver)"); }
     
     $key = $ARGV[1];
@@ -1372,5 +1414,5 @@
     
 
-    if (@ARGV != 1) { &escape ("USAGE: mkfringe html1"); }
+    if (@ARGV != 1) { &escape ("USAGE: $MKFRINGE html1"); }
     
     @list = load_config ();
@@ -1414,5 +1456,5 @@
     
     if (@ARGV != 2) {
-	print STDERR "USAGE: mkfringe html2 (config.ver)\n";
+	print STDERR "USAGE: $MKFRINGE html2 (config.ver)\n";
 	&goodbye; 
     }
@@ -1489,5 +1531,5 @@
     
     if (@ARGV != 3) {
-	print STDERR "USAGE: mkfringe html3 (entry.config.ver) (mode)\n";
+	print STDERR "USAGE: $MKFRINGE html3 (entry.config.ver) (mode)\n";
 	&goodbye; 
     }
@@ -1557,5 +1599,5 @@
     
     if (@ARGV != 2) {
-	print STDERR "USAGE: mkfringe dads (config.ver)\n";
+	print STDERR "USAGE: $MKFRINGE dads (config.ver)\n";
 	&goodbye; 
     }
@@ -1680,5 +1722,5 @@
     
     if (@ARGV != 1) {
-	print STDERR "USAGE: mkfringe dads.top\n";
+	print STDERR "USAGE: $MKFRINGE dads.top\n";
 	&goodbye; 
     }
@@ -1921,5 +1963,5 @@
     
     if (($mode ne "def") && ($mode ne "med")) {
-	print STDOUT "error in mkfringe mode\n";
+	print STDOUT "error in $MKFRINGE mode\n";
 	&goodbye;
     }
@@ -2069,5 +2111,5 @@
 }
 
-print STDOUT "error: invalid mkfringe command\n";
+print STDOUT "error: invalid $MKFRINGE command\n";
 
 # run:    $root/detrend.config    - current run
@@ -2123,4 +2165,8 @@
 	    last;
 	}
+	if ($type eq "links") {
+	    $value = "$det/flips/links";
+	    last;
+	}
 	if ($type eq "html") {
 	    $value = "$det/html";
@@ -2172,4 +2218,17 @@
 	    $dir = mkfiles ("fringe");
 	    $value = sprintf "$dir/$words[0].$words[1].$words[2].$words[3].master";
+	    last;
+	}
+	# output link file for fhtool
+	if ($type eq "link") {
+	    $dir = mkfiles ("links");
+	    if ($ccd eq "") { &escape ("missing CCD for mknames link"); }
+	    $value = "$dir/$words[0].$words[1].$words[2].$ccd.$words[3].fits";
+	    last;
+	}
+	# output mef file name
+	if ($type eq "mef") {
+	    $dir = mkfiles ("fringe");
+	    $value = "$dir/$words[0].$words[1].$words[2].$words[3].fits";
 	    last;
 	}
@@ -2538,6 +2597,5 @@
     if ($?) { &escape ("error with elixir camera configuration"); }
 
-    $answer = `cameraconfig -ccds`;
-    @ccds = split (" ", $answer); 
+    @ccds = split (" ", `cameraconfig -ccdn`);
     if ($?) { &escape ("error with elixir camera configuration"); }
 
@@ -2589,5 +2647,5 @@
     }
     
-    if (@ARGV > 2) { print STDERR "USAGE: mkfringe (help) [mode]\n"; &goodbye; }
+    if (@ARGV > 2) { print STDERR "USAGE: $MKFRINGE (help) [mode]\n"; &goodbye; }
     
     if ($ARGV[1] eq "config") {
