Index: trunk/ippScripts/scripts/chip_imfile.pl
===================================================================
--- trunk/ippScripts/scripts/chip_imfile.pl	(revision 24379)
+++ trunk/ippScripts/scripts/chip_imfile.pl	(revision 24396)
@@ -20,4 +20,5 @@
 use PS::IPP::Metadata::Config;
 use PS::IPP::Config 1.01 qw( :standard );
+use File::Temp qw( tempfile );
 
 use Getopt::Long qw( GetOptions :config auto_help auto_version gnu_getopt );
@@ -39,5 +40,5 @@
 # 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, $deburned );
+     $no_update, $save_temps, $no_op, $redirect, $magicked, $deburned );
 GetOptions(
     'exp_id=s'          => \$exp_id,    # Exposure identifier
@@ -58,4 +59,5 @@
     'no-op'             => \$no_op,     # Don't do any operations?
     'redirect-output'   => \$redirect,
+    'save-temps'        => \$save_temps, # Save temporary files?
     ) or pod2usage( 2 );
 
@@ -144,4 +146,44 @@
         $uri =~ s/fits$/burn.fits/;
         &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);
+    }
+
+    # apply the 'tiltystreak' operation, if desired
+    my $applyTiltyStreak = metadataLookupBool($recipeData, 'APPLY.TILTYSTREAK');
+    if ($applyTiltyStreak) {
+
+	my ($success, $error_code, $full_buf, $stdout_buf, $stderr_buf);
+
+	# XXX make these optional (must be built by psbuild as well...)
+	my $funpack = can_run('funpack') or &my_die ("Can't find funpack", $exp_id, $chip_id, $class_id, $PS_EXIT_SYS_ERROR);
+	my $tiltystreak = can_run('tiltystreak') or &my_die ("Can't find tiltystreak", $exp_id, $chip_id, $class_id, $PS_EXIT_SYS_ERROR);
+
+	# create an temporary output file:
+	my ($tempFile, $tempName) = tempfile( "/tmp/chip.$exp_id.$class_id.tmp.XXXX", UNLINK => !$save_temps );
+
+	print "uri: $uri\n";
+
+	# get the UNIX version of the (possible) neb: or path: filename
+	my $uriReal = $ipprc->file_resolve( $uri );
+
+	print "uriReal: $uriReal\n";
+
+	# unpack the data (is a NOP if not compressed)
+	$command = "$funpack -S $uriReal > $tempName";
+	( $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 funpack: $error_code", $exp_id, $chip_id, $class_id, $PS_EXIT_SYS_ERROR);
+	}
+
+	# run tiltystreak
+	$command = "$tiltystreak $tempName";
+	( $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 tiltystreak: $error_code", $exp_id, $chip_id, $class_id, $PS_EXIT_SYS_ERROR);
+	}
+
+	# supply the output file as the new input file
+	$uri = $tempName;
     }
 
