Index: /branches/czw_branch/20120906/ippScripts/scripts/regenerate_background.pl
===================================================================
--- /branches/czw_branch/20120906/ippScripts/scripts/regenerate_background.pl	(revision 34745)
+++ /branches/czw_branch/20120906/ippScripts/scripts/regenerate_background.pl	(revision 34746)
@@ -20,4 +20,5 @@
 	   'camera|i=s'      => \$camera,      # user-supplied camera name
 	   'stage_id=s'      => \$stage_id,    # id for this stage
+	   'skycell_id=s'    => \$skycell_id,  # skycell_id
 	   'verbose'         => \$verbose,     # verbose commands
 	   'logfile=s'       => \$logfile      # destination for stdout and stderr  
@@ -33,4 +34,8 @@
     defined $stage_id;
 
+pod2usage( -msg => "Required options: --camera (name) --stage (stage) --stage_id (stage_id) --skycell_id (skycell_id)",
+	   -exitval => 3) if (($stage eq 'warp')&&(!defined($skycell_id)));
+
+
 my $ipprc = PS::IPP::Config->new ( $camera ) or 
     &my_die("Unable to set up", $stage, $stage_id, $PS_EXIT_CONFIG_ERROR); # used for path/neb info
@@ -51,4 +56,5 @@
     my $warp_id = $stage_id; # Because I think I used the wrong id in places.
     &my_die("--stage_id required for stage warp", $stage, $stage_id, $PS_EXIT_CONFIG_ERROR) if !$stage_id;
+    &my_die("--skycell_id required for stage warp", $stage, $stage_id, $PS_EXIT_CONFIG_ERROR) if !$skycell_id;
 
     # Configuration stuff
@@ -74,5 +80,5 @@
 
     my $imfiles;   # Array of component files
-    my $command = "$warptool -warped -warp_id $stage_id";
+    my $command = "$warptool -warped -warp_id $stage_id -skycell_id $skycell_id";
     my $command .= " -dbname $dbname " if defined $dbname;
 
@@ -104,6 +110,7 @@
 	my $poor_quality = $imfile->{quality} > 0;
 	
-	my $bkg_file = $ipprc->filename("PSWARP.OUTPUT.BKGMODEL",$path_base,$skycell_id);
-	my $bkg_exists = $ipprc->file_exists($bkg_file);
+# 	my $bkg_file = $ipprc->filename("PSWARP.OUTPUT.BKGMODEL",$path_base,$skycell_id);
+# 	my $bkg_exists = $ipprc->file_exists($bkg_file);
+	my $bkg_exists = $imfile->{background_model};
 	if ($bkg_exists) { $status = 0; } # We do not need to remake this.	
 
@@ -218,4 +225,8 @@
     foreach my $imfile (@$imfiles) {
 	if ($imfile->{ignored}) {next; }
+	unless ($imfile->{background_model}) {
+	    &my_die("Not all inputs have valid background models",
+		    $stage,$stage_id,$PS_EXIT_PROG_ERROR);
+	}
 	print $inputMDC_file "INPUT${num}\tMETADATA\n";
 	
