Index: /trunk/ippScripts/scripts/phase4_warp.pl
===================================================================
--- /trunk/ippScripts/scripts/phase4_warp.pl	(revision 11816)
+++ /trunk/ippScripts/scripts/phase4_warp.pl	(revision 11817)
@@ -32,11 +32,8 @@
 use Pod::Usage qw( pod2usage );
 
-my ($det_id, $exp_tag, $class_id, $p3_version, $uri, $camera, $dbname, $workdir, $no_update);
+my ($p4_id, $skycell_id, $camera, $dbname, $workdir, $no_update);
 GetOptions(
     'p4_id|i=s'         => \$p4_id, # Phase 4 identifier
-    'exp_tag|e=s'       => \$exp_tag, # Exposure tag
-    'class_id|i=s'      => \$class_id, # Class identifier
-    'p3_version|i=s'    => \$p3_version, # Phaser 3 version
-    'uri|u=s'           => \$uri, # URI for input file
+    'skycell_id|s=s'    => \$skycell_id, # Skycell identifier
     'camera|c=s'        => \$camera, # Camera name
     'dbname|d=s'        => \$dbname, # Database name
@@ -47,14 +44,10 @@
 pod2usage( -msg => "Unknown option: @ARGV", -exitval => 2 ) if @ARGV;
 pod2usage(
-    -msg => "Required options: --p4_id --exp_tag --class_id --p3_version --uri --camera",
+    -msg => "Required options: --p4_id --skycell_id --camera",
     -exitval => 3,
 ) unless defined $p4_id
-    and defined $exp_tag
-    and defined $class_id
-    and defined $p3_version
-    and defined $uri
+    and defined $skycell_id
     and defined $camera;
 
-# XXX this exits with status = 0 on failure
 $ipprc->define_camera($camera);
 
@@ -68,20 +61,45 @@
 }
 
+# Get list of component imfiles for exposure
+my $imfiles;
+{
+    my $command = "$p4tool -imfile -p4_id $p4_id -skycell_id $skycell_id";
+    $command .= " -dbname $dbname" if defined $dbname;
+    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
+	run(command => $command, verbose => 1);
+    unless ($success) {
+	$error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
+	&my_die("Unable to perform p4tool -imfile: $error_code", $p4_id, $skycell_id, $error_code);
+    }
+
+    my $metadata = $mdcParser->parse(join "", @$stdout_buf) or
+	&my_die("Unable to parse metadata config doc", $p4_id, $skycell_id, $PS_EXIT_PROG_ERROR);
+    $imfiles = parse_md_list($metadata) or 
+	&my_die("Unable to parse metadata list", $p4_id, $skycell_id, $PS_EXIT_PROG_ERROR);
+}
+
 ### Output file name
 if (defined $workdir) {
     $workdir = $ipprc->convert_filename_absolute( $workdir );
 } else {
-    my ($vol, $dir, $file) = File::Spec->splitpath( $uri );
+    my ($vol, $dir, $file) = File::Spec->splitpath( $$imfiles[0]->{uri} );
     $workdir = $dir;
 }
-my $outputFile = "$exp_tag.warp.$det_id"; # Root name
-my $outputRoot = File::Spec->catfile( $workdir, $exp_tag, $outputFile );
-my $outputImage = $ipprc->filename("PSWARP.OUTPUT", $outputRoot, $class_id);
-my $outputBin1 = $ipprc->filename("PSWARP.BIN1", $outputRoot, $class_id);
-my $outputBin2 = $ipprc->filename("PSWARP.BIN2", $outputRoot, $class_id);
+my $outputFile = "$skycell_id.warp.$p4_id"; # Root name
+my $outputRoot = File::Spec->catfile( $workdir, $outputFile );
+my $outputImage = $ipprc->filename("PSWARP.OUTPUT", $outputRoot, $skycell_id );
+my $outputBin1 = $ipprc->filename("PSWARP.BIN1", $outputRoot, $skycell_id );
+my $outputBin2 = $ipprc->filename("PSWARP.BIN2", $outputRoot, $skycell_id );
+my $outputStats = $outputRoot . '.stats';
+my $listName = $outputRoot . '.list';
 
-my $outputStats = $outputRoot . '.' . $class_id . '.stats';
+# Get list of filenames
+open my $listFile, '>' . $listName;
+foreach my $imfile (@$imfiles) {
+    my $uri = $ipprc->convert_filename_absolute( $file->{uri} );
 
-$uri = $ipprc->convert_filename_absolute( $uri );
+    print $listFile $uri . "\n";
+}
+close $listFile;
 
 # Run pswarp
@@ -92,10 +110,10 @@
     unless ($success) {
 	$error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
-	&my_die("Unable to perform pswarp: $error_code", $p4_id, $exp_tag, $class_id, $p3_version, $error_code);
+	&my_die("Unable to perform pswarp: $error_code", $p4_id, $skycell_id, $error_code);
     }
-    &my_die("Couldn't find expected output file: $outputImage", $p4_id, $exp_tag, $class_id, $p3_version, $PS_EXIT_SYS_ERROR) unless -f $outputImage;
-    &my_die("Couldn't find expected output file: $outputStats", $p4_id, $exp_tag, $class_id, $p3_version, $PS_EXIT_SYS_ERROR) unless -f $outputStats;
-    &my_die("Couldn't find expected output file: $outputBin1", $p4_id, $exp_tag, $class_id, $p3_version, $PS_EXIT_SYS_ERROR) unless -f $outputBin1;
-    &my_die("Couldn't find expected output file: $outputBin2", $p4_id, $exp_tag, $class_id, $p3_version, $PS_EXIT_SYS_ERROR) unless -f $outputBin2;
+    &my_die("Couldn't find expected output file: $outputImage", $p4_id, $skycell_id, $PS_EXIT_SYS_ERROR) unless -f $outputImage;
+    &my_die("Couldn't find expected output file: $outputStats", $p4_id, $skycell_id, $PS_EXIT_SYS_ERROR) unless -f $outputStats;
+    &my_die("Couldn't find expected output file: $outputBin1", $p4_id, $skycell_id, $PS_EXIT_SYS_ERROR) unless -f $outputBin1;
+    &my_die("Couldn't find expected output file: $outputBin2", $p4_id, $skycell_id, $PS_EXIT_SYS_ERROR) unless -f $outputBin2;
 }
 
@@ -109,7 +127,7 @@
     my $mdcParser = PS::IPP::Metadata::Config->new;	# Parser for metadata config files
     my $metadata = $mdcParser->parse(join "", @contents)
-        or &my_die("Unable to parse metadata config", $p4_id, $exp_tag, $class_id, $p3_version, $PS_EXIT_PROG_ERROR);
+        or &my_die("Unable to parse metadata config", $p4_id, $skycell_id, $PS_EXIT_PROG_ERROR);
     $stats = PS::IPP::Metadata::Stats->new(); # Stats parser
-    $stats->parse($metadata) or &my_die("Unable to find all values in statistics output.", $p4_id, $exp_tag, $class_id, $p3_version, $PS_EXIT_PROG_ERROR);
+    $stats->parse($metadata) or &my_die("Unable to find all values in statistics output.", $p4_id, $skycell_id, $PS_EXIT_PROG_ERROR);
 }
 
@@ -121,6 +139,6 @@
 # Add the processed file to the database
 unless ($no_update) {
-    my $command = "$p4tool -addwarpedimfile -p4_id $p4_id -exp_tag $exp_tag " .
-	"-class_id $class_id -p3_version $p3_version -uri $outputImage -b1_uri $outputRoot";  # Command to run dettool
+    my $command = "$p4tool -warped -p4_id $p4_id -skycell_id $skycell_id" .
+	" -uri $outputImage -b1_uri $outputRoot";  # Command to run dettool
     $command .= " -bg " . $stats->bg_mean();
     $command .= " -bg_mean_stdev " . $stats->bg_mean_stdev();
@@ -142,12 +160,10 @@
     my $msg = shift;		# Warning message on die
     my $p4_id = shift;		# Phase 4 identifier
-    my $exp_tag = shift;	# Exposure tag
-    my $class_id = shift;	# Class identifier
-    my $p3_version = shift;	# Phase 3 version
+    my $skycell_id = shift;	# Skycell identifier
     my $exit_code = shift;	# Exit code to add
 
     warn($msg);
-    if ($det_id and $exp_tag and $class_id) {
-	my $command = "$p4tool -addwarpedimfile -p4_id $p4_id -exp_tag $exp_tag -class_id $class_id -p3_version $p3_version -code $exit_code";
+    if ($p4_id and $skycell_id) {
+	my $command = "$p4tool -warped -p4_id $p4_id -skycell_id $skycell_id -code $exit_code";
 	$command .= " -dbname $dbname" if defined $dbname;
         system ($command);
