Index: trunk/ippScripts/scripts/sc_prepare_ff.pl
===================================================================
--- trunk/ippScripts/scripts/sc_prepare_ff.pl	(revision 38145)
+++ trunk/ippScripts/scripts/sc_prepare_ff.pl	(revision 38168)
@@ -18,16 +18,9 @@
 use Pod::Usage qw( pod2usage );
 
-# Hard coded values
-# my $remote_root = '/lustre/scratch1/turquoise/watersc1/ps1/'; # Far side destination base location
-my $remote_root     = '/scratch3/watersc1/';
-my $remote_hostname = "LANL/Mustang";         # Name of the remote node.
-my $threads_req     = 4;                      # How many threads are we going to use?
-
-my $fail_state = "prep_fail";
-
 # Look for programs we need
 my $missing_tools;
 my $remotetool = can_run('remotetool') or (warn "Can't find remotetool" 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);
 
 if ($missing_tools) {
@@ -36,5 +29,5 @@
 }
 
-my ($remote_id,$ff_id,$camera,$dbname,$verbose,$path_base,$no_update);
+my ($remote_id,$ff_id,$camera,$dbname,$verbose,$path_base,$no_update,$cmd_recipe);
 GetOptions(
     'remote_id=s'    => \$remote_id,
@@ -42,4 +35,5 @@
     'camera|c=s'     => \$camera,
     'dbname|d=s'     => \$dbname,
+    'recipe=s'       => \$cmd_recipe,
     'path_base=s'    => \$path_base,
     'no_update'      => \$no_update,
@@ -48,10 +42,68 @@
 
 pod2usage( -msg => "Unknown option: @ARGV", -exitval => 2 ) if @ARGV;
-pod2usage( -msg => "Required options: --remote_id -ff_id --camera --dbname --path_base", -exitval => 3) unless
+pod2usage( -msg => "Required options: --remote_id -ff_id --camera --dbname --path_base --recipe", -exitval => 3) unless
     defined($remote_id) and
     defined($ff_id) and
     defined($camera) and
     defined($path_base) and
+    defined($cmd_recipe) and
     defined($dbname);
+
+
+# Hard coded values
+# Now accessible from a recipe
+my %remote_recipe = ();
+{
+    my $verbose = 0;
+    my $conf_cmd = "$ppConfigDump -dump-recipe REMOTE -";
+    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
+        run(command => $conf_cmd, verbose => $verbose);
+    unless ($success) {
+        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
+        &my_die("Unable to perform ppConfigDump: $error_code", -1, $PS_EXIT_SYS_ERROR);
+    }
+    my $mdcParser = PS::IPP::Metadata::Config->new;
+    my $metadata = $mdcParser->parse(join "", @$stdout_buf);
+
+    my $active_recipe = '';
+    my %recipes = ();
+    
+#    print Dumper($metadata);
+    foreach my $entry (@{ $metadata }) {
+        if (${ $entry }{name} eq 'ACTIVE') {
+            $active_recipe = ${ $entry }{value}; # Not actually used
+        }
+        else {
+            if (${ $entry }{class} eq 'metadata') { # A real recipe
+                my $name = ${ $entry }{name};
+                foreach my $tentry (@{ ${ $entry }{value} }) {
+                    if (${ $tentry }{class} eq 'scalar') { # A recipe value
+                        $recipes{$name}{${ $tentry }{name}} = ${ $tentry }{value};
+                    }
+                    elsif (${ $tentry }{class} eq 'metadata') { # A recipe array 
+                        foreach my $arr_entry (@{ ${ $tentry }{value} }) {
+                            push @{ $recipes{$name}{${ $tentry }{name}} }, ${ $arr_entry }{value};
+			}
+		    }
+		}
+	    }
+	}
+    }
+    
+    unless (exists($recipes{$cmd_recipe})) { &my_die("Cannot find recipe $cmd_recipe", -1, $PS_EXIT_CONFIG_ERROR) };
+#    print Dumper(%recipes);
+    %remote_recipe = %{ $recipes{$cmd_recipe} }; # Select the appropriate recipe.
+#    print Dumper(\%remote_recipe);
+}
+
+# my $remote_root = '/lustre/scratch1/turquoise/watersc1/ps1/'; # Far side destination base location
+my $remote_root     = $remote_recipe{REMOTE_ROOT};
+my $remote_hostname = $remote_recipe{REMOTE_HOSTNAME};         # Name of the remote node.
+my $remote_raw      = "${remote_root}/tmp/";  # Directory to find raw data in.
+
+my $threads_req     = 4;                      # How many threads are we going to use?
+
+my $fail_state = "prep_fail";
+
 
 my $ipprc = PS::IPP::Config->new( $camera ) or my_die( "Unable to set up", $remote_id, $ff_id, $PS_EXIT_CONFIG_ERROR, $fail_state);
@@ -126,8 +178,13 @@
 	my $ipp_insourc = $ipprc->filename("PSPHOT.OUTPUT.CFF",$source_pb);
 
-	my ($ipp_disk_inimage, $remote_inimage) = &uri_to_outputs($ipp_inimage);
-	my ($ipp_disk_inmask, $remote_inmask)  = &uri_to_outputs($ipp_inmask);
-	my ($ipp_disk_inwt, $remote_inwt)    = &uri_to_outputs($ipp_inwt);
-	my ($ipp_disk_insourc, $remote_insourc) = &uri_to_outputs($ipp_insourc);
+# 	my ($ipp_disk_inimage, $remote_inimage) = &uri_to_outputs($ipp_inimage);
+# 	my ($ipp_disk_inmask, $remote_inmask)  = &uri_to_outputs($ipp_inmask);
+# 	my ($ipp_disk_inwt, $remote_inwt)    = &uri_to_outputs($ipp_inwt);
+# 	my ($ipp_disk_insourc, $remote_insourc) = &uri_to_outputs($ipp_insourc);
+
+	my (undef,$remote_inimage) = uri_to_outputs_raw($ipp_inimage);
+	my (undef,$remote_inmask)  = uri_to_outputs_raw($ipp_inmask);
+	my (undef,$remote_inwt)    = uri_to_outputs_raw($ipp_inwt);
+	my (undef,$remote_insourc) = uri_to_outputs_raw($ipp_insourc);
 
 	# make any directory we may need
@@ -142,4 +199,5 @@
 		    $remote_id,$ff_id,  $PS_EXIT_CONFIG_ERROR, $fail_state);
 	}
+
 
 
@@ -176,4 +234,6 @@
             print CONFIG " && mkdir -p ${remote_root}/tmp/${remote_outroot_dir} && ln -sf $remote_disk ${remote_root}/tmp/${ipp_disk} && touch $remote_disk ";
         }
+	# If we're this far, we succeeded, so delete the input files.
+	print CONFIG " && rm -f $remote_insourc $remote_inimage $remote_inmask $remote_inwt ";
         print CONFIG "\n";
 #       die();
@@ -234,4 +294,14 @@
     my $neb_uri = shift;
     my ($ipp_disk, $remote_disk) = &uri_convert( $neb_uri );
+
+    print TRANSFER "$ipp_disk\n";
+    print CHECK    "$remote_disk\n";
+    return($ipp_disk,$remote_disk);
+}
+
+sub uri_to_outputs_raw {
+    my $neb_uri = shift;
+    my ($ipp_disk, $remote_disk) = uri_convert( $neb_uri );
+    $remote_disk = $remote_raw . $ipp_disk;
 
     print TRANSFER "$ipp_disk\n";
