Index: /branches/bills_branches/bills_201312/ippScripts/scripts/psphot_fullforce_warp.pl
===================================================================
--- /branches/bills_branches/bills_201312/ippScripts/scripts/psphot_fullforce_warp.pl	(revision 36393)
+++ /branches/bills_branches/bills_201312/ippScripts/scripts/psphot_fullforce_warp.pl	(revision 36394)
@@ -31,6 +31,5 @@
 my $psphotFullForce = can_run('psphotFullForce') or (warn "Can't find psphotFullForce" and $missing_tools = 1);
 my $ppStatsFromMetadata = can_run('ppStatsFromMetadata') or (warn "Can't find ppStatsFromMetadata" and $missing_tools = 1);
-# XXX: fftool is yet to be written
-my $fftool = "fftool";  # can_run('fftool') or (warn "Can't find fftool" and $missing_tools = 1);
+my $fftool = can_run('fftool') or (warn "Can't find fftool" and $missing_tools = 1);
 if ($missing_tools) {
     warn("Can't find required tools.");
@@ -38,14 +37,14 @@
 }
 
-my ($ffw_id, $warp_id, $skycell_id, $path_base, $sourceroot, $camera);
+my ($ff_id, $warp_id, $skycell_id, $path_base, $sourceroot, $camera);
 my ($outroot, $reduction);
 my ($dbname, $threads, $verbose, $no_update, $no_op, $redirect);
 
 GetOptions(
-    'ffw_id=s'          => \$ffw_id,
+    'ff_id=s'          => \$ff_id,
     'warp_id=s'         => \$warp_id,   # warp identifier
     'skycell_id=s'      => \$skycell_id,# Skycell identifier
     'warp_path_base=s'  => \$path_base, # path_base of the warp skycell
-    'sourceroot=s'      => \$sourceroot,# path_base of sources
+    'sources_path_base=s' => \$sourceroot,# path_base of sources
     'camera=s'          => \$camera,    # camera name of sources
     'dbname|d=s'        => \$dbname,    # Database name
@@ -61,7 +60,7 @@
 pod2usage( -msg => "Unknown option: @ARGV", -exitval => 2 ) if @ARGV;
 pod2usage(
-    -msg => "Required options: --ffw_id --sourceroot --skycell_id --warp_path_base --outroot --camera",
+    -msg => "Required options: --ff_id --sourceroot --skycell_id --warp_path_base --outroot --camera",
     -exitval => 3,
-          ) unless defined $ffw_id,
+          ) unless defined $ff_id,
     and defined $sourceroot
     and (defined $path_base or defined $warp_id) # if we don't have warp's path_base we need warp_id
@@ -70,8 +69,5 @@
     and defined $outroot;
 
-# XXX: fftool is not ready to run commands that update the database
-$no_update = 1;
-
-my $ipprc = PS::IPP::Config->new($camera) or my_die( "Unable to set up", $ffw_id, $skycell_id, $PS_EXIT_CONFIG_ERROR );
+my $ipprc = PS::IPP::Config->new($camera) or my_die( "Unable to set up", $ff_id, $skycell_id, $PS_EXIT_CONFIG_ERROR );
 
 my $neb;
@@ -84,5 +80,5 @@
 
 $ipprc->redirect_to_logfile($logDest) or my_die( "Unable to redirect output", 
-    $ffw_id, $skycell_id, $PS_EXIT_SYS_ERROR ) if $redirect;
+    $ff_id, $skycell_id, $PS_EXIT_SYS_ERROR ) if $redirect;
 
 if (!$path_base) {
@@ -98,14 +94,14 @@
             $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
             &my_die("Unable to perform warptool -warpskyfile -inputskyfile: $error_code", 
-                $ffw_id, $skycell_id, $error_code);
+                $ff_id, $skycell_id, $error_code);
         }
 
         my $metadata = $mdcParser->parse(join "", @$stdout_buf) or
-            &my_die("Unable to parse metadata config doc", $ffw_id, $skycell_id, $PS_EXIT_PROG_ERROR);
+            &my_die("Unable to parse metadata config doc", $ff_id, $skycell_id, $PS_EXIT_PROG_ERROR);
         $files = parse_md_list($metadata) or
-            &my_die("Unable to parse metadata list", $ffw_id, $skycell_id, $PS_EXIT_PROG_ERROR);
-    }
-
-    &my_die("Input list does not contain exactly one elements", $ffw_id, $skycell_id, $PS_EXIT_SYS_ERROR) 
+            &my_die("Unable to parse metadata list", $ff_id, $skycell_id, $PS_EXIT_PROG_ERROR);
+    }
+
+    &my_die("Input list does not contain exactly one elements", $ff_id, $skycell_id, $PS_EXIT_SYS_ERROR) 
         unless scalar @$files == 1;
 
@@ -113,5 +109,5 @@
 
     $path_base = $warp->{path_base};
-    &my_die("Couldn't find input path in warptool output", $ffw_id, $skycell_id, $PS_EXIT_UNKNOWN_ERROR) 
+    &my_die("Couldn't find input path in warptool output", $ff_id, $skycell_id, $PS_EXIT_UNKNOWN_ERROR) 
         unless defined $path_base;
 
@@ -123,5 +119,5 @@
 unless ($recipe_psphot) {
     &my_die("Couldn't find selected reduction for PSPHOT: $reduction\n", 
-        $ffw_id, $skycell_id, $PS_EXIT_CONFIG_ERROR);
+        $ff_id, $skycell_id, $PS_EXIT_CONFIG_ERROR);
 }
 
@@ -134,8 +130,12 @@
 print "recipe_psphot: $recipe_psphot\n";
 
+# use psf measured on input warp
+# XXX: get this from recipe
+my $useWarpPSF = 0;
+
 my $input         = $ipprc->filename('PSWARP.OUTPUT', $path_base);
 my $inputMask     = $ipprc->filename('PSWARP.OUTPUT.MASK', $path_base);
 my $inputVariance = $ipprc->filename('PSWARP.OUTPUT.VARIANCE', $path_base);
-my $inputPSF      = $ipprc->filename('PSPHOT.PSF.SKY.SAVE', $path_base);
+my $inputPSF      = $useWarpPSF ? $ipprc->filename('PSPHOT.PSF.SKY.SAVE', $path_base) : "";
 my $inputSources  = $ipprc->filename('PSPHOT.OUTPUT.CFF', $sourceroot);
 
@@ -144,15 +144,14 @@
     print "inputMask:     $inputMask\n";
     print "inputVariance: $inputVariance\n";
-    # print "inputPath:     $path_base\n";
-    print "inputPSF:      $inputPSF\n";
+    print "inputPSF:      $inputPSF\n" if $inputPSF;
     print "inputSources:  $inputSources\n";
 }
 
 # check that the inputs exist (and have non-zero size)
-&my_die("Couldn't find input: $input", $ffw_id, $skycell_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($input);
-&my_die("Couldn't find input: $inputMask", $ffw_id, $skycell_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($inputMask);
-&my_die("Couldn't find input: $inputVariance", $ffw_id, $skycell_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($inputVariance);
-&my_die("Couldn't find input: $inputPSF", $ffw_id, $skycell_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($inputPSF);
-&my_die("Couldn't find input: $inputSources", $ffw_id, $skycell_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($inputSources);
+&my_die("Couldn't find input: $input", $ff_id, $skycell_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($input);
+&my_die("Couldn't find input: $inputMask", $ff_id, $skycell_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($inputMask);
+&my_die("Couldn't find input: $inputVariance", $ff_id, $skycell_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($inputVariance);
+&my_die("Couldn't find input: $inputPSF", $ff_id, $skycell_id, $PS_EXIT_SYS_ERROR) if ($inputPSF && !$ipprc->file_exists($inputPSF));
+&my_die("Couldn't find input: $inputSources", $ff_id, $skycell_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($inputSources);
 
 my $dump_config = 1; 
@@ -193,5 +192,5 @@
         unless ($success) {
             $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
-            &my_die("Unable to perform ppSub: $error_code", $ffw_id, $skycell_id, $error_code);
+            &my_die("Unable to perform ppSub: $error_code", $ff_id, $skycell_id, $error_code);
         }
 
@@ -207,5 +206,5 @@
             unless ($success) {
                 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
-                &my_die("Unable to perform ppStatsFromMetadata: $error_code", $ffw_id, $skycell_id, $error_code);
+                &my_die("Unable to perform ppStatsFromMetadata: $error_code", $ff_id, $skycell_id, $error_code);
             }
             foreach my $line (@$stdout_buf) {
@@ -226,6 +225,6 @@
 # Add the result to the database
 {
-    my $command = "$fftool -ffw_id $ffw_id -skycell_id $skycell_id";
-    $command .= " -addwarped -path_base $outroot";
+    my $command = "$fftool -ff_id $ff_id"; 
+    $command .= " -addresult -path_base $outroot";
     $command .= " $cmdflags";
     $command .= (" -dtime_script " . ((DateTime->now->mjd - $mjd_start) * 86400));
@@ -239,5 +238,5 @@
             $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
             my $err_message = "Unable to perform fftool -addwarped" ;
-                &my_die("$err_message: $error_code", $ffw_id, $skycell_id, $error_code);
+                &my_die("$err_message: $error_code", $ff_id, $skycell_id, $error_code);
         }
     } else {
@@ -262,5 +261,5 @@
     my $error;
     my $output = $ipprc->prepare_output($filerule, $outroot, undef, $delete, \$error)
-                    or &my_die("failed to prepare output file for: $filerule", $ffw_id, $skycell_id, $error);
+                    or &my_die("failed to prepare output file for: $filerule", $ff_id, $skycell_id, $error);
     return $output;
 }
@@ -275,15 +274,15 @@
     }
 
-    &my_die("Couldn't find expected output file: $file",  $ffw_id, $skycell_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($file);
+    &my_die("Couldn't find expected output file: $file",  $ff_id, $skycell_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($file);
 
     # Funpack to confirm we've really made things correctly
     my $diskfile = $ipprc->file_resolve($file);
     if ($diskfile =~ /fits/) {
-        my $funpack  = can_run('funpack') or &my_die ("Can't find funpack", $ffw_id, $skycell_id, $PS_EXIT_SYS_ERROR);
+        my $funpack  = can_run('funpack') or &my_die ("Can't find funpack", $ff_id, $skycell_id, $PS_EXIT_SYS_ERROR);
 	my $check_command = "$funpack -S $diskfile > /dev/null";
 	my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
 	    run(command => $check_command, verbose => $verbose);
 	if (!$success) {
-	    &my_die("Output file not a valid fits file: $file", $ffw_id, $skycell_id, $PS_EXIT_SYS_ERROR);
+	    &my_die("Output file not a valid fits file: $file", $ff_id, $skycell_id, $PS_EXIT_SYS_ERROR);
 	}
     }
@@ -291,5 +290,5 @@
 
     if ($replicate and $neb) {
-        $ipprc->replicate_file($file) or &my_die("failed to replicate: $file\n",  $ffw_id, $skycell_id, $PS_EXIT_SYS_ERROR);
+        $ipprc->replicate_file($file) or &my_die("failed to replicate: $file\n",  $ff_id, $skycell_id, $PS_EXIT_SYS_ERROR);
     }
 }
@@ -299,5 +298,5 @@
 {
     my $msg = shift;            # Warning message on die
-    my $ffw_id = shift;         # full force warp identifier
+    my $ff_id = shift;         # full force warp identifier
     my $skycell_id = shift;     # Skycell identifier
     my $exit_code = shift;      # Exit code to add
@@ -306,7 +305,7 @@
 
     warn($msg);
-    if (defined $ffw_id and defined $skycell_id) {
-        my $command = "$fftool -ffw_id $ffw_id -skycell_id $skycell_id -fault $exit_code";
-        $command .= " -addffskyfile";
+    if (defined $ff_id and defined $skycell_id) {
+        my $command = "$fftool -ff_id $ff_id -fault $exit_code";
+        $command .= " -addresult";
         $command .= (" -dtime_script " . ((DateTime->now->mjd - $mjd_start) * 86400));
         $command .= " -hostname $host" if defined $host;
