Index: trunk/ippScripts/scripts/sc_prepare_run.pl
===================================================================
--- trunk/ippScripts/scripts/sc_prepare_run.pl	(revision 38145)
+++ trunk/ippScripts/scripts/sc_prepare_run.pl	(revision 38168)
@@ -21,7 +21,85 @@
 use Pod::Usage qw( pod2usage );
 
+#use Data::Dumper;
+# Look for programs we need
+my $missing_tools;
+my $remotetool = can_run('remotetool') or (warn "Can't find remotetool" and $missing_tools = 1);
+my $ppConfigDump = can_run('ppConfigDump') or (warn "Can't find ppConfigDump" and $missing_tools = 1);
+
+if ($missing_tools) {
+    warn("Can't find required tools.");
+    exit($PS_EXIT_CONFIG_ERROR);
+}
+
+# Options
+my ($remote_id,$cmd_recipe,$stage,$camera,$path_base,$dbname,$verbose,$no_update);
+GetOptions(
+    'remote_id=s'    => \$remote_id,
+    'recipe=s'       => \$cmd_recipe,
+    'stage=s'        => \$stage,
+    'camera|c=s'     => \$camera,
+    'path_base=s'    => \$path_base,
+    'dbname|d=s'     => \$dbname,
+    'verbose'        => \$verbose,
+    'no_update'      => \$no_update,
+    ) or pod2usage( 2 );
+
+pod2usage( -msg => "Unknown option: @ARGV", -exitval => 2 ) if @ARGV;
+pod2usage( -msg => "Required options: --remote_id --stage --camera --dbname --path_base --recipe", -exitval => 3) unless
+    defined($remote_id) and
+    defined($stage) and
+    defined($camera) and
+    defined($path_base) and
+    defined($cmd_recipe) and
+    defined($dbname) and
+    defined($dbname);
+
 # Hard coded values
-# my $remote_root   = '/lustre/scratch1/turquoise/watersc1/ps1/'; # Far side destination base location
-my $remote_root = '/scratch3/watersc1/';
+# 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 = $remote_recipe{REMOTE_ROOT};
 my $remote_raw  = "${remote_root}/tmp/";  # Directory to find raw data in.
 
@@ -51,42 +129,15 @@
 $job_subscription{"ff"} = 1;
 
-my $proc_per_node = 24;                     # processors per node
-my $min_nodes     = 1;                      # smallest allocation to ask for
-my $max_nodes     = 1000;                   # largest allocation to ask for
-my $min_time      = 1;                      # shortest allocation to ask for
-my $max_time      = 8;                      # longest allocation to ask for
+my $proc_per_node = $remote_recipe{PROC_PER_NODE};  # processors per node
+my $min_nodes     = $remote_recipe{MIN_NODES};      # smallest allocation to ask for
+my $max_nodes     = $remote_recipe{MAX_NODES};      # largest allocation to ask for
+my $min_time      = $remote_recipe{MIN_TIME};       # shortest allocation to ask for
+my $max_time      = $remote_recipe{MAX_TIME};       # longest allocation to ask for
 
 # We need to ensure we only ever try to transfer a file once.
 my %file_filter = ();
 
-# Look for programs we need
-my $missing_tools;
-my $remotetool = can_run('remotetool') or (warn "Can't find remotetool" and $missing_tools = 1);
-
-if ($missing_tools) {
-    warn("Can't find required tools.");
-    exit($PS_EXIT_CONFIG_ERROR);
-}
-
-# Options
-my ($remote_id,$stage,$camera,$path_base,$dbname,$verbose,$no_update);
-GetOptions(
-    'remote_id=s'    => \$remote_id,
-    'stage=s'        => \$stage,
-    'camera|c=s'     => \$camera,
-    'path_base=s'    => \$path_base,
-    'dbname|d=s'     => \$dbname,
-    'verbose'        => \$verbose,
-    'no_update'      => \$no_update,
-    ) or pod2usage( 2 );
-
-pod2usage( -msg => "Unknown option: @ARGV", -exitval => 2 ) if @ARGV;
-pod2usage( -msg => "Required options: --remote_id --stage --camera --dbname --path_base", -exitval => 3) unless
-    defined($remote_id) and
-    defined($stage) and
-    defined($camera) and
-    defined($path_base) and
-    defined($dbname);
-
+
+# Finish setup
 my $ipprc = PS::IPP::Config->new( $camera ) or &my_die( "Unable to set up", $remote_id, $PS_EXIT_CONFIG_ERROR, $fail_state);
 
