Index: /trunk/ippScripts/scripts/automate_stacks.pl
===================================================================
--- /trunk/ippScripts/scripts/automate_stacks.pl	(revision 27859)
+++ /trunk/ippScripts/scripts/automate_stacks.pl	(revision 27860)
@@ -56,5 +56,5 @@
 # Grab options
 my ( $date, $camera, $dbname, $logfile, $verbose, $manual);
-my ( $help, $isburning, $force_stack_count, $test_mode, $this_target_only, $this_filter_only);
+my ( $help, $isburning, $force_stack_count, $test_mode, $this_target_only, $this_filter_only, $check_mode);
 my ( $check_registration, $define_burntool, $queue_burntool, $check_chips, $queue_chips);
 my ( $check_stacks, $queue_stacks, $check_diffs, $queue_diffs, $clean_old);
@@ -70,4 +70,5 @@
     'isburning'            => \$isburning,
     'force_stack_count'    => \$force_stack_count,
+    'check'                => \$check_mode,
     'test_mode'            => \$test_mode,
     'this_target_only=s'   => \$this_target_only,
@@ -116,5 +117,5 @@
     defined $queue_chips or defined $queue_stacks or
     defined $check_chips or defined $check_stacks or
-    defined $test_mode or defined $clean_old;
+    defined $test_mode or defined $clean_old or defined $check_mode;
 
 # Configurable parameters from our config file.
@@ -127,6 +128,7 @@
 my %stackable_list = ();
 my %reduction_class = ();
-my $retention_time = 9000;
-
+my %clean_commands = ();
+my %clean_retention = ();
+my %noclean_list = ();
 # Grab the configuration data.
 my $conf_cmd = "$ppConfigDump -dump-recipe NIGHTLY_SCIENCE -";
@@ -141,7 +143,22 @@
 my $metadata = $mdcParser->parse(join "", @$stdout_buf);
 foreach my $entry (@{ $metadata }) {
-    if (${ $entry }{name} eq 'RETENTION_TIME') {
-        $retention_time = ${ $entry }{value};
-    }
+    if (@{ $entry }{name} eq 'CLEAN_MODES') {
+	my @mode_data = @{ ${ $entry }{value} };
+	my $this_mode = '';
+	foreach my $mentry (@mode_data) {
+	    if (${ $mentry }{name} eq 'MODE') {
+		$this_mode = ${ $mentry }{value};
+	    }
+	    elsif (${ $mentry }{name} eq 'COMMAND') {
+		$clean_commands{$this_mode} = ${ $mentry }{value};
+	    }
+	    elsif (${ $mentry }{name} eq 'RETENTION_TIME') {
+		$clean_retention{$this_mode} = ${ $mentry }{value};
+	    }
+	}
+    }
+#    if (${ $entry }{name} eq 'RETENTION_TIME') {
+#        $retention_time = ${ $entry }{value};
+#    }
     elsif (${ $entry }{name} eq 'FILTERS') {
         push @filter_list, ${ $entry }{value};
@@ -173,4 +190,7 @@
 		$reduction_class{$this_target} = ${ $tentry }{value};
 	    }
+	    elsif (${ $tentry }{name} eq 'NOCLEAN') {
+		$noclean_list{$this_target} = ${ $tentry }{value};
+	    }
         }
     }
@@ -218,11 +238,22 @@
 if (defined($test_mode)) {
     $debug = 1;
-}
-
-if (defined($check_registration) || defined($test_mode)) {
+    my $z;
+    foreach $z (@target_list) {
+	print "TARGET: $z $tessID_list{$z} $obsmode_list{$z} $object_list{$z} $comment_list{$z} $stackable_list{$z} $reduction_class{$z}\n";
+    }
+    foreach $z (@filter_list) {
+	print "FILTER: $z\n";
+    }
+    foreach $z (keys (%clean_commands)) {
+	print "CLEAN: $z $clean_commands{$z} $clean_retention{$z}\n";
+    }
+    
+}
+
+if (defined($check_registration) || defined($test_mode) || defined($check_mode)) {
     $metadata_out{nsState} = 'NEW';
     my ($Nsummit_exp,$Nfaults) = check_summit_copy($date);
     return_metadata($date);
-    unless (defined($test_mode)) { exit(0); }
+    unless (defined($test_mode) || defined($check_mode)) { exit(0); }
 }
 if (defined($define_burntool) || defined($test_mode)) {
@@ -237,5 +268,5 @@
     unless (defined($test_mode)) { exit(0); }
 }
-if (defined($check_chips) || defined($test_mode)) {
+if (defined($check_chips) || defined($test_mode) || defined($check_mode)) {
     $metadata_out{nsState} = 'QUEUECHIPS';
     &execute_chips($date,"pretend");
@@ -244,5 +275,5 @@
     }
     return_metadata($date);
-    unless (defined($test_mode)) { exit(0); }
+    unless (defined($test_mode) || defined($check_mode)) { exit(0); }
 }
 if (defined($queue_chips)) {
@@ -252,5 +283,5 @@
     exit(0);
 }
-if (defined($check_stacks) || defined($test_mode)) {
+if (defined($check_stacks) || defined($test_mode) || defined($check_mode)) {
     $metadata_out{nsState} = 'TOWARP';
     &execute_stacks($date,"pretend");
@@ -259,10 +290,10 @@
     }
     return_metadata($date);
-    unless (defined($test_mode)) { exit(0); }
+    unless (defined($test_mode) || defined($check_mode)) { exit(0); }
 }
 if (defined($queue_stacks)) {
     $metadata_out{nsState} = 'STACKING';
     &execute_stacks($date);
-    if ($metadata_out{nsState} == 'QUEUESTACKING') {
+    if ($metadata_out{nsState} eq 'QUEUESTACKING') {
 	$metadata_out{nsState} = 'STACKING_POSSIBLE_ERROR';
     }
@@ -731,4 +762,8 @@
     my $date = shift;
     my $target = shift;
+    my $mode = shift;
+
+    my $command = $clean_commands{$mode};
+    my $retention_time = $clean_retention{$mode};
 
     my ($year,$month,$day) = split /-/,$date;
@@ -740,6 +775,6 @@
 
     my ($label,$workdir,$obs_mode,$object,$comment,$tess_id,$dist_group,$data_group,$reduction) = get_tool_parameters($cleaning_date,$target);
-
-    my $args .= " -dbname gpc1 -updaterun -set_state goto_cleaned -state full -data_group $data_group ";
+    my $args = $command;
+    $args .= " -dbname gpc1 -updaterun -set_state goto_cleaned -state full -set_label goto_cleaned -label $label -data_group $data_group ";
     if ($debug == 1) {
         $args .= ' -pretend ';
@@ -752,29 +787,22 @@
     my $pretend = shift;
 
-    foreach my $target (@target_list) {
-        my ($cleaning_date,$args) = construct_cleantool_args($date,$target);
-
-        my $command = $chiptool . $args;
-        print STDERR "$command\n";
-        if (!(defined($pretend) || $debug == 1)) {
+    foreach my $mode (keys (%clean_commands)) {
+	foreach my $target (@target_list) {
+	    if (exists($noclean_list{$target})) {
+		next;
+	    }
+	    my ($cleaning_date,$command) = construct_cleantool_args($date,$target,$mode);
+
+	    print STDERR "$command\n";
+	    if (!(defined($pretend) || $debug == 1)) {
 #           print STDERR "BEAR IS DRIVING!?\n";
-            my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
-                run ( command => $command, verbose => $verbose );
-            unless ($success) {
-                $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
-                &my_die("Unable to perform stacktool: $error_code", 0,0,$date, $PS_EXIT_SYS_ERROR);
-            }
-        }
-        $command = $warptool . $args;
-        print STDERR "$command\n";
-        if (!(defined($pretend) || $debug == 1)) {
-#           print STDERR "BEAR IS DRIVING $pretend $debug!?\n";
-            my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
-                run ( command => $command, verbose => $verbose );
-            unless ($success) {
-                $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
-                &my_die("Unable to perform stacktool: $error_code", 0,0,$date, $PS_EXIT_SYS_ERROR);
-            }
-        }
+		my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
+		    run ( command => $command, verbose => $verbose );
+		unless ($success) {
+		    $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
+		    &my_die("Unable to perform stacktool: $error_code", 0,0,$date, $PS_EXIT_SYS_ERROR);
+		}
+	    }
+	}
     }
     return(0);
Index: /trunk/ippTasks/nightly_stacks.pro
===================================================================
--- /trunk/ippTasks/nightly_stacks.pro	(revision 27859)
+++ /trunk/ippTasks/nightly_stacks.pro	(revision 27860)
@@ -164,10 +164,12 @@
 
   task.exec
+    stdout $LOGDIR/ns.initday.log
+    stderr $LOGDIR/ns.initday.log
     $today = `date +%Y-%m-%d`
     book newpage nsData $today
     book setword nsData $today nsState NEW
 
-    command echo $today
-#   command automate_stacks.pl --clean_old --date $today
+#    command echo $today
+   command automate_stacks.pl --clean_old --date $today
   end
 
Index: /trunk/ippconfig/recipes/nightly_science.config
===================================================================
--- /trunk/ippconfig/recipes/nightly_science.config	(revision 27859)
+++ /trunk/ippconfig/recipes/nightly_science.config	(revision 27860)
@@ -1,3 +1,20 @@
 RETENTION_TIME   U16	9000
+
+CLEAN_MODES MULTI
+CLEAN_MODES METADATA
+  MODE STR CHIP
+  COMMAND STR chiptool
+  RETENTION_TIME U16 30
+END
+CLEAN_MODES METADATA
+  MODE STR WARP
+  COMMAND STR warptool
+  RETENTION_TIME U16 7
+END
+CLEAN_MODES METADATA
+  MODE STR DIFF
+  COMMAND STR difftool
+  RETENTION_TIME U16 30
+END
 
 FILTERS MULTI
