Index: trunk/ippScripts/scripts/sc_prepare_warp.pl
===================================================================
--- trunk/ippScripts/scripts/sc_prepare_warp.pl	(revision 37154)
+++ trunk/ippScripts/scripts/sc_prepare_warp.pl	(revision 37833)
@@ -1,3 +1,5 @@
 #! /usr/bin/env perl
+
+# generate the input & output files lists and commands for a single warpRun
 
 use Carp;
@@ -16,21 +18,14 @@
 use Pod::Usage qw( pod2usage );
 
-
 # Hard coded values
-# my $remote_root   = '/scratch3/watersc1/';  
-my $remote_root = '/lustre/scratch1/turquoise/watersc1/ps1/'; # Far side destination base location
-$remote_root = '/scratch3/watersc1/';
-my $threads       = 2;                      # How many threads are we going to use?
-my $job_cost      = 110 / 60 / 60;          # Estimate of how long a job runs, in hours.
-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 $remote_hostname= "LANL/Mustang";         # Name of the remote node.
-my @return_component_list = ("DBINFO.EXP", "PSWARP.CONFIG", "PSWARP.OUTPUT", "PSWARP.OUTPUT.MASK", "PSWARP.OUTPUT.VARIANCE", "PSWARP.OUTPUT.SOURCES","PSPHOT.PSF.SKY.SAVE","LOG.EXP");
+# 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 $warptool    = can_run('warptool') or (warn "Can't find warptool" and $missing_tools = 1);
@@ -41,7 +36,8 @@
 }
 
-my ($remote_id,$warp_id,,$camera,$dbname,$verbose,$path_base,$no_update);
+my ($remote_id,$warp_id,$camera,$dbname,$verbose,$path_base,$no_update);
 GetOptions(
     'remote_id=s'    => \$remote_id,
+    'warp_id=s'      => \$warp_id,
     'camera|c=s'     => \$camera,
     'dbname|d=s'     => \$dbname,
@@ -52,35 +48,18 @@
 
 pod2usage( -msg => "Unknown option: @ARGV", -exitval => 2 ) if @ARGV;
-pod2usage( -msg => "Required options: --remote_id --camera --dbname --path_base", -exitval => 3) unless
+pod2usage( -msg => "Required options: --remote_id -warp_id --camera --dbname --path_base", -exitval => 3) unless
     defined($remote_id) and
+    defined($warp_id) and
     defined($camera) and
     defined($path_base) and
     defined($dbname);
-my $ipprc = PS::IPP::Config->new( $camera ) or my_die( "Unable to set up", $warp_id);
+
+my $ipprc = PS::IPP::Config->new( $camera ) or my_die( "Unable to set up", $remote_id, $warp_id, $PS_EXIT_CONFIG_ERROR, $fail_state);
 
 my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files
 
-#
-# Step 1: Get a list of the components that make up this remoteRun
-
-# SHould this call listrun to ensure we're in state new?
-my $rt_cmd = "$remotetool -listcomponent -remote_id $remote_id";
-$rt_cmd   .= " -dbname $dbname " if defined($dbname);
-
-my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
-    run(command => $rt_cmd, verbose => $verbose);
-unless ($success) {
-    $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
-    &my_die("Unable to run remotetool to determine stage parameters.",
-            $remote_id,$error_code);
-}
-my $compData = $mdcParser->parse(join "", @$stdout_buf) or
-    &my_die("Unable to determine component information.",
-            $remote_id,$PS_EXIT_PROG_ERROR);
-my $compData2= parse_md_list($compData);
-
-#
-# Step 1b: Open output files
-my $uri_command = $path_base . ".cmd";
+my @return_component_list = ("DBINFO.EXP", "PSWARP.CONFIG", "PSWARP.OUTPUT", "PSWARP.OUTPUT.MASK", "PSWARP.OUTPUT.VARIANCE", "PSWARP.OUTPUT.SOURCES","PSPHOT.PSF.SKY.SAVE","LOG.EXP");
+
+# STEP 0: Open output files
 my $uri_transfer= $path_base . ".transfer";
 my $uri_check   = $path_base . ".check";
@@ -89,5 +68,4 @@
 my $uri_return  = $path_base . ".return";
 
-my $disk_command = $ipprc->file_resolve($uri_command,1);
 my $disk_transfer= $ipprc->file_resolve($uri_transfer,1);
 my $disk_check   = $ipprc->file_resolve($uri_check,1);
@@ -96,136 +74,132 @@
 my $disk_return  = $ipprc->file_resolve($uri_return,1);
 
-my (undef, $remote_config) = uri_convert($uri_config); # Needs to be done after we've created it.
-
-open(TRANSFER, ">$disk_transfer")  || &my_die("Couldn't open file? $disk_transfer",$remote_id,$PS_EXIT_SYS_ERROR);
-open(CHECK,    ">$disk_check")  || &my_die("Couldn't open file? $disk_check",$remote_id,$PS_EXIT_SYS_ERROR);
-open(CONFIG,   ">$disk_config")  || &my_die("Couldn't open file? $disk_config",$remote_id,$PS_EXIT_SYS_ERROR);
-open(GENERATE, ">$disk_generate") || &my_die("Couldn't open file? $disk_generate",$remote_id,$PS_EXIT_SYS_ERROR);
-open(RETURN,   ">$disk_return") || &my_die("Couldn't open file? $disk_return", $remote_id, $PS_EXIT_SYS_ERROR);
-
-
-#
-# Step 2: Iterate over all componenets in this remote run.
+my (undef, $remote_config) = &uri_convert($uri_config); # Needs to be done after we've created it.
+
+open(TRANSFER, ">$disk_transfer")  || &my_die("Couldn't open file? $disk_transfer",$remote_id, $warp_id, $PS_EXIT_SYS_ERROR, $fail_state);
+open(CHECK,    ">$disk_check")     || &my_die("Couldn't open file? $disk_check",   $remote_id, $warp_id, $PS_EXIT_SYS_ERROR, $fail_state);
+open(CONFIG,   ">$disk_config")    || &my_die("Couldn't open file? $disk_config",  $remote_id, $warp_id, $PS_EXIT_SYS_ERROR, $fail_state);
+open(GENERATE, ">$disk_generate")  || &my_die("Couldn't open file? $disk_generate",$remote_id, $warp_id, $PS_EXIT_SYS_ERROR, $fail_state);
+open(RETURN,   ">$disk_return")    || &my_die("Couldn't open file? $disk_return",  $remote_id, $warp_id, $PS_EXIT_SYS_ERROR, $fail_state);
+
 my $job_index = 0;
-my @pre_commands = ();
-my @main_commands = ();
-my @post_commands = ();
-
-my %file_filter = ();
-
-foreach my $compEntry (@$compData2) {
-    my $warp_id = $compEntry->{stage_id};
-
-# Get exposure level information from the warpRun we're working from.
+
+# STEP 1: Get exposure level information from the warpRun we're working from.
+my ($warpData);
+{
     # This actually returns all the individual warp/skyfiles that comprise this run.  Because consistency.
     my $command = "$warptool -towarped -warp_id $warp_id ";
     $command   .= " -dbname $dbname " if defined($dbname);
-    ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
-	run(command => $command, verbose => 0);
+
+    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 run warptool -pendingimfile ",
-		$warp_id,$error_code);
-    }
-    my $warpData = $mdcParser->parse(join "", @$stdout_buf) or
-	&my_die("Unable to determine warp component information.",
-		$warp_id,$PS_EXIT_PROG_ERROR);
-    my $warpData2= parse_md_list($warpData);
-
-#
-# Step 3: Iterate over the sub-components
-    foreach my $warpEntry ( @{ $warpData2 } ) {
-	my $workdir = $warpEntry->{workdir};
-	my $exp_tag = $warpEntry->{exp_tag};
-	my $skycell_id = $warpEntry->{skycell_id};
-	my $tess_id = $warpEntry->{tess_id};
-	my $reduction = 'DEFAULT' unless defined $warpEntry->{reduction};
-	my $recipe_pswarp = $ipprc->reduction($reduction, 'WARP_PSWARP'); # Recipe to use                                                                          
-	my $ipp_outroot = "${workdir}/${exp_tag}/${exp_tag}.wrp.${warp_id}.${skycell_id}";
-	print "$ipp_outroot\n";
-	my $remote_outroot = uri_local_to_remote($ipp_outroot);
-
-	my $reg_command = "$warptool -scmap -warp_id $warp_id -skycell_id ${skycell_id}";
-	$reg_command   .= " -dbname $dbname " if defined($dbname);
-	
-	( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
-	    run(command => $reg_command, verbose => 0);
-	unless ($success) {
-	    $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
-	    &my_die("Unable to run warptool -pendingimfile: $reg_command ",
-		    $warp_id,$error_code);
-	}
-    
-	my $inpData = $mdcParser->parse(join "", @$stdout_buf) or
-	    &my_die("Unable to determine warp component information.",
-		    $warp_id, $PS_EXIT_PROG_ERROR);
-	my $inpData2=parse_md_list($inpData);
-	
-	my $pre_cmd_ims = "ls -1 ";
-	my $pre_cmd_masks= "ls -1 ";
-	my $pre_cmd_vars = "ls -1 ";
-	my $pre_cmd_astrom = "";
-
-	foreach my $imfile (@{ $inpData2 }) {
-	    my $image = $ipprc->filename("PPIMAGE.CHIP", $imfile->{chip_path_base}, $imfile->{class_id});
-	    my $mask  = $ipprc->filename("PSASTRO.OUTPUT.MASK", $imfile->{cam_path_base}, $imfile->{class_id});
-	    my $var   = $ipprc->filename("PPIMAGE.CHIP.VARIANCE", $imfile->{chip_path_base}, $imfile->{class_id});
-
-	    my $astrom= $ipprc->filename("PSASTRO.OUTPUT", $imfile->{cam_path_base});
-	    
-	    my $remote_image = uri_local_to_remote($image);
-	    my $remote_mask  = uri_local_to_remote($mask);
-	    my $remote_var   = uri_local_to_remote($var);
-	    my $remote_astrom= uri_local_to_remote($astrom);
-
-	    $pre_cmd_ims     .= " $remote_image ";
-	    $pre_cmd_masks   .= " $remote_mask  "; 
-	    $pre_cmd_vars    .= " $remote_var   "; 
-	    $pre_cmd_astrom   = "echo $remote_astrom > ${remote_outroot}.astrom ";
-	}
-	$pre_cmd_ims   .= "  > ${remote_outroot}.imlist ";
-	$pre_cmd_masks .= "  > ${remote_outroot}.masklist ";
-	$pre_cmd_vars  .= "  > ${remote_outroot}.varlist ";
-
-	my $skycell_command = " dvoImageExtract -D CATDIR /turquoise/usr/projects/ps1/watersc1/tess/${tess_id} $skycell_id -o ${remote_outroot}.skyfile ";
-
-	my $pswarp_command  = " pswarp -list ${remote_outroot}.imlist ";
-	$pswarp_command    .= " -masklist ${remote_outroot}.masklist -variancelist ${remote_outroot}.varlist ";
-	$pswarp_command    .= " -astromlist ${remote_outroot}.astrom ";
-	$pswarp_command    .= " ${remote_outroot} ${remote_outroot}.skyfile ";
-	$pswarp_command    .= " -F PSPHOT.PSF.SAVE PSPHOT.PSF.SKY.SAVE ";
-	$pswarp_command    .= " -F PSPHOT.OUTPUT PSPHOT.OUT.CMF.MEF ";
-	$pswarp_command    .= " -F PSPHOT.BACKMDL PSPHOT.BACKMDL.MEF ";
-	$pswarp_command    .= " -F SOURCE.PLOT.MOMENTS SOURCE.PLOT.SKY.MOMENTS ";
-	$pswarp_command    .= " -F SOURCE.PLOT.PSFMODEL SOURCE.PLOT.SKY.PSFMODEL ";
-	$pswarp_command    .= " -F SOURCE.PLOT.APRESID SOURCE.PLOT.SKY.APRESID ";
-	$pswarp_command    .= " -recipe PSWARP $recipe_pswarp ";
-	$pswarp_command    .= " -tracedest ${remote_outroot}.trace -log ${remote_outroot}.log ";
-	$pswarp_command    .= " -threads 4 "; # -image_id ${image_id} -source_id ${source_id} ";
-	$pswarp_command    .= " -recipe PPSTATS WARPSTATS ";
-	$pswarp_command    .= " -dumpconfig ${remote_outroot}.pswarp.mdc -stats ${remote_outroot}.stats ";
-
-#	print "$pswarp_command \n";
-	
-	my $post_cmd_echo = " echo -n \"warptool  -addwarped -warp_id $warp_id -skycell_id $skycell_id -tess_id $tess_id ";
-	$post_cmd_echo   .= " -path_base $remote_outroot -uri UNKNOWN ";
-	$post_cmd_echo   .=  " -dbname $dbname " if defined $dbname;
-	$post_cmd_echo   .= " -path_base $ipp_outroot -hostname $remote_hostname -dtime_script 0 \" > ${remote_outroot}.dbinfo ";
-	
-	my $post_cmd_SfM  = " ppStatsFromMetadata ${remote_outroot}.stats - WARP_SKYCELL >> ${remote_outroot}.dbinfo ";
-
-	print CONFIG "${pre_cmd_ims} && ${pre_cmd_masks} && ${pre_cmd_vars} && ${pre_cmd_astrom} && ${skycell_command} && ${pswarp_command} && ${post_cmd_echo} && ${post_cmd_SfM} ";
-	$job_index++;
-
-	# Determine which output files need to be returned
-	foreach my $component(@return_component_list) {
-	    my $filename = $ipprc->filename($component,$ipp_outroot,$skycell_id);
-	    my ($ipp_disk, $remote_disk) = uri_to_outputs_for_return( $filename);
-	    my $remote_outroot_dir = dirname($ipp_disk);
-	    print CONFIG " && mkdir -p ${remote_root}/tmp/${remote_outroot_dir} && ln -sf $remote_disk ${remote_root}/tmp/${ipp_disk} && touch $remote_disk ";
-	}
-
-	print CONFIG "\n";
-#	die();
+        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
+        &my_die("Unable to run warptool -pendingimfile ", $remote_id, $warp_id, $error_code, $fail_state);
+    }
+
+    my $MDlist = $mdcParser->parse(join "", @$stdout_buf) or
+        &my_die("Unable to determine warp component information.", $remote_id, $warp_id, $PS_EXIT_PROG_ERROR, $fail_state);
+    $warpData = parse_md_list($MDlist);
+}
+
+# STEP 2: Iterate over the sub-components
+{
+    foreach my $warpEntry ( @{ $warpData } ) {
+        my $workdir = $warpEntry->{workdir};
+        my $exp_tag = $warpEntry->{exp_tag};
+        my $skycell_id = $warpEntry->{skycell_id};
+        my $tess_id = $warpEntry->{tess_id};
+
+        my $reduction = $warpEntry->{reduction};
+        $reduction = 'DEFAULT' unless defined $warpEntry->{reduction};
+
+        my $recipe_pswarp = $ipprc->reduction($reduction, 'WARP_PSWARP'); # Recipe to use
+        if ($recipe_pswarp eq "") {
+            &my_die("Unable to determine PSWARP recipe for $reduction", $remote_id, $warp_id, $PS_EXIT_SYS_ERROR, $fail_state);
+        }
+
+        my $ipp_outroot = "${workdir}/${exp_tag}/${exp_tag}.wrp.${warp_id}.${skycell_id}";
+        print "$ipp_outroot\n";
+        my $remote_outroot = &uri_local_to_remote($ipp_outroot);
+
+        my $command = "$warptool -scmap -warp_id $warp_id -skycell_id ${skycell_id}";
+        $command   .= " -dbname $dbname " if defined($dbname);
+
+        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 run warptool -pendingimfile: $command ", $remote_id, $warp_id, $error_code, $fail_state);
+        }
+
+        my $MDlist = $mdcParser->parse(join "", @$stdout_buf) or
+            &my_die("Unable to determine warp component information.", $remote_id, $warp_id, $PS_EXIT_PROG_ERROR, $fail_state);
+        my $inData = parse_md_list($MDlist);
+
+        my $pre_cmd_ims = "ls -1 ";
+        my $pre_cmd_masks= "ls -1 ";
+        my $pre_cmd_vars = "ls -1 ";
+        my $pre_cmd_astrom = "";
+
+        foreach my $imfile (@{ $inData }) {
+            my $image = $ipprc->filename("PPIMAGE.CHIP", $imfile->{chip_path_base}, $imfile->{class_id});
+            my $mask  = $ipprc->filename("PSASTRO.OUTPUT.MASK", $imfile->{cam_path_base}, $imfile->{class_id});
+            my $var   = $ipprc->filename("PPIMAGE.CHIP.VARIANCE", $imfile->{chip_path_base}, $imfile->{class_id});
+
+            my $astrom= $ipprc->filename("PSASTRO.OUTPUT", $imfile->{cam_path_base});
+
+            my $remote_image = &uri_local_to_remote($image);
+            my $remote_mask  = &uri_local_to_remote($mask);
+            my $remote_var   = &uri_local_to_remote($var);
+            my $remote_astrom= &uri_local_to_remote($astrom);
+
+            $pre_cmd_ims     .= " $remote_image ";
+            $pre_cmd_masks   .= " $remote_mask  ";
+            $pre_cmd_vars    .= " $remote_var   ";
+            $pre_cmd_astrom   = "echo $remote_astrom > ${remote_outroot}.astrom ";
+        }
+        $pre_cmd_ims   .= "  > ${remote_outroot}.imlist ";
+        $pre_cmd_masks .= "  > ${remote_outroot}.masklist ";
+        $pre_cmd_vars  .= "  > ${remote_outroot}.varlist ";
+
+        my $skycell_command = " dvoImageExtract -D CATDIR /turquoise/usr/projects/ps1/watersc1/tess/${tess_id} $skycell_id -o ${remote_outroot}.skyfile ";
+
+        my $pswarp_command  = " pswarp -list ${remote_outroot}.imlist ";
+        $pswarp_command    .= " -masklist ${remote_outroot}.masklist -variancelist ${remote_outroot}.varlist ";
+        $pswarp_command    .= " -astromlist ${remote_outroot}.astrom ";
+        $pswarp_command    .= " ${remote_outroot} ${remote_outroot}.skyfile ";
+        $pswarp_command    .= " -F PSPHOT.PSF.SAVE PSPHOT.PSF.SKY.SAVE ";
+        $pswarp_command    .= " -F PSPHOT.OUTPUT PSPHOT.OUT.CMF.MEF ";
+        $pswarp_command    .= " -F PSPHOT.BACKMDL PSPHOT.BACKMDL.MEF ";
+        $pswarp_command    .= " -F SOURCE.PLOT.MOMENTS SOURCE.PLOT.SKY.MOMENTS ";
+        $pswarp_command    .= " -F SOURCE.PLOT.PSFMODEL SOURCE.PLOT.SKY.PSFMODEL ";
+        $pswarp_command    .= " -F SOURCE.PLOT.APRESID SOURCE.PLOT.SKY.APRESID ";
+        $pswarp_command    .= " -recipe PSWARP $recipe_pswarp ";
+        $pswarp_command    .= " -tracedest ${remote_outroot}.trace -log ${remote_outroot}.log ";
+        $pswarp_command    .= " -threads $threads_req "; # -image_id ${image_id} -source_id ${source_id} ";
+        $pswarp_command    .= " -recipe PPSTATS WARPSTATS ";
+        $pswarp_command    .= " -dumpconfig ${remote_outroot}.pswarp.mdc -stats ${remote_outroot}.stats ";
+
+#       print "$pswarp_command \n";
+
+        my $post_cmd_echo = " echo -n \"warptool  -addwarped -warp_id $warp_id -skycell_id $skycell_id -tess_id $tess_id ";
+        $post_cmd_echo   .=  " -dbname $dbname " if defined $dbname;
+        $post_cmd_echo   .= " -uri ${ipp_outroot}.fits ";
+        $post_cmd_echo   .= " -path_base $ipp_outroot -hostname $remote_hostname -dtime_script 0 \" > ${remote_outroot}.dbinfo ";
+
+        my $post_cmd_SfM  = " ppStatsFromMetadata ${remote_outroot}.stats - WARP_SKYCELL >> ${remote_outroot}.dbinfo ";
+
+        print CONFIG "${pre_cmd_ims} && ${pre_cmd_masks} && ${pre_cmd_vars} && ${pre_cmd_astrom} && ${skycell_command} && ${pswarp_command} && ${post_cmd_echo} && ${post_cmd_SfM} ";
+        $job_index++;
+
+        # Determine which output files need to be returned
+        foreach my $component(@return_component_list) {
+            my $filename = $ipprc->filename($component,$ipp_outroot,$skycell_id);
+            my ($ipp_disk, $remote_disk) = &uri_to_outputs_for_return( $filename);
+            my $remote_outroot_dir = dirname($ipp_disk);
+            print CONFIG " && mkdir -p ${remote_root}/tmp/${remote_outroot_dir} && ln -sf $remote_disk ${remote_root}/tmp/${ipp_disk} && touch $remote_disk ";
+        }
+        print CONFIG "\n";
+#       die();
     }
 }
@@ -236,48 +210,14 @@
 close(GENERATE);
 
-#
-# Construct the moab command last, so we can use the job_index counter to estimate resources.  Somehow.
-my $proc_need = $job_index * $threads;       # how many total processors do we need?
-my $node_need = $proc_need / $proc_per_node; # this equals how many nodes?
-my $time_need = $job_index * $job_cost;      # How many seconds will this take?
-
-my $fill_factor = 0.8;  # This is the factor of how much of the time allocation we'd like to fill
-my ($time_req,$node_req);
-if ($node_need * $job_cost < $fill_factor * $min_nodes * $min_time) {
-    $time_req = $min_time;
-    $node_req = $min_nodes;
-}
-elsif ($node_need * $job_cost > $fill_factor * $max_nodes * $max_time) {
-    $time_req = $max_time;
-    $node_req = $max_nodes;
-    print STDERR "You've requested the construction of a bundle that appears to need $node_need nodes and $job_cost time per job.  This exceeds the max limits ($max_nodes, $max_time).  Using those max values instead.  Good luck.\n";
-}
-else {
-    $time_req = int(($node_need * $job_cost) / ($fill_factor * $max_nodes)) + 1;
-    $node_req = int(($node_need * $job_cost) / ($fill_factor * $time_req)) + 1;
-}
-$time_req += 1; # Safety addition.
-
-open(COMMAND,  ">$disk_command") || &my_die("Couldn't open file? $disk_command",$remote_id,$PS_EXIT_SYS_ERROR);
-print COMMAND "#!/bin/tcsh\n";
-print COMMAND "##### Moab controll lines\n";
-print COMMAND "#MSUB -l nodes=${node_req}:ppn=${proc_per_node},walltime=${time_req}:00:00\n"; ## CHECK RESOURCES
-print COMMAND "#MSUB -j oe\n";
-print COMMAND "#MSUB -V\n";
-print COMMAND "#MSUB -o ${remote_root}warp.${remote_id}.out\n";
-print COMMAND "date\n";
-print COMMAND 'srun -n $SLURM_JOB_NUM_NODES -m cyclic -l /bin/hostname | sort -n | awk \'{printf "%s\n", $2}\' > hosts.${SLURM_JOB_ID}' . "\n";
-print COMMAND "${remote_root}/stask_chip.py $remote_config " . 'hosts.${SLURM_JOB_ID} 1' . "\n";
-print COMMAND "date\n";
-close(COMMAND);
-
 unless($no_update) {
-    my $command = "remotetool -updaterun -remote_id $remote_id ";
-    $command .= " -set_state pending ";
+    my $command = "remotetool -updatecomponent -remote_id $remote_id -stage_id $warp_id ";
+    $command .= " -set_jobs $job_index";
+    $command .= " -set_path_base $path_base";
+    $command .= " -set_state prep_done";
     $command .= " -dbname $dbname " if defined $dbname;
 
     system($command);
 }
-
+exit (0);
 
 ## Common SC routines
@@ -287,7 +227,7 @@
     my $ipp_disk= $ipprc->file_resolve( $neb_uri );
     my $remote_disk = $ipp_disk;
-    
+
     unless(defined($ipp_disk)) {
-        my_die();
+        &my_die( "Unable to generate file for $neb_uri ", $remote_id, $warp_id, $PS_EXIT_SYS_ERROR, $fail_state);
     }
 
@@ -303,7 +243,7 @@
     my $ipp_disk= $ipprc->file_resolve( $neb_uri , 1);
     my $remote_disk = $ipp_disk;
-    
+
     unless(defined($ipp_disk)) {
-        my_die();
+        &my_die( "Unable to generate file for $neb_uri ", $remote_id, $warp_id, $PS_EXIT_SYS_ERROR, $fail_state);
     }
 
@@ -317,11 +257,8 @@
 sub uri_to_outputs { # (ipp_disk,remote_disk) = uri_to_output(neb_uri); Appends to TRANSFER and CHECK filehandles
     my $neb_uri = shift;
-    my ($ipp_disk, $remote_disk) = uri_convert( $neb_uri );
-    
-    unless (exists($file_filter{$neb_uri})) {
-        $file_filter{$neb_uri} = 1;
-        print TRANSFER "$ipp_disk\n";
-        print CHECK    "$remote_disk\n";
-    }
+    my ($ipp_disk, $remote_disk) = &uri_convert( $neb_uri );
+
+    print TRANSFER "$ipp_disk\n";
+    print CHECK    "$remote_disk\n";
     return($ipp_disk,$remote_disk);
 }
@@ -329,10 +266,8 @@
 sub uri_to_outputs_for_return { # (ipp_disk,remote_disk) = uri_to_outputs_for_return(neb_uri); create ipp_disk, append to RETURN and GENERATE
     my $neb_uri = shift;
-    my ($ipp_disk, $remote_disk) = uri_convert_and_create( $neb_uri );
-    unless (exists($file_filter{$neb_uri})) {
-        $file_filter{$neb_uri} = 1;
-        print RETURN "$ipp_disk\n";
-        print GENERATE "$remote_disk\n";
-    }
+    my ($ipp_disk, $remote_disk) = &uri_convert_and_create( $neb_uri );
+
+    print RETURN "$ipp_disk\n";
+    print GENERATE "$remote_disk\n";
     return($ipp_disk,$remote_disk);
 }
@@ -348,5 +283,5 @@
     return($remote_uri);
 }
- 
+
 sub uri_remote_to_local { #(local_neb_uri) = uri_remote_to_local(remote_uri);
     # This needs to replace the remote root directory with the nebulous tag.
@@ -354,5 +289,5 @@
     $remote_uri =~ s%${remote_root}%%;
     my $local_uri  = "neb:///" . $remote_uri;
-    
+
     return($local_uri);
 }
@@ -361,5 +296,6 @@
 sub my_die { # exit with status; my_die(message,stage_id,exit_code,exit_status);
     my $msg = shift;
-    my $id  = shift;
+    my $remote_id  = shift;
+    my $stage_id  = shift;
     my $exit_code = shift;
     my $exit_state = shift;
@@ -368,8 +304,7 @@
 
     carp($msg);
-    
-    if (defined $id and not $no_update) {
-        my $command = "remotetool -updaterun -remote_id $id";
-        $command .= " -fault $exit_code " if defined $exit_code;
+
+    if (defined $remote_id and defined $stage_id and not $no_update) {
+        my $command = "remotetool -updatecomponent -remote_id $remote_id -stage_id $stage_id";
         $command .= " -set_state $exit_state " if defined $exit_state;
         $command .= " -dbname $dbname " if defined $dbname;
