Index: trunk/ippScripts/scripts/automate_stacks.pl
===================================================================
--- trunk/ippScripts/scripts/automate_stacks.pl	(revision 27512)
+++ trunk/ippScripts/scripts/automate_stacks.pl	(revision 27513)
@@ -55,5 +55,5 @@
 
 # Grab options
-my ( $date, $camera, $dbname, $logfile, $verbose);
+my ( $date, $camera, $dbname, $logfile, $verbose, $manual);
 my ( $help, $isburning, $force_stack_count, $test_mode, $this_target_only, $this_filter_only);
 my ( $check_registration, $define_burntool, $queue_burntool, $check_chips, $queue_chips);
@@ -125,4 +125,5 @@
 my %comment_list= ();
 my %stackable_list = ();
+my %reduction_class = ();
 my $retention_time = 9000;
 
@@ -168,4 +169,7 @@
                 $stackable_list{$this_target} = ${ $tentry }{value};
             }
+	    elsif (${ $tentry }{name} eq 'REDUCTION') {
+		$reduction_class{$this_target} = ${ $tentry }{value};
+	    }
         }
     }
@@ -307,5 +311,5 @@
         $Nsummit_exps++;
         if ($summit_fault) {
-            print STDERR "check_summit_copy: $date $exp_name has summit_fault $summit_fault";
+	    print STDERR "check_summit_copy: $date $exp_name has summit_fault $summit_fault";
             if ($exp_type ne 'OBJECT') {
                 print STDERR " (but I don't care).\n";
@@ -450,5 +454,5 @@
     my $target = shift;
 
-    my ($label,$workdir,$obs_mode,$object,$comment,$tess_id,$dist_group,$data_group) = get_tool_parameters($date,$target);
+    my ($label,$workdir,$obs_mode,$object,$comment,$tess_id,$dist_group,$data_group,$reduction) = get_tool_parameters($date,$target);
 
     my $select =  "-dateobs_begin ${date}T00:00:00 -dateobs_end ${date}T23:59:59 ";
@@ -469,4 +473,7 @@
         $cmd .= " -comment '$comment' ";
     }
+    if (defined($reduction)) {
+	$cmd .= " -set_reduction $reduction ";
+    }
     $cmd .= " $select ";
     if ($debug == 1) {
@@ -484,5 +491,5 @@
     my $db = init_gpc_db();
     $date =~ s/-//g;
-    my ($label,$workdir,$obs_mode,$object,$comment,$tess_id,$dist_group,$data_group) = get_tool_parameters($date,$target);
+    my ($label,$workdir,$obs_mode,$object,$comment,$tess_id,$dist_group,$data_group,$reduction) = get_tool_parameters($date,$target);
 
     my $sth = "SELECT exp_id from chipRun where data_group = '$data_group' AND exp_id = $exp_id";
@@ -543,13 +550,13 @@
         my ($Nexposures,$Nimfiles,$Nburntooled,$Nalready) = pre_chip_queue($date,$target);
         if ($Nexposures == 0) {
-            print STDERR "execute_chips: Target $target on $date had no exposures.\n";
+	    print STDERR "execute_chips: Target $target on $date had no exposures.\n";
+	    next;
+        }
+        if ($Nalready != 0) {
+	    print STDERR "execute_chips: Not queueing $target on $date due to already existing exposures.\n";
             next;
         }
-        if ($Nalready != 0) {
-            print STDERR "execute_chips: Not queueing $target on $date due to already existing exposures.\n";
-            next;
-        }
         if ($Nimfiles != $Nburntooled) {
-            print STDERR "execute_chips: Target $target on $date is not fully burntooled.\n";
+	    print STDERR "execute_chips: Target $target on $date is not fully burntooled.\n";
             $metadata_out{nsState} = 'NEEDSBURNING';
             next;
@@ -574,5 +581,5 @@
     my $filter = shift;
 
-    my ($label,$workdir,$obs_mode,$object,$comment,$tess_id,$dist_group,$data_group) = get_tool_parameters($date,$target);
+    my ($label,$workdir,$obs_mode,$object,$comment,$tess_id,$dist_group,$data_group,$reduction) = get_tool_parameters($date,$target);
 
     my $select =  "-select_dateobs_begin ${date}T00:00:00 -select_dateobs_end ${date}T23:59:59 ";
@@ -603,5 +610,5 @@
     my $db = init_gpc_db();
     $date =~ s/-//g;
-    my ($label,$workdir,$obs_mode,$object,$comment,$tess_id,$dist_group,$data_group) = get_tool_parameters($date,$target);
+    my ($label,$workdir,$obs_mode,$object,$comment,$tess_id,$dist_group,$data_group,$reduction) = get_tool_parameters($date,$target);
 
     my $sth = "SELECT skycell_id from stackRun where data_group = '$data_group' AND skycell_id = '$skycell' AND filter = '$filter'";
@@ -616,5 +623,5 @@
     my $filter = shift;
 
-    my ($label,$workdir,$obs_mode,$object,$comment,$tess_id,$dist_group,$data_group) = get_tool_parameters($date,$target);
+    my ($label,$workdir,$obs_mode,$object,$comment,$tess_id,$dist_group,$data_group,$reduction) = get_tool_parameters($date,$target);
     # check warp stage == chip stage
     my $db = init_gpc_db();
@@ -716,5 +723,5 @@
     my $cleaning_date = $dt->ymd;
 
-    my ($label,$workdir,$obs_mode,$object,$comment,$tess_id,$dist_group,$data_group) = get_tool_parameters($cleaning_date,$target);
+    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 ";
@@ -779,6 +786,6 @@
     my $data_group = "${target}.${trunc_date}";
     my $tess_id = $tessID_list{$target};
-
-    return($label,$workdir,$obs_mode,$object,$comment,$tess_id,$dist_group,$data_group);
+    my $reduction = $reduction_class{$target};
+    return($label,$workdir,$obs_mode,$object,$comment,$tess_id,$dist_group,$data_group,$reduction);
 }
 
