Index: trunk/ippScripts/scripts/camera_exp.pl
===================================================================
--- trunk/ippScripts/scripts/camera_exp.pl	(revision 33576)
+++ trunk/ippScripts/scripts/camera_exp.pl	(revision 35081)
@@ -41,5 +41,5 @@
 
 my ( $exp_tag, $cam_id, $camera, $outroot, $dbname, $reduction, $dvodb, $verbose, $no_update,
-     $no_op, $redirect, $save_temps, $run_state, $skip_binned, $skip_masks);
+     $no_op, $redirect, $save_temps, $run_state, $skip_binned, $skip_masks, $bkg_only);
 GetOptions(
     'exp_tag=s'         => \$exp_tag, # Exposure identifier
@@ -53,4 +53,5 @@
     'skip-binned'       => \$skip_binned, # override recipe - don't create binned images
     'skip-refmask'      => \$skip_masks, # override recipe - don't create refmask
+    'bkg-only'          => \$bkg_only,  # override recipe - only do background continuity
     'verbose'           => \$verbose,   # Print to stdout
     'no-update'         => \$no_update, # Update the database?
@@ -111,4 +112,5 @@
 &my_die("Unrecognised PSASTRO recipe", $cam_id, $PS_EXIT_CONFIG_ERROR) unless defined $recipe_psastro;
 
+my $bkg_recipe     = 'PPIMAGE_BKGCONT'; # Add to reduction?
 my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files
 
@@ -215,6 +217,10 @@
 my ($list4File, $list4Name) = tempfile( "/tmp/$exp_tag.cm.$cam_id.b4.list.XXXX", UNLINK => !$save_temps ); # For astrometry
 
+### Create temp file for background models
+my ($list5File, $list5Name) = tempfile( "/tmp/$exp_tag.cm.$cam_id.b5.list.XXXX", UNLINK => !$save_temps ); # For background models
+
 # XXX we perform astrometry iff photometry output exists
 my @outMasks;                   # Names of output masks
+my @bkg_models;                 # Names of output background models
 foreach my $file (@$files) {
     next if $file->{quality} != 0;
@@ -226,11 +232,13 @@
     my $chipObjects = $ipprc->filename("PSPHOT.OUTPUT", $file->{path_base}, $class_id);
     my $chipMask   = $ipprc->filename("PPIMAGE.CHIP.MASK", $file->{path_base}, $class_id);
-
+    
     print $list1File ($ipprc->filename("PPIMAGE.BIN1", $file->{path_base}, $class_id) . "\n");
     print $list2File ($ipprc->filename("PPIMAGE.BIN2", $file->{path_base}, $class_id) . "\n");
     print $list3File ($chipObjects . "\n");
     print $list4File ($chipMask . "\n");
+    print $list5File ($ipprc->filename("PSPHOT.BACKMDL", $file->{path_base}, $class_id) . "\n");
 
     push @outMasks, prepare_output("PSASTRO.OUTPUT.MASK", $outroot, $class_id, 1) if $produceMasks;
+    push @bkg_models, prepare_output("PPIMAGE.BACKMDL", $outroot, $class_id, 1);
 }
 close $list1File;
@@ -238,5 +246,5 @@
 close $list3File;
 close $list4File;
-
+close $list5File;
 # Output products
 $ipprc->outroot_prepare($outroot);
@@ -291,5 +299,5 @@
     }
 
-    {
+    if (!$bkg_only) {
         # run psastro on the chipObjects, producing fpaObjects
         my $command;
@@ -353,4 +361,22 @@
             }
         }
+    }
+    # Construct FPA continuity corrected background images
+    {
+	my $command;
+	$command = "$ppImage";
+	$command .= " -list $list5Name $outroot";
+	$command .= " -recipe PPIMAGE $bkg_recipe";
+	$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 perform ppImage to fix background: $error_code", $cam_id, $error_code);
+	}
+	foreach my $bkgModel (@bkg_models) {
+	    check_output($bkgModel, $replicateOutputs);
+	}
     }
 }
