Index: trunk/ippScripts/scripts/chip_imfile.pl
===================================================================
--- trunk/ippScripts/scripts/chip_imfile.pl	(revision 23540)
+++ trunk/ippScripts/scripts/chip_imfile.pl	(revision 23548)
@@ -35,7 +35,9 @@
 }
 
+my @ARGS = @ARGV;
+
 # Parse the command-line arguments
 my ( $exp_id, $chip_id, $class_id, $chip_imfile_id, $uri, $camera, $outroot, $dbname, $run_state, $reduction, $threads, $verbose,
-     $no_update, $no_op, $redirect, $magicked );
+     $no_update, $no_op, $redirect, $magicked, $deburned );
 GetOptions(
     'exp_id=s'          => \$exp_id,    # Exposure identifier
@@ -49,5 +51,6 @@
     'reduction=s'       => \$reduction, # Reduction class
     'run-state=s'       => \$run_state, # current state of the run (new, update)
-    'magicked'          => \$magicked,  # magicked state of intput file
+    'magicked'          => \$magicked,  # magicked state of input file
+    'deburned=s'        => \$deburned,  # does deburned image exist? 
     'threads=s'         => \$threads,   # Number of threads to use for ppImage
     'verbose'           => \$verbose,   # Print to stdout
@@ -78,5 +81,5 @@
     print STDOUT "\n\n";
     print STDOUT "Starting script $0 on $host\n\n";
-    print STDOUT "COMMAND IS: @ARGV\n\n";
+    print STDOUT "FULL COMMAND: $0 @ARGS\n\n";
 }
 
@@ -124,4 +127,22 @@
     my $command;
     my $do_stats;
+
+    ## get the ppImage recipe for this camera and CHIP reduction
+    $command = "$ppConfigDump -camera $camera -dump-recipe PPIMAGE -recipe PPIMAGE $recipe_ppImage -";
+    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 ppConfigDump: $error_code", $exp_id, $chip_id, $class_id, $PS_EXIT_SYS_ERROR);
+    }
+    my $recipeData = $mdcParser->parse(join "", @$stdout_buf) or
+        &my_die("Unable to parse metadata config doc", $exp_id, $chip_id, $class_id, $PS_EXIT_SYS_ERROR);
+
+    ## XXX make the feature more general?
+    my $useDeburnedImage = metadataLookupBool($recipeData, 'USE.DEBURNED.IMAGE');
+    if ($useDeburnedImage && $deburned) {
+	$uri =~ s/fits$/burn.tbl/;
+	&my_die("Couldn't find deburned input file: $uri\n", $exp_id, $chip_id, $class_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($uri);
+    }
 
     if ($run_state eq "new") {
@@ -151,5 +172,5 @@
     }
 
-    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
+    ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
         run(command => $command, verbose => $verbose);
     unless ($success) {
@@ -157,15 +178,4 @@
         &my_die("Unable to perform ppImage: $error_code", $exp_id, $chip_id, $class_id, $error_code);
     }
-
-    ## get the ppImage recipe for this camera and CHIP reduction
-    $command = "$ppConfigDump -camera $camera -dump-recipe PPIMAGE -recipe PPIMAGE $recipe_ppImage -";
-    ( $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 ppConfigDump: $error_code", $exp_id, $chip_id, $class_id, $PS_EXIT_SYS_ERROR);
-    }
-    my $recipeData = $mdcParser->parse(join "", @$stdout_buf) or
-        &my_die("Unable to parse metadata config doc", $exp_id, $chip_id, $class_id, $PS_EXIT_SYS_ERROR);
 
     ## allow the output images to be optional, depending on the recipe / reduction class
