Index: trunk/ippScripts/scripts/addstar_run.pl
===================================================================
--- trunk/ippScripts/scripts/addstar_run.pl	(revision 38709)
+++ trunk/ippScripts/scripts/addstar_run.pl	(revision 38937)
@@ -31,6 +31,11 @@
 my $addtool = can_run('addtool') or (warn "Can't find addtool" and $missing_tools = 1);
 my $camtool = can_run('camtool') or (warn "Can't find camtool" and $missing_tools = 1);
+my $fftool  = can_run('fftool') or (warn "Can't find fftool" and $missing_tools = 1);
+
 my $ppConfigDump = can_run('ppConfigDump') or (warn "Can't find ppConfigDump" and $missing_tools = 1);
+
 my $addstar = can_run('addstar') or (warn "Can't find addstar" and $missing_tools = 1);
+my $loadgalphot = can_run('loadgalphot') or (warn "Can't find loadgalphot" and $missing_tools = 1);
+
 if ($missing_tools) {
     warn("Can't find required tools.");
@@ -92,4 +97,15 @@
 }
 
+my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files
+
+# Output products
+$ipprc->outroot_prepare($outroot);
+
+
+#
+# Step 1: sort out reductions / recipes
+#
+
+
 # Recipes to use based on reduction class
 $reduction = 'DEFAULT' unless defined $reduction;
@@ -101,9 +117,12 @@
 #} 
 
-if ($stage =~/fullforce/) {
+if ($stage eq 'fullforce') {
     $reduction='DEFAULT';
     #hardwired because why not
 }
-if ($stage =~/diff/) {
+elsif ($stage eq 'fullforce_summary') {
+    $reduction = 'DEFAULT';
+}
+elsif ($stage eq 'diff') {
     $reduction='DEFAULT';
     #hardwired because why not
@@ -112,16 +131,16 @@
 my $recipe_addstar = $ipprc->reduction($reduction, 'ADDSTAR');
 # XXX This is now not used: do we still need it?
-if ($stage =~/cam/) {
+if ($stage eq 'cam') {
   $recipe_addstar = $ipprc->reduction($reduction, 'ADDSTAR'); # Recipe to use
 }
-if ($stage =~/stack/) {
+elsif ($stage eq 'stack') {
   $recipe_addstar = $ipprc->reduction($reduction, 'ADDSTAR_STACK'); # Recipe to use
+}
+elsif ($stage eq 'skycal') {
+    $recipe_addstar = $ipprc->reduction($reduction, 'ADDSTAR'); # Recipe to use                                                              
 }
 #if ($stage =~/staticsky/) {
 #  $recipe_addstar = $ipprc->reduction($reduction, 'ADDSTAR_STATICSKY'); # Recipe to use
 #}
-if ($stage =~/skycal/) {
-    $recipe_addstar = $ipprc->reduction($reduction, 'ADDSTAR'); # Recipe to use                                                              
-}
 
 
@@ -129,10 +148,11 @@
 &my_die("Unrecognised ADDSTAR recipe", $add_id, $PS_EXIT_CONFIG_ERROR) unless defined $recipe_addstar;
 
-my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files
-
-# Output products
-$ipprc->outroot_prepare($outroot);
 
 # the camera configurations should define the psastro output to be a single file (MEF), regardless of the inputs
+
+#
+# Step 2: Determine where sources should come from, modify them as needed.
+#
+
 
 # it was PSASTRO.OUTPUT
@@ -141,18 +161,16 @@
 my $fpaObjectsAlt = $fpaObjects;
 
-if ($stage =~ /skycal/) {
+if ($stage eq 'skycal') {
     #should be ok for skycal?
     print "using $fpaObjects for $stage\n";
 }
-if ($stage =~/diff/) {
+elsif ($stage eq 'diff') {
     print "using $fpaObjects for $stage\n";
 }
-if ($stage =~/fullforce/)  {
+elsif ($stage eq 'fullforce')  {
     print "using $fpaObjects for $stage\n";
 } 
 
-
-
-if ($stage =~ /cam/) {
+if ($stage eq 'cam') {
     # if it is cam stage we need to be careful when grabbing the filename. 
     # This breaks down into a few steps: 
@@ -197,8 +215,11 @@
 }
 
-if (($stage =~/stack/ || $stage =~ /skycal/ || $stage =~/diff/ || $stage=~/fullforce/)) {
+if (($stage eq 'stack') || 
+    ($stage eq 'skycal') || 
+    ($stage eq 'diff') || 
+    ($stage eq 'fullforce')||
+    ($stage eq 'fullforce_summary')) {
     $fpaObjects =~ s/smf$/cmf/;
     $fpaObjectsAlt =~ s/smf$/cmf/;
-
 }
 
@@ -206,5 +227,5 @@
 my $fpaObjects2;
 my $checkalt = 0;
-if ($stage =~/staticsky/) {
+if ($stage eq 'staticsky') {
     $checkalt = 1;
     my $sources   = $ipprc->filename("PSPHOT.OUT.CMF.MEF", $stageroot); #this is mostly rigtht except the .cmf needs either
@@ -239,7 +260,10 @@
 	$fpaObjects = $fpaObjects1;
     }
-     
-
-}
+}
+
+
+#
+# Step 3 Set up addtool/loadgalphot commands.
+#
 
 my $traceDest  = $ipprc->filename("TRACE.EXP",          $outroot) or &my_die("Missing entry from camera config", $add_id, $PS_EXIT_CONFIG_ERROR);
@@ -251,8 +275,9 @@
     $dvodbReal = $ipprc->convert_filename_absolute( $dvodbReal ) or &my_die("can't get path for dvodb", $add_id, $PS_EXIT_CONFIG_ERROR);
 }
+
 my $dtime_addstar = 0;
 if (defined $dvodbReal) {
     if ($minidvodb) {
-	my $command = "addtool -listminidvodbrun ";
+	my $command = "$addtool -listminidvodbrun ";
 	$command .= " -minidvodb_group $minidvodb_group" if defined $minidvodb_group;
 	$command .= " -minidvodb_name $minidvodb_name" if defined $minidvodb_name;
@@ -285,5 +310,4 @@
     unless ($no_op) {
             print $dvodbReal;
-	    
 	    ## addstar can either save the full set of detections, or just
 	    ## the image metadata, in the dvodb.  this is set in the
@@ -311,27 +335,62 @@
 	    }		
 
-	    # require a defined output dvo database to run addstar (ie, refuse to use the .ptolemyrc default)
-	    my $command  = "$addstar -update"; # XXX optionally set -update?
-	    $command .= " -D CAMERA $camdir";
-	    $command .= " -D CATDIR $minidvodb_path";
-	    $command .= " -D ZERO_POINT_OPTION $zeroPointOption";
-	    $command .= " $realFile";
-	    $command .= " -use-name $fpaObjects"; # DVO wants the neb-name as a file reference
-	    $command .= " -image" if $image_only;
-	    if ($stage =~ /staticsky/) {
-		$command .= " -accept-astrom -quick-airmass";
-	    }  #careful here - this matches staticsky and staticsky_multi
-	    if ($stage =~ /skycal/) {
-		$command .= " -quick-airmass";
-	    }  #careful here - this matches staticsky and staticsky_multi
-	    if ($stage =~ /diff/) {
-		$command .= " -accept-astrom";
+	    my $command;
+
+	    if ($stage ne 'fullforce_summary') {
+		# require a defined output dvo database to run addstar (ie, refuse to use the .ptolemyrc default)
+		$command  = "$addstar -update"; # XXX optionally set -update?
+		$command .= " -D CAMERA $camdir";
+		$command .= " -D CATDIR $minidvodb_path";
+		$command .= " -D ZERO_POINT_OPTION $zeroPointOption";
+		$command .= " $realFile";
+		$command .= " -use-name $fpaObjects"; # DVO wants the neb-name as a file reference
+		$command .= " -image" if $image_only;
+		if ($stage =~ /staticsky/) {
+		    $command .= " -accept-astrom -quick-airmass";
+		}  #careful here - this matches staticsky and staticsky_multi
+		if ($stage =~ /skycal/) {
+		    $command .= " -quick-airmass";
+		}  #careful here - this matches staticsky and staticsky_multi
+		if ($stage =~ /diff/) {
+		    $command .= " -accept-astrom";
+		}
+		if ($stage =~ /fullforce/) {
+		    $command .= " -accept-astrom -xrad"; 
+		}
 	    }
-	    if ($stage =~ /fullforce/) {
-		$command .= " -accept-astrom -xrad"; 
+	    else { # Full force summary case
+		# We need to know the filter to set up the photcode, as the summaries do not include that in the header.
+		# We /could/ set up the addtool stuff to pass that in to the script when needed, but that would require adding 
+		# a lot of extra hooks and option handlers.  Therefore, call out to fftool, and get the filter that way, and
+		# construct the correct photcode.
+
+		my $photcode = '';
+		{
+		    my $ff_command = "$fftool -dbname ${dbname} -summary -ff_id ${stage_id}";
+		    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 fetch filter via fftool: $error_code", $add_id, $error_code);
+		    }
+		    my $MDlist = $mdcParser->parse(join "", @$stdout_buf) or
+			&my_die("Unable to determine ff summary information.", $add_id, $error_code);
+		    my $metadata = parse_md_list($MDlist);
+		    my $ffSummary = $metadata->[0];
+		    my $filter = $ffSummary->{filter};
+		    
+		    $filter =~ s/\.00000//;
+		    $photcode = "GPC1.${filter}.ForcedWarp";
+		}
+
+		$command =  "$loadgalphot -v ";
+		$command .= " -D CAMERA $camdir ";
+		$command .= " -D CATDIR $minidvodb_path ";
+		$command .= " $realFile ";
+		$command .= " -p $photcode ";
 	    }
-
+		    
 	    my $mjd_addstar_start = DateTime->now->mjd;   # MJD of starting script
-
+	    
 	    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
 		run(command => $command, verbose => $verbose);
