Index: /branches/czw_branch/20120906/ippScripts/scripts/regenerate_background.pl
===================================================================
--- /branches/czw_branch/20120906/ippScripts/scripts/regenerate_background.pl	(revision 34755)
+++ /branches/czw_branch/20120906/ippScripts/scripts/regenerate_background.pl	(revision 34756)
@@ -11,10 +11,12 @@
 use File::Spec;
 use PS::IPP::Config 1.01 qw( :standard );
-use Getopt::Long qw (GetOtions :config auto_help auto_version gnu_getopt );
+use Getopt::Long qw (GetOptions :config auto_help auto_version gnu_getopt );
 use Pod::Usage qw( pod2usage );
 
+my $ppConfigDump = can_run('ppConfigDump');
+my $pswarp       = can_run('pswarp');
 
 # Parse command line options.
-my ($stage, $camera, $stage_id, $dbname, $verbose, $logfile);
+my ($stage, $camera, $stage_id, $skycell_id, $dbname, $verbose, $logfile, $save_temps);
 GetOptions('stage=s'         => \$stage,       # which analysis stage to generate bkg model
 	   'camera|i=s'      => \$camera,      # user-supplied camera name
@@ -22,5 +24,6 @@
 	   'skycell_id=s'    => \$skycell_id,  # skycell_id
 	   'verbose'         => \$verbose,     # verbose commands
-	   'logfile=s'       => \$logfile      # destination for stdout and stderr  
+	   'logfile=s'       => \$logfile,     # destination for stdout and stderr  
+	   'save_temps'      => \$save_temps   # save temporary files.
     ) or pod2usage ( 2 );
 
@@ -49,5 +52,5 @@
     &my_die("Unable to redirect output to logfile", $stage, $stage_id, $PS_EXIT_UNKNOWN_ERROR) if $logfile;
 
-my $mdcParser = PS:IPP:Metadata::Config->new; # parser for metadata config files
+my $mdcParser = PS::IPP::Metadata::Config->new; # parser for metadata config files
 
 
@@ -64,5 +67,5 @@
     my $astromSource;               # The astrometry source
     {
-	my $command = "$ppConfigDump -camera $camera -recipe PSWARP $recipe_pswarp -dump-recipe PSWARP -";
+	my $command = "$ppConfigDump -camera $camera -recipe PSWARP DEFAULT -dump-recipe PSWARP -";
 	my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
 	    run(command => $command, verbose => $verbose);
@@ -70,16 +73,16 @@
 	    $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
 	    &my_die("Unable to perform ppConfigDump: $error_code", 
-		    $warp_id, $skycell_id, $tess_dir, $error_code);
+		    $stage, $stage_id, $error_code);
 	}
 	my $metadata = $mdcParser->parse(join "", @$stdout_buf) or
 	    &my_die("Unable to parse metadata config doc", 
-		    $warp_id, $skycell_id, $tess_dir, $PS_EXIT_PROG_ERROR);
+		    $stage, $stage_id, $PS_EXIT_PROG_ERROR);
 	$astromSource = metadataLookupStr($metadata, 'ASTROM.SOURCE');
     }
 
-
+    
     my $imfiles;   # Array of component files
     my $command = "$warptool -warped -warp_id $stage_id -skycell_id $skycell_id";
-    my $command .= " -dbname $dbname " if defined $dbname;
+    $command .= " -dbname $dbname " if defined $dbname;
 
     my ( $success, $error_code, $full_buf, $stdout_buf, $stderrr_buf ) = 
@@ -118,5 +121,5 @@
 	my ($bkgList_file,$bkgList_name) = tempfile("/tmp/bkgreg.warp.bkg.${warp_id}.${skycell_id}.XXXX",
 						    UNLINK => !$save_temps);
-	my ($astromList_file,$astroList_name) = tempfile("/tmp/bkgreg.warp.astrom.${warp_id}.${skycell_id}.XXXX",
+	my ($astromList_file,$astromList_name) = tempfile("/tmp/bkgreg.warp.astrom.${warp_id}.${skycell_id}.XXXX",
 							 UNLINK => !$save_temps);
 	my $chipFiles;
@@ -159,5 +162,5 @@
 	if (!$skyCell_exists) { # Generate it
 	    my $skyFile = prepare_output("SKYCELL.TEMPLATE", $path_base, $skycell_id, 1);
-	    $ipprc->skycell_file( $tess_dir, $skycell_id, $skyFile, $verbose ) or
+	    $ipprc->skycell_file( $tess_id, $skycell_id, $skyFile, $verbose ) or
 		&my_die("Unable to generate template skycell",$skycell_id,$warp_id,$PS_EXIT_SYS_ERROR);
 	}
@@ -269,5 +272,5 @@
     my $error;
     my $output = $ipprc->prepare_output($filerule, $outroot, $skycell_id, $delete, \$error)
-	or &my_die("failed to prepare output file for: $filerule", $skycell_id, $warp_id, $error);
+	or &my_die("failed to prepare output file for: $filerule", $skycell_id, $stage_id, $error);
     return $output;
 }
